mirror of
https://github.com/dg/dibi.git
synced 2025-08-06 14:16:39 +02:00
Tracy\Panel: one panel is used per connection
This commit is contained in:
@@ -100,20 +100,24 @@ class Panel implements Tracy\IBarPanel
|
|||||||
*/
|
*/
|
||||||
public function getPanel()
|
public function getPanel()
|
||||||
{
|
{
|
||||||
|
if (!$this->events) {
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
$totalTime = $s = NULL;
|
$totalTime = $s = NULL;
|
||||||
$h = 'htmlSpecialChars';
|
|
||||||
foreach ($this->events as $event) {
|
foreach ($this->events as $event) {
|
||||||
$totalTime += $event->time;
|
$totalTime += $event->time;
|
||||||
|
$connection = $event->connection;
|
||||||
$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 === Event::SELECT) {
|
if ($this->explain && $event->type === Event::SELECT) {
|
||||||
try {
|
try {
|
||||||
$backup = [$event->connection->onEvent, \dibi::$numOfQueries, \dibi::$totalTime];
|
$backup = [$connection->onEvent, \dibi::$numOfQueries, \dibi::$totalTime];
|
||||||
$event->connection->onEvent = NULL;
|
$connection->onEvent = NULL;
|
||||||
$cmd = is_string($this->explain) ? $this->explain : ($event->connection->getConfig('driver') === 'oracle' ? 'EXPLAIN PLAN FOR' : 'EXPLAIN');
|
$cmd = is_string($this->explain) ? $this->explain : ($connection->getConfig('driver') === 'oracle' ? 'EXPLAIN PLAN FOR' : 'EXPLAIN');
|
||||||
$explain = @Helpers::dump($event->connection->nativeQuery("$cmd $event->sql"), TRUE);
|
$explain = @Helpers::dump($connection->nativeQuery("$cmd $event->sql"), TRUE);
|
||||||
} catch (Dibi\Exception $e) {
|
} catch (Dibi\Exception $e) {
|
||||||
}
|
}
|
||||||
list($event->connection->onEvent, \dibi::$numOfQueries, \dibi::$totalTime) = $backup;
|
list($connection->onEvent, \dibi::$numOfQueries, \dibi::$totalTime) = $backup;
|
||||||
}
|
}
|
||||||
|
|
||||||
$s .= '<tr><td>' . sprintf('%0.3f', $event->time * 1000);
|
$s .= '<tr><td>' . sprintf('%0.3f', $event->time * 1000);
|
||||||
@@ -131,17 +135,18 @@ class Panel implements Tracy\IBarPanel
|
|||||||
$s .= Tracy\Helpers::editorLink($event->source[0], $event->source[1]);//->class('tracy-DibiProfiler-source');
|
$s .= Tracy\Helpers::editorLink($event->source[0], $event->source[1]);//->class('tracy-DibiProfiler-source');
|
||||||
}
|
}
|
||||||
|
|
||||||
$s .= "</td><td>{$event->count}</td><td>{$h($event->connection->getConfig('driver') . '/' . $event->connection->getConfig('name'))}</td></tr>";
|
$s .= "</td><td>{$event->count}</td></tr>";
|
||||||
}
|
}
|
||||||
|
|
||||||
return empty($this->events) ? '' :
|
return '<style> #tracy-debug td.tracy-DibiProfiler-sql { background: white !important }
|
||||||
'<style> #tracy-debug td.tracy-DibiProfiler-sql { background: white !important }
|
|
||||||
#tracy-debug .tracy-DibiProfiler-source { color: #999 !important }
|
#tracy-debug .tracy-DibiProfiler-source { color: #999 !important }
|
||||||
#tracy-debug tracy-DibiProfiler tr table { margin: 8px 0; max-height: 150px; overflow:auto } </style>
|
#tracy-debug tracy-DibiProfiler tr table { margin: 8px 0; max-height: 150px; overflow:auto } </style>
|
||||||
<h1>Queries: ' . count($this->events) . ($totalTime === NULL ? '' : sprintf(', time: %0.3f ms', $totalTime * 1000)) . '</h1>
|
<h1>Queries: ' . count($this->events)
|
||||||
|
. ($totalTime === NULL ? '' : sprintf(', time: %0.3f ms', $totalTime * 1000)) . ', '
|
||||||
|
. htmlSpecialChars($connection->getConfig('driver') . ($connection->getConfig('name') ? '/' . $connection->getConfig('name') : '')) . '</h1>
|
||||||
<div class="tracy-inner tracy-DibiProfiler">
|
<div class="tracy-inner tracy-DibiProfiler">
|
||||||
<table>
|
<table>
|
||||||
<tr><th>Time ms</th><th>SQL Statement</th><th>Rows</th><th>Connection</th></tr>' . $s . '
|
<tr><th>Time ms</th><th>SQL Statement</th><th>Rows</th></tr>' . $s . '
|
||||||
</table>
|
</table>
|
||||||
</div>';
|
</div>';
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user