📊 A powerful profiling tool built into the Go runtime for performance analysis

Overview

The pprof package provides detailed insights into Go programs' performance, including:

  • CPU usage
  • Memory allocation
  • Goroutine activity
  • Blocking operations

🔧 Tip: To access pprof data, start your Go program with the -pprof flag or use the /debug/pprof endpoint.

Basic Usage

  1. Start profiling
    go run main.go -pprof
    
  2. Access the web UI
    Visit http://localhost:6060/debug/pprof/ in your browser 🌐
  3. Analyze results
    Use commands like:
    • top (CPU usage)
    • heap (memory allocation)
    • goroutine (active goroutines)

Example: CPU Profiling

To capture CPU profiles:

import _ "net/http/pprof"
// Your code here  

Then navigate to:
http://localhost:6060/debug/pprof/profile?seconds=30
⏱️ This will collect CPU data for 30 seconds

Related Resources

📖 Go pprof Documentation
⚙️ Performance Optimization Guide

Go_pprof