jstat是用於監視虛擬機各種運行狀態信息的命令行工具,它可以顯示本地或者遠程虛擬機進程中中的類裝載,內存,垃圾收集,JIT編輯等運行數據。我們使用jstat -help 可以查看jstat的具體用法,如下所示:
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 -help 可以查看該命令的使用詳情,而jstat -options則用於查看JVM的各種信息。jstat的命令格式爲:
jstat -<option> [-t] [-h<lines>] <vmid> [<interval> [<count>]]。
其中參數vmid爲進程id,當查看的爲遠程虛擬機的時候的時候爲 [protocol:][//]vmid@ip:port/servername。參數interval和count代表查詢時間間隔和查詢次數。如果省略這兩個參數,說明只查詢一次。參數option代表用戶希望查詢的虛擬機信息,主要分爲類裝載,垃圾收集,運行期編譯情況。如下爲option的詳細描述:
-class 監視類裝載,卸載數量,總空間以及類裝載所耗費的時間。
監視3071進程的類裝載類信息,每隔兩秒輸出一次,共輸出兩次
jstat -class 3071 2000 2
Loaded Bytes Unloaded Bytes Time
13037 27557.3 320 773.4 14.62
13037 27557.3 320 773.4 14.62
Loaded 已加載數量 Bytes 所佔字節數 Unloaded 未加載數量 Time 加載耗時
-gc 監視java堆狀況,包括Eden區,兩個surivivor區,老年代,永久代等容量,已使用空間,GC時間合計等信息。
jstat -gc 3071 2000 1
S0C S1C S0U S1U EC EU OC OU PC PU YGC YGCT FGC FGCT GCT
1216.0 1216.0 0.0 749.8 72960.0 18768.3 150040.0 89445.2 155972.0 93480.1 331 4.178 151 80.582 84.760
-gccapacity 監視內容與-gc基本相同,但輸出主要關注Java堆各個區域使用到的最大、最小空間。
jstat -gccapacity 3071 2000 1
NGCMN NGCMX NGC S0C S1C EC OGCMN OGCMX OGC OC PGCMN PGCMX PGC PC YGC FGC
2176.0 349504.0 75392.0 1216.0 1216.0 72960.0 4416.0 699072.0 150040.0 150040.0 21248.0 196608.0 155972.0 155972.0 331 151
-gcutil 監視內容與-gc基本相同,但輸出主要關注已使用空間佔總空間的百分比
jstat -gcutil 3071 2000 1
S0 S1 E O P YGC YGCT FGC FGCT GCT
0.00 61.66 29.10 59.61 59.93 331 4.178 151 80.582 84.760
-gccause 與-gcutil一致,但會額外輸出上次GC產生的原因
jstat -gccause 3071 2000 1
S0 S1 E O P YGC YGCT FGC FGCT GCT LGCC GCC
0.00 0.00 11.97 59.63 59.93 331 4.178 152 81.235 85.413 System.gc() No GC
-gcnew 監視新生代GC狀況
jstat -gcnew 3071 2000 1
S0C S1C S0U S1U TT MTT DSS EC EU YGC YGCT
1216.0 1216.0 0.0 0.0 1 15 608.0 72960.0 9844.6 331 4.178
-gcnewcapacity 監視內容與-gcnew基本相同,輸出主要關注用到的最大、最小空間
jstat -gcnewcapacity 3071 2000 1
NGCMN NGCMX NGC S0CMX S0C S1CMX S1C ECMX EC YGC FGC
2176.0 349504.0 75392.0 1216.0 5824.0 5824.0 1216.0 337856.0 72960.0 331 152
-gcold 監視老年代GC狀況
jstat -gcold 3071 2000 1
PC PU OC OU YGC FGC FGCT GCT
155972.0 93480.1 150040.0 89464.1 331 152 81.235 85.413
-gcoldcapacity 監視內容與-gcold基本相同,輸出主要關注用到的最大、最小空間
jstat -gcoldcapacity 3071 2000 1
OGCMN OGCMX OGC OC YGC FGC FGCT GCT
4416.0 699072.0 150040.0 150040.0 331 152 81.235 85.413
-gcpermcapacity 輸出永久代主要關注用到的最大、最小空間
jstat -gcpermcapacity 3071 2000 1
PGCMN PGCMX PGC PC YGC FGC FGCT GCT
21248.0 196608.0 155972.0 155972.0 331 152 81.235 85.413
-compiler 輸出JIT編譯器編譯過的方法、耗時的等信息
jstat -compiler 3071 2000 1
Compiled Failed Invalid Time FailedType FailedMethod
1463 1 0 28.84 1 com/sun/enterprise/admin/meta/MBeanMetaHelper mergeWithConfigBean
-printcompilation 輸出已經被JIT編譯的方法
jstat -printcompilation 3071 2000 1
Compiled Size Type Method
1463 573 1 java/util/logging/Logger findResourceBundle
至於標題頭的意思,不想做太多解釋,因爲實在太對了,重點是掌握英文縮寫,比如:OC中的 O代表Old,C代表Capacity,合起來表示當前老年代容量大小。其他的具體的意思可以查看官方文檔:jstat。