Jstat

mac2024-04-02  39

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类加载器compilerJITgcgc堆状态gccapacity各区大小gccause最近一次gc统计和原因gcnewcapacity新区大小gcold老区统计gcoldcapacity老区大小gcpermcapacity永久区大小gcutilGC统计汇总printcompilationHotSpot编译统计 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 ~]# 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)