I would like to measure time (or occurences) of very specific parts in a C code (they may be limited to a few instructions in some functions). One purpose is to track local performance improvements or regressions over several code revisions.
I know I can define macros for that purpose. But is there any tool which already does that in an even less intrusive way? Using annotations (#pragma) would be perfect:
void func_to_profile()
{
/* Some instructions */
...
#pragma profile foo start
/* A part of the code to track */
...
#pragma profile foo stop
/* More instructions */
...
#pragma profile bar start
/* Another part to measure */
...
#pragma profile bar stop
}
Ideally, at the end of the run the tool would display the cumulated elasped times per subsections. For instance:
-- [foo] cumulated time: 42s
-- [bar] cumulated time: 7s
Is there any existing tool which already does that or do I have no choice but develop my own GCC plugin?