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

1.7 KiB

编号 作者 发表时间 变更时间 版本 状态
23062906 北野 2023-06-29 2023-06-29 v1.0 提议

概述

Beginning in Go 1.20, the Go compiler supports profile-guided optimization (PGO) to further optimize builds.

疑问

  1. 为什么要添加pprof功能特性?
    使用 net/http/pprof 在线获取CPU profile信息用于 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:

$ 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:

go tool pprof http://localhost:6060/debug/pprof/profile?seconds=30

参考文档

更新记录

v1.0(2023-06-20) - 北野

  • 初始文档