Jstat

Jstat是JDK自带的一个轻量级小工具,全称"Java Vitual Machine statistics monitoring tool" 它位于java的bin目录下,主要利用JVM内建的指令对Java应用程序的资源和性能进行实时的命令行的监控,包括了对Heap size和垃圾回收状况的监控。可见,Jstat是轻量级的、专门针对JVM的工具,非常适用。

使用方法如下:

[root@01 ]# 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.

常见options 及说明:

选项说明
class类加载器
compilerJIT
gcgc堆状态
gccapacity各区大小
gccause最近一次gc统计和原因
gcnewcapacity新区大小
gcold老区统计
gcoldcapacity老区大小
gcpermcapacity永久区大小
gcutilGC统计汇总
printcompilationHotSpot编译统计
  1. jstat -class <pid>: 显示加载class数量,及所占空间等信息。
显示列明具体描述
Loaded装载的类的数量
Bytes装载类所占用的字节数
Unloaded卸载类的数量
Bytes卸载类的字节数
Time装载和卸载类所花费的时间

示例:

[root@hqbs-group-01 ~]# jstat -class 10631
Loaded  Bytes  Unloaded  Bytes     Time
 10499 17459.3     6211  9604.4       3.55
[root@hqbs-group-01 ~]#

2.jstat -compiler <pid>:显示VM实时编译的数量等信息。

显示列名具体描述
Compiled编译任务执行数量
Failed编译任务执行失败数量
Invalid编译任务执行失效数量
Time编译任务消耗时间
FailedType最后一个编译失败任务的类型
FailedMethod最后一个编译失败任务所在的类及方法

示例:

[root@01 ~]# jstat -compiler 10631
Warning: Unresolved Symbol: sun.ci.totalCompiles substituted NaN
Warning: Unresolved Symbol: sun.ci.totalBailouts substituted NaN
Warning: Unresolved Symbol: sun.ci.totalInvalidates substituted NaN
Warning: Unresolved Symbol: java.ci.totalTime substituted NaN
Warning: Unresolved Symbol: sun.ci.lastFailedType substituted NaN
Warning: Unresolved Symbol: sun.ci.lastFailedMethod substituted NaN
Compiled Failed Invalid   Time   FailedType FailedMethod
       -      -       -        -          - -
[root@01 ~]#

3.jstat -gc <pid>:可以显示gc的信息,查看gc的次数,及时间。

显示列名具体描述
S0C年轻代中第一个survivor(幸存区)的容量 (字节)
S1C年轻代中第二个survivor(幸存区)的容量 (字节)
S0U年轻代中第一个survivor(幸存区)目前已使用空间 (字节)
S1U年轻代中第二个survivor(幸存区)目前已使用空间 (字节)
EC年轻代中Eden(伊甸园)的容量 (字节)
EU年轻代中Eden(伊甸园)目前已使用空间 (字节)
OCOld代的容量 (字节)
OUOld代目前已使用空间 (字节)
MC方法区大小(字节)
MU方法区使用大小(字节)
CCSC压缩类空间大小
CCSU压缩类空间使用大小
YGC从应用程序启动到采样时年轻代垃圾回收次数
YGCT从应用程序启动到采样时年轻代垃圾回收消耗时间
FGC从应用程序启动到采样时老年代垃圾回收次数
FGCT从应用程序启动到采样时老年代垃圾回收消耗时间
GCT从应用程序启动到采样时垃圾回收消耗总时间

示例:

[root@-01 ~]# jstat -gc 10631
 S0C    S1C    S0U    S1U      EC       EU        OC         OU       MC     MU    CCSC   CCSU   YGC     YGCT    FGC    FGCT     GCT
1216.0 1216.0  0.0   146.3  10240.0   5659.0   12600.0     8229.3   29044.0 20782.3 6656.0 2791.1  96117  155.466   5      0.125  155.591
[root@-01 ~]# jstat -gc 10631 2 10
 S0C    S1C    S0U    S1U      EC       EU        OC         OU       MC     MU    CCSC   CCSU   YGC     YGCT    FGC    FGCT     GCT
1216.0 1216.0 148.2   0.0   10240.0   5376.9   12600.0     8229.3   29044.0 20782.3 6656.0 2791.1  96120  155.470   5      0.125  155.595
1216.0 1216.0 148.2   0.0   10240.0   5376.9   12600.0     8229.3   29044.0 20782.3 6656.0 2791.1  96120  155.470   5      0.125  155.595
1216.0 1216.0 148.2   0.0   10240.0   5376.9   12600.0     8229.3   29044.0 20782.3 6656.0 2791.1  96120  155.470   5      0.125  155.595
1216.0 1216.0 148.2   0.0   10240.0   5376.9   12600.0     8229.3   29044.0 20782.3 6656.0 2791.1  96120  155.470   5      0.125  155.595
1216.0 1216.0 148.2   0.0   10240.0   5376.9   12600.0     8229.3   29044.0 20782.3 6656.0 2791.1  96120  155.470   5      0.125  155.595
1216.0 1216.0 148.2   0.0   10240.0   5377.2   12600.0     8229.3   29044.0 20782.3 6656.0 2791.1  96120  155.470   5      0.125  155.595
1216.0 1216.0 148.2   0.0   10240.0   5377.2   12600.0     8229.3   29044.0 20782.3 6656.0 2791.1  96120  155.470   5      0.125  155.595
1216.0 1216.0 148.2   0.0   10240.0   5377.2   12600.0     8229.3   29044.0 20782.3 6656.0 2791.1  96120  155.470   5      0.125  155.595
1216.0 1216.0 148.2   0.0   10240.0   5377.2   12600.0     8229.3   29044.0 20782.3 6656.0 2791.1  96120  155.470   5      0.125  155.595
1216.0 1216.0 148.2   0.0   10240.0   5377.2   12600.0     8229.3   29044.0 20782.3 6656.0 2791.1  96120  155.470   5      0.125  155.595
[root@-01 ~]#

4.jstat -gccapacity <pid>: 可以显示,VM内存中三代(young,old,perm)对象的使用和占用大小

显示列名具体描述
NGCMN新生代最小容量
NGCMX新生代最大容量
NGC当前新生代容量
S0C第一个幸存区大小
S1C第二个幸存区的大小
EC伊甸园区的大小
OGCMN老年代最小容量
OGCMX老年代最大容量
OGCold代当前新生成的容量 (字节)
OC当前老年代大小
MCMN最小元数据容量
MCMX最大元数据容量
MC当前元数据空间大小
CCSMN最小压缩类空间大小
CCSMX最大压缩类空间大小
CCSC当前压缩类空间大小
YGC年轻代gc次数
FGC老年代GC次数

示例:

[root@01 ~]# jstat -gccapacity 10631
 NGCMN    NGCMX     NGC     S0C   S1C       EC      OGCMN      OGCMX       OGC         OC       MCMN     MCMX      MC     CCSMN    CCSMX     CCSC    YGC    FGC
  8192.0  16384.0  12672.0 1216.0 1216.0  10240.0     8192.0    16384.0    12600.0    12600.0      0.0 1071104.0  29044.0      0.0 1048576.0   6656.0  96122     5
[root@01 ~]#
  1. jstat -gcutil :`统计gc信息。
显示列名具体描述
S0幸存1区当前使用比例
S1幸存2区当前使用比例
E伊甸园区使用比例
O老年代使用比例
M元数据区使用比例
CCS压缩使用比例
YGC年轻代垃圾回收次数
YGCT从应用程序启动到采样时年轻代中gc所用时间(s)
FGC老年代垃圾回收次数
FGCT老年代垃圾回收消耗时间
GCT垃圾回收消耗总时间

示例:

[root@01 ~]# jstat -gcutil 10631
  S0     S1     E      O      M     CCS    YGC     YGCT    FGC    FGCT     GCT
  0.00  23.53  94.33  65.33  71.55  41.93  96129  155.484     5    0.125  155.609

6、jstat -gcnew <pid>:年轻代对象的信息。

显示列名具体描述
S0C第一个幸存区的大小(字节)
S1C第二个幸存区的大小
S0U第一个幸存区的使用大小
S1U第二个幸存区的使用大小
TT对象在新生代存活的次数
MTT对象在新生代存活的最大次数
DSS期望的幸存区大小
EC伊甸园区的大小
EU伊甸园区的使用大小
YGC年轻代垃圾回收次数
YGCT年轻代垃圾回收消耗时间

示例:

[root@01 ~]# jstat -gcnew 32011
 S0C    S1C    S0U    S1U   TT MTT  DSS      EC       EU     YGC     YGCT
1024.0 1024.0  256.0    0.0  1  15 1024.0 1472512.0 1097625.6  12494  115.353
[root@01 ~]# jstat -gcnew 10631
 S0C    S1C    S0U    S1U   TT MTT  DSS      EC       EU     YGC     YGCT
1216.0 1216.0  156.9    0.0 15  15  608.0  10240.0   5212.0  96138  155.498
[root@01 ~]#

7、jstat -gcnewcapacity<pid>: 年轻代对象的信息及其占用量。

显示列名具体描述
NGCMN新生代最小容量
NGCMX新生代最大容量
NGC当前新生代容量
S0CMX最大幸存1区大小
S0C当前幸存1区大小
S1CMX最大幸存2区大小
S1C当前幸存2区大小
ECMX最大伊甸园区大小
EC当前伊甸园区大小
YGC年轻代垃圾回收次数
FGC老年代回收次数

示例:

[root@01 ~]# jstat -gcnewcapacity 10631
  NGCMN      NGCMX       NGC      S0CMX     S0C     S1CMX     S1C       ECMX        EC      YGC   FGC
    8192.0    16384.0    12672.0   1600.0   1216.0   1600.0   1216.0    13184.0    10240.0 96140     5
[root@01 ~]# jstat -gcnewcapacity 32011
  NGCMN      NGCMX       NGC      S0CMX     S0C     S1CMX     S1C       ECMX        EC      YGC   FGC
 1474560.0  1474560.0  1474560.0 491520.0   1024.0 491520.0   1024.0  1473536.0  1472512.0 12495     0
[root@01 ~]#

8、jstat -gcold <pid>:old代对象的信息。

显示列名具体描述
MC方法区大小
MU方法区使用大小
CSCC压缩类空间大小
CSCU压缩类空间使用大小
OC老年代大小
OU老年代使用大小
YGC年轻代垃圾回收次数
FGC老年代垃圾回收次数
FGCT老年代垃圾回收消耗时间
GCT垃圾回收消耗总时间

示例:

[root@01 ~]# jstat -gcold 10631
   MC       MU      CCSC     CCSU       OC          OU       YGC    FGC    FGCT     GCT
 29044.0  20782.3   6656.0   2791.1     12600.0      8231.4  96142     5    0.125  155.630
[root@01 ~]# jstat -gcold 32011
   MC       MU      CCSC     CCSU       OC          OU       YGC    FGC    FGCT     GCT
104832.0 100731.4  11648.0  10935.6   1671168.0   1147747.1  12496     0    0.000  115.374
[root@01 ~]#

9、jstat -gcoldcapacity <pid>: old代对象的信息及其占用量。

示例:

[root@01 ~]# jstat -gcoldcapacity 32011
   OGCMN       OGCMX        OGC         OC       YGC   FGC    FGCT     GCT
  1671168.0   1671168.0   1671168.0   1671168.0 12496     0    0.000  115.374
[root@01 ~]# jstat -gcoldcapacity 10631
   OGCMN       OGCMX        OGC         OC       YGC   FGC    FGCT     GCT
     8192.0     16384.0     12600.0     12600.0 96145     5    0.125  155.634
[root@01 ~]#
显示列名具体描述
OGCMN老年代最小容量
OGCMX老年代最大容量
OGC当前老年代大小
OC老年代大小
YGC年轻代垃圾回收次数
FGC老年代垃圾回收次数
FGCT老年代垃圾回收消耗时间
GCT垃圾回收消耗总时间

参考链接:

https://blog.csdn.net/zhaozheng7758/article/details/8623549

https://blog.csdn.net/maosijunzi/article/details/46049117

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值