|
| 1 | +name: Benchmark Xdebug performance |
| 2 | + |
| 3 | +on: |
| 4 | + # This workflow runs on three triggers: Weekly on schedule, manually, or when pull requests are labeled |
| 5 | + schedule: |
| 6 | + # Every Sunday at 03:00 UTC |
| 7 | + - cron: '0 3 * * 0' |
| 8 | + workflow_dispatch: |
| 9 | + pull_request: |
| 10 | + types: [ labeled ] |
| 11 | + |
| 12 | +jobs: |
| 13 | + run-benchmark: |
| 14 | + # When triggered when a pull request is labeled we check the name of the label |
| 15 | + if: | |
| 16 | + github.event_name == 'schedule' || github.event_name == 'workflow_dispatch' || |
| 17 | + ( |
| 18 | + github.event_name == 'pull_request' && |
| 19 | + github.event.label.name == 'performance-check' |
| 20 | + ) |
| 21 | + runs-on: ubuntu-latest |
| 22 | + strategy: |
| 23 | + fail-fast: false |
| 24 | + matrix: |
| 25 | + command: ["bench", "symfony", "rector"] |
| 26 | +# php: ["8.2", "8.3", "8.4", "8.5"] |
| 27 | + php: ["8.2"] |
| 28 | + xdebug_mode: ["no", "off", "debug"] |
| 29 | + steps: |
| 30 | + - uses: actions/checkout@v6 |
| 31 | + |
| 32 | + - name: Setup PHP |
| 33 | + uses: shivammathur/setup-php@v2 |
| 34 | + with: |
| 35 | + php-version: "${{ matrix.php }}" |
| 36 | + coverage: none |
| 37 | + # We need to use a specific version of Composer because we are using a specific version of the |
| 38 | + # Symfony Demo which is not compatible with the latest versions of Composer |
| 39 | + tools: composer:v2.2.21 |
| 40 | + |
| 41 | + - name: Disable ASLR |
| 42 | + # ASLR can cause a lot of noise due to missed sse opportunities for memcpy |
| 43 | + # and other operations, so we disable it during benchmarking. |
| 44 | + run: echo 0 | sudo tee /proc/sys/kernel/randomize_va_space |
| 45 | + |
| 46 | + - name: Install valgrind |
| 47 | + run: sudo apt-get update && sudo apt-get install -y valgrind |
| 48 | + |
| 49 | + - name: Compile |
| 50 | + run: | |
| 51 | + phpize |
| 52 | + ./configure --enable-php-debugger |
| 53 | + make -j$(nproc) |
| 54 | +
|
| 55 | + - name: create results and opcache folder |
| 56 | + run: | |
| 57 | + mkdir -p results |
| 58 | + mkdir -p /tmp/opcache |
| 59 | +
|
| 60 | + - name: install Symfony demo |
| 61 | + if: matrix.command == 'symfony' |
| 62 | + # For versions of PHP greater than 8.4 we need to run a different version of the Symfony Demo. |
| 63 | + # The older versions suffer from the nulllable parameter deprecation and this generated a lot of |
| 64 | + # deprecations in the code and this skewed the tests results a lot. And we cannot use the newer version |
| 65 | + # for older versions of PHP as it is not compatible. |
| 66 | + run: | |
| 67 | + if [ "${{ matrix.php }}" \< "8.4" ]; then |
| 68 | + version="v2.0.2" |
| 69 | + else |
| 70 | + version="v2.7.0" |
| 71 | + fi |
| 72 | + git clone -q --branch "$version" --depth 1 https://github.com/symfony/demo.git ./symfony-demo |
| 73 | + cd symfony-demo |
| 74 | + composer install |
| 75 | + # We do not want our tests to be skewed by any error, warning, notice or deprecation thrown by the |
| 76 | + # code, so we set the error level to 0 on purpose. Unfortunately, Symfony overrides this setup and |
| 77 | + # sets their own error reporting level. We fix this by changing all the places where Symfony is |
| 78 | + # setting the error reporting level so that it continues to be set to 0 |
| 79 | + find . -type f -name "*.php" -exec sed -i.bak -E 's/error_reporting\(.*\);/error_reporting(0);/g' {} + |
| 80 | +
|
| 81 | + - name: install Rector |
| 82 | + if: matrix.command == 'rector' |
| 83 | + run: | |
| 84 | + composer require rector/rector:2.1.2 phpstan/phpstan:2.1.33 --dev |
| 85 | + cp .github/benchmark-files/rector.php . |
| 86 | +
|
| 87 | + - name: Copy ini file |
| 88 | + run: | |
| 89 | + sudo cp ./.github/benchmark-files/benchmark.ini /etc/php/${{ matrix.php }}/cli/conf.d |
| 90 | + sudo cp ./.github/benchmark-files/benchmark.ini /etc/php/${{ matrix.php }}/cgi/conf.d |
| 91 | +
|
| 92 | + - name: Copy xdebug ini file |
| 93 | + if: matrix.xdebug_mode != 'no' |
| 94 | + run: | |
| 95 | + sudo cp ./.github/benchmark-files/xdebug-benchmark.ini /etc/php/${{ matrix.php }}/cli/conf.d |
| 96 | + sudo cp ./.github/benchmark-files/xdebug-benchmark.ini /etc/php/${{ matrix.php }}/cgi/conf.d |
| 97 | + |
| 98 | + - name: Set xdebug mode |
| 99 | + run: echo "XDEBUG_MODE=${{ matrix.xdebug_mode }}" >> $GITHUB_ENV |
| 100 | + |
| 101 | + - name: benchmark bench.php |
| 102 | + if: matrix.command == 'bench' |
| 103 | + run: valgrind --tool=callgrind --dump-instr=yes --callgrind-out-file=callgrind.out -- php ./.github/benchmark-files/bench.php |
| 104 | + |
| 105 | + - name: benchmark Symfony |
| 106 | + if: matrix.command == 'symfony' |
| 107 | + run: | |
| 108 | + cd symfony-demo |
| 109 | + # The Symfony demo is run using php-cgi to simulate a web server. Symfony needs that this env |
| 110 | + # variable is set, it would usually be set by the web server, we need to set it manually instead |
| 111 | + export SCRIPT_FILENAME="$(realpath public/index.php)" |
| 112 | + # Symfony also needs this to be set to a non empty value |
| 113 | + export APP_SECRET=APP_SECRET |
| 114 | + # We run the web page twice so that the files have already been compiled into the opcache in order |
| 115 | + # to remove the compilation time from the equation. This also better reflects the normal situation |
| 116 | + # in a web server |
| 117 | + php-cgi public/index.php |
| 118 | + valgrind --tool=callgrind --dump-instr=yes --callgrind-out-file=callgrind.out -- php-cgi public/index.php |
| 119 | + mv callgrind.out .. |
| 120 | + cd .. |
| 121 | +
|
| 122 | + - name: benchmark rector.php |
| 123 | + if: matrix.command == 'rector' |
| 124 | + # Rector needs to be run with the --xdebug flag so that it does not try to disable Xdebug and also with |
| 125 | + # the --debug flag so that it does not try to run several threads in parallel |
| 126 | + run: valgrind --tool=callgrind --dump-instr=yes --callgrind-out-file=callgrind.out -- php vendor/bin/rector --dry-run --xdebug --debug || true |
| 127 | + |
| 128 | + - name: save matrix values |
| 129 | + run: | |
| 130 | + # We read the number of executed instructions from the callgrind.out file and save it in an artifact |
| 131 | + # to be processed later |
| 132 | + awk '/^summary:/ { print $2 }' callgrind.out > results/php-${{ matrix.php }}_cmd-${{ matrix.command }}_xdebug-${{ matrix.xdebug_mode }}.txt |
| 133 | + # We also save the matrix variables so that in a later step we can build a list of the executed |
| 134 | + # options |
| 135 | + echo "${{ matrix.php }},${{ matrix.command }},${{ matrix.xdebug_mode }}" > results/matrix-values-${{ matrix.php }}-${{ matrix.command }}-${{ matrix.xdebug_mode }}.txt |
| 136 | +
|
| 137 | + - name: Upload result and matrix info |
| 138 | + uses: actions/upload-artifact@v6 |
| 139 | + with: |
| 140 | + name: results-${{ matrix.command }}-${{ matrix.php }}-${{ matrix.xdebug_mode }} |
| 141 | + path: results/ |
| 142 | + |
| 143 | + performance: |
| 144 | + # After running all benchmarks for all commands, PHP versions and Xdebug modes, we run a new job that builds a |
| 145 | + # summary of all execution times |
| 146 | + needs: run-benchmark |
| 147 | + runs-on: ubuntu-latest |
| 148 | + strategy: |
| 149 | + fail-fast: false |
| 150 | + matrix: |
| 151 | + comparison: |
| 152 | + - name: "base-branch" |
| 153 | + branch: "" # Empty means use default base branch logic |
| 154 | + - name: "base" |
| 155 | + branch: "base" |
| 156 | + steps: |
| 157 | + - name: Setup PHP |
| 158 | + uses: shivammathur/setup-php@v2 |
| 159 | + with: |
| 160 | + php-version: "8.5" |
| 161 | + coverage: none |
| 162 | + |
| 163 | + - uses: actions/checkout@v6 |
| 164 | + |
| 165 | + - name: Download all artifacts |
| 166 | + uses: actions/download-artifact@v7 |
| 167 | + with: |
| 168 | + path: results |
| 169 | + |
| 170 | + - name: Generate summary table as markdown |
| 171 | + env: |
| 172 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 173 | + COMPARISON_BRANCH: ${{ matrix.comparison.branch }} |
| 174 | + run: php .github/benchmark-files/generate_summary.php |
| 175 | + |
| 176 | + - name: print summary |
| 177 | + # This generated summary file is copied into a special file which GitHub has defined |
| 178 | + # in this special env variable and it will use it to print a summary for the workflow |
| 179 | + run: cat summary.md >> $GITHUB_STEP_SUMMARY |
| 180 | + |
| 181 | + - name: delete intermediary artifacts |
| 182 | + # The intermediate files that we generated are not needed and can be deleted, |
| 183 | + # helping us keep the summary page clean |
| 184 | + uses: geekyeggo/delete-artifact@v6 |
| 185 | + with: |
| 186 | + name: results-* |
| 187 | + |
| 188 | + - name: Upload summary.csv as artifact |
| 189 | + if: matrix.comparison.name == 'base-branch' |
| 190 | + uses: actions/upload-artifact@v6 |
| 191 | + with: |
| 192 | + name: summary.csv |
| 193 | + path: summary.csv |