JDK的幾種分析工具

531968912發表於2016-07-11

學習了一下JDK中的一些自帶系統效能分析工具。

 

在jdk的bin目錄下,jconsole,jstack、jmap、jstat、jhat

jconsole 是監視和管理工具。可以檢視堆記憶體,執行緒,類,CPU狀況。直接雙擊就可以啟動了,然後選擇連線本地local還是遠端remote,分析結果就出現在介面上了。當然也可以從命令列啟動介面。

 

jstack 主要用於執行緒死鎖的監控。

命令列中輸入jstack -h檢視用法

C:/Program Files (x86)/Java/jdk1.6.0_14/bin>jstack -h
Usage:
    jstack [-l] <pid>
        (to connect to running process)

Options:
    -l  long listing. Prints additional infor
    -h or -help to print this help message

pid 程式號


jmap 主要用於監控記憶體洩露時候物件佔用的位元組數。

命令列中輸入jmap -h檢視用法

C:/Program Files (x86)/Java/jdk1.6.0_14/bin>jmap -h
Usage:
    jmap -histo <pid>
      (to connect to running process and print histogram of java object heap
    jmap -dump:<dump-options> <pid>
      (to connect to running process and dump java heap)

    dump-options:
      format=b     binary default
      file=<file>  dump heap to <file>

    Example:       jmap -dump:format=b,file=heap.bin <pid>

 

jstat 主要用於監控jvm的gc使用情況。

命令列中輸入jstat -h檢視用法

C:/Program Files (x86)/Java/jdk1.6.0_14/bin>jstat -h
-h requires an integer argument
Usage: jstat -help|-options
       jstat -<option> [-t] [-h<lines>] <vmid> [<interval> [<count>]]

Definitions:
  <option>      An option reported by the -options option
  <vmid>        Virtual Machine Identifier. A vmid takes the following form:
                     <lvmid>[@<hostname>[:<port>]]
                Where <lvmid> is the local vm identifier for the target
                Java virtual machine, typically a process id; <hostname> is
                the name of the host running the target Java virtual machine;
                and <port> is the port number for the rmiregistry on the
                target host. See the jvmstat documentation for a more complete
                description of the Virtual Machine Identifier.
  <lines>       Number of samples between header lines.
  <interval>    Sampling interval. The following forms are allowed:
                    <n>["ms"|"s"]
                Where <n> is an integer and the suffix specifies the units as
                milliseconds("ms") or seconds("s"). The default units are "ms".
  <count>       Number of samples to take before terminating.
  -J<flag>      Pass <flag> directly to the runtime system.

 

pid 程式號,interval時間間隔,count次數


jhat 主要用於分析jmap產生的dump並提供web頁面檢視分析結果。

命令列中輸入jhat -h檢視用法

C:/Program Files (x86)/Java/jdk1.6.0_14/bin>jhat -h
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"

 

jhat filename.bin //就可以分析產生的dump檔案,可以透過訪問

 

IBM的堆分析工具HeapAnalyzer ( )。堆的dump log的檢視化檢視工具。

TDA - Thread Dump Analyzer (https://tda.dev.java.net/ )。執行緒dump的檢視化檢視工具。

來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/25462274/viewspace-2121807/,如需轉載,請註明出處,否則將追究法律責任。

相關文章