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. And then you can use 'bt' to find where in your code this syscall is being called from.



P.S. Don't use random() in multi-threaded program. Use random_r().