go常用命令
go help
GODEBUG环境变量
GODEBUG=gctrace=1 go run cmd/agent_bin.go
- 设置 `schedtrace=X` 参数可以使运行时在每 X 毫秒发出一行调度器的摘要信息到标准 err 输出中
- `scheddetail=1` 可以使运行时在每 X 毫秒发出一次详细的多行信息,信息内容主要包括调度程序、处理器、OS 线程 和 Goroutine 的状态。
go tool
pprof
display
- 命令行方式
go tool pprof xx.out
- web方式
go tool pprof -http=:8080 heap.out
- 命令行方式
生成文件
代码生成
// cpu pprof.StartCPUProfile(w) defer pprof.StopCPUProfile() // mem pprof.WriteHeapProfile(w)
curl从http获取 localhost:6061/debug/pprof/profile?...
性能测试 go test -bench=. -cpuprofile=./cpu.prifile
分析
- go tool pprof x.prof
- top
- list func
- web
- go-torch x.prof | go-torch -u http=localhost:6061 -t30
- go tool pprof x.prof
trace
- 获取trace文件
- 写代码
trace.Start(w) defer trace.Stop()
- http请求 /debug/pprof/trace
- 写代码
- 分析
- go tool trace /tmp/trace.output
objdump反汇编
- go tool objdump -S -s “main.example” ./example1
test
性能测试
- GOGC=off go test -cpu 1 -run none -bench . -benchtime 3s
- GOGC=off go test -cpu 8 -run none -bench . -benchtime 3s
压力测试
- go-wrk
本作品采用《CC 协议》,转载必须注明作者和本文链接