Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to profile my C++ application on linux

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.

like image 685
richard Avatar asked May 12 '10 20:05

richard


People also ask

What is GNU profiler gprof?

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.

What is the correct filename of the current user’s profile?

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.

How do I install gprof on Linux?

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:

Why do people use debug mode for CPU profiling?

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.


3 Answers

Check out oprofile. Also for more system-level diagnostics, try systemtap.

like image 185
florin Avatar answered Oct 21 '22 14:10

florin


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.

like image 28
Kaleb Pederson Avatar answered Oct 21 '22 12:10

Kaleb Pederson


LTTng is a good tool to use for full system profiling.

like image 3
Yann Ramin Avatar answered Oct 21 '22 13:10

Yann Ramin