How to get Java profiling dump for creating flame graphs on the mac?

前端 未结 4 1479
一个人的身影
一个人的身影 2021-02-04 15:45

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

4条回答
  •  北海茫月
    2021-02-04 16:29

    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:

    flame graphs

    In this example, I can clearly see that my application is I/O bound (notice blue bars on top).

提交回复
热议问题