0

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.

user877329
  • 6,717
  • 8
  • 46
  • 88
  • Even if gprof allowed that, it would not work, because gprof does not sample in waiting threads. OTOH, you can run the whole thing under GDB and get stack samples manually using Ctrl-C and *bt*. That is [*this technique*](http://stackoverflow.com/a/378024/23771). The fraction of samples showing the main thread waiting for workers is the time fraction you want. To get the number of calls, you can put a counter in the code. – Mike Dunlavey Jul 19 '15 at 17:54

1 Answers1

0

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.

user877329
  • 6,717
  • 8
  • 46
  • 88