博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
golang开启GODEBUG gctrace =1 显示信息的含义
阅读量:6271 次
发布时间:2019-06-22

本文共 3955 字,大约阅读时间需要 13 分钟。

hot3.png

golang开启GODEBUG gctrace =1 显示信息的含义

标签(空格分隔): golang


如何开启打印gc信息

只要在程序执行之前加上环境变量GODEBUG gctrace =1 ,如:

GODEBUG gctrace =1 ./xxxx.exe or GODEBUG gctrace =1 go run main.go

程序将会显示gc信息,如下

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, 12 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, 22 MB goal, 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, 41 MB goal, 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, 78 MB goal, 4 Pgc 7 @6.688s 0%: 0.020+117+0.34 ms clock, 0.082+11/117/330+1.3 ms cpu, 147->148->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 10 @236.621s 0%: 0.006+59+0.11 ms clock, 0.025+0/59/173+0.47 ms cpu, 484->484->248 MB, 496 MB goal, 4 Pgc 11 @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 12 @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

gc信息的含义

查看官方的说明:

gctrace: setting gctrace=1 causes the garbage collector to emit a single line to standarderror at each collection, summarizing 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 line is subject to change.Currently, it is:	gc # @#s #%: #+#+# ms clock, #+#/#/#+# ms cpu, #->#-># MB, # MB goal, # Pwhere 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 usedThe phases are stop-the-world (STW) sweep termination, concurrentmark and scan, and STW mark termination. The CPU timesfor mark/scan are broken down in to assist time (GC performed inline with allocation), background GC time, and idle GC time.If the line ends with "(forced)", this GC was forced by aruntime.GC() call and all phases are STW.Setting gctrace to any value > 0 also causes the garbage collectorto 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

垃圾回收信息

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

1 表示第一次执行

@2.104s 表示程序执行的总时间
0% 垃圾回收时间占用的百分比,(不知道和谁比?难道是和上面的程序执行总时间,这样比较感觉没意义)
0.018+1.3+0.076 ms clock 垃圾回收的时间,分别为STW(stop-the-world)清扫的时间, 并发标记和扫描的时间,STW标记的时间
0.054+0.35/1.0/3.0+0.23 ms cpu 垃圾回收占用cpu时间
4->4->3 MB 堆的大小,gc后堆的大小,存活堆的大小
5 MB goal 整体堆的大小
4 P 使用的处理器数量

系统内存回收信息,这个很直白,看单词就知道大概意思了

scvg0: inuse: 426, idle: 0, sys: 427, released: 0, consumed: 427 (MB)

426 使用多少M内存

0 剩下要清除的内存
427 系统映射的内存
0 释放的系统内存
427 申请的系统内存

转载于:https://my.oschina.net/u/2374678/blog/799477

你可能感兴趣的文章
将 tomcat 安装成 windows 服务
查看>>
建立一个node.js服务器(使用express搭建第一个Web环境)
查看>>
Sql — CTE公用表表达式和With用法总结
查看>>
mysql update中需要根据条件列更新写法update case
查看>>
AJAX里调用AJAX,作定时进度刷新
查看>>
IOS修改webView背景透明以及IOS调用前台js的方法
查看>>
Iterating elements using NightWatchJS
查看>>
运行自己的 DaemonSet - 每天5分钟玩转 Docker 容器技术(131)
查看>>
Android studio动态调试
查看>>
Vue-cli + Express 构建的SPA Blog(前后分离)
查看>>
黄聪: $(document).click() 在iphone上不触发事件解决办法
查看>>
[Err] 1062 - Duplicate entry '0' for key 'PRIMARY'
查看>>
怎么保证系统可靠性
查看>>
autoHotKey 一些脚本积累
查看>>
linux下svn清除非版本控制文件的方法
查看>>
Gradle 设置全局代理
查看>>
使用iTerm2快捷连接SSH
查看>>
CentOS6.5安装kafka-2.10-0.8.2(单机)
查看>>
主从复制、读写分离水平拆分及库表散列
查看>>
spring boot controller设置 @Transactional 不回滚的解决办法
查看>>