Java命令:jstat — 查看JVM的GC信息

一、简介

jstat(JVM statistics Monitoring)命令主要是 对java应用程序的资源和性能进行实时的命令行监控,包括了对 heap size垃圾回收状况 的监控。

jstat

输出结果:

root@yzh-zabbix-server:bin #jstat
invalid argument count
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 [option] vmid [interval] [count]

参数说明:

参数说明
option操作参数,我们经常使用的选项有gc、gccapacity、gcnew、gcnewcapacity、gcold、gcoldcapacity、gcmetacapacity、gcutil等。
vmidjava进程ID
interval间隔时间,单位为毫秒。
count打印次数。

option参数总览:

参数说明
classclass loader的行为统计。
compilerHotSpot JIT编译器行为统计。
gc垃圾回收堆的行为统计。
gccapacity各个垃圾回收代容量(young、old、perm)和他们相应的空间统计。
gcutil垃圾回收统计概述。
gccause垃圾收集器概述。
gcnew新生代行为统计。
gcnewcapacity新生代与其相应的内存空间的统计。
gcold老年代和永久代行为统计。
gcoldcapacity老年代行为统计
gcmetacapacity元数据区行为统计。
printcompilationHotSpot编译方法统计。

二、常用命令

1、jstat -class pid : class loader行为统计

监视类装载、卸载数量、总空间以及耗费的时间

jstat -class pid

输出结果:

Loaded  Bytes  Unloaded  Bytes     Time
  4995 10540.4        0     0.0       5.22

字段说明:

字段说明
Loaded加载class的数量。
Bytesclass字节大小。
Unloaded未加载class的数量。
Bytes未加载class的字节大小。
Time加载时间。

2、jstat -compiler pid : JIT编译器行为统计

输出JIT编译过的方法数量耗时等。

jstat -compiler pid

输出结果:

Compiled Failed Invalid   Time   FailedType FailedMethod
    3641      1       0    16.62          1 com/cloudwise/agent/deps/asm/ClassReader accept

字段说明:

字段说明
Compiled编译数量。
Failed编译失败数量。
Invalid无效数量。
Time编译耗时。
FailedType失败类型。
FailedMethod失败方法的全限定名。

3、jstat -gc pid 5000 20 : 垃圾回收堆行为统计

5秒钟打印一次,一共打印20次。

jstat -gc pid 5000 20

输出结果:

root@yzh-zabbix-server:bin #jstat -gc 3111 5000 20
 S0C    S1C      S0U    S1U      EC       EU        OC         OU       MC     MU      CCSC   CCSU     YGC     YGCT  FGC    FGCT     GCT   
14336.0 24576.0  0.0    0.0   50688.0  50687.9   330752.0   330634.8  55296.0 53462.8 6400.0 5925.3    178    2.226  2483   438.892  441.117
14336.0 24576.0  0.0    0.0   50688.0  50688.0   330752.0   330607.2  55296.0 53467.9 6400.0 5925.3    178    2.226  2511   443.944  446.169
14336.0 24576.0  0.0    0.0   50688.0  50686.3   330752.0   330591.4  55296.0 53467.9 6400.0 5925.3    178    2.226  2541   449.050  451.275
14336.0 24576.0  0.0    0.0   50688.0  50687.9   330752.0   330603.5  55296.0 53467.9 6400.0 5925.3    178    2.226  2569   454.029  456.255
14336.0 24576.0  0.0    0.0   50688.0  50688.0   330752.0   330607.6  55296.0 53467.9 6400.0 5925.3    178    2.226  2598   458.971  461.197

CCapacity 总容量,UUsed 已使用的容量。

字段说明:

字段说明
S0C年轻代第一个Survivor区的大小(单位:KB)
S1C年轻代第二个Survivor区的大小(单位:KB)
S0U年轻代第一个Survivor区的使用大小(单位:KB)
S1U年轻代第二个Survivor区的使用大小(单位:KB)
EC年轻代中Eden区的大小(单位:KB)
EU年轻代中Eden区的使用大小(单位:KB)
OC老年代大小(单位:KB)
OU老年代使用大小(单位:KB)
MC方法区大小(单位:KB)
MU方法区使用大小(单位:KB)
CCSC压缩类空间大小(单位:KB)
CCSU压缩类空间使用大小(单位:KB)
YGC年轻代垃圾回收次数
YGCT年轻代垃圾回收消耗时间
FGC老年代垃圾回收次数
FGCT老年代垃圾回收消耗时间
GCT垃圾回收消耗总时间

4、jstat -gccapacity pid 5000 20 : 堆内存统计

5秒钟打印一次,一共打印20次。

-gc ,不过还会输出 Java 堆各区域使用到的最大、最小空间。

jstat -gccapacity pid 5000 20

输出结果:

root@yzh-zabbix-server:bin #jstat -gccapacity 3111 5000 20
 NGCMN    NGCMX     NGC     S0C      S1C       EC      OGCMN      OGCMX       OGC         OC       MCMN     MCMX       MC     CCSMN    CCSMX      CCSC    YGC    FGC 
 10752.0 164864.0 110080.0 14336.0 24576.0  50688.0    22016.0   330752.0   330752.0   330752.0     0.0   1097728.0  55296.0   0.0    1048576.0   6400.0  178    7491
 10752.0 164864.0 110080.0 14336.0 24576.0  50688.0    22016.0   330752.0   330752.0   330752.0     0.0   1097728.0  55296.0   0.0    1048576.0   6400.0  178    7520
 10752.0 164864.0 110080.0 14336.0 24576.0  50688.0    22016.0   330752.0   330752.0   330752.0     0.0   1097728.0  55296.0   0.0    1048576.0   6400.0  178    7547

字段说明:

字段说明
NGCMN新生代最小容量
NGCMX新生代最大容量
NGC当前新生代容量
S0C第一个Survivor区大小
S1C第二个Survivor区的大小
ECEden区的大小
OGCMN老年代最小容量
OGCMX老年代最大容量
OGC当前老年代大小
OC当前老年代大小
MCMN最小元数据容量
MCMX最大元数据容量
MC当前元数据空间大小
CCSMN最小压缩类空间大小
CCSMX最大压缩类空间大小
CCSC当前压缩类空间大小
YGC年轻代gc次数
FGC老年代GC次数

5、jstat -gcutil pid 5000 20 : 总结垃圾回收统计

5秒钟打印一次,一共打印20次。

-gc ,不过输出的是已使用空间占总空间的百分比

jstat -gcutil pid 5000 20

输出结果:

root@yzh-zabbix-server:bin #jstat -gcutil 3111 5000 20
  S0     S1     E      O      M     CCS    YGC     YGCT    FGC    FGCT     GCT   
  0.00   0.00 100.00  99.95  96.75  92.57  178    2.226   10172  1772.566 1774.791
  0.00   0.00 100.00  99.95  96.75  92.57  178    2.226   10203  1777.589 1779.814
  0.00   0.00 100.00  99.95  96.75  92.57  178    2.226   10234  1782.580 1784.806

字段说明:

字段说明
S0第一个Servivor区当前使用比例
S1第二个Servivor区当前使用比例
EEden区使用比例
O老年代使用比例
M元数据区使用比例
CCS压缩使用比例
YGC年轻代垃圾回收次数
FGC老年代垃圾回收次数
FGCT老年代垃圾回收消耗时间
GCT垃圾回收消耗总时间

6、jstat -gccause pid 5000 20 : 垃圾收集统计概述

5秒钟打印一次,一共打印20次。

-gcutil ,附加最近两次垃圾回收事件的原因。

jstat -gccause pid 5000 20

输出结果:

S0     S1     E      O      M     CCS    YGC     YGCT    FGC    FGCT     GCT    LGCC                 GCC
0.00   0.00  35.78  19.43  97.96  95.19     20    0.176    11    0.406    0.582 Heap Inspection Initiated GC No GC

字段说明:

字段说明
S0第一个Servivor区当前使用比例
S1第二个Servivor区当前使用比例
EEden区使用比例
O老年代使用比例
M元数据区使用比例
CCS压缩使用比例
YGC年轻代垃圾回收次数
FGC老年代垃圾回收次数
FGCT老年代垃圾回收消耗时间
GCT垃圾回收消耗总时间
LGCC最近垃圾回收的原因
GCC当前垃圾回收的原因

7、jstat -gcnew pid 5000 20 : 新生代垃圾回收统计

5秒钟打印一次,一共打印20次。

jstat -gcnew pid 5000 20

输出结果:

root@yzh-zabbix-server:bin #jstat -gcnew 3111 5000 20
 S0C       S1C      S0U    S1U  TT  MTT    DSS      EC       EU       YGC     YGCT  
14336.0  24576.0    0.0    0.0  12  15   24576.0  50688.0  50688.0    178    2.226
14336.0  24576.0    0.0    0.0  12  15   24576.0  50688.0  50688.0    178    2.226
14336.0  24576.0    0.0    0.0  12  15   24576.0  50688.0  50688.0    178    2.226

字段说明:

字段说明
S0C第一个Survivor区大小
S1C第二个Survivor区的大小
S0U第一个Survivor区的使用大小
S1U第二个Survivor区的使用大小
TT对象在新生代存活的次数
MTT对象在新生代存活的最大次数
DSS期望的Survivor区大小
ECEden区的大小
EUEden区的使用大小
YGC年轻代垃圾回收次数
YGCT年轻代垃圾回收消耗时间

8、jstat -gcnewcapacity pid 5000 20 : 新生代内存统计

5秒钟打印一次,一共打印20次。

jstat -gcnewcapacity pid 5000 20

输出结果:

root@yzh-zabbix-server:bin #jstat -gcnewcapacity 3111 5000 20
  NGCMN      NGCMX       NGC      S0CMX     S0C     S1CMX     S1C       ECMX        EC      YGC   FGC 
   10752.0   164864.0   110080.0  54784.0  14336.0  54784.0  24576.0   163840.0    50688.0   178 14824
   10752.0   164864.0   110080.0  54784.0  14336.0  54784.0  24576.0   163840.0    50688.0   178 14850
   10752.0   164864.0   110080.0  54784.0  14336.0  54784.0  24576.0   163840.0    50688.0   178 14878

字段说明:

字段说明
NGCMN新生代最小容量
NGCMX新生代最大容量
NGC当前新生代容量
S0CMX第一个Survivor区最大大小
S0C第一个Survivor区当前大小
S1CMX第二个Survivor区最大大小
S1C第二个Survivor区当前大小
ECMXEden区最大大小
ECEden区当前大小
YGC年轻代垃圾回收次数
FGC老年代回收次数

9、jstat -gcold pid 5000 20 : 老年代垃圾回收统计

5秒钟打印一次,一共打印20次。

jstat -gcold pid 5000 20

输出结果:

root@yzh-zabbix-server:bin #jstat -gcold 3111 5000 20
   MC       MU      CCSC     CCSU       OC          OU       YGC    FGC    FGCT     GCT   
 55552.0  53550.5   6400.0   5924.5    330752.0    330602.1    178 16635 2895.316 2897.541
 55552.0  53550.5   6400.0   5924.5    330752.0    330601.3    178 16665 2900.278 2902.504
 55552.0  53550.5   6400.0   5924.5    330752.0    330604.3    178 16693 2905.210 2907.435

字段说明:

字段说明
MC方法区大小
MU方法区使用大小
CCSC压缩类空间大小
CCSU压缩类空间使用大小
OC老年代大小
OU老年代使用大小
YGC年轻代垃圾回收次数
FGC老年代垃圾回收次数
FGCT老年代垃圾回收消耗时间
GCT垃圾回收消耗总时间

10、jstat -gcoldcapacity pid 5000 20 : 老年代内存统计

5秒钟打印一次,一共打印20次。

jstat -gcoldcapacity pid 5000 20

输出结果:

root@yzh-zabbix-server:bin #jstat -gcoldcapacity 3111 5000 20
   OGCMN       OGCMX        OGC         OC       YGC   FGC    FGCT     GCT   
    22016.0    330752.0    330752.0    330752.0   178 17810 3099.915 3102.140
    22016.0    330752.0    330752.0    330752.0   178 17840 3104.912 3107.137
    22016.0    330752.0    330752.0    330752.0   178 17870 3109.847 3112.073

字段说明:

字段说明
OGCMN老年代最小容量
OGCMX老年代最大容量
OGC当前老年代大小
OC老年代大小
YGC年轻代垃圾回收次数
FGC老年代垃圾回收次数
FGCT老年代垃圾回收消耗时间
GCT垃圾回收消耗总时间

11、jstat -gcmetacapacity pid 5000 20 : 元数据空间统计

5秒钟打印一次,一共打印20次。

jstat -gcmetacapacity pid 5000 20

输出结果:

root@yzh-zabbix-server:bin #jstat -gcmetacapacity 3111 5000 20
   MCMN       MCMX        MC       CCSMN      CCSMX       CCSC     YGC   FGC    FGCT     GCT   
    0.0     1097728.0    55552.0    0.0     1048576.0     6400.0   178  18795  3270.543 3272.768
    0.0     1097728.0    55552.0    0.0     1048576.0     6400.0   178  18824  3275.425 3277.650
    0.0     1097728.0    55552.0    0.0     1048576.0     6400.0   178  18853  3280.369 3282.595

字段说明:

字段说明
MCMN最小元数据容量
MCMX最大元数据容量
MC当前元数据空间大小
CCSMN最小压缩类空间大小
CCSMX最大压缩类空间大小
CCSC当前压缩类空间大小
YGC年轻代垃圾回收次数
FGC老年代垃圾回收次数
FGCT老年代垃圾回收消耗时间
GCT垃圾回收消耗总时间

12、jstat -printcompilation pid : 编译方法统计

jstat -printcompilation -pid

输出结果:

Compiled  Size  Type Method
   3745      8    1  java/lang/Long toString

字段说明:

字段说明
Compiled被执行的编译任务的数量
Size方法字节码的字节数
Type编译类型
Method编译方法的类名和方法名。类名使用"/" 代替 “.” 作为空间分隔符. 方法名是给出类的方法名. 格式是一致于HotSpot - XX:+PrintComplation 选项



  • 17
    点赞
  • 64
    收藏
    觉得还不错? 一键收藏
  • 4
    评论
评论 4
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值