Chapter 8. GC Logging, Monitoring, Tuning, and Tools
In this chapter, we will introduce the huge subject of GC logging and monitoring. This is one of the most important and visible aspects of Java performance tuning, and also one of the most often misunderstood.
Introduction to GC Logging
The GC log is a great source of information. It is especially useful for “cold case” analysis of performance problems, such as providing some insight into why a crash occurred. It can allow the analyst to work, even with no live application process to diagnose.
Every serious application should always:
Generate a GC log.
Keep it in a separate file from application output.
This is especially true for production applications. As we’ll see, GC logging has no real observable overhead, so it should always be on for any important JVM process.
Switching On GC Logging
The first thing to do is to add some switches to the application startup. These are best thought of as the “mandatory GC logging flags,” which should be on for any Java/JVM application (except, perhaps, desktop apps). The flags are:
-Xloggc:gc.log -XX:+PrintGCDetails -XX:+PrintTenuringDistribution -XX:+PrintGCTimeStamps -XX:+PrintGCDateStamps
Let’s look at each of these flags in more detail. Their usage is described in Table 8-1.
Controls which file to log GC events to
Logs GC event details
Adds extra GC event detail ...