示例代码 test.go
package main import ( "fmt" "time" ) func main() { a := "123" fmt.Println(a) B := make(chan int, 8) go func() { B <- 1 }() go func() { fmt.Println(<-B) }() c := make([]int, 10, 20) c = append(c, 1, 2, 3) fmt.Println(c) time.Sleep(1 * time.Second) }
命令行调用 go 程序代码,输出gc信息到日志
GODEBUG=gctrace=1 go run test.go 2> log.file 123 [0 0 0 0 0 0 0 0 0 0 1 2 3] 1 gc 1 @0.030s 0%: 0.036+0.47+0.11 ms clock, 0.14+0.16/0.33/0.91+0.44 ms cpu, 4->4->0 MB, 5 MB goal, 4 P gc 2 @0.052s 0%: 0.005+0.43+0.077 ms clock, 0.023+0.19/0.30/0.71+0.31 ms cpu, 4->4->0 MB, 5 MB goal, 4 P gc 3 @0.082s 3%: 1.6+1.2+0.25 ms clock, 6.5+1.5/2.4/0+1.0 ms cpu, 4->4->1 MB, 5 MB goal, 4 P gc 4 @0.089s 4%: 0.10+0.79+0.087 ms clock, 0.41+0.27/0.73/0.60+0.35 ms cpu, 4->4->1 MB, 5 MB goal, 4 P gc 5 @0.096s 4%: 0.005+0.50+0.035 ms clock, 0.023+0.055/0.38/0.94+0.14 ms cpu, 4->4->0 MB, 5 MB goal, 4 P gc 6 @0.102s 4%: 0.005+0.51+0.049 ms clock, 0.022+0.10/0.40/0.93+0.19 ms cpu, 4->4->1 MB, 5 MB goal, 4 P # command-line-arguments gc 1 @0.005s 9%: 0.008+3.3+0.071 ms clock, 0.035+0.18/3.0/2.4+0.28 ms cpu, 4->5->3 MB, 5 MB goal, 4 P # command-line-arguments gc 1 @0.001s 18%: 0.006+3.7+0.087 ms clock, 0.026+0.16/3.5/0.30+0.35 ms cpu, 4->5->4 MB, 5 MB goal, 4 P gc 2 @0.012s 11%: 0.006+3.5+0.034 ms clock, 0.026+0.10/3.3/0.94+0.13 ms cpu, 8->9->8 MB, 9 MB goal, 4 P gc 3 @0.020s 13%: 0.006+6.1+0.056 ms clock, 0.024+0.16/6.0/3.4+0.22 ms cpu, 14->14->14 MB, 16 MB goal, 4 P gc 4 @0.060s 8%: 0.009+11+0.041 ms clock, 0.038+0.19/11/6.6+0.16 ms cpu, 26->26->24 MB, 28 MB goal, 4 P
以上所述就是小编给大家介绍的《Golang垃圾回收gc调优》,希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对 码农网 的支持!
猜你喜欢:- Go 语言的垃圾回收演化历程:垃圾回收和运行时问题
- 垃圾回收2:垃圾收集算法
- 垃圾收集3: 垃圾回收器
- 垃圾回收算法(7)-分代回收算法
- JAVA 垃圾回收机制(二) --- GC回收具体实现
- 对象回收判定与垃圾回收算法-JVM学习笔记(1)
本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们。