In this article we are going to see how to analyze GC Logs for finding memory leak. Previously we have seen generic approach of memory leak finding (top down analysis). In here we will see more quick and efficient approach to detect memory leak. In this approach, we will not pinpoint where is the root cause but we will see how can we quick make decision about memory leak and go for further investigation.
What is memory leak? When an application memory usages is not dropping after high usages or memory usages increases(may or may not with certain condition) then a memory leak is suspected. We need to find an easy way to get that. So, first, we need to generate GC logs. GC logs represents GC activity. For GC activity monitoring we can do following
- Storing GC logs in a log file :
- Printing GC activity in console :
- Monitoring GC activity using Tools :
I will skip monitoring GC part as I will cover in separate post with JMX monitoring.
How to view & take GC logs via JVM Arguments : The following JVM argument applicable to show GC logs and later on on save the log to a file will enable us to analyze.
Oracle JDK 1.8 -Xloggc: [-XX:+PrintGCDetails] [-XX:+PrintGCDateStamps] Sun / Oracle JDK 1.7 with option -Xloggc: [-XX:+PrintGCDetails] [-XX:+PrintGCDateStamps] Sun / Oracle JDK 1.6 with option -Xloggc: [-XX:+PrintGCDetails] [-XX:+PrintGCDateStamps] Sun JDK 1.4/1.5 with the option -Xloggc: [-XX:+PrintGCDetails] Sun JDK 1.2.2/1.3.1/1.4 with the option -verbose:gc IBM JDK 1.3.1/1.3.0/1.2.2 with the option -verbose:gc IBM iSeries Classic JVM 1.4.2 with option -verbose:gc HP-UX JDK 1.2/1.3/1.4.x with the option -Xverbosegc BEA JRockit 1.4.2/1.5/1.6 with the option -verbose:memory [-Xverbose:gcpause,gcreport] [-Xverbosetimestamp]
-verbose:gc = will show GC logs in command line -XX:-PrintGC Print messages at garbage collection. Manageable. -XX:+PrintGCDetails = Shows details logs. -XX:+PrintGCTimeStamps= Shows with time stamp
To save GC log in a file :
IBM JVM : -Xverbosegclog:
in both case, it is pointed to current working directory. But we can customize that.
File format Example :
For IBM : -Xverbosegclog:
So, finally, for IBM : -verbose:gc –Xloggc:verbosegc.%Y%m%d.%H%M%S.%pid.txt -XX:+PrintGCDetails -XX:+PrintGCTimeStamps
For Oracle :
Note : This option is available for Oracle JVM 1.7+(after bug fix)
you can specify path also, Tools for analysis: I prefer : independent tool : . https://github.com/chewiebug/GCViewer Eclipse IDE tool : IBM tool : You can see details in this post for tooling.
Raw Log File Format : Oracle/OpenJDK/Sun Format :
IBM : it is XML format , having all information in XML about GC. Here is one example from IBM JVM 1.5 (single GC event entry)
<?xml version=”1.0” ?>