June 19, 2014

Perf and Stack Traces

I was wondering why perf record -g don’t show proper stack traces for my programs in production environment. First I thought that kernel was too old, but after performing few experiments I have found out that it wasn’t the case. Problem was that when you compile with optimizations (-O3), gcc automatically omits frame pointers. And it is not easy to unwind stack traces without frame pointers. But gcc can do it somehow. Read more

May 2, 2014

Who's Calling

Sometimes your program uses a lot of system time. Let’s say 90%. You fire up your favorite profiling tool and it tells you which system call it is. If you are experiences and maybe lucky, you can say straight away which part of your program is to blame. But it’s not always so obvious. GDB comes to the rescue. You can use catch syscall <syscall> and it will break when particular syscall is called. Read more

May 2, 2014

Perf on Latest Linux Kernel

I have being playing today with perf on latest available kernel in Fedora (3.13). These are just some observations and thoughts. perf trace This tool is similar to strace, but almost without overhead. Contrary to strace, you can use perf trace to watch syscalls system wide or system calls generated by processes owned by certain user. perf top Function names are shown correctly and -g parameter is now available. It means that you can get call traces in a real time (without perf record). Read more

June 30, 2012

Searching for a position of set bits in a variable

In a deamon that I have created in Badoo I need to search for a positions of a bits in a 32 bit variable. The simplest solution is to look at each bit, but there is a faster solution using GCC built in function __builtin_ctzl: Returns the number of trailing 0-bits in x, starting at the least significant bit position. If x is 0, the result is undefined. So I wrote test to compare speed of these two approaches: Read more