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

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

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

友情链接更多精彩内容