|
3 | 3 | // we do not want the /home/application/.config/composer/vendor/autoload.php
|
4 | 4 | // we want minimal file inclusion.
|
5 | 5 |
|
6 |
| -if ((isset($_COOKIE['XDEBUG_PROFILE']) || getenv('PROFILING_ENABLED'))) { |
| 6 | +if (!isset($_COOKIE['XDEBUG_PROFILE']) && !getenv('PROFILING_ENABLED')) { |
| 7 | + return; |
| 8 | +} |
| 9 | + |
| 10 | +(function () { |
7 | 11 | $composerVendorDir = '/home/application/.composer/vendor';
|
8 | 12 | if (!is_dir($composerVendorDir)) {
|
9 | 13 | $composerVendorDir = '/home/application/.config/composer/vendor';
|
10 | 14 | }
|
11 | 15 | require_once $composerVendorDir . '/perftools/php-profiler/autoload.php';
|
12 |
| - |
13 |
| - $tmpFile = '/tmp/' . uniqid('xhgui', true) . '.data.jsonl'; |
14 |
| - |
15 | 16 | $profiler = new \Xhgui\Profiler\Profiler(
|
16 | 17 | [
|
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', |
24 | 20 | ],
|
25 | 21 | ]
|
26 | 22 | );
|
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(); |
67 | 24 | }
|
| 25 | +)(); |
0 commit comments