Ask HN: What's your best C/C++ profiling tool, hints and best practice?
I frequently come across wanting to profile C++ on Linux. I have used perf a lot before but do not have vtune handy. I have dabbled around with poor man's profiler but that seems to get trickier with lots and lots of threads. What are your favorite outside-the-box approaches? How do you figure out contention or IO wait issues?
12 comments
[ 2.6 ms ] story [ 34.7 ms ] threadhttp://hpctoolkit.org/ https://www.cs.uoregon.edu/research/tau/home.php
[TAU is doubtless a good bet, but for what it's worth for general interest, the other common systems for HPC are openspeedshop.org, cube/scalasca (scalasca.org), and extrae/paraver (bsc.es). A good comparison of them all would be useful, but I've not found one.]
Gprof is good too.
I've also tried vtune, but it doesn't support stack-tracing (or things like lbr) for system-wide profiling, and it doesn't have a specific option for sampling drivers. You can attach to the System process, but then you're missing a lot of the your driver code, that runs in other contexts.
I kept thinking about implementing my own sampling profiler (using LBR for stack-tracing, and hardware performance events, like linux's oprofile/ freebsd's hwpmc), but I can't see how I could only profile my driver, and not the whole system, without hooking the Windows scheduler. I guess I will just profile the whole system and check if the program counter is inside my module.
Write end2end tests that execises the application as close to what user would. Then, use a profiler with an API so you can start dump when test/app setup is completed (to avoid extranous noise/misleading data). I like gperftools combined with KCachegrind as a GUI. Used it very successfully for instance in MyPaint: http://www.jonnor.com/2012/11/improved-drawing-performance-i...
That said, http://www.brendangregg.com/flamegraphs.html is a nice introduction to a site that has lots of material.