Open aalexand opened 6 years ago
To accomplish this right now, one has to:
go get github.com/uber/go-torch
go-torch -b ./profile.pprof --binaryname ./binary
. (make sure FlameGraph is on your PATH)go-torch is deprecated, use pprof instead after go1.11. We can browse web ui as follow:
server nginx:
server_name pprof.graph.com
location / {
proxy_pass http://127.0.0.1:8031
}
local host:
your.server.ip pprof.graph.com
start pprof:
go tool pprof -http=:8031 "http://your.server.ip:port/debug/pprof/profile"
access local browser:
pprof.graph.com
I think the easiest way to implement this feature is to use scripts in https://github.com/brendangregg/FlameGraph and have a standalone command to indicate this is what the user wants. Is "-flamegraph" a good candidate due to the internal conflicting flag "-flame"?
We should not bring in dependency on external scripts that wouldn't be a part of the executable. pprof is a part of Go runtime distribution, so everything should be contained within the pprof executable, either in the form of Go or JS code (like we do for the web UI).
We currently use https://github.com/spiermar/d3-flame-graph as our flame graph; it would be ideal to continue to use that code.
I'm not sure of the licenses for https://github.com/brendangregg/FlameGraph. And, as aalexand noted, pprof is a part of Go, so we need to be very careful with dependencies.
ref https://github.com/spiermar/d3-flame-graph/issues/33 (but nobody ever replied there)
How about exporting self-contained HTML? That sounds easier with d3-flame-graph than interactive SVG... Would that satisfy the same needs?
The only reason I want SVG is to be able to send/attach a single file that co-workers can open and zoom into.
<img>
somewhere, which misses out on the zooming by JavaScript :sparkles:, so I have to explicity recommend people to only open it in a browser (because I want them to explore it, not just take my conclusions).Huh, saving the HTML from the browser, in simple "just HTML" mode already works! :tada:
As does downloading it with curl
:
# The redirect avoids it being suspended for reading from terminal.
go tool pprof --http :9000 --no_browser ./CMD PROFILE.heap < /dev/null &
sleep 1
for sample in {alloc,inuse}_{objects,space}; do
curl "http://localhost:9000/ui/?si=$sample" -o graph-$sample.html
curl "http://localhost:9000/ui/flamegraph?si=$sample" -o flamegraph-$sample.html
# add `source` to pages loop for annotated source view, but it's _really_ slow!
for page in top peek disasm; do
time curl "http://localhost:9000/ui/$page?si=$sample" -o $page-$sample.html
done
done
kill $!
This works because data is not served in separate requests, it's simply inlined into the HTML: https://github.com/google/pprof/blob/427632fa3b1c4f7ee2ec76e79aa1f7dc5bb25e28/internal/driver/webhtml.go#L1324 (and CSS and JS are inlined too).
-html
flag??h=...
appended.I think we shouldn't bake in a requirement that the -http
mode generates a single HTML page. This may easily change in the future so this seems too fragile of an assumption.
Some prior art: @felixge's https://github.com/felixge/pprofutils#folded can generate "Folded Stacks" format from pprof for feeding into FlameGraph toolkit.
My way which I used to send FlameGraph file to my colleagues.
show collected data in a browser
go tool pprof -http :8081 filename.pb.gz
download html page with flamegraph as a file with all data
wget -O flamegraph.htm http://localhost:8081/ui/flamegraph
pprof currently supports flame graph visualization in the HTTP server mode. Sometimes it is desired to generate the flame graph visualization as a persistent report, likely as an SVG file.