IMP logo
IMP Manual  for IMP version 2.5.0
profiling.md
1 Profiling your code {#profiling}
2 ===================
3 
4 # Linux
5 
6 On linux you can use [gperftools](http://code.google.com/p/gperftools/?redir=1) for code profiling. The key bits are:
7 - install `gperftools` (available as a pre-built package on most platforms)
8 - make sure debugging symbols are being included in your build by, with `g++` or `clang++` adding `-g` to your `CMAKE_CXX_FLAGS`.
9 
10 then if you are using a program that used the IMP flags support
11 - you can add the flag `--cpu-profiling` to profile the whole program
12 
13 if not
14 
15 - either use environment variables to control profiling as in the web page above
16 - or add `-DCMAKE_EXE_LINKER_FLAGS=-ltcmalloc_and_profiler -DCMAKE_SHARED_LINKER_FLAGS=-ltcmalloc_and_profiler -DCMAKE_REQUIRED_FLAGS=-ltcmalloc_and_profiler` to your `cmake` invocation to add the required library to all compilations. This will activate control via IMP flags and classes. Note that the name of the library might be different on your system. More explanations here: http://google-perftools.googlecode.com/svn/trunk/doc/heap_checker.html
17 
18 To profile a specific piece of code use:
19 
20 `#include <IMP/benchmark/Profiler.h>`
21 
22 add a Profiler before the code you want to profile:
23 
24 `IMP::benchmark::Profiler pp("prof_out");`
25 
26 This will produce a prof_out file that can be viewed with pprof tool.
27 
28 For detection of memory leaks, run your program this way:
29 
30 `env HEAPCHECK=normal your_program_exe`
31 
32 it will output the leaks and also produce output file that can be viewed with pprof.
33 
34 # Mac
35 
36 On a Mac, you can use the `Instruments` program that is part of the developer tools. It is pretty straight forwards to use and can do cpu profiling, memory profile, leak checking etc. It is currently located in `/Applications/Xcode.app/Contents/Applications/Instruments.app/`.