NOTE
4.5 trace
Runtime/trace 可以记录 Go 程序的运行轨迹。笔记从引入包和采集数据开始,整理跟踪与查看结果的步骤。
这是历史学习笔记,可能存在过时或不完整的理解。
1. 使用
步骤如下:
- 导入包:
import runtime/trace - 开启分析:
trace.Start(file)停止分析:trace.Stop()
package main
import (
"fmt"
"os"
"runtime/trace"
)
func main() {
file, err := os.Create("trace.out")
if err != nil {
panic(err)
}
defer file.Close()
err = trace.Start(file)
if err != nil {
panic(err)
}
fmt.Println("Hello World")
trace.Stop()
}
- 命令行分析
go tool trace trace.out
2. 参考
Go execution tracer | Gopher Academy Blog Go 执行追踪器(execution tracer) - Go语言中文网 - Golang中文社区 An Introduction to go tool trace How to analyze the performance of your go application in production | Developer’s life Go code refactoring : the 23x performance hunt | by Val Deleplace | Medium
拖动可平移,滚轮缩放,点击节点可展开或折叠。大型导图默认折叠较深层级,可点击节点继续展开。

讨论
使用 GitHub 账号参与讨论,评论会保存在 GitHub Issues 中。在 GitHub 查看