美文网首页
go排查问题的方法和手段总结

go排查问题的方法和手段总结

作者: 潘雪雯 | 来源:发表于2023-02-08 00:02 被阅读0次

dlv

dlv类似c语言中的gdb,但是会比gdb更好用一些
如果调试core文件 ./dlv core ./bin(二进制产出) core.1234
args: 当前变量
p:就是print

race

如果go程序出现core,且出现类似错误: panic: runtime error: invalid memory address or nil pointer dereference
可以使用race查看gorountine之间是否存在数据竞争关系
如果是大型项目: 可以在编译二进制的时候加上race:go build -race bin(二进制产出)
然后在执行bin文件的时候,会发现

image.png

pprof的使用

go tool pprof ./bin http://localhost:port/debug/pprof/heap

image.png
image.png

failed to execute dot. Is Graphviz installed? Error: exec: "dot": executable file not found in $PATH
sudo yum install graphviz

exec: "sensible-browser": executable file not found in $PATH
sudo yum install -y sensible-utils

参考

https://go.dev/blog/race-detector

相关文章

网友评论

      本文标题:go排查问题的方法和手段总结

      本文链接:https://www.haomeiwen.com/subject/erafkdtx.html