背景
最近在分析golang的一个内存泄漏问题。一般来讲,使用golang自带的pprof工具就可以分析内存的使用,协程情况,是否有block等情况。但是我们项目中调用了C库,导致C库的一些东西没法通过pprof来进行监控分析。实际上通过pprof来监控程序的话,内存是稳定的,但是占用Linux的内存是一直增长的,即RES一直增长,实际上程序是有泄漏的。怀疑是使用C库导致,所以通过coredump文件来进行分析。下面主要介绍golang coredump的使用。
分析
主要参考golang官网Debugging Go Code with GDB。
其中:
The GOTRACEBACK variable controls the amount of output generated when a Go program fails due to an unrecovered panic or an unexpected runtime condition. By default, a failure prints a stack trace for the current goroutine, eliding functions internal to the run-time system, and then exits with exit code 2. The failure prints stack traces for all goroutines if there is no current goroutine or the failure is internal to the run-time. GOTRACEBACK=none omits the goroutine stack traces entirely. GOTRACEBACK=singl

本文介绍了如何在Go语言程序中分析coredump,特别是在遇到内存泄漏问题且涉及C库时。通过设置GOTRACEBACK变量,配合gdb调试工具,可以详细查看程序调用栈,有效地定位和解决程序崩溃、内存泄漏等问题。虽然pprof工具在某些情况下无法监控C库,但coredump结合gdb成为一种有效的排查手段。
最低0.47元/天 解锁文章
341

被折叠的 条评论
为什么被折叠?



