failed to execute dot. Is Graphviz installed? Error: exec: “dot”: executable file not found in %PATH%。
问题原因
pprof 在生成火焰图或其他可视化图表时,依赖于 Graphviz 的 dot 工具。该错误提示表示系统未安装 Graphviz,或者 dot 命令未添加到系统的环境变量 (%PATH% 或 $PATH) 中。
解决方案
windows
- 访问 Graphviz 官网 下载并安装。
- 安装完成后,将
Graphviz
的安装目录(例如:C:\Program Files\Graphviz\bin
)添加到系统环境变量PATH
中。
步骤:
- 打开“控制面板” → “系统” → “高级系统设置” → “环境变量”。
- 在“系统变量”中找到
PATH
,点击“编辑”。 - 添加 Graphviz 的
bin
路径,确认并保存。
验证是否Ok
go tool pprof C:\Users\admin\pprof\pprof.___go_build_example_etcd_learn.exe.samples.cpu.004.pb.gz
(pprof) svg
Generating report in profile001.svg
简单测试go代码为:
func main() {
defer cli.Close()
go func() {
http.ListenAndServe("0.0.0.0:6060", nil)
}()
var i int
for {
fmt.Printf("执行第%d次操作\n", i)
i++
}
}
代码会一直在不停打印日志。所以我们看到火焰图上面是main.main()方法里面的fmt.printf函数耗时占比最多。
Linux (Debian/Ubuntu):
sudo apt-get update
sudo apt-get install graphviz
Linux (CentOS/RHEL):
sudo yum install graphviz
MacOS:
使用 Homebrew 安装:
brew install graphviz