Skip to content

pprofでアプリのパフォーマンスデータを可視化

cf. https://pkg.go.dev/net/http/pprof

事前準備

  • main.goに下記を追加します:
import _ "net/http/pprof"
func main() {

    go func() {
        http.ListenAndServe("localhost:6060", nil)
    }()

    // 通常のアプリ起動処理
}
  • 必要なパッケージをインストールします:
sudo apt update
sudo apt install -y graphviz

利用方法

例として、CPU利用率を確認したい場合:

# ブラウザが自動で起動し、8081ポートでプロファイル情報が公開されます。
go tool pprof -http=:8081 http://localhost:6060/debug/pprof/profile