Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support flame graph as an output format #401

Open
aalexand opened this issue Jul 17, 2018 · 11 comments
Open

Support flame graph as an output format #401

aalexand opened this issue Jul 17, 2018 · 11 comments
Labels
Priority: p2 Buganizer priority - P2 type: feat Buganizer type - Feature Request

Comments

@aalexand
Copy link
Collaborator

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.

@aalexand aalexand changed the title Support flame graph as SVG output format Support flame graph as an output format Jul 17, 2018
@ShaneHarvey
Copy link

To accomplish this right now, one has to:

  1. Install go-torch: go get github.com/uber/go-torch
  2. Install brendangregg/FlameGraph
  3. Finally, generate the svg: go-torch -b ./profile.pprof --binaryname ./binary. (make sure FlameGraph is on your PATH)

@itczl22
Copy link

itczl22 commented Jan 14, 2019

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

@wyk9787
Copy link
Contributor

wyk9787 commented Apr 7, 2020

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"?

@aalexand
Copy link
Collaborator Author

aalexand commented Apr 7, 2020

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).

@nolanmar511
Copy link
Contributor

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.

@cben
Copy link

cben commented Jun 26, 2020

ref spiermar/d3-flame-graph#33 (but nobody ever replied there)

@cben
Copy link

cben commented Dec 6, 2020

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.

  • a minor benefit of .html over .svg: it's easy to open .svg in an image viewer, or to embed it as <img> somewhere, which misses out on the zooming by JavaScript ✨, 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).

@cben
Copy link

cben commented Dec 6, 2020

Huh, saving the HTML from the browser, in simple "just HTML" mode already works! 🎉
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:

var data = {{.FlameGraph}};

(and CSS and JS are inlined too).

  • So, anybody else wants a -html flag?
  • Search already works too!
  • Sorting by clicking columns already works!
  • "Refine" menu doesn't work and probably can't as it requires backend re-computation. E.g. "Hide" reloads the page with ?h=... appended.
  • The links in "View" & "Sample" menus do not work.
    • Strawman: Just drop the menu (or most of it) in export?
    • For heap, would be neat to embed all 4 sample types into one HTML, and avoid reloads when switching from menu.
    • Similar strategy could allow all visualizations to be packed into 1 HTML? Would need deeper changes... And including everything is too big & slow for most needs.

@aalexand
Copy link
Collaborator Author

aalexand commented Dec 7, 2020

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.

@mhansen
Copy link
Contributor

mhansen commented Oct 7, 2021

Some prior art: @felixge's https://github.com/felixge/pprofutils#folded can generate "Folded Stacks" format from pprof for feeding into FlameGraph toolkit.

@fubss
Copy link

fubss commented Apr 5, 2022

My way which I used to send FlameGraph file to my colleagues.

  1. show collected data in a browser
    go tool pprof -http :8081 filename.pb.gz

  2. download html page with flamegraph as a file with all data
    wget -O flamegraph.htm http://localhost:8081/ui/flamegraph

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Priority: p2 Buganizer priority - P2 type: feat Buganizer type - Feature Request
Projects
None yet
Development

No branches or pull requests

9 participants