golang学习笔记-查看gc

[Go GC 20 问]https://mp.weixin.qq.com/s?__biz=MjM5MDUwNTQwMQ==&mid=2257484062&idx=1&sn=40a8cca15b9c215f8a29e60e6d8a3542&scene=21#wechat_redirect

windows:

在cmd命令行下:
1.设置跟踪GC的临时环境变量

set GOGCTRACE=1
set GODEBUG=gctrace=1

2.将gc写入日志中

 xxx.exe 2> gc.log

在生成的gc跟踪日志中查看gc的过程,下面是截取的一部分gc日志:

gc 1 @0.005s 0%: 0+11+0.99 ms clock, 0+0/15/0+7.9 ms cpu, 25->25->24 MB, 26 MB goal, 8 P
gc 2 @0.033s 0%: 0+2.5+0 ms clock, 0+0/5.0/9.0+0 ms cpu, 25->26->25 MB, 49 MB goal, 8 P
gc 3 @0.213s 0%: 0+3.0+0 ms clock, 0+0/6.0/14+0 ms cpu, 37->38->33 MB, 51 MB goal, 8 P
gc 4 @1.197s 0%: 0+4.5+0 ms clock, 0+0.50/9.0/18+0 ms cpu, 57->57->47 MB, 66 MB goal, 8 P
gc 5 @2.162s 0%: 0+5.0+0 ms clock, 0+1.0/8.0/18+0 ms cpu, 88->88->54 MB, 94 MB goal, 8 P
gc 6 @3.048s 0%: 0+4.5+0 ms clock, 0+0.50/8.5/20+0 ms cpu, 104->105->68 MB, 108 MB goal, 8 P
gc 7 @4.424s 0%: 0+6.5+0 ms clock, 0+0.50/9.5/24+0 ms cpu, 133->133->89 MB, 137 MB goal, 8 P
gc 8 @6.326s 0%: 0+4.5+0 ms clock, 0+0/8.5/19+0 ms cpu, 175->175->93 MB, 179 MB goal, 8 P
gc 9 @8.695s 0%: 0+5.5+0 ms clock, 0+0.50/10/22+0 ms cpu, 181->181->100 MB, 186 MB goal, 8 P
scvg4: inuse: 143, idle: 70, sys: 213, released: 0, consumed: 213 (MB)

说明:gc 1 @0.005s 0%: 0+11+0.99 ms clock, 0+0/15/0+7.9 ms cpu, 25->25->24 MB, 26 MB goal, 8 P
gc 1:说明gc过程,不做解释,1 表示第几次执行gc操作
@0.005s:表示程序执行的总时间
0%::表示gc时时间和程序运行总时间的百分比
0+11+0.99 ms clock,wall-clock (还不清楚什么意思)
0+0/15/0+7.9 ms cpu,CPU times for the phases of the GC (还不清楚什么意思)
25->25->24 MB,:gc开始时的堆大小;GC结束时的堆大小;存活的堆大小
26 MB goal,:整体堆的大小
8 P:使用的处理器的数量

说明 scvg4: inuse: 143, idle: 70, sys: 213, released: 0, consumed: 213 (MB)

inuse: 143,:使用多少M内存
idle: 70,:0 剩下要清除的内存
sys: 213,: 系统映射的内存
released: 0,: 释放的系统内存
consumed: 213: 申请的系统内存

官网部分释义

gctrace: setting gctrace=1 causes the garbage collector to emit a single line to standard
error at each collection, summarizing the amount of memory collected and the
length of the pause. Setting gctrace=2 emits the same summary but also
repeats each collection. The format of this line is subject to change.
Currently, it is:
	gc # @#s #%: #+#+# ms clock, #+#/#/#+# ms cpu, #->#-># MB, # MB goal, # P
where the fields are as 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 used
The phases are stop-the-world (STW) sweep termination, concurrent
mark and scan, and STW mark termination. The CPU times
for mark/scan are broken down in to assist time (GC performed in
line with allocation), background GC time, and idle GC time.
If the line ends with "(forced)", this GC was forced by a
runtime.GC() call and all phases are STW.

Setting gctrace to any value > 0 also causes the garbage collector
to emit a summary when memory is released back to the system.
This process of returning memory to the system is called scavenging.
The format of this summary is subject to change.
Currently it is:
	scvg#: # MB released  printed only if non-zero
	scvg#: inuse: # idle: # sys: # released: # consumed: # (MB)
where the fields are 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 system
	released: #  MB released to the system
	consumed: #  MB allocated from the system

官方runtime

linux:

GODEBUG=gctrace=1 ./xxx

或者

GODEBUG=gctrace=1 ./xxx 2> gc.log
  • 1
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值