#!/bin/bash # Horus Stack Benchmark Runner # This script ensures the Horus stack is running before executing benchmarks set -e SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" PROJECT_ROOT="$(dirname "$SCRIPT_DIR")" # Colors for output RED='\033[0;31m' GREEN='\033[0;32m' YELLOW='\033[1;33m' NC='\033[0m' # No Color # Configuration SUPERVISOR_URL="http://127.0.0.1:3030" OSIRIS_URL="http://127.0.0.1:8081" REDIS_URL="127.0.0.1:6379" echo -e "${GREEN}=== Horus Stack Benchmark Runner ===${NC}\n" # Function to check if a service is running check_service() { local url=$1 local name=$2 if curl -s -f "$url/health" > /dev/null 2>&1 || curl -s -f "$url" > /dev/null 2>&1; then echo -e "${GREEN}✓${NC} $name is running" return 0 else echo -e "${RED}✗${NC} $name is not running" return 1 fi } # Function to check if Redis is running check_redis() { if redis-cli -h 127.0.0.1 -p 6379 ping > /dev/null 2>&1; then echo -e "${GREEN}✓${NC} Redis is running" return 0 else echo -e "${RED}✗${NC} Redis is not running" return 1 fi } # Check prerequisites echo "Checking prerequisites..." echo "" REDIS_OK=false OSIRIS_OK=false SUPERVISOR_OK=false if check_redis; then REDIS_OK=true fi if check_service "$OSIRIS_URL" "Osiris"; then OSIRIS_OK=true fi if check_service "$SUPERVISOR_URL" "Supervisor"; then SUPERVISOR_OK=true fi echo "" # If any service is not running, provide instructions if [ "$REDIS_OK" = false ] || [ "$OSIRIS_OK" = false ] || [ "$SUPERVISOR_OK" = false ]; then echo -e "${YELLOW}Some services are not running. Please start the Horus stack:${NC}" echo "" if [ "$REDIS_OK" = false ]; then echo " 1. Start Redis:" echo " redis-server" echo "" fi echo " 2. Start Horus stack:" echo " cd $PROJECT_ROOT" echo " RUST_LOG=info ./target/release/horus all --admin-secret SECRET --kill-ports" echo "" echo " Or run in the background:" echo " RUST_LOG=info ./target/release/horus all --admin-secret SECRET --kill-ports &" echo "" read -p "Do you want to continue anyway? (y/N) " -n 1 -r echo if [[ ! $REPLY =~ ^[Yy]$ ]]; then echo -e "${RED}Benchmark cancelled.${NC}" exit 1 fi fi # Build the project first echo -e "${GREEN}Building project...${NC}" cd "$PROJECT_ROOT" cargo build --release echo "" echo -e "${GREEN}Running benchmarks...${NC}" echo "" # Run benchmarks with any additional arguments passed to this script cargo bench --bench horus_stack "$@" echo "" echo -e "${GREEN}=== Benchmark Complete ===${NC}" echo "" echo "Results saved to: target/criterion/" echo "View HTML reports: open target/criterion/report/index.html"