GC topic - View Log

GC log parameter list

-XX:+PrintGC 输出GC日志
-XX:+PrintGCDetails 输出GC的详细日志
-XX:+PrintGCTimeStamps 输出GC的时间戳(以基准时间的形式)
-XX:+PrintGCDateStamps 输出GC的时间戳(以日期的形式,如 2013-05-04T21:53:59.234+0800)
-XX:+PrintHeapAtGC 在进行GC的前后打印出堆的信息
-Xloggc:../logs/gc.log 日志文件的输出路径

Note:
GC logs are alternative ways (>) is written, rather than appending (>>), if the next write to the same file, then previous GC content will be cleared. You can add the following script before the program starts or stops when the dump before gc.log to other files.

if [ -f ${LOGS}/gc.log ]; then
    mv ${LOGS}/gc.log ${LOGS}/gc.log.`date +%Y%m%d%H%M%S`
fi

GC log example

GC Parameters In addition, more consistent production environment to increase the number of fixed parameters as follows


-Xms2g -Xmx2g -Xmn1g -XX:MetaspaceSize=256m -XX:MaxMetaspaceSize=512m -XX:MaxDirectMemorySize=1g -XX:SurvivorRatio=10 -XX:+UseConcMarkSweepGC

-XX:+PrintGC -Xloggc:gc.log

0.687: [GC (Allocation Failure)  873632K->751K(2009792K), 0.0024686 secs]
0.797: [GC (Allocation Failure)  874392K->805K(2009792K), 0.0016258 secs]
0.878: [GC (Allocation Failure)  874217K->765K(2009792K), 0.0014693 secs]
0.958: [GC (Allocation Failure)  874337K->703K(2009792K), 0.0015396 secs]
1.036: [GC (Allocation Failure)  874399K->852K(2009792K), 0.0022075 secs]
1.117: [GC (Allocation Failure)  874628K->772K(2009792K), 0.0015507 secs]
1.194: [GC (Allocation Failure)  874600K->788K(2009792K), 0.0014966 secs]

-XX:+PrintGC -XX:+PrintHeapAtGC -Xloggc:gc.log

{Heap before GC invocations=0 (full 0):
 par new generation   total 961216K, used 873632K [0x0000000760800000, 0x00000007a0800000, 0x00000007a0800000)
  eden space 873856K,  99% used [0x0000000760800000, 0x0000000795d28150, 0x0000000795d60000)
  from space 87360K,   0% used [0x0000000795d60000, 0x0000000795d60000, 0x000000079b2b0000)
  to   space 87360K,   0% used [0x000000079b2b0000, 0x000000079b2b0000, 0x00000007a0800000)
 concurrent mark-sweep generation total 1048576K, used 0K [0x00000007a0800000, 0x00000007e0800000, 0x00000007e0800000)
 Metaspace       used 3261K, capacity 4556K, committed 4864K, reserved 1056768K
  class space    used 320K, capacity 392K, committed 512K, reserved 1048576K
0.585: [GC (Allocation Failure)  873632K->765K(2009792K), 0.0022171 secs]
Heap after GC invocations=1 (full 0):
 par new generation   total 961216K, used 765K [0x0000000760800000, 0x00000007a0800000, 0x00000007a0800000)
  eden space 873856K,   0% used [0x0000000760800000, 0x0000000760800000, 0x0000000795d60000)
  from space 87360K,   0% used [0x000000079b2b0000, 0x000000079b36f520, 0x00000007a0800000)
  to   space 87360K,   0% used [0x0000000795d60000, 0x0000000795d60000, 0x000000079b2b0000)
 concurrent mark-sweep generation total 1048576K, used 0K [0x00000007a0800000, 0x00000007e0800000, 0x00000007e0800000)
 Metaspace       used 3261K, capacity 4556K, committed 4864K, reserved 1056768K
  class space    used 320K, capacity 392K, committed 512K, reserved 1048576K
}
{Heap before GC invocations=1 (full 0):
 par new generation   total 961216K, used 874406K [0x0000000760800000, 0x00000007a0800000, 0x00000007a0800000)
  eden space 873856K,  99% used [0x0000000760800000, 0x0000000795d2a518, 0x0000000795d60000)
  from space 87360K,   0% used [0x000000079b2b0000, 0x000000079b36f520, 0x00000007a0800000)
  to   space 87360K,   0% used [0x0000000795d60000, 0x0000000795d60000, 0x000000079b2b0000)
 concurrent mark-sweep generation total 1048576K, used 0K [0x00000007a0800000, 0x00000007e0800000, 0x00000007e0800000)
 Metaspace       used 3262K, capacity 4556K, committed 4864K, reserved 1056768K
  class space    used 320K, capacity 392K, committed 512K, reserved 1048576K
0.701: [GC (Allocation Failure)  874406K->834K(2009792K), 0.0019298 secs]
Heap after GC invocations=2 (full 0):
 par new generation   total 961216K, used 834K [0x0000000760800000, 0x00000007a0800000, 0x00000007a0800000)
  eden space 873856K,   0% used [0x0000000760800000, 0x0000000760800000, 0x0000000795d60000)
  from space 87360K,   0% used [0x0000000795d60000, 0x0000000795e308a0, 0x000000079b2b0000)
  to   space 87360K,   0% used [0x000000079b2b0000, 0x000000079b2b0000, 0x00000007a0800000)
 concurrent mark-sweep generation total 1048576K, used 0K [0x00000007a0800000, 0x00000007e0800000, 0x00000007e0800000)
 Metaspace       used 3262K, capacity 4556K, committed 4864K, reserved 1056768K
  class space    used 320K, capacity 392K, committed 512K, reserved 1048576K
}

-XX:+PrintGCDetails -XX:+PrintHeapAtGC -Xloggc:gc.log

{Heap before GC invocations=0 (full 0):
 par new generation   total 961216K, used 873632K [0x0000000760800000, 0x00000007a0800000, 0x00000007a0800000)
  eden space 873856K,  99% used [0x0000000760800000, 0x0000000795d28150, 0x0000000795d60000)
  from space 87360K,   0% used [0x0000000795d60000, 0x0000000795d60000, 0x000000079b2b0000)
  to   space 87360K,   0% used [0x000000079b2b0000, 0x000000079b2b0000, 0x00000007a0800000)
 concurrent mark-sweep generation total 1048576K, used 0K [0x00000007a0800000, 0x00000007e0800000, 0x00000007e0800000)
 Metaspace       used 3261K, capacity 4556K, committed 4864K, reserved 1056768K
  class space    used 320K, capacity 392K, committed 512K, reserved 1048576K
0.793: [GC (Allocation Failure) 0.793: [ParNew: 873632K->765K(961216K), 0.0039284 secs] 873632K->765K(2009792K), 0.0041837 secs] [Times: user=0.01 sys=0.00, real=0.01 secs] 
Heap after GC invocations=1 (full 0):
 par new generation   total 961216K, used 765K [0x0000000760800000, 0x00000007a0800000, 0x00000007a0800000)
  eden space 873856K,   0% used [0x0000000760800000, 0x0000000760800000, 0x0000000795d60000)
  from space 87360K,   0% used [0x000000079b2b0000, 0x000000079b36f520, 0x00000007a0800000)
  to   space 87360K,   0% used [0x0000000795d60000, 0x0000000795d60000, 0x000000079b2b0000)
 concurrent mark-sweep generation total 1048576K, used 0K [0x00000007a0800000, 0x00000007e0800000, 0x00000007e0800000)
 Metaspace       used 3261K, capacity 4556K, committed 4864K, reserved 1056768K
  class space    used 320K, capacity 392K, committed 512K, reserved 1048576K
}
{Heap before GC invocations=1 (full 0):
 par new generation   total 961216K, used 874406K [0x0000000760800000, 0x00000007a0800000, 0x00000007a0800000)
  eden space 873856K,  99% used [0x0000000760800000, 0x0000000795d2a518, 0x0000000795d60000)
  from space 87360K,   0% used [0x000000079b2b0000, 0x000000079b36f520, 0x00000007a0800000)
  to   space 87360K,   0% used [0x0000000795d60000, 0x0000000795d60000, 0x000000079b2b0000)
 concurrent mark-sweep generation total 1048576K, used 0K [0x00000007a0800000, 0x00000007e0800000, 0x00000007e0800000)
 Metaspace       used 3262K, capacity 4556K, committed 4864K, reserved 1056768K
  class space    used 320K, capacity 392K, committed 512K, reserved 1048576K
0.917: [GC (Allocation Failure) 0.917: [ParNew: 874406K->776K(961216K), 0.0015625 secs] 874406K->776K(2009792K), 0.0016277 secs] [Times: user=0.01 sys=0.00, real=0.00 secs] 
Heap after GC invocations=2 (full 0):
 par new generation   total 961216K, used 776K [0x0000000760800000, 0x00000007a0800000, 0x00000007a0800000)
  eden space 873856K,   0% used [0x0000000760800000, 0x0000000760800000, 0x0000000795d60000)
  from space 87360K,   0% used [0x0000000795d60000, 0x0000000795e221c8, 0x000000079b2b0000)
  to   space 87360K,   0% used [0x000000079b2b0000, 0x000000079b2b0000, 0x00000007a0800000)
 concurrent mark-sweep generation total 1048576K, used 0K [0x00000007a0800000, 0x00000007e0800000, 0x00000007e0800000)
 Metaspace       used 3262K, capacity 4556K, committed 4864K, reserved 1056768K
  class space    used 320K, capacity 392K, committed 512K, reserved 1048576K
}

-XX:+PrintGCDetails -XX:+PrintHeapAtGC -Xloggc:gc.log -XX:+PrintGCDateStamps

{Heap before GC invocations=0 (full 0):
 par new generation   total 961216K, used 873632K [0x0000000760800000, 0x00000007a0800000, 0x00000007a0800000)
  eden space 873856K,  99% used [0x0000000760800000, 0x0000000795d28150, 0x0000000795d60000)
  from space 87360K,   0% used [0x0000000795d60000, 0x0000000795d60000, 0x000000079b2b0000)
  to   space 87360K,   0% used [0x000000079b2b0000, 0x000000079b2b0000, 0x00000007a0800000)
 concurrent mark-sweep generation total 1048576K, used 0K [0x00000007a0800000, 0x00000007e0800000, 0x00000007e0800000)
 Metaspace       used 3260K, capacity 4556K, committed 4864K, reserved 1056768K
  class space    used 320K, capacity 392K, committed 512K, reserved 1048576K
2020-02-26T14:50:12.302-0800: 0.579: [GC (Allocation Failure) 2020-02-26T14:50:12.302-0800: 0.579: [ParNew: 873632K->84744K(961216K), 0.0430026 secs] 873632K->84744K(2009792K), 0.0431113 secs] [Times: user=0.22 sys=0.05, real=0.04 secs] 
Heap after GC invocations=1 (full 0):
 par new generation   total 961216K, used 84744K [0x0000000760800000, 0x00000007a0800000, 0x00000007a0800000)
  eden space 873856K,   0% used [0x0000000760800000, 0x0000000760800000, 0x0000000795d60000)
  from space 87360K,  97% used [0x000000079b2b0000, 0x00000007a05723f0, 0x00000007a0800000)
  to   space 87360K,   0% used [0x0000000795d60000, 0x0000000795d60000, 0x000000079b2b0000)
 concurrent mark-sweep generation total 1048576K, used 0K [0x00000007a0800000, 0x00000007e0800000, 0x00000007e0800000)
 Metaspace       used 3260K, capacity 4556K, committed 4864K, reserved 1056768K
  class space    used 320K, capacity 392K, committed 512K, reserved 1048576K
}
{Heap before GC invocations=1 (full 0):
 par new generation   total 961216K, used 958386K [0x0000000760800000, 0x00000007a0800000, 0x00000007a0800000)
  eden space 873856K,  99% used [0x0000000760800000, 0x0000000795d2a518, 0x0000000795d60000)
  from space 87360K,  97% used [0x000000079b2b0000, 0x00000007a05723f0, 0x00000007a0800000)
  to   space 87360K,   0% used [0x0000000795d60000, 0x0000000795d60000, 0x000000079b2b0000)
 concurrent mark-sweep generation total 1048576K, used 0K [0x00000007a0800000, 0x00000007e0800000, 0x00000007e0800000)
 Metaspace       used 3261K, capacity 4556K, committed 4864K, reserved 1056768K
  class space    used 320K, capacity 392K, committed 512K, reserved 1048576K
2020-02-26T14:50:12.445-0800: 0.723: [GC (Allocation Failure) 2020-02-26T14:50:12.445-0800: 0.723: [ParNew: 958386K->86052K(961216K), 0.0858331 secs] 958386K->170593K(2009792K), 0.0859161 secs] [Times: user=0.34 sys=0.08, real=0.09 secs] 
Heap after GC invocations=2 (full 0):
 par new generation   total 961216K, used 86052K [0x0000000760800000, 0x00000007a0800000, 0x00000007a0800000)
  eden space 873856K,   0% used [0x0000000760800000, 0x0000000760800000, 0x0000000795d60000)
  from space 87360K,  98% used [0x0000000795d60000, 0x000000079b169330, 0x000000079b2b0000)
  to   space 87360K,   0% used [0x000000079b2b0000, 0x000000079b2b0000, 0x00000007a0800000)
 concurrent mark-sweep generation total 1048576K, used 84540K [0x00000007a0800000, 0x00000007e0800000, 0x00000007e0800000)
 Metaspace       used 3261K, capacity 4556K, committed 4864K, reserved 1056768K
  class space    used 320K, capacity 392K, committed 512K, reserved 1048576K
}

GC log interpretation

Log substantially above this line are as follows, on the interpretation of each segment

示例
2020-02-26T14:50:12.445-0800: 0.723: [GC (Allocation Failure) 2020-02-26T14:50:12.445-0800: 0.723: [ParNew: 958386K->86052K(961216K), 0.0858331 secs] 958386K->170593K(2009792K), 0.0859161 secs] [Times: user=0.34 sys=0.08, real=0.09 secs] 


// gc发生的时间点
2020-02-26T14:50:12.445-0800: 0.723: 

// GC (分配 失败)
[GC (Allocation Failure) 2020-02-26T14:50:12.445-0800: 0.723: 

//年青代gc收集器是ParNew:年青代(eden+from+to)整体占用了(961216K),其中部分年青代(eden+from)空间回收前占用了958386K,回收后变成了86052K,耗时0.0859161 secs
[ParNew: 958386K->86052K(961216K), 0.0858331 secs] 

//整个堆回收前的占用了958386K->回收后的占用了170593K,整个堆大小(2009792K)
958386K->170593K(2009792K), 0.0859161 secs] 

//用户耗时0.34秒 , 系统耗时0.08秒 , 实际耗时 0.09秒
[Times: user=0.34 sys=0.08, real=0.09 secs] 

GC time-consuming log interpretation

I did a little knowledge you understand whether the above paragraph, the following case will be explained in detail

//用户耗时0.34秒 , 系统耗时0.08秒 , 实际耗时 0.09秒
[Times: user=0.34 sys=0.08, real=0.09 secs] 

Official English Description

  • Real is wall clock time – time from start to finish of the call. This is all elapsed time including time slices used by other processes and time the process spends blocked (for example if it is waiting for I/O to complete).

  • User is the amount of CPU time spent in user-mode code (outside the kernel) within the process. This is only actual CPU time used in executing the process. Other processes and time the process spends blocked do not count towards this figure.

  • Sys is the amount of CPU time spent in the kernel within the process. This means executing CPU time spent in system calls within the kernel, as opposed to library code, which is still running in user-space. Like ‘user’, this is only CPU time used by the process.

Chinese Description

  • real - time clock program from start to finish used. This time includes the time sheet and blocked processes used by other processes (such as waiting for I / O completion).

  • user - user mode process executing the code (than the core) time used. This is the actual CPU time used to perform this process, other processes and the process to block time is not included. In the case of garbage collection, it represents the total execution time CPU GC threads used.

  • sys - process kernel mode CPU time consumed, that call or waiting for CPU time used by system events in the kernel execution system.

Interpretation of
user + sys CPU time tells us that the program execution time actually used. Note that this means all the CPU, so if there are multiple threads in the process, then this may take longer than real time clock represented.
This is on top of the log user (0.34) + sys (0.08 )> reason for real (0.09 secs) of.
So we observe a single gc time consuming spending is mainly to see real field situation.

Annex: java code is used herein,

public class GarbageCollectorDemo {
    public static void main(String[] args) {
        /* -XX:+UseParallelOldGC和-XX:+UseParallelGC结果一样,因为MXBean名字一样,但是实际使用的不一样 */
        List<GarbageCollectorMXBean> gcbeans = ManagementFactory.getGarbageCollectorMXBeans();
        for (GarbageCollectorMXBean gcbean : gcbeans) {
            System.out.println("alioolog gcbean:" + gcbean.getName());
        }
        List list2 = new ArrayList();
        for (int i = 0; i < 10000; i++) {
            List list = new ArrayList();
            byte[] b = new byte[1_000_000];
            list.add(b);

            if (i % 10 == 0) {
                list2.add(b);
            }
        }

        try {
            Thread.sleep(10 * 60 * 1000L);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }
}

Published 101 original articles · won praise 67 · views 260 000 +

Guess you like

Origin blog.csdn.net/hl_java/article/details/104522545