java 类似于 HPjmeter 的图形工具,用于查看 -agentlib:hprof 分析输出
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/707609/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
HPjmeter-like graphical tool to view -agentlib:hprof profiling output
提问by David Citron
What tools are available to view the output of the built-in JVM profiler? For example, I'm starting my JVM with:
有哪些工具可用于查看内置 JVM 分析器的输出?例如,我使用以下命令启动我的 JVM:
-agentlib:hprof=cpu=times,thread=y,cutoff=0,format=a,file=someFile.hprof.txt
This generates output in the hprof ("JAVA PROFILE 1.0.1") format.
这将生成 hprof(“JAVA PROFILE 1.0.1”)格式的输出。
I have had success in the past using HPjmeterto view these output files in a reasonable way. However, for whatever reason the files that are generated using the current version of the Sun JVM fail to load in the current version of HPjmeter:
我过去曾成功地使用HPjmeter以合理的方式查看这些输出文件。但是,无论出于何种原因,使用当前版本的 Sun JVM 生成的文件都无法在当前版本的 HPjmeter 中加载:
java.lang.NullPointerException
at com.hp.jmeter.f.jb.a(Unknown Source)
at com.hp.jmeter.f.a.a(Unknown Source)
at com.hp.c.a.j.z.run(Unknown Source)
Exception in thread "HPeprofDataFileReaderThread" java.lang.AssertionError: null pointer exception from loader
at com.hp.jmeter.f.a.a(Unknown Source)
at com.hp.c.a.j.z.run(Unknown Source)
(Why would they obfuscate the bytecode for a free product?!)
(他们为什么要混淆免费产品的字节码?!)
Two questions arise from this:
由此产生两个问题:
- Does anyone know the cause of this HPjmeter error? (EDIT: Yes--see below)
- What other tools exist to read hprof files? And why are there none from Sun (are there)?
- 有谁知道这个 HPjmeter 错误的原因?(编辑:是的——见下文)
- 还有哪些其他工具可以读取 hprof 文件?为什么没有来自 Sun(在那里)?
I know the Eclipse TPTPand other tools can monitor JVMTI data on the fly, but I need a solution that can process the generated hprof files after the fact since the deployed machine only has a JRE (not a JDK) intalled.
我知道Eclipse TPTP和其他工具可以实时监控 JVMTI 数据,但是我需要一个可以在事后处理生成的 hprof 文件的解决方案,因为部署的机器只安装了 JRE(而不是 JDK)。
EDIT: A very helpful HPjmeter developer replied to my question on an HP ITRC forumindicating that heap=dumpneeds to be included in the -agentliboptions temporarily until a bug in HPjmeter is fixed. This information makes HPjmeter viable again, but I will still leave the question open to see if anyone knows of any other tools.
编辑:一位非常有帮助的 HPjmeter 开发人员在 HP ITRC 论坛上回答了我的问题,表明heap=dump需要-agentlib暂时将其包含在选项中,直到 HPjmeter 中的错误得到修复。这些信息使 HPjmeter 再次可行,但我仍然会留下这个问题,看看是否有人知道任何其他工具。
EDIT: As of version 4.0.00 of HPjmeter (available 05/2009) this bug has been fixed.
编辑:从 HPjmeter 4.0.00 版(可用 05/2009)开始,此错误已得到修复。
回答by Bogdan
Your KitJava Profiler is able to read hprof snapshots (I am not sure if only for memory profiling or for CPU as well). It is not free but is by far the best java profiler I ever used. It presents the results in a clear, intuitive way and performs well on large data sets. The documentation is also pretty good.
您的 KitJava Profiler 能够读取 hprof 快照(我不确定是否仅用于内存分析或 CPU)。它不是免费的,但它是迄今为止我用过的最好的 Java 分析器。它以清晰、直观的方式呈现结果,并且在大型数据集上表现良好。文档也很不错。
回答by sleske
For viewing and analyzing the output of hprof=samplesor hprof=cpuI have used PerfAnal with good results. The GUI is a bit spartan, but very useful.
为了查看和分析hprof=samples或的输出,hprof=cpu我使用了 PerfAnal,结果很好。GUI 有点简陋,但非常有用。
PerfAnal is a free download (GPL, originally an example project in the book Java Programming on Linux). See this article:
PerfAnal 是一个免费下载(GPL,最初是Java Programming on Linux一书中的一个示例项目)。看这篇文章:
http://www.oracle.com/technetwork/articles/javase/perfanal-137231.html
http://www.oracle.com/technetwork/articles/javase/perfanal-137231.html
for more information and the download.
了解更多信息和下载。
Normally you can just run
通常你可以运行
java -jar PerfAnal.jar hprof.java.txt
You may need to fiddle with -Xmx for large hprof files.
对于大型 hprof 文件,您可能需要使用 -Xmx。
回答by Daniel H.
I have been using Eclipse Memory Analyzerfor analyzing different performance problems successfully. First of all, install the tool as described in the project webpage in Eclipse.
我一直在使用Eclipse Memory Analyzer成功地分析不同的性能问题。首先,按照 Eclipse 中项目网页中的描述安装该工具。
After that, you can create a dump file knowing the pid of the jvm to be analyzed
之后,您可以创建一个转储文件,知道要分析的 jvm 的 pid
jmap -dump:format=b,file=<filename>.hprof <jvm_pid>
Then just import the .hprof file in eclipse. It has some automatic reports that try (for me they usually do not work) to point out which could be the possible problems.
然后只需在 eclipse 中导入 .hprof 文件。它有一些自动报告试图(对我来说它们通常不起作用)指出哪些可能是可能的问题。
Edit:
编辑:
Answering the comment: You are right, it is more like a leak finder for Java. For performance problems, I have played with JRatfor small projects. It shows time comsumed per method, number of times a method is called, hierarchy of calls, etc. The only problem is that as far as I know, it does not support .hprof files. To use it, yo need to execute your program adding a VM argument
回答评论:您说得对,它更像是 Java 的泄漏查找器。对于性能问题,我曾在小型项目中使用过JRat。它显示每个方法的时间、调用方法的次数、调用的层次结构等。唯一的问题是,据我所知,它不支持 .hprof 文件。要使用它,您需要执行您的程序并添加一个 VM 参数
-javaagent:<path>/shiftone-jrat.jar
This will generate a directory with the profile captured by the tool. Then, execute
这将生成一个包含该工具捕获的配置文件的目录。然后,执行
java -jar shiftone-jrat.jar
And open the trace. Even been a simple tool, I think it could be useful.
并打开痕迹。即使是一个简单的工具,我认为它也很有用。

