java中的nath.sqrt_java - 将GC日志与Logback集成 - 堆栈内存溢出

我想将GC日志与我自己的基于http的Logger集成在一起,以避免基于文件的日志记录。 从JDk 7开始,我们可以在GC事件上添加我们自己的侦听器,该侦听器运行良好。 但是我希望我的gc日志的打印方式与之前的记录方式相同。

像下面。

2019-11-04T10:12:33.754+0000: 3.199: [GC pause (G1 Evacuation Pause) (young)

Desired survivor size 50331648 bytes, new threshold 15 (max 15)

, 0.0300627 secs]

[Parallel Time: 18.2 ms, GC Workers: 8]

[GC Worker Start (ms): Min: 3198.9, Avg: 3198.9, Max: 3199.0, Diff: 0.1]

[Ext Root Scanning (ms): Min: 0.7, Avg: 2.7, Max: 11.7, Diff: 11.0, Sum: 21.3]

[Update RS (ms): Min: 0.0, Avg: 0.0, Max: 0.0, Diff: 0.0, Sum: 0.0]

[Processed Buffers: Min: 0, Avg: 0.0, Max: 0, Diff: 0, Sum: 0]

[Scan RS (ms): Min: 0.0, Avg: 0.0, Max: 0.0, Diff: 0.0, Sum: 0.0]

[Code Root Scanning (ms): Min: 0.0, Avg: 0.6, Max: 2.6, Diff: 2.6, Sum: 4.5]

[Object Copy (ms): Min: 0.8, Avg: 9.9, Max: 16.1, Diff: 15.3, Sum: 79.4]

[Termination (ms): Min: 0.0, Avg: 4.8, Max: 5.6, Diff: 5.6, Sum: 38.6]

[Termination Attempts: Min: 1, Avg: 1.0, Max: 1, Diff: 0, Sum: 8]

[GC Worker Other (ms): Min: 0.0, Avg: 0.0, Max: 0.0, Diff: 0.0, Sum: 0.1]

[GC Worker Total (ms): Min: 17.9, Avg: 18.0, Max: 18.1, Diff: 0.1, Sum: 143.9]

[GC Worker End (ms): Min: 3216.9, Avg: 3216.9, Max: 3217.0, Diff: 0.1]

[Code Root Fixup: 0.9 ms]

[Code Root Purge: 0.1 ms]

[Clear CT: 0.2 ms]

[Other: 10.8 ms]

所以我来自通知,我能够打印:

end of minor GC: - 1342 ParNew (from Allocation Failure) 26 milliseconds; start-end times 67212728-67212754

end of minor GC: - 1343 ParNew (from Allocation Failure) 28 milliseconds; start-end times 68412633-68412661

end of major GC: - 54 ConcurrentMarkSweep (from System.gc()) 147 milliseconds; start-end times 68563369-68563516

end of minor GC: - 1344 ParNew (from Allocation Failure) 109 milliseconds; start-end times 70212722-70212831

end of minor GC: - 1345 ParNew (from Allocation Failure) 39 milliseconds; start-end times 71413175-71413214

end of minor GC: - 1346 ParNew (from Allocation Failure) 42 milliseconds; start-end times 72013977-72014019

public void handleNotification(Notification notification, Object handback) {

//get the information associated with this notification

//get all the info and pretty print it

GarbageCollectionNotificationInfo info = GarbageCollectionNotificationInfo.from((CompositeData) notification.getUserData());

LOG.info(info.getGcAction() + ": - " + info.getGcInfo().getId()+ " " + info.getGcName() + " (from " + info.getGcCause()+") "+info.getGcInfo().getDuration() + " milliseconds; start-end times " + info.getGcInfo().getStartTime()+ "-" + info.getGcInfo().getEndTime());

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值