Exclusion of a function from gprof results

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 the percentage time spent by each function at runtime. I read the -E option in one place.

However, I use gprof -E function_to_be_exluded my_program_name , but nothing happens. The manual says that it has depreciated, and symspecs should be used instead . However, I spent half an hour trying to figure out how to achieve this with symspecs , but no luck. Anyone can help me with this.

+6
source share
3 answers

Similarly, gprof -e -E is deprecated and replaced by the use of newer relevant options with an 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. eg gprof --no-time=name_of_function_you_dont_want_to_profile. 

Use this with your other gprof options (-E -e is definitely excluded)

+4
source

According to the person:

  • to display a flat profile and exclude it, use the -P option:

     gprof main gmon.out -Pfunction_name 
  • To display the call schedule and the function of exclusion from it, you need to use the -Q option:

     gprof main gmon.out -Qfunction_name 

These parameters can be repeated and used at the same time:

 gprof main gmon.out -Pfunction_name -Qfunction_name -Qother_function_name 

If you need to exclude a function from one report, but not exclude any function from another, you need to use the -P or -Q options.

Example:

Create a 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 

Profile reporting:

  • If you only need a flat print profile, you need to 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 a flat print profile, excluding the func_a and func_c , and a full call schedule, you need to 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 a flat print profile, excluding the func_a and func_c , and a call graph, excluding func_b , you need to 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] ----------------------------------------------- 
+3
source

If I do not understand what you are asking ...

gprof a.out --no-time = function_name

works for me.

+2
source

Source: https://habr.com/ru/post/892308/


All Articles