gprof reports no time accumulated

2019-01-12 01:54发布

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?

7条回答
看我几分像从前
2楼-- · 2019-01-12 02:21

Btw, do you fork() in your code? If so, add this in the child process just after the fork():

extern void _start (void), etext (void);
monstartup ((u_long) &_start, (u_long) &etext);

That did the trick for me.

查看更多
Emotional °昔
3楼-- · 2019-01-12 02:28

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.

查看更多
我想做一个坏孩纸
4楼-- · 2019-01-12 02:28

the precision of time in gprof is 0.00. so maybe your module taking less time (milli sec/micro sec).Hence, it will show 0.00 and no time accumulated.So, run the whole program about 1000/1000000 times so that it will come to seconds.At last, divide obtained time with your looping factor (1000/1000000) and that going to be your processing time. I too faced the same problem and by doing this it gets solved.

查看更多
老娘就宠你
5楼-- · 2019-01-12 02:30

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!

查看更多
【Aperson】
6楼-- · 2019-01-12 02:34

Perhaps not relevant to the OP's question, there is a common scenario where "no time accumulated" happens: if your code calls the kernel or calls libraries not compiled with -pg, you won't see any time accumulated for time spent there.

查看更多
乱世女痞
7楼-- · 2019-01-12 02:37

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.

查看更多
登录 后发表回答