🔥码云GVP开源项目 12k star Uniapp+ElementUI 功能强大 支持多语言、二开方便! 广告
mac下的Graphviz安装及使用 一.安装 Graphviz http://www.graphviz.org/ mac用户建议直接用homebrew来安装,官网上版本比较旧 1.安装homebrew 打开终端复制、粘贴以下命令: ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)" 2.安装Graphviz homebrew安装完毕后运行 brew install graphviz 即可 注:运行第2步时可能会提示-bash: brew: command not found 解决办法: 终端输入sudo vim .bash_profile, 输入i进入输入模式, 添加export PATH="/usr/local/bin:$PATH" , 按esc键退出输入模式, 输入:wq退出并保存 最后输入source .bash_profile使配置生效。 (注意: 和空格也要输入,bash_profile保存时可能会警告,:w!强制保存即可,更多vim命令参考http://www.cnblogs.com/usergaojie/p/4583796.html **关于pprof** pprof是golang程序一个性能分析的工具,可以查看堆栈、cpu信息等。 **源码示例** ~~~ package main import ( "flag" "log" "net/http" _ "net/http/pprof" "sync" "time" ) func Counter(wg *sync.WaitGroup) { time.Sleep(time.Second) var counter int for i := 0; i < 1000000; i++ { time.Sleep(time.Millisecond * 200) counter++ } wg.Done() } func main() { flag.Parse() //远程获取pprof数据 go func() { log.Println(http.ListenAndServe("localhost:8080", nil)) }() var wg sync.WaitGroup wg.Add(10) for i := 0; i < 10; i++ { go Counter(&wg) } wg.Wait() // sleep 10mins, 在程序退出之前可以查看性能参数. time.Sleep(60 * time.Second) } ~~~ 编译运行: ~~~ go run main.go ~~~ 通过网页查看overview http://localhost:8080/debug/pprof/ 通过终端命令查看各参数: 1)查看堆栈信息 ~~~ go tool pprof http://localhost:8080/debug/pprof/heap top10 #命令查看了堆栈空间最大的10个函数调用 ~~~ 2)查看cpu性能信息 ~~~ go tool pprof http://localhost:8080/debug/pprof/profile top10 #命令查看了堆栈空间最大的10个函数调用 ~~~