Skip to content
Draft
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
1 change: 1 addition & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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)"
},
Expand Down
34 changes: 34 additions & 0 deletions src/Profilers/XdebugProfiler.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?php

namespace Xhgui\Profiler\Profilers;

/**
* @see https://xdebug.org/docs/execution_trace
*/
class XdebugProfiler extends AbstractProfiler
{
const EXTENSION_NAME = 'xdebug';

public function isSupported()
{
return extension_loaded(self::EXTENSION_NAME);
}

public function enable($flags = array(), $options = array())
{
$traceFile = xdebug_start_trace();
// uprofiler_enable($this->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);
}
}
23 changes: 23 additions & 0 deletions tests/Profiler/XdebugProfilerTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?php

namespace Xhgui\Profiler\Test\Profiler;

use Xhgui\Profiler\Profilers\XdebugProfiler;
use Xhgui\Profiler\Test\TestCase;

/**
* @requires extension xdebug
*/
class XdebugProfilerTest extends TestCase
{
public function setUp()
{
$this->profiler = new XdebugProfiler();
}

public function testDefaults()
{
$data = $this->runProfiler();
$this->assertCount(13, $data);
}
}