#!/bin/bash # Full Trading Cycle Performance Profiling Script # Wave 105 Agent 3 # # This script runs comprehensive performance profiling of the trading cycle: # 1. Compiles benchmarks in release mode # 2. Runs validation tests to get P50/P99/P999 metrics # 3. Runs full benchmarks # 4. Generates flamegraph for bottleneck identification # # Usage: ./scripts/profile_trading_cycle.sh set -euo pipefail SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" PROJECT_ROOT="$(dirname "$SCRIPT_DIR")" cd "$PROJECT_ROOT" echo "===================================================" echo "Full Trading Cycle Performance Profiling" echo "===================================================" echo "" # Step 1: Build benchmark echo "Step 1/4: Building benchmark in release mode..." echo "---------------------------------------------------" cargo build --release --bench full_trading_cycle echo "✓ Build complete" echo "" # Step 2: Run validation tests echo "Step 2/4: Running validation tests (10K iterations)..." echo "---------------------------------------------------" cargo test --release --bench full_trading_cycle -- \ --nocapture \ --test-threads=1 \ validate_full_cycle_latency_targets \ validate_throughput_capacity echo "✓ Validation complete" echo "" # Step 3: Run full benchmarks echo "Step 3/4: Running comprehensive benchmarks..." echo "---------------------------------------------------" cargo bench --bench full_trading_cycle echo "✓ Benchmarks complete" echo "" # Step 4: Generate flamegraph (if flamegraph is installed) echo "Step 4/4: Generating flamegraph..." echo "---------------------------------------------------" if command -v flamegraph &> /dev/null; then echo "Generating flamegraph for full trading cycle..." cargo flamegraph --release --bench full_trading_cycle -- \ --bench validate_full_cycle_latency_targets echo "✓ Flamegraph saved to flamegraph.svg" else echo "⚠️ flamegraph not installed. Install with:" echo " cargo install flamegraph" echo " Skipping flamegraph generation." fi echo "" # Summary echo "===================================================" echo "Profiling Complete!" echo "===================================================" echo "" echo "Results saved to:" echo " - target/criterion/ (benchmark reports)" echo " - flamegraph.svg (if flamegraph installed)" echo "" echo "View benchmark results:" echo " open target/criterion/full_trading_cycle/report/index.html" echo "" echo "Next steps:" echo " 1. Review WAVE105_AGENT3_PERFORMANCE_PROFILE.md" echo " 2. Compare actual measurements to predictions" echo " 3. Identify bottlenecks from flamegraph" echo " 4. Implement HashMap optimization if needed" echo ""