1
0
mirror of https://github.com/dg/dibi.git synced 2025-08-06 06:07:39 +02:00

Merge pull request #56 from Andrewsville/multiple-connections-nettepanel-fix

Fixed NettePanel output for multiple connections
This commit is contained in:
David Grudl
2012-02-06 09:04:27 -08:00
3 changed files with 15 additions and 5 deletions

View File

@@ -101,9 +101,11 @@ class DibiNettePanel extends DibiObject implements IBarPanel
*/ */
public function getTab() public function getTab()
{ {
$event = reset($this->events);
return '<span title="dibi"><img src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAQAAAC1+jfqAAAABGdBTUEAAK/INwWK6QAAABl0RVh0U29mdHdhcmUAQWRvYmUgSW1hZ2VSZWFkeXHJZTwAAAEYSURBVBgZBcHPio5hGAfg6/2+R980k6wmJgsJ5U/ZOAqbSc2GnXOwUg7BESgLUeIQ1GSjLFnMwsKGGg1qxJRmPM97/1zXFAAAAEADdlfZzr26miup2svnelq7d2aYgt3rebl585wN6+K3I1/9fJe7O/uIePP2SypJkiRJ0vMhr55FLCA3zgIAOK9uQ4MS361ZOSX+OrTvkgINSjS/HIvhjxNNFGgQsbSmabohKDNoUGLohsls6BaiQIMSs2FYmnXdUsygQYmumy3Nhi6igwalDEOJEjPKP7CA2aFNK8Bkyy3fdNCg7r9/fW3jgpVJbDmy5+PB2IYp4MXFelQ7izPrhkPHB+P5/PjhD5gCgCenx+VR/dODEwD+A3T7nqbxwf1HAAAAAElFTkSuQmCC" />' return '<span title="dibi"><img src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAQAAAC1+jfqAAAABGdBTUEAAK/INwWK6QAAABl0RVh0U29mdHdhcmUAQWRvYmUgSW1hZ2VSZWFkeXHJZTwAAAEYSURBVBgZBcHPio5hGAfg6/2+R980k6wmJgsJ5U/ZOAqbSc2GnXOwUg7BESgLUeIQ1GSjLFnMwsKGGg1qxJRmPM97/1zXFAAAAEADdlfZzr26miup2svnelq7d2aYgt3rebl585wN6+K3I1/9fJe7O/uIePP2SypJkiRJ0vMhr55FLCA3zgIAOK9uQ4MS361ZOSX+OrTvkgINSjS/HIvhjxNNFGgQsbSmabohKDNoUGLohsls6BaiQIMSs2FYmnXdUsygQYmumy3Nhi6igwalDEOJEjPKP7CA2aFNK8Bkyy3fdNCg7r9/fW3jgpVJbDmy5+PB2IYp4MXFelQ7izPrhkPHB+P5/PjhD5gCgCenx+VR/dODEwD+A3T7nqbxwf1HAAAAAElFTkSuQmCC" />'
. dibi::$numOfQueries . ' queries' . ($event ? $event->connection->numOfQueries : 0) . ' queries'
. (dibi::$totalTime ? ' / ' . sprintf('%0.1f', dibi::$totalTime * 1000) . 'ms' : '') . ($event && $event->connection->totalTime ? ' / ' . sprintf('%0.1f', $event->connection->totalTime * 1000) . 'ms' : '')
. '</span>'; . '</span>';
} }
@@ -121,12 +123,12 @@ class DibiNettePanel extends DibiObject implements IBarPanel
$explain = NULL; // EXPLAIN is called here to work SELECT FOUND_ROWS() $explain = NULL; // EXPLAIN is called here to work SELECT FOUND_ROWS()
if ($this->explain && $event->type === DibiEvent::SELECT) { if ($this->explain && $event->type === DibiEvent::SELECT) {
try { try {
$backup = array($event->connection->onEvent, dibi::$numOfQueries, dibi::$totalTime); $backup = array($event->connection->onEvent, $event->connection->numOfQueries, $event->connection->totalTime, dibi::$numOfQueries, dibi::$totalTime);
$event->connection->onEvent = NULL; $event->connection->onEvent = NULL;
$cmd = is_string($this->explain) ? $this->explain : ($event->connection->getConfig('driver') === 'oracle' ? 'EXPLAIN PLAN' : 'EXPLAIN'); $cmd = is_string($this->explain) ? $this->explain : ($event->connection->getConfig('driver') === 'oracle' ? 'EXPLAIN PLAN' : 'EXPLAIN');
$explain = dibi::dump($event->connection->nativeQuery("$cmd $event->sql"), TRUE); $explain = dibi::dump($event->connection->nativeQuery("$cmd $event->sql"), TRUE);
} catch (DibiException $e) {} } catch (DibiException $e) {}
list($event->connection->onEvent, dibi::$numOfQueries, dibi::$totalTime) = $backup; list($event->connection->onEvent, $event->connection->numOfQueries, $event->connection->totalTime, dibi::$numOfQueries, dibi::$totalTime) = $backup;
} }
$s .= '<tr><td>' . sprintf('%0.3f', $event->time * 1000); $s .= '<tr><td>' . sprintf('%0.3f', $event->time * 1000);
@@ -155,7 +157,7 @@ class DibiNettePanel extends DibiObject implements IBarPanel
'<style> #nette-debug td.nette-DibiProfiler-sql { background: white !important } '<style> #nette-debug td.nette-DibiProfiler-sql { background: white !important }
#nette-debug .nette-DibiProfiler-source { color: #999 !important } #nette-debug .nette-DibiProfiler-source { color: #999 !important }
#nette-debug nette-DibiProfiler tr table { margin: 8px 0; max-height: 150px; overflow:auto } </style> #nette-debug nette-DibiProfiler tr table { margin: 8px 0; max-height: 150px; overflow:auto } </style>
<h1>Queries: ' . dibi::$numOfQueries . (dibi::$totalTime === NULL ? '' : ', time: ' . sprintf('%0.3f', dibi::$totalTime * 1000) . ' ms') . '</h1> <h1>Queries: ' . (isset($event) ? $event->connection->numOfQueries : 0) . (isset($event) && $event->connection->totalTime === NULL ? '' : ', time: ' . sprintf('%0.3f', $event->connection->totalTime * 1000) . ' ms') . '</h1>
<div class="nette-inner nette-DibiProfiler"> <div class="nette-inner nette-DibiProfiler">
<table> <table>
<tr><th>Time&nbsp;ms</th><th>SQL Statement</th><th>Rows</th><th>Connection</th></tr>' . $s . ' <tr><th>Time&nbsp;ms</th><th>SQL Statement</th><th>Rows</th><th>Connection</th></tr>' . $s . '

View File

@@ -44,6 +44,12 @@ class DibiConnection extends DibiObject
/** @var DibiHashMap Substitutes for identifiers */ /** @var DibiHashMap Substitutes for identifiers */
private $substitutes; private $substitutes;
/** @var int Elapsed time for all queries */
public $totalTime = 0;
/** @var int Number or queries */
public $numOfQueries = 0;
/** /**
@@ -339,6 +345,7 @@ class DibiConnection extends DibiObject
$this->connected || $this->connect(); $this->connected || $this->connect();
$event = $this->onEvent ? new DibiEvent($this, DibiEvent::QUERY, $sql) : NULL; $event = $this->onEvent ? new DibiEvent($this, DibiEvent::QUERY, $sql) : NULL;
$this->numOfQueries++;
dibi::$numOfQueries++; dibi::$numOfQueries++;
dibi::$sql = $sql; dibi::$sql = $sql;
try { try {

View File

@@ -96,6 +96,7 @@ class DibiEvent
$this->time += microtime(TRUE); $this->time += microtime(TRUE);
dibi::$elapsedTime = $this->time; dibi::$elapsedTime = $this->time;
dibi::$totalTime += $this->time; dibi::$totalTime += $this->time;
$this->connection->totalTime += $this->time;
return $this; return $this;
} }