fetch_ml/scripts/track_performance.sh

64 lines
2.4 KiB
Bash
Executable file

#!/bin/bash
# Simple performance tracking script
RESULTS_DIR="test_results/performance"
TIMESTAMP=$(date +"%Y%m%d_%H%M%S")
RESULTS_FILE="$RESULTS_DIR/load_test_$TIMESTAMP.json"
mkdir -p "$RESULTS_DIR"
echo "Running load test performance tracking..."
echo "Timestamp: $TIMESTAMP"
# Run tests and capture results
go test ./tests/load -run=TestLoadTestSuite -v -load-suite=medium -timeout=10m > "$RESULTS_DIR/raw_$TIMESTAMP.log"
# Extract key metrics
{
echo "{"
echo " \"timestamp\": \"$TIMESTAMP\","
echo " \"tests\": ["
# Parse light load
LIGHT_RPS=$(grep -A1 "LightLoad" "$RESULTS_DIR/raw_$TIMESTAMP.log" | grep "Throughput" | awk '{print $2}')
LIGHT_ERROR=$(grep -A2 "LightLoad" "$RESULTS_DIR/raw_$TIMESTAMP.log" | grep "Error rate" | awk '{print $3}')
LIGHT_P99=$(grep -A4 "LightLoad" "$RESULTS_DIR/raw_$TIMESTAMP.log" | grep "P99 latency" | awk '{print $3}')
echo " {"
echo " \"name\": \"LightLoad\","
echo " \"throughput_rps\": $LIGHT_RPS,"
echo " \"error_rate_percent\": $LIGHT_ERROR,"
echo " \"p99_latency_ms\": \"$LIGHT_P99\""
echo " },"
# Parse medium load
MEDIUM_RPS=$(grep -A1 "MediumLoad" "$RESULTS_DIR/raw_$TIMESTAMP.log" | grep "Throughput" | awk '{print $2}')
MEDIUM_ERROR=$(grep -A2 "MediumLoad" "$RESULTS_DIR/raw_$TIMESTAMP.log" | grep "Error rate" | awk '{print $3}')
MEDIUM_P99=$(grep -A4 "MediumLoad" "$RESULTS_DIR/raw_$TIMESTAMP.log" | grep "P99 latency" | awk '{print $3}')
echo " {"
echo " \"name\": \"MediumLoad\","
echo " \"throughput_rps\": $MEDIUM_RPS,"
echo " \"error_rate_percent\": $MEDIUM_ERROR,"
echo " \"p99_latency_ms\": \"$MEDIUM_P99\""
echo " }"
echo " ]"
echo "}"
} > "$RESULTS_FILE"
echo "Results saved to: $RESULTS_FILE"
echo "Raw logs: $RESULTS_DIR/raw_$TIMESTAMP.log"
# Show comparison with previous run if exists
PREV_FILE=$(ls -t "$RESULTS_DIR"/load_test_*.json | sed -n '2p')
if [ -n "$PREV_FILE" ]; then
echo ""
echo "=== Comparison with previous run ==="
echo "Previous: $(basename $PREV_FILE)"
echo "Current: $(basename $RESULTS_FILE)"
echo ""
echo "Light Load Throughput:"
echo " Previous: $(jq -r '.tests[0].throughput_rps' "$PREV_FILE") RPS"
echo " Current: $(jq -r '.tests[0].throughput_rps' "$RESULTS_FILE") RPS"
echo " Change: $(echo "$(jq -r '.tests[0].throughput_rps' "$RESULTS_FILE") - $(jq -r '.tests[0].throughput_rps' "$PREV_FILE")" | bc -l) RPS"
fi