Mastering jstat: How to Monitor JVM Performance with Command-Line Options
This guide explains how to use the jstat command-line tool to monitor Java Virtual Machine performance metrics such as garbage collection, memory usage, and compilation time, detailing its syntax, options, intervals, counts, and providing concrete examples with expected outputs.
Purpose
jstat is a tool for retrieving performance statistics of a running Java Virtual Machine (JVM), including garbage collection activity, memory sizes, and compilation times.
Command Syntax
jstat [ generalOption | outputOptions vmid [interval[s|ms] [count]] ]
generalOption
jstat -help|-optionsRunning jstat -options displays the available options (see the option list below).
-class : class‑loading statistics
-compiler : JIT compilation statistics
-gc : heap statistics
-gcutil : same as -gc but shows used space as a percentage of total
-gccapacity : maximum and minimum space of each heap region
-gccause : garbage‑collection cause information
-gcnew : young‑generation statistics
-gcnewcapacity : capacity information for the young generation
-gcold : old‑generation statistics
-gcoldcapacity : capacity information for the old generation
-printcompilation : details of methods compiled by the JIT
outputOptions
One or more output options, which may include a single stat option together with any -t, -h and -J flags.
vmid
The identifier of the target JVM (process ID). ps -ef | grep java or
jps -linterval
Sampling interval in the specified unit, seconds ( s) or milliseconds ( ms). The default unit is milliseconds. It must be a positive integer; if provided, jstat emits output at each interval.
count
Number of output samples. The default is infinite, meaning jstat continues until the JVM exits or the command is stopped. It must be a positive integer.
Examples
-class option
Input
jstat -class 29271 1000 20Output
Loaded Bytes Unloaded Bytes Time
22182 42401.0 638 847.4 39.52
22182 42401.0 638 847.4 39.52loaded : amount of data loaded
bytes : number of bytes loaded
unloaded : number of classes unloaded
bytes : bytes of unloaded classes
time : time spent loading and unloading
-compiler option
Input
jstat -compiler 29271 1000 20Output
Compiled Failed Invalid Time FailedType FailedMethod
6663 3 0 108.64 1 org/apache/jasper/xmlparser/ParserUtils convert
6663 3 0 108.64 1 org/apache/jasper/xmlparser/ParserUtils convertCompiled : number of compilation tasks executed
Failed : number of compilation tasks that failed
Invalid : number of invalid compilations
Time : time spent compiling
FailedType : type of failed task
FailedMethod : method that failed to compile
-gc option
Input
jstat -gc 29271 1000 20Output
S0C S1C S0U S1U EC EU OC OU PC PU YGC YGCT FGC FGCT GCT
4096.0 4096.0 0.0 3088.4 691200.0 85378.5 1398272.0 337712.4 262144.0 121554.1 25374 413.439 7 5.536 418.975
4096.0 4096.0 0.0 3088.4 691200.0 85727.0 1398272.0 337712.4 262144.0 121554.1 25374 413.439 7 5.536 418.975S0C : capacity of the first survivor space
S1C : capacity of the second survivor space
S0U : usage of the first survivor space
S1U : usage of the second survivor space
EC : total capacity of the Eden space
EU : used capacity of the Eden space
OC : total capacity of the old generation
OU : used capacity of the old generation
PC : capacity of the permanent generation (KB)
PU : used capacity of the permanent generation (KB)
YGC : number of young‑generation garbage collections
YGCT : time spent in young‑generation GC
FGC : number of full (old‑generation) garbage collections
FGCT : time spent in full GC
GCT : total garbage‑collection time
-gcutil option
Input
jstat -gcutil 29271 1000 20Output
S0 S1 E O P YGC YGCT FGC FGCT GCT
83.70 0.00 62.04 24.11 46.37 25373 413.423 7 5.536 418.958
83.70 0.00 62.06 24.11 46.37 25373 413.423 7 5.536 418.958S0 : capacity of the first survivor space
S1 : capacity of the second survivor space
E : total capacity of the Eden space
O : total capacity of the old generation
P : capacity of the permanent generation (KB)
YGC : young‑generation GC count
YGCT : young‑generation GC time
FGC : full GC count
FGCT : full GC time
GCT : total GC time
-gccapacity option
Input
jstat -gccapacity 29271 1000 20Output
NGCMN NGCMX NGC S0C S1C EC OGCMN OGCMX OGC OC PGCMN PGCMX PGC PC YGC FGC
699392.0 699392.0 699392.0 4096.0 4096.0 691200.0 1398272.0 1398272.0 1398272.0 1398272.0 262144.0 262144.0 262144.0 262144.0 25374 7
699392.0 699392.0 699392.0 4096.0 4096.0 691200.0 1398272.0 1398272.0 1398272.0 1398272.0 262144.0 262144.0 262144.0 262144.0 25374 7NGCMN : initial capacity of the young generation (KB)
NGCMX : maximum capacity of the young generation (KB)
NGC : current capacity of the young generation
S0C : current capacity of survivor space 0 (KB)
S1C : current capacity of survivor space 1 (KB)
EC : capacity of the Eden space
OGCMN : initial capacity of the old generation (KB)
OGCMX : maximum capacity of the old generation (KB)
OGC : current capacity of the old generation
OC : capacity of the old generation
PGCMN : initial size of the permanent generation (KB)
PGCMX : maximum size of the permanent generation (KB)
PGC : current size of the permanent generation
PC : capacity of the permanent generation
YGC : young‑generation GC count
FGC : full GC count
-gccause option
Input
jstat -gccause 29271 1000 20Output
S0 S1 E O P YGC YGCT FGC FGCT GCT LGCC GCC
0.00 75.40 72.95 24.15 46.37 25374 413.439 7 5.536 418.975 Allocation Failure No GC
0.00 75.40 73.03 24.15 46.37 25374 413.439 7 5.536 418.975 Allocation Failure No GCS0 : capacity of the first survivor space
S1 : capacity of the second survivor space
E : total capacity of the Eden space
O : total capacity of the old generation
P : capacity of the permanent generation (KB)
YGC : young‑generation GC count
YGCT : young‑generation GC time
FGC : full GC count
FGCT : full GC time
GCT : total GC time
LGCC : most recent GC cause
GCC : current GC cause
-gcnew option
Input
jstat -gcnew 29271 1000 20Output
S0C S1C S0U S1U TT MTT DSS EC EU YGC YGCT
4096.0 4096.0 0.0 3088.4 1 15 4096.0 691200.0 588124.7 25374 413.439
4096.0 4096.0 0.0 3088.4 1 15 4096.0 691200.0 588759.6 25374 413.439S0C : capacity of the first survivor space
S1C : capacity of the second survivor space
S0U : usage of the first survivor space
S1U : usage of the second survivor space
TT : maximum tenuring threshold
MTT : current tenuring threshold
DSS : desired survivor size
EC : total capacity of the Eden space
EU : used capacity of the Eden space
YGC : young‑generation GC count
YGCT : young‑generation GC time
-gcnewcapacity option
Input
jstat -gcnewcapacity 29271 1000 20Output
NGCMN NGCMX NGC S0CMX S0C S1CMX S1C ECMX EC YGC FGC
699392.0 699392.0 699392.0 232960.0 4096.0 232960.0 4096.0 698368.0 691200.0 25374 7
699392.0 699392.0 699392.0 232960.0 4096.0 232960.0 4096.0 698368.0 691200.0 25374 7NGCMN : initial capacity of the young generation (KB)
NGCMX : maximum capacity of the young generation (KB)
NGC : current capacity of the young generation
S0CMX : maximum capacity of survivor space 0 (KB)
S0C : current capacity of survivor space 0 (KB)
S1CMX : maximum capacity of survivor space 1 (KB)
S1C : current capacity of survivor space 1 (KB)
ECMX : maximum capacity of the Eden space
EC : current capacity of the Eden space
YGC : young‑generation GC count
FGC : full GC count
-gcold option
Input
jstat -gcold 29271 1000 20Output
PC PU OC OU YGC FGC FGCT GCT
262144.0 121554.1 1398272.0 337896.5 25375 7 5.536 418.995
262144.0 121554.1 1398272.0 337896.5 25375 7 5.536 418.995PC : permanent generation capacity
PU : permanent generation used
OC : old generation capacity
OU : old generation used
YGC : young‑generation GC count
FGC : full GC count
FGCT : full GC time
GCT : total GC time
-gcoldcapacity option
Input
jstat -gcoldcapacity 29271 1000 20Output
OGCMN OGCMX OGC OC YGC FGC FGCT GCT
1398272.0 1398272.0 1398272.0 1398272.0 25373 7 5.536 418.958
1398272.0 1398272.0 1398272.0 1398272.0 25373 7 5.536 418.958OGCMN : initial capacity of the old generation (KB)
OGCMX : maximum capacity of the old generation (KB)
OGC : current capacity of the old generation
OC : old generation capacity
YGC : young‑generation GC count
FGC : full GC count
FGCT : full GC time
GCT : total GC time
-printcompilation option
Input
jstat -printcompilation 29271 1000 20Output
Compiled Size Type Method
6663 3093 1 com/alibaba/dubbo/registry/support/FailbackRegistry retry
6663 3093 1 com/alibaba/dubbo/registry/support/FailbackRegistry retryCompiled : number of compilation tasks
Size : bytecode size of the compiled method
Type : compilation type
Method : method that was compiled
Reference Documentation
https://docs.oracle.com/javase/7/docs/technotes/tools/share/jstat.html#general_options
Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
Programmer DD
A tinkering programmer and author of "Spring Cloud Microservices in Action"
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
