jvm 基础篇-(3)-gclog输出常用参数要不要了解下?-XX:+PrintHeapAtGC -verbose:gc -XX:+PrintTenuringDistribution -XX...

详解如下参数:

-XX:+PrintHeapAtGC 
-verbose:gc 
-XX:+PrintTenuringDistribution
-XX:+PrintGCDateStamps 
-XX:+PrintGCDetails
-XX:+PrintReferenceGC 
-XX:+PrintGCTimeStamps
-XX:+PrintGC
-XX:+PrintGCApplicationStoppedTime
1、-XX:+PrintHeapAtGC

作用:每次gc(yonggc,fullgc) 都会输出gc前后堆详情(Eden区域、from区、to区、old区、Metaspace区 、Class space等) 个人认为这个输出的gclog是目前最细的力度(极力推荐查找gc问题配置上这个参数)

ParallelGC中log:

{Heap before GC invocations=5 (full 0):
 PSYoungGen      total 45056K, used 38644K [0x00000007bce00000, 0x00000007c0000000, 0x00000007c0000000)
  eden space 38912K, 99% used [0x00000007bce00000,0x00000007bf3bd328,0x00000007bf400000)
  from space 6144K, 0% used [0x00000007bfa00000,0x00000007bfa00000,0x00000007c0000000)
  to   space 6144K, 0% used [0x00000007bf400000,0x00000007bf400000,0x00000007bfa00000)
 ParOldGen       total 153600K, used 1509K [0x00000007b3800000, 0x00000007bce00000, 0x00000007bce00000)
  object space 153600K, 0% used [0x00000007b3800000,0x00000007b39797c8,0x00000007bce00000)
 Metaspace       used 3290K, capacity 4496K, committed 4864K, reserved 1056768K
  class space    used 362K, capacity 388K, committed 512K, reserved 1048576K
2018-08-03T17:50:29.631-0800: [GC (Allocation Failure) 
Desired survivor size 3670016 bytes, new threshold 2 (max 3)
[PSYoungGen: 38644K->3072K(45056K)] 40154K->4581K(198656K), 0.0037607 secs] [Times: user=0.01 sys=0.00, real=0.00 secs] 
Heap after GC invocations=5 (full 0):
 PSYoungGen      total 45056K, used 3072K [0x00000007bce00000, 0x00000007c0000000, 0x00000007c0000000)
  eden space 38912K, 0% used [0x00000007bce00000,0x00000007bce00000,0x00000007bf400000)
  from space 6144K, 50% used [0x00000007bf400000,0x00000007bf700030,0x00000007bfa00000)
  to   space 3584K, 0% used [0x00000007bfc80000,0x00000007bfc80000,0x00000007c0000000)
 ParOldGen       total 153600K, used 1509K [0x00000007b3800000, 0x00000007bce00000, 0x00000007bce00000)
  object space 153600K, 0% used [0x00000007b3800000,0x00000007b39797c8,0x00000007bce00000)
 Metaspace       used 3290K, capacity 4496K, committed 4864K, reserved 1056768K
  class space    used 362K, capacity 388K, committed 512K, reserved 1048576K
}

CMS中 log:

{Heap before GC invocations=1 (full 0):
 par new generation   total 46080K, used 42256K [0x00000007b3800000, 0x00000007b6a00000, 0x00000007b6a00000)
  eden space 40960K,  99% used [0x00000007b3800000, 0x00000007b5fc6ae0, 0x00000007b6000000)
  from space 5120K,  29% used [0x00000007b6500000, 0x00000007b667d750, 0x00000007b6a00000)
  to   space 5120K,   0% used [0x00000007b6000000, 0x00000007b6000000, 0x00000007b6500000)
 concurrent mark-sweep generation total 153600K, used 0K [0x00000007b6a00000, 0x00000007c0000000, 0x00000007c0000000)
 Metaspace       used 3288K, capacity 4496K, committed 4864K, reserved 1056768K
  class space    used 362K, capacity 388K, committed 512K, reserved 1048576K
2018-08-03T17:40:09.703-0800: [GC (Allocation Failure) 2018-08-03T17:40:09.703-0800: [ParNew
Desired survivor size 3145728 bytes, new threshold 3 (max 3)
- age   2:    1492936 bytes,    1492936 total
: 42256K->1686K(46080K), 0.0013712 secs] 42256K->1686K(199680K), 0.0014078 secs] [Times: user=0.00 sys=0.00, real=0.00 secs] 
Heap after GC invocations=2 (full 0):
 par new generation   total 46080K, used 1686K [0x00000007b3800000, 0x00000007b6a00000, 0x00000007b6a00000)
  eden space 40960K,   0% used [0x00000007b3800000, 0x00000007b3800000, 0x00000007b6000000)
  from space 5120K,  32% used [0x00000007b6000000, 0x00000007b61a5b18, 0x00000007b6500000)
  to   space 5120K,   0% used [0x00000007b6500000, 0x00000007b6500000, 0x00000007b6a00000)
 concurrent mark-sweep generation total 153600K, used 0K [0x00000007b6a00000, 0x00000007c0000000, 0x00000007c0000000)
 Metaspace       used 3288K, capacity 4496K, committed 4864K, reserved 1056768K
  class space    used 362K, capacity 388K, committed 512K, reserved 1048576K
}
2、-verbose:gc

作用:每次gc(yonggc,fullgc) 输出前后结果信息
** CMS&ParallelGC中log:**

[GC (Allocation Failure)  37929K->1720K(198656K), 0.0015626 secs]
[GC (Allocation Failure)  40362K->1576K(198656K), 0.0018508 secs]
3、-XX:+PrintTenuringDistribution

作用:每次新生代 young GC时,输出幸存区中对象的年龄分布

ParallelGC中log:

Desired survivor size 6291456 bytes, new threshold 3 (max 3)

Desired survivor size 6291456 bytes, new threshold 3 (max 3)

Desired survivor size 6291456 bytes, new threshold 3 (max 3)

CMS中log:

Desired survivor size 3145728 bytes, new threshold 3 (max 3)
- age   1:    1528520 bytes,    1528520 total

Desired survivor size 3145728 bytes, new threshold 3 (max 3)
- age   2:    1493000 bytes,    1493000 total
4、-XX:+PrintGCDateStamps

作用:输出GC的时间戳(以日期的形式,如 2019-11-30T17:54:12.986-0800)
ParallelGC中log:

CMS中log:

{Heap before GC invocations=0 (full 0):
par new generation   total 9216K, used 8191K [0x00000007bce00000, 0x00000007bd800000, 0x00000007bd800000)
eden space 8192K,  99% used [0x00000007bce00000, 0x00000007bd5ffc38, 0x00000007bd600000)
from space 1024K,   0% used [0x00000007bd600000, 0x00000007bd600000, 0x00000007bd700000)
to   space 1024K,   0% used [0x00000007bd700000, 0x00000007bd700000, 0x00000007bd800000)
concurrent mark-sweep generation total 40960K, used 0K [0x00000007bd800000, 0x00000007c0000000, 0x00000007c0000000)
Metaspace       used 2674K, capacity 4490K, committed 4864K, reserved 1056768K
class space    used 288K, capacity 386K, committed 512K, reserved 1048576K
2019-11-30T17:54:12.986-0800: 0.126: [GC (Allocation Failure) 2019-11-30T17:54:12.986-0800: 0.126: [ParNew2019-11-30T17:54:12.995-0800: 0.134: [SoftReference, 0 refs, 0.0000312 secs]2019-11-30T17:54:12.995-0800: 0.134: [WeakReference, 10 refs, 0.0000163 secs]2019-11-30T17:54:12.995-0800: 0.134: [FinalReference, 0 refs, 0.0000166 secs]2019-11-30T17:54:12.995-0800: 0.134: [PhantomReference, 0 refs, 0 refs, 0.0000149 secs]2019-11-30T17:54:12.995-0800: 0.134: [JNI Weak Reference, 0.0000138 secs]: 8191K->1024K(9216K), 0.0083958 secs] 8191K->7628K(50176K), 0.0084375 secs] [Times: user=0.01 sys=0.01, real=0.01 secs] 
Heap after GC invocations=1 (full 0):
par new generation   total 9216K, used 1024K [0x00000007bce00000, 0x00000007bd800000, 0x00000007bd800000)
eden space 8192K,   0% used [0x00000007bce00000, 0x00000007bce00000, 0x00000007bd600000)
from space 1024K, 100% used [0x00000007bd700000, 0x00000007bd800000, 0x00000007bd800000)
to   space 1024K,   0% used [0x00000007bd600000, 0x00000007bd600000, 0x00000007bd700000)
concurrent mark-sweep generation total 40960K, used 6604K [0x00000007bd800000, 0x00000007c0000000, 0x00000007c0000000)
Metaspace       used 2674K, capacity 4490K, committed 4864K, reserved 1056768K
class space    used 288K, capacity 386K, committed 512K, reserved 1048576K
}
5、-XX:+PrintGCDetails

作用:输出GC的详细日志,相比-XX:+PrintHeapAtGC力度粗了很多,重点放在了回收♻️耗时上级,只分YongGeneration与OldGeneration。
ParallelGC中log:

[GC (Allocation Failure) [PSYoungGen: 37929K->1616K(45056K)] 37929K->1624K(198656K), 0.0022814 secs] [Times: user=0.00 sys=0.00, real=0.00 secs] 
[GC (Allocation Failure) [PSYoungGen: 40258K->1664K(45056K)] 40266K->1672K(198656K), 0.0019262 secs] [Times: user=0.01 sys=0.01, real=0.00 secs] 
[GC (Allocation Failure) [PSYoungGen: 40062K->1584K(45056K)] 40070K->1592K(198656K), 0.0010587 secs] [Times: user=0.00 sys=0.00, real=0.00 secs] 
[GC (Allocation Failure) [PSYoungGen: 40225K->0K(45056K)] 40233K->1501K(198656K), 0.0018711 secs] [Times: user=0.01 sys=0.00, real=0.00 secs] 

CMS中log:

[GC (Allocation Failure) [ParNew: 40141K->1529K(46080K), 0.0016821 secs] 40141K->1529K(199680K), 0.0017271 secs] [Times: user=0.01 sys=0.00, real=0.00 secs] 
[GC (Allocation Failure) [ParNew: 42260K->1618K(46080K), 0.0015961 secs] 42260K->1618K(199680K), 0.0016258 secs] [Times: user=0.01 sys=0.00, real=0.00 secs] 
[GC (Allocation Failure) [ParNew: 42145K->1637K(46080K), 0.0013662 secs] 42145K->1637K(199680K), 0.0014078 secs] [Times: user=0.01 sys=0.01, real=0.00 secs] 
[GC (Allocation Failure) [ParNew: 42366K->0K(46080K), 0.0049625 secs] 42366K->1502K(199680K), 0.0049983 secs] [Times: user=0.01 sys=0.00, real=0.01 secs] 
6、 -XX:+PrintReferenceGC

作用:输出GC回收的四种应用类型详情。

{Heap before GC invocations=0 (full 0):
 par new generation   total 9216K, used 8189K [0x00000007bce00000, 0x00000007bd800000, 0x00000007bd800000)
  eden space 8192K,  99% used [0x00000007bce00000, 0x00000007bd5ff4b8, 0x00000007bd600000)
  from space 1024K,   0% used [0x00000007bd600000, 0x00000007bd600000, 0x00000007bd700000)
  to   space 1024K,   0% used [0x00000007bd700000, 0x00000007bd700000, 0x00000007bd800000)
 concurrent mark-sweep generation total 40960K, used 0K [0x00000007bd800000, 0x00000007c0000000, 0x00000007c0000000)
 Metaspace       used 2674K, capacity 4490K, committed 4864K, reserved 1056768K
  class space    used 288K, capacity 386K, committed 512K, reserved 1048576K
0.106: [GC (Allocation Failure) 0.106: [ParNew0.113: [SoftReference, 0 refs, 0.0000162 secs]0.113: [WeakReference, 10 refs, 0.0000077 secs]0.113: [FinalReference, 0 refs, 0.0000057 secs]0.113: [PhantomReference, 0 refs, 0 refs, 0.0000076 secs]0.113: [JNI Weak Reference, 0.0000074 secs]: 8189K->1024K(9216K), 0.0074205 secs] 8189K->7621K(50176K), 0.0074596 secs] [Times: user=0.01 sys=0.01, real=0.00 secs] 
Heap after GC invocations=1 (full 0):
 par new generation   total 9216K, used 1024K [0x00000007bce00000, 0x00000007bd800000, 0x00000007bd800000)
  eden space 8192K,   0% used [0x00000007bce00000, 0x00000007bce00000, 0x00000007bd600000)
  from space 1024K, 100% used [0x00000007bd700000, 0x00000007bd800000, 0x00000007bd800000)
  to   space 1024K,   0% used [0x00000007bd600000, 0x00000007bd600000, 0x00000007bd700000)
 concurrent mark-sweep generation total 40960K, used 6597K [0x00000007bd800000, 0x00000007c0000000, 0x00000007c0000000)
 Metaspace       used 2674K, capacity 4490K, committed 4864K, reserved 1056768K
  class space    used 288K, capacity 386K, committed 512K, reserved 1048576K
}

CMS-YongGC-log中截取 -XX:+PrintReferenceGC 作用:

[GC (Allocation Failure) 
  0.106: [ParNew
    0.113:[SoftReference, 0 refs, 0.0000162 secs]
    0.113:[WeakReference, 10 refs, 0.0000077 secs]
    0.113:[FinalReference, 0 refs, 0.0000057 secs]
    0.113:[PhantomReference, 0 refs, 0 refs, 0.0000076 secs]
    0.113:[JNI Weak Reference, 0.0000074 secs]
  :8189K->1024K(9216K), 0.0074205 secs] 
8189K->7621K(50176K), 0.0074596 secs] 
[Times: user=0.01 sys=0.01, real=0.00 secs] 

将以此回收♻️中涉及到的四种引用信息详情输出到log中。(如上log中WeakReference清理了10个引用)

7、-XX:+PrintGCTimeStamps

作用:输出GC的时间戳(以基准时间的形式)。

image.png

不仔细对比真的无法发现加了这个参数gclog有什么变化。

8、-XX:+PrintGC

CMS中log:

7.774: [GC (Allocation Failure)  32768K->17253K(200704K), 0.0833318 secs]
23.877: [GC (Allocation Failure)  50021K->52439K(200704K), 0.0543904 secs]
40.501: [GC (Allocation Failure)  85207K->84427K(200704K), 0.0473820 secs]
56.633: [GC (Allocation Failure)  117195K->116277K(200704K), 0.0425909 secs]
73.247: [GC (Allocation Failure)  149045K->148270K(200704K), 0.0435195 secs]
73.291: [GC (CMS Initial Mark)  148386K(200704K), 0.0011136 secs]
73.396: [GC (CMS Final Remark)  148767K(200704K), 0.0028249 secs]
75.464: [GC (CMS Initial Mark)  153371K(200704K), 0.0033355 secs]
80.679: [GC (CMS Final Remark)  163165K(200704K), 0.0045811 secs]
82.747: [GC (CMS Initial Mark)  167081K(200704K), 0.0065648 secs]
82.858: [GC (CMS Final Remark)  168061K(200704K), 0.0061034 secs]
84.933: [GC (CMS Initial Mark)  171915K(200704K), 0.0108552 secs]
85.047: [GC (CMS Final Remark)  171915K(200704K), 0.0085279 secs]
87.120: [GC (CMS Initial Mark)  175833K(200704K), 0.0084935 secs]
8、-XX:+PrintGCApplicationStoppedTime

作用:打印GC造成应用暂停的时间。 tips:web页面有卡顿可以参考这个值来进行排查问题。

{Heap before GC invocations=0 (full 0):
 par new generation   total 9216K, used 8191K [0x00000007bce00000, 0x00000007bd800000, 0x00000007bd800000)
  eden space 8192K,  99% used [0x00000007bce00000, 0x00000007bd5ffc38, 0x00000007bd600000)
  from space 1024K,   0% used [0x00000007bd600000, 0x00000007bd600000, 0x00000007bd700000)
  to   space 1024K,   0% used [0x00000007bd700000, 0x00000007bd700000, 0x00000007bd800000)
 concurrent mark-sweep generation total 40960K, used 0K [0x00000007bd800000, 0x00000007c0000000, 0x00000007c0000000)
 Metaspace       used 2674K, capacity 4490K, committed 4864K, reserved 1056768K
  class space    used 288K, capacity 386K, committed 512K, reserved 1048576K
2019-11-30T18:23:40.613-0800: [GC (Allocation Failure) 2019-11-30T18:23:40.613-0800: [ParNew: 8191K->1023K(9216K), 0.0076207 secs] 8191K->7626K(50176K), 0.0076643 secs] [Times: user=0.01 sys=0.00, real=0.01 secs] 
Heap after GC invocations=1 (full 0):
 par new generation   total 9216K, used 1023K [0x00000007bce00000, 0x00000007bd800000, 0x00000007bd800000)
  eden space 8192K,   0% used [0x00000007bce00000, 0x00000007bce00000, 0x00000007bd600000)
  from space 1024K,  99% used [0x00000007bd700000, 0x00000007bd7ffff8, 0x00000007bd800000)
  to   space 1024K,   0% used [0x00000007bd600000, 0x00000007bd600000, 0x00000007bd700000)
 concurrent mark-sweep generation total 40960K, used 6602K [0x00000007bd800000, 0x00000007c0000000, 0x00000007c0000000)
 Metaspace       used 2674K, capacity 4490K, committed 4864K, reserved 1056768K
  class space    used 288K, capacity 386K, committed 512K, reserved 1048576K
}
2019-11-30T18:23:40.620-0800: Total time for which application threads were stopped: 0.0078554 seconds, Stopping threads took: 0.0000152 seconds
2019-11-30T18:23:44.632-0800: Total time for which application threads were stopped: 0.0001055 seconds, Stopping threads took: 0.0000237 seconds
如上log中最后两行就是jvm回收♻️造成的应用服务器停顿时间!


看看你需要那种?
是的组合在一起,才是真爱~
我一般这么组合:

-XX:+PrintHeapAtGC -XX:+PrintGCDateStamps -XX:+PrintGCDetails  -XX:+PrintGCApplicationStoppedTime
-XX:+PrintReferenceGC -XX:+PrintTenuringDistribution 
-Xloggc:/export/Logs/xxxxxxx/tomcat7-cms-gc.log

你可能感兴趣的:(jvm 基础篇-(3)-gclog输出常用参数要不要了解下?-XX:+PrintHeapAtGC -verbose:gc -XX:+PrintTenuringDistribution -XX...)