Search code examples
garbage-collectionjavajava-5

How to redirect verbose garbage collection output to a file?


How do I redirect verbose garbage collection output to a file? Sun’s website shows an example for Unix but it doesn't work for Windows.


Solution

  • From the output of java -X:

        -Xloggc:<file>    log GC status to a file with time stamps
    

    Documented here:

    -Xloggc:filename

    Sets the file to which verbose GC events information should be redirected for logging. The information written to this file is similar to the output of -verbose:gc with the time elapsed since the first GC event preceding each logged event. The -Xloggc option overrides -verbose:gc if both are given with the same java command.

    Example:

        -Xloggc:garbage-collection.log

    So the output looks something like this:

    0.590: [GC 896K->278K(5056K), 0.0096650 secs]
    0.906: [GC 1174K->774K(5056K), 0.0106856 secs]
    1.320: [GC 1670K->1009K(5056K), 0.0101132 secs]
    1.459: [GC 1902K->1055K(5056K), 0.0030196 secs]
    1.600: [GC 1951K->1161K(5056K), 0.0032375 secs]
    1.686: [GC 1805K->1238K(5056K), 0.0034732 secs]
    1.690: [Full GC 1238K->1238K(5056K), 0.0631661 secs]
    1.874: [GC 62133K->61257K(65060K), 0.0014464 secs]