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.
相关问题
- Delete Messages from a Topic in Apache Kafka
- Jackson Deserialization not calling deserialize on
- How to maintain order of key-value in DataFrame sa
- StackExchange API - Deserialize Date in JSON Respo
- Difference between Types.INTEGER and Types.NULL in
Java 9 & Unified JVM Logging
JEP 158 introduces a common logging system for all components of the JVM which will change (and IMO simplify) how logging works with GC. JEP 158 added a new command-line option to control logging from all components of the JVM:
For example, the following option:
will log messages tagged with
gc
tag usinginfo
level tostdout
. Or this one:would log messages tagged with
gc
tag usingdebug
level to a file calledgc.txt
with no decorations. For more detailed discussion, you can checkout the examples in the JEP page.If in addition you want to pipe the output to a separate file, you can do:
On a Sun JVM:
ON an IBM JVM:
To add to the above answers, there's a good article: Useful JVM Flags – Part 8 (GC Logging) by Patrick Peschlow.
A brief excerpt:
The flag
-XX:+PrintGC
(or the alias-verbose:gc
) activates the “simple” GC logging modeBy default the GC log is written to stdout. With
-Xloggc:<file>
we may instead specify an output file. Note that this flag implicitly sets-XX:+PrintGC
and-XX:+PrintGCTimeStamps
as well.If we use
-XX:+PrintGCDetails
instead of-XX:+PrintGC
, we activate the “detailed” GC logging mode which differs depending on the GC algorithm used.With
-XX:+PrintGCTimeStamps
a timestamp reflecting the real time passed in seconds since JVM start is added to every line.If we specify
-XX:+PrintGCDateStamps
each line starts with the absolute date and time.From the output of
java -X
:Documented here:
So the output looks something like this: