目录
jstat查询虚拟机信息主要有3类:类装载、垃圾收集、运行期编译状况
使用场景说明
jstat(JVM Statistics Monitoring Tool):用于监视虚拟机各种运行状态信息的命令行工具
显示信息:本地获取远程虚拟机进程中的类装载、内存、垃圾收集、JIT编译等运行数据
适合场景:在纯文本控制台环境上,是运行定位虚拟机性能问题的首选工具
jstat格式:jstat 选项 虚拟机进程ID [ [ 间隔时间] [ 单位秒|毫秒 ] [ 查询次数 ] ]
查询
第一步:先通过jps查询虚拟机进程ID
jps -l
查询到正在运行的springboot项目MyTallyApplication虚拟机进程ID=11784
C:\Users\guangang>jps -l
2224 sun.tools.jps.Jps
28624
28132 org.jetbrains.idea.maven.server.RemoteMavenServer
11784 com.gg.MyTallyApplication
22856 org.jetbrains.jps.cmdline.Launcher
jstat查询虚拟机信息主要有3类:类装载、垃圾收集、运行期编译状况
类装载
jstat -class 11784 250 10
监视类装载、卸载数量、总空间和类装载锁耗费的时间(每250毫秒输出一次,总共输出10次
C:\Users\guangang>jstat -class 11784 250 10
Loaded Bytes Unloaded Bytes Time
11966 21580.1 1 0.9 4.04
11966 21580.1 1 0.9 4.04
11966 21580.1 1 0.9 4.04
11966 21580.1 1 0.9 4.04
11966 21580.1 1 0.9 4.04
11966 21580.1 1 0.9 4.04
11966 21580.1 1 0.9 4.04
11966 21580.1 1 0.9 4.04
11966 21580.1 1 0.9 4.04
11966 21580.1 1 0.9 4.04
垃圾收集相关
字符代表的含义列表
E | 表示Eden |
S0、S1 | 表示survivor0和survivor1 |
O\OLD | 老年代 |
P | Permanent永久代 |
YGC | Minor GC |
FGC | FULL GC |
FGCT | FULL GC耗时 |
jstat -gc 11784 250 2
监视java堆状况,包括Eden区,survivor区、老年代、永久代、医用空间、GC时间合计等信息
C:\Users\guangang>jstat -gc 11784 250 2
S0C S1C S0U S1U EC EU OC OU MC MU CCSC CCSU YGC YGCT FGC FGCT GCT
16896.0 20480.0 0.0 0.0 298496.0 38325.2 347648.0 30344.3 59136.0 55938.7 8192.0 7632.8 8 0.058 3 0.217 0.275
16896.0 20480.0 0.0 0.0 298496.0 38325.2 347648.0 30344.3 59136.0 55938.7 8192.0 7632.8 8 0.058 3 0.217 0.275
jstat -gccapacity 11784 250 2
监视内容与-gc基本相同,输出主要关注各个区域使用到的最大、最小空间
C:\Users\guangang>jstat -gccapacity 11784 250 2
NGCMN NGCMX NGC S0C S1C EC OGCMN OGCMX OGC OC MCMN MCMX MC CCSMN CCSMX CCSC YGC FGC
131072.0 2086912.0 364544.0 16896.0 20480.0 298496.0 262144.0 4173824.0 347648.0 347648.0 0.0 1099776.0 59136.0 0.0 1048576.0 8192.0 8 3
131072.0 2086912.0 364544.0 16896.0 20480.0 298496.0 262144.0 4173824.0 347648.0 347648.0 0.0 1099776.0 59136.0 0.0 1048576.0 8192.0 8 3
jstat -gcutil 11784 250 2
已经使用空间和总空间的百分比
C:\Users\guangang>jstat -gcutil 11784 250 2
S0 S1 E O M CCS YGC YGCT FGC FGCT GCT
0.00 0.00 12.84 8.73 94.59 93.17 8 0.058 3 0.217 0.275
0.00 0.00 12.84 8.73 94.59 93.17 8 0.058 3 0.217 0.275
jstat -gccause 11784 250 2
与-gcutil基本相同:会输出导致上一次GC产生的原因
C:\Users\guangang>jstat -gccause 11784 250 2
S0 S1 E O M CCS YGC YGCT FGC FGCT GCT LGCC GCC
0.00 0.00 12.84 8.73 94.59 93.17 8 0.058 3 0.217 0.275 Metadata GC Threshold No GC
0.00 0.00 12.84 8.73 94.59 93.17 8 0.058 3 0.217 0.275 Metadata GC Threshold No GC
jstat -gcnew 11784 250 2
减产新生代GC情况
C:\Users\guangang>jstat -gcnew 11784 250 2
S0C S1C S0U S1U TT MTT DSS EC EU YGC YGCT
16896.0 20480.0 0.0 0.0 5 15 20480.0 298496.0 38325.2 8 0.058
16896.0 20480.0 0.0 0.0 5 15 20480.0 298496.0 38325.2 8 0.058
jstat -gcnewcapacity 11784 250 2
与-gcnew基本相同,主要关注最大最小空间
C:\Users\guangang>jstat -gcnewcapacity 11784 250 2
NGCMN NGCMX NGC S0CMX S0C S1CMX S1C ECMX EC YGC FGC
131072.0 2086912.0 364544.0 695296.0 16896.0 695296.0 20480.0 2085888.0 298496.0 8 3
131072.0 2086912.0 364544.0 695296.0 16896.0 695296.0 20480.0 2085888.0 298496.0 8 3
jstat -gcold 11784 250 2
老年代gc情况
C:\Users\guangang>jstat -gcold 11784 250 2
MC MU CCSC CCSU OC OU YGC FGC FGCT GCT
59136.0 55938.7 8192.0 7632.8 347648.0 30344.3 8 3 0.217 0.275
59136.0 55938.7 8192.0 7632.8 347648.0 30344.3 8 3 0.217 0.275
jstat -gcoldcapacity 11784 250 2
老年代gc情况,主要关注最大最小空间
C:\Users\guangang>jstat -gcoldcapacity 11784 250 2
OGCMN OGCMX OGC OC YGC FGC FGCT GCT
262144.0 4173824.0 347648.0 347648.0 8 3 0.217 0.275
262144.0 4173824.0 347648.0 347648.0 8 3 0.217 0.275
jstat -gcpermcapacity 11784 250 2
输出永久代最大最小空间,照着书上打的,不晓得为啥没效果了
C:\Users\guangang>jstat -gcpermcapacity 11784 250 2
Unknown option: -gcpermcapacity
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 -compiler 11784 250 2
输出JIT编译器编译过的方法和耗时等细腻
C:\Users\guangang>jstat -compiler 11784 250 2
Compiled Failed Invalid Time FailedType FailedMethod
5537 0 0 1.14 0
5537 0 0 1.14 0
jstat -printcompilation 11784 250 2
输出已经被jIT编译的方法
C:\Users\guangang>jstat -printcompilation 11784 250 2
Compiled Size Type Method
5538 12 1 java/io/IOException <init>
5538 12 1 java/io/IOException <init>