# pprof — Visualization and Analysis Tool for Profiling Data > An open-source tool by Google for visualizing and analyzing profiling data from Go, C++, Java, and other runtimes, generating interactive flame graphs, call graphs, and source annotations. ## Install Save in your project root: # pprof — Visualization and Analysis Tool for Profiling Data ## Quick Use ```bash # Install pprof go install github.com/google/pprof@latest # Analyze a Go CPU profile and open interactive web UI go tool pprof -http=:8080 cpu.prof # Generate a flame graph SVG from a profile file pprof -svg cpu.prof > flamegraph.svg ``` ## Introduction pprof is an open-source profiling visualization tool developed by Google. It reads profiling data in the protocol buffer-based pprof format and renders it as interactive flame graphs, directed call graphs, top function tables, and source-level annotations. Originally built for Go's runtime profiler, pprof now supports any profiler that emits the pprof protobuf format, including C++ (gperftools), Java (async-profiler), and Node.js. ## What pprof Does - Reads CPU, memory, goroutine, mutex, and block profiles in the pprof protobuf format - Renders interactive flame graphs and call graphs in a local web UI - Generates SVG, PDF, and text reports for sharing and documentation - Annotates source code and disassembly with per-line profiling data - Compares two profiles to show regressions or improvements between versions ## Architecture Overview pprof parses a profile protobuf file that contains samples, each sample associating a set of call stack frames with numeric values (CPU time, allocation bytes, etc.). It builds a weighted call graph from these samples and applies user-specified filters (focus, ignore, hide) to narrow the view. The web UI mode starts a local HTTP server that serves an interactive flame graph, a graph visualization (rendered via Graphviz), top tables, and per-line source annotations. The same engine can export static SVG, PDF, or plain text via command-line flags. ## Self-Hosting & Configuration - Install with Go: `go install github.com/google/pprof@latest` - Go programs expose profiles at `/debug/pprof/` when importing `net/http/pprof` - Open interactive web UI: `pprof -http=:8080 profile.pb.gz` - Fetch a live profile from a Go server: `pprof http://server:port/debug/pprof/profile` - Compare two profiles: `pprof -diff_base=old.prof new.prof` ## Key Features - Interactive web UI with flame graph, graph view, top table, and source annotation - Profile diffing to visualize performance changes between two versions - Supports remote profile fetching from running Go servers over HTTP - Filtering by function name regex to focus on specific code paths - Works with any profiler that outputs the pprof protobuf format ## Comparison with Similar Tools - **go tool trace** — shows goroutine scheduling and system events as a timeline; pprof aggregates CPU and memory samples into call graphs - **Speedscope** — web-based flame graph viewer; pprof adds call graph rendering, source annotation, and profile diffing - **FlameGraph (Brendan Gregg)** — generates SVG flame graphs from folded stacks; pprof provides an interactive web UI and multiple visualization modes - **py-spy** — sampling profiler for Python; pprof is a visualization tool that reads profiles from any runtime that emits pprof format - **Pyroscope / Grafana Pyroscope** — continuous profiling platform with storage and querying; pprof is a standalone CLI tool for ad-hoc analysis ## FAQ **Q: Is pprof only for Go programs?** A: No. Any profiler that outputs the pprof protobuf format works. This includes gperftools (C++), async-profiler (Java), and perf (Linux) with conversion tools. **Q: Do I need Graphviz installed?** A: Graphviz is needed for the directed call graph view. Flame graphs and top tables work without it. Install Graphviz with your package manager if you want graph output. **Q: Can I profile a production Go service?** A: Yes. Import `net/http/pprof` in your server, then fetch profiles remotely with `pprof http://host:port/debug/pprof/profile?seconds=30`. **Q: How do I compare performance between two releases?** A: Use `pprof -diff_base=baseline.prof current.prof` to see a call graph highlighting the delta. ## Sources - https://github.com/google/pprof - https://pkg.go.dev/net/http/pprof --- Source: https://tokrepo.com/en/workflows/asset-0908f023 Author: AI Open Source