使Java GC日志显示MB或GB而不是KB [英] Make Java GC logs show MB or GB instead of KB

查看:356
本文介绍了使Java GC日志显示MB或GB而不是KB的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

默认情况下, Java GC日志输出以 KB (千字节)显示内存详细信息。我知道这可能听起来很愚蠢,但考虑到我所处理的大部分Jvms堆大小接近20至40GB,我发现用KB快速读取数字非常不方便,尤其是在快速扫描腻子等日志时。



是否有可能使Java以 MB GB 的分数打印这些数字?

我在JDK文档中找不到任何选项。



如果不可能,有没有关于如何将此功能添加到GC日志记录的想法? (不是来自外部,而是来自JVM)



预先感谢您的帮助。 方案

没有运行时选项来改变它,它取决于特定的垃圾回收器用于打印日志数据。



使用G1 JDK 8,它将以合适的单位打印,具体取决于堆大小:

  $ java -XX:+ UseG1GC -verbose: gc 
[GC暂停(元数据GC阈值)(年轻)(初始标记)592M-> 23M(100G),0.0137879秒]

升级到JDK 9,然后统一日志将根据堆大小以适当的单位打印所有收集器(加上时间戳也以适当的单位):

  $ java -XX:+ UseParallelGC -Xlog:gc 
[0.766s] [info] [gc] GC(0)暂停年轻(元数据GC阈值)4300M-> 15M(117760M)6.765ms


By default Java GC log output shows the memory details in KB (kilo bytes). I know it might sound silly, but given most of the Jvms I deal with have heap sizes close to 20 to 40GB, I find it quite inconvenient to read the numbers in KB quickly, especially when quickly scanning logs in putty etc.

Is it possible to make Java print these number in fractions of MB or GB instead?

I didn't find any option in JDK documentation.

If it is not possible, are there any ideas around how one can go about adding this feature to GC logging? (not from outside but from with in JVM)

Thank you in advance for your help.

解决方案

There is no runtime option to change this, it depends on what particular garbage collector is using to print the logging data.

Use G1 in JDK 8, and it will print in proper units, depending on heap size:

$ java -XX:+UseG1GC -verbose:gc
[GC pause (Metadata GC Threshold) (young) (initial-mark) 592M->23M(100G), 0.0137879 secs]

Upgrade to JDK 9, and then Unified Logging would print in proper units, depending on the heap size, for all collectors (plus, timestamps are in proper units too):

$ java -XX:+UseParallelGC -Xlog:gc
[0.766s][info][gc] GC(0) Pause Young (Metadata GC Threshold) 4300M->15M(117760M) 6.765ms

这篇关于使Java GC日志显示MB或GB而不是KB的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆