From ae6c8756b67496a06c71af912bacaf7ca97c5fc3 Mon Sep 17 00:00:00 2001 From: David Grudl Date: Fri, 9 Jun 2017 12:33:38 +0200 Subject: [PATCH] Tracy\Panel: one panel is used per connection --- src/Dibi/Bridges/Tracy/Panel.php | 27 ++++++++++++++++----------- 1 file changed, 16 insertions(+), 11 deletions(-) diff --git a/src/Dibi/Bridges/Tracy/Panel.php b/src/Dibi/Bridges/Tracy/Panel.php index b4467606..02452604 100644 --- a/src/Dibi/Bridges/Tracy/Panel.php +++ b/src/Dibi/Bridges/Tracy/Panel.php @@ -100,20 +100,24 @@ class Panel implements Tracy\IBarPanel */ public function getPanel() { + if (!$this->events) { + return NULL; + } + $totalTime = $s = NULL; - $h = 'htmlSpecialChars'; foreach ($this->events as $event) { $totalTime += $event->time; + $connection = $event->connection; $explain = NULL; // EXPLAIN is called here to work SELECT FOUND_ROWS() if ($this->explain && $event->type === Event::SELECT) { try { - $backup = [$event->connection->onEvent, \dibi::$numOfQueries, \dibi::$totalTime]; - $event->connection->onEvent = NULL; - $cmd = is_string($this->explain) ? $this->explain : ($event->connection->getConfig('driver') === 'oracle' ? 'EXPLAIN PLAN FOR' : 'EXPLAIN'); - $explain = @Helpers::dump($event->connection->nativeQuery("$cmd $event->sql"), TRUE); + $backup = [$connection->onEvent, \dibi::$numOfQueries, \dibi::$totalTime]; + $connection->onEvent = NULL; + $cmd = is_string($this->explain) ? $this->explain : ($connection->getConfig('driver') === 'oracle' ? 'EXPLAIN PLAN FOR' : 'EXPLAIN'); + $explain = @Helpers::dump($connection->nativeQuery("$cmd $event->sql"), TRUE); } catch (Dibi\Exception $e) { } - list($event->connection->onEvent, \dibi::$numOfQueries, \dibi::$totalTime) = $backup; + list($connection->onEvent, \dibi::$numOfQueries, \dibi::$totalTime) = $backup; } $s .= '' . 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 .= "{$event->count}{$h($event->connection->getConfig('driver') . '/' . $event->connection->getConfig('name'))}"; + $s .= "{$event->count}"; } - return empty($this->events) ? '' : - ' -

Queries: ' . count($this->events) . ($totalTime === NULL ? '' : sprintf(', time: %0.3f ms', $totalTime * 1000)) . '

+

Queries: ' . count($this->events) + . ($totalTime === NULL ? '' : sprintf(', time: %0.3f ms', $totalTime * 1000)) . ', ' + . htmlSpecialChars($connection->getConfig('driver') . ($connection->getConfig('name') ? '/' . $connection->getConfig('name') : '')) . '

- ' . $s . ' + ' . $s . '
Time msSQL StatementRowsConnection
Time msSQL StatementRows
'; }