Skip to content

Commit

Permalink
Add TidewaysXHProf profiler
Browse files Browse the repository at this point in the history
  • Loading branch information
glensc committed Feb 10, 2020
1 parent 4b7adb3 commit 216e665
Show file tree
Hide file tree
Showing 3 changed files with 79 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/Profilers/Tideways.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@

use Xhgui\Profiler\ProfilingFlags;

/**
* v4 (tideways)
*
* @see https://github.com/tideways/php-profiler-extension
*/
class Tideways extends AbstractProfiler
{
/**
Expand Down
42 changes: 42 additions & 0 deletions src/Profilers/TidewaysXHProf.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
<?php

namespace Xhgui\Profiler\Profilers;

use Xhgui\Profiler\ProfilingFlags;

/**
* v5 (tideways_xhprof)
*
* @see https://github.com/tideways/php-profiler-extension
*/
class TidewaysXHProf extends AbstractProfiler
{
/**
* {@inheritdoc}
*/
public function enableWith($flags = array(), $options = array())
{
tideways_xhprof_enable($this->combineFlags($flags), $options);
}

/**
* {@inheritdoc}
*/
public function disable()
{
return tideways_xhprof_disable();
}

/**
* {@inheritdoc}
*/
public function getProfileFlagMap()
{
return array(
ProfilingFlags::CPU => TIDEWAYS_XHPROF_FLAGS_CPU,
ProfilingFlags::MEMORY => TIDEWAYS_XHPROF_FLAGS_MEMORY,
ProfilingFlags::NO_BUILTINS => TIDEWAYS_XHPROF_FLAGS_NO_BUILTINS,
ProfilingFlags::NO_SPANS => 0,
);
}
}
32 changes: 32 additions & 0 deletions tests/TidewaysXHProfTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?php

namespace Xhgui\Profiler\Test;

use Xhgui\Profiler\Profilers\TidewaysXHProf;
use Xhgui\Profiler\ProfilingFlags;

/**
* @requires extension tideways_xhprof
*/
class TidewaysXHProfTest extends TestCase
{
public function setUp()
{
$this->profiler = new TidewaysXHProf();
}

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

public function testNoFlags()
{
$flags = array(
ProfilingFlags::NO_BUILTINS,
);
$data = $this->runProfiler($flags);
$this->assertCount(2, $data);
}
}

0 comments on commit 216e665

Please sign in to comment.