zoukankan      html  css  js  c++  java
  • JVM调优命令-jhat

    jhat

    JVM Heap Analysis Tool命令是与jmap搭配使用,用来分析jmap生成的dump,jhat内置了一个微型的HTTP/HTML服务器,生成dump的分析结果后,可以在浏览器中查看。在此要注意,一般不会直接在服务器上进行分析,因为jhat是一个耗时并且耗费硬件资源的过程,一般把服务器生成的dump文件复制到本地或其他机器上进行分析。【内存分析】


    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    [root@localhost bin]# jhat -help
    Usage:  jhat [-stack <bool>] [-refs <bool>] [-port <port>] [-baseline <file>] [-debug <int>] [-version] [-h|-help] <file>
     
        -J<flag>          Pass <flag> directly to the runtime system. For
                  example, -J-mx512m to use a maximum heap size of 512MB
        -stack false:     Turn off tracking object allocation call stack.
        -refs false:      Turn off tracking of references to objects
        -port <port>:     Set the port for the HTTP server.  Defaults to 7000
        -exclude <file>:  Specify a file that lists data members that should
                  be excluded from the reachableFrom query.
        -baseline <file>: Specify a baseline object dump.  Objects in
                  both heap dumps with the same ID and same class will
                  be marked as not being "new".
        -debug <int>:     Set debug level.
                    0:  No debug output
                    1:  Debug hprof file parsing
                    2:  Debug hprof file parsing, no server
        -version          Report version number
        -h|-help          Print this help and exit
        <file>            The file to read
     
    For a dump file that contains multiple heap dumps,
    you may specify which dump in the file
    by appending "#<number>" to the file name, i.e. "foo.hprof#3".
     
    All boolean options default to "true"


    参数

    -J< flag >                 
    因为 jhat 命令实际上会启动一个JVM来执行, 通过 -J 可以在启动JVM时传入一些启动参数. 例如, -J-Xmx512m 则指定运行 jhat 的Java虚拟机使用的最大堆内存为 512 MB. 如果需要使用多个JVM启动参数,则传入多个 -Jxxxxxx.
    -stack false|true 
    关闭对象分配调用栈跟踪(tracking object allocation call stack)。 如果分配位置信息在堆转储中不可用. 则必须将此标志设置为 false. 默认值为 true.
    -refs false|true 
    关闭对象引用跟踪(tracking of references to objects)。 默认值为 true. 默认情况下, 返回的指针是指向其他特定对象的对象,如反向链接或输入引用(referrers or incoming references), 会统计/计算堆中的所有对象。
    -port port-number 
    设置 jhat HTTP server 的端口号. 默认值 7000。
    -exclude exclude-file 
    指定对象查询时需要排除的数据成员列表文件(a file that lists data members that should be excluded from the reachable objects query)。 例如, 如果文件列列出了 java.lang.String.value , 那么当从某个特定对象 Object o 计算可达的对象列表时, 引用路径涉及 java.lang.String.value 的都会被排除。
    -baseline exclude-file 
    指定一个基准堆转储(baseline heap dump)。 在两个 heap dumps 中有相同 object ID 的对象会被标记为不是新的(marked as not being new). 其他对象被标记为新的(new). 在比较两个不同的堆转储时很有用。
    -debug int 
    设置 debug 级别. 0 表示不输出调试信息。 值越大则表示输出更详细的 debug 信息。
    -version 
    启动后只显示版本信息就退出。

    示例
    1
    jhat -J-Xmx512m dump.hprof
    1
    jhat -port 7000 mem.dat
    • jmap -dump:format=b,file=mem.dat pid #将内存使用的详细情况输出到mem.dat 文件
      通过jhat -port 7000 mem.dat可以将mem.dat的内容以web的方式暴露到网络,访问http://ip-server:7000查看。

     一般查看堆异常情况主要看这个两个部分: Show instance counts for all classes (excluding platform),平台外的所有对象信息。Show heap histogram 以树状图形式展示堆情况。

     
     
     观察是否大量应该被回收的对象在一直被引用或者是否有占用内存特别大的对象无法被回收。

  • 相关阅读:
    MAC Operation not permitted
    Failed to connect to raw.githubusercontent.com port 443
    Ubuntu adb 报错:no permissions (user in plugdev group; are your udev rules wrong?);
    mysql随机抽取数据
    git 初始创建项目
    VS Code 中的代码自动补全和自动导入包
    25个ssh命令行技巧
    KaTex语法说明
    聊聊OkHttp实现WebSocket细节,包括鉴权和长连接保活及其原理!
    面试官:“看你简历上写熟悉 Handler 机制,那聊聊 IdleHandler 吧?”
  • 原文地址:https://www.cnblogs.com/myna/p/7590620.html
Copyright © 2011-2022 走看看