[DoctrineMongoDBBundle] added a quick profiler panel
This commit is contained in:
parent
5f9c365971
commit
e6bff045c9
@ -27,6 +27,7 @@ class DoctrineMongoDBDataCollector extends DataCollector
|
||||
public function collect(Request $request, Response $response, \Exception $exception = null)
|
||||
{
|
||||
$this->data['nb_queries'] = $this->logger->getNbQueries();
|
||||
$this->data['queries'] = $this->logger->getQueries();
|
||||
}
|
||||
|
||||
public function getQueryCount()
|
||||
@ -34,6 +35,11 @@ class DoctrineMongoDBDataCollector extends DataCollector
|
||||
return $this->data['nb_queries'];
|
||||
}
|
||||
|
||||
public function getQueries()
|
||||
{
|
||||
return $this->data['queries'];
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
|
@ -12,6 +12,8 @@ use Symfony\Component\Yaml\Yaml;
|
||||
*/
|
||||
class DoctrineMongoDBLogger
|
||||
{
|
||||
const LOG_PREFIX = 'MongoDB query: ';
|
||||
|
||||
protected $logger;
|
||||
protected $nbQueries;
|
||||
|
||||
@ -26,7 +28,7 @@ class DoctrineMongoDBLogger
|
||||
++$this->nbQueries;
|
||||
|
||||
if (null !== $this->logger) {
|
||||
$this->logger->info(static::formatQuery($query));
|
||||
$this->logger->info(static::LOG_PREFIX.static::formatQuery($query));
|
||||
}
|
||||
}
|
||||
|
||||
@ -35,6 +37,26 @@ class DoctrineMongoDBLogger
|
||||
return $this->nbQueries;
|
||||
}
|
||||
|
||||
public function getQueries()
|
||||
{
|
||||
$logger = $this->logger->getDebugLogger();
|
||||
|
||||
if (!$logger) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$offset = strlen(static::LOG_PREFIX);
|
||||
$mapper = function($log) use($offset)
|
||||
{
|
||||
if (0 === strpos($log['message'], DoctrineMongoDBLogger::LOG_PREFIX)) {
|
||||
return substr($log['message'], $offset);
|
||||
}
|
||||
};
|
||||
|
||||
// map queries from logs, remove empty entries and re-index the array
|
||||
return array_values(array_filter(array_map($mapper, $logger->getLogs())));
|
||||
}
|
||||
|
||||
/**
|
||||
* Formats the supplied query array recursively.
|
||||
*
|
||||
|
@ -1,2 +1,3 @@
|
||||
<div class="count"><?php echo $data->getQueryCount() ?></div>
|
||||
<img style="margin: 0 5px 0 0; vertical-align: middle; width: 32px" alt="" src="<?php echo $view->get('assets')->getUrl('bundles/webprofiler/images/db.png') ?>" />
|
||||
Doctrine MongoDB
|
@ -1,6 +1,17 @@
|
||||
<h2>Queries</h2>
|
||||
|
||||
<?php if (0 == $data->getQueryCount()): ?>
|
||||
<?php if (false === $queries = $data->getQueries()): ?>
|
||||
<em>Query logging is disabled.</em>
|
||||
<?php elseif (0 == $data->getQueryCount()): ?>
|
||||
<em>No queries.</em>
|
||||
<?php else: ?>
|
||||
<ul class="alt">
|
||||
<?php foreach ($queries as $i => $query): ?>
|
||||
<li class="<?php echo $i % 2 ? 'odd' : 'even' ?>">
|
||||
<div>
|
||||
<code><?php echo $query ?></code>
|
||||
</div>
|
||||
</li>
|
||||
<?php endforeach; ?>
|
||||
</ul>
|
||||
<?php endif; ?>
|
||||
|
Reference in New Issue
Block a user