-
Notifications
You must be signed in to change notification settings - Fork 38
Profiling Code
Official doc with information about how to interpret the output: http://google-perftools.googlecode.com/svn/trunk/doc/cpuprofile.html
Install google performance tools: Ubuntu
sudo apt-get install google-perftools
OSX
brew install google-perftools
Then when you run your code, you need to define CPUPROFILE and LD_PRELOAD
Ubuntu
CPUPROFILE=/tmp/my_executable.prof LD_PRELOAD=/usr/lib/libprofiler.so.0 ./my_executable
OSX
CPUPROFILE=/tmp/my_executable.prof LD_PRELOAD=/usr/local/Cellar/google-perftools/2.1/lib/libprofiler.dylib ./my_executable
Finally, generate the call-graph pdf:
google-pprof --pdf my_executable /tmp/my_executable.prof > my_executable_profiling.pdf
The call graph then looks like:
Other useful variables:
CPUPROFILE_FREQUENCY=x
where the default x = 100 (value is in Hz).
// Pull in the sm_timing definitions
#include <sm_timing/Timer.h>
//Enable timing.
typedef sm::timing::Timer Timer;
//Disable timing by switching the typedef.
typedef sm::timing::DummyTimer Timer;
After adding this definition you can now time specific code segments by adding a timer call:
Timer expensive_operation_timer("ExpensiveOperation");
DoExpensiveOperation();
expensive_operation_timer.Stop();
When you want to print out the timing information you call:
sm::timing::Timing::Print(std::cout);
//or similarly
LOG(INFO) << sm::timing::Timing::Print();
You will get a table containing the following information:
SM Timing
---------
//a b c d e f g
ExpensiveOperation 5 00:00:09:00.12 (00:00:08:56.67 +- 00:00:00.15) [00:00:08.00 00:00:09.000]
Where the columns denote:
a) Name of the timer.
b) Number of calls.
c) Overall time of all calls.
d) Mean time of a call.
e) Std-dev of the times.
f) Min time of a call.
g) Max time of a call.