You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
paopao-ce/docs/proposal/23062906-关于开启pgo编译优化.md

39 lines
1.7 KiB

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

| 编号 | 作者 | 发表时间 | 变更时间 | 版本 | 状态 |
| ----- | ----- | ----- | ----- | ----- | ----- |
| 23062906| 北野 | 2023-06-29 | 2023-06-29 | v1.0 | 提议 |
### 概述
Beginning in Go 1.20, the Go compiler supports profile-guided optimization ([PGO](https://go.dev/doc/pgo)) to further optimize builds.
### 疑问
1. 为什么要添加`pprof`功能特性?
使用 net/http/pprof 在线获取CPU profile信息用于 [PGO](https://go.dev/doc/pgo) 编译优化。
2. 如何开启`pgo`编译优化?
The standard approach is to store a pprof CPU profile with filename default.pgo in the main package directory of the profiled binary, and build with go build -pgo=auto, which will pick up default.pgo files automatically.
3. 常见命令
#### Merging profiles
The pprof tool can merge multiple profiles like this:
```sh
$ go tool pprof -proto a.pprof b.pprof > default.pgo
```
This merge is effectively a straightforward sum of samples in the input, regardless of wall duration of the profile. As a result, when profiling a small time slice of an application (e.g., a server that runs indefinitely), you likely want to ensure that all profiles have the same wall duration (i.e., all profiles are collected for 30s). Otherwise, profiles with longer wall duration will be overrepresented in the merged profile.
#### look at a 30-second CPU profile:
```sh
go tool pprof http://localhost:6060/debug/pprof/profile?seconds=30
```
### 参考文档
* [PGO](https://go.dev/doc/pgo)
* [net/http/pprof](https://pkg.go.dev/net/http/pprof)
* [runtime/pprof](https://pkg.go.dev/runtime/pprof)
### 更新记录
#### v1.0(2023-06-20) - 北野
* 初始文档