Skip to content

Commit

Permalink
added a configuraiton to allow the profiler to be enabled only when a…
Browse files Browse the repository at this point in the history
…n exception occurs
  • Loading branch information
fabpot committed Aug 31, 2010
1 parent 1e1a411 commit 60ea1ee
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 2 deletions.
Expand Up @@ -81,6 +81,12 @@ public function configLoad($config, ContainerBuilder $container)
$loader->load('profiling.xml');
$loader->load('collectors.xml');
}

if (isset($config['profiler']['only-exceptions'])) {
$container->setParameter('profiler_listener.only_exceptions', $config['profiler']['only-exceptions']);
} elseif (isset($config['profiler']['only_exceptions'])) {
$container->setParameter('profiler_listener.only_exceptions', $config['profiler']['only_exceptions']);
}
} elseif ($container->hasDefinition('profiler')) {
$container->getDefinition('profiling')->clearTags();
}
Expand Down
Expand Up @@ -10,6 +10,7 @@
<parameter key="profiler.storage.file">%kernel.cache_dir%/profiler.db</parameter>
<parameter key="profiler.storage.lifetime">86400</parameter>
<parameter key="profiler_listener.class">Symfony\Component\HttpKernel\Profiler\ProfilerListener</parameter>
<parameter key="profiler_listener.only_exceptions">false</parameter>
</parameters>

<services>
Expand All @@ -27,6 +28,7 @@
<service id="profiler_listener" class="%profiler_listener.class%">
<tag name="kernel.listener" />
<argument type="service" id="profiler" />
<argument>%profiler_listener.only_exceptions%</argument>
</service>
</services>
</container>
11 changes: 9 additions & 2 deletions src/Symfony/Component/HttpKernel/Profiler/ProfilerListener.php
Expand Up @@ -25,15 +25,18 @@ class ProfilerListener
{
protected $profiler;
protected $exception;
protected $onlyException;

/**
* Constructor.
*
* @param Profiler $profiler A Profiler instance
* @param Profiler $profiler A Profiler instance
* @param Boolean $onlyException true if the profiler only collects data when an exception occurs, false otherwise
*/
public function __construct(Profiler $profiler)
public function __construct(Profiler $profiler, $onlyException = false)
{
$this->profiler = $profiler;
$this->onlyException = $onlyException;
}

/**
Expand Down Expand Up @@ -77,6 +80,10 @@ public function handleResponse(Event $event, Response $response)
return $response;
}

if ($this->onlyException && null === $this->exception) {
return $response;
}

$this->profiler->collect($event->getParameter('request'), $response, $this->exception);
$this->exception = null;

Expand Down

0 comments on commit 60ea1ee

Please sign in to comment.