Skip to content
This repository has been archived by the owner on Aug 2, 2022. It is now read-only.

Commit

Permalink
Merge pull request #73 from ewgRa/require_extension_exists
Browse files Browse the repository at this point in the history
require_extension_exists configuration option
  • Loading branch information
jonaswouters committed Jun 4, 2015
2 parents 5855fa3 + 1e007e0 commit ba79294
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 2 deletions.
13 changes: 12 additions & 1 deletion DataCollector/XhprofCollector.php
Expand Up @@ -35,6 +35,7 @@ public function __construct(ContainerInterface $container, $logger = null, Doctr

$this->logger = $logger;
$this->doctrine = $doctrine;
$this->data['xhprof_extension_exists'] = function_exists('xhprof_enable');
$this->data['xhprof'] = null;
$this->data['source'] = null;
$this->data['xhprof_url'] = null;
Expand All @@ -59,7 +60,7 @@ public function collect(Request $request, Response $response, \Exception $except
*/
public function startProfiling(Request $request = null)
{
if (mt_rand(1, $this->container->getParameter('jns_xhprof.sample_size')) != 1) {
if (!function_exists('xhprof_enable') || mt_rand(1, $this->container->getParameter('jns_xhprof.sample_size')) != 1) {
return false;
}

Expand Down Expand Up @@ -227,6 +228,16 @@ public function getName()
return 'xhprof';
}

/**
* Gets the XHProf extension exists or not.
*
* @return boolean Extension exists or not
*/
public function getXhprofExtensionExists()
{
return $this->data['xhprof_extension_exists'];
}

/**
* Gets the run id.
*
Expand Down
1 change: 1 addition & 0 deletions DependencyInjection/Configuration.php
Expand Up @@ -40,6 +40,7 @@ public function getConfigTree()
->arrayNode('exclude_patterns')->prototype('scalar')->end()->end()
->scalarNode('sample_size')->defaultValue(1)->end()
->scalarNode('enabled')->defaultFalse()->end()
->scalarNode('require_extension_exists')->defaultTrue()->end()
->scalarNode('skip_builtin_functions')->defaultFalse()->end()
->scalarNode('request_query_argument')->defaultFalse()->end()
->scalarNode('response_header')->defaultValue('X-Xhprof-Url')->end()
Expand Down
2 changes: 1 addition & 1 deletion DependencyInjection/JnsXhprofExtension.php
Expand Up @@ -32,7 +32,7 @@ public function load(array $configs, ContainerBuilder $container)
$config = $processor->process($configuration->getConfigTree(), $configs);

if ($config['enabled']) {
if (function_exists('xhprof_enable')) {
if (!$config['require_extension_exists'] || function_exists('xhprof_enable')) {
$this->loadDefaults($container);

foreach ($config as $key => $value) {
Expand Down
4 changes: 4 additions & 0 deletions Resources/views/Collector/xhprof.html.twig
Expand Up @@ -11,6 +11,10 @@
{% spaceless %}
<span>Not profiling</span>
{% endspaceless %}
{% if not collector.xhprofextensionexists %}
<br />
<span style="color:red;">Xhprof extension not exists</span>
{% endif %}
{% endset %}
{% endif %}
{% set icon %}
Expand Down

0 comments on commit ba79294

Please sign in to comment.