在Tomcat 6中为Java的GC消息添加时间戳

时间:2009-12-02 17:28:50

标签: java logging garbage-collection

我打开了Java的GC日志选项

  

-XX:+ PrintGC -XX:+ PrintGCTimeStamps -XX:+ PrintGCDetails

将这些消息打印到标准输出(catalina.out):

314.884: [CMS-concurrent-mark-start]
315.014: [CMS-concurrent-mark: 0.129/0.129 secs] [Times: user=0.14 sys=0.00, real=0.13 secs]
315.014: [CMS-concurrent-preclean-start]
315.016: [CMS-concurrent-preclean: 0.003/0.003 secs] [Times: user=0.00 sys=0.00, real=0.00 secs]
315.016: [CMS-concurrent-abortable-preclean-start]
332.055: [GC 332.055: [ParNew: 17128K->84K(19136K), 0.0017700 secs] 88000K->70956K(522176K) icms_dc=4 , 0.0018660 secs] [Times: user=0.00 sys=0.00, real=0.00 secs]
 CMS: abort preclean due to time 352.253: [CMS-concurrent-abortable-preclean: 0.023/37.237 secs] [Times: user=0.78 sys=0.02, real=37.23 secs]

如何使这些日志行显示实际时间戳(包括日期)而不是这些数字,这可能意味着“自JVM启动以来的时间”?

2 个答案:

答案 0 :(得分:1)

据我所知,这是无法做到的。根据 sun documentation

The format is not guaranteed to be the same in later releases. In particular the output associated with -XX:+PrintGCDetails is almost guaranteed to change in that it represents the current needs of JVM developers. 

不可否认,这是一个旧的参考资料(对于java 1.4!)但是我找不到更新的内容,而且上一次我们的小组经历了gc调优,几个月前,我们在当前的文档中没有看到任何专门针对格式化的内容。

答案 1 :(得分:1)

检查此blog entry,了解如何在GC日志文件中显示人类可读的时间戳。