cgcccompilationprofilinggprof

How to exclude a function from Gprof activity during running


Suppose i have function foo

void foo()
{
  //do something
}

Now this fn foo is now called by other function defined in other files. if gprof is enabled it would do profiling activity and subroutines for this function as well when called, which i want to avoid. Is this possible?

Please note i am not asking how to exclude the function from results. I want to avoid profiling activity by gprof which happens when fn/fns are called.


Solution

  • According to GCC doc you should be able to avoid instrumentation with the no_instrument_function function attribute:

    void __attribute__((no_instrument_function)) foo()
    {
      //do something
    }
    

    Alternatively you could also put the function (and any other functions that you don't want to be profiled) in a separate file and compile that file without -p or -pg to avoid instrumentation for that compilation unit.