如何分析 .hprof 文件?
我有一个使用以下标志运行的生产服务器: -XX:+HeapDumpOnOutOfMemoryError
昨晚,当我们的服务器遇到堆错误时,它生成了 java-38942.hprof 文件。 事实证明,系统的开发人员知道该标志,但无法从中获取任何有用的信息。
有任何想法吗?
I have a production server running with the following flag: -XX:+HeapDumpOnOutOfMemoryError
Last night it generated a java-38942.hprof file when our server encountered a heap error. It turns out that the developers of the system knew of the flag but no way to get any useful information from it.
Any ideas?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(9)
如果您想要一个相当高级的工具来进行一些认真的探索,请查看 Eclipse 中的内存分析器项目 ,由 SAP 贡献。
您可以做的一些事情对于查找内存泄漏等非常有用——包括针对内存中的对象运行某种形式的有限 SQL (OQL),即
非常出色。
If you want a fairly advanced tool to do some serious poking around, look at the Memory Analyzer project at Eclipse, contributed to them by SAP.
Some of what you can do is mind-blowingly good for finding memory leaks etc -- including running a form of limited SQL (OQL) against the in-memory objects, i.e.
Totally brilliant.
您可以使用 JHAT,Java 堆分析JDK 默认提供的工具。 它是命令行,但会启动一个用于检查内存的 Web 服务器/浏览器。 虽然不是最用户友好的,但至少它已经安装在您要去的大多数地方。 一个非常有用的视图是最底部的“堆直方图”链接。
例如:
jhat -port 7401 -J-Xmx4G dump.hprof
jhat
“这些天”也可以执行 OQL(底部链接“执行 OQL”)You can use JHAT, The Java Heap Analysis Tool provided by default with the JDK. It's command line but starts a web server/browser you use to examine the memory. Not the most user friendly, but at least it's already installed most places you'll go. A very useful view is the "heap histogram" link at the very bottom.
ex:
jhat -port 7401 -J-Xmx4G dump.hprof
jhat
can execute OQL "these days" as well (bottom link "execute OQL")您还可以使用 Netbeans Profiler 或 Visual VM 独立工具。 Visual VM 是 JHAT 的一个很好的替代品,因为它是独立的,但比 JHAT 更容易使用。
您需要 Java 6+ 才能充分使用 Visual VM。
You can also use HeapWalker from the Netbeans Profiler or the Visual VM stand-alone tool. Visual VM is a good alternative to JHAT as it is stand alone, but is much easier to use than JHAT.
You need Java 6+ to fully use Visual VM.
只需获取 Eclipse 内存分析器。 没有比这更好的了,而且它是免费的。
JHAT 仅可用于“玩具应用”
Just get the Eclipse Memory Analyzer. There's nothing better out there and it's free.
JHAT is only usable for "toy applications"
我个人更喜欢VisualVM。 我喜欢 VisualVM 的功能之一是堆转储比较。 当您进行堆转储分析时,有多种方法可以找出导致崩溃的原因。 我发现有用的方法之一是比较健康与不健康的堆转储。
以下是您可以遵循的步骤:
链接:https://visualvm.github.io
I personally prefer VisualVM. One of the features I like in VisualVM is heap dump comparison. When you are doing a heap dump analysis there are various ways to go about figuring out what caused the crash. One of the ways I have found useful is doing a comparison of healthy vs unhealthy heap dumps.
Following are the steps you can follow for it :
link : https://visualvm.github.io
YourKit Java Profiler 似乎也可以处理它们。
YourKit Java Profiler seems to handle them too.
如果您想对堆转储进行自定义分析,可以使用:
这个库速度很快,但您需要用 Java 编写分析代码。
来自文档:
If you want to do a custom analysis of your heapdump then there's:
This library is fast but you will need to write your analysis code in Java.
From the docs:
我在 Ultimate 版本中使用 IntelliJ IDEA profiler。
在 IDEA 中,按两次 Shift 按钮。
在
Actions
选项卡中写入 - “profiler”。选择带有图标的“分析器”行。
然后
打开快照..
按钮。I'm using IntelliJ IDEA profiler in Ultimate version.
In IDEA, press the Shift button twice.
In
Actions
tab write - "profiler".Choice row "profiler" with icon.
Then
Open snapshot..
button.您可能会从 Oracle Java 平台标准版故障排除指南,其中详细介绍了 HPROF:堆/CPU 分析工具。 它可用于从 JVM 接收相关信息,例如 CPU 使用率采样/次数和内存分配。 您可以使用该工具查看该文件并收集一些高级信息。
调用 HPROF 工具
获取堆分配配置文件
显示程序各个部分的分配
HPROF 帮助
文件通常很大,文档建议 JHAT 用于可视化堆转储的输出(还提到
You may get some value out of the Oracle Java Platform, Standard Edition Troubleshooting guide, which details the HPROF: A Heap/CPU Profiling Tool. It can be used to receive relevant information from from the JVM, like CPU usage sampling/times and memory allocation. You can take a look into that file with the tool and glean some high-level information.
Invoking the HPROF Tool
Obtaining Heap Allocation Profile
Shows allocation for various parts of the program
HPROF Help
The files are usually large and docs recommend JHAT for visualizing the outputs of the heap dump (Also mentioned above). Can figure out what parts of your program are eating your heap memory and maxing out CPU usage.