Skip to content

Commit

Permalink
Tracy\Panel: supports multiple connections [Closes dg#365]
Browse files Browse the repository at this point in the history
Partially reverts "Tracy\Panel: one panel is used per connection"

This reverts commit ae6c875.
  • Loading branch information
dg committed Oct 8, 2020
1 parent cc37121 commit df4cdda
Showing 1 changed file with 24 additions and 4 deletions.
28 changes: 24 additions & 4 deletions src/Dibi/Bridges/Tracy/Panel.php
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,15 @@ public function getPanel(): ?string
}

$totalTime = $s = null;

$singleConnection = reset($this->events)->connection;
foreach ($this->events as $event) {
if ($event->connection !== $singleConnection) {
$singleConnection = null;
break;
}
}

foreach ($this->events as $event) {
$totalTime += $event->time;
$connection = $event->connection;
Expand Down Expand Up @@ -135,20 +144,31 @@ public function getPanel(): ?string
$s .= Tracy\Helpers::editorLink($event->source[0], $event->source[1]);//->class('tracy-DibiProfiler-source');
}

$s .= "</td><td>{$event->count}</td></tr>";
$s .= "</td><td>{$event->count}</td>";
if (!$singleConnection) {
$s .= '<td>' . htmlspecialchars($this->getConnectionName($connection)) . '</td></tr>';
}
}

return '<style> #tracy-debug td.tracy-DibiProfiler-sql { background: white !important }
#tracy-debug .tracy-DibiProfiler-source { color: #999 !important }
#tracy-debug tracy-DibiProfiler tr table { margin: 8px 0; max-height: 150px; overflow:auto } </style>
<h1>Queries: ' . count($this->events)
. ($totalTime === null ? '' : ', time: ' . number_format($totalTime * 1000, 1, '.', '') . ' ms') . ', '
. htmlspecialchars($connection->getConfig('driver') . ($connection->getConfig('name') ? '/' . $connection->getConfig('name') : '')
. ($connection->getConfig('host') ? ' @ ' . $connection->getConfig('host') : '')) . '</h1>
. htmlspecialchars($this->getConnectionName($singleConnection)) . '</h1>
<div class="tracy-inner tracy-DibiProfiler">
<table>
<tr><th>Time&nbsp;ms</th><th>SQL Statement</th><th>Rows</th></tr>' . $s . '
<tr><th>Time&nbsp;ms</th><th>SQL Statement</th><th>Rows</th>' . (!$singleConnection ? '<th>Connection</th>' : '') . '</tr>
' . $s . '
</table>
</div>';
}


private function getConnectionName(Dibi\Connection $connection): string
{
return $connection->getConfig('driver')
. ($connection->getConfig('name') ? '/' . $connection->getConfig('name') : '')
. ($connection->getConfig('host') ? ' @ ' . $connection->getConfig('host') : '');
}
}

0 comments on commit df4cdda

Please sign in to comment.