-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprofile_cascade.sh
More file actions
executable file
·98 lines (78 loc) · 2.34 KB
/
profile_cascade.sh
File metadata and controls
executable file
·98 lines (78 loc) · 2.34 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
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:8002/api/v1/debug/raw/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