AgentSkillsCN

rust-profiling

使用 samply 对 Rust 代码进行性能剖析,定位 CPU 瓶颈。适用于性能缓慢的情况,或在优化前进行性能分析,亦或当用户提出性能剖析需求时。

SKILL.md
--- frontmatter
name: rust-profiling
description: Profile Rust code using samply to identify CPU bottlenecks. Use when performance is slow, before optimizing, or when the user asks to profile.

Rust Profiling with Samply

Profile Rust binaries to find CPU bottlenecks using samply.

Quick Start

bash
# 1. Ensure profiling profile exists in Cargo.toml (see reference.md)
# 2. Build with debug symbols
cargo build --profile profiling

# 3. Profile (opens Firefox Profiler UI)
samply record ./target/profiling/<binary> [args...]

# 4. Or save for CLI analysis
samply record --save-only -o profile.json ./target/profiling/<binary>
python3 ~/.claude/skills/rust-profiling/scripts/analyze_profile.py profile.json

Skill Files

FilePurpose
reference.mdCargo.toml setup, samply options, troubleshooting
examples.mdCommon profiling scenarios and analysis patterns
scripts/analyze_profile.pyCLI tool to analyze saved profile.json files

When to Use

  • Performance is slower than expected
  • Before optimizing (measure first!)
  • After optimization (verify improvement)
  • Investigating CPU-bound operations

What to Look For

PatternMeaningAction
High self-timeFunction itself is slowDirect optimization target
High total-timeCalled often or slow calleesCheck call frequency
malloc/alloc in hot pathAllocation overheadPool, arena, or stack allocate
pthread_mutex/parking_lotLock contentionReduce lock scope or use lock-free