How to redirect verbose garbage collection to a file?

How to redirect verbose garbage collection to a file? The Suns website shows an example for Unix, but it does not work for Windows.

+64
java garbage-collection
Jul 21 '09 at 20:44
source share
4 answers

From java -X output:

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

Documented here :

-Xloggc: file name

Installs the file to which you want to redirect the details of GC events 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 registered event. The -Xloggc option overrides -verbose:gc if both are specified using the same java command.

Example:

  -Xloggc: garbage-collection.log 

So the result 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]
+83
Jul 21 '09 at 21:06
source share

If you want to transfer the output to a separate file, you can do:

In the Sun JVM:

 -Xloggc:C:\whereever\jvm.log -verbose:gc -XX:+PrintGCDateStamps 

ON IBM JVM:

 -Xverbosegclog:C:\whereever\jvm.log 
+35
Feb 21 '11 at 16:50
source share

To add to the answers above, there is a good article: Useful JVM Flags - Part 8 (GC Registration) by Patrick Pesblow.

Brief excerpt:

The -XX:+PrintGC (or the -verbose:gc alias) activates the "simple" GC registration mode

By default, the GC log is written to standard output. With -Xloggc:<file> we can specify the output file. Note that this flag implicitly sets -XX:+PrintGC and -XX:+PrintGCTimeStamps .

If we use -XX:+PrintGCDetails instead of -XX:+PrintGC , we activate the "detailed" GC logging mode, which differs depending on the GC algorithm used.

C -XX:+PrintGCTimeStamps timestamp, reflecting the real time elapsed after seconds, since the beginning of the JVM is added to each line.

If we specify -XX:+PrintGCDateStamps , each line starts with an absolute date and time.

+8
May 23 '16 at 7:58 a.m.
source share

Java 9 and Unified JVM Logging

JEP 158 introduces a common logging system for all JVM components, which will change (and IMO simplify) how logging works with the GC. A new command line parameter has been added to JEP 158 to control logging from all JVM components:

 -Xlog 

For example, the following parameter:

 -Xlog:gc 

will write tags with gc tag with info tag to stdout . Or this one:

 -Xlog:gc=debug:file=gc.txt:none 

will write tags with gc tag with debug tag to a file named gc.txt without decoration. For a more detailed discussion, you can check out the examples on the JEP page.

+3
Apr 20 '17 at 10:25
source share



All Articles