从 gprof 结果中排除函数

发布于 2024-11-18 20:18:10 字数 308 浏览 3 评论 0原文

我想从 gprof 生成的输出中排除一些函数。换句话说,我不希望在计算每个函数在执行期间花费的时间百分比时将它们包括在内。我在一处读到可以使用 -E 选项。

但是,我正在使用 gprof -E function_to_be_exluded my_program_name,但没有任何反应。手册说它已折旧,您应该使用 symspecs 代替。然而,我浪费了半个小时试图弄清楚如何使用 symspecs 来实现它,但没有运气。任何人都可以在这方面帮助我。

I want to exclude some functions from the output generated by gprof. In other words, I do not want them to be included when calculating percentage time spent by each function during execution. I read at one place -E option can be used.

However I'm using gprof -E function_to_be_exluded my_program_name, but nothing happens. The manual says it is depreciated and you should use symspecs instead. However, I have wasted half an hour trying to figure out how to achieve it with symspecs, but no luck. Anyone can kindly help me in this.

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

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

发布评论

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

评论(3

梅窗月明清似水 2024-11-25 20:18:10

确切地说, gprof -e -E 已被弃用并被具有参数 - symspecs 的较新的相关选项所取代。因此,请尝试使用:

gprof --no-time=symspec 

The -n option causes "gprof", in its call graph analysis, not to propagate times for
symbols matching symspec.

e.g.

gprof --no-time=name_of_function_you_dont_want_to_profile.

将其与其他 gprof 选项一起使用(-E -e 绝对排除)

Exactly, gprof -e -E are deprecated and superseded by usage of newer relevant options that have argument - symspecs. So try using:

gprof --no-time=symspec 

The -n option causes "gprof", in its call graph analysis, not to propagate times for
symbols matching symspec.

e.g.

gprof --no-time=name_of_function_you_dont_want_to_profile.

Use this along with your other gprof options (-E -e definitely ruled out)

动次打次papapa 2024-11-25 20:18:10

根据该人的说法:

  • 要显示平面配置文件并从中排除功能,您需要使用-P选项:

    gprof main gmon.out -Pfunction_name
    
  • 要显示调用图并从中排除函数,您需要使用 - Q选项:

    gprof main gmon.out -Qfunction_name
    

此选项可以重复并同时使用:

gprof main gmon.out -Pfunction_name -Qfunction_name -Qother_function_name

如果您需要从其中排除函数报告但不排除您需要使用 -p-q 选项的其他功能。

示例:

创建程序:

#include <stdio.h>
#include <stdlib.h>

void func_a () {printf ("%s ",__FUNCTION__);}
void func_b () {printf ("%s ",__FUNCTION__);}
void func_c () {printf ("%s ",__FUNCTION__);}

int main ()
{
    func_a ();
    func_b ();
    func_c ();
    return EXIT_SUCCESS;
}

编译它:
gcc main.c -pg -o main

并启动:

$ ./main
func_a func_b func_c

生成配置文件报告:

  • 如果您只需要打印平面配置文件,则需要调用:

    $ gprof main gmon.out -b -p  
      % 累计自我总计             
     时间 秒 秒 呼叫 Ts/呼叫 Ts/呼叫名称      
      0.00 0.00 0.00 1 0.00 0.00 函数_a  
      0.00 0.00 0.00 1 0.00 0.00 函数_b  
      0.00 0.00 0.00 1 0.00 0.00 函数_c
    
  • 如果您需要打印平面配置文件,不包括函数 func_afunc_c 以及完整调用您需要调用的图表:

    $ gprof main gmon.out -b -Pfunc_a -Pfunc_c -q
      % 累计自我总计           
     时间 秒 秒 呼叫 Ts/呼叫 Ts/呼叫名称    
      0.00 0.00 0.00 1 0.00 0.00 函数_b
    
    索引%时间自己的孩子叫名字
                    0.00 0.00 1/1 主 [9]
    [1] 0.0 0.00 0.00 1 func_a [1]
    -----------------------------------------------------------
                    0.00 0.00 1/1 主 [9]
    [2] 0.0 0.00 0.00 1 func_b [2]
    -----------------------------------------------------------
                    0.00 0.00 1/1 主 [9]
    [3] 0.0 0.00 0.00 1 func_c [3]
    -----------------------------------------------------------
    
  • 如果您需要打印平面配置文件排除函数 func_afunc_c 以及调用图,排除 func_b 您需要调用:

    $ gprof main gmon.out -b -Pfunc_a -Pfunc_c -Qfunc_b
      % 累计自我自我总计           
     时间 秒 秒 呼叫 Ts/呼叫 Ts/呼叫名称    
      0.00 0.00 0.00 1 0.00 0.00 函数_b
    
    索引%时间自己的孩子叫名字
                    0.00 0.00 1/1 主 [9]
    [1] 0.0 0.00 0.00 1 func_a [1]
    -----------------------------------------------------------
                    0.00 0.00 1/1 主 [9]  
    [3] 0.0 0.00 0.00 1 func_c [3]
    -----------------------------------------------------------
    

According to the man:

  • for display flat profile and exclude function from it you need use -P option:

    gprof main gmon.out -Pfunction_name
    
  • for display call graph and exclude function from it you need use -Q option:

    gprof main gmon.out -Qfunction_name
    

This options can be repeated and used in the same time:

gprof main gmon.out -Pfunction_name -Qfunction_name -Qother_function_name

If you need exclude function from one report but not exclude any function from other you need use -p or -q options.

Example:

Create program:

#include <stdio.h>
#include <stdlib.h>

void func_a () {printf ("%s ",__FUNCTION__);}
void func_b () {printf ("%s ",__FUNCTION__);}
void func_c () {printf ("%s ",__FUNCTION__);}

int main ()
{
    func_a ();
    func_b ();
    func_c ();
    return EXIT_SUCCESS;
}

Compile it:
gcc main.c -pg -o main

And launch:

$ ./main
func_a func_b func_c

Generate profile reports:

  • If you need print only flat profile you need call:

    $ gprof main gmon.out -b -p  
      %   cumulative   self              self     total             
     time   seconds   seconds    calls  Ts/call  Ts/call  name      
      0.00      0.00     0.00        1     0.00     0.00  func_a  
      0.00      0.00     0.00        1     0.00     0.00  func_b  
      0.00      0.00     0.00        1     0.00     0.00  func_c
    
  • If you need print flat profile excluding functions func_a and func_c and full call graph you need call:

    $ gprof main gmon.out -b -Pfunc_a -Pfunc_c -q
      %   cumulative   self              self     total           
     time   seconds   seconds    calls  Ts/call  Ts/call  name    
      0.00      0.00     0.00        1     0.00     0.00  func_b
    
    index % time    self  children    called     name
                    0.00    0.00       1/1           main [9]
    [1]      0.0    0.00    0.00       1         func_a [1]
    -----------------------------------------------
                    0.00    0.00       1/1           main [9]
    [2]      0.0    0.00    0.00       1         func_b [2]
    -----------------------------------------------
                    0.00    0.00       1/1           main [9]
    [3]      0.0    0.00    0.00       1         func_c [3]
    -----------------------------------------------
    
  • If you need print flat profile excluding functions func_a and func_c and call graph excluding func_b you need call:

    $ gprof main gmon.out -b -Pfunc_a -Pfunc_c -Qfunc_b
      %   cumulative   self              self     total           
     time   seconds   seconds    calls  Ts/call  Ts/call  name    
      0.00      0.00     0.00        1     0.00     0.00  func_b
    
    index % time    self  children    called     name
                    0.00    0.00       1/1           main [9]
    [1]      0.0    0.00    0.00       1         func_a [1]
    -----------------------------------------------
                    0.00    0.00       1/1           main [9]  
    [3]      0.0    0.00    0.00       1         func_c [3]
    -----------------------------------------------
    
水中月 2024-11-25 20:18:10

除非我误解了你的要求...

gprof a.out --no-time=function_name

对我有用。

Unless I've misunderstood what you're asking...

gprof a.out --no-time=function_name

works for me.

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