|
| 1 | +# Profiling guide |
| 2 | + |
| 3 | +1. Run the agent with the `PROFILE_PORT` variable set to e.g. 6060. |
| 4 | + - If you are executing the agent from the Openshift NetObserv Operator, you can do it by |
| 5 | + adding the following section to your `ebpf` spec: |
| 6 | + ```yaml |
| 7 | + apiVersion: flows.netobserv.io/v1alpha1 |
| 8 | + kind: FlowCollector |
| 9 | + metadata: |
| 10 | + name: cluster |
| 11 | + spec: |
| 12 | + ebpf: |
| 13 | + env: |
| 14 | + PROFILE_PORT: "6060" |
| 15 | + ``` |
| 16 | +
|
| 17 | +2. If you are running OpenShift/Kubernetes, port-forward the pod that you want to profile. |
| 18 | +
|
| 19 | + ``` |
| 20 | + oc -n netobserv-privileged port-forward netobserv-ebpf-agent-4kt9d 6060 |
| 21 | + ``` |
| 22 | + |
| 23 | +3. Download the required profiles: |
| 24 | + |
| 25 | + ``` |
| 26 | + curl -o <profile> http://localhost:6060/debug/pprof/<profile> |
| 27 | + ``` |
| 28 | + |
| 29 | + Where `<profile>` can be: |
| 30 | + |
| 31 | +* `allocs`: A sampling of all past memory allocations |
| 32 | +* `block`: Stack traces that led to blocking on synchronization primitives |
| 33 | +* `cmdline`: The command line invocation of the current program |
| 34 | +* `goroutine`: Stack traces of all current goroutines |
| 35 | +* `heap`: A sampling of memory allocations of live objects. |
| 36 | + * You can specify the `gc` GET parameter to run GC before taking the heap sample. |
| 37 | +* `mutex`: Stack traces of holders of contended mutexes |
| 38 | +* `profile`: CPU profile. |
| 39 | + * You can specify the `duration` in the seconds GET parameter. |
| 40 | +* `threadcreate`: Stack traces that led to the creation of new OS threads |
| 41 | +* `trace`: A trace of execution of the current program. |
| 42 | + * You can specify the `duration` in the seconds GET parameter. |
| 43 | + |
| 44 | +Example: |
| 45 | + |
| 46 | +``` |
| 47 | +curl "http://localhost:6060/debug/pprof/trace?duration=20" -o trace20s |
| 48 | +curl "http://localhost:6060/debug/pprof/profile?duration=20" -o profile20s |
| 49 | +curl "http://localhost:6060/debug/pprof/heap?gc" -o heap |
| 50 | +curl "http://localhost:6060/debug/pprof/allocs" -o allocs |
| 51 | +curl "http://localhost:6060/debug/pprof/goroutine" -o goroutine |
| 52 | +``` |
| 53 | + |
| 54 | +4. Use `go tool pprof` to dig into the profiles (`go tool trace` for the `trace` profile) |
0 commit comments