The classes presented here are simply included in you project and compiled in. Blocks are instrumented manually with pre-processor macros that initialize and register timers. Timing is performed with QueryPerformanceCounter on Windows and gettimeofday on Linux/Mac, giving an approximate lower bound on the intervals that can be resolved of about 1 microsecond. If you need more resolution than this, you'll have to use something else. Statistics can then be dumped to any std::ostream, allowing you to print profiling statistics to a file, the console, log window or whatever. The only statistics collected are the call count for each block, average time per call and total elapse time in the block.
Here is an example of how to use them:
#include<iostream> // comment this out to turn off profiling // (and avoid its associated cost) #define USE_PROFILING #include"Profiler.h" int main( int argc, char **argv ){ PROFILER_START( main_timer ); // do stuff here PROFILER_END( main_timer ); ProfileManager::Get()->PrintStatistics( std::cout ); return 0; }
Here are the source files. You can use them under a BSD license. If you find them useful I'd appreciate if you let me know.
Profiler.h
Profiler.cpp
No comments:
Post a Comment