DbgProfiler - Example:
The code for the following example can be found in "./tests/linux/example.cpp" or "./tests/win32/example.cpp"
void foo(int i)
1. Step:Add PROFILE_BEGIN and PROFILE_END macros around the code blocks you want to measure. The name in brackets must be a valid and unique C/C++ identifier otherwise you will get compile errors. Moreover, make sure that each PROFILE_BEGIN has its corresponding PROFILE_END call. In the below example an additional PROFILE_END(bar) had to be added to the if-statement block to make sure, that the PROFILE_BEGIN(bar) has its counterpart in any case of the control flow.
void foo(int i)
2. StepCall dbgProfiler.writeReport() just before your application is about to terminate. In the parameter you must specify the directory where to write the report with the profiling results. The directory must exist already.
3. StepAdd the DbgProfiler.cpp source file to your project, compile and link with all compiler flags and optimizations you desire and run your application just as normal.
4. StepAnalyze the profiling report which is written to the specified directory after your application has terminated.
HERE you can find the report for the example above. Below it will be revised in detail.
The profiling report:For each PROFILE_BEGIN - PROFILE_END block a separate HTML file is generated. Each file consists of three sections: statistics, callees and callers. If you have the Graphviz dot tool installed the call graph is shown at the top of each HTML file. The following output was generated for the block foo of the above example.
Statistics for: 'foo'
Here you can see that the block foo was called 10 times. Overall 2,036 seconds where spend in this block. Hence the average time per call is 203 milliseconds.
foo has called dummy and bar. The block dummy was called 10 times from foo and with 1021.3 milliseconds 50.2% of foos execution time was spend there. bar also was called 10 times and with 1015.1 milliseconds 49.8% of foos time was spend in this block. The block bar itself has called the blocks dummy and bar recursively, ...
Callers:The following Callers-table was generated for the block dummy:
Last modified: 02 Dez. 2006 (Copyright 2006 by Erik Einhorn)