
使用方式
关于
使用 Chrome DevTools、火焰图和 APM 工具分析和优化应用性能。
name: perf-ops description: "性能分析和优化编排器——诊断症状、分派分析到语言专家、管理前后对比。触发条件:performance、profiling、flamegraph、pprof、py-spy、clinic.js、memray、heaptrack、bundle size、webpack analyzer、load testing、k6、artillery、vegeta、locust、benchmark、hyperfine、criterion、slow query、EXPLAIN ANALYZE、N+1、caching、optimization、latency、throughput、p99、memory leak、CPU spike、bottleneck。" license: MIT allowed-tools: "Read Edit Write Bash Glob Grep Agent TaskCreate TaskUpdate" metadata: author: claude-mods related-skills: debug-ops, monitoring-ops, testing-ops, code-stats, postgres-ops
性能操作
跨语言性能分析和优化的编排器。内联分类症状,将分析分派给语言专家代理(后台),并通过确认管理优化。
架构
User describes performance issue or requests profiling
|
+---> T1: Diagnose (inline, fast)
| +---> Classify symptom (decision tree)
| +---> Detect language/runtime from project
| +---> Check installed profiling tools
| +---> Determine production vs development
| +---> Gather system baseline (CPU/mem/disk)
| +---> Present: diagnosis + recommended profiling approach
|
+---> T2: Profile (dispatch to language expert, background)
| +---> Select expert agent from routing table
| +---> Build perf-focused dispatch prompt
| +---> Expert runs profiler, collects data, interprets results
| +---> Returns: findings + bottleneck identification + suggestions
|
+---> T3: Optimize (dispatch to expert, foreground + confirm)
+---> Expert proposes specific code changes
+---> Preflight: what changes, expected impact, risks
+---> User confirms
+---> Apply changes
+---> Re-benchmark for before/after delta
安全层级
T1:诊断 - 内联运行
无需代理。通过 Bash 直接执行获取即时结果。
| 操作 | 命令 | 用途 |
|------|------|------|
| CPU 基线 | top -l 1 / mpstat | 当前 CPU 使用率 |
| 内存基线 | vm_stat / free -h | 内存压力 |
| 磁盘 I/O | iostat | 磁盘瓶颈 |
| 进程列表 | ps aux --sort=-%cpu | 高 CPU 进程 |
| 网络 | ss -tuln / netstat | 连接状态 |
T2:分析 - 后台分派
| 语言 | 工具 | 命令 |
|------|------|------|
| Python | py-spy | py-spy record -o profile.svg -- python app.py |
| Python | memray | memray run app.py |
| Node.js | clinic.js | clinic doctor -- node app.js |
| Go | pprof | go tool pprof http://localhost:6060/debug/pprof/profile |
| Rust | criterion | 内置基准测试框架 |
| 通用 | hyperfine | hyperfine 'command1' 'command2' |
T3:优化 - 需确认
在应用更改前始终确认:
- 预期影响是什么?
- 有什么风险?
- 能否回滚?
症状分类决策树
症状是什么?
│
├─ 高 CPU 使用率
│ ├─ 持续高 → CPU 分析(火焰图)
│ └─ 间歇性尖峰 → 采样分析 + 时间关联
│
├─ 高内存使用
│ ├─ 持续增长 → 内存泄漏分析
│ └─ 突然尖峰 → 堆快照对比
│
├─ 慢响应时间
│ ├─ 所有请求都慢 → 系统级瓶颈
│ ├─ 特定端点慢 → 端点分析
│ └─ 随时间变慢 → 资源耗尽/泄漏
│
├─ 高延迟
│ ├─ 数据库查询 → EXPLAIN ANALYZE
│ ├─ 外部 API → 网络追踪
│ └─ 计算密集 → CPU 分析
│
└─ 吞吐量低
├─ 单线程瓶颈 → 并发/并行
├─ I/O 绑定 → 异步/连接池
└─ 资源竞争 → 锁分析
数据库性能
-- 慢查询分析
EXPLAIN ANALYZE SELECT * FROM users WHERE email = 'test@example.com';
-- 缺失索引检测
SELECT schemaname, tablename, attname
FROM pg_stats
WHERE n_distinct > 100 AND tablename NOT LIKE 'pg_%';
附加资源
./references/flamegraph-guide.md- 火焰图解读指南./references/load-testing.md- k6/Artillery 负载测试模式./references/database-perf.md- 数据库性能优化./references/frontend-perf.md- 前端性能(Core Web Vitals)
兼容工具
Claude CodeCursorGitHub Copilot
标签
通用
