【问题标题】:How to profile a class inside a jar?如何分析 jar 中的类?
【发布时间】:2012-11-05 16:40:14
【问题描述】:

如果我在试图分析的 JAR(使用 mvn assembly:assembly 编译)中有一个类,那么获取可与 jhat 或 Eclipse 内存分析器一起使用的有效核心转储的命令是什么?

我试过运行这个:

java -agentlib:hprof=heap=sites,cpu=samples,file=profile.hprof,format=b -jar the-jar.jar

当我停止进程时会创建核心转储。

但 jhat 或 Eclipse 内存分析器都不会将此视为有效转储。

jhat 给了我这个警告:

Resolving 0 objects...
WARNING:  hprof file does not include java.lang.Class!
WARNING:  hprof file does not include java.lang.String!
WARNING:  hprof file does not include java.lang.ClassLoader!

还阅读了 hprof 文档,我看到我必须传递类名。当它在 JAR 中时,我该怎么做?

【问题讨论】:

    标签: java jar profiling executable-jar hprof


    【解决方案1】:

    类是从 JAR 文件加载的事实与堆转储无关。

    您可以使用jmap 获取可用的 HPROF 堆转储,而无需修改启动命令。

    jmap -heap:format=b <pid>
    

    您可以使用jps 命令行实用程序获取的进程ID 在哪里。这两个可执行文件都是 JDK 的一部分。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-07-31
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-12-20
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多