Skip to content

Commit 1f524bf

Browse files
committed
Add profile script
1 parent 74fb97e commit 1f524bf

File tree

1 file changed

+98
-0
lines changed

1 file changed

+98
-0
lines changed

profile_cascade.sh

Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
#!/bin/bash
2+
3+
# Cascade Download Heap Profiling Script
4+
# Samples heap every 30 seconds during cascade downloads
5+
6+
# Configuration - modify these as needed
7+
PROFILE_URL="http://localhost:6062/debug/pprof/heap"
8+
INTERVAL=30
9+
TIMESTAMP=$(date +%Y%m%d_%H%M%S)
10+
PROFILE_DIR="profiles_${TIMESTAMP}"
11+
12+
# Allow override via command line
13+
if [ "$1" != "" ]; then
14+
PROFILE_URL="$1"
15+
fi
16+
17+
echo "=== Cascade Heap Profiling ==="
18+
echo "Profile URL: $PROFILE_URL"
19+
echo "Interval: ${INTERVAL}s"
20+
echo "Output Dir: $PROFILE_DIR"
21+
echo
22+
23+
# Create profile directory
24+
mkdir -p "$PROFILE_DIR"
25+
cd "$PROFILE_DIR"
26+
27+
# Test connection first
28+
echo "Testing connection to profiling server..."
29+
if ! curl -s --fail "$PROFILE_URL" > /dev/null; then
30+
echo "ERROR: Cannot connect to profiling server at $PROFILE_URL"
31+
echo "Make sure your supernode is running on testnet!"
32+
exit 1
33+
fi
34+
35+
echo "✓ Connected to profiling server"
36+
echo
37+
38+
# Take baseline
39+
echo "Taking baseline heap snapshot..."
40+
curl -s -o "heap_00s.prof" "$PROFILE_URL"
41+
echo "✓ Baseline saved: heap_00s.prof"
42+
echo
43+
44+
echo "*** NOW START YOUR CASCADE DOWNLOAD ***"
45+
echo "Press ENTER when download has started..."
46+
read
47+
48+
echo "Starting heap profiling every ${INTERVAL}s..."
49+
echo "Press Ctrl+C to stop"
50+
echo
51+
52+
# Counter for snapshots
53+
counter=1
54+
55+
# Function to handle cleanup on exit
56+
cleanup() {
57+
echo
58+
echo "Profiling stopped. Taking final snapshot..."
59+
final_elapsed=$((counter * INTERVAL))
60+
curl -s -o "heap_${final_elapsed}s_final.prof" "$PROFILE_URL"
61+
62+
echo
63+
echo "=== Profiling Complete ==="
64+
echo "Location: $(pwd)"
65+
echo "Files created:"
66+
ls -la *.prof
67+
echo
68+
echo "Analysis commands:"
69+
echo "# Compare baseline to final:"
70+
echo "go tool pprof -http=:8080 -base heap_00s.prof heap_${final_elapsed}s_final.prof"
71+
exit 0
72+
}
73+
74+
# Set up signal handler
75+
trap cleanup INT TERM
76+
77+
# Main profiling loop
78+
while true; do
79+
sleep $INTERVAL
80+
81+
elapsed=$((counter * INTERVAL))
82+
minutes=$((elapsed / 60))
83+
seconds=$((elapsed % 60))
84+
85+
timestamp=$(date +%H:%M:%S)
86+
filename="heap_${elapsed}s.prof"
87+
88+
echo "[$timestamp] Taking snapshot $counter (${minutes}m ${seconds}s elapsed)..."
89+
90+
if curl -s -o "$filename" "$PROFILE_URL"; then
91+
size=$(ls -lh "$filename" | awk '{print $5}')
92+
echo "✓ Saved: $filename ($size)"
93+
else
94+
echo "✗ Failed to get snapshot $counter"
95+
fi
96+
97+
((counter++))
98+
done

0 commit comments

Comments
 (0)