profile

Run CPU and memory profiling with pprof to identify performance hotspots. Use when investigating high resource usage.

12 stars

Best use case

profile is best used when you need a repeatable AI agent workflow instead of a one-off prompt.

Run CPU and memory profiling with pprof to identify performance hotspots. Use when investigating high resource usage.

Teams using profile should expect a more consistent output, faster repeated execution, less prompt rewriting.

When to use this skill

  • You want a reusable workflow that can be run more than once with consistent structure.

When not to use this skill

  • You only need a quick one-off answer and do not need a reusable workflow.
  • You cannot install or maintain the underlying files, dependencies, or repository context.

Installation

Claude Code / Cursor / Codex

$curl -o ~/.claude/skills/profile/SKILL.md --create-dirs "https://raw.githubusercontent.com/PeterBooker/veloria/main/.claude/skills/profile/SKILL.md"

Manual Installation

  1. Download SKILL.md from GitHub
  2. Place it in .claude/skills/profile/SKILL.md inside your project
  3. Restart your AI agent — it will auto-discover the skill

How profile Compares

Feature / AgentprofileStandard Approach
Platform SupportNot specifiedLimited / Varies
Context Awareness High Baseline
Installation ComplexityUnknownN/A

Frequently Asked Questions

What does this skill do?

Run CPU and memory profiling with pprof to identify performance hotspots. Use when investigating high resource usage.

Where can I find the source code?

You can find the source code on GitHub using the link provided at the top of the page.

SKILL.md Source

# CPU and Memory Profiling

Profile Go code to identify CPU hotspots and memory allocators using pprof.

## Usage

- `/profile cpu ./internal/index/` - CPU profiling on index package
- `/profile memory ./internal/repo/` - Memory profiling on repo package
- `/profile all ./...` - Both CPU and memory on all packages

## Steps

1. **Parse arguments**
   - First argument: Profile type (`cpu`, `memory`, or `all`)
   - Second argument: Package path (defaults to `./...`)

2. **Create profile output directory**
   ```bash
   mkdir -p .profiles
   ```

4. **Run profiling benchmarks**

   For CPU profiling:
   ```bash
   go test -cpuprofile=.profiles/cpu.prof -bench=. $PACKAGE 2>&1
   ```

   For memory profiling:
   ```bash
   go test -memprofile=.profiles/mem.prof -bench=. $PACKAGE 2>&1
   ```

5. **Analyze CPU profile**
   ```bash
   go tool pprof -top -cum .profiles/cpu.prof 2>&1 | head -30
   ```

   Identify:
   - Top 10 CPU consumers by cumulative time
   - Functions with high self time (computation hotspots)
   - Unexpected entries (potential optimization targets)

6. **Analyze memory profile**
   ```bash
   go tool pprof -top -alloc_space .profiles/mem.prof 2>&1 | head -30
   ```

   Identify:
   - Top allocators by total bytes
   - Functions with high allocation counts
   - Potential sources of GC pressure

7. **Generate flamegraph data** (if requested)
   ```bash
   go tool pprof -raw .profiles/cpu.prof > .profiles/cpu.raw
   ```

8. **Report findings**

   Structure the report as:

   ### CPU Hotspots
   | Function | Self% | Cum% | Observation |
   |----------|-------|------|-------------|

   ### Memory Allocators
   | Function | Bytes | Allocs | Observation |
   |----------|-------|--------|-------------|

   ### Optimization Suggestions
   - List specific, actionable recommendations
   - Reference line numbers where applicable
   - Note any patterns (e.g., repeated allocations in loops)

## Interpreting Results

### CPU Profile Indicators
- **High self%**: Direct computation hotspot
- **High cum% but low self%**: Calls expensive functions
- **runtime.***: GC or scheduler overhead

### Memory Profile Indicators
- **High alloc_space**: Total memory pressure
- **High alloc_objects**: GC pressure from many small allocations
- **Repeated patterns**: Loop allocations, string concatenation

## Common Hotspots in Veloria

Watch for issues in:
- `(*Index).Search` - Regex compilation, line reading
- `(*Repository).Load` - Index file mapping
- `(*IndexedExtension).Update` - Hot-swap operations
- HTTP handlers - JSON marshaling, response writing

## Cleanup

Profile files are stored in `.profiles/`. Add to `.gitignore` if not already present.

Related Skills

We are still matching the closest adjacent skills for this page. In the meantime, continue through the full directory.