GC日志打印添加以及说明

        项目经常自动重启,但是没有gc日志和dump文件。可以使用一下命令添加日志:

        -XX:+PrintGCDetails -XX:+UseStringDeduplication -Xmx100M -XX:+UseG1GC -XX:+PrintGCTimeStamps -Xloggc:gc-%t.log -XX:+UseGCLogFileRotation  -XX:GCLogFileSize=10M -XX:+HeapDumpAfterFullGC    -XX:HeapDumpPath=e:\testDump  

 

    说明:

   -XX:+PrintGCDetails 打印gc日志详情,比如:

   

40.951: [GC pause (G1 Evacuation Pause) (young), 0.0031053 secs]
   [Parallel Time: 1.7 ms, GC Workers: 13]
      [GC Worker Start (ms): Min: 40951.5, Avg: 40951.6, Max: 40951.6, Diff: 0.1]
      [Ext Root Scanning (ms): Min: 0.3, Avg: 0.5, Max: 1.6, Diff: 1.2, Sum: 6.6]
      [Update RS (ms): Min: 0.0, Avg: 0.0, Max: 0.0, Diff: 0.0, Sum: 0.1]
         [Processed Buffers: Min: 0, Avg: 0.2, Max: 1, Diff: 1, Sum: 2]
      [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.0, Max: 0.0, Diff: 0.0, Sum: 0.0]
      [Object Copy (ms): Min: 0.0, Avg: 0.0, Max: 0.0, Diff: 0.0, Sum: 0.2]
      [Termination (ms): Min: 0.0, Avg: 1.0, Max: 1.1, Diff: 1.1, Sum: 13.0]
         [Termination Attempts: Min: 1, Avg: 1.0, Max: 1, Diff: 0, Sum: 13]
      [GC Worker Other (ms): Min: 0.0, Avg: 0.0, Max: 0.0, Diff: 0.0, Sum: 0.1]
      [GC Worker Total (ms): Min: 1.5, Avg: 1.5, Max: 1.6, Diff: 0.1, Sum: 20.0]
      [GC Worker End (ms): Min: 40953.1, Avg: 40953.1, Max: 40953.1, Diff: 0.0]
   [Code Root Fixup: 0.0 ms]
   [Code Root Purge: 0.0 ms]
   [String Dedup Fixup: 0.3 ms, GC Workers: 13]
      [Queue Fixup (ms): Min: 0.0, Avg: 0.0, Max: 0.0, Diff: 0.0, Sum: 0.0]
      [Table Fixup (ms): Min: 0.2, Avg: 0.2, Max: 0.3, Diff: 0.0, Sum: 3.1]
   [Clear CT: 0.1 ms]
   [Other: 1.0 ms]
      [Choose CSet: 0.0 ms]
      [Ref Proc: 0.9 ms]
      [Ref Enq: 0.0 ms]
      [Redirty Cards: 0.1 ms]
      [Humongous Register: 0.0 ms]
      [Humongous Reclaim: 0.0 ms]
      [Free CSet: 0.0 ms]
   [Eden: 0.0B(5120.0K)->0.0B(5120.0K) Survivors: 0.0B->0.0B Heap: 95.3M(100.0M)->95.3M(100.0M)]
 [Times: user=0.06 sys=0.00, real=0.00 secs] 

   eden区:回收前的内存(eden区总内存) ->回收后的内存(eden区总内存)  Survivors: 回收前内存->回收后内存  堆区: 回收前内存(堆总内存) ->回收后内存(堆总内存)

   

 

 -XX:+UseG1G   -XX:+UseStringDeduplication 

Note 1:要想使用此功能,你需要把你的Java升级到Java 8 update 20以及往后的版本。

Note 2:“ -XX:+UseStringDeduplication” 参数是运行在G1之上的,所以你需要在G1下使用此参数才会生效。

这个网上看是说能节省内存,可是自己使用profile比对,发现除了减少了一部分内存,full GC的次数大大减少了。附上自己的截图:

 

-XX:+PrintGCDetails -Xmx100M -XX:+UseG1GC -Xloggc:gc-%t.log -XX:+UseGCLogFileRotation  -XX:GCLogFileSize=10M -XX:+HeapDumpAfterFullGC    -XX:HeapDumpPath=e:\testDump  

 

 

 

-XX:+PrintGCDetails -Xmx100M -XX:+UseG1GC -XX:+UseStringDeduplication -Xloggc:gc-%t.log -XX:+UseGCLogFileRotation  -XX:GCLogFileSize=10M -XX:+HeapDumpAfterFullGC    -XX:HeapDumpPath=e:\testDump  

 

 

 

 

 

 

 

-Xloggc:gc-%t.log :GC日志文件名称

 -XX:GCLogFileSize=10M  日志文件大小

-XX:+HeapDumpAfterFullGC   fullgc前dump文件保存

 -XX:HeapDumpPath=e:\testDump    dump文件保存路径

-XX:+PrintGCTimeStamps 输出GC的时间戳(以基准时间的形式)

-XX:+PrintGCDateStamps 输出GC的时间戳(以日期的形式,如 2023-05-04T21:53:59.234+0800)

 
 

 

  

posted @ 2022-11-15 11:45  Doyourself!  阅读(891)  评论(0编辑  收藏  举报