简体   繁体   English

从 gprof 结果中排除 function

[英]Excluding a function from gprof results

I want to exclude some functions from the output generated by gprof.我想从 gprof 生成的 output 中排除一些函数。 In other words, I do not want them to be included when calculating percentage time spent by each function during execution.换句话说,我不希望在计算每个 function 在执行期间花费的时间百分比时包括它们。 I read at one place -E option can be used.我在一处读到-E选项可以使用。

However I'm using gprof -E function_to_be_exluded my_program_name , but nothing happens.但是我正在使用gprof -E function_to_be_exluded my_program_name ,但没有任何反应。 The manual says it is depreciated and you should use symspecs instead.手册说它已折旧,您应该改用symspecs However, I have wasted half an hour trying to figure out how to achieve it with symspecs , but no luck.但是,我浪费了半个小时试图弄清楚如何使用symspecs来实现它,但没有运气。 Anyone can kindly help me in this.任何人都可以在这方面帮助我。

Exactly, gprof -e -E are deprecated and superseded by usage of newer relevant options that have argument - symspecs.确切地说, gprof -e -E 已被弃用并被具有参数的较新相关选项的使用所取代 - 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)将此与其他 gprof 选项一起使用(-E -e 绝对排除)

According to the man:据该男子称:

  • for display flat profile and exclude function from it you need use -P option:对于显示平面轮廓并从中排除 function 您需要使用-P选项:

     gprof main gmon.out -Pfunction_name
  • for display call graph and exclude function from it you need use -Q option:为了显示调用图并从中排除 function 您需要使用-Q选项:

     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.如果您需要从一份报告中排除 function 但不排除其他任何 function 您需要使用-p-q选项。

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编译它: 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:如果您需要打印平面配置文件,不包括函数func_afunc_c以及完整的调用图,您需要调用:

     $ 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:如果您需要打印不包括函数func_afunc_c的平面配置文件以及不包括func_b的调用图,则需要调用:

     $ 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] -----------------------------------------------

Unless I've misunderstood what you're asking...除非我误解了你在问什么...

gprof a.out --no-time=function_name gprof a.out --no-time=function_name

works for me.为我工作。

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

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