Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Golang: Debug Tool #143

Open
hhstore opened this issue Apr 19, 2019 · 3 comments
Open

Golang: Debug Tool #143

hhstore opened this issue Apr 19, 2019 · 3 comments

Comments

@hhstore
Copy link
Owner

hhstore commented Apr 19, 2019

No description provided.

@hhstore
Copy link
Owner Author

hhstore commented Apr 19, 2019

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
Copy link
Owner Author

hhstore commented Jun 13, 2019

示例分析:

main code:

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


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


内联优化:

  • 在 Go 中,函数调用有固定的开销;栈和抢占检查。
  • 硬件分支预测器改善了其中的一些功能,但就功能大小和时钟周期而言,这仍然是一个成本。
  • 内联是避免这些成本的经典优化方法。
  • 内联只对叶子函数有效,叶子函数是不调用其他函数的.
  • 使用 -gcflags = -m 标识来查看编译器优化决策
  • https://segmentfault.com/a/1190000016354799

test code:

  • bench test + pprof 火焰图分析

# 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



Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant