8000 merged branch willdurand/propel-stopwatch (PR #3352) · symfony/symfony@b8322b3 · GitHub
[go: up one dir, main page]

Skip to content

Commit b8322b3

Browse files
committed
merged branch willdurand/propel-stopwatch (PR #3352)
Commits ------- b3fd2fa [Propel] Added Propel to Stopwatch Discussion ---------- [Propel] Added Propel to Stopwatch I've added the Stopwatch feature, everything is ready on the PropelBundle. The trick is to log `prepare` queries in Propel, that way we got first the prepared statement, and then the executed query. That's why there is a `$isPrepare` boolean. I kept BC if people don't update the PropelBundle too. William --------------------------------------------------------------------------- by stof at 2012-02-14T12:16:51Z @willdurand toggling a flag for each call seems a bit hackish to me. Is there no better way to do it ? --------------------------------------------------------------------------- by willdurand at 2012-02-14T12:21:38Z Unfortunately no... But it's quite safe as we cannot change logged methods. There is neighter start/stop methods, nor typed messages. Le 14 févr. 2012 à 13:16, Christophe Coevoet<reply@reply.github.com> a écrit : > @willdurand toggling a flag for each call seems a bit hackish to me. Is there no better way to do it ? > > --- > Reply to this email directly or view it on GitHub: > #3352 (comment) --------------------------------------------------------------------------- by stof at 2012-02-14T12:26:04Z @willdurand then let's use this for propel 1. But please improve the logging interface for Propel 2 :) --------------------------------------------------------------------------- by willdurand at 2012-02-14T12:34:28Z Sure! I've added that on my todolist… 2012/2/14 Christophe Coevoet < reply@reply.github.com > > @willdurand then let's use this for propel 1. But please improve the > logging interface for Propel 2 :) > > --- > Reply to this email directly or view it on GitHub: > #3352 (comment) >
2 parents 9f05d4a + b3fd2fa commit b8322b3

File tree

2 files changed

+34
-6
lines changed

2 files changed

+34
-6
lines changed

src/Symfony/Bridge/Propel1/Logger/PropelLogger.php

Lines changed: 33 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
namespace Symfony\Bridge\Propel1\Logger;
1313

14+
use Symfony\Component\HttpKernel\Debug\Stopwatch;
1415
use Symfony\Component\HttpKernel\Log\LoggerInterface;
1516

1617
/**
@@ -31,15 +32,25 @@ class PropelLogger
3132
*/
3233
protected $queries;
3334

35+
/**
36+
* @var \Symfony\Component\HttpKernel\Debug\Stopwatch
37+
*/
38+
protected $stopwatch;
39+
40+
private $isPrepare;
41+
3442
/**
3543
* Constructor.
3644
*
3745
* @param LoggerInterface $logger A LoggerInterface instance
46+
* @param Stopwatch $stopwatch A Stopwatch instance
3847
*/
39-
public function __construct(LoggerInterface $logger = null)
48+
public function __construct(LoggerInterface $logger = null, Stopwatch $stopwatch = null)
4049
{
41-
$this->logger = $logger;
42-
$this->queries = array();
50+
$this->logger = $logger;
51+
$this->queries = array();
52+
$this->stopwatch = $stopwatch;
53+
$this->isPrepare = true;
4354
}
4455

4556
/**
@@ -121,9 +132,25 @@ public function info($message)
121132
*/
122133
public function debug($message)
123134
{
124-
$this->queries[] = $message;
125-
if (null !== $this->logger) {
126-
$this->logger->debug($message);
135+
$add = true;
136+
137+
if (null !== $this->stopwatch) {
138+
if ($this->isPrepare) {
139+
$this->stopwatch->start('propel', 'propel');
140+
$this->isPrepare = false;
141+
142+
$add = false;
143+
} else {
144+
$this->stopwatch->stop('propel');
145+
$this->isPrepare = true;
146+
}
147+
}
148+
149+
if ($add) {
150+
$this->queries[] = $message;
151+
if (null !== $this->logger) {
152+
$this->logger->debug($message);
153+
}
127154
}
128155
}
129156

src/Symfony/Bundle/WebProfilerBundle/Resources/views/Collector/time.html.twig

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
'event_listener_loading': '#add',
99
'template': '#dd3',
1010
'doctrine': '#d3d',
11+
'propel': '#f4d',
1112
'child_sections': '#eed',
1213
} %}
1314
{% endif %}

0 commit comments

Comments
 (0)
0