本文介绍如何打印调用堆栈进行go代码的调试。
打印堆栈使用的runtime package中的Stack()函数
func Stack(buf []byte, all bool) int Stack formats a stack trace of the calling goroutine into buf and returns the number of bytes written to buf. If all is true, Stack formats stack traces of all other goroutines into buf after the trace for the current goroutine.
example
package main import ( "runtime" "time" "fmt" ) func main() { go power1() for { time.Sleep(time.Duration(1)*time.Minute) } } func power1(){ var buf [1024]byte fmt.Println("power1.....") n := runtime.Stack(buf[:], true) fmt.Println(string(buf[:]), n) }
输出结果:
power1..... goroutine 5 [running]: main.power1() /home/lanyang/src/t.go:29 +0xec created by main.main /home/lanyang/src/t.go:14 +0x3c
goroutine 1 [sleep]: time.Sleep(0xdf8475800) /home/lanyang/src/t.go:59 +0x107 main.main() /home/lanyang/src/t.go:17 +0x4f 303
以上这篇go 代码的调试---打印调用堆栈的实例就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持。
标签:
调用堆栈
免责声明:本站文章均来自网站采集或用户投稿,网站不提供任何软件下载或自行开发的软件!
如有用户或公司发现本站内容信息存在侵权行为,请邮件告知! 858582#qq.com
白云城资源网 Copyright www.dyhadc.com
暂无“go 代码的调试---打印调用堆栈的实例”评论...
更新日志
2024年05月24日
2024年05月24日
- 蔡国权《极品天碟》UPM24K金碟[WAV+CUE][430MB]
- 李健《溺爱 HQCD 规格高质感》[WAV+CUE][480MB]
- 降央卓玛-经典珍藏版《金色的辉煌》[WAV/分轨][550MB]
- 林保怡.1989-NATURAL【BMG】【WAV+CUE】
- 谢宜君.2014-坚强的女人【豪记】【WAV+CUE】
- 江美丽.1992-红颜心事【金圆唱片】【FLAC+CUE】
- 群星《情歌最毒4CD》24KHD黄金母盘[WAV分轨]
- HI-FI白金唱片-群星《白金唱片·靓声经典》[WAV分轨]
- 赵鹏《闪亮的日子·人声低音炮》头版限量编号24K金碟[低速原抓WAV+CUE]
- 王威翔.2008-威风凛凛6CD【音乐谷】【WAV+CUE】
- 辛晓琪.1999-怎么【滚石】【WAV+CUE】
- 陈升.2000-思念人之屋2CD【滚石】【WAV+CUE】
- 叶倩文《动情的倾诉式唱腔 面对面》[WAV+CUE][540MB]
- 李宗盛《希望》[WAV+CUE][130MB]
- 《QQ音乐.热歌榜 TOP300首 2024.03.01期》[FLAC/分轨][9.5GB]