jstat是JDK自带的一个轻量级小工具。全称“Java Virtual Machine statistics monitoring tool”,它位于java的bin目录下,主要利用JVM内建的指令对Java应用程序的资源和性能进行实时的命令行的监控,包括了对Heap size和垃圾回收情况的监控。css
jstat 是用于见识虚拟机各类运行状态信息的命令行工具。它能够显示本地或者远程虚拟机进程中的类装载、内存、垃圾收集、jit编译等运行数据,它是线上定位jvm性能的首选工具。java
jstat [ generalOption | outputOptions vmid [interval[s|ms] [count]] ]python
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. # option: 参数选项 # -t: 能够在打印的列加上Timestamp列,用于显示系统运行的时间 # -h: 能够在周期性数据数据的时候,能够在指定输出多少行之后输出一次表头 # vmid: Virtual Machine ID( 进程的 pid) # interval: 执行每次的间隔时间,单位为毫秒 # count: 用于指定输出多少次记录,缺省则会一直打印
> jstat -options -class 显示ClassLoad的相关信息; -compiler 显示JIT编译的相关信息; -gc 显示和gc相关的堆信息; -gccapacity 显示各个代的容量以及使用状况; -gcmetacapacity 显示metaspace的大小 -gcnew 显示新生代信息; -gcnewcapacity 显示新生代大小和使用状况; -gcold 显示老年代和永久代的信息; -gcoldcapacity 显示老年代的大小; -gcutil 显示垃圾收集信息; -gccause 显示垃圾回收的相关信息(通-gcutil),同时显示最后一次或当前正在发生的垃圾回收的诱因; -printcompilation 输出JIT编译的方法信息
参数名称 | 参数说明
---|---|---
class | 用于查看类加载状况的统计,显示加载class的数量,及所占空间等信息。
compiler | 查看HotSpot中即时编译器编译状况的统计
gc | 查看JVM中堆的垃圾收集状况的统计,能够显示gc的信息,查看gc的次数,及时间。其中最后五项,分别是young gc的次数,young gc的时间,full gc的次数,full gc的时间,gc的总时间。
gccapacity | 查看新生代、老生代及持久代的存储容量状况,能够显示,VM内存中三代(young,old,perm)对象的使用和占用大小
gccause | 查看垃圾收集的统计状况(这个和-gcutil选项同样),若是有发生垃圾收集,它还会显示最后一次及当前正在发生垃圾收集的缘由
gcmetacapacity | 显示关于metaspace大小的统计信息。
gcnew | 查看新生代垃圾收集的状况,new对象的信息
gcnewcapacity | 用于查看新生代的存储容量状况,new对象的信息及其占用量
gcold | 用于查看老生代及持久代发生GC的状况,old对象的信息
gcoldcapacity | 用于查看老生代的容量,old对象的信息及其占用量
gcpermcapacity | 用于查看持久代的容量,perm对象的信息及其占用量
gcutil | 查看新生代、老生代及持代垃圾收集的状况
printcompilation | 当前VM执行的信息apache
# 在屏幕打印出一次结果 > jstat -gccause pid # 不断的在屏幕打印出结果 > jstat -gccause pid 1 每格1毫秒输出结果 > jstat -gccause pid 2000 每格2秒输出结果
PS C:\> PS C:\> jstat -class 6368 Loaded Bytes Unloaded Bytes Time 1846 3621.2 0 0.0 0.98 PS C:\>
PS C:\> jstat -compiler 6368 Compiled Failed Invalid Time FailedType FailedMethod 791 0 0 1.17 0 PS C:\>
PS C:\> jstat -gc 6368 S0C S1C S0U S1U EC EU OC OU MC MU CCSC CCSU YGC YGCT FGC FGCT GCT 5120.0 5120.0 0.0 0.0 32768.0 29858.7 86016.0 0.0 4480.0 770.3 384.0 75.9 0 0.000 0 0.000 0.000 PS C:\>
PS C:\> jstat -gccapacity 6368 NGCMN NGCMX NGC S0C S1C EC OGCMN OGCMX OGC OC MCMN MCMX MC CCSMN CCSMX CCSC YGC FGC 43008.0 687104.0 43008.0 5120.0 5120.0 32768.0 86016.0 1375232.0 86016.0 86016.0 0.0 1056768.0 4480.0 0.0 1048576.0 384.0 0 0 PS C:\>
PS C:\> jstat -gcnew 6368 S0C S1C S0U S1U TT MTT DSS EC EU YGC YGCT 5120.0 5120.0 0.0 0.0 15 15 0.0 32768.0 29858.7 0 0.000 PS C:\>
PS C:\> jstat -gcnewcapacity 6368 NGCMN NGCMX NGC S0CMX S0C S1CMX S1C ECMX EC YGC FGC 43008.0 687104.0 43008.0 228864.0 5120.0 228864.0 5120.0 686080.0 32768.0 0 0 PS C:\>
PS C:\> jstat -gcold 6368 MC MU CCSC CCSU OC OU YGC FGC FGCT GCT 4480.0 770.3 384.0 75.9 86016.0 0.0 0 0 0.000 0.000 PS C:\>
PS C:\> jstat -gcoldcapacity 6368 OGCMN OGCMX OGC OC YGC FGC FGCT GCT 86016.0 1375232.0 86016.0 86016.0 0 0 0.000 0.000 PS C:\>
PS C:\> jstat -gcmetacapacity 6368 MCMN MCMX MC CCSMN CCSMX CCSC YGC FGC FGCT GCT 0.0 1056768.0 4480.0 0.0 1048576.0 384.0 0 0 0.000 0.000 PS C:\>
PS C:\> jstat -gcutil 6368 S0 S1 E O M CCS YGC YGCT FGC FGCT GCT 0.00 0.00 91.12 0.00 17.19 19.76 0 0.000 0 0.000 0.000 PS C:\>
PS C:\> jstat -printcompilation 6368 Compiled Size Type Method 791 5510 1 com/sun/org/apache/xerces/internal/impl/XMLDocumentFragmentScannerImpl$FragmentContentDriver next PS C:\>