|
1 | | -# Pprof |
| 1 | +--- |
| 2 | +layout: default |
| 3 | +title: Pprof |
| 4 | +permalink: /testing-and-debugging/pprof |
| 5 | +--- |
2 | 6 |
|
3 | | -There is a built pprof server to faciliate profiling the program. |
| 7 | +## Pprof |
| 8 | + |
| 9 | +There is a built-in pprof server to faciliate profiling the program. |
| 10 | +You can enable it with the flag `--pprofserver` or by modifying the TOML configuration file. |
4 | 11 |
|
5 | 12 | Note it does not affect performance unless the server is queried. |
6 | 13 |
|
7 | 14 | We assume Gossamer runs on `localhost` and the Pprof server is listening |
8 | | -on the default `6060` port. |
| 15 | +on the default `6060` port. You can configure the Pprof server listening address with the pprof TOML key `listening-address` or the flag `--pprofaddress`. |
9 | 16 |
|
10 | 17 | You need to have [Go](https://golang.org/dl/) installed to profile the program. |
11 | 18 |
|
| 19 | +### Browser |
| 20 | + |
12 | 21 | The easiest way to visualize profiling data is through your browser. |
13 | 22 |
|
14 | | -The following commands are available and will show the result at [http://localhost:8000](http://localhost:8000): |
| 23 | +For example, the following commands will show interactive results at [http://localhost:8000](http://localhost:8000): |
15 | 24 |
|
16 | 25 | ```sh |
17 | 26 | # Check the heap |
18 | 27 | go tool pprof -http=localhost:8000 http://localhost:6060/debug/pprof/heap |
| 28 | +# Check the CPU time spent for 10 seconds |
| 29 | +go tool pprof -http=localhost:8000 http://localhost:6060/debug/pprof/profile?seconds=10 |
19 | 30 | ``` |
| 31 | + |
| 32 | +### Compare heaps |
| 33 | + |
| 34 | +You can compare heaps with Go's pprof, this is especially useful to find memory leaks. |
| 35 | + |
| 36 | +1. Download the first heap profile `wget -qO heap.1.out http://localhost:6060/debug/pprof/heap` |
| 37 | +1. Download the second heap profile `wget -qO heap.2.out http://localhost:6060/debug/pprof/heap` |
| 38 | +1. Compare the second heap profile with the first one using `go tool pprof -base ./heap.1.out heap.2.out` |
| 39 | + |
| 40 | +### More routes |
| 41 | + |
| 42 | +More routes are available in the HTTP pprof server. You can also list them at [http://localhost:6060/debug/pprof/](http://localhost:6060/debug/pprof/). |
| 43 | +Notable ones are written below: |
| 44 | + |
| 45 | +#### Goroutine blocking profile |
| 46 | + |
| 47 | +The route `/debug/pprof/block` is available but requires to set the block profile rate, using either the toml value `block-rate` or the flag `--pprofblockrate`. |
| 48 | + |
| 49 | +#### Mutex contention profile |
| 50 | + |
| 51 | +The route `/debug/pprof/mutex` is available but requires to set the mutex profile rate, using either the toml value `mutex-rate` or the flag `--pprofmutexrate`. |
| 52 | + |
| 53 | +#### Other routes |
| 54 | + |
| 55 | +The other routes are listed below, if you need them: |
| 56 | + |
| 57 | +- `/debug/pprof/cmdline` |
| 58 | +- `/debug/pprof/symbol` |
| 59 | +- `/debug/pprof/trace` |
| 60 | +- `/debug/pprof/goroutine` |
| 61 | +- `/debug/pprof/threadcreate` |
0 commit comments