Java 可以随意生成HPROF文件吗?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/2344417/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-13 06:24:11  来源:igfitidea点击:

Can I generate an HPROF file at will?

javahprof

提问by Nick Stinemates

I have a java process which is acting dubiously. I'd like to see what's up using the various HPROF analysis tools.

我有一个行为可疑的 java 进程。我想看看使用各种 HPROF 分析工具的情况。

How do I generate one on the fly?

如何即时生成一个?

回答by erickson

You have to start the Java process with the correct arguments,which vary a little depending on the JVM version. Then, send a QUITsignal to the process to generate a new file.

您必须使用正确的参数启动 Java 进程,这些参数会因 JVM 版本而略有不同。然后,向QUIT进程发送信号以生成新文件。

The output is normally generated when the VM exits, although this can be disabled by setting the “dump on exit” option to “n” (doe=n). In addition, a profile is generated when Ctrl-\ or Ctrl-Break (depending on platform) is pressed. On Solaris OS and Linux a profile is also generated when a QUIT signal is received (kill -QUIT pid). If Ctrl-\ or Ctrl-Break is pressed multiple times, multiple profiles are generated to the one file.

输出通常在 VM 退出时生成,尽管这可以通过将“退出时转储”选项设置为“n”(doe=n)来禁用。此外,按下 Ctrl-\ 或 Ctrl-Break(取决于平台)时会生成配置文件。在 Solaris OS 和 Linux 上,当接收到 QUIT 信号 (kill -QUIT pid) 时也会生成配置文件。如果多次按下 Ctrl-\ 或 Ctrl-Break,则会为一个文件生成多个配置文件。

回答by ChrisH

VisualVMcan help you dig into what your process is doing, including the ability to arbitrarily force a heap dump on a running process.

VisualVM可以帮助您深入了解您的进程正在做什么,包括在正在运行的进程上任意强制堆转储的能力。

回答by ChrisH

Yes. You can generate an hprof file (containing heap memory usage) on the fly using the jmap tool, which ships with Sun's Java VM:

是的。您可以使用 jmap 工具即时生成一个 hprof 文件(包含堆内存使用情况),该工具随 Sun 的 Java VM 一起提供:

jmap -dump:file=<file_name> <pid>

jmap -dump:file=<file_name> <pid>

回答by SLapp

jconsole now has the ability to create a dump to the app's current working directory.

jconsole 现在能够创建到应用程序当前工作目录的转储。

  1. Connect to your JMX enabled instance
  2. Navigate to com.sun.management-->HotspotDiagnostic-->Operations
  3. Fill in p0 to name the Heap Dump
  4. press the heapDump button
  1. 连接到启用了 JMX 的实例
  2. 导航到 com.sun.management-->HotspotDiagnostic-->Operations
  3. 填写 p0 以命名堆转储
  4. 按下 heapDump 按钮

Jconsole Screen Shot

Jconsole 屏幕截图