mirror of
https://github.com/dg/dibi.git
synced 2025-08-07 14:46:50 +02:00
DibiProfiler: added [explain] info
This commit is contained in:
@@ -705,7 +705,7 @@ class dibi
|
||||
|
||||
$sql = wordwrap($sql, 100);
|
||||
$sql = htmlSpecialChars($sql);
|
||||
$sql = preg_replace("#\n{2,}#", "\n", $sql);
|
||||
$sql = preg_replace("#([ \t]*\r?\n){2,}#", "\n", $sql);
|
||||
|
||||
// syntax highlight
|
||||
$sql = preg_replace_callback("#(/\\*.+?\\*/)|(\\*\\*.+?\\*\\*)|(?<=[\\s,(])($keywords1)(?=[\\s,)])|(?<=[\\s,(=])($keywords2)(?=[\\s,)=])#is", array('dibi', 'highlightCallback'), $sql);
|
||||
|
@@ -89,7 +89,7 @@ class DibiProfiler extends DibiObject implements IDibiProfiler, /*Nette\*/IDebug
|
||||
{
|
||||
if ($event & self::QUERY) dibi::$numOfQueries++;
|
||||
dibi::$elapsedTime = FALSE;
|
||||
self::$tickets[] = array($connection, $event, trim($sql), -microtime(TRUE), NULL);
|
||||
self::$tickets[] = array($connection, $event, trim($sql), -microtime(TRUE), NULL, NULL);
|
||||
end(self::$tickets);
|
||||
return key(self::$tickets);
|
||||
}
|
||||
@@ -132,6 +132,13 @@ class DibiProfiler extends DibiObject implements IDibiProfiler, /*Nette\*/IDebug
|
||||
$connection->getConfig('driver') . '/' . $connection->getConfig('name')
|
||||
);
|
||||
|
||||
if ($event === self::SELECT) {
|
||||
try {
|
||||
$ticket[5] = dibi::dump($connection->setProfiler(NULL)->nativeQuery('EXPLAIN ' . $sql), TRUE);
|
||||
} catch (DibiException $e) {}
|
||||
$connection->setProfiler($this);
|
||||
}
|
||||
|
||||
if ($this->useFirebug && !headers_sent()) {
|
||||
header('X-Wf-Protocol-dibi: http://meta.wildfirehq.org/Protocol/JsonStream/0.2');
|
||||
header('X-Wf-dibi-Plugin-1: http://meta.firephp.org/Wildfire/Plugin/FirePHP/Library-FirePHPCore/0.2.0');
|
||||
@@ -233,14 +240,34 @@ class DibiProfiler extends DibiObject implements IDibiProfiler, /*Nette\*/IDebug
|
||||
{
|
||||
if (!dibi::$numOfQueries) return;
|
||||
|
||||
$content = '<h1>SQL queries: ' . dibi::$numOfQueries . (dibi::$totalTime === NULL ? '' : ', elapsed time: ' . sprintf('%0.3f', dibi::$totalTime * 1000) . ' ms') . '</h1>';
|
||||
$content .= '<table class="nette-inner">';
|
||||
foreach (self::$table as $i => $row) {
|
||||
if ($i === 0) {
|
||||
$content .= "<tr><th>$row[0]</th><th>$row[1]</th><th>$row[2]</th><th>$row[3]</th></tr>";
|
||||
} else {
|
||||
$content .= "<tr ".($i%2 ? 'class="nette-alt"':'')."><td>$row[0]</td><td><code>$row[1]</code></td><td>$row[2]</td><td>$row[3]</td></tr>";
|
||||
}
|
||||
$content = "
|
||||
<h1>SQL queries: " . dibi::$numOfQueries . (dibi::$totalTime === NULL ? '' : ', elapsed time: ' . sprintf('%0.3f', dibi::$totalTime * 1000) . ' ms') . "</h1>
|
||||
|
||||
<style>
|
||||
#nette-debug-DibiProfiler td.dibi-sql { background: white }
|
||||
#nette-debug-DibiProfiler .nette-alt td.dibi-sql { background: #F5F5F5 }
|
||||
#nette-debug-DibiProfiler .dibi-sql div { display: none; margin-top: 10px; max-height: 150px; overflow:auto }
|
||||
</style>
|
||||
|
||||
<table class='nette-inner'>
|
||||
<tr>
|
||||
<th>Time</th><th>SQL Statement</th><th>Rows</th><th>Connection</th>
|
||||
</tr>
|
||||
";
|
||||
$i = 0; $classes = array('class="nette-alt"', '');
|
||||
foreach (self::$tickets as $ticket) {
|
||||
list($connection, $event, $sql, $time, $count, $explain) = $ticket;
|
||||
if (!($event & self::QUERY)) continue;
|
||||
$content .= "
|
||||
<tr {$classes[++$i%2]}>
|
||||
<td>" . sprintf('%0.3f', $time * 1000) . "
|
||||
<br><a href='#' class='nette-toggler' rel='#nette-debug-DibiProfiler-row-$i'>explain ►</a></td>
|
||||
<td class='dibi-sql'>" . dibi::dump(strlen($sql) > self::$maxLength ? substr($sql, 0, self::$maxLength) . '...' : $sql, TRUE) . "
|
||||
<div id='nette-debug-DibiProfiler-row-$i'>{$explain}</div></td>
|
||||
<td>{$count}</td>
|
||||
<td>" . htmlSpecialChars($connection->getConfig('driver') . '/' . $connection->getConfig('name')) . "</td>
|
||||
</tr>
|
||||
";
|
||||
}
|
||||
$content .= '</table>';
|
||||
return $content;
|
||||
|
File diff suppressed because one or more lines are too long
Reference in New Issue
Block a user