gprof 报告没有累积时间

发布于 2024-07-26 00:32:29 字数 522 浏览 5 评论 0原文

我正在尝试在运行 OSX 10.5.7 的计算机上使用 gprof 分析 C++ 应用程序。 我以通常的方式使用 g++ 进行编译,但使用 -pg 标志,运行应用程序并尝试使用 gprof 查看调用图。

不幸的是,我的调用图包含所有时间列的全零。 “被调用”列中的值具有合理的值,因此看起来像是对某些内容进行了分析,但我对缺乏其他数据感到困惑。

我的所有源文件都以类似的方式编译:

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

然后运行“ar”将所有目标文件捆绑到一个库中。 后来,我像这样链接并运行 gprof:

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

有什么想法吗?

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(7

是伱的 2024-08-02 00:32:29

如果您的程序以非干净的方式终止,那么配置文件数据将无法正确写入 - 您的程序如何退出?

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

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.

甜`诱少女 2024-08-02 00:32:29

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

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.

仙女山的月亮 2024-08-02 00:32:29

你的程序运行速度有多快? 如果速度非常快,则可能太快而无法进行实际分析。 我在使用一个非常简单的文本处理程序时遇到了这个问题:当我使用低于 1kb 的测试文件运行它时,它报告时间列中全为 0。 我通过运行《了不起的盖茨比》的全文来解决这个问题。 尝试更大的数据集或循环主要计算数百次。

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.

遮云壑 2024-08-02 00:32:29

我想我可以分享这个 Apple 邮件列表讨论我最近跑过。

这里描述的行为正是我所经历的。
看起来 gprof 在 OSX 上已经被破坏了一段时间了。

我求助于戴夫·里格比(Dave Rigby)很有帮助的建议的鲨鱼。

谢谢!

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!

顾挽 2024-08-02 00:32:29

你的程序使用多线程吗? 我在 Linux 上的多线程程序中遇到过这个问题,不确定 OS X 是否也会遇到同样的问题

这里是 我过去成功使用过的多线程问题的解决方案

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.

无所谓啦 2024-08-02 00:32:29

顺便说一句,你的代码中有 fork() 吗?
如果是这样,请将其添加到 fork() 之后的子进程中:

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

这对我来说很有效。

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.

逆流 2024-08-02 00:32:29

gprof 中的时间精度为 0.00。 所以也许你的模块花费的时间更少
(毫秒/微秒)。因此,它将显示 0.00 并且没有时间累积。因此,运行整个程序大约 1000/1000000 次,这样它就会达到最后,将获得的时间除以循环因子(1000/1000000),这将是您的处理时间。 我也遇到了同样的问题,通过这样做它就得到了解决。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文