mcpField
P
performance-analysis

performance-analysis

github.com/ruvnetAgent 工作流80.0k1.2k 次安装今天更新
代码仓库

关于 performance-analysis

performance-analysis 是用于分析 Claude Flow swarm 性能的技能,面向需要定位瓶颈和跟踪运行状况的开发者。它提供检测、性能剖析、报告生成及优化建议。

主要功能

  1. 01检测通信、处理、内存和网络瓶颈
  2. 02实时监控与历史性能剖析
  3. 03生成多种格式的性能报告
  4. 04提供优化建议并支持自动修复

适用场景

  1. 01排查 swarm 运行中的性能瓶颈
  2. 02比较 swarm 性能变化并生成报告
  3. 03持续监控任务执行和资源使用

MCP 相关

该技能通过 Claude Flow MCP 工具执行瓶颈检测并获取任务分析结果。

安装

复制下面的命令,在终端中运行。

$npx skills add https://github.com/ruvnet/ruflo --skill performance-analysis

安装后在 Claude Code 中输入/performance-analysis确认已加载。

详细介绍

性能分析技能

全面的性能分析套件,可用于识别瓶颈、分析蜂群操作、生成详细报告并提供可执行的优化建议。

概述

此技能整合了所有性能分析功能:

  • 瓶颈检测:识别通信、处理、内存和网络方面的性能瓶颈
  • 性能分析:实时监控蜂群操作并进行历史分析
  • 报告生成:以多种格式创建全面的性能报告
  • 优化建议:借助 AI 提供提升性能的建议

快速开始

基本瓶颈检测
npx claude-flow bottleneck detect
生成性能报告
npx claude-flow analysis performance-report --format html --include-metrics
分析并自动修复
npx claude-flow bottleneck detect --fix --threshold 15

核心功能

1. 瓶颈检测
命令语法
npx claude-flow bottleneck detect [options]
选项
  • --swarm-id, -s <id> - 分析指定的蜂群(默认:当前蜂群)
  • --time-range, -t <range> - 分析时间范围:1h、24h、7d、all(默认:1h)
  • --threshold <percent> - 瓶颈阈值百分比(默认:20)
  • --export, -e <file> - 将分析结果导出到文件
  • --fix - 应用自动优化
用法示例
# Basic detection for current swarm
npx claude-flow bottleneck detect

# Analyze specific swarm over 24 hours
npx claude-flow bottleneck detect --swarm-id swarm-123 -t 24h

# Export detailed analysis
npx claude-flow bottleneck detect -t 24h -e bottlenecks.json

# Auto-fix detected issues
npx claude-flow bottleneck detect --fix --threshold 15

# Low threshold for sensitive detection
npx claude-flow bottleneck detect --threshold 10 --export critical-issues.json
分析指标

通信瓶颈:

  • 消息队列延迟
  • Agent 响应时间
  • 协调开销
  • 内存访问模式
  • Agent 间通信延迟

处理瓶颈:

  • 任务完成时间
  • Agent 利用率
  • 并行执行效率
  • 资源争用
  • CPU$memory 使用模式

内存瓶颈:

  • 缓存命中率
  • 内存访问模式
  • 存储 I/O 性能
  • 神经模式加载时间
  • 内存分配效率

网络瓶颈:

  • API 调用延迟
  • MCP 通信延迟
  • 外部服务超时
  • 并发请求限制
  • 网络吞吐量问题
输出格式
🔍 Bottleneck Analysis Report
━━━━━━━━━━━━━━━━━━━━━━━━━━━

📊 Summary
├── Time Range: Last 1 hour
├── Agents Analyzed: 6
├── Tasks Processed: 42
└── Critical Issues: 2

🚨 Critical Bottlenecks
1. Agent Communication (35% impact)
   └── coordinator → coder-1 messages delayed by 2.3s avg

2. Memory Access (28% impact)
   └── Neural pattern loading taking 1.8s per access

⚠️ Warning Bottlenecks
1. Task Queue (18% impact)
   └── 5 tasks waiting > 10s for assignment

💡 Recommendations
1. Switch to hierarchical topology (est. 40% improvement)
2. Enable memory caching (est. 25% improvement)
3. Increase agent concurrency to 8 (est. 20% improvement)

✅ Quick Fixes Available
Run with --fix to apply:
- Enable smart caching
- Optimize message routing
- Adjust agent priorities
2. 性能分析
实时检测

在任务执行期间自动分析:

  • 执行时间与复杂度的关系
  • Agent 利用率
  • 资源限制
  • 操作模式
常见瓶颈模式

时间瓶颈:

  • 耗时超过 5 分钟的任务
  • 可并行执行的串行操作
  • 冗余的文件操作
  • 低效的算法实现

协调瓶颈:

  • 复杂任务仅由单个 Agent 处理
  • Agent 工作负载不均衡
  • 拓扑选择不当
  • 同步点过多

资源瓶颈:

  • 操作数量过多(> 100)
  • 内存限制
  • I/O 限制
  • 线程池饱和
MCP 集成
// Check for bottlenecks in Claude Code
mcp__claude-flow__bottleneck_detect({
  timeRange: "1h",
  threshold: 20,
  autoFix: false
})

// Get detailed task results with bottleneck analysis
mcp__claude-flow__task_results({
  taskId: "task-123",
  format: "detailed"
})

结果格式:

{
  "bottlenecks": [
    {
      "type": "coordination",
      "severity": "high",
      "description": "Single agent used for complex task",
      "recommendation": "Spawn specialized agents for parallel work",
      "impact": "35%",
      "affectedComponents": ["coordinator", "coder-1"]
    }
  ],
  "improvements": [
    {
      "area": "execution_time",
      "suggestion": "Use parallel task execution",
      "expectedImprovement": "30-50% time reduction",
      "implementationSteps": [
        "Split task into smaller units",
        "Spawn 3-4 specialized agents",
        "Use mesh topology for coordination"
      ]
    }
  ],
  "metrics": {
    "avgExecutionTime": "142s",
    "agentUtilization": "67%",
    "cacheHitRate": "82%",
    "parallelizationFactor": 1.2
  }
}
3. 报告生成
命令语法
npx claude-flow analysis performance-report [options]
选项
  • --format <type> - 报告格式:json、html、markdown(默认:markdown)
  • --include-metrics - 包含详细指标和图表
  • --compare <id> - 与之前的蜂群进行比较
  • --time-range <range> - 分析时间范围:1h、24h、7d、30d、all
  • --output <file> - 输出文件路径
  • --sections <list> - 以逗号分隔的要包含的章节列表
报告章节
  1. 执行摘要

    • 整体性能评分
    • 关键指标概览
    • 重要发现
  2. 蜂群概览

    • 拓扑配置
    • Agent 分布
    • 任务统计
  3. 性能指标

    • 执行时间
    • 吞吐量分析
    • 资源利用率
    • 延迟细分
  4. 瓶颈分析

    • 已识别的瓶颈
    • 影响评估
    • 优化优先级
  5. 对比分析(使用 --compare 时)

    • 性能趋势
    • 改进指标
    • 回归检测
  6. 建议

    • 按优先级排列的行动项
    • 预期改进
    • 实施指南
用法示例
# Generate HTML report with all metrics
npx claude-flow analysis performance-report --format html --include-metrics

# Compare current swarm with previous
npx claude-flow analysis performance-report --compare swarm-123 --format markdown

# Custom output with specific sections
npx claude-flow analysis performance-report \
  --sections summary,metrics,recommendations \
  --output reports$perf-analysis.html \
  --format html

# Weekly performance report
npx claude-flow analysis performance-report \
  --time-range 7d \
  --include-metrics \
  --format markdown \
  --output docs$weekly-performance.md

# JSON format for CI/CD integration
npx claude-flow analysis performance-report \
  --format json \
  --output build$performance.json
Markdown 报告示例
# Performance Analysis Report

## Executive Summary
- **Overall Score**: 87/100
- **Analysis Period**: Last 24 hours
- **Swarms Analyzed**: 3
- **Critical Issues**: 1

## Key Metrics
| Metric | Value | Trend | Target |
|--------|-------|-------|--------|
| Avg Task Time | 42s | ↓ 12% | 35s |
| Agent Utilization | 78% | ↑ 5% | 85% |
| Cache Hit Rate | 91% | → | 90% |
| Parallel Efficiency | 2.3x | ↑ 0.4x | 2.5x |

## Bottleneck Analysis
### Critical
1. **Agent Communication Delay** (Impact: 35%)
   - Coordinator → Coder messages delayed by 2.3s avg
   - **Fix**: Switch to hierarchical topology

### Warnings
1. **Memory Access Pattern** (Impact: 18%)
   - Neural pattern loading: 1.8s per access
   - **Fix**: Enable memory caching

## Recommendations
1. **High Priority**: Switch to hierarchical topology (40% improvement)
2. **Medium Priority**: Enable memory caching (25% improvement)
3. **Low Priority**: Increase agent concurrency to 8 (20% improvement)
4. 优化建议
自动修复

使用 --fix 时,可能会应用以下优化:

1. 拓扑优化

  • 切换为效率更高的拓扑(网格 → 分层)
  • 调整通信模式
  • 降低协调开销
  • 优化消息路由

2. 缓存增强

  • 启用内存缓存
  • 优化缓存策略
  • 预加载常用模式
  • 实施缓存预热

3. 并发调优

  • 调整 Agent 数量
  • 优化并行执行
  • 平衡工作负载分布
  • 实施负载均衡

4. 优先级调整

  • 重新排列任务队列
  • 优先处理关键路径
  • 缩短等待时间
  • 实施公平调度

5. 资源优化

  • 优化内存使用
  • 减少 I/O 操作
  • 批量调用 API
  • 实施连接池
性能影响

解决瓶颈后的典型改进:

  • 通信:消息传递速度提升 30-50%
  • 处理:任务完成时间缩短 20-40%
  • 内存:缓存未命中减少 40-60%
  • 网络:API 延迟降低 25-45%
  • 整体:总性能提升 25-45%

高级用法

持续监控
# Monitor performance in real-time
npx claude-flow swarm monitor --interval 5

# Generate hourly reports
while true; do
  npx claude-flow analysis performance-report \
    --format json \
    --output logs$perf-$(date +%Y%m%d-%H%M).json
  sleep 3600
done
CI/CD 集成
# .github$workflows$performance.yml
name: Performance Analysis
on: [push, pull_request]

jobs:
  analyze:
    runs-on: ubuntu-latest
    steps:
      - uses: actions$checkout@v2
      - name: Run Performance Analysis
        run: |
          npx claude-flow analysis performance-report \
            --format json \
            --output performance.json
      - name: Check Performance Thresholds
        run: |
          npx claude-flow bottleneck detect \
            --threshold 15 \
            --export bottlenecks.json
      - name: Upload Reports
        uses: actions$upload-artifact@v2
        with:
          name: performance-reports
          path: |
            performance.json
            bottlenecks.json
自定义分析脚本
// scripts$analyze-performance.js
const { exec } = require('child_process');
const fs = require('fs');

async function analyzePerformance() {
  // Run bottleneck detection
  const bottlenecks = await runCommand(
    'npx claude-flow bottleneck detect --format json'
  );

  // Generate performance report
  const report = await runCommand(
    'npx claude-flow analysis performance-report --format json'
  );

  // Analyze results
  const analysis = {
    bottlenecks: JSON.parse(bottlenecks),
    performance: JSON.parse(report),
    timestamp: new Date().toISOString()
  };

  // Save combined analysis
  fs.writeFileSync(
    'analysis$combined-report.json',
    JSON.stringify(analysis, null, 2)
  );

  // Generate alerts if needed
  if (analysis.bottlenecks.critical.length > 0) {
    console.error('CRITICAL: Performance bottlenecks detected!');
    process.exit(1);
  }
}

function runCommand(cmd) {
  return new Promise((resolve, reject) => {
    exec(cmd, (error, stdout, stderr) => {
      if (error) reject(error);
      else resolve(stdout);
    });
  });
}

analyzePerformance().catch(console.error);

最佳实践

1. 定期分析
  • 在重大变更后运行瓶颈检测
  • 每周生成性能报告
  • 随时间监控趋势
  • 设置自动提醒
2. 阈值调优
  • 从默认阈值(20%)开始
  • 生产系统使用较低阈值(10-15%)
  • 开发环境使用较高阈值(25-30%)
  • 根据需求进行调整
3. 修复策略
  • 应用 --fix 前务必先审查
  • 先在开发环境中测试修复
  • 逐步应用修复
  • 变更后监控影响
4. 报告集成
  • 纳入文档
  • 定期与团队分享
  • 跟踪改进情况
  • 用于容量规划
5. 持续优化
  • 从每次分析中学习
  • 制定性能预算
  • 建立基准
  • 设定改进目标

故障排除

常见问题

内存使用率高

# Analyze memory bottlenecks
npx claude-flow bottleneck detect --threshold 10

# Check cache performance
npx claude-flow cache manage --action stats

# Review memory metrics
npx claude-flow memory usage

任务执行缓慢

# Identify slow tasks
npx claude-flow task status --detailed

# Analyze coordination overhead
npx claude-flow bottleneck detect --time-range 1h

# Check agent utilization
npx claude-flow agent metrics

缓存性能不佳

# Analyze cache hit rates
npx claude-flow analysis performance-report --sections metrics

# Review cache strategy
npx claude-flow cache manage --action analyze

# Enable cache warming
npx claude-flow bottleneck detect --fix

与其他技能集成

  • swarm-orchestration:使用性能数据优化拓扑
  • memory-management:根据分析结果改进缓存策略
  • task-coordination:根据瓶颈调整调度
  • neural-training:根据性能数据训练模式

相关命令

  • npx claude-flow swarm monitor - 实时监控
  • npx claude-flow token usage - Token 优化分析
  • npx claude-flow cache manage - 缓存优化
  • npx claude-flow agent metrics - Agent 性能指标
  • npx claude-flow task status - 任务执行分析

另请参阅


版本:1.0.0 最后更新:2025-10-19 维护者:Claude Flow 团队

评论

支持 Markdown