Skip to content

Commit

Permalink
Add TidewaysXHProf profiler (#8)
Browse files Browse the repository at this point in the history
Add TidewaysXHProf profiler
  • Loading branch information
glensc authored Feb 11, 2020
2 parents 4b7adb3 + 112d5c1 commit 26de797
Show file tree
Hide file tree
Showing 5 changed files with 90 additions and 2 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ This profiling library will auto-detect what you have installed and use that.

The preference order is currently as follows:
1. uprofiler
1. tideways_xhprof
1. tideways
1. xhprof

Expand Down
12 changes: 10 additions & 2 deletions src/Profiler.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ class Profiler

const PROFILER_XHPROF = 'xhprof';
const PROFILER_TIDEWAYS = 'tideways';
const PROFILER_TIDEWAYS_XHPROF = 'tideways_xhprof';
const PROFILER_UPROFILER = 'uprofiler';

/**
Expand Down Expand Up @@ -138,8 +139,9 @@ public function shutDown()
/**
* Determines which profiler you're running.
* If you're running multiple (which you shouldn't!),
* It will return them in this preference order :
* It will return them in this preference order:
* 1) uprofiler
* 2) tideways_xhprof
* 2) tideways
* 3) xhprof
*
Expand All @@ -148,7 +150,13 @@ public function shutDown()
private function getProfilerType()
{
$profiler = null;
$extensions = array(self::PROFILER_XHPROF, self::PROFILER_TIDEWAYS, self::PROFILER_UPROFILER);
// NOTE: the list here is reversed
$extensions = array(
self::PROFILER_XHPROF,
self::PROFILER_TIDEWAYS,
self::PROFILER_UPROFILER,
self::PROFILER_TIDEWAYS_XHPROF,
);
foreach ($extensions as $extension) {
$profiler = extension_loaded($extension) ? $extension : $profiler;
}
Expand Down
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 26de797

Please sign in to comment.