165 | | On debian-based systems, [https://github.com/gperftools/gperftools gperftools] are packaged under the google-perftools package. For graphical output you also need graphviz installed: |
166 | | |
167 | | ```sudo apt-get install google-perftools graphviz``` |
168 | | |
169 | | On arch-based systems, the package is called gperftools. |
170 | | |
171 | | To start profiling, run |
172 | | |
173 | | ```LD_PRELOAD=/usr/lib/libprofiler.so CPUPROFILE=/tmp/0ad.prof 0ad``` |
174 | | |
175 | | LD_PRELOAD is used to preload the profiler's library, CPUPROFILE determines the location of the profiler's output, and in the above example, 0ad is the name of the binary to be executed. The path to the libprofiler library may differ distribution by distribution - I have also seen it under /usr/lib/libprofiler.so.0. |
176 | | |
177 | | Do whatever you want to profile in 0ad. When finished, close 0ad. |
178 | | |
179 | | At this point, /tmp/0ad.prof contains the CPU profile information. To view it graphically, run |
180 | | |
181 | | ```google-pprof --web /usr/bin/0ad /tmp/0ad.prof``` |
182 | | |
183 | | (Note the absolute path to 0ad must be used here.) |
184 | | |
185 | | On arch-based systems, use `pprof` instead of `google-pprof`. |
186 | | |
187 | | After several minutes, your default web browser will open and display the graphical profile in the svg format. |
188 | | |
189 | | It will look similar to this:[[BR]] |
| 165 | On debian-based systems, [https://github.com/gperftools/gperftools gperftools] is packaged under `google-perftools`. For graphical output you also need to install `graphviz`. |
| 166 | |
| 167 | {{{ |
| 168 | sudo apt-get install google-perftools graphviz |
| 169 | }}} |
| 170 | |
| 171 | On arch-based systems, the package is called `gperftools`. |
| 172 | |
| 173 | To start profiling, run: |
| 174 | |
| 175 | {{{ |
| 176 | LD_PRELOAD=/usr/lib/libprofiler.so CPUPROFILE=/tmp/0ad.prof 0ad |
| 177 | }}} |
| 178 | |
| 179 | `LD_PRELOAD` pre-loads the profiler library, `CPUPROFILE` determines the location of the profiler output. `0ad` is the name of the binary file to be executed. The path to the `libprofiler` library may vary depending on the distribution, the path could also be `/usr/lib/libprofiler.so.0`. When you are finished profiling, close `0ad`. |
| 180 | |
| 181 | At this point, `/tmp/0ad.prof` contains the CPU profile information. To display it graphically, run the following command and ensure that you use the absolute path to `0ad`. On arch-based systems, use `pprof` rather than `google-pprof`. |
| 182 | |
| 183 | {{{ |
| 184 | google-pprof --web /usr/bin/0ad /tmp/0ad.prof |
| 185 | }}} |
| 186 | |
| 187 | After a couple of minutes, your default web browser opens and displays the graphical profile in a svg format. |
| 188 | |
| 189 | It is going to look similar to this: |
| 190 | |