Enabling GC logs in Apache Tomcat

22 Jul

There are so many way to analyze the performance of Application Server. 1 of those are called GC logs. GC logs is a log to monitor the movement of your application server’s memory usage. GC log is superb to analyze any kind of memory leaks or even analyze your optimization of your application. GC is actually stand for Garbage Collection, method in JVM to collecting all un-used or un-referenced object in memory to free up memory. So, lets get it on!

1. Enabling CATALINA_OPTS option and setting up the GC log enable parameter

You need to enable your CATALINA_OPTS parameter. CATALINA_OPTS is a parameter that allow you to specify a specific option during the startup of your tomcat server, such as the initial parameter for heap space, perm space, and so on. This can be done in 2 ways. In Windows Environment, you can create a new variable in your Environment Variable. Another simpler way, you can go to bin folder of your tomcat directory, find for startup.bat script. Open the script and you can set the CATALINA_OPTS variable. I prefer the second way to be explained since the first one only applicable for Windows user only.
So, open your startup.bat script, and add this code below :

set "CATALINA_OPTS=-Xloggc:log.gc"

at wherever you want (as long as it is put before :end and it is not in between if listing code šŸ˜€ ).
The -Xloggc is parameter for enabling GC logs. and log.gc is the name of file that will contain the log for memory. if you write like this, the GC will be created in bin folder right after server getting started up.

2. Start your apache tomcat

Next step, run your startup.bat. Right after the server getting started up, you will see in your bin folder, there will be a file called log.gc as per screen shot below :

If you can see this file, it means you have succesfully enabling your gc log for your performance monitor.

3. Analyze your GC logs

You might want to analyze your GC log since you have enable it and i’m pretty sure that you dont want to open the file using the editor since the content is such a horrible.
There are a lot of tools to analyze it, 1 sample that i take is HPjmeter, 1 of free application too analyze. You can google it to download 1 copy for you. Once you have installed it, you can drag your log.gc file into it, and you can see several options that you can use. Below is the sample screen shot from HPjmeter based on my log.gc :

GC Log Chart Example

GC Log Chart Example

GC Time Duration



Posted by on July 22, 2011 in English, Programming


Tags: , , , ,

4 responses to “Enabling GC logs in Apache Tomcat

  1. wiem

    October 28, 2012 at 6:00 pm

    Saya pake tomcat 6 , di directori tomcat tidak saya temukan file startup.bat?
    salam dari Indonesia

  2. Hans Kristanto

    October 28, 2012 at 6:05 pm

    Coba ke folder bin nya, harusnya disana ada. Salam juga.

    Hans Kristanto

    M: +6016-273-6948 @:

  3. Muhammad Ghufron

    February 8, 2014 at 8:32 pm

    hi guys, good writing …

  4. performancetestexpert

    September 4, 2015 at 2:56 pm

    For free gc log analysis, send the log file to


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: