Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add TidewaysXHProf profiler #8

Merged
merged 2 commits into from
Feb 11, 2020
Merged
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 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);
}
}