Jstat全称JVM Statistics Monitoring Tool,用于监视虚拟机各种运行状态信息的命令工具。它可以显示本地或者远程虚拟机进程中的类装载、内存、垃圾收集、JIT编译等运行数据
jstat -help,查看帮助信息:
[root@iZwz96yphgzn3atc5wa1b1Z logs]# 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.
interval参数用于指定输出统计数据的周期,单位毫秒,即查询间隔
count参数用于指定查询的次数
-t参数用于显示程序运行的时间
-h参数在周期性输出数据时,输出多少行后输出一个表头信息
option可以由一下值构成:
- 类装载相关
- -class:显示ClassLoader的相关信息:类的装载、卸载数量、总空间、类装载所消耗的时间等信息(需要先用jps查看java进程号)
C:\Users\lenovo>jstat -class 21236 Loaded Bytes Unloaded Bytes Time 714 1386.2 0 0.0 0.08
- -class:显示ClassLoader的相关信息:类的装载、卸载数量、总空间、类装载所消耗的时间等信息(需要先用jps查看java进程号)
- 垃圾回收相关
- -gc:显示GC相关的堆信息。包括Eden区、两个Survivor区、老年代、永久代(jdk8叫元空间)等的容量、已用空间、GC时间合计等信息:
jstat -gc -t -h2 21236 1000 10 表示:监控进程号为21236java进程堆信息,每个1秒打印一次,每次都输出对应的时间,每两次输出一次表头信息,总共打印10次。
(S0C表示幸存者0区的容量,S1C表示幸存者1区的容量,S0U表示幸存者0区使用容量,EC表示伊甸园区的容量,EU表示伊甸园区使用的容量,OC表示老年代的容量,OU表示老年代使用的容量,MC表示元空间的容量,MU表示元空间使用的容量,CCSC表示压缩类的容量,CCSU压缩类使用的容量,YGC表示YoungGC发生的次数,YGCT表示YoungGC的耗时,FGC表示FullGC发生的次数,FGCT表示FullGC的耗时,GCT表示发生GC的总时长[GCT=YGCT+FGCT]) -
C:\Users\lenovo>jstat -gc -t -h2 21236 1000 10 Timestamp S0C S1C S0U S1U EC EU OC OU MC MU CCSC CCSU YGC YGCT FGC FGCT GCT 1464.2 1024.0 1024.0 0.0 0.0 8192.0 4155.5 10240.0 0.0 4480.0 769.7 384.0 75.8 0 0.000 0 0.000 0.000 1465.2 1024.0 1024.0 0.0 0.0 8192.0 4155.5 10240.0 0.0 4480.0 769.7 384.0 75.8 0 0.000 0 0.000 0.000 Timestamp S0C S1C S0U S1U EC EU OC OU MC MU CCSC CCSU YGC YGCT FGC FGCT GCT 1466.2 1024.0 1024.0 0.0 0.0 8192.0 4155.5 10240.0 0.0 4480.0 769.7 384.0 75.8 0 0.000 0 0.000 0.000 1467.3 1024.0 1024.0 0.0 0.0 8192.0 4155.5 10240.0 0.0 4480.0 769.7 384.0 75.8 0 0.000 0 0.000 0.000 Timestamp S0C S1C S0U S1U EC EU OC OU MC MU CCSC CCSU YGC YGCT FGC FGCT GCT 1468.2 1024.0 1024.0 0.0 0.0 8192.0 4155.5 10240.0 0.0 4480.0 769.7 384.0 75.8 0 0.000 0 0.000 0.000 1469.2 1024.0 1024.0 0.0 0.0 8192.0 4155.5 10240.0 0.0 4480.0 769.7 384.0 75.8 0 0.000 0 0.000 0.000 Timestamp S0C S1C S0U S1U EC EU OC OU MC MU CCSC CCSU YGC YGCT FGC FGCT GCT 1470.3 1024.0 1024.0 0.0 0.0 8192.0 4155.5 10240.0 0.0 4480.0 769.7 384.0 75.8 0 0.000 0 0.000 0.000 1471.2 1024.0 1024.0 0.0 0.0 8192.0 4155.5 10240.0 0.0 4480.0 769.7 384.0 75.8 0 0.000 0 0.000 0.000 Timestamp S0C S1C S0U S1U EC EU OC OU MC MU CCSC CCSU YGC YGCT FGC FGCT GCT 1472.2 1024.0 1024.0 0.0 0.0 8192.0 4155.5 10240.0 0.0 4480.0 769.7 384.0 75.8 0 0.000 0 0.000 0.000 1473.3 1024.0 1024.0 0.0 0.0 8192.0 4155.5 10240.0 0.0 4480.0 769.7 384.0 75.8 0 0.000 0 0.000 0.000
- -gccapacity:与-gc输出的基本相同,但是输出的主要关注Java堆各个空间的区域的用到的最大、最小空间
- -gcutil:与-gc输出的基本相同,但是输出信息主要关注使用空间占总空间的百分比
- -gccause:与-gcutil输出的基本相同,但是会输出导致最后一次或者当前正在发生gc产生的原因
- -gcnew:显示新生代的状状况
- -gcnewcapacity:与-gcnew显示的基本相同,输出主要关注使用到的最大、最小的空间
- -gcold:显示老年代的状况
- -gc:显示GC相关的堆信息。包括Eden区、两个Survivor区、老年代、永久代(jdk8叫元空间)等的容量、已用空间、GC时间合计等信息:
- JIT相关
- -compiler:显示被JIT编译过的方法、耗时等信息(需要先用jps查看java进程号)
C:\Users\lenovo>jstat -compiler 21236 Compiled Failed Invalid Time FailedType FailedMethod 167 0 0 0.04 0
- -printcompilation:输出已经被编译的方法(需要先用jps查看java进程号)
C:\Users\lenovo>jstat -printcompilation 21236 Compiled Size Type Method 167 5 1 java/nio/Buffer position
- -compiler:显示被JIT编译过的方法、耗时等信息(需要先用jps查看java进程号)