摘要:jstat命令可以查看堆内存各部分的使用量,以及加载类的数量。
本文分享自华为云社区《JVM之通过jstat命令进行查看堆内存使用情况》,作者:共饮一杯无 。
jstat是JDK自带的一个轻量级小工具。它位于java的bin目录下,主要利用JVM内建的指令对Java应用程序的资源和性能进行实时的命令行的监控,包括了对Heap size和垃圾回收状况的监控。jstat命令可以查看堆内存各部分的使用量,以及加载类的数量。命令的格式如下:
jstat [-命令选项] [vmid] [间隔时间/毫秒] [查询次数]
C:\Users\zjq>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.
说明:
option 可以从下面参数中选择
jstat -options
C:\Users\zjq>jps 24832 Jps 21180 Bootstrap C:\Users\zjq>jstat -class 21180 Loaded Bytes Unloaded Bytes Time 3800 7339.7 409 783.0 6.35
说明:
C:\Users\zjq>jstat -compiler 21180 Compiled Failed Invalid Time FailedType FailedMethod 2743 0 0 10.53 0
说明:
C:\Users\zjq>jstat -gc 21180 S0C S1C S0U S1U EC EU OC OU MC MU CCSC CCSU YGC YGCT FGC FGCT GCT 28160.0 30208.0 0.0 0.0 260096.0 163920.6 115712.0 27193.7 21248.0 18539.6 2560.0 2053.2 6 0.096 1 0.057 0.153 #也可以指定打印的间隔和次数,每1秒中打印一次,共打印5次 C:\Users\zjq>jstat -gc 21180 1000 3 S0C S1C S0U S1U EC EU OC OU MC MU CCSC CCSU YGC YGCT FGC FGCT GCT 28160.0 30208.0 0.0 0.0 260096.0 171724.8 115712.0 27193.7 21248.0 18539.6 2560.0 2053.2 6 0.096 1 0.057 0.153 28160.0 30208.0 0.0 0.0 260096.0 172592.0 115712.0 27193.7 21248.0 18539.6 2560.0 2053.2 6 0.096 1 0.057 0.153 28160.0 30208.0 0.0 0.0 260096.0 172592.0 115712.0 27193.7 21248.0 18539.6 2560.0 2053.2 6 0.096 1 0.057 0.153
说明:
[root@zjq ~]# jstat -gccapacity 3346 #用于查看新生代、老生代及持久代的存储容量情况 NGCMN NGCMX NGC S0C S1C EC OGCMN OGCMX OGC OC MCMN MCMX MC CCSMN CCSMX CCSC YGC FGC 1280.0 83264.0 1280.0 128.0 128.0 1024.0 15104.0 166592.0 15104.0 15104.0 0.0 1056768.0 8448.0 0.0 1048576.0 1024.0 7 0 [root@zjq ~]# jstat -gccapacity -h5 3346 1000 #-h5:每5行显示一次表头 1000:每1秒钟显示一次,单位为毫秒 NGCMN NGCMX NGC S0C S1C EC OGCMN OGCMX OGC OC MCMN MCMX MC CCSMN CCSMX CCSC YGC FGC 1280.0 83264.0 1280.0 128.0 128.0 1024.0 15104.0 166592.0 15104.0 15104.0 0.0 1056768.0 8448.0 0.0 1048576.0 1024.0 7 0 1280.0 83264.0 1280.0 128.0 128.0 1024.0 15104.0 166592.0 15104.0 15104.0 0.0 1056768.0 8448.0 0.0 1048576.0 1024.0 7 0 1280.0 83264.0 1280.0 128.0 128.0 1024.0 15104.0 166592.0 15104.0 15104.0 0.0 1056768.0 8448.0 0.0 1048576.0 1024.0 7 0 1280.0 83264.0 1280.0 128.0 128.0 1024.0 15104.0 166592.0 15104.0 15104.0 0.0 1056768.0 8448.0 0.0 1048576.0 1024.0 7 0 1280.0 83264.0 1280.0 128.0 128.0 1024.0 15104.0 166592.0 15104.0 15104.0 0.0 1056768.0 8448.0 0.0 1048576.0 1024.0 7 0 NGCMN NGCMX NGC S0C S1C EC OGCMN OGCMX OGC OC MCMN MCMX MC CCSMN CCSMX CCSC YGC FGC 1280.0 83264.0 1280.0 128.0 128.0 1024.0 15104.0 166592.0 15104.0 15104.0 0.0 1056768.0 8448.0 0.0 1048576.0 1024.0 7 0 1280.0 83264.0 1280.0 128.0 128.0 1024.0 15104.0 166592.0 15104.0 15104.0 0.0 1056768.0 8448.0 0.0 1048576.0 1024.0 7 0 1280.0 83264.0 1280.0 128.0 128.0 1024.0 15104.0 166592.0 15104.0 15104.0 0.0 1056768.0 8448.0 0.0 1048576.0 1024.0 7 0 1280.0 83264.0 1280.0 128.0 128.0 1024.0 15104.0 166592.0 15104.0 15104.0 0.0 1056768.0 8448.0 0.0 1048576.0 1024.0 7 0
[root@zjq ~]# jstat -gcmetacapacity 3346 #显示元数据空间的大小 MCMN MCMX MC CCSMN CCSMX CCSC YGC FGC FGCT GCT 0.0 1056768.0 8448.0 0.0 1048576.0 1024.0 8 0 0.000 0.020
[root@zjq ~]# jstat -gcnew 3346 #用于查看新生代垃圾收集的情况 S0C S1C S0U S1U TT MTT DSS EC EU YGC YGCT 128.0 128.0 67.8 0.0 1 15 64.0 1024.0 362.2 8 0.020
[root@zjq ~]# jstat -gcnewcapacity 3346 #用于查看新生代存储容量的情况 NGCMN NGCMX NGC S0CMX S0C S1CMX S1C ECMX EC YGC FGC 1280.0 83264.0 1280.0 8320.0 128.0 8320.0 128.0 66624.0 1024.0 8 0
[root@zjq~]# jstat -gcold 3346 #用于查看老年代及持久代垃圾收集的情况 MC MU CCSC CCSU OC OU YGC FGC FGCT GCT 8448.0 8227.5 1024.0 1003.7 15104.0 2102.2 8 0 0.000 0.020
[root@zjq~]# jstat -gcoldcapacity 3346 #用于查看老年代的容量 OGCMN OGCMX OGC OC YGC FGC FGCT GCT 15104.0 166592.0 15104.0 15104.0 8 0 0.000 0.020
[root@zjq~]# jstat -gcutil 3346 #显示垃圾收集信息 S0 S1 E O M CCS YGC YGCT FGC FGCT GCT 52.97 0.00 42.10 13.92 97.39 98.02 8 0.020 0 0.000 0.020
[root@zjq~]# jstat -gccause 3346 #显示垃圾回收的相关信息(同-gcutil),同时显示最后一次或当前正在发生的垃圾回收的诱因 S0 S1 E O M CCS YGC YGCT FGC FGCT GCT LGCC GCC 52.97 0.00 46.09 13.92 97.39 98.02 8 0.020 0 0.000 0.020 Allocation Failure No GC
[root@zjq ~]# jstat -printcompilation 3346 #输出JIT编译的方法信息 Compiled Size Type Method 421 60 1 sun/nio/ch/Util$2 clear