This commit is contained in:
2026-02-07 09:23:49 +00:00
parent 96eabe3db6
commit 36552903e7
85 changed files with 9820870 additions and 1767 deletions

91
collect_performance_data.sh Executable file
View File

@@ -0,0 +1,91 @@
#!/bin/bash
# Script to collect performance data for Motia Calendar Sync degradation analysis
# Run this script to start monitoring, simulate load, and collect logs
echo "Starting performance data collection for Motia Calendar Sync..."
# Create log directory
LOG_DIR="/opt/motia-app/performance_logs_$(date +%Y%m%d_%H%M%S)"
mkdir -p "$LOG_DIR"
echo "Logs will be saved to: $LOG_DIR"
# 1. Start system monitoring (top)
echo "Starting top monitoring..."
MAIN_PID=$(pgrep -f "node.*motia" | head -1)
if [ -z "$MAIN_PID" ]; then
echo "No motia node process found, skipping top monitoring"
else
top -b -d 5 -p $MAIN_PID > "$LOG_DIR/top_log.txt" &
TOP_PID=$!
echo "Top PID: $TOP_PID (monitoring Node process $MAIN_PID)"
fi
# 2. Start Redis monitoring
echo "Starting Redis monitoring..."
redis-cli MONITOR > "$LOG_DIR/redis_log.txt" &
REDIS_PID=$!
echo "Redis monitor PID: $REDIS_PID"
# 3. Start journalctl logging
echo "Starting journalctl logging..."
journalctl -u motia -f > "$LOG_DIR/motia_journal.log" &
JOURNAL_PID=$!
echo "Journalctl PID: $JOURNAL_PID"
# 4. Start Clinic.js profiling (Node.js runtime)
echo "Starting Clinic.js Doctor for Node.js profiling..."
cd /opt/motia-app/bitbylaw
clinic doctor -- node node_modules/.bin/motia start --host 0.0.0.0 > "$LOG_DIR/clinic_output.log" 2>&1 &
CLINIC_PID=$!
echo "Clinic PID: $CLINIC_PID"
cd /opt/motia-app
# 5. Python profiling is enabled in the event step (generates profile.pstats and yappi.stats)
# 6. Wait for cron to run (assuming it runs every 1 minute)
echo "Waiting for cron jobs to run and generate data (60 minutes for long-term degradation)..."
sleep 3600 # Wait 60 minutes for cron cycles
# 6. Take heap snapshots periodically
echo "Taking heap snapshots every 15 minutes..."
for i in {1..4}; do
kill -USR2 $MAIN_PID 2>/dev/null || echo "Failed to trigger heap snapshot $i"
sleep 5
cp *.heapsnapshot "$LOG_DIR/heap_snapshot_$i.heapsnapshot" 2>/dev/null || echo "No heap snapshot $i found"
if [ $i -lt 4 ]; then
sleep 900 # 15 minutes
fi
done
# 7. Stop monitoring tools
echo "Stopping monitoring tools..."
kill $TOP_PID
kill $REDIS_PID
kill $JOURNAL_PID
kill $CLINIC_PID
# 8. Collect profiling data (if generated)
echo "Collecting profiling data..."
cp /opt/motia-app/profile.pstats /opt/motia-app/yappi.stats "$LOG_DIR/" 2>/dev/null || echo "No profiling data found"
# 9. Generate summary
echo "Generating summary..."
echo "Performance Data Collection Complete" > "$LOG_DIR/summary.txt"
echo "Duration: $(date)" >> "$LOG_DIR/summary.txt"
echo "Top log size: $(stat -c%s "$LOG_DIR/top_log.txt" 2>/dev/null || echo "N/A") bytes" >> "$LOG_DIR/summary.txt"
echo "Redis log size: $(stat -c%s "$LOG_DIR/redis_log.txt" 2>/dev/null || echo "N/A") bytes" >> "$LOG_DIR/summary.txt"
echo "Journal log size: $(stat -c%s "$LOG_DIR/motia_journal.log" 2>/dev/null || echo "N/A") bytes" >> "$LOG_DIR/summary.txt"
echo "Clinic output size: $(stat -c%s "$LOG_DIR/clinic_output.log" 2>/dev/null || echo "N/A") bytes" >> "$LOG_DIR/summary.txt"
echo "Heap snapshots: $(ls "$LOG_DIR"/heap_snapshot_*.heapsnapshot 2>/dev/null | wc -l)" >> "$LOG_DIR/summary.txt"
echo "Collection complete. Logs saved to $LOG_DIR"
echo "Next steps:"
echo "1. Analyze top_log.txt for CPU/memory trends"
echo "2. Check redis_log.txt for Redis activity"
echo "3. Review motia_journal.log for timings and errors"
echo "4. Open clinic-doctor-*.html for Node.js profiling (Event Loop Delay, etc.)"
echo "5. Use Chrome DevTools to analyze heap snapshots"
echo "6. Run 'snakeviz profile.pstats' for Python CPU profiling"
echo "7. Run 'yappi -f pstat yappi.stats' for Python async profiling"