From 60ea1eef698c6eae0d19465e00e9ff9be29bfc4b Mon Sep 17 00:00:00 2001 From: Fabien Potencier Date: Tue, 31 Aug 2010 22:22:31 +0200 Subject: [PATCH] added a configuraiton to allow the profiler to be enabled only when an exception occurs --- .../DependencyInjection/WebExtension.php | 6 ++++++ .../FrameworkBundle/Resources/config/profiling.xml | 2 ++ .../HttpKernel/Profiler/ProfilerListener.php | 11 +++++++++-- 3 files changed, 17 insertions(+), 2 deletions(-) diff --git a/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/WebExtension.php b/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/WebExtension.php index d2da5e87ee..328824d730 100644 --- a/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/WebExtension.php +++ b/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/WebExtension.php @@ -81,6 +81,12 @@ class WebExtension extends Extension $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(); } diff --git a/src/Symfony/Bundle/FrameworkBundle/Resources/config/profiling.xml b/src/Symfony/Bundle/FrameworkBundle/Resources/config/profiling.xml index c6bd63b390..22256b3622 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Resources/config/profiling.xml +++ b/src/Symfony/Bundle/FrameworkBundle/Resources/config/profiling.xml @@ -10,6 +10,7 @@ %kernel.cache_dir%/profiler.db 86400 Symfony\Component\HttpKernel\Profiler\ProfilerListener + false @@ -27,6 +28,7 @@ + %profiler_listener.only_exceptions% diff --git a/src/Symfony/Component/HttpKernel/Profiler/ProfilerListener.php b/src/Symfony/Component/HttpKernel/Profiler/ProfilerListener.php index 6f61e215ee..429bc9c2c6 100644 --- a/src/Symfony/Component/HttpKernel/Profiler/ProfilerListener.php +++ b/src/Symfony/Component/HttpKernel/Profiler/ProfilerListener.php @@ -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; } /** @@ -77,6 +80,10 @@ class ProfilerListener return $response; } + if ($this->onlyException && null === $this->exception) { + return $response; + } + $this->profiler->collect($event->getParameter('request'), $response, $this->exception); $this->exception = null;