This guide explains how to profile the Mim application to identify performance bottlenecks.
- Run the application with CPU profiling enabled:
./mim -cpuprofile=cpu.prof-
Let the application run for at least 30 seconds to collect meaningful data, then quit (press 'q')
-
Analyze the profile:
# Text-based analysis
go tool pprof cpu.prof
# Web-based visualization (opens in browser)
go tool pprof -http=:8080 cpu.prof- Run the application with web pprof enabled:
./mim -webpprof- While the application is running, access profiles at:
- CPU Profile: http://localhost:6060/debug/pprof/profile?seconds=30
- Heap Profile: http://localhost:6060/debug/pprof/heap
- Goroutine Profile: http://localhost:6060/debug/pprof/goroutine
- All profiles: http://localhost:6060/debug/pprof/
- Download and analyze a 30-second CPU profile:
# Download profile
go tool pprof http://localhost:6060/debug/pprof/profile?seconds=30
# Or analyze directly
go tool pprof -http=:8080 http://localhost:6060/debug/pprof/profile?seconds=30Once in the pprof interactive mode:
top- Show top functions by CPU timetop -cum- Show top functions by cumulative CPU timelist <function>- Show source code for a functionweb- Generate a graph (requires graphviz)pdf- Generate a PDF report
- High Self Time: Functions that consume CPU directly
- High Cumulative Time: Functions whose callees consume CPU
- Frequent Allocations: Check the heap profile for memory pressure
- Lock Contention: Check the mutex profile if enabled
# Generate a CPU profile
./mim -cpuprofile=cpu.prof
# In another terminal, after 30+ seconds
go tool pprof cpu.prof
(pprof) top 10
(pprof) list <suspicious_function>
(pprof) web- Profile under realistic load - ensure all collectors are running
- Profile for at least 30 seconds to get statistically significant data
- Compare profiles before and after optimizations
- Focus on the hottest paths first (highest CPU consumers)
- Don't forget to check memory allocations - they can cause GC pressure
Based on the architecture, pay attention to:
- Metric collection loops (1-second intervals)
- View rendering functions (called every update)
- String formatting and concatenation
- Sorting operations
- Terminal rendering overhead