修改部分描述,添加必要的标点符号,补充代码超链接 (#804)

This commit is contained in:
Jck
2021-10-25 23:34:42 +08:00
committed by GitHub
parent d5578df00a
commit 39dbdb7094
100 changed files with 433 additions and 414 deletions

View File

@@ -39,13 +39,13 @@ func main() {
...
```
代码定义了一个名为 cpuprofile 的 flag调用 Go flag 库来解析命令行 flag如果命令行设置了 cpuprofile flag则开始 CPU 性能分析并把结果重定向到那个文件os.Create 用拿到的名字创建了用来写入分析数据的文件)。这个分析程序最后需要在程序退出之前调用 StopCPUProfile 来刷新挂起的写操作到文件中;我们用 defer 来保证这一切会在 main 返回时触发。
代码定义了一个名为 cpuprofile 的 flag调用 Go flag 库来解析命令行 flag如果命令行设置了 cpuprofile flag则开始 CPU 性能分析并把结果重定向到那个文件os.Create 用拿到的名字创建了用来写入分析数据的文件)。这个分析程序最后需要在程序退出之前调用 StopCPUProfile 来刷新挂起的写操作到文件中;我们用 defer 来保证这一切会在 main 返回时触发。
现在用这个 flag 运行程序:```progexec -cpuprofile=progexec.prof```
然后可以像这样用 gopprof 工具:```gopprof progexec progexec.prof```
gopprof 程序是 Google pprofC++ 分析器的一个轻微变种;关于此工具更多的信息,参见[https://github.com/gperftools/gperftools](https://github.com/gperftools/gperftools)。
gopprof 程序是 Google pprofC++ 分析器的一个轻微变种;关于此工具更多的信息,参见[https://github.com/gperftools/gperftools](https://github.com/gperftools/gperftools)
如果开启了 CPU 性能分析Go 程序会以大约每秒 100 次的频率阻塞,并记录当前执行的 goroutine 栈上的程序计数器样本。