Skip to content

Commit

Permalink
Merge pull request #4 from PostMix/feature/tideways_xhprof
Browse files Browse the repository at this point in the history
feat(xhprof): Implement tideways xhprof provider
  • Loading branch information
rez1dent3 committed Mar 2, 2020
2 parents f35699f + dfb3e91 commit 57fe2a8
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 2 deletions.
2 changes: 2 additions & 0 deletions config/config.php
Expand Up @@ -6,4 +6,6 @@
'path' => '/opt/xhprof',
'name' => 'xhprof',
'freq' => 1 / 1000,
'extension_name' => 'xhprof',
'provider' => \Bavix\XHProf\Providers\XHProfProvider::class,
];
31 changes: 31 additions & 0 deletions src/Provides/TidewaysProvider.php
@@ -0,0 +1,31 @@
<?php

namespace Bavix\XHProf\Providers;

use XHProfRuns_Default;

class TidewaysProvider implements ProviderInterface
{

/**
* @inheritDoc
*/
public function enable()
{
$path = config('xhprof.path');
include_once $path . '/xhprof_lib/utils/xhprof_lib.php';
include_once $path . '/xhprof_lib/utils/xhprof_runs.php';
tideways_xhprof_enable(config('xhprof.flags', 0));
}

/**
* @inheritDoc
*/
public function disable()
{
$data = tideways_xhprof_disable();
$runs = new XHProfRuns_Default();
$runs->save_run($data, config('xhprof.name'));
}

}
13 changes: 11 additions & 2 deletions src/Services/XHProfService.php
Expand Up @@ -3,6 +3,7 @@
namespace Bavix\XHProf\Services;

use Bavix\XHProf\Providers\ProviderInterface;
use Bavix\XHProf\Providers\TidewaysProvider;
use Bavix\XHProf\Providers\XHProfProvider;
use function extension_loaded;
use function mt_getrandmax;
Expand All @@ -21,7 +22,7 @@ class XHProfService
*/
public function __construct()
{
if (!extension_loaded('xhprof')) {
if (!extension_loaded(config('xhprof.extension_name', 'xhprof'))) {
return;
}

Expand All @@ -31,7 +32,15 @@ public function __construct()

$freq = config('xhprof.freq', 0.01);
if ($freq >= (mt_rand() / mt_getrandmax())) {
$this->provider = new XHProfProvider();
switch (config('xhprof.provider', XHProfProvider::class)) {
case TidewaysProvider::class:
$this->provider = new TidewaysProvider();
break;
default:
case XHProfProvider::class:
$this->provider = new XHProfProvider();
break;
}
}
}

Expand Down

0 comments on commit 57fe2a8

Please sign in to comment.