go tool pprof file 下web命令报错 "failed to execute dot. Is Graphviz installed?"

Golang golang 2377      收藏
go tool pprof file 下web命令报错 "failed to execute dot. Is Graphviz installed?"

failed to execute dot. Is Graphviz installed? Error: exec: "dot": executable file not found in $PATH


生成go test对应的性能日志文件

go test -bench . cpuprofile cpu.out

该文件为二进制文件,不能用less等命令直接查看

可以使用pprof进行查看

go tool pprof cpu.out

指定该命令可以进入到pprof交互窗口

输入web命令可以生成对应的svg性能图片。

在输入web命令之后会提示 failed to execute dot. Is Graphviz installed?

需要安装Graphviz工具,在安装 Graphviz 之前还需要安装 MacPorts 工具

MacPorts 官网: https://www.macports.org/install.php

MacPorts下载地址:https://github.com/macports/macports-base/releases/download/v2.7.1/MacPorts-2.7.1-10.15-Catalina.pkg

下载安装MacPorts工具之后要执行如下命令才可以使用

export PATH=/opt/local/bin:/opt/local/sbin:$PATH

此时可以使用命令安装Graphviz工具,安装命令为:

sudo port install graphviz

安装成功之后,发现输入web依然报错,无法生成svg图片

此时需要配置环境变量

vi ~/.bash_profile
# add the following line
export PATH=/opt/local/bin:/opt/local/sbin:$PATH
source ~/.profile

然后执行如下命令查看运行是否成功

dot -V

如果成功会输出

dot - graphviz version 2.50.0 (20211204.2007)

此时再输入web会发现成功生成了svg文件。