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
Did you try the jstack
command? just run it on the command line: jstack pidOfJavaProcess > stack.txt
(naturally, replacing pidOfJavaProcess with the actual process number). You could run this in a loop in bash (the default shell used on Mac OS X):
while true; do jstack pidOfJavaProcess >> stack.txt; sleep 1.0; done
note the >>
to append to the file, and not overwrite it each second. Press Ctrl+C
to stop logging the stack traces.
This will only generate the java stack traces, and not the native call stacks from the JVM.