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/23062905-添加Pprof功能特性用于获取Pro...

2.3 KiB

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

概述

使用net/http/pprof获取Profile信息。添加Pprof功能特性用于开启PprofServer服务。

需求

  • 只在开发环境下获取profile信息
  • 可以在配置文件中开启获取profile的服务

方案

  • 添加Pprof功能特性
  • 添加PprofServer服务

设计细节

  • 配置文件中添加PprofServer项用于配制http server
  • 添加Pprof功能特性
  • 添加PprofServer服务
  • 使用//go:build pprof按需编译profile功能
  • PprofServer 不能和其他服务共用一个端口

疑问

  1. 为什么要添加pprof功能特性?
    使用 net/http/pprof 在线获取CPU profile信息用于 PGO 编译优化。

  2. 如何开启Pprof服务?

  • 构建时将 pprof 添加到TAGS中:
    make run TAGS='pprof'   
    
  • 在配置文件config.yaml中的Features中添加Pprof功能项开启该功能:
    ...
    # features中加上 Friendship
    Features:
      Default: ["Meili", "LoggerMeili", "Base", "Sqlite3", "BigCacheIndex", "MinIO", "Pprof"]
      Base: ["Redis", "PhoneBind"]
    ...
    
  1. 常见命令

Merging profiles

The pprof tool can merge multiple profiles like this:

$ go tool pprof -proto a.pprof b.pprof > merged.pprof

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) - 北野

  • 初始文档