Warning, /acts/docs/pages/contributing/profiling.md is written in an unsupported language. File is not indexed.
0001 @page howto_profiling Performance Profiling
0002 @brief Guide on using `gperftools` and `pprof` for profiling ACTS
0003
0004 Software profiling allows you to inspect the performance of a piece of software, seeing where the bottlenecks are and how they can be improved.
0005 gperftools is a software profiling package. It contains a CPU profiler, thread-caching malloc library, memory leak detection tool, memory allocation profiler and pprof (discussed later). More information about gperftools and its components can be found on the project's [GitHub](https://github.com/gperftools/gperftools) and [documentation page](https://gperftools.github.io/gperftools/).
0006
0007 ## Install gperftools
0008
0009 It is strongly recommended to install [libunwind](https://github.com/libunwind/libunwind) before trying to configure or install gperftools.
0010
0011 ### Ubuntu
0012
0013 If you're using Ubuntu you can use the following command to install gperftools:
0014
0015 ```
0016 apt install google-perftools libgoogle-perftools-dev
0017 ```
0018
0019 ### Other Systems
0020
0021 Alternatively, you can use the following commands to install it:
0022
0023 ```console
0024 git clone https://github.com/gperftools/gperftools
0025 cd gperftools
0026 git tag -l # checkout the latest release version
0027 git checkout <gperftools-X.x>
0028 ./autogen.sh
0029 ./configure --prefix=<your/desired/install/dir>
0030 make
0031 make install
0032 ```
0033
0034 This will install gperftools in `your/desired/install/dir/lib` which is the path you should use when specifying where gperftools is, if necessary.
0035
0036 If you wish to install gperftools to a directory that is not one of the standard directories for libraries and therefore not findable by the `-l` compiler flag, you will need to specify the path to it with the `GPERF_INSTALL_DIR` option at build time.
0037 Further information about installing gperftools is [here](https://github.com/gperftools/gperftools/blob/master/INSTALL).
0038
0039 ## pprof
0040
0041 pprof is a tool for visualising and analysing profiling data.
0042 An older version of pprof comes bundled with gperftools but using the newer Go version comes with several benefits: nicer looking graphs and additional options that make looking through specific sections of a program easier being among them.
0043
0044 ### Install Go pprof (Optional)
0045
0046 First, you must install Go. Instructions to do so are available [here](https://go.dev/doc/install).
0047 Optionally, you can install [Graphviz](https://www.graphviz.org/download/) to produce visualisations of profiles.
0048
0049 Then, run the following command to install pprof itself:
0050
0051 ```console
0052 go install github.com/google/pprof@latest
0053 ```
0054
0055 ## Link gperftools Libraries When Compiling
0056
0057 The library needed to run the CPU profiler should be linked into the ACTS project using the following build option:
0058
0059 ```
0060 -DACTS_ENABLE_CPU_PROFILING=ON
0061 ```
0062
0063 Similarly, to enable the memory profiler the following build option should be used:
0064
0065 ```
0066 -DACTS_ENABLE_MEMORY_PROFILING=ON
0067 ```
0068
0069 ## Alternative to Recompiling
0070
0071 Alternatively, you can avoid rebuilding the project by pointing the `LD_PRELOAD` environment variable to the profiler library for CPU profiling:
0072
0073 ```
0074 LD_PRELOAD="<path/to/libprofiler.so>" <other_options> <path/to/binary> <binary_flags>
0075 ```
0076
0077 You can do the same thing with the tcmalloc library for memory profiling:
0078
0079 ```
0080 LD_PRELOAD="<path/to/libtcmalloc.so>" <other_options> <path/to/binary> <binary_flags>
0081 ```
0082
0083 Using the `LD_PRELOAD` method is not recommended by the developers of gperftools so using the build options is preferable. Both CPU and memory profiling can be enabled at the same time but note that turning on memory profiling (or the heap checker) will affect performance.
0084 Specify multiple libraries to load with `LD_PRELOAD` using a space-separated list e.g.
0085
0086 ```
0087 LD_PRELOAD="<path/to/first/library> <path/to/second/library>"
0088 ```
0089
0090 Note that these steps don't turn on profiling, they only enable it to work. The following section details how to turn it on.
0091
0092 ## Produce a CPU Profile
0093
0094 To turn on CPU profiling when running an executable define the `CPUPROFILE` environment variable when executing the program:
0095
0096 ```
0097 CPUPROFILE=<path/to/profile> <path/to/binary> [binary args]
0098 ```
0099
0100 This variable specifies where the profile will be written to.
0101 There are additional environment variables that modify the behaviour of the profiler.
0102 [Would you like to know more](https://github.com/gperftools/gperftools)?
0103
0104 ## Produce a Memory Profile
0105
0106 To turn on memory profiling use the following command:
0107
0108 ```
0109 HEAPPROFILE=<path/to/profile> <path/to/binary> [binary args]
0110 ```
0111
0112 ## Run the Heap Checker
0113
0114 To run the heap checker for checking for memory leaks run the following command:
0115
0116 ```
0117 PPROF_PATH=<path/to/pprof> HEAPCHECK=normal <path/to/binary> [binary args]
0118 ```
0119
0120 The CPU profiler, memory profiler and heap checker can be used in tandem.
0121
0122 ## Using pprof
0123
0124 ### View Profile as a Graph
0125
0126 A graphical representation of a profile can be produced using:
0127
0128 ```
0129 pprof -pdf <path/to/binary> <path/to/profile> > <path/to/pdf>
0130 ```
0131
0132 Where `path/to/binary` is the binary is used to produce the profile in the first place.
0133 Other output formats are available.
0134
0135 The following opens the graph in your web browser:
0136
0137 ```
0138 pprof -web <path/to/binary> <path/to/profile>
0139 ```
0140
0141 ### Interactive Mode
0142
0143 To launch pprof in interactive mode use the following command:
0144
0145 ```
0146 pprof <path/to/binary> <path/to/profile>
0147 ```
0148
0149 The following command will display the top x entries by the current sorting criteria:
0150
0151 ```
0152 top <number>
0153 ```
0154
0155 To view the statistics of a function line by line use:
0156
0157 ```
0158 list <nameOfFunction>
0159 ```
0160
0161 Various options can be specified to filter, sort and set the granularity of entries.
0162 There are also a number of other commands available.
0163 Read more about pprof [here](https://github.com/google/pprof).