Open Gctrace in Golang

Source: Internet
Author: User
Tags emit
This is a creation in Article, where the information may have evolved or changed.

How to turn on print GC information

Just add the environment variables before the program executes GODEBUG gctrace =1 , such as:
GODEBUG gctrace =1 ./xxxx.exeorGODEBUG gctrace =1 go run main.go

The program will display GC information, as follows

GC 1 @2.104s 0%: 0.018+1.3+0.076 ms Clock, 0.054+0.35/1.0/3.0+0.23 MS CPU, 4->4->3 MB, 5 MB goal, 4 PGC 2 @2.241s 0% : 0.019+2.4+0.077 ms Clock, 0.079+0/2.4/6.4+0.30 MS CPU, 5->6->5 MB, 6 MB goal, 4 PGC 3 @2.510s 0%: 0.011+3.2+0.063 Ms Clock, 0.047+0.10/2.9/9.0+0.25 MS CPU, 11->11->10 MB, goal, 4 PGC 4 @3.021s 0%: 0.013+6.6+0.076 ms Clock, 0 .053+0.34/6.2/18+0.30 MS CPU, 21->21->20 MB, goal MB, 4 PGC 5 @3.725s 0%: 0.015+15+0.079 ms Clock, 0.062+0.35/15/ 45+0.31 MS CPU, 40->40->39 MB, goal MB, 4 PGC 6 @4.741s 0%: 0.008+35+0.17 ms Clock, 0.035+0.19/35/100+0.70 MS CPU , 76->76->75 MB, goal MB, 4 PGC 7 @6.688s 0%: 0.020+117+0.34 ms Clock, 0.082+11/117/330+1.3 MS CPU, 147->148-& gt;146 MB, 151 MB goal, 4 PGC 8 @68.645s 0%: 0.019+146+0.30 ms Clock, 0.078+0.006/146/407+1.2 MS CPU, 285->285->248 MB, 292 MB goal, 4 pscvg0:inuse:426, idle:0, sys:427, released:0, consumed:427 (MB) GC 9 @175.448s 0%: 0.030+60+0.12 Ms Clock, 0.12+0.013/60/177+0.51 MS CPU, 484->484->248 MB, 496 MB goal, 4 PGC @236.621s 0%: 0.006+59+0.11 ms Clock, 0.025+0/59/173+0.47 m s CPU, 484->484->248 MB, 496 MB goal, 4 PGC @285.967s 0%: 0.027+57+0.22 ms Clock, 0.11+0/57/163+0.89 MS CPU, 484-  >484->248 MB, 496 MB goal, 4 pscvg1:inuse:331, idle:175, sys:507, released:0, consumed:507 (MB) GC @333.817s 0%: 0.009+52+0.18 ms Clock, 0.036+0/52/155+0.72 MS CPU, 484->484->248 MB, 496 MB goal, 4 P

Meaning of GC information

View the official runtime instructions:

Gctrace:setting gctrace=1 causes the garbage collector to emit a single line to StandardError at each collection, Summari Zing The amount of memory collected and thelength of the pause. Setting gctrace=2 emits the same summary but alsorepeats each collection. The format of this was subject to change. Currently, it IS:GC # @ #s #%: #+#+# ms Clock, #+#/#/#+# MS CPU, #->#-># MB, # MB goal, # PWhere The fields is a          S FOLLOWS:GC # The GC number, incremented at each GC @ #s time in seconds since program start #%    Percentage of time spent in GC since program start #+...+# wall-clock/cpu times for the phases of the GC #->#-># MB Heap size at GC start, at GC end, and live heap # MB goal goal Heap Size # P number of Processors usedthe phases is Stop-the-world (STW) sweep termination, Concurrentmark and Scan, and STW mark termination. The CPU timesfor Mark/scan is broken down-assist time (GC performed inline with Allocation), background GC time, and idle GC time. If the line ends with "(forced)", this GC is forced by aruntime. GC () Call and all phases is STW.  Setting gctrace to all value > 0 also causes the garbage Collectorto emit a summary when memory was released back to the System. This process of returning memory to the system is called scavenging. The format of this summary are subject to change.  Currently it is:scvg#: # MB released printed only if Non-zero scvg#: inuse: # idle: # sys: # Released: # consumed: # (MB) where the fields is as follows:scvg# the scavenge cycle number, incremented at each scavenge inuse: # MB used or partially used spans idle: # MB spans pending scavenging sys: # MB mapped from the Syste M Released: # MB released to the system consumed: # MB allocated from the system

Garbage Collection Information
gc 1 @2.104s 0%: 0.018+1.3+0.076 ms clock, 0.054+0.35/1.0/3.0+0.23 ms cpu, 4->4->3 MB, 5 MB goal, 4 P.

1Represents the first time the execution
@2.104sindicates the total time of program execution
0%the percentage of garbage collection time taken up (don't know who to compare with?) Is the total time with the above program execution, so it feels meaningless
Time of 0.018+1.3+0.076 ms clock garbage collection, STW (Stop-the-world) sweep time, time for concurrent tagging and scanning, STW marking time
0.054+0.35/1.0/3.0+0.23 ms cpugarbage collection consumes CPU time
The size of the heap, the size of the 4->4->3 MB heap after the GC, the size of the surviving heap
5 MB goalthe size of the whole heap
4 Pnumber of processors used

System memory Recycling information, this is very straightforward, look at the word will know the meaning of
scvg0: inuse: 426, idle: 0, sys: 427, released: 0, consumed: 427 (MB)

426How many m of memory are used
0the rest of the memory to erase
427System-Mapped memory
0Freed system memory
427system Memory requested

1979 Reads ∙2 likes
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.