Added more information to the Propel panel by using the Propel logger

This commit is contained in:
William DURAND 2011-04-08 01:16:09 +02:00
parent e9cbf82de1
commit fe58d40a38
4 changed files with 118 additions and 3 deletions

View file

@ -45,7 +45,8 @@ class PropelDataCollector extends DataCollector
public function collect(Request $request, Response $response, \Exception $exception = null)
{
$this->data = array(
'queries' => $this->logger->getQueries(),
'queries' => $this->buildQueries(),
'querycount' => \Propel::getConnection($this->connectionName)->getQueryCount(),
'connectionName' => $this->connectionName,
);
}
@ -60,6 +61,36 @@ class PropelDataCollector extends DataCollector
return 'propel';
}
/**
* Creates an array of Build objects.
*
* @return array An array of Build objects
*/
private function buildQueries()
{
$queries = array();
$config = \Propel::getConfiguration(\PropelConfiguration::TYPE_OBJECT);
$outerGlue = $config->getParameter('debugpdo.logging.outerglue', ' | ');
$innerGlue = $config->getParameter('debugpdo.logging.innerglue', ': ');
foreach($this->logger->getQueries() as $q)
{
$parts = explode($outerGlue, $q);
$times = explode($innerGlue, $parts[0]);
$memories = explode($innerGlue, $parts[1]);
$sql = trim($parts[2]);
$time = trim($times[1]);
$memory = trim($memories[1]);
$queries[] = new Query($sql, $time, $memory);
}
return $queries;
}
/**
* Returns queries.
*
@ -77,7 +108,7 @@ class PropelDataCollector extends DataCollector
*/
public function getQueryCount()
{
return count($this->data['queries']);
return count($this->data['querycount']);
}
/**

73
DataCollector/Query.php Normal file
View file

@ -0,0 +1,73 @@
<?php
namespace Propel\PropelBundle\DataCollector;
/**
* A Query class is designed to represent query information.
*
* @author William DURAND <william.durand1@gmail.com>
*/
class Query
{
/**
* SQL statement
* @var string
*/
private $sql;
/**
* Execution time
*
* @var string
*/
private $time;
/**
* Memory
*
* @var string
*/
private $memory;
/**
* Default constructor
*
* @param $sql A SQL statement
* @param $time An execution time
* @param $memory Memory used
*/
public function __construct($sql, $time, $memory)
{
$this->sql = $sql;
$this->time = $time;
$this->memory = $memory;
}
/**
* Getter
*
* @return string SQL statement
*/
public function getSql()
{
return $this->sql;
}
/**
* Getter
*
* @return string Execution time
*/
public function getTime()
{
return $this->time;
}
/**
* Getter
*
* @return string Memory
*/
public function getMemory()
{
return $this->memory;
}
}

View file

@ -27,6 +27,14 @@ class PropelBundle extends Bundle
\Propel::setConfiguration($this->container->get('propel.configuration'));
if ($this->container->getParameter('propel.logging')) {
$this
->container
->get('propel.configuration')
->setParameter('debugpdo.logging.details', array(
'time' => array('enabled' => true),
'mem' => array('enabled' => true),
));
\Propel::setLogger($this->container->get('propel.logger'));
}

View file

@ -44,7 +44,10 @@
{% else %}
{% for query in collector.queries %}
<tr>
<td><code>{{ query }}</code></td>
<td>
<code>{{ query.sql }}</code>
<div style="color: gray;font-size: 0.9em;">Time: {{ query.time }} - Memory: {{ query.memory }}</div>
</td>
</tr>
{% endfor %}
{% endif %}