Go CPU and Memory Profiling

VerifiedSafe

This skill runs CPU and memory profiling on Go packages using pprof, then analyzes the results to identify performance hotspots and memory allocation issues. Use it when investigating high resource usage or optimizing code.

Sby Skills Guide Bot
DevelopmentIntermediate
6/2/2026
Claude Code
#go-profiling#pprof#performance#cpu-profiling#memory-profiling

Recommended for

Automated summary

Profiles CPU and memory of Go code using pprof to identify performance bottlenecks.

Strengths

  • Detailed analysis of CPU hotspots and memory allocators
  • Generates tabular reports with actionable observations
  • Provides optimization suggestions with function references

Limitations

  • Requires code to be runnable with benchmarks (go test -bench=.)
  • Only works for Go code
  • Profiles are generated on benchmarks, not on real execution
When to use it

When investigating high CPU or memory usage in a Go application.

When not to use it

For production profiling or languages other than Go.

Security analysis

Safe
Quality score90/100

The skill uses standard Go tooling for profiling, with no destructive or exfiltrating behaviors. Package path is user-provided but confined to Go test contexts. No network calls or disablement of safety features.

No concerns found

How this analysis is made

Examples

CPU profile on a specific package
/profile cpu ./internal/index/
Memory profile on all packages
/profile memory ./...
Full profile (CPU and memory) on current module
/profile all .

name: profile description: Run CPU and memory profiling with pprof to identify performance hotspots. Use when investigating high resource usage. disable-model-invocation: true argument-hint: "cpu|memory|all package-path"

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

    mkdir -p .profiles
    
  3. Run profiling benchmarks

    For CPU profiling:

    go test -cpuprofile=.profiles/cpu.prof -bench=. $PACKAGE 2>&1
    

    For memory profiling:

    go test -memprofile=.profiles/mem.prof -bench=. $PACKAGE 2>&1
    
  4. Analyze CPU profile

    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)
  5. Analyze memory profile

    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
  6. Generate flamegraph data (if requested)

    go tool pprof -raw .profiles/cpu.prof > .profiles/cpu.raw
    
  7. 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.

From the file to a first result

The download contains exactly the content displayed on this page. This copy may differ from the latest version in the source repository.

View the source and supporting files

This download contains SKILL.md only. Any scripts, references, templates and dependencies are not included. Get the required files from the source, preserving their directory structure, before continuing.

1. Download the file

Download SKILL.md

From the root of a test project, save the file as .skill-downloads/go-cpu-and-memory-profiling-mmlj2nss/SKILL.md, or use the command below. This folder is for inspecting the skill before installation.

Command for macOS/Linux or WSL: requires a POSIX shell and curl. On Windows without WSL, use the download button and create the folder manually.

mkdir -p '.skill-downloads/go-cpu-and-memory-profiling-mmlj2nss' && curl --fail --show-error --location 'https://skills-guides.com/api/skills/go-cpu-and-memory-profiling-mmlj2nss/download' --output '.skill-downloads/go-cpu-and-memory-profiling-mmlj2nss/SKILL.md.part' && mv '.skill-downloads/go-cpu-and-memory-profiling-mmlj2nss/SKILL.md.part' '.skill-downloads/go-cpu-and-memory-profiling-mmlj2nss/SKILL.md'

2. Check prerequisites

Read SKILL.md before using it. If it references scripts or external services, inspect them and prepare the required access in your test environment.

No recognized prerequisites section in this file. This does not mean it is self-contained: libraries, tools and access requirements may be mentioned elsewhere in the content or source repository.

The platforms on this page are catalog indications. The paths below follow tool documentation; they do not prove this skill has been run in those tools. No minimum tool version is confirmed for this listing.

3. Load the skill

After inspection, copy the complete folder into your project using one of the commands below, then open a new tool session. The command stops if a folder with the same name already exists: compare the files before replacing it.

Claude Code
test -f '.skill-downloads/go-cpu-and-memory-profiling-mmlj2nss/SKILL.md' && test -s '.skill-downloads/go-cpu-and-memory-profiling-mmlj2nss/SKILL.md' && mkdir -p '.claude/skills' && test ! -e '.claude/skills/profile' && cp -R '.skill-downloads/go-cpu-and-memory-profiling-mmlj2nss' '.claude/skills/profile'

OpenSkills

OpenSkills must already be installed. The local install/read procedure is checked with OpenSkills 1.5.0, which requires Node.js ≥ 20.6.0. Catalog slugs are not resolved automatically.

Official OpenSkills installation
openskills install './.skill-downloads/go-cpu-and-memory-profiling-mmlj2nss'

openskills read 'go-cpu-and-memory-profiling-mmlj2nss'

Reading should display the installed file content and its base directory. It does not run the skill or install its dependencies.

For an agent that reads AGENTS.md, then sync the index. This command changes AGENTS.md: review the diff before using it.

openskills sync

Manual method or another tool: attach SKILL.md to a conversation, or open it in an agent that can read files. Include any required supporting resources. No universal folder is recognized by every tool.

4. Try a first task

Use a short, synthetic input: an API endpoint, a small document or an interface brief. In a new conversation, attach the file or give the agent its path, then adapt this request:

Read .skill-downloads/go-cpu-and-memory-profiling-mmlj2nss/SKILL.md and apply its instructions to this example: [describe a test input]. Identify any missing files, dependencies or access. Produce the result requested by the skill without inventing data or running unreviewed scripts.

Expected result: output matching the skill instructions, or a precise list of missing prerequisites. A read confirmation alone does not validate a first use. If an external resource is unavailable, that path remains untested.

Related skills