Debian Codegraph @

README.md

raw
1 # panicparse
2
3 Parses panic stack traces, densifies and deduplicates goroutines with similar
4 stack traces. Helps debugging crashes and deadlocks in heavily parallelized
5 process.
6
7 [![PkgGoDev](https://pkg.go.dev/badge/github.com/maruel/panicparse/v2/stack)](https://pkg.go.dev/github.com/maruel/panicparse/v2/stack)
8 [![codecov](https://codecov.io/gh/maruel/panicparse/branch/main/graph/badge.svg?token=izj1cLjUi3)](https://codecov.io/gh/maruel/panicparse)
9 [![go-recipes](https://raw.githubusercontent.com/nikolaydubina/go-recipes/main/badge.svg?raw=true)](https://github.com/nikolaydubina/go-recipes#-pretty-print-panic-messages)
10
11
12 panicparse helps make sense of Go crash dumps:
13
14 ![Screencast](https://raw.githubusercontent.com/wiki/maruel/panicparse/parse.gif "Screencast")
15
16
17 ## Features
18
19 * Race detector support, e.g. it can parse output produced by `go test -race`
20 * HTML export.
21 * Easy to use as an [HTTP Handler
22 middleware](https://pkg.go.dev/github.com/maruel/panicparse/v2/stack#example-package-HttpHandlerMiddleware).
23 * High performance parsing.
24 * [HTTP web server](https://pkg.go.dev/github.com/maruel/panicparse/v2/stack/webstack#SnapshotHandler)
25 that serves a very tight and swell snapshot of your goroutines, much more
26 readable than [net/http/pprof](https://pkg.go.dev/net/http/pprof).
27 * >50% more compact output than original stack dump yet more readable.
28 * Deduplicates redundant goroutine stacks. Useful for large server crashes.
29 * Arguments as pointer IDs instead of raw pointer values.
30 * Pushes stdlib-only stacks at the bottom to help focus on important code.
31 * Parses the source files if available to augment the output.
32 * Works on any platform supported by Go, including Windows, macOS, linux.
33 * Full go module support.
34 * Requires >=go1.17. Use v2.3.1 for older Go versions.
35
36
37 ## Installation
38
39 go install github.com/maruel/panicparse/v2/cmd/pp@latest
40
41
42 ## Usage
43
44 ### Piping a stack trace from another process
45
46 #### TL;DR
47
48 * Ubuntu (bash v4 or zsh): `|&`
49 * macOS, [install bash 4+](README.md#updating-bash-on-macos), then: `|&`
50 * Windows _or_ macOS with stock bash v3: `2>&1 |`
51 * [Fish](http://fishshell.com/) shell: `&|`
52
53
54 #### Longer version
55
56 `pp` streams its stdin to stdout as long as it doesn't detect any panic.
57 `panic()` and Go's native deadlock detector [print to
58 stderr](https://golang.org/src/runtime/panic1.go) via the native [`print()`
59 function](https://golang.org/pkg/builtin/#print).
60
61
62 **Bash v4** or **zsh**: `|&` tells the shell to redirect stderr to stdout,
63 it's an alias for `2>&1 |` ([bash
64 v4](https://www.gnu.org/software/bash/manual/bash.html#Pipelines),
65 [zsh](http://zsh.sourceforge.net/Doc/Release/Shell-Grammar.html#Simple-Commands-_0026-Pipelines)):
66
67 go test -v |&pp
68
69
70 **Windows or macOS native bash** [(which is
71 3.2.57)](http://meta.ath0.com/2012/02/05/apples-great-gpl-purge/): They don't
72 have this shortcut, so use the long form:
73
74 go test -v 2>&1 | pp
75
76
77 **Fish**: `&|` redirects stderr and stdout. It's an alias for `2>&1 |`
78 ([fish piping](https://fishshell.com/docs/current/language.html#piping)):
79
80 go test -v &| pp
81
82
83 **PowerShell**: [It has broken `2>&1` redirection](https://connect.microsoft.com/PowerShell/feedback/details/765551/in-powershell-v3-you-cant-redirect-stderr-to-stdout-without-generating-error-records). The workaround is to shell out to cmd.exe. :(
84
85
86 ### Investigate deadlock
87
88 On POSIX, use `Ctrl-\` to send SIGQUIT to your process, `pp` will ignore
89 the signal and will parse the stack trace.
90
91
92 ### Parsing from a file
93
94 To dump to a file then parse, pass the file path of a stack trace
95
96 go test 2> stack.txt
97 pp stack.txt
98
99
100 ## Tips
101
102 ### Disable inlining
103
104 The Go toolchain inlines functions when it can. This causes traces to be less
105 informative. Optimization also interfere with traces. You can use the following
106 to help diagnosing issues:
107
108 go install -gcflags '-N -l' path/to/foo
109 foo |& pp
110
111 or
112
113 go test -gcflags '-N -l' ./... |& pp
114
115
116 Run `go tool compile -help` to get the full list of valid values for -gcflags.
117
118
119 ### GOTRACEBACK
120
121 By default, [`GOTRACEBACK`](https://golang.org/pkg/runtime/) defaults to
122 `single`, which means that a panic will only return the current goroutine trace
123 alone. To get all goroutines trace and not just the crashing one, set the
124 environment variable:
125
126 export GOTRACEBACK=all
127
128 or `set GOTRACEBACK=all` on Windows. Probably worth to put it in your `.bashrc`.
129
130
131 ### Updating bash on macOS
132
133 Install bash v4+ on macOS via [homebrew](http://brew.sh) or
134 [macports](https://www.macports.org/). Your future self will appreciate having
135 done that.
136
137
138 ### If you have `/usr/bin/pp` installed
139
140 If you try `pp` for the first time and you get:
141
142 Creating tables and indexes...
143 Done.
144
145 and/or
146
147 /usr/bin/pp5.18: No input files specified
148
149 you may be running the _Perl PAR Packager_ instead of panicparse.
150
151 You have two choices, either you put `$GOPATH/bin` at the beginning of `$PATH`
152 or use long name `panicparse` with:
153
154 go install github.com/maruel/panicparse/v2@latest
155
156 then using `panicparse` instead of `pp`:
157
158 go test 2> panicparse
159
160 Hint: You may also use shell aliases
161
162 alias gp=panicparse
163 go test 2> gp
164
165 alias p=panicparse
166 go test 2> p
167
168
169 ### webstack in action
170
171 The
172 [webstack.SnapshotHandler](https://pkg.go.dev/github.com/maruel/panicparse/v2/stack/webstack#SnapshotHandler)
173 http.Handler enables glancing at at a snapshot of your process trivially:
174
175 ![Screencast](https://raw.githubusercontent.com/wiki/maruel/panicparse/panicparse_webstack.gif "Screencast")
176
177
178 ## Authors
179
180 `panicparse` was created with ❤️️ and passion by [Marc-Antoine
181 Ruel](https://github.com/maruel) and
182 [friends](https://github.com/maruel/panicparse/graphs/contributors).