一键导入
perf-profile
Profile Python and Node.js application performance. Identify slow endpoints, memory leaks, and CPU bottlenecks.
用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
菜单
Profile Python and Node.js application performance. Identify slow endpoints, memory leaks, and CPU bottlenecks.
用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
基于 SOC 职业分类
Scan project, then generate or reconcile .primeignore patterns for smarter /prime loading
Run WCAG accessibility audits on frontend projects. Checks HTML semantics, ARIA usage, color contrast, and keyboard navigation patterns.
Generate OpenAPI specs from code, validate API contracts, and check for breaking changes between versions.
Backend architecture patterns, API design, database optimization, and server-side best practices for Node.js, Express, and Next.js API routes.
Incrementally fix TypeScript and build errors one at a time with verification. Invokes the build-error-resolver agent.
Create or verify a checkpoint in your workflow
| name | perf-profile |
| description | Profile Python and Node.js application performance. Identify slow endpoints, memory leaks, and CPU bottlenecks. |
| argument-hint | [--python|--node|--endpoint <url>|--memory|--cpu] |
Profile application performance for Python and Node.js projects. Identifies slow endpoints, memory usage, and CPU bottlenecks.
Parse $ARGUMENTS:
--python: Profile a Python application--node: Profile a Node.js application--endpoint <url>: Profile a specific HTTP endpoint with timing--memory: Focus on memory usage analysis--cpu: Focus on CPU profiling--slow: Find slow functions/queries in the codebase (static analysis)--endpoint)Time a specific HTTP endpoint with multiple requests:
# Single request with timing breakdown
curl -w "\n DNS: %{time_namelookup}s\n Connect: %{time_connect}s\n TLS: %{time_appconnect}s\n TTFB: %{time_starttransfer}s\n Total: %{time_total}s\n Size: %{size_download} bytes\n" -o /dev/null -s <url>
# Multiple requests for p50/p95/p99 (10 requests)
for i in $(seq 1 10); do
curl -o /dev/null -s -w "%{time_total}\n" <url>
done | sort -n | awk '
{ a[NR] = $1; sum += $1 }
END {
print " Requests: " NR
print " Mean: " sum/NR "s"
print " p50: " a[int(NR*0.5)] "s"
print " p95: " a[int(NR*0.95)] "s"
print " p99: " a[int(NR*0.99)] "s"
print " Min: " a[1] "s"
print " Max: " a[NR] "s"
}
'
--python)Search for known performance anti-patterns:
# N+1 query patterns (SQLAlchemy)
grep -rn "\.query\." --include="*.py" <path> | grep -i "for\|loop\|iter"
# Synchronous I/O in async code
grep -rn "requests\.\(get\|post\|put\)" --include="*.py" <path>
# Missing pagination
grep -rn "\.all()" --include="*.py" <path>
# Large file reads without streaming
grep -rn "\.read()" --include="*.py" <path> | grep -v test
# Sleep calls (potential polling anti-pattern)
grep -rn "time\.sleep\|asyncio\.sleep" --include="*.py" <path>
Suggest profiling commands:
To profile a running Python app:
# cProfile (built-in)
python -m cProfile -s cumtime app.py 2>&1 | head -30
# py-spy (sampling profiler, no code changes needed)
pip install py-spy
py-spy top --pid <PID> # Live top-like view
py-spy record --pid <PID> -o profile.svg # Flame graph
# memory_profiler
pip install memory_profiler
python -m memory_profiler app.py
--node)# Synchronous fs operations
grep -rn "readFileSync\|writeFileSync\|existsSync" --include="*.ts" --include="*.js" <path>
# Missing async/await (potential unhandled promises)
grep -rn "\.then(" --include="*.ts" --include="*.js" <path> | grep -v node_modules | head -10
# Console.log in production code
grep -rn "console\.log" --include="*.ts" --include="*.js" <path> | grep -v node_modules | grep -v test
# Large payload without streaming
grep -rn "JSON\.parse\|JSON\.stringify" --include="*.ts" --include="*.js" <path> | grep -v node_modules | head -10
To profile a running Node.js app:
# Built-in profiler
node --prof app.js
node --prof-process isolate-*.log > profile.txt
# Clinic.js (comprehensive)
npx clinic doctor -- node app.js
npx clinic flame -- node app.js
# Heap snapshot
node --inspect app.js
# Then connect Chrome DevTools to chrome://inspect
--memory)Python:
# Check process memory (if running)
ps aux | grep -E "python|uvicorn|gunicorn" | grep -v grep | awk '{print $2, $4"%", $6/1024"MB", $11}'
# Check for memory leak patterns
grep -rn "global\|cache\s*=\s*{}\|_cache\|lru_cache" --include="*.py" <path> | head -10
Node.js:
# Check process memory
ps aux | grep -E "node|next|express" | grep -v grep | awk '{print $2, $4"%", $6/1024"MB", $11}'
Docker containers:
docker stats --no-stream --format "table {{.Name}}\t{{.CPUPerc}}\t{{.MemUsage}}\t{{.MemPerc}}" 2>/dev/null
--slow)Search for potentially slow operations:
# Database queries without limits
grep -rn "SELECT.*FROM" --include="*.py" --include="*.ts" <path> | grep -v "LIMIT\|limit\|test" | head -10
# Missing indexes (check model definitions)
grep -rn "Column\|mapped_column" --include="*.py" <path> | grep -v "index=True\|primary_key" | head -10
# Large loop operations
grep -rn "for.*in.*\.all()\|for.*in.*find(" --include="*.py" <path>
## Performance Profile: <project-name>
### Endpoint Timing (if --endpoint)
| Metric | Value |
|--------|-------|
| Mean | 0.234s |
| p50 | 0.198s |
| p95 | 0.412s |
| p99 | 0.891s |
### Static Analysis Findings
| Category | Count | Severity | Files |
|----------|-------|----------|-------|
| Sync I/O in async code | 3 | HIGH | api/routes.py, services/email.py |
| Missing pagination (.all()) | 5 | MEDIUM | models.py, reports.py |
| N+1 query patterns | 2 | HIGH | orders.py |
### Memory (if --memory)
| Process | PID | Memory | CPU |
|---------|-----|--------|-----|
| uvicorn | 12345 | 245MB | 2.3% |
### Recommendations
1. [HIGH] Replace `requests.get()` with `httpx` async client in 3 files
2. [HIGH] Add pagination to 5 `.all()` queries
3. [MEDIUM] Add database indexes for frequently queried columns
py-spy (Python) or clinic (Node) as they have low overhead