Search code examples
multithreadinggccgprof

Disable profiling on certain function and all its descendants


Is it possible preferably with a function attribute to disable profiling on a certain function? I want to do this because I need to profile the time spent in multithreaded parts of a program. I do not care about the details of the particular threads, just the amount of time spent in the whole batch.

Timegraph:

                  +--------------------------------+
                  +--------------------------------+
---Main thread----+ Main thread waits for workers  +----Main thread continues-----
                  +--------------------------------+
                  +--------------------------------+
                 t0                                t1

I want the profile output to correctly measure t1-t0, and the number of calls to the batch, but mcount is not threadsafe, so the stuff that runs in parallel must be excluded somehow.

Valgrind is no go since physical bus speed is main concern.


Solution

  • I solved it with }, the most powerful C++ feature. In the top of the scope, add an object that store current time. Let its destructor read the time again and take the difference. Write output to a file.