Assuming gcc has something like MSVC files and line macros that expand to the current file and current line, you can create your own pseudo-profiling function. Put this in the header:
void MyPseudoProfileLog(const char* file, int line, int* count); #define MY_PSEUDO_PROFILE_LOG(file, line) { static int count = 0; MyPseudoProfileLog(file, line, &count); }
This applies to the cpp file (if you put it in the header, you will get several copies of the static variable, one for each cpp file in which you include the header):
void MyPseudoProfileLog(const char* file, int line, int* count) { static FILE* f = NULL; const int max_count = 1000; if (++(*count) == max_count) { *count = 0; if (!f) f = fopen("/tmp/my_pseudo_profile_log.log"); fprintf(f, "file=\"%s\", line=%d was passed %d times\n", file, line, max_count); fflush(f); } }
Then you can paste
MY_PSEUDO_PROFILE_LOG(__FILE__, __LINE__);
in different places in your code to find out how often they are called. Keep in mind that this is not thread safe, so use only in the main thread.
source share