📊 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
- Start profiling
go run main.go -pprof
- Access the web UI
Visithttp://localhost:6060/debug/pprof/
in your browser 🌐 - 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