如何获取 Java 分析转储以在 Mac 上创建火焰图? [英] How to get Java profiling dump for creating flame graphs on the mac?
问题描述
我想从我的 Java 应用程序收集堆栈跟踪以创建 CPU 火焰图 用于分析.
I'd like to collect stacktraces from my Java app for creating CPU Flame Graphs for profiling.
这与这个问题非常相似:如何在每个样本中从分析器中获取完整的堆栈转储以用于火焰图? 有 2 个不同之处:
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:
- 我使用 Java 代码,我需要 Java 堆栈跟踪
- 我在 Mac 上工作(这意味着没有
pref
并且 OSX 上的 AFAIKdtrace
不支持jstack
扩展).
- I work with Java code and I need Java stacktraces
- I'm working on Mac (this means there is no
pref
and AFAIKdtrace
on OSX doesn't supportjstack
extension).
我已经尝试过 lightweight-java-profiler 和
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.
对我来说,第一优先级是从 Java 堆栈跟踪生成的火焰图,但是拥有本机调用堆栈也会很棒,因为它可以让我解决 I/O 问题(甚至可能生成 热/冷火焰图).
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).
推荐答案
我根据 @cello 的回答创建了 2 个小 shell 脚本.它们生成热/冷火焰图.
I created 2 little shell scripts based on @cello's answer. They generate hot/cold flame graphs.
从本要点获取它们.
用法:
ps ax | grep java # find the PID of your process
./profile.sh 20402 stacks.txt
./gen.sh stacks.txt
或者,从启动开始测量应用程序(在这种情况下,我的 gradle 构建也需要在另一个目录和一些输入流中运行)我使用:
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
结果:
在此示例中,我可以清楚地看到我的应用程序受 I/O 限制(注意顶部的蓝色条).
In this example, I can clearly see that my application is I/O bound (notice blue bars on top).
这篇关于如何获取 Java 分析转储以在 Mac 上创建火焰图?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!