C++ gprof 报告没有累积时间
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/1030829/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
gprof reports no time accumulated
提问by Daniel
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.
我正在尝试在运行 OSX 10.5.7 的机器上使用 gprof 分析 C++ 应用程序。我以通常的方式使用 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. Later, I link and run gprof as so:
然后我运行 'ar' 将所有目标文件捆绑到一个库中。后来,我链接并运行 gprof 如下:
g++ -pg -lm -o vrpalone vrpalone.o ../src/atomicprof.a lastbuild.o
./vrpalone
gprof gmon.out | less
Any ideas?
有任何想法吗?
采纳答案by Daniel
I thought I might share this Apple mailing list discussionwhich 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!
谢谢!
回答by DaveR
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 Sharkinstead 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 - 并且不需要您重新编译您的程序。
回答by Fixee
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.
也许与 OP 的问题无关,有一种常见的情况是“没有时间积累”发生:如果您的代码调用内核或调用未使用 编译的库-pg
,您将看不到在那里花费的时间积累的任何时间。
回答by Big Papoo
Btw, do you fork() in your code? If so, add this in the child process just after the fork():
顺便说一句,你在你的代码中 fork() 吗?如果是这样,请在 fork() 之后的子进程中添加以下内容:
extern void _start (void), etext (void);
monstartup ((u_long) &_start, (u_long) &etext);
That did the trick for me.
这对我有用。
回答by psanf
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.
你的程序运行速度有多快?如果它非常快,那么实际分析可能太快了。我在一个非常简单的文本处理程序中遇到了这个问题:当我用低于 1kb 的测试文件运行它时,它在时间列中报告全为 0。我通过运行《了不起的盖茨比》的整个文本来解决这个问题。尝试更大的数据集或在主要计算中循环数百次。
回答by bdk
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 solutionto the multithreading issue which I've used sucessfully in the past.
这是我过去成功使用的多线程问题的解决方案。
回答by Tharun Meddi
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.
gprof 中的时间精度为0.00
. 所以也许你的模块花费的时间更少(毫秒/微秒)。因此,它会显示0.00
并且不会累积时间。1000/1000000 times
所以,运行整个程序,使其变为秒。最后,将获得的时间除以你的循环因子(1000/1000000)
这将是您的处理时间。我也遇到了同样的问题,这样做就解决了。