Open geektutu opened 3 years ago
总结:
性能分析类型
CPU 性能分析
使用原生 runtime/pprof
包,通过在 main 函数中添加代码运行可生成性能分析报告:
pprof.StartCPUProfile(os.Stdout)
defer pprof.StopCPUProfile()
可通过 go tool pprof -http=:9999 cpu.pprof
在 web 页面查看分析数据
可通过 go tool pprof cpu.prof
交互模式查看分析数据,可使用 help
查看支持的命令和选项
内存性能分析
使用 pkg/profile
库,通过在 main 函数中添加代码运行可生成性能分析报告:
defer profile.Start(profile.MemProfile, profile.MemProfileRate(1)).Stop()
同样可通过 web 页面或交互模式查看分析数据
benchmark 生成 profile
go test
中添加参数 -cpuprofile=$FILE,-memprofile=$FILE,-blockprofile=$FILE
生成相应的 profile 文件博主,想问下该网站是如何开发或者生成的?
http://www.graphviz.org/download/
graphviz Windows下载地址,需配置环境变量,重启后生效
你好, 本文章貌似有一处错误(不知道是不是因为Go版本不同,本人使用1.18)
go test -bench="Fib$" -cpuprofile=cpu.pprof .
应是
go test -bench="Fib$" --cpuprofile=cpu.pprof .
博主,请问 profile 翻译成中文应该叫什么?
@dablelv 博主,请问 profile 翻译成中文应该叫什么?
拆成两个单词 pro+file pro专业的,file文件,专业的文件
@dablelv 博主,请问 profile 翻译成中文应该叫什么?
profile,画像,轮廓;对于人来说,profile类似于用户的档案;对于程序来说,程序的轮廓就是内存、cpu使用情况,线程的数量,堆栈之类的情况。
https://geektutu.com/post/hpg-pprof.html
Go 语言/golang 高性能编程,Go 语言进阶教程,Go 语言高性能编程(high performance go)。详细介绍如何测试/评估 Go 代码的性能,内容包括使用 testing 库进行基准测试(benchmark),性能分析(profiling) 编译优化(compiler optimisations),内存管理(memory management)和垃圾回收(garbage collect)、pprof 等内容。同时也介绍了使用 Go 语言如何写出高性能的程序和应用,包括不限于 Go 语言标准库、第三方库的使用方式和最佳实践。