Skip to content

Commit 3fe9920

Browse files
committed
🐛 fix xhgui profiling
1 parent 447499a commit 3fe9920

File tree

2 files changed

+11
-53
lines changed

2 files changed

+11
-53
lines changed

Dockerfile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ FROM base${DIST_ADDON}
1919
COPY entrypoint.d/* /opt/docker/provision/entrypoint.d/
2020
COPY profiler.php /opt/docker/profiler.php
2121
COPY --from=mlocati/php-extension-installer /usr/bin/install-php-extensions /usr/bin/
22-
RUN install-php-extensions @fix_letsencrypt xhprof mongodb pcov && \
22+
RUN install-php-extensions @fix_letsencrypt xhprof pcov && \
2323
echo "auto_prepend_file=/opt/docker/profiler.php" >> /opt/docker/etc/php/php.ini && \
2424
echo "pcov.enabled=0" >> /usr/local/etc/php/conf.d/docker-php-ext-pcov.ini && \
2525
echo "pcov.exclude='~vendor~'" >> /usr/local/etc/php/conf.d/docker-php-ext-pcov.ini && \
@@ -50,7 +50,7 @@ ENV \
5050
XHGUI_PROFILING="enabled" \
5151
TZ=Europe/Berlin
5252

53-
RUN composer global require davidrjonas/composer-lock-diff perftools/xhgui-collector alcaeus/mongo-php-adapter perftools/php-profiler && \
53+
RUN composer global require davidrjonas/composer-lock-diff perftools/php-profiler && \
5454
composer clear && \
5555
echo "source ~/.additional_bashrc.sh" >> ~/.bashrc && \
5656
curl -L https://raw.github.com/git/git/master/contrib/completion/git-prompt.sh > ~/.bash_git

profiler.php

Lines changed: 9 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -3,65 +3,23 @@
33
// we do not want the /home/application/.config/composer/vendor/autoload.php
44
// we want minimal file inclusion.
55

6-
if ((isset($_COOKIE['XDEBUG_PROFILE']) || getenv('PROFILING_ENABLED'))) {
6+
if (!isset($_COOKIE['XDEBUG_PROFILE']) && !getenv('PROFILING_ENABLED')) {
7+
return;
8+
}
9+
10+
(function () {
711
$composerVendorDir = '/home/application/.composer/vendor';
812
if (!is_dir($composerVendorDir)) {
913
$composerVendorDir = '/home/application/.config/composer/vendor';
1014
}
1115
require_once $composerVendorDir . '/perftools/php-profiler/autoload.php';
12-
13-
$tmpFile = '/tmp/' . uniqid('xhgui', true) . '.data.jsonl';
14-
1516
$profiler = new \Xhgui\Profiler\Profiler(
1617
[
17-
'profiler' => \Xhgui\Profiler\Profiler::PROFILER_XHPROF,
18-
# 'save.handler' => \Xhgui\Profiler\Profiler::SAVER_MONGODB,
19-
20-
'save.handler' => \Xhgui\Profiler\Profiler::SAVER_FILE,
21-
'save.handler.file' => [
22-
// Appends jsonlines formatted data to this path
23-
'filename' => $tmpFile,
18+
'save.handler.upload' => [
19+
'url' => 'http://' . (getenv('XHGUI_MONGO_HOST') ?: 'global-xhgui') . '/run/import',
2420
],
2521
]
2622
);
27-
$profiler->enable();
28-
29-
30-
register_shutdown_function(static function () use ($composerVendorDir, $tmpFile, $profiler) {
31-
//we want this autoloading only after the main php script executed everything.
32-
require_once $composerVendorDir . '/autoload.php';
33-
$profiler->stop();
34-
35-
//huge performance Optimisation possible:
36-
// do not import into mongodb at this point, do it asyncroniasly in the background
37-
//return;
38-
$saver = \Xhgui\Profiler\SaverFactory::create(
39-
\Xhgui\Profiler\Profiler::SAVER_MONGODB,
40-
new \Xhgui\Profiler\Config(
41-
[
42-
'save.handler.mongodb' => [
43-
'dsn' => 'mongodb://' . str_replace('mongodb://', '', getenv('XHGUI_MONGO_URI') ?: 'global-xhgui:27017'),
44-
'database' => 'xhprof',
45-
// Allows you to pass additional options like replicaSet to MongoClient.
46-
// 'username', 'password' and 'db' (where the user is added)
47-
'options' => [],
48-
// Allows you to pass driver options like ca_file to MongoClient
49-
'driverOptions' => [],
50-
],
51-
]
52-
)
53-
);
54-
if (!$saver) {
55-
throw new RuntimeException("Unable to obtain saver");
56-
}
57-
58-
$importer = new \Xhgui\Profiler\Importer($saver);
59-
$fp = fopen($tmpFile, 'r');
60-
if (!$fp) {
61-
throw new RuntimeException("Can't open " . $tmpFile);
62-
}
63-
$importer->import($fp);
64-
fclose($fp);
65-
unlink($tmpFile);
66-
});
23+
$profiler->start();
6724
}
25+
)();

0 commit comments

Comments
 (0)