tags:

views:

758

answers:

5

I'm trying to profile a C++ application with gprof on a machine running OSX 10.5.7. I compile with g++ in the usual way, but using -pg flags, run the application and try to view the call graph with gprof.

Unfortunately my call graph contains all zeroes for all time columns. The values in the "called" columns have reasonable values so it looks like something was profiled but I'm mystified about the lack of other data.

All my source files are compiled in a similar way:

g++ -pg -O2 -DNDEBUG -I./ -ansi -c -o  ScenarioLoader.o ScenarioLoader.cpp

I then run 'ar' to bundle all the object files into a library. Later, I link and run gprof as so:

g++ -pg -lm  -o vrpalone vrpalone.o ../src/atomicprof.a lastbuild.o
./vrpalone
gprof gmon.out | less

Any ideas?

+2  A: 

If your program terminates in a non-clean manner then the profile data won't get written correctly - how is your program exiting?

Regardless, I'd strongly recommend using Shark instead of gprof - it's very easy to use and superior in pretty much every way to gprof - and doesn't require you to recompile your program.

Dave Rigby
Hi Dave. My program terminates cleanly. I've had a look at Shark and while it does work I can't seem to make it generate a flat profile. There is a flattening option that I've found but it doesn't display the same information as gprof which is dissapointing; ideally I would like all functions with the same name added together. I also can't seem to make Shark display the number of calls to each function.
Daniel
I found the "heavy view" option to solve the flattening problem. Still can't see a nice way of displaying number of calls. Oh well. I think I have enough! Cheers for the help Dave.
Daniel
Strong +1 for Shark. Beats gprof or Google Perf Tools when developing on OSX.You can see the exact number of samples by selecting a given row. It then shows the number of samples to that function on the bottom. Rarely is this useful though given that the % is what's helpful.
Tristan
+1  A: 

How fast does your program run? If its extremely quick, it might be too fast to actually profile. I had this problem with a very simple text processing program: when I ran it with my sub-1kb test file it reported all 0s in the time columns. I solved this by running the entire text of The Great Gatsby through it. Try a larger dataset or looping through your main computation a few hundred times.

psanf
Hi psanf. My program runs for quite some time depending on the input I give it (it solves various traveling salesman problems). I've tried profiling it using a small problem involving 318 cities which takes ~30 seconds to solve.
Daniel
+1  A: 

Does your program use multiple threads? I've experienced this issue with multithreaded programs on Linux, not sure if OS X would have the same problems

Here is a solution to the multithreading issue which I've used sucessfully in the past.

bdk
Hi bklock. My program is only singly threaded at the moment. I will keep that link in mind though!
Daniel
+1  A: 

I thought I might share this Apple mailing list discussion which I recently ran across.

The behaviour described here is exactly what I am experiencing. It looks like gprof has been broken on OSX for quite some time.

I've resorted to Shark which has been helpfully suggested by Dave Rigby.

Thanks!

Daniel
A: 

gprof has been around since 1982. Since that time, design of computers and languages has advanced enormously, but our collective understanding of performance issues has progressed very little. We still talk loosely about the same concepts that gprof introduced, and we have not sought to really understand them.

Here's a discussion and presentation of some newer ideas.

Mike Dunlavey