From 1f524bf39752989de190659c25116ef129a52bd5 Mon Sep 17 00:00:00 2001 From: j-rafique Date: Wed, 24 Sep 2025 18:37:05 +0500 Subject: [PATCH] Add profile script --- profile_cascade.sh | 98 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 98 insertions(+) create mode 100755 profile_cascade.sh diff --git a/profile_cascade.sh b/profile_cascade.sh new file mode 100755 index 00000000..7fe0af5e --- /dev/null +++ b/profile_cascade.sh @@ -0,0 +1,98 @@ +#!/bin/bash + +# Cascade Download Heap Profiling Script +# Samples heap every 30 seconds during cascade downloads + +# Configuration - modify these as needed +PROFILE_URL="http://localhost:6062/debug/pprof/heap" +INTERVAL=30 +TIMESTAMP=$(date +%Y%m%d_%H%M%S) +PROFILE_DIR="profiles_${TIMESTAMP}" + +# Allow override via command line +if [ "$1" != "" ]; then + PROFILE_URL="$1" +fi + +echo "=== Cascade Heap Profiling ===" +echo "Profile URL: $PROFILE_URL" +echo "Interval: ${INTERVAL}s" +echo "Output Dir: $PROFILE_DIR" +echo + +# Create profile directory +mkdir -p "$PROFILE_DIR" +cd "$PROFILE_DIR" + +# Test connection first +echo "Testing connection to profiling server..." +if ! curl -s --fail "$PROFILE_URL" > /dev/null; then + echo "ERROR: Cannot connect to profiling server at $PROFILE_URL" + echo "Make sure your supernode is running on testnet!" + exit 1 +fi + +echo "✓ Connected to profiling server" +echo + +# Take baseline +echo "Taking baseline heap snapshot..." +curl -s -o "heap_00s.prof" "$PROFILE_URL" +echo "✓ Baseline saved: heap_00s.prof" +echo + +echo "*** NOW START YOUR CASCADE DOWNLOAD ***" +echo "Press ENTER when download has started..." +read + +echo "Starting heap profiling every ${INTERVAL}s..." +echo "Press Ctrl+C to stop" +echo + +# Counter for snapshots +counter=1 + +# Function to handle cleanup on exit +cleanup() { + echo + echo "Profiling stopped. Taking final snapshot..." + final_elapsed=$((counter * INTERVAL)) + curl -s -o "heap_${final_elapsed}s_final.prof" "$PROFILE_URL" + + echo + echo "=== Profiling Complete ===" + echo "Location: $(pwd)" + echo "Files created:" + ls -la *.prof + echo + echo "Analysis commands:" + echo "# Compare baseline to final:" + echo "go tool pprof -http=:8080 -base heap_00s.prof heap_${final_elapsed}s_final.prof" + exit 0 +} + +# Set up signal handler +trap cleanup INT TERM + +# Main profiling loop +while true; do + sleep $INTERVAL + + elapsed=$((counter * INTERVAL)) + minutes=$((elapsed / 60)) + seconds=$((elapsed % 60)) + + timestamp=$(date +%H:%M:%S) + filename="heap_${elapsed}s.prof" + + echo "[$timestamp] Taking snapshot $counter (${minutes}m ${seconds}s elapsed)..." + + if curl -s -o "$filename" "$PROFILE_URL"; then + size=$(ls -lh "$filename" | awk '{print $5}') + echo "✓ Saved: $filename ($size)" + else + echo "✗ Failed to get snapshot $counter" + fi + + ((counter++)) +done \ No newline at end of file