From 7557f885d32f58031a49c83e3b1a5f011b301843 Mon Sep 17 00:00:00 2001 From: Peter Verraedt Date: Wed, 25 Nov 2020 10:11:23 +0100 Subject: [PATCH] Allow configuration of run_id, drop xhprof_lib dependency Signed-off-by: Peter Verraedt --- config/config.php | 2 +- src/Providers/TidewaysProvider.php | 12 +++++++----- src/Providers/XHProfProvider.php | 12 +++++++----- 3 files changed, 15 insertions(+), 11 deletions(-) diff --git a/config/config.php b/config/config.php index c3daa6d..544ed60 100644 --- a/config/config.php +++ b/config/config.php @@ -3,10 +3,10 @@ return [ 'enabled' => true, 'global_middleware' => true, - 'path' => '/opt/xhprof', 'output_dir' => null, 'name' => 'xhprof', 'freq' => 1 / 1000, 'extension_name' => 'xhprof', 'provider' => \Bavix\XHProf\Providers\XHProfProvider::class, + 'run_id' => uniqid(), ]; diff --git a/src/Providers/TidewaysProvider.php b/src/Providers/TidewaysProvider.php index 280f434..a8ce720 100644 --- a/src/Providers/TidewaysProvider.php +++ b/src/Providers/TidewaysProvider.php @@ -12,9 +12,6 @@ class TidewaysProvider implements ProviderInterface */ public function enable() { - $path = config('xhprof.path'); - include_once $path . '/xhprof_lib/utils/xhprof_lib.php'; - include_once $path . '/xhprof_lib/utils/xhprof_runs.php'; tideways_xhprof_enable(config('xhprof.flags', 0)); } @@ -24,8 +21,13 @@ public function enable() public function disable() { $data = tideways_xhprof_disable(); - $runs = new XHProfRuns_Default(config('xhprof.output_dir', null)); - $runs->save_run($data, config('xhprof.name')); + + $run_id = config('xhprof.run_id', null) ?? uniqid(); + + file_put_contents( + config('xhprof.output_dir', '/tmp') . '/' . $run_id . '.' . config('xhprof.name') . '.xhprof', + serialize($data) + ); } } diff --git a/src/Providers/XHProfProvider.php b/src/Providers/XHProfProvider.php index 40a67dc..3828018 100644 --- a/src/Providers/XHProfProvider.php +++ b/src/Providers/XHProfProvider.php @@ -14,9 +14,6 @@ class XHProfProvider implements ProviderInterface */ public function enable() { - $path = config('xhprof.path'); - include_once $path . '/xhprof_lib/utils/xhprof_lib.php'; - include_once $path . '/xhprof_lib/utils/xhprof_runs.php'; xhprof_enable(config('xhprof.flags', 0)); } @@ -26,8 +23,13 @@ public function enable() public function disable() { $data = xhprof_disable(); - $runs = new XHProfRuns_Default(config('xhprof.output_dir', null)); - $runs->save_run($data, config('xhprof.name')); + + $run_id = config('xhprof.run_id', null) ?? uniqid(); + + file_put_contents( + config('xhprof.output_dir', '/tmp') . '/' . $run_id . '.' . config('xhprof.name') . '.xhprof', + serialize($data) + ); } }