简体   繁体   中英

How to get Java 9 print Java 8 -style information about GC

On java 8 giving JVM a command line options

-XX:+PrintGCDateStamps and -XX:+PrintGCDetails
results in the JVM printing exactly on line per each GC operation, like this:

2018-03-21T01:35:58.404-0700: [Full GC (Metadata GC Threshold) [PSYoungGen: 1952K->0K(348672K)] [ParOldGen: 457235K->256822K(873984K)] 459187K->256822K(1222656K), [Metaspace: 122374K->122350K(1163264K)], 0.9086909 secs] [Times: user=3.25 sys=0.01, real=0.91 secs]

or

 2018-03-21T01:35:58.404-0700: [Full GC (Metadata GC Threshold) [PSYoungGen: 1952K->0K(348672K)] [ParOldGen: 457235K->256822K(873984K)] 459187K->256822K(1222656K), [Metaspace: 122374K->122350K(1163264K)], 0.9086909 secs] [Times: user=3.25 sys=0.01, real=0.91 secs] 

How can I make Java 9 do something similar? One row per GC operation and preferably listing both elapsed time and the amount of memory free after the operation.

The closest I've been able to get is to enable GC logging at level 'info', like this: -Xlog:gc=info.

However, it still prints half a dozen rows for every round of GC.

This article details the missing/deprecated command line options.

Briefly, PrintGCDetails is replaced with -Xlog:gc* . There doesn't appear to be a documented replacement for -XX:+PrintGCDateStamps

Try -Xlog:gc,gc+cpu=info::utc . Or read -Xlog:help and assemble your own log configuration.

And you really shouldn't worry about lines so much. In the end it's just about bytes and two shorter lines are not that different from a longer one. Plus you can always compress them etc. etc. If the number of characters in a GC log line is what breaks your system then you already have a much bigger problem.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM