Java性能调优工具——Jstat

版权声明:本文为个人学习总结,欢迎转载,转载时请附加原文链接 https://blog.csdn.net/cockroach02/article/details/82670500

一、命令说明

jstat(Java Virtual Machine Statistics Monitoring Tool)是从JDK1.5自带的一个轻量级小工具。它位于java/bin目录下,主要利用JVM内建的指令对Java虚拟机的资源和性能进行实时的监控。

二、参数说明

C:\Users\Administrator>jstat -help
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.

由以上可知,jstat的命令的格式如下:

jstat -<option> [-t] [-h<lines>] <vmid> [<interval> [<count>]]

我们可以通过jstat -options查看可以支持的具体参数

C:\Users\Administrator>jstat -options
-class
-compiler
-gc
-gccapacity
-gccause
-gcmetacapacity
-gcnew
-gcnewcapacity
-gcold
-gcoldcapacity
-gcutil
-printcompilation

Option参数说明

参数 说明
-class 类加载的行为统计 Displays statistics about the behavior of the class loader.
-compiler HotSpt JIT编译器行为统计 Displays statistics about the behavior of the Java HotSpot VM Just-in-Time compiler.
-gc 垃圾回收堆的行为统计。Displays statistics about the behavior of the garbage collected heap.
-gccapacity 各个垃圾回收代容量(young,old,meta)和他们相应的空间统计。isplays statistics about the capacities of the generations and their corresponding spaces.
-gccause 垃圾收集统计概述(同-gcutil),附加最近两次垃圾回收事件的原因。Displays a summary about garbage collection statistics (same as -gcutil), with the cause of the last and current (when applicable) garbage collection events.
-gcmetacapacity 统计元空间使用情况 Displays statistics about the sizes of the metaspace.
-gcnew 显示新生代统计信息 Displays statistics of the behavior of the new generation.
-gcnewcapacity 统计新生代及内存使用情况 Displays statistics about the sizes of the new generations and its corresponding spaces.
-gcold 统计老年代和元空间使用情况 Displays statistics about the behavior of the old generation and metaspace statistics.
-gcoldcapacity 统计老年代内存使用情况 Displays statistics about the sizes of the old generation.
-gcutil 显示各个各代内存使用百分比 Displays a summary about garbage collection statistics.
-printcompilation Hotspot方法编译统计情况 Displays Java HotSpot VM compilation method statistics.

三、使用示例

1 .jstat -class : 类加载的行为统计

C:\Users\Administrator>jstat -class 2284
Loaded  Bytes  Unloaded  Bytes     Time
 30116 75021.8       26    51.4      86.72
  • Loaded :加载class的数量
  • Bytes : 加载class的大小(单位KB)
  • Unloaded :卸载class的数量
  • Bytes: 卸载class的大小(单位KB)
  • Time : 加载和卸载class所耗费的时间

2 . jstat -compiler :HotSpt JIT编译器行为统计

C:\Users\Administrator>jstat -compiler 2284
Compiled Failed Invalid   Time   FailedType FailedMethod
   21247      8       0   189.38          1 com/fr/third/alibaba/druid/pool/DruidDataSource shrink
  • Compiled :编译成功数
  • Failed : 编译失败数
  • Invalid : 无效数量
  • FailedType : 最后一次编译失效类型
  • FailedMethod :最后一次编译失效的方法

3 .jstat -gc:垃圾回收堆的行为统计

C:\Users\Administrator>jstat -gc 2284
 S0C    S1C    S0U    S1U      EC       EU        OC         OU       MC     MU    CCSC   CCSU   YGC     YGCT    FGC    FGCT     GCT
104832.0 104832.0  0.0    0.0   838912.0 600103.2 1048576.0   565828.4  238672.0 232272.3 22392.0 21028.5     59    4.898  11      6.323   11.221
  • S0C : 第一个幸存区的总容量(KB)
  • S1C : 第二个幸存区的总容量(KB)
  • S0U : 第一个幸存区已使用的容量(KB)
  • S1U : 第二个幸存区已使用的容量(KB)
  • EC : 伊甸区的总容量(KB)
  • EU : 伊甸区已使用容量(KB)
  • OC : 老年区的总容量(KB)
  • MC : 元空间的总容量(KB)
  • MU : 元空间已使用容量(KB)
  • CCSC : 压缩类空间总容量(KB)
  • CCSU : 压缩类空间已使用总容量(KB)
  • YGC : 新生代GC次数
  • YGCT :新生代GC总耗费时间
  • FGC : 老年代GC次数
  • FGCT : 老年代GC总耗费时间
  • GCT : GC总耗费时间

4 . jstat -gccapacity : 各个回收区内存情况

C:\Users\Administrator>jstat -gccapacity 2284
 NGCMN    NGCMX     NGC     S0C   S1C       EC      OGCMN      OGCMX       OGC         OC       MCMN     MCMX      MC     CCSMN    CCSMX     CCSC    YGC    FGC
1048576.0 1048576.0 1048576.0 104832.0 104832.0 838912.0  1048576.0  3145728.0  1048576.0  1048576.0      0.0 1265664.0 238672.0      0.0 1048576.0  22392.0
59    11
  • NGCMN : 新生代占用的最小空间大小(KB)
  • NGCMX : 新生代占用的最大空间大小(KB)
  • NGC : 当前新生代空间大小(KB)
  • S0C : 第一幸存区当前空间大小(KB)
  • S1C :第二幸存区当前空间大小(KB)
  • EC : 伊甸区当前空间大小(KB)
  • OGCMN : 老年区最小空间大小(KB)
  • OGCMX : 老年区最大空间大小(KB)
  • OGC : 老年区当前空间大小(KB)
  • MCMN : 元空间最小空间大小(KB)
  • MCMX : 元空间最大空间大小(KB)
  • MC : 元空间当前空间大小(KB)
  • CCSMN : 压缩类空间最小大小(KB)
  • CCSMX : 压缩类最大空间大小(KB)
  • CCSC : 压缩类当前空间大小(KB)
  • YGC : 新生代GC次数
  • FGC : 老年代GC次数

5 .jstat -gccause :垃圾收集统计概述

C:\Users\Administrator>jstat -gccause 2284
  S0     S1     E      O      M     CCS    YGC     YGCT    FGC    FGCT     GCT    LGCC                 GCC
  0.00   0.00  91.90  53.96  97.32  93.91     59    4.898    11    6.323   11.221 System.gc()          No GC
  • S0 :第一幸存区已使用空间百分比.
  • S1 : 第二幸存区已使用空间百分比
  • E : 伊甸区已使用空间百分比
  • O : 老年区已使用空间百分比
  • M : 元空间使用百分比
  • CCS : 压缩类空间使用百分比
  • YGC : 新生代GC次数
  • FGC : 老年代GC次数
  • LGCC :最近一次GC原因
  • GCC : 当前GC原因

6 . gc -gcmetacapacity :元空间使用情况

C:\Users\Administrator>jstat -gcmetacapacity 2284
   MCMN       MCMX        MC       CCSMN      CCSMX       CCSC     YGC   FGC    FGCT     GCT
       0.0  1265664.0   238672.0        0.0  1048576.0    22392.0    59    11    6.323   11.221

  • MCMN : 元空间最小空间大小(KB)
  • MCMX : 元空间最大空间大小(KB)
  • MC : 元空间当前空间大小(KB)
  • CCSMN : 压缩类空间最小空间大小(KB)
  • CCSMX : 压缩类空间最大空间大小(KB)
  • CCSC : 压缩类空间当前空间大小(KB)
  • YGC : 新生代GC次数
  • FGC : 老年代GC次数
  • FGCT: 老年代GC耗费时间
  • GCT : GC总耗费时间

7 . jstat -gcnew : 显示新生代统计信息

C:\Users\Administrator>jstat -gcnew 2284
 S0C    S1C    S0U    S1U   TT MTT  DSS      EC       EU     YGC     YGCT
104832.0 104832.0 46710.2    0.0  6   6 52416.0 838912.0  22526.9     60    4.972
  • S0C : 第一幸存区总空间大小(KB)
  • S1C : 第二幸存区总空间大小(KB)
  • S0U : 第一幸存区已使用空间大小(KB)
  • S1U : 第二幸存区已使用空间大小(KB)
  • TT : 提升阈值(提升阈值)
  • MTT : 最大阈值
  • DSS : survivor区域大小 (KB)
  • EC : 伊甸区总空间大小(KB)
  • EU : 伊甸区已使用空间大小(KB)

8 . jstat -gcnewcapacity : 统计新生代及内存使用情况

C:\Users\Administrator>jstat -gcnewcapacity 2284
  NGCMN      NGCMX       NGC      S0CMX     S0C     S1CMX     S1C       ECMX        EC      YGC   FGC
 1048576.0  1048576.0  1048576.0 104832.0 104832.0 104832.0 104832.0   838912.0   838912.0    60    11
  • NGCMN : 新生代最小空间大小(KB)
  • NGCMX : 新生代最大空间大小(KB)
  • NGC : 当前新生代空间大小(KB)
  • S0CMX : 第一幸存区最大空间大小(KB)
  • S0C : 第一幸存区当前空间大小(KB)
  • S1CMX : 第二幸存区最大空间大小(KB)
  • S1C : 第二幸存区当前空间大小(KB)
  • ECMX : 伊甸区最大空间大小(KB)
  • EC : 伊甸区当前空间大小(KB)
  • YGC : 新生代GC次数
  • FGC : 老年代GC次数

9 . jstat -gcold : 统计老年代和元空间使用情况

C:\Users\Administrator>jstat -gcold 2284
   MC       MU      CCSC     CCSU       OC          OU       YGC    FGC    FGCT     GCT
251088.0 244521.5  23544.0  22058.7   1048576.0    565828.4     60    11    6.323   11.295
  • MC : 元空间总大小(KB)
  • MU : 元空间已使用大小(KB)
  • CCSC : 压缩类空间总大小(KB)
  • CCSU : 压缩类空间已使用大小(KB)
  • OC : 老年区空间总大小(KB)
  • OU : 老年区已使用大小(KB)
  • YGC : 新生代GC次数
  • FGC : 老年代GC次数
  • FGCT : 老年代GC总耗时
  • GCT : GC总耗时

10 . jstat -gcoldcapacity : 统计老年代内存使用情况

C:\Users\Administrator>jstat -gcoldcapacity 2284
   OGCMN       OGCMX        OGC         OC       YGC   FGC    FGCT     GCT
  1048576.0   3145728.0   1048576.0   1048576.0    60    11    6.323   11.295

  • OGCMN :老年区占用最小空间(KB)
  • OGCMX : 老年区占用最大空间(KB)
  • OGC : 当前老年区空间(KB)
  • OC : 当前老年区空间(KB)
  • YGC :新生代GC次数
  • FGC : 老年代GC次数
  • FGCT : 老年代GC总耗时
  • GCT : GC总耗时

11 . jstat -gcutil : 垃圾回收统计

C:\Users\Administrator>jstat -gcutil 2284
  S0     S1     E      O      M     CCS    YGC     YGCT    FGC    FGCT     GCT
 44.56   0.00   9.85  53.96  97.38  93.69     60    4.972    11    6.323   11.295
  • S0 :第一幸存区已使用空间百分比.
  • S1 : 第二幸存区已使用空间百分比
  • E : 伊甸区已使用空间百分比
  • O : 老年区已使用空间百分比
  • M : 元空间使用百分比
  • CCS : 压缩类空间使用百分比
  • YGC : 新生代GC次数
  • FGC : 老年代GC次数
  • GCT :GC总耗时

12 . jstat -printcompilation : Hotspot方法编译统计情况

C:\Users\Administrator>jstat -printcompilation 2284
Compiled  Size  Type Method
   21538    150    1 java/util/Collections reverse
  • Compiled : 已编译方法次数
  • Size : 最近一次方法编译大小
  • Type : 最近一次编译方法类型
  • Method : 最近一次编译方法

四、参考链接

  1. jstat
  2. jstat命令使用
  3. JVM调优命令-jstat

猜你喜欢

转载自blog.csdn.net/cockroach02/article/details/82670500