pprof
Profile program execution for performance analysis
TLDR
Generate a text report from a specific profiling file, on fibbo binary
Generate a graph and open it on a web browser
Run pprof in interactive mode to be able to manually launch pprof on a file
Run a web server that serves a web interface on top of pprof
Fetch a profile from an HTTP server and generate a report
SYNOPSIS
pprof [options] [binary] [profile_source]
PARAMETERS
-alloc_space
Display only in-use allocations.
-call_graph
Call graph options (e.g., -call_graph flat). Supported values are flat, tree.
-diff_base
Compare against base profile.
-edgefraction
Hide edges below edgefraction (default 0.001).
-focus
Restrict to nodes matching focus (regexp).
-ignore
Ignore nodes matching ignore (regexp).
-nodecount
Maximum number of nodes to show (default 80).
-output
Output filename (default pprof.pdf or pprof.svg).
-peek
Restrict to paths matching focus & ignore (regexp).
-png
Output in PNG format. (web mode only)
-proto
Output in protobuf format.
-svg
Output in SVG format. (web mode only)
-top
Display top N entries.
-web
Display interactive web UI.
-http
Start HTTP server on specified address.
-symbolize
Symbolize addresses using source code.
binary
The binary being profiled. If not provided, `pprof` tries to infer it.
profile_source
The source of the profile data. Can be a file, a URL, or empty (use binary).
DESCRIPTION
The `pprof` command is a powerful tool for profiling Go programs. It allows developers to collect data about CPU usage, memory allocation, goroutine blocking, and other performance metrics. `pprof` then provides interactive visualizations, including flame graphs and call graphs, to help identify performance bottlenecks. It works by analyzing profile data generated by the Go runtime's profiling mechanisms. This data can be acquired in several formats, allowing offline analysis. The most common use case involves analyzing CPU profiles to pinpoint functions consuming the most processing time. However, `pprof` is equally useful for memory profiling to detect memory leaks or inefficient allocation patterns. By understanding where resources are being spent, developers can optimize their Go code for better performance and scalability. It supports various input formats (profile, heap, allocs, etc.) and outputs including text, web UI, and PDF.
CAVEATS
Note: The effectiveness of `pprof` relies on accurate symbol information. Ensure binaries are built with debugging information to get meaningful results. Also, profiling adds overhead and affects application performance, especially during CPU and memory profiling.
PROFILE TYPES
pprof can collect various profile types:
CPU Profile: Samples CPU usage.
Memory Profile (Heap): Samples memory allocation.
Block Profile: Records blocking operations.
Mutex Profile: Records mutex contention.
WEB INTERFACE
The pprof web interface is a powerful tool for visualizing profiling data. It provides interactive flame graphs, call graphs, and other visualizations that can help you identify performance bottlenecks in your code.
HISTORY
`pprof` was initially developed as a part of the Go toolchain to provide profiling capabilities for Go programs. It has evolved over time to support various profiling data formats and visualization techniques. The web UI was added to offer a more interactive and user-friendly experience, making it easier to navigate and understand profiling data. Its development has been driven by the need to identify and address performance bottlenecks in Go applications.
SEE ALSO
go(1)