views:

1489

answers:

8

I need to profile some code running C++ on Linux. Can you guys recommend some profilers?

+4  A: 

valgrind is a well-know linux profiler

dfa
thought valgrind was more for memory leak checking.. I am trying to see which functions are getting called etc
shergill
use the suite tool called "callgrind"
dfa
Valgrind is simply a framework for building dynamic tools. Although, it's become synonymous with Memcheck, a tool built on Valgrind. Callgrind is a pretty good at profiler.
Falaina
+5  A: 

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.

Falaina
+1 for oprofile, that is not an "easy tool"
dfa
Haha, true. I should probably not make that sound so easy :) It's certainly not as simple as "run program under it" as Vtune and Valgrind tools, but I feel you get used to it pretty quickly.
Falaina
oprofile looks interesting - does it support x86_64?
LiraNuna
+1  A: 

gprof is the standard gnu tool for profiling.

twk
You're right, and that's sad. http://stackoverflow.com/questions/1777556/alternatives-to-gprof/1779343#1779343
Mike Dunlavey
+2  A: 

Google also has a nice profiler as part of the google-perftools -- which are included in Debian / Ubuntu and possibly other distros.

Dirk Eddelbuettel
+1  A: 

Take a look at KCacheGrind which is a graphical frontend to valgrind and makes it really easy to use it.

Milan Babuškov
+4  A: 

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.

smcameron
+1  A: 

This is what I use.

Mike Dunlavey
+5  A: 

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.

XWare