← 返回命令列表

Linux command

pprof 命令

网络

复制后可按需替换文件名、目录或参数。

常用示例

Start web interface

pprof -http=[localhost:8080] [profile.pb.gz]

Show top functions

pprof -top [profile.pb.gz]

Show call graph as text

pprof -text [profile.pb.gz]

Show call graph as PDF

pprof -pdf [profile.pb.gz] > [profile.pdf]

Profile from running server

pprof -http=[localhost:8080] [http://localhost:6060/debug/pprof/profile]

Compare two profiles

pprof -base [baseline.pb.gz] [current.pb.gz]

Focus on specific function

pprof -focus=[FunctionName] [profile.pb.gz]

说明

pprof analyzes and visualizes performance profiles from Go programs and other sources. It shows where programs spend time and memory. The web interface provides interactive exploration. Flame graphs show call hierarchies. Graph views display caller/callee relationships. Profiles capture CPU usage, memory allocations, goroutine counts, and custom metrics. Go's runtime/pprof package generates these profiles. Live profiling connects to running servers through HTTP endpoints. The standard /debug/pprof/ path provides various profile types. Comparison mode highlights changes between profiles. This identifies performance regressions or improvements after code changes. Focus and ignore filters narrow analysis to specific areas. Regular expressions match function names for targeted investigation.

参数

-http _ADDR_
Start web server.
-top
Show top functions.
-text
Text report.
-pdf
PDF output.
-svg
SVG output.
-png
PNG output.
-web
Open in browser.
-focus _REGEX_
Focus on matching functions.
-ignore _REGEX_
Ignore matching functions.
-base _PROFILE_
Compare against baseline.
-seconds _N_
Profile duration.
-sample_index _IDX_
Sample type (cpu, alloc, etc.).
-lines
Show line-level info.

FAQ

What is the pprof command used for?

pprof analyzes and visualizes performance profiles from Go programs and other sources. It shows where programs spend time and memory. The web interface provides interactive exploration. Flame graphs show call hierarchies. Graph views display caller/callee relationships. Profiles capture CPU usage, memory allocations, goroutine counts, and custom metrics. Go's runtime/pprof package generates these profiles. Live profiling connects to running servers through HTTP endpoints. The standard /debug/pprof/ path provides various profile types. Comparison mode highlights changes between profiles. This identifies performance regressions or improvements after code changes. Focus and ignore filters narrow analysis to specific areas. Regular expressions match function names for targeted investigation.

How do I run a basic pprof example?

Run `pprof -http=[localhost:8080] [profile.pb.gz]` in a terminal, then adjust file names, paths, flags, or remote targets for your system.

What does -http _ADDR_ do in pprof?

Start web server.