I would like to profile my c++ application on linux. I would like to find out how much time my application spent on CPU processing vs time spent on block by IO/being idle.
I know there is a profile tool call valgrind on linux. But it breaks down time spent on each method, and it does not give me an overall picture of how much time spent on CPU processing vs idle? Or is there a way to do that with valgrind.
If you are a programmer who develops software applications for Linux, the GNU profiler “gprof” is the tool to look out for. Gprof comes pre-installed with most of the Linux distributions, but if that’s not the case with your Linux distro, you can download and install it through a command line package manager like apt-get or yum.
The correct filename of the current user’s profile is ~/.profile (where ~ is a shortcut for the current user’s home directory). (Press q to quit less .) Of course, you can open the file using your favorite editor, e.g. vi (a command-line based editor) or gedit (the default GUI text editor in Ubuntu) to view (and modify) it.
Gprof comes pre-installed with most of the Linux distributions, but if that’s not the case with your Linux distro, you can download and install it through a command line package manager like apt-get or yum. For example, run the following command to download and install gprof on Debian-based systems:
You're statistically likely to land in a region that is eating most of your CPU cycles. For CPU, the reason for profiling in DEBUG mode is because if your tried profiling in RELEASE mode, the compiler is going to reduce math, vectorize loops, and inline functions which tends to glob your code into an un-mappable mess when it's assembled.
Check out oprofile. Also for more system-level diagnostics, try systemtap.
I can recommend valgrind
's callgrind tool in conjunction with KCacheGrind for visualization. KCacheGrind makes it pretty easy to see where the hotspots are.
Note: It's been too long since I used it, so I'm not sure if you'll be able to get I/O Wait time out of that. Perhaps in conjunction with iostat or pidstat you'll be able to see where all the time was spent.
LTTng is a good tool to use for full system profiling.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With