From 5c9355b13f18f5891a8345ad64619f2c1e2f2bcc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Elan=20Ruusam=C3=A4e?= Date: Thu, 30 Jul 2020 08:40:15 +0300 Subject: [PATCH] Add XdebugProfiler class --- composer.json | 1 + src/Profilers/XdebugProfiler.php | 34 +++++++++++++++++++++++++++ tests/Profiler/XdebugProfilerTest.php | 23 ++++++++++++++++++ 3 files changed, 58 insertions(+) create mode 100644 src/Profilers/XdebugProfiler.php create mode 100644 tests/Profiler/XdebugProfilerTest.php diff --git a/composer.json b/composer.json index ff6d42a..fb98e31 100644 --- a/composer.json +++ b/composer.json @@ -36,6 +36,7 @@ "ext-mongodb": "mongodb extension (PHP>=5.4)", "ext-tideways": "Use tideways to profile", "ext-uprofiler": "Use uprofiler to profile", + "ext-xdebug": "Use xdebug to profile", "ext-xhprof": "Use xhprof to profile", "alcaeus/mongo-php-adapter": "Adapter to provide ext-mongo interface on top of mongo-php-libary (PHP>=5.6)" }, diff --git a/src/Profilers/XdebugProfiler.php b/src/Profilers/XdebugProfiler.php new file mode 100644 index 0000000..822c28d --- /dev/null +++ b/src/Profilers/XdebugProfiler.php @@ -0,0 +1,34 @@ +combineFlags($flags, $this->getProfileFlagMap()), $options); + } + + public function disable() + { + $traceFile = xdebug_stop_trace(); + + return $this->readTrace($traceFile); + } + + private function readTrace($traceFile) + { + return file_get_contents($traceFile); + } +} diff --git a/tests/Profiler/XdebugProfilerTest.php b/tests/Profiler/XdebugProfilerTest.php new file mode 100644 index 0000000..1d338cb --- /dev/null +++ b/tests/Profiler/XdebugProfilerTest.php @@ -0,0 +1,23 @@ +profiler = new XdebugProfiler(); + } + + public function testDefaults() + { + $data = $this->runProfiler(); + $this->assertCount(13, $data); + } +}