简体   繁体   English

gprof报告没有时间积累

[英]gprof reports no time accumulated

I'm trying to profile a C++ application with gprof on a machine running OSX 10.5.7. 我正在尝试在运行OSX 10.5.7的计算机上使用gprof配置C ++应用程序。 I compile with g++ in the usual way, but using -pg flags, run the application and try to view the call graph with gprof. 我以通常的方式使用g ++编译,但是使用-pg标志,运行应用程序并尝试使用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. 然后我运行'ar'将所有目标文件捆绑到一个库中。 Later, I link and run gprof as so: 后来,我链接并运行gprof如下:

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

Any ideas? 有任何想法吗?

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. 无论如何,我强烈建议使用Shark而不是gprof - 它非常易于使用,并且在几乎所有方面都优于gprof - 并且不需要您重新编译程序。

I thought I might share this Apple mailing list discussion which I recently ran across. 我想我可能会分享我最近遇到的Apple邮件列表讨论

The behaviour described here is exactly what I am experiencing. 这里描述的行为正是我所经历的。 It looks like gprof has been broken on OSX for quite some time. 看起来gprof已经在OSX上被打破了很长一段时间。

I've resorted to Shark which has been helpfully suggested by Dave Rigby. 我已经使用了由Dave Rigby帮助建议的Shark。

Thanks! 谢谢!

也许与OP的问题无关,有一个常见的情况是“没有时间累积”发生:如果您的代码调用内核或调用未使用-pg编译的库,您将看不到在那里花费的时间累积的任何时间。

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. 我在一个非常简单的文本处理程序中遇到了这个问题:当我用我的sub-1kb测试文件运行它时,它报告了时间列中的所有0。 I solved this by running the entire text of The Great Gatsby through it. 我通过运行The Great Gatsby的全文来解决这个问题。 Try a larger dataset or looping through your main computation a few hundred times. 尝试更大的数据集或循环几次主计算。

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 我在Linux上遇到过多线程程序这个问题,不确定OS X会遇到同样的问题

Here is a solution to the multithreading issue which I've used sucessfully in the past. 这是我过去成功使用的多线程问题的解决方案

Btw, do you fork() in your code? 顺便问一下,你在代码中fork()吗? If so, add this in the child process just after the fork(): 如果是这样,请在fork()之后的子进程中添加:

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

That did the trick for me. 这对我有用。

the precision of time in gprof is 0.00 . gprof中的时间精度为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. 所以也许你的模块花费更少的时间(毫秒/微秒)。因此,它将显示0.00并且没有时间累积。因此,运行整个程序大约1000/1000000 times以便它将达到秒。最后,获得分割循环因子(1000/1000000) ,这将是您的处理时间。 I too faced the same problem and by doing this it gets solved. 我也面临同样的问题,通过这样做,它得到了解决。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM