问题
I need to profile some code running C++ on Linux. Can you guys recommend some profilers?
回答1:
Use gprof.
Just compile with -pg
flag (I think (but am not sure) you have to turn of optimizations though.) and use gprof to analyze the gmon.out file that your executable will then produce.
eg:
gcc -pg -o whatever whatever.c
./whatever
gprof whatever gmon.out
Same thing with g++ and cpp.
回答2:
valgrind is a well-know linux profiler
回答3:
Zoom from RotateRight ( http://www.rotateright.com ) is what I've been using. It has a butterfly view of functions and you can double-click any function to dive into source or asm code. Build with debugging information (-g) to see your source, but you should still build and profile optimized code.
回答4:
I'm a fan of Oprofile. It involves installing a kernel module and has a bit of a learning curve to it, but it's fairly powerful and works very well for optimized programs/programs without debugging symbols.
Vtune is another very powerful profiler made by Intel. I believe the Linux version is free for Non-commercial software.
There is also the Valgrind suite of tools proposed by dfa. Callgrind would probably be what you're most interested in. Cachegrind(whose featureset is a subset of Callgrind's) and Massif are interesting as well, but I have no experience with the latter.
回答5:
Take a look at KCacheGrind which is a graphical frontend to valgrind and makes it really easy to use it.
回答6:
Google also has a nice profiler as part of the google-perftools -- which are included in Debian / Ubuntu and possibly other distros.
回答7:
gprof is the standard gnu tool for profiling.
回答8:
Take a look at Sysprof. You distribution most likely has it available already.
Note that all of the mentioned profilers work best if your application is compiled with frame pointers. That is, you should use -fno-omit-frame-pointer on the gcc command line.
回答9:
This is what I use.
来源:https://stackoverflow.com/questions/1168766/what-is-a-good-easy-to-use-profiler-for-c-on-linux