golang graphviz与pprof
sudo port install graphviz
fuyundeMacBook-Pro:~ fuyun$ sudo port install graphviz Warning: The Xcode Command Line Tools don't appear to be installed; most ports will likely fail to build. Warning: Install them by running `xcode-select --install'. ---> Computing dependencies for graphviz ---> Fetching archive for graphviz ---> Attempting to fetch graphviz-2.38.0_0+pangocairo+x11.darwin_14.x86_64.tbz2 from http://mse.uk.packages.macports.org/sites/packages.macports.org/graphviz ---> Attempting to fetch graphviz-2.38.0_0+pangocairo+x11.darwin_14.x86_64.tbz2 from http://packages.macports.org/graphviz ---> Attempting to fetch graphviz-2.38.0_0+pangocairo+x11.darwin_14.x86_64.tbz2 from http://lil.fr.packages.macports.org/graphviz ---> Fetching distfiles for graphviz ---> Verifying checksums for graphviz ---> Extracting graphviz ---> Configuring graphviz ---> Building graphviz ---> Staging graphviz into destroot ---> Installing graphviz @2.38.0_0+pangocairo+x11 ---> Activating graphviz @2.38.0_0+pangocairo+x11 ---> Cleaning graphviz ---> Updating database of binaries ---> Scanning binaries for linking errors ---> No broken files found.
xcode-select --install
清除之前未安装成功的graphviz sudo port uninstall graphviz
重新安装graphviz fuyundeMacBook-Pro:~ fuyun$ sudo port install graphviz ---> Computing dependencies for graphviz ---> Fetching archive for graphviz ---> Attempting to fetch graphviz-2.38.0_0+pangocairo+x11.darwin_14.x86_64.tbz2 from http://mse.uk.packages.macports.org/sites/packages.macports.org/graphviz ---> Attempting to fetch graphviz-2.38.0_0+pangocairo+x11.darwin_14.x86_64.tbz2 from http://packages.macports.org/graphviz ---> Attempting to fetch graphviz-2.38.0_0+pangocairo+x11.darwin_14.x86_64.tbz2 from http://lil.fr.packages.macports.org/graphviz ---> Fetching distfiles for graphviz ---> Verifying checksums for graphviz ---> Extracting graphviz ---> Configuring graphviz ---> Building graphviz ---> Staging graphviz into destroot ---> Installing graphviz @2.38.0_0+pangocairo+x11 ---> Activating graphviz @2.38.0_0+pangocairo+x11 ---> Cleaning graphviz ---> Updating database of binaries ---> Scanning binaries for linking errors ---> No broken files found. 运行 go tool pprof 30秒等待工具
fuyundeMacBook-Pro:~ fuyun$ go tool pprof http://localhost:8080/debug/pprof/profile Fetching profile from http://localhost:8080/debug/pprof/profile Please wait... (30s) Saved profile in /Users/fuyun/pprof/pprof.localhost:8080.samples.cpu.002.pb.gz Entering interactive mode (type "help" for commands)
在这30秒中新的终端进行测试并发 ab -n 10000 -c 200 http://localhost:8080/storemanager/goods?telphone=18200566251
This is ApacheBench,Version 2.3 <$Revision: 1554214 $> Copyright 1996 Adam Twiss,Zeus Technology Ltd,http://www.zeustech.net/ Licensed to The Apache Software Foundation,http://www.apache.org/
Benchmarking localhost (be patient) Completed 1000 requests Completed 2000 requests Completed 3000 requests Completed 4000 requests Completed 5000 requests Completed 6000 requests Completed 7000 requests Completed 8000 requests Completed 9000 requests Completed 10000 requests Finished 10000 requests Server Software: Server Hostname: localhost Server Port: 8080
Document Path: /storemanager/goods?telphone=18200566251 Document Length: 0 bytes
Concurrency Level: 200 Time taken for tests: 9.711 seconds Complete requests: 10000 Failed requests: 9793 (Connect: 0,Receive: 0,Length: 9793,Exceptions: 0) Total transferred: 21197939 bytes HTML transferred: 19960000 bytes Requests per second: 1029.74 [#/sec] (mean) Time per request: 194.223 [ms] (mean) Time per request: 0.971 [ms] (mean,across all concurrent requests) Transfer rate: 2131.68 [Kbytes/sec] received
Connection Times (ms) min mean[+/-sd] median max Connect: 0 0 0.8 0 9 Processing: 90 192 24.7 191 264 Waiting: 2 192 24.7 191 264 Total: 99 192 24.6 191 268
Percentage of the requests served within a certain time (ms) 50% 191 66% 203 75% 210 80% 214 90% 226 95% 233 98% 246 99% 255 100% 268 (longest request) 当获取样本后在pprof命令提示符下可以建入web命令,如果默认没有浏览器打开,选择SVG文件COMMAND+I 选择打开方式挑一个浏览器,单击全部更改。 (pprof) web (pprof) 注意该方式在WEB中,如果你使用的标准servermux则只需要包含import _ "net/http/pprof" 就行,如果自定义的路由需要使用pprof相应的函数去输出并且附加debug的参数,这样浏览器显示的就不是字节方式了。
debug参数用于开启附加的输出。如果debug=0,只会打印pprof所需要的十六进制地址;如果debug=1,会将地址翻译为函数名和行号并添加注释,以便让程序员无需工具阅读分析报告。 预定义Profile为其它debug值赋予了含义。例如,当打印“Go程”的分析报告时,debug=2意为:由于不可恢复的恐慌而濒临崩溃时,使用与Go程序相同的格式打印Go程的堆栈信息。 Then use the pprof tool to look at the heap profile: go tool pprof http://localhost:8080/debug/pprof/heap
Or to look at a 30-second CPU profile: http://localhost:8080/debug/pprof/profile Or to look at the goroutine blocking profile: http://localhost:8080/debug/pprof/block 具体可参考:http://blog.golang.org/profiling-go-programs
https://github.com/hyper-carrot/go_command_tutorial/blob/master/0.12.md
以下为转载为 http://www.cnblogs.com/yjf512/archive/2012/12/27/2835331.html
(编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |