From b59bb349dc63bd3b52b8a875af1709d888c0ef86 Mon Sep 17 00:00:00 2001 From: Ivan Date: Sat, 27 Sep 2025 05:44:47 -0500 Subject: [PATCH] add basic performance monitoring action --- .github/workflows/performance-monitor.yml | 41 ++++++++ tests/scripts/monitor_performance.sh | 113 ++++++++++++++++++++++ 2 files changed, 154 insertions(+) create mode 100644 .github/workflows/performance-monitor.yml create mode 100644 tests/scripts/monitor_performance.sh diff --git a/.github/workflows/performance-monitor.yml b/.github/workflows/performance-monitor.yml new file mode 100644 index 0000000..10a1f39 --- /dev/null +++ b/.github/workflows/performance-monitor.yml @@ -0,0 +1,41 @@ +name: Performance Monitor + +on: + push: + branches: [ main ] + pull_request: + branches: [ main ] + workflow_dispatch: + +jobs: + performance-monitor: + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v5 + + - name: Set up Go + uses: actions/setup-go@v4 + with: + go-version: '1.25' + + - name: Cache Go modules + uses: actions/cache@v3 + with: + path: | + ~/go/pkg/mod + ~/.cache/go-build + key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }} + restore-keys: | + ${{ runner.os }}-go- + + - name: Build + run: | + go build -o bin/reticulum-go ./cmd/reticulum-go + + - name: Run Performance Monitor + id: monitor + run: | + cp tests/scripts/monitor_performance.sh . + chmod +x monitor_performance.sh + ./monitor_performance.sh \ No newline at end of file diff --git a/tests/scripts/monitor_performance.sh b/tests/scripts/monitor_performance.sh new file mode 100644 index 0000000..9ef845f --- /dev/null +++ b/tests/scripts/monitor_performance.sh @@ -0,0 +1,113 @@ +#!/bin/bash +set -e + +echo "Starting Reticulum-Go with memory and CPU monitoring..." + +# Start the process in background +./bin/reticulum-go & +PID=$! + +echo "Process started with PID: $PID" + +# Initialize tracking variables +MAX_RSS=0 +MAX_VSZ=0 +MAX_CPU=0 +SAMPLES=0 +TOTAL_RSS=0 +TOTAL_VSZ=0 +TOTAL_CPU=0 + +END_TIME=$((SECONDS + 40)) + +while [ $SECONDS -lt $END_TIME ] && kill -0 $PID 2>/dev/null; do + # Get memory and CPU info using ps + if PROC_INFO=$(ps -o pid,rss,vsz,pcpu --no-headers -p $PID 2>/dev/null); then + RSS=$(echo $PROC_INFO | awk '{print $2}') # RSS in KB + VSZ=$(echo $PROC_INFO | awk '{print $3}') # VSZ in KB + CPU=$(echo $PROC_INFO | awk '{print $4}') # CPU percentage + + if [ -n "$RSS" ] && [ -n "$VSZ" ] && [ -n "$CPU" ]; then + SAMPLES=$((SAMPLES + 1)) + TOTAL_RSS=$((TOTAL_RSS + RSS)) + TOTAL_VSZ=$((TOTAL_VSZ + VSZ)) + TOTAL_CPU=$((TOTAL_CPU + CPU)) + + if [ $RSS -gt $MAX_RSS ]; then + MAX_RSS=$RSS + fi + + if [ $VSZ -gt $MAX_VSZ ]; then + MAX_VSZ=$VSZ + fi + + # CPU is already a percentage (0-100), so compare as integers + CPU_INT=$(echo $CPU | cut -d. -f1) + if [ $CPU_INT -gt $MAX_CPU ]; then + MAX_CPU=$CPU_INT + fi + fi + fi + + sleep 0.1 # Sample every 100ms +done + +# Stop the process if still running +if kill -0 $PID 2>/dev/null; then + echo "Stopping process..." + kill $PID 2>/dev/null || true + sleep 1 + kill -9 $PID 2>/dev/null || true +fi + +# Calculate averages +if [ $SAMPLES -gt 0 ]; then + AVG_RSS=$((TOTAL_RSS / SAMPLES)) + AVG_VSZ=$((TOTAL_VSZ / SAMPLES)) + AVG_CPU=$((TOTAL_CPU / SAMPLES)) +else + AVG_RSS=0 + AVG_VSZ=0 + AVG_CPU=0 +fi + +# Convert to MB and GB +MAX_RSS_MB=$((MAX_RSS / 1024)) +MAX_RSS_GB=$((MAX_RSS_MB / 1024)) +AVG_RSS_MB=$((AVG_RSS / 1024)) +AVG_RSS_GB=$((AVG_RSS_MB / 1024)) + +MAX_VSZ_MB=$((MAX_VSZ / 1024)) +MAX_VSZ_GB=$((MAX_VSZ_MB / 1024)) +AVG_VSZ_MB=$((AVG_VSZ / 1024)) +AVG_VSZ_GB=$((AVG_VSZ_MB / 1024)) + +# Output results +echo "=== Performance Usage Report ===" +echo "Monitoring duration: 40 seconds" +echo "Samples collected: $SAMPLES" +echo "" + +echo "## CPU Usage - Processor Utilization (since process start)" +echo "- Max CPU: ${MAX_CPU}%" +echo "- Avg CPU: ${AVG_CPU}%" +echo "- Note: Low CPU usage is normal for I/O-bound network applications" +echo "" + +echo "## RSS (Resident Set Size) - Actual Memory Used" +echo "- Max RSS: ${MAX_RSS} KB (${MAX_RSS_MB} MB / ${MAX_RSS_GB} GB)" +echo "- Avg RSS: ${AVG_RSS} KB (${AVG_RSS_MB} MB / ${AVG_RSS_GB} GB)" +echo "" + +echo "## VSZ (Virtual Memory Size) - Total Virtual Memory" +echo "- Max VSZ: ${MAX_VSZ} KB (${MAX_VSZ_MB} MB / ${MAX_VSZ_GB} GB)" +echo "- Avg VSZ: ${AVG_VSZ} KB (${AVG_VSZ_MB} MB / ${AVG_VSZ_GB} GB)" +echo "" + +# Output for potential future use +echo "MAX_CPU=$MAX_CPU" >> $GITHUB_OUTPUT +echo "AVG_CPU=$AVG_CPU" >> $GITHUB_OUTPUT +echo "MAX_RSS_MB=$MAX_RSS_MB" >> $GITHUB_OUTPUT +echo "AVG_RSS_MB=$AVG_RSS_MB" >> $GITHUB_OUTPUT +echo "MAX_VSZ_MB=$MAX_VSZ_MB" >> $GITHUB_OUTPUT +echo "AVG_VSZ_MB=$AVG_VSZ_MB" >> $GITHUB_OUTPUT