Recently I had a few performance problems with an application that required JVM GC monitoring. It had been so long since the last time I’d had to perform any CG analysis that I had to remind myself of what to do!
First, ensure that an appropriate JDK is on your path
[dave@titan ~]$ java -version java version "1.7.0_45" OpenJDK Runtime Environment (fedora-18.104.22.168.fc19-x86_64 u45-b15) OpenJDK 64-Bit Server VM (build 24.45-b08, mixed mode)
Next, issue the command
jps which shows a list of all running Java processes that can be
[dave@titan ~]$ jps 2472 RemoteMavenServer 3189 Jps 2364 Main
Once you have identified the PID issue the following command:
jstat -gcutil [PID] [Frequency ms] [Iterations]
jstatloops until it gets a signal.
[dave@titan ~]$ jstat -gcutil 2472 5000 S0 S1 E O P YGC YGCT FGC FGCT GCT 0.00 0.00 12.60 2.42 40.12 2 0.012 1 0.037 0.050 0.00 0.00 12.60 2.42 40.12 2 0.012 1 0.037 0.050
Basically, the first set of columns (S0, S1, E, O, P) describes the utilisation of the various memory heaps (Survivor heaps, Eden - young generation, Old generation and Permanent heap space).
Next, (YGC and YGCT) show the number of young (Eden) space collections and total time taken so far doing these collections.
Columns (FCG, FGCT) show the number and time taken doing old space collections.
Lastly, GCT shows the total time taken performing garbage collection so far.
This guide only breaks the surface of what output you can get from
jstat; the Oracle website provides complete documentation for jstat. Also, I’m assuming that you are using the default garbage collector - if not the columns output may vary.