From b3fd2fad9f679cd4cf011e1b46f1618636f8b1a3 Mon Sep 17 00:00:00 2001 From: William DURAND Date: Tue, 14 Feb 2012 12:08:37 +0100 Subject: [PATCH] [Propel] Added Propel to Stopwatch --- .../Bridge/Propel1/Logger/PropelLogger.php | 39 ++++++++++++++++--- .../Resources/views/Collector/time.html.twig | 1 + 2 files changed, 34 insertions(+), 6 deletions(-) diff --git a/src/Symfony/Bridge/Propel1/Logger/PropelLogger.php b/src/Symfony/Bridge/Propel1/Logger/PropelLogger.php index dade0cebfb..c5001db582 100644 --- a/src/Symfony/Bridge/Propel1/Logger/PropelLogger.php +++ b/src/Symfony/Bridge/Propel1/Logger/PropelLogger.php @@ -11,6 +11,7 @@ namespace Symfony\Bridge\Propel1\Logger; +use Symfony\Component\HttpKernel\Debug\Stopwatch; use Symfony\Component\HttpKernel\Log\LoggerInterface; /** @@ -31,15 +32,25 @@ class PropelLogger */ protected $queries; + /** + * @var \Symfony\Component\HttpKernel\Debug\Stopwatch + */ + protected $stopwatch; + + private $isPrepare; + /** * Constructor. * * @param LoggerInterface $logger A LoggerInterface instance + * @param Stopwatch $stopwatch A Stopwatch instance */ - public function __construct(LoggerInterface $logger = null) + public function __construct(LoggerInterface $logger = null, Stopwatch $stopwatch = null) { - $this->logger = $logger; - $this->queries = array(); + $this->logger = $logger; + $this->queries = array(); + $this->stopwatch = $stopwatch; + $this->isPrepare = true; } /** @@ -121,9 +132,25 @@ class PropelLogger */ public function debug($message) { - $this->queries[] = $message; - if (null !== $this->logger) { - $this->logger->debug($message); + $add = true; + + if (null !== $this->stopwatch) { + if ($this->isPrepare) { + $this->stopwatch->start('propel', 'propel'); + $this->isPrepare = false; + + $add = false; + } else { + $this->stopwatch->stop('propel'); + $this->isPrepare = true; + } + } + + if ($add) { + $this->queries[] = $message; + if (null !== $this->logger) { + $this->logger->debug($message); + } } } diff --git a/src/Symfony/Bundle/WebProfilerBundle/Resources/views/Collector/time.html.twig b/src/Symfony/Bundle/WebProfilerBundle/Resources/views/Collector/time.html.twig index 6a97c900b5..f04a4751cc 100644 --- a/src/Symfony/Bundle/WebProfilerBundle/Resources/views/Collector/time.html.twig +++ b/src/Symfony/Bundle/WebProfilerBundle/Resources/views/Collector/time.html.twig @@ -8,6 +8,7 @@ 'event_listener_loading': '#add', 'template': '#dd3', 'doctrine': '#d3d', + 'propel': '#f4d', 'child_sections': '#eed', } %} {% endif %}