#!/usr/bin/env bash
set -euo pipefail

# Panasyn profiling script
# Builds with profiling instrumentation and runs the terminal.

SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
PROJECT_ROOT="$SCRIPT_DIR/.."
cd "$PROJECT_ROOT"

echo "==> Building Panasyn with profiling support..."
PROFILE=1 cargo build --release 2>&1

echo "==> Running Panasyn under Instruments (macOS)..."
echo "    Use DTrace or Xcode Instruments to attach."
echo "    For quick CPU sampling:"
echo "        sudo sample target/release/panasyn 10000"
echo ""
echo "    For Instruments:"
echo "        xcrun xctrace record --template 'Time Profiler' --launch target/release/panasyn"
