为什么循环摘要在 gprof 的调用图输出中没有任何调用者?

发布于 2024-07-19 02:59:25 字数 1323 浏览 8 评论 0原文

我使用 GNU gprof 2.15.94.0.2.2 对我的 C++ 程序进行分析,该程序具有较大的调用周期。 我期望在调用图输出中看到类似下面的内容 gprof 的文档表明

index  % time    self  children called     name
----------------------------------------
                 1.77        0    1/1        main [2]
[3]     91.71    1.77        0    1+5    <cycle 1 as a whole> [3]
                 1.02        0    3          b <cycle 1> [4]
                 0.75        0    2          a <cycle 1> [5]
                    0        0    6/6        c [6]
----------------------------------------

但是,我的 条目都没有列出任何调用者。 它们都是这样的:

index  % time    self  children called             name
----------------------------------------------
[8]     65.6    259.55  5342.63  9334767+60122608 <cycle 2 as a whole> [8]
                133.28  2051.45  12043564+74015448    foo <cycle 2> [14]
                18.90   976.38   2379645              bar <cycle 2> [21]
...                                                                      
-----------------------------------------------

由于我的循环非常大,因此很难通过循环中的各个函数来跟踪调用者。

谁能告诉我为什么循环调用者在输出中丢失,以及如何让它们出现?

I use GNU gprof 2.15.94.0.2.2 to do profiling of my C++ program, which has large call cycles. I expected to see something like below in the call graph output as gprof's documentation indicates:

index  % time    self  children called     name
----------------------------------------
                 1.77        0    1/1        main [2]
[3]     91.71    1.77        0    1+5    <cycle 1 as a whole> [3]
                 1.02        0    3          b <cycle 1> [4]
                 0.75        0    2          a <cycle 1> [5]
                    0        0    6/6        c [6]
----------------------------------------

However, none of my <cycle as a whole> entries have any callers listed. They are all like this:

index  % time    self  children called             name
----------------------------------------------
[8]     65.6    259.55  5342.63  9334767+60122608 <cycle 2 as a whole> [8]
                133.28  2051.45  12043564+74015448    foo <cycle 2> [14]
                18.90   976.38   2379645              bar <cycle 2> [21]
...                                                                      
-----------------------------------------------

Since my cycles are quite large, it is very hard to trace the callers via individual functions in a cycle.

Can anyone tell me why the cycle callers are missing in the output, and how to make them show up?

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

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

发布评论

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

评论(3

终难遇 2024-07-26 02:59:25

您的应用程序使用多线程吗? gprof 根本不支持线程。 否则,您很可能遇到了 gprof 中的错误。 它充满了错误并且已经过时了。 最好使用 oprofile 或 valgrind 之类的东西。

Does your application use multithreading? gprof doesn't work with threads at all. Otherwise, you may very likely have hit a bug in gprof. It's bug ridden and obsolete. Better use something like oprofile or valgrind.

北恋 2024-07-26 02:59:25

我什至将其称为 gprof 中的错误。 我设置了一个相互递归函数的简单示例,并得到了与您完全相同的行为。 我有 Functions:

int a(int n){return b(n);}
int b(int n){return c(n);}
int c(int n){return (n==0)?n:a(n-1);}

和 main():

for(int j=0; j <1000; ++j)
  for(int i=0; i < 10; ++i)
     cout << a(i);

我尝试将对 a() 的调用替换为:

int d(int n){return a(n);}

希望 gprof 能够比 main() 的调用更好地注册对 d() 的循环的调用,但我得到了相同的结果。

我还用 printf() 替换了 cout 并编写了一个 C 程序,与循环中没有列出调用者的结果相同。

I'm going to go so far as to call this a bug in gprof. I set up a simple example of mutually recursive functions and got the exact same behavior you did. I had functions:

int a(int n){return b(n);}
int b(int n){return c(n);}
int c(int n){return (n==0)?n:a(n-1);}

and a main():

for(int j=0; j <1000; ++j)
  for(int i=0; i < 10; ++i)
     cout << a(i);

I tried replacing the call to a() with:

int d(int n){return a(n);}

in the hopes that gprof would register a call to the cycle from d() better than the call from main(), but I got the same result.

I also replaced the cout with printf() and made a C program, with the same results of no caller listed for the cycle.

春庭雪 2024-07-26 02:59:25

这是您主要关心的问题,还是您有更大的目标,例如尝试找到可以优化的东西? 通常,这就是人们使用 gprof 的原因。

gprof就是这样,但你可以做得更好。

Is this your main concern, or do you have a larger goal, like trying to find things you can optimize? Usually, that's why people use gprof.

gprof is what it is, but you can do better.

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