jlfwong / speedscope

🔬 A fast, interactive web-based viewer for performance profiles.
https://www.speedscope.app
MIT License
5.38k stars 236 forks source link

Format Support: concatenated output from many calls to jstack #173

Open JensRantil opened 5 years ago

JensRantil commented 5 years ago

Poor man's profiling of a JVM:

$ for i in `seq 1 300`;do jstack $(pgrep java) > $i.jstack;sleep 1;done;zip profile.zip *.jstack;rm *.jstack

...and then uploading profile.zip. I'm tired of opening up traffic for profiling to production and/or building lots of tooling around it. jstack (and shell) is always availalable.

jlfwong commented 5 years ago

Hi @JensRantil!

Thanks for the idea! speedscope doesn't have any support for directly importing java profiles at the moment, so I'm open to the idea of improving support on that front.

Is this a common practice? I'd generally like to keep speedscope's source formats to be standard formats that have a fairly unambiguous way of importing them. A zipfile containing a list of jstack files seems a bit ambiguous on how you'd import it (e.g. you could reasonably interpret each file to be a separate profile per-process, or each one to be a separate stack collection).

It seems like Brendan Gregg's flamegraph tooling supports generation of flamegraphs from multiple jstack invocations appended to a single file, which strikes me as less ambiguous: https://github.com/brendangregg/FlameGraph/blob/master/stackcollapse-jstack.pl.

From the example in the comment at the top of that, the invocation would look like this:

i=0; while (( i++ < 200 )); do jstack PID >> out.jstacks; sleep 10; done

I'd prefer to support that rather than a zipfile both because it's IMO less amibiguous and because it's easier to inspect the file contents and determine which format it is. speedscope supports many formats, and uses a number of simple heuristics to determine what file format is being imported. Having a zipfile introduces ambiguities around what to do e.g. if there are other files in the zipfiles, and whether the sorting should be done lexicographically or numerically before import.

How does that sound to you?

JensRantil commented 5 years ago

Is this a common practice?

Not that I know. I invented it as I submitted my issue. :) Jokes aside, I've been thinking about this for a while wanting an easy way to profile a running JVM. Appending to a file would work equally well, or even better, and I like that approach. So go with that!

jlfwong commented 5 years ago

Cool! I think the task is clear now, so I'll place this under the same policy as a few other tasks for prioritization. This is stated at the bottom, but just for added clarity, I'd also accept a PR to implement this and would review & merge (assuming the PR is high quality) independent of donations made.


I’ll commit to implementing this feature myself if a total of $200 of donations is made to any combination of these specific charities:

If you’d like to contribute to that total, please post a screenshot of your donation receipt in this thread*.

Independent of that, I would accept a PR to implement this, regardless of donation amounts.

*: I'm planning on trying this policy on a number of issues. Donations will apply to the total of exactly one issue, so please don't post the same receipt in multiple issue threads.