During my work as an Application Server
Administrator, I use many tools and commands provided by both java and also
underlying O.S.Here are a list of tools provided by java that I use regularly
during my work
Jps : Java tool that lists all JVM processes on the
local machine or a remote machine
Dev:localhost:root-~ $ jps
713 Jps
10855 Bootstrap
To Find the Arguments passed
to the JVM’s
Dev:localhost:root-~ $ jps -v
10855 Bootstrap
-Djbs.name=JAS-C3 -Xms256m -Xmx256m -XX:MaxPermSize=256m
-Dcom.sun.management.jmxremote.port=10029
-Dcom.sun.management.jmxremote.ssl=false
-Dcom.sun.management.jmxremote.authenticate=false -XX:+PrintGCDetails
-XX:+PrintGCTimeStamps -Dimplementation.environment=dev -Dhost.name=localhost
-XX:+PrintGC -XX:+PrintGCTimeStamps -XX:+PrintGCDetails
1693 Jps
-Dapplication.home=/software/java32/jdk1.6.0_16 -Xms8m
To find from where the Java
Process has been started,
Dev:localhost:root-~ $ jps -l
-m -v
10855
org.apache.catalina.startup.Bootstrap start -Djbs.name=JAS-C3 -Xms256m -Xmx256m
-XX:MaxPermSize=256m -Dcom.sun.management.jmxremote.port=10029
-Dcom.sun.management.jmxremote.ssl=false
-Dcom.sun.management.jmxremote.authenticate=false -XX:+PrintGCDetails
-XX:+PrintGCTimeStamps -Dimplementation.environment=dev -Dhost.name=localhost
-XX:+PrintGC -XX:+PrintGCTimeStamps -XX:+PrintGCDetails
Jstat : Jstat is a jvm statistics
monitoring tool that displays the performance statistics of a given jvm process
with a specified interval
Dev:localhost:root-~ $ jstat
-gcutil 10855
S0
S1 E O
P YGC YGCT
FGC FGCT GCT
0.00
25.00 78.34 3.13
99.95 89 0.702
0 0.000
0.702
The Explanation of these ( as
provided by Java Docs )
S0
|
Survivor space 0 utilization as a percentage of the space's
current capacity.
|
S1
|
Survivor space 1 utilization as a percentage of the space's
current capacity.
|
E
|
Eden space utilization as a percentage of the space's current
capacity.
|
O
|
Old space utilization as a percentage of the space's current
capacity.
|
P
|
Permanent space utilization as a percentage of the space's
current capacity.
|
YGC
|
Number of young generation GC events.
|
YGCT
|
Young generation garbage collection time.
|
FGC
|
Number of full GC events.
|
FGCT
|
Full garbage collection time.
|
GCT
|
Total garbage collection time.
|
This tool
can be used to take some sample output with timed intervals .The following
command allows to take 7 samples at 250 millisecond intervals and displays the
output
Dev:localhsot:root-~ $ jstat
-gcutil 10855 250 7
S0
S1 E O
P YGC
YGCT FGC FGCT
GCT
0.00
25.00 82.13 3.13
99.95 89 0.702
0 0.000
0.702
0.00
25.00 82.13 3.13
99.95 89 0.702
0 0.000
0.702
0.00
25.00 82.13 3.13
99.95 89 0.702
0 0.000
0.702
0.00
25.00 82.13 3.13
99.95 89 0.702
0 0.000
0.702
0.00
25.00 82.13 3.13
99.95 89 0.702
0 0.000
0.702
0.00
25.00 82.13 3.13
99.95 89 0.702
0 0.000
0.702
0.00
25.00 82.13 3.13
99.95 89 0.702
0 0.000
0.702
If we need the results with
time stamps ,we can use
Dev:localhost:root-~ $ jstat
-gcpermcapacity -t 10855
Timestamp PGCMN PGCMX PGC PC
YGC FGC
FGCT GCT
348601.8
16384.0 262144.0 19712.0
19712.0 89 0
0.000 0.702
The Explanation of these ( as
provided by Java Docs )
PGCMN
|
Minimum permanent generation capacity (KB).
|
PGCMX
|
Maximum permanent generation capacity (KB).
|
PGC
|
Current permanent generation capacity (KB).
|
PC
|
Current permanent space capacity (KB).
|
YGC
|
Number of young generation GC events.
|
FGC
|
Number of full GC events.
|
FGCT
|
Full garbage collection time.
|
GCT
|
Total garbage collection time.
|
If we need to get details of
the Space Utilizations , we can use
Dev:localhost:root-~ $ jstat
-gcold -t 10855
Timestamp PC PU
OC OU
YGC FGC
FGCT GCT
348666.5
19712.0 19701.2
233024.0 7302.4
89 0 0.000
0.702
The Explanation of these ( as
provided by Java Docs )
PC
|
Current permanent space capacity (KB).
|
PU
|
Permanent space utilization (KB).
|
OC
|
Current old space capacity (KB).
|
OU
|
old space utilization (KB).
|
If we need a class loaded
information , we can use
Dev:localhost:root-~ $ jstat
-class -t 10855
Timestamp Loaded
Bytes Unloaded Bytes
Time
348808.6 3762
4285.6 0 0.0
5.69
The Explanation of these (as
provided by Java Docs )
Loaded
|
Number of classes loaded.
|
Bytes
|
Number of Kbytes loaded.
|
Unloaded
|
Number of classes unloaded.
|
Bytes
|
Number of Kbytes unloaded.
|
Time
|
Time spent performing class load and unload operations.
|
Jmap : jmap allows you to attach
to any 1.5 JVM process to obtain heap information,
class histograms and complete heap snapshots
We can use jmap like,
jmap -dump:file=heap.conf
10855
This command generates a file
heap.conf which contains the heap information of the JMV process.
jmap -heap:format=heap.conf 10855
This was added in a
5.0 update to allow for the recovery of heap dump from a core file or hung
process. This takes considerable time to take a snapshot of a running process
If you need to print a
Histogram of the Heap, we can use
Dev:localhost:root-~ $ jmap
-histo 10855
Or about live objects ,we can
use
Jmap –histo:live 10855
If we need to find the memory
information about a running JVM Process , we can use
Dev:localhost:root-~ $ jmap
-heap 10855
Attaching to process ID
10855, please wait...
Debugger attached successfully.
Server compiler detected.
JVM version is 14.2-b01
using thread-local object
allocation.
Parallel GC with 2 thread(s)
Heap Configuration:
MinHeapFreeRatio = 40
MaxHeapFreeRatio = 70
MaxHeapSize = 268435456 (256.0MB)
NewSize = 1048576 (1.0MB)
MaxNewSize = 4294901760 (4095.9375MB)
OldSize = 4194304 (4.0MB)
NewRatio = 8
SurvivorRatio = 8
PermSize = 16777216 (16.0MB)
MaxPermSize = 268435456 (256.0MB)
Heap Usage:
PS Young Generation
Eden Space:
capacity = 29687808 (28.3125MB)
used
= 8972352 (8.55670166015625MB)
free
= 20715456 (19.75579833984375MB)
30.222345819536425% used
From Space:
capacity = 65536 (0.0625MB)
used
= 16384 (0.015625MB)
free
= 49152 (0.046875MB)
25.0% used
To Space:
capacity = 65536 (0.0625MB)
used
= 0 (0.0MB)
free
= 65536 (0.0625MB)
0.0% used
PS Old Generation
capacity = 238616576 (227.5625MB)
used
= 7477632 (7.1312255859375MB)
free
= 231138944 (220.4312744140625MB)
3.1337437345509476% used
PS Perm Generation
capacity = 20185088 (19.25MB)
used
= 20174168 (19.239585876464844MB)
free
= 10920 (0.01041412353515625MB)
99.94590065696023% used
jhat : The jhat command parses a java heap dump file and launches a web server.
jhat enables you to browse heap dumps using your favorite web browser
The Heap File generated by the
jmap command are not readable.jhat command helps to read the file.Once the jhat
command is started , a server is started at 7000 .Once the command says,server
is ready.Open a browser and type , localhost:7000 to see all about object
information.
Dev:localhost:root-~ $ jhat
-J-Xmx2G hprof.bin
Reading from hprof.bin...
Dump file created Mon Jul 16
02:14:50 CDT 2012
Snapshot read, resolving...
Resolving 408187 objects...
Chasing references, expect 81
dots.................................................................................
Eliminating duplicate
references.................................................................................
Snapshot resolved.
Started HTTP server on port
7000
Server is ready.
Jinfo : jinfo prints
Java configuration information for a given Java process or core file
Dev:localhost:root-~ $ jinfo
-flag ThreadStackSize 10855
-XX:ThreadStackSize=320
If we need to print the System
properties, we can use
jinfo -sysprops 10855
More to Come, Happy Learning J