How to profile my C++ application on linux

2020-03-01 07:38发布

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.

9条回答
兄弟一词,经得起流年.
2楼-- · 2020-03-01 07:43

callgrind is a very good tool but I found OProfile to me more 'complete'. Also, it is the only one that lets you specify module and/or kernel source to allow deeper insight into your bottlenecks. The output is supposed to be able to interface with KCacheGrind but I had trouble with that so I used Gprof2Dot instead. You can export your callgraph to a .png.

Edit:

OProfile looks at the overall system so the process will just be:

[setup oprofile]

opcontrol --init
opcontorl --vmlinux=/path/to/vmlinux     (or --no-vmlinux)
opcontrol --start

[run your app here]

opcontrol --stop   (or opcontrol --shutdown [man for difference]

then to start looking at the results look at the man page on opreport

查看更多
一夜七次
3楼-- · 2020-03-01 07:44

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.

查看更多
贼婆χ
4楼-- · 2020-03-01 07:46

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

查看更多
够拽才男人
5楼-- · 2020-03-01 07:49

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

查看更多
一夜七次
6楼-- · 2020-03-01 07:52

The lackey and/or helgrind tools in valgrind should allow you to do this.

查看更多
beautiful°
7楼-- · 2020-03-01 07:54

You might want to check out Zoom, which is a lot more polished and full-featured than oprofile et al. It costs money ($199), but you can get a free 30 day evaluation licence.

查看更多
登录 后发表回答