hhstore / blog

My Tech Blog: about Mojo / Rust / Golang / Python / Kotlin / Flutter / VueJS / Blockchain etc.
https://github.com/hhstore/blog/issues
291 stars 24 forks source link

Golang: Debug Tool #143

Open hhstore opened 5 years ago

hhstore commented 5 years ago

go tool:

brew install graphviz

bench test + pprof + 火焰图:

# 性能测试, 生成测试报告:
# cpu:
go test -bench=. -cpuprofile=cpu.prof

# 内存:
go test -bench=. -memprofile=mem.prof

# IO阻塞:
go test -bench=. -blockprofile=block.prof

# 浏览器查看: 
go tool pprof -http=:8080 cpu.prof
go tool pprof -http=:8080 mem.prof
go tool pprof -http=:8080 block.prof

相关项目:

# Get the pprof tool directly
go get -u -v github.com/google/pprof

pprof -http=":8081" [binary] [profile]
hhstore commented 5 years ago

示例分析:

main code:

# gc 内存分配, 栈, 堆, 逃逸分析:
go run -gcflags -m gc_cost.go

go build -gcflags=-m examples/esc/sum.go

内联优化:

test code:


# cpu:
go test -bench=. -cpuprofile=cpu.prof

# 内存:
go test -bench=. -memprofile=mem.prof

# 浏览器打开火焰图查看:
# cpu 分析:
go tool pprof -http=:8080 cpu.prof

# 内存分析:
go tool pprof -http=:8080 mem.prof
hhstore commented 5 years ago

ref: