From 76eecd52bc5789f35591b710e161e30578bd218e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Felix=20Geisend=C3=B6rfer?= Date: Wed, 14 Apr 2021 09:12:36 +0200 Subject: [PATCH] Better pprof decoding tutorial --- pprof.md | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/pprof.md b/pprof.md index 1a04012..16a19e3 100644 --- a/pprof.md +++ b/pprof.md @@ -32,11 +32,27 @@ The code for generating pprof output in Go can be found in: [runtime/pprof/proto ### Decoding +Below are a few tools for decoding pprof files into human readable text output. They are ordered by the complexity of their output format, with tools showing simplified output being listed first: + +#### Using `pprofutils` + +[pprofutils](https://github.com/felixge/pprofutils) is a small tool I build for converting between pprof files and Brendan Gregg's [folded text](https://github.com/brendangregg/FlameGraph#2-fold-stacks) format. You can use it like this: + +``` +$ pprof2text < examples/cpu/pprof.samples.cpu.001.pb.gz + +golang.org/x/sync/errgroup.(*Group).Go.func1;main.run.func2;main.computeSum 19 +golang.org/x/sync/errgroup.(*Group).Go.func1;main.run.func2;main.computeSum;runtime.asyncPreempt 5 +runtime.mcall;runtime.gopreempt_m;runtime.goschedImpl;runtime.schedule;runtime.findrunnable;runtime.stopm;runtime.notesleep;runtime.semasleep;runtime.pthread_cond_wait 1 +runtime.mcall;runtime.park_m;runtime.schedule;runtime.findrunnable;runtime.checkTimers;runtime.nanotime;runtime.nanotime1 1 +runtime.mcall;runtime.park_m;runtime.schedule;runtime.findrunnable;runtime.stopm;runtime.notesleep;runtime.semasleep;runtime.pthread_cond_wait 2 +runtime.mcall;runtime.park_m;runtime.resetForSleep;runtime.resettimer;runtime.modtimer;runtime.wakeNetPoller;runtime.netpollBreak;runtime.write;runtime.write1 7 +runtime.mstart;runtime.mstart1;runtime.sysmon;runtime.usleep 3 +``` + #### Using `go tool pprof` -The easiest way to decode a pprof file and see its contents is to use `go tool pprof -raw`. The output is formatted for human readability, so arguabiliy it's not as `-raw` as the `protoc` output shown later on. - -Let's have a look at the [examples/cpu/pprof.samples.cpu.001.pb.gz](./examples/cpu/pprof.samples.cpu.001.pb.gz) CPU profile included in this repository: +`pprof` itself has an output mode called `-raw` that will show you the contents of a pprof file. However, it should be noted that this is not as `-raw` as it gets, checkout `protoc` below for that: ``` $ go tool pprof -raw examples/cpu/pprof.samples.cpu.001.pb.gz