IMP logo
IMP Manual  for IMP version 2.16.0
profiling.md
1 Profiling your code {#profiling}
2 ===================
3 
4 See also the [profiling tutorial](https://integrativemodeling.org/tutorials/profiling/)
5 for a walkthrough of profiling a simple %IMP application.
6 
7 # Linux
8 
9 On linux you can use [gperftools](https://github.com/gperftools/gperftools)
10 - install `gperftools` (available as a pre-built package on most platforms)
11 - make sure debugging symbols are being included in your build by, with `g++` or `clang++` adding `-g` to your `CMAKE_CXX_FLAGS`.
12 
13 then if you are using a program that used the IMP flags support
14 - you can add the flag `--cpu-profiling` to profile the whole program
15 
16 if not
17 
18 - either use environment variables to control profiling as in the web page above
19 - 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. See the [gperftool docs](https://github.com/gperftools/gperftools/blob/master/README) for more details.
20 
21 To profile a specific piece of code use:
22 
23 `#include <IMP/benchmark/Profiler.h>`
24 
25 add a Profiler before the code you want to profile:
26 
27 `IMP::benchmark::Profiler pp("prof_out");`
28 
29 This will produce a prof_out file that can be viewed with pprof tool.
30 
31 For detection of memory leaks, run your program this way:
32 
33 `env HEAPCHECK=normal your_program_exe`
34 
35 it will output the leaks and also produce output file that can be viewed with pprof.
36 
37 # Mac
38 
39 On a Mac, you can use the `Instruments` program that is part of Xcode.
40 It is pretty straightforward to use and can do CPU profiling, memory profiling,
41 leak checking etc. It is currently located in `/Applications/Xcode.app/Contents/Applications/Instruments.app/`.