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:\>