#!/bin/bash # Performance Testing Script for debian-forge # This script tests build performance and generates benchmarks set -e echo "๐Ÿš€ Debian Forge Performance Testing" echo "====================================" # Configuration TEST_DIR="./performance-tests" RESULTS_DIR="./performance-results" MANIFESTS_DIR="./test/data/manifests/debian" # Create directories mkdir -p "$TEST_DIR" "$RESULTS_DIR" # Test configurations declare -A TESTS=( ["debian-minimal"]="debian-trixie-minimal.json" ["ubuntu-server"]="ubuntu-jammy-server.json" ["debian-atomic"]="debian-atomic-container.json" ["debian-arm64"]="debian-trixie-arm64.json" ) # Performance metrics declare -A BUILD_TIMES declare -A PACKAGE_COUNTS declare -A IMAGE_SIZES echo "" echo "๐Ÿ“Š Running Performance Tests..." echo "===============================" for test_name in "${!TESTS[@]}"; do manifest="${TESTS[$test_name]}" manifest_path="$MANIFESTS_DIR/$manifest" if [ ! -f "$manifest_path" ]; then echo "โŒ Manifest not found: $manifest_path" continue fi echo "" echo "๐Ÿงช Testing: $test_name ($manifest)" echo "-----------------------------------" # Clean previous build rm -rf "$TEST_DIR/$test_name" mkdir -p "$TEST_DIR/$test_name" # Start timing start_time=$(date +%s.%N) # Run build echo "โฑ๏ธ Starting build..." if python3 -m osbuild "$manifest_path" --output-dir "$TEST_DIR/$test_name" --libdir . --json > "$RESULTS_DIR/${test_name}_build.json" 2>&1; then end_time=$(date +%s.%N) build_time=$(echo "$end_time - $start_time" | bc -l) BUILD_TIMES[$test_name]=$build_time echo "โœ… Build completed in $(printf "%.2f" $build_time) seconds" # Extract package count from build log package_count=$(grep -o '"packages":\[[^]]*\]' "$RESULTS_DIR/${test_name}_build.json" | wc -l || echo "0") PACKAGE_COUNTS[$test_name]=$package_count # Calculate image size (if output exists) if [ -d "$TEST_DIR/$test_name" ]; then image_size=$(du -sh "$TEST_DIR/$test_name" 2>/dev/null | cut -f1 || echo "0B") IMAGE_SIZES[$test_name]=$image_size else IMAGE_SIZES[$test_name]="0B" fi echo "๐Ÿ“ฆ Packages: $package_count" echo "๐Ÿ’พ Size: ${IMAGE_SIZES[$test_name]}" else echo "โŒ Build failed for $test_name" BUILD_TIMES[$test_name]="FAILED" PACKAGE_COUNTS[$test_name]="0" IMAGE_SIZES[$test_name]="0B" fi done echo "" echo "๐Ÿ“ˆ Performance Summary" echo "======================" # Create performance report cat > "$RESULTS_DIR/performance-report.md" << EOF # Debian Forge Performance Report Generated: $(date) ## Build Times | Test Case | Build Time | Status | |-----------|------------|--------| EOF for test_name in "${!TESTS[@]}"; do build_time="${BUILD_TIMES[$test_name]}" if [ "$build_time" = "FAILED" ]; then status="โŒ FAILED" time_display="N/A" else status="โœ… SUCCESS" time_display="$(printf "%.2f" $build_time)s" fi echo "| $test_name | $time_display | $status |" >> "$RESULTS_DIR/performance-report.md" done cat >> "$RESULTS_DIR/performance-report.md" << EOF ## Package Counts | Test Case | Package Count | |-----------|---------------| EOF for test_name in "${!TESTS[@]}"; do package_count="${PACKAGE_COUNTS[$test_name]}" echo "| $test_name | $package_count |" >> "$RESULTS_DIR/performance-report.md" done cat >> "$RESULTS_DIR/performance-report.md" << EOF ## Image Sizes | Test Case | Size | |-----------|------| EOF for test_name in "${!TESTS[@]}"; do image_size="${IMAGE_SIZES[$test_name]}" echo "| $test_name | $image_size |" >> "$RESULTS_DIR/performance-report.md" done cat >> "$RESULTS_DIR/performance-report.md" << EOF ## Performance Analysis ### Fastest Build EOF # Find fastest build fastest_time=999999 fastest_test="" for test_name in "${!TESTS[@]}"; do build_time="${BUILD_TIMES[$test_name]}" if [ "$build_time" != "FAILED" ]; then if (( $(echo "$build_time < $fastest_time" | bc -l) )); then fastest_time=$build_time fastest_test=$test_name fi fi done if [ -n "$fastest_test" ]; then echo "- **$fastest_test**: $(printf "%.2f" $fastest_time)s" >> "$RESULTS_DIR/performance-report.md" else echo "- No successful builds" >> "$RESULTS_DIR/performance-report.md" fi cat >> "$RESULTS_DIR/performance-report.md" << EOF ### Slowest Build EOF # Find slowest build slowest_time=0 slowest_test="" for test_name in "${!TESTS[@]}"; do build_time="${BUILD_TIMES[$test_name]}" if [ "$build_time" != "FAILED" ]; then if (( $(echo "$build_time > $slowest_time" | bc -l) )); then slowest_time=$build_time slowest_test=$test_name fi fi done if [ -n "$slowest_test" ]; then echo "- **$slowest_test**: $(printf "%.2f" $slowest_time)s" >> "$RESULTS_DIR/performance-report.md" else echo "- No successful builds" >> "$RESULTS_DIR/performance-report.md" fi cat >> "$RESULTS_DIR/performance-report.md" << EOF ## Recommendations 1. **Use apt-cacher-ng** for 2-3x faster builds 2. **Minimize package count** for faster builds 3. **Use minimal base images** when possible 4. **Monitor build times** regularly 5. **Optimize manifest structure** for better performance ## Next Steps 1. Implement apt-cacher-ng integration 2. Add parallel build support 3. Optimize package installation 4. Add build caching 5. Monitor memory usage EOF echo "" echo "๐Ÿ“Š Performance Report Generated" echo "===============================" echo "๐Ÿ“„ Report: $RESULTS_DIR/performance-report.md" echo "๐Ÿ“ Results: $RESULTS_DIR/" echo "๐Ÿงช Test Data: $TEST_DIR/" echo "" echo "๐ŸŽฏ Performance Summary:" echo "=======================" for test_name in "${!TESTS[@]}"; do build_time="${BUILD_TIMES[$test_name]}" package_count="${PACKAGE_COUNTS[$test_name]}" image_size="${IMAGE_SIZES[$test_name]}" if [ "$build_time" = "FAILED" ]; then echo "โŒ $test_name: FAILED" else echo "โœ… $test_name: $(printf "%.2f" $build_time)s | $package_count packages | $image_size" fi done echo "" echo "๐Ÿš€ Performance testing completed!"