LinuxCommandLibrary

pprof

Profile program execution for performance analysis

TLDR

Generate a text report from a specific profiling file, on fibbo binary

$ pprof -top [./fibbo] [./fibbo-profile.pb.gz]
copy

Generate a graph and open it on a web browser
$ pprof -svg [./fibbo] [./fibbo-profile.pb.gz]
copy

Run pprof in interactive mode to be able to manually launch pprof on a file
$ pprof [./fibbo] [./fibbo-profile.pb.gz]
copy

Run a web server that serves a web interface on top of pprof
$ pprof -http=[localhost:8080] [./fibbo] [./fibbo-profile.pb.gz]
copy

Fetch a profile from an HTTP server and generate a report
$ pprof [http://localhost:8080/debug/pprof]
copy

SYNOPSIS

pprof [options] [executable] profile_data_source
Where profile_data_source can be a file path to profiling data or a URL to a live profiling endpoint (e.g., from a Go debug/pprof server). The executable is often optional but recommended for better symbol resolution, especially with Go binaries.

PARAMETERS

-web
    Launches an interactive web interface in your browser to explore the profile data. This is often the most comprehensive and user-friendly way to analyze profiles.

-text
    Displays the profile data as a plain text report, typically showing call stacks and their associated costs.

-list regexp
    Lists source code for functions matching the provided regular expression, with line-by-line annotations of profiling data.

-top [N]
    Shows the top N (default 10) entries (functions, files, etc.) that consume the most resources based on the profile type.

-call_tree
    Generates a graphical call tree visualization, showing function calls and their hierarchical relationships.

-flame
    Generates an SVG flame graph, a powerful visualization for hierarchical data that quickly highlights hot paths.

-output path
    Specifies the file path where the generated output (e.g., graph, flame graph, text report) should be saved.

-seconds duration
    When profiling from a URL, specifies the duration (in seconds) for which to collect profiling samples.

-sample_index type
    Selects the specific type of samples to analyze within a profile. Common types include cpu, alloc_space (total bytes allocated), inuse_space (bytes currently in use), goroutine, mutex, and block.

-base profile_path
    Subtracts the profile data from a specified base profile, useful for comparing two profiles (e.g., before and after an optimization).

-focus regexp
    Filters the profile to focus only on data paths (functions, files) that match the given regular expression.

-ignore regexp
    Filters the profile to ignore data paths (functions, files) that match the given regular expression.

DESCRIPTION

pprof is a command-line tool for visualizing and analyzing profiling data. It reads various profiling formats, including those generated by Go programs (CPU, heap, goroutine, mutex, block profiles), and can also process profiles from other sources like perf, gperftools, and Java applications (when converted to the pprof format).

pprof can generate a wide range of reports and visualizations, such as text-based call stacks, flame graphs, call graphs, and highly interactive web UIs. It's an indispensable tool for performance tuning, helping developers identify bottlenecks, memory leaks, and concurrency issues in their applications. By providing deep insights into where CPU time is spent, memory allocations occur, or contention arises, pprof enables targeted optimizations across diverse programming environments. Its versatility and powerful visualization capabilities make it a staple in performance analysis workflows.

CAVEATS

pprof primarily processes profiles in the Go-specific pprof format (gzipped protocol buffers). While it can ingest other formats (like perf data) via conversion tools (e.g., perf_to_pprof), direct support is limited. For proper symbol resolution, especially with Go binaries, providing the original executable is crucial. Analyzing very large profiles can be resource-intensive, requiring significant memory and CPU. The -web option requires a web browser configured to open URLs.

SUPPORTED PROFILE TYPES

pprof can interpret various types of profiling data, including CPU usage, heap allocations (both total allocated and currently in-use memory), goroutine stacks, mutex contention, blocking operations, and trace data. The type of analysis depends on the nature of the collected profile.

OUTPUT FORMATS

Beyond the interactive web UI and text reports, pprof can generate static graphical outputs in formats like SVG, PNG, JPEG, GIF, and PDF. It can also produce raw profile data in protocol buffer format or convert to dot format for further processing with graph visualization tools.

HISTORY

pprof originated at Google as an internal profiling tool for C++ applications and was later open-sourced as a core component of the Go programming language toolchain. Its development focused on providing robust and flexible profile visualization capabilities. Over time, it has evolved to support a broader range of profiling data sources beyond just Go applications, establishing itself as a widely adopted tool for performance analysis across various languages and environments.

SEE ALSO

perf(1), valgrind(1), strace(1)

Copied to clipboard