Skip to content

Benchmarking mean #11085

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Apr 15, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .github/workflows/push.yml
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,7 @@ jobs:
sudo apt-get update
sudo apt-get install \
bison \
libgmp-dev \
libonig-dev \
libsqlite3-dev \
openssl \
Expand All @@ -253,6 +254,7 @@ jobs:
--enable-werror \
--prefix=/usr \
--with-config-file-scan-dir=/etc/php.d \
--with-gmp \
--with-mysqli=mysqlnd \
--with-openssl \
--with-pdo-sqlite \
Expand Down
11 changes: 8 additions & 3 deletions benchmark/benchmark.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ function runSymfonyDemo(bool $jit): array {
cloneRepo($dir, 'https://github.com/php/benchmarking-symfony-demo-2.2.3.git');
runPhpCommand([$dir . '/bin/console', 'cache:clear']);
runPhpCommand([$dir . '/bin/console', 'cache:warmup']);
return runValgrindPhpCgiCommand([$dir . '/public/index.php'], cwd: $dir, jit: $jit, warmup: 50);
return runValgrindPhpCgiCommand([$dir . '/public/index.php'], cwd: $dir, jit: $jit, warmup: 50, repeat: 50);
}

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

// Warmup
runPhpCommand([$dir . '/index.php'], $dir);
return runValgrindPhpCgiCommand([$dir . '/index.php'], cwd: $dir, jit: $jit, warmup: 50);
return runValgrindPhpCgiCommand([$dir . '/index.php'], cwd: $dir, jit: $jit, warmup: 50, repeat: 50);
}

function runPhpCommand(array $args, ?string $cwd = null): ProcessResult {
Expand All @@ -90,6 +90,7 @@ function runValgrindPhpCgiCommand(
?string $cwd = null,
bool $jit = false,
int $warmup = 0,
int $repeat = 1,
): array {
global $phpCgi;
$process = runCommand([
Expand All @@ -99,13 +100,17 @@ function runValgrindPhpCgiCommand(
'--callgrind-out-file=/dev/null',
'--',
$phpCgi,
'-T' . ($warmup ? $warmup . ',' : '') . '1',
'-T' . ($warmup ? $warmup . ',' : '') . $repeat,
'-d max_execution_time=0',
'-d opcache.enable=1',
'-d opcache.jit_buffer_size=' . ($jit ? '128M' : '0'),
'-d opcache.validate_timestamps=0',
...$args,
]);
$instructions = extractInstructionsFromValgrindOutput($process->stderr);
if ($repeat > 1) {
$instructions = gmp_strval(gmp_div_q($instructions, $repeat));
}
return ['instructions' => $instructions];
}

Expand Down
16 changes: 13 additions & 3 deletions sapi/cgi/cgi_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -2219,6 +2219,8 @@ consult the installation file that came with this distribution, or visit \n\
#ifdef HAVE_VALGRIND
if (warmup_repeats > 0) {
CALLGRIND_STOP_INSTRUMENTATION;
/* We're not interested in measuring startup */
CALLGRIND_ZERO_STATS;
}
#endif
} else {
Expand Down Expand Up @@ -2427,6 +2429,12 @@ consult the installation file that came with this distribution, or visit \n\
}
} /* end !cgi && !fastcgi */

#ifdef HAVE_VALGRIND
if (warmup_repeats == 0) {
CALLGRIND_START_INSTRUMENTATION;
}
#endif

/* request startup only after we've done all we can to
* get path_translated */
if (php_request_startup() == FAILURE) {
Expand Down Expand Up @@ -2546,6 +2554,11 @@ consult the installation file that came with this distribution, or visit \n\
SG(request_info).query_string = NULL;
}

#ifdef HAVE_VALGRIND
/* We're not interested in measuring shutdown */
CALLGRIND_STOP_INSTRUMENTATION;
#endif

if (!fastcgi) {
if (benchmark) {
if (warmup_repeats) {
Expand All @@ -2555,9 +2568,6 @@ consult the installation file that came with this distribution, or visit \n\
gettimeofday(&start, NULL);
#else
time(&start);
#endif
#ifdef HAVE_VALGRIND
CALLGRIND_START_INSTRUMENTATION;
#endif
}
continue;
Expand Down