| name | memory-profiling |
| description | Go application memory profiling and analysis. Use when investigating memory leaks or high memory usage. |
| disable-model-invocation | true |
| user-invocable | true |
| allowed-tools | Bash, Read, Grep |
Memory Profiling Skill
Investigate and analyze Go application memory usage through heap profiling and comparative analysis.
Prerequisites
IMPORTANT: pprof server requires KATTLE_DEBUG=1 environment variable:
KATTLE_DEBUG=1 wails dev
Verify pprof server is running:
curl -s http://localhost:6060/debug/pprof/ > /dev/null && echo "pprof OK" || echo "pprof NOT available"
Current State Check
Before profiling, establish the current memory baseline:
ps aux | grep -E "(PID|kattle|gui)" | head -20
Verify baseline profile exists (from project root):
ls -lh baseline_heap.pb.gz 2>/dev/null || echo "No baseline found"
Heap Profile Collection
Collect a heap profile from the running application:
curl -o /tmp/heap.pb.gz http://localhost:6060/debug/pprof/heap
Verify collection was successful:
ls -lh /tmp/heap.pb.gz
Alternative: The app provides DumpMemory(label) function which saves labeled dumps to ~/kattle-dumps/:
- Format:
heap_<timestamp>_<seq>_<label>.pb.gz
- Location:
~/kattle-dumps/
Analysis Commands
Top 10 Memory Allocators
Get the most significant memory allocators:
go tool pprof -top /tmp/heap.pb.gz | head -15
Differential Analysis (vs Baseline)
Compare current heap profile against a known baseline:
go tool pprof -diff_base=baseline_heap.pb.gz -top /tmp/heap.pb.gz
Or use the helper script:
bash /Users/hansuk.hong/P/kattle/.claude/skills/memory-profiling/scripts/compare-heap.sh [baseline_path] [current_path]
Interactive Investigation
For deeper analysis, use interactive mode:
go tool pprof /tmp/heap.pb.gz
Reporting Format
When analyzing memory profiles, report:
- Top 10 Allocators: List of functions responsible for largest allocations
- Delta from Baseline: Increase/decrease in allocation patterns since baseline
- Suspect Areas: Functions or packages with unexplained growth
- Memory Metrics:
- Total inuse_space (bytes)
- Total alloc_objects (count)
- Per-function percentages of total heap
Example Report Structure
Memory Profile Analysis Report
==============================
Top 10 Allocators (Current):
1. package.function - X.XGB (XX%)
2. package.function - X.XGB (XX%)
...
Changes vs Baseline:
- package.function: +X.XGB (new allocation)
- package.function: -X.XGB (reduction)
Suspect Areas:
- package.function: Excessive allocation growth
- Recommendations for investigation
Usage Workflow
- Establish baseline: Collect heap profile when application is in healthy state
- Run application under load or over time
- Collect current heap profile
- Compare using differential analysis
- Investigate top allocators and changes
- Identify memory leaks or optimization opportunities