Skip to content

Commit 24cc402

Browse files
authored
Benchmarking mean (#11085)
* Use 50 runs and calculate mean * Don't validate timestamps * Don't profile PHP startup and shutdown in cgi with valgrind
1 parent 35647aa commit 24cc402

File tree

3 files changed

+23
-6
lines changed

3 files changed

+23
-6
lines changed

.github/workflows/push.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -230,6 +230,7 @@ jobs:
230230
sudo apt-get update
231231
sudo apt-get install \
232232
bison \
233+
libgmp-dev \
233234
libonig-dev \
234235
libsqlite3-dev \
235236
openssl \
@@ -253,6 +254,7 @@ jobs:
253254
--enable-werror \
254255
--prefix=/usr \
255256
--with-config-file-scan-dir=/etc/php.d \
257+
--with-gmp \
256258
--with-mysqli=mysqlnd \
257259
--with-openssl \
258260
--with-pdo-sqlite \

benchmark/benchmark.php

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ function runSymfonyDemo(bool $jit): array {
5555
cloneRepo($dir, 'https://github.com/php/benchmarking-symfony-demo-2.2.3.git');
5656
runPhpCommand([$dir . '/bin/console', 'cache:clear']);
5757
runPhpCommand([$dir . '/bin/console', 'cache:warmup']);
58-
return runValgrindPhpCgiCommand([$dir . '/public/index.php'], cwd: $dir, jit: $jit, warmup: 50);
58+
return runValgrindPhpCgiCommand([$dir . '/public/index.php'], cwd: $dir, jit: $jit, warmup: 50, repeat: 50);
5959
}
6060

6161
function runWordpress(bool $jit): array {
@@ -78,7 +78,7 @@ function runWordpress(bool $jit): array {
7878

7979
// Warmup
8080
runPhpCommand([$dir . '/index.php'], $dir);
81-
return runValgrindPhpCgiCommand([$dir . '/index.php'], cwd: $dir, jit: $jit, warmup: 50);
81+
return runValgrindPhpCgiCommand([$dir . '/index.php'], cwd: $dir, jit: $jit, warmup: 50, repeat: 50);
8282
}
8383

8484
function runPhpCommand(array $args, ?string $cwd = null): ProcessResult {
@@ -90,6 +90,7 @@ function runValgrindPhpCgiCommand(
9090
?string $cwd = null,
9191
bool $jit = false,
9292
int $warmup = 0,
93+
int $repeat = 1,
9394
): array {
9495
global $phpCgi;
9596
$process = runCommand([
@@ -99,13 +100,17 @@ function runValgrindPhpCgiCommand(
99100
'--callgrind-out-file=/dev/null',
100101
'--',
101102
$phpCgi,
102-
'-T' . ($warmup ? $warmup . ',' : '') . '1',
103+
'-T' . ($warmup ? $warmup . ',' : '') . $repeat,
103104
'-d max_execution_time=0',
104105
'-d opcache.enable=1',
105106
'-d opcache.jit_buffer_size=' . ($jit ? '128M' : '0'),
107+
'-d opcache.validate_timestamps=0',
106108
...$args,
107109
]);
108110
$instructions = extractInstructionsFromValgrindOutput($process->stderr);
111+
if ($repeat > 1) {
112+
$instructions = gmp_strval(gmp_div_q($instructions, $repeat));
113+
}
109114
return ['instructions' => $instructions];
110115
}
111116

sapi/cgi/cgi_main.c

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2219,6 +2219,8 @@ consult the installation file that came with this distribution, or visit \n\
22192219
#ifdef HAVE_VALGRIND
22202220
if (warmup_repeats > 0) {
22212221
CALLGRIND_STOP_INSTRUMENTATION;
2222+
/* We're not interested in measuring startup */
2223+
CALLGRIND_ZERO_STATS;
22222224
}
22232225
#endif
22242226
} else {
@@ -2427,6 +2429,12 @@ consult the installation file that came with this distribution, or visit \n\
24272429
}
24282430
} /* end !cgi && !fastcgi */
24292431

2432+
#ifdef HAVE_VALGRIND
2433+
if (warmup_repeats == 0) {
2434+
CALLGRIND_START_INSTRUMENTATION;
2435+
}
2436+
#endif
2437+
24302438
/* request startup only after we've done all we can to
24312439
* get path_translated */
24322440
if (php_request_startup() == FAILURE) {
@@ -2546,6 +2554,11 @@ consult the installation file that came with this distribution, or visit \n\
25462554
SG(request_info).query_string = NULL;
25472555
}
25482556

2557+
#ifdef HAVE_VALGRIND
2558+
/* We're not interested in measuring shutdown */
2559+
CALLGRIND_STOP_INSTRUMENTATION;
2560+
#endif
2561+
25492562
if (!fastcgi) {
25502563
if (benchmark) {
25512564
if (warmup_repeats) {
@@ -2555,9 +2568,6 @@ consult the installation file that came with this distribution, or visit \n\
25552568
gettimeofday(&start, NULL);
25562569
#else
25572570
time(&start);
2558-
#endif
2559-
#ifdef HAVE_VALGRIND
2560-
CALLGRIND_START_INSTRUMENTATION;
25612571
#endif
25622572
}
25632573
continue;

0 commit comments

Comments
 (0)