Merge branch 'master' of https://github.com/run-as-root/magento2-prom⦠#9
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Performance Monitoring | |
| on: | |
| push: | |
| branches: [master, develop] | |
| pull_request: | |
| branches: [master, develop] | |
| schedule: | |
| # Run performance tests weekly on Sundays at 3 AM UTC | |
| - cron: "0 3 * * 0" | |
| workflow_dispatch: | |
| jobs: | |
| syntax-performance: | |
| name: PHP Syntax Performance | |
| runs-on: ubuntu-latest | |
| strategy: | |
| matrix: | |
| php-version: ["7.4", "8.0", "8.1", "8.2"] | |
| steps: | |
| - name: Checkout | |
| uses: actions/checkout@v4 | |
| - name: Setup PHP ${{ matrix.php-version }} | |
| uses: shivammathur/setup-php@v2 | |
| with: | |
| php-version: ${{ matrix.php-version }} | |
| - name: Check PHP syntax performance | |
| run: | | |
| echo "## π PHP Syntax Performance - PHP ${{ matrix.php-version }}" >> $GITHUB_STEP_SUMMARY | |
| echo "" >> $GITHUB_STEP_SUMMARY | |
| # Count total PHP files | |
| TOTAL_FILES=$(find src/ lib/ -name "*.php" | wc -l) | |
| echo "π Total PHP files: $TOTAL_FILES" >> $GITHUB_STEP_SUMMARY | |
| # Time syntax checking | |
| START_TIME=$(date +%s) | |
| find src/ lib/ -name "*.php" -exec php -l {} \; > /dev/null | |
| END_TIME=$(date +%s) | |
| DURATION=$((END_TIME - START_TIME)) | |
| echo "β±οΈ Syntax check time: ${DURATION}s" >> $GITHUB_STEP_SUMMARY | |
| if [ $TOTAL_FILES -gt 0 ]; then | |
| AVG_TIME=$(awk "BEGIN {printf \"%.4f\", $DURATION / $TOTAL_FILES}") | |
| echo "π Average per file: ${AVG_TIME}s" >> $GITHUB_STEP_SUMMARY | |
| fi | |
| code-complexity: | |
| name: Code Complexity Analysis | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout | |
| uses: actions/checkout@v4 | |
| - name: Setup PHP | |
| uses: shivammathur/setup-php@v2 | |
| with: | |
| php-version: "8.1" | |
| - name: Install PHPLOC | |
| run: | | |
| composer global require phploc/phploc || true | |
| continue-on-error: true | |
| - name: Analyze code complexity | |
| run: | | |
| echo "## π Code Complexity Analysis" >> $GITHUB_STEP_SUMMARY | |
| echo "" >> $GITHUB_STEP_SUMMARY | |
| echo "### Code Metrics" >> $GITHUB_STEP_SUMMARY | |
| echo '```' >> $GITHUB_STEP_SUMMARY | |
| if [ -f ~/.composer/vendor/bin/phploc ]; then | |
| ~/.composer/vendor/bin/phploc src/ lib/ --exclude=Test 2>/dev/null || echo "PHPLOC analysis completed" | |
| else | |
| echo "PHPLOC not available - install with: composer global require phploc/phploc" | |
| fi | |
| echo '```' >> $GITHUB_STEP_SUMMARY | |
| memory-usage-analysis: | |
| name: Memory Usage Analysis | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout | |
| uses: actions/checkout@v4 | |
| - name: Setup PHP | |
| uses: shivammathur/setup-php@v2 | |
| with: | |
| php-version: "8.1" | |
| ini-values: memory_limit=256M | |
| - name: Analyze memory usage patterns | |
| run: | | |
| echo "## π§ Memory Usage Analysis" >> $GITHUB_STEP_SUMMARY | |
| echo "" >> $GITHUB_STEP_SUMMARY | |
| # Create a simple memory test script | |
| cat > memory_test.php << 'EOF' | |
| <?php | |
| $memory_start = memory_get_usage(true); | |
| $peak_start = memory_get_peak_usage(true); | |
| // Simulate loading class files | |
| $classes = []; | |
| $files = glob('src/**/*.php') ?: []; | |
| $files = array_merge($files, glob('lib/**/*.php') ?: []); | |
| foreach (array_slice($files, 0, 10) as $file) { | |
| if (is_readable($file)) { | |
| $content = file_get_contents($file); | |
| $classes[] = strlen($content); | |
| } | |
| } | |
| $memory_after = memory_get_usage(true); | |
| $peak_after = memory_get_peak_usage(true); | |
| echo "Memory start: " . round($memory_start / 1024 / 1024, 2) . " MB\n"; | |
| echo "Memory after loading: " . round($memory_after / 1024 / 1024, 2) . " MB\n"; | |
| echo "Peak memory: " . round($peak_after / 1024 / 1024, 2) . " MB\n"; | |
| echo "Memory increase: " . round(($memory_after - $memory_start) / 1024 / 1024, 2) . " MB\n"; | |
| echo "Files processed: " . count($classes) . "\n"; | |
| EOF | |
| echo "### Memory Usage Test" >> $GITHUB_STEP_SUMMARY | |
| echo '```' >> $GITHUB_STEP_SUMMARY | |
| php memory_test.php >> $GITHUB_STEP_SUMMARY | |
| echo '```' >> $GITHUB_STEP_SUMMARY | |
| rm memory_test.php | |
| file-size-analysis: | |
| name: File Size Analysis | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout | |
| uses: actions/checkout@v4 | |
| - name: Analyze file sizes | |
| run: | | |
| echo "## π File Size Analysis" >> $GITHUB_STEP_SUMMARY | |
| echo "" >> $GITHUB_STEP_SUMMARY | |
| # Total project size | |
| TOTAL_SIZE=$(du -sh . | cut -f1) | |
| echo "π¦ Total project size: $TOTAL_SIZE" >> $GITHUB_STEP_SUMMARY | |
| # Source code size | |
| SRC_SIZE=$(du -sh src/ 2>/dev/null | cut -f1 || echo "0K") | |
| LIB_SIZE=$(du -sh lib/ 2>/dev/null | cut -f1 || echo "0K") | |
| TEST_SIZE=$(du -sh Test/ 2>/dev/null | cut -f1 || echo "0K") | |
| echo "π Source code size: $SRC_SIZE" >> $GITHUB_STEP_SUMMARY | |
| echo "π Library size: $LIB_SIZE" >> $GITHUB_STEP_SUMMARY | |
| echo "π§ͺ Test size: $TEST_SIZE" >> $GITHUB_STEP_SUMMARY | |
| echo "" >> $GITHUB_STEP_SUMMARY | |
| echo "### Largest Files" >> $GITHUB_STEP_SUMMARY | |
| echo '```' >> $GITHUB_STEP_SUMMARY | |
| find src/ lib/ -name "*.php" -type f -exec ls -lah {} \; 2>/dev/null | \ | |
| sort -k5 -hr | head -10 | \ | |
| awk '{print $5 " " $9}' || echo "No files found" | |
| echo '```' >> $GITHUB_STEP_SUMMARY | |
| dependency-performance: | |
| name: Dependency Performance | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout | |
| uses: actions/checkout@v4 | |
| - name: Setup PHP | |
| uses: shivammathur/setup-php@v2 | |
| with: | |
| php-version: "8.1" | |
| tools: composer | |
| - name: Analyze composer performance | |
| run: | | |
| echo "## π¦ Dependency Performance Analysis" >> $GITHUB_STEP_SUMMARY | |
| echo "" >> $GITHUB_STEP_SUMMARY | |
| # Create minimal composer.json for testing | |
| cat > composer-test.json << 'EOF' | |
| { | |
| "name": "performance-test", | |
| "require": { | |
| "symfony/console": "^5.0|^6.0", | |
| "guzzlehttp/guzzle": "^7.0", | |
| "monolog/monolog": "^2.0|^3.0", | |
| "psr/log": "^1.0|^2.0|^3.0" | |
| }, | |
| "autoload": { | |
| "psr-4": { | |
| "RunAsRoot\\PrometheusExporter\\": "src/", | |
| "RunAsRoot\\NewRelicApi\\": "lib/" | |
| } | |
| } | |
| } | |
| EOF | |
| # Time composer operations | |
| echo "### Composer Performance" >> $GITHUB_STEP_SUMMARY | |
| START_TIME=$(date +%s) | |
| composer validate --no-check-all --no-check-lock composer-test.json >/dev/null 2>&1 | |
| END_TIME=$(date +%s) | |
| VALIDATE_TIME=$((END_TIME - START_TIME)) | |
| echo "- **Validation time**: ${VALIDATE_TIME}s" >> $GITHUB_STEP_SUMMARY | |
| # Test autoload generation | |
| START_TIME=$(date +%s) | |
| composer dump-autoload --working-dir=. --file=composer-test.json >/dev/null 2>&1 || true | |
| END_TIME=$(date +%s) | |
| AUTOLOAD_TIME=$((END_TIME - START_TIME)) | |
| echo "- **Autoload generation**: ${AUTOLOAD_TIME}s" >> $GITHUB_STEP_SUMMARY | |
| # Count dependencies | |
| DEP_COUNT=$(grep -c '".*":' composer.json 2>/dev/null || echo "0") | |
| echo "- **Total dependencies**: $DEP_COUNT" >> $GITHUB_STEP_SUMMARY | |
| rm -f composer-test.json | |
| performance-benchmark: | |
| name: Performance Benchmark | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout | |
| uses: actions/checkout@v4 | |
| - name: Setup PHP | |
| uses: shivammathur/setup-php@v2 | |
| with: | |
| php-version: "8.1" | |
| - name: Run performance benchmarks | |
| run: | | |
| echo "## π Performance Benchmarks" >> $GITHUB_STEP_SUMMARY | |
| echo "" >> $GITHUB_STEP_SUMMARY | |
| # Create benchmark script | |
| cat > benchmark.php << 'EOF' | |
| <?php | |
| function benchmark($name, $callable, $iterations = 1000) { | |
| $start = microtime(true); | |
| for ($i = 0; $i < $iterations; $i++) { | |
| $callable(); | |
| } | |
| $end = microtime(true); | |
| $total = ($end - $start) * 1000; // Convert to milliseconds | |
| $avg = $total / $iterations; | |
| echo sprintf("%-30s | %8.2f ms | %8.4f ms/op\n", $name, $total, $avg); | |
| } | |
| echo "| Benchmark | Total Time | Avg per Op |\n"; | |
| echo "|-----------|------------|------------|\n"; | |
| // File operations benchmark | |
| benchmark("File reading (small)", function() { | |
| $files = glob('src/*.php'); | |
| if (!empty($files)) { | |
| file_get_contents($files[0]); | |
| } | |
| }, 100); | |
| // String operations benchmark | |
| benchmark("String concatenation", function() { | |
| $str = ''; | |
| for ($i = 0; $i < 100; $i++) { | |
| $str .= 'test_metric_' . $i; | |
| } | |
| }, 100); | |
| // Array operations benchmark | |
| benchmark("Array operations", function() { | |
| $arr = []; | |
| for ($i = 0; $i < 100; $i++) { | |
| $arr[] = ['metric' => 'test_' . $i, 'value' => $i]; | |
| } | |
| array_map(function($item) { return $item['metric']; }, $arr); | |
| }, 100); | |
| // JSON operations benchmark | |
| benchmark("JSON encode/decode", function() { | |
| $data = ['metrics' => range(1, 50)]; | |
| $json = json_encode($data); | |
| json_decode($json, true); | |
| }, 100); | |
| EOF | |
| echo "### Benchmark Results" >> $GITHUB_STEP_SUMMARY | |
| echo '```' >> $GITHUB_STEP_SUMMARY | |
| php benchmark.php >> $GITHUB_STEP_SUMMARY | |
| echo '```' >> $GITHUB_STEP_SUMMARY | |
| rm benchmark.php | |
| generate-performance-report: | |
| name: Generate Performance Report | |
| runs-on: ubuntu-latest | |
| needs: | |
| [ | |
| syntax-performance, | |
| code-complexity, | |
| memory-usage-analysis, | |
| file-size-analysis, | |
| dependency-performance, | |
| performance-benchmark, | |
| ] | |
| if: always() | |
| steps: | |
| - name: Generate performance summary | |
| run: | | |
| echo "## π Performance Monitoring Summary" >> $GITHUB_STEP_SUMMARY | |
| echo "" >> $GITHUB_STEP_SUMMARY | |
| echo "| Analysis Type | Status |" >> $GITHUB_STEP_SUMMARY | |
| echo "|---------------|--------|" >> $GITHUB_STEP_SUMMARY | |
| echo "| Syntax Performance | ${{ needs.syntax-performance.result == 'success' && 'β Completed' || 'β Failed' }} |" >> $GITHUB_STEP_SUMMARY | |
| echo "| Code Complexity | ${{ needs.code-complexity.result == 'success' && 'β Analyzed' || 'β Failed' }} |" >> $GITHUB_STEP_SUMMARY | |
| echo "| Memory Usage | ${{ needs.memory-usage-analysis.result == 'success' && 'β Analyzed' || 'β Failed' }} |" >> $GITHUB_STEP_SUMMARY | |
| echo "| File Size Analysis | ${{ needs.file-size-analysis.result == 'success' && 'β Completed' || 'β Failed' }} |" >> $GITHUB_STEP_SUMMARY | |
| echo "| Dependency Performance | ${{ needs.dependency-performance.result == 'success' && 'β Benchmarked' || 'β Failed' }} |" >> $GITHUB_STEP_SUMMARY | |
| echo "| Performance Benchmark | ${{ needs.performance-benchmark.result == 'success' && 'β Completed' || 'β Failed' }} |" >> $GITHUB_STEP_SUMMARY | |
| echo "" >> $GITHUB_STEP_SUMMARY | |
| # Count successful analyses | |
| SUCCESS_COUNT=0 | |
| if [[ "${{ needs.syntax-performance.result }}" == "success" ]]; then | |
| SUCCESS_COUNT=$((SUCCESS_COUNT + 1)) | |
| fi | |
| if [[ "${{ needs.code-complexity.result }}" == "success" ]]; then | |
| SUCCESS_COUNT=$((SUCCESS_COUNT + 1)) | |
| fi | |
| if [[ "${{ needs.memory-usage-analysis.result }}" == "success" ]]; then | |
| SUCCESS_COUNT=$((SUCCESS_COUNT + 1)) | |
| fi | |
| if [[ "${{ needs.file-size-analysis.result }}" == "success" ]]; then | |
| SUCCESS_COUNT=$((SUCCESS_COUNT + 1)) | |
| fi | |
| if [[ "${{ needs.dependency-performance.result }}" == "success" ]]; then | |
| SUCCESS_COUNT=$((SUCCESS_COUNT + 1)) | |
| fi | |
| if [[ "${{ needs.performance-benchmark.result }}" == "success" ]]; then | |
| SUCCESS_COUNT=$((SUCCESS_COUNT + 1)) | |
| fi | |
| echo "### π Overall Performance Status" >> $GITHUB_STEP_SUMMARY | |
| echo "" >> $GITHUB_STEP_SUMMARY | |
| echo "**Completed analyses**: $SUCCESS_COUNT/6" >> $GITHUB_STEP_SUMMARY | |
| echo "" >> $GITHUB_STEP_SUMMARY | |
| if [ $SUCCESS_COUNT -eq 6 ]; then | |
| echo "β **All performance analyses completed successfully!**" >> $GITHUB_STEP_SUMMARY | |
| echo "" >> $GITHUB_STEP_SUMMARY | |
| echo "The codebase shows good performance characteristics." >> $GITHUB_STEP_SUMMARY | |
| elif [ $SUCCESS_COUNT -ge 4 ]; then | |
| echo "β οΈ **Most performance analyses completed successfully.**" >> $GITHUB_STEP_SUMMARY | |
| echo "" >> $GITHUB_STEP_SUMMARY | |
| echo "Minor issues detected that should be reviewed." >> $GITHUB_STEP_SUMMARY | |
| else | |
| echo "β **Several performance analyses failed.**" >> $GITHUB_STEP_SUMMARY | |
| echo "" >> $GITHUB_STEP_SUMMARY | |
| echo "Please review the failed analyses and address any issues." >> $GITHUB_STEP_SUMMARY | |
| fi | |
| echo "" >> $GITHUB_STEP_SUMMARY | |
| echo "### π§ Performance Optimization Tips" >> $GITHUB_STEP_SUMMARY | |
| echo "- Monitor memory usage in production" >> $GITHUB_STEP_SUMMARY | |
| echo "- Keep file sizes reasonable" >> $GITHUB_STEP_SUMMARY | |
| echo "- Optimize database queries" >> $GITHUB_STEP_SUMMARY | |
| echo "- Use appropriate caching strategies" >> $GITHUB_STEP_SUMMARY | |
| echo "- Regular dependency updates" >> $GITHUB_STEP_SUMMARY | |
| echo "" >> $GITHUB_STEP_SUMMARY | |
| echo "**Next scheduled run**: Weekly on Sundays at 03:00 UTC" |