diff --git a/.claude/checkpoints/1754481271.json b/.claude/checkpoints/1754481271.json new file mode 100644 index 0000000000..6e5eae4d86 --- /dev/null +++ b/.claude/checkpoints/1754481271.json @@ -0,0 +1 @@ +{"branch": "checkpoint/pre-edit-20250806-115431", "file": "/workspaces/claude-code-flow/benchmark/examples/basic/benchmark_with_reports.py", "timestamp": "2025-08-06T11:54:31Z", "type": "pre-edit", "original_branch": "alpha-88"} diff --git a/.claude/checkpoints/1754481273.json b/.claude/checkpoints/1754481273.json new file mode 100644 index 0000000000..62dd970850 --- /dev/null +++ b/.claude/checkpoints/1754481273.json @@ -0,0 +1 @@ +{"tag": "checkpoint-20250806-115433", "file": "/workspaces/claude-code-flow/benchmark/examples/basic/benchmark_with_reports.py", "timestamp": "2025-08-06T11:54:33Z", "type": "post-edit", "branch": "alpha-88", "diff_summary": " .claude-flow/metrics/performance.json | 2 +- .claude-flow/metrics/system-metrics.json | 72 +++++++++++ .claude-flow/metrics/task-metrics.json | 6 +- .claude/checkpoints/1754481230.json | 1 + .claude/checkpoints/1754481232.json | 1 + benchmark/examples/basic/benchmark_with_reports.py | 71 +++++++++++ .../cli/__pycache__/main.cpython-312.pyc | Bin 29784 -> 36741 bytes benchmark/test_improved_report.py | 35 ------ claude-flow-wiki | 0 ...hmark_1be63008-e1d4-4020-a6c6-7d253ecc91de.json | 38 ++++++ reports/hive_mind_20250806_115403.json | 31 +++++ ...trics_1be63008-e1d4-4020-a6c6-7d253ecc91de.json | 66 +++++++++++ ...eport_1be63008-e1d4-4020-a6c6-7d253ecc91de.json | 47 ++++++++ ...lized_1be63008-e1d4-4020-a6c6-7d253ecc91de.json | 132 +++++++++++++++++++++ 14 files changed, 463 insertions(+), 39 deletions(-) "} diff --git a/benchmark/examples/reporting/enhanced_report_viewer.py b/benchmark/examples/reporting/enhanced_report_viewer.py new file mode 100644 index 0000000000..4850e6fec6 --- /dev/null +++ b/benchmark/examples/reporting/enhanced_report_viewer.py @@ -0,0 +1,259 @@ +#!/usr/bin/env python3 +""" +Enhanced Report Viewer for Claude Flow Benchmarks +Shows detailed metrics with file references and analysis. +""" + +import json +import sys +from pathlib import Path +from datetime import datetime +from typing import Dict, List, Optional +import subprocess +from dataclasses import dataclass +from collections import defaultdict + +@dataclass +class BenchmarkReport: + """Structured benchmark report with detailed metrics.""" + benchmark_id: str + status: str + duration: float + metrics: Dict + results: List[Dict] + file_path: Path + + @property + def success_rate(self) -> float: + """Calculate success rate from results.""" + if not self.results: + return 0.0 + successful = sum(1 for r in self.results if r.get('status') == 'success') + return successful / len(self.results) + + @property + def total_tokens(self) -> int: + """Calculate total tokens used.""" + total = 0 + for result in self.results: + output = result.get('output', {}) + if isinstance(output, dict): + total += output.get('token_count', 0) + return total + + @property + def average_execution_time(self) -> float: + """Calculate average execution time.""" + times = [r.get('execution_time', 0) for r in self.results] + return sum(times) / len(times) if times else 0 + +class EnhancedReportViewer: + """View and analyze benchmark reports with detailed metrics.""" + + def __init__(self, report_dir: Path = Path("reports")): + self.report_dir = report_dir + self.reports: List[BenchmarkReport] = [] + + def load_reports(self, pattern: str = "benchmark_*.json") -> None: + """Load all benchmark reports matching pattern.""" + if not self.report_dir.exists(): + print(f"āŒ Report directory not found: {self.report_dir}") + return + + json_files = list(self.report_dir.glob(pattern)) + print(f"šŸ“‚ Found {len(json_files)} benchmark reports in {self.report_dir}") + + for file_path in json_files: + try: + with open(file_path) as f: + data = json.load(f) + report = BenchmarkReport( + benchmark_id=data.get('benchmark_id', 'unknown'), + status=data.get('status', 'unknown'), + duration=data.get('duration', 0), + metrics=data.get('metrics', {}), + results=data.get('results', []), + file_path=file_path + ) + self.reports.append(report) + except Exception as e: + print(f"āš ļø Failed to load {file_path}: {e}") + + def display_summary(self) -> None: + """Display summary of all reports.""" + if not self.reports: + print("No reports loaded") + return + + print("\n" + "="*80) + print("šŸ“Š BENCHMARK REPORTS SUMMARY") + print("="*80) + + for i, report in enumerate(self.reports, 1): + print(f"\nšŸ“‹ Report {i}/{len(self.reports)}") + print(f" šŸ“„ File: {report.file_path}") + print(f" šŸ†” ID: {report.benchmark_id}") + print(f" āœ… Status: {report.status}") + print(f" ā±ļø Duration: {report.duration:.2f}s") + print(f" šŸ“ˆ Success Rate: {report.success_rate:.1%}") + print(f" šŸŽÆ Tasks: {len(report.results)}") + + # Display key metrics + if report.metrics: + print(f"\n šŸ“Š Performance Metrics:") + print(f" • Wall Clock Time: {report.metrics.get('wall_clock_time', 'N/A'):.2f}s") + print(f" • Tasks/Second: {report.metrics.get('tasks_per_second', 'N/A'):.2f}") + print(f" • Peak Memory: {report.metrics.get('peak_memory_mb', 'N/A'):.1f} MB") + print(f" • Avg CPU: {report.metrics.get('average_cpu_percent', 'N/A'):.1f}%") + + def display_detailed_report(self, benchmark_id: Optional[str] = None) -> None: + """Display detailed report for specific benchmark or latest.""" + if not self.reports: + print("No reports loaded") + return + + # Find report + if benchmark_id: + report = next((r for r in self.reports if r.benchmark_id == benchmark_id), None) + else: + # Get latest report + report = max(self.reports, key=lambda r: r.file_path.stat().st_mtime) + + if not report: + print(f"Report not found: {benchmark_id}") + return + + print("\n" + "="*80) + print("šŸ“Š DETAILED BENCHMARK REPORT") + print("="*80) + + # File references + print("\nšŸ“ FILE REFERENCES:") + print(f" • Report: {report.file_path}") + print(f" • Metrics: {report.file_path.parent / f'metrics_{report.benchmark_id}.json'}") + print(f" • Process: {report.file_path.parent / f'process_report_{report.benchmark_id}.json'}") + + # Overview + print(f"\nšŸ“‹ OVERVIEW:") + print(f" • Benchmark ID: {report.benchmark_id}") + print(f" • Status: {report.status}") + print(f" • Total Duration: {report.duration:.3f}s") + print(f" • Success Rate: {report.success_rate:.1%}") + + # Performance metrics + print(f"\n⚔ PERFORMANCE:") + if report.metrics: + print(f" • Wall Clock Time: {report.metrics.get('wall_clock_time', 0):.3f}s") + print(f" • Tasks/Second: {report.metrics.get('tasks_per_second', 0):.2f}") + print(f" • Total Output Lines: {report.metrics.get('total_output_lines', 0)}") + + # Resource usage + print(f"\nšŸ’¾ RESOURCE USAGE:") + if report.metrics: + print(f" • Peak Memory: {report.metrics.get('peak_memory_mb', 0):.1f} MB") + print(f" • Average CPU: {report.metrics.get('average_cpu_percent', 0):.1f}%") + + # Task details + print(f"\nšŸ“ TASK DETAILS:") + for i, result in enumerate(report.results, 1): + print(f"\n Task {i}/{len(report.results)}:") + print(f" • ID: {result.get('task_id', 'N/A')}") + print(f" • Agent: {result.get('agent_id', 'N/A')}") + print(f" • Status: {result.get('status', 'N/A')}") + print(f" • Execution Time: {result.get('execution_time', 0):.3f}s") + + # Resource usage for this task + usage = result.get('resource_usage', {}) + if usage: + print(f" • CPU: {usage.get('cpu_percent', 0):.1f}%") + print(f" • Memory: {usage.get('memory_mb', 0):.1f} MB") + + # Output preview + output = result.get('output', {}) + if isinstance(output, dict) and 'lines' in output: + lines = output['lines'] + if lines: + print(f" • Output: {len(lines)} lines") + if len(lines) > 0: + preview = lines[0][:100] + "..." if len(lines[0]) > 100 else lines[0] + print(f" Preview: {preview}") + + # Errors + errors = result.get('errors', []) + if errors: + print(f" • āš ļø Errors: {len(errors)}") + for error in errors[:2]: # Show first 2 errors + print(f" - {error[:80]}...") + + def analyze_trends(self) -> None: + """Analyze trends across multiple benchmarks.""" + if len(self.reports) < 2: + print("Need at least 2 reports for trend analysis") + return + + print("\n" + "="*80) + print("šŸ“ˆ TREND ANALYSIS") + print("="*80) + + # Sort by file modification time + sorted_reports = sorted(self.reports, key=lambda r: r.file_path.stat().st_mtime) + + # Calculate trends + durations = [r.duration for r in sorted_reports] + success_rates = [r.success_rate for r in sorted_reports] + memory_usage = [r.metrics.get('peak_memory_mb', 0) for r in sorted_reports] + + print(f"\nšŸ“Š Performance Trends (last {len(sorted_reports)} runs):") + + # Duration trend + if len(durations) >= 2: + duration_change = ((durations[-1] - durations[0]) / durations[0]) * 100 + print(f" • Duration: {durations[0]:.2f}s → {durations[-1]:.2f}s ({duration_change:+.1f}%)") + + # Success rate trend + if len(success_rates) >= 2: + sr_change = (success_rates[-1] - success_rates[0]) * 100 + print(f" • Success Rate: {success_rates[0]:.1%} → {success_rates[-1]:.1%} ({sr_change:+.1f}pp)") + + # Memory trend + if len(memory_usage) >= 2 and memory_usage[0] > 0: + mem_change = ((memory_usage[-1] - memory_usage[0]) / memory_usage[0]) * 100 + print(f" • Peak Memory: {memory_usage[0]:.1f}MB → {memory_usage[-1]:.1f}MB ({mem_change:+.1f}%)") + + # Best/worst performances + print(f"\nšŸ† Best & Worst:") + best_duration = min(sorted_reports, key=lambda r: r.duration) + worst_duration = max(sorted_reports, key=lambda r: r.duration) + print(f" • Fastest: {best_duration.duration:.2f}s ({best_duration.benchmark_id[:8]}...)") + print(f" • Slowest: {worst_duration.duration:.2f}s ({worst_duration.benchmark_id[:8]}...)") + + best_success = max(sorted_reports, key=lambda r: r.success_rate) + print(f" • Best Success: {best_success.success_rate:.1%} ({best_success.benchmark_id[:8]}...)") + +def main(): + """Main entry point for enhanced report viewer.""" + import argparse + + parser = argparse.ArgumentParser(description="View and analyze Claude Flow benchmark reports") + parser.add_argument("--dir", default="reports", help="Directory containing reports") + parser.add_argument("--id", help="Specific benchmark ID to view") + parser.add_argument("--summary", action="store_true", help="Show summary of all reports") + parser.add_argument("--trends", action="store_true", help="Analyze trends across reports") + parser.add_argument("--latest", action="store_true", help="Show latest report in detail") + + args = parser.parse_args() + + viewer = EnhancedReportViewer(Path(args.dir)) + viewer.load_reports() + + if args.summary or (not args.id and not args.trends and not args.latest): + viewer.display_summary() + + if args.id or args.latest: + viewer.display_detailed_report(args.id) + + if args.trends: + viewer.analyze_trends() + +if __name__ == "__main__": + main() \ No newline at end of file diff --git a/reports/benchmark_5bc58293-0faf-4f16-a1db-f127b86244f1.json b/reports/benchmark_5bc58293-0faf-4f16-a1db-f127b86244f1.json new file mode 100644 index 0000000000..478f7e0420 --- /dev/null +++ b/reports/benchmark_5bc58293-0faf-4f16-a1db-f127b86244f1.json @@ -0,0 +1,38 @@ +{ + "benchmark_id": "5bc58293-0faf-4f16-a1db-f127b86244f1", + "status": "success", + "summary": "Completed 1 tasks", + "duration": 0.304343, + "metrics": { + "wall_clock_time": 1.3054707050323486, + "tasks_per_second": 0.7660072310663001, + "success_rate": 1.0, + "peak_memory_mb": 0.0, + "average_cpu_percent": 0.0, + "total_output_lines": 1 + }, + "results": [ + { + "id": "feef8581-4b3e-44f0-bad1-f7fbf6393f00", + "task_id": "533a9aaa-097d-43e5-a986-27756de932f9", + "agent_id": "claude-flow", + "status": "success", + "output": { + "raw_output": "\u274c Failed to run SPARC mode: Deno is not defined", + "lines": [ + "\u274c Failed to run SPARC mode: Deno is not defined" + ], + "sections": {} + }, + "errors": [], + "warnings": [], + "execution_time": 0.2671480178833008, + "resource_usage": { + "cpu_percent": 92.7, + "memory_mb": 41.415364583333336 + }, + "created_at": "2025-08-06T11:54:50.880247", + "completed_at": "2025-08-06T11:54:50.879782" + } + ] +} \ No newline at end of file diff --git a/reports/metrics_5bc58293-0faf-4f16-a1db-f127b86244f1.json b/reports/metrics_5bc58293-0faf-4f16-a1db-f127b86244f1.json new file mode 100644 index 0000000000..fea3b2b283 --- /dev/null +++ b/reports/metrics_5bc58293-0faf-4f16-a1db-f127b86244f1.json @@ -0,0 +1,66 @@ +{ + "summary": { + "wall_clock_time": 1.3054707050323486, + "tasks_per_second": 0.7660072310663001, + "success_rate": 1.0, + "peak_memory_mb": 0.0, + "average_cpu_percent": 0.0 + }, + "performance": { + "average_duration": 0.0, + "median_duration": 0.0, + "p95_duration": 0.0, + "p99_duration": 0.0, + "total_cpu_seconds": 0.0 + }, + "resources": { + "memory": { + "peak_mb": 0.0, + "average_mb": 0.0 + }, + "cpu": { + "average_percent": 0.0, + "total_seconds": 0.0 + }, + "io": { + "disk_read_mb": 0.0, + "disk_write_mb": 0.0, + "network_sent_mb": 0.0, + "network_recv_mb": 0.0 + } + }, + "processes": { + "total": 1, + "peak_threads": 0, + "peak_fds": 0 + }, + "output": { + "total_size": 1, + "average_size": 1, + "complexity_score": 0.7660072310663001 + }, + "collectors": { + "performance": 1, + "resource": 1 + }, + "timestamp": "2025-08-06T11:54:53.884642", + "process_executions": { + "sparc:{\"positional\": [\"orchestrator\", \"Design hello world in ./hello-bench/\"]}": { + "command_type": "sparc", + "args": { + "positional": [ + "orchestrator", + "Design hello world in ./hello-bench/" + ] + }, + "execution_count": 1, + "success_count": 1, + "failure_count": 0, + "success_rate": 1.0, + "average_duration": 0.3034534454345703, + "total_duration": 0.3034534454345703, + "average_memory_mb": 41.415364583333336, + "peak_memory_mb": 67.6015625 + } + } +} \ No newline at end of file diff --git a/reports/process_report_5bc58293-0faf-4f16-a1db-f127b86244f1.json b/reports/process_report_5bc58293-0faf-4f16-a1db-f127b86244f1.json new file mode 100644 index 0000000000..d7f86cc7bb --- /dev/null +++ b/reports/process_report_5bc58293-0faf-4f16-a1db-f127b86244f1.json @@ -0,0 +1,47 @@ +{ + "summary": { + "total_executions": 1, + "successful_executions": 1, + "failed_executions": 0, + "overall_success_rate": 1.0, + "total_duration": 0.3034534454345703, + "average_duration": 0.3034534454345703, + "peak_memory_mb": 67.6015625, + "average_memory_mb": 41.415364583333336, + "total_output_lines": 1, + "total_errors": 1 + }, + "command_statistics": { + "sparc:{\"positional\": [\"orchestrator\", \"Design hello world in ./hello-bench/\"]}": { + "command_type": "sparc", + "args": { + "positional": [ + "orchestrator", + "Design hello world in ./hello-bench/" + ] + }, + "execution_count": 1, + "success_count": 1, + "failure_count": 0, + "success_rate": 1.0, + "average_duration": 0.3034534454345703, + "total_duration": 0.3034534454345703, + "average_memory_mb": 41.415364583333336, + "peak_memory_mb": 67.6015625 + } + }, + "executions": [ + { + "command": "claude-flow sparc orchestrator Design hello world in ./hello-bench/", + "exit_code": 0, + "success": true, + "duration": 0.3034534454345703, + "start_time": 1754481290.5763288, + "output_size": 1, + "error_count": 1, + "cpu_percent": 92.7, + "memory_mb": 41.415364583333336, + "peak_memory_mb": 67.6015625 + } + ] +} \ No newline at end of file diff --git a/reports/real-benchmark-auto-centralized_5bc58293-0faf-4f16-a1db-f127b86244f1.json b/reports/real-benchmark-auto-centralized_5bc58293-0faf-4f16-a1db-f127b86244f1.json new file mode 100644 index 0000000000..d13d8a7f09 --- /dev/null +++ b/reports/real-benchmark-auto-centralized_5bc58293-0faf-4f16-a1db-f127b86244f1.json @@ -0,0 +1,132 @@ +{ + "id": "5bc58293-0faf-4f16-a1db-f127b86244f1", + "name": "real-benchmark-auto-centralized", + "description": "Real Benchmark: Design hello world in ./hello-bench/", + "status": "completed", + "config": { + "name": "real-benchmark-auto-centralized", + "description": "Real Benchmark: Design hello world in ./hello-bench/", + "strategy": "auto", + "mode": "centralized", + "max_agents": 5, + "max_tasks": 100, + "timeout": 3600, + "task_timeout": 300, + "max_retries": 3, + "parallel": false, + "background": false, + "monitoring": false, + "quality_threshold": 0.8, + "resource_limits": { + "max_memory_mb": 1024, + "max_cpu_percent": 80, + "max_network_mbps": 100 + }, + "output_formats": [ + "json" + ], + "output_directory": "./reports", + "verbose": false + }, + "tasks": [ + { + "id": "533a9aaa-097d-43e5-a986-27756de932f9", + "objective": "Design hello world in ./hello-bench/", + "description": "Benchmark task: Design hello world in ./hello-bench/", + "strategy": "auto", + "mode": "centralized", + "parameters": {}, + "timeout": 300, + "max_retries": 3, + "priority": 1, + "status": "pending", + "created_at": "2025-08-06T11:54:50.575892", + "started_at": null, + "completed_at": null, + "duration": null, + "assigned_agents": [], + "parent_task_id": null, + "subtasks": [], + "dependencies": [] + } + ], + "results": [ + { + "id": "feef8581-4b3e-44f0-bad1-f7fbf6393f00", + "task_id": "533a9aaa-097d-43e5-a986-27756de932f9", + "agent_id": "claude-flow", + "status": "success", + "output": { + "raw_output": "\u274c Failed to run SPARC mode: Deno is not defined", + "lines": [ + "\u274c Failed to run SPARC mode: Deno is not defined" + ], + "sections": {} + }, + "errors": [], + "warnings": [], + "performance_metrics": { + "execution_time": 0.2671480178833008, + "queue_time": 0.0, + "throughput": 3.7432431950022313, + "success_rate": 1.0, + "error_rate": 0.0, + "retry_count": 0, + "coordination_overhead": 0.0, + "communication_latency": 0.0 + }, + "quality_metrics": { + "accuracy_score": 0.0, + "completeness_score": 1.0, + "consistency_score": 0.0, + "relevance_score": 0.0, + "overall_quality": 0.5, + "review_score": null, + "automated_score": null + }, + "resource_usage": { + "cpu_percent": 92.7, + "memory_mb": 41.415364583333336, + "network_bytes_sent": 0, + "network_bytes_recv": 0, + "disk_bytes_read": 0, + "disk_bytes_write": 0, + "peak_memory_mb": 67.6015625, + "average_cpu_percent": 92.7 + }, + "execution_details": { + "command": "claude-flow sparc orchestrator Design hello world in ./hello-bench/", + "exit_code": 0, + "output_lines": 1, + "error_count": 1 + }, + "created_at": "2025-08-06T11:54:50.880247", + "started_at": "2025-08-06T11:54:50.576329", + "completed_at": "2025-08-06T11:54:50.879782", + "duration": 0.303453 + } + ], + "metrics": { + "total_tasks": 1, + "completed_tasks": 1, + "failed_tasks": 0, + "total_agents": 0, + "active_agents": 0, + "average_execution_time": 0.0, + "total_execution_time": 1.3054707050323486, + "success_rate": 1.0, + "throughput": 0.7660072310663001, + "resource_efficiency": 0.0, + "coordination_efficiency": 1.0, + "quality_score": 0.0, + "peak_memory_usage": 0.0, + "total_cpu_time": 0.0, + "network_overhead": 0.0 + }, + "created_at": "2025-08-06T11:54:50.575918", + "started_at": "2025-08-06T11:54:50.575924", + "completed_at": "2025-08-06T11:54:50.880267", + "duration": 0.304343, + "error_log": [], + "metadata": {} +} \ No newline at end of file