3

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:39.624-0700: [GC (Allocation Failure) [PSYoungGen: 328192K->23443K(382464K)] 328192K->23459K(1256448K), 0.0268406 secs] [Times: user=0.04 sys=0.01, real=0.03 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.

Zds
  • 4,311
  • 2
  • 24
  • 28
  • Possible duplicate of [Handle PrintGCApplicationStoppedTime flag in java 9](https://stackoverflow.com/questions/45911952/handle-printgcapplicationstoppedtime-flag-in-java-9) – Naman Mar 21 '18 at 16:16
  • I don't really see much similarity. That question is about different JVM option to begin with. – Zds Mar 21 '18 at 16:28
  • Ya(didn't actually vote for that reason), but the solutions would be close to being one. Expecting you to go through the links in the answer, specifically one by Alan there. The logging methods, of course, have changed. I am not sure if you're looking for someone to actually solve it for you in which case I leave this as an open estate still. – Naman Mar 21 '18 at 16:32
  • Why does the number of lines matter? They should be written out in a single write syscall (I hope), so the load on the system should not change significantly from the old logging style. – the8472 Mar 22 '18 at 00:01
  • The more compact format would take less disk space and be easier to read. Of course, with the new logging API you can move the logging to a custom file and rotate that, but I tried to find a way that would not require splitting logs into several places. – Zds Mar 23 '18 at 13:31
  • Zds, have you found solution to have 1 line logging per GC operation? – inspiral Nov 13 '18 at 16:03

2 Answers2

1

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

Brian Agnew
  • 268,207
  • 37
  • 334
  • 440
  • 1
    Yes, but result of that switch is *really* verbose, printing out 20+ lines for each GC event. Thus it's not really a replacement; I cannot leave it on in production environment. – Zds Mar 21 '18 at 13:12
  • If this be the solution to it, I consider the question can be marked as a duplicate of [Handle PrintGCApplicationStoppedTime flag in java 9](https://stackoverflow.com/questions/49406148/how-to-get-java-9-print-java-8-style-information-about-gc?noredirect=1#comment85824587_49406148) – Naman Mar 21 '18 at 16:34
1

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.

the8472
  • 40,999
  • 5
  • 70
  • 122