| 49 | |
| 50 | == Profiling with google-perf or pprof |
| 51 | |
| 52 | On debian-based systems the tools are packaged under the google-perftools package. For graphical output you also need graphviz installed: |
| 53 | |
| 54 | ```sudo apt-get install google-perftools graphviz``` |
| 55 | |
| 56 | On arch-based systems, the package is called gperftools. |
| 57 | |
| 58 | To start profiling, run |
| 59 | |
| 60 | ```LD_PRELOAD=/usr/lib/libprofiler.so CPUPROFILE=/tmp/0ad.prof 0ad``` |
| 61 | |
| 62 | 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. |
| 63 | |
| 64 | Do whatever you want to profile in 0ad. When finished, close 0ad. |
| 65 | |
| 66 | At this point, /tmp/0ad.prof contains the CPU profile information. To view it graphically, run |
| 67 | |
| 68 | ```google-pprof --web /usr/bin/0ad /tmp/0ad.prof``` |
| 69 | |
| 70 | (Note the absolute path to 0ad must be used here.) T |
| 71 | |
| 72 | On arch-based systems, use `pprof` instead of `google-pprof`. |
| 73 | |
| 74 | After several minutes, your default web browser will open and display the graphical profile in the svg format. |