I'd like to collect stacktraces from my Java app for creating CPU Flame Graphs for profiling.
This is very similar to this question: How to get complete stack dump from profiler in every sample for use in flame graph? with 2 differences:
pref
and AFAIK dtrace
on OSX doesn't support jstack
extension).I have already tried lightweight-java-profiler and Honest profiler, and both of them don't seem to work on Mac. I also Tried VisualVM, but I couldn't get it to produce the stacktrace dumps that I needed.
First prioirty for me are flame graphs generated from Java stacktraces, but having the native call stack as well would be great, because it would let me address the I/O issues (and maybe even generate hot/cold flame graphs).
I created 2 little shell scripts based on @cello's answer. They generate hot/cold flame graphs.
Get them from this Gist.
Usage:
ps ax | grep java # find the PID of your process
./profile.sh 20402 stacks.txt
./gen.sh stacks.txt
Alternatively, to measure application from startup (in this, case, my gradle build that also needed to be run in another directory and with some input stream) I used:
cd ../my-project; ./gradlew --no-daemon clean build < /dev/zero &; cd -; ./profile.sh $! stacks.txt
./gen.sh stacks.txt
Results:
In this example, I can clearly see that my application is I/O bound (notice blue bars on top).