Skip to content

Commit eb69e38

Browse files
pavarnosbarryvdh
authored andcommitted
add pdo connection name to time collector (php-debugbar#301)
so that we can see that a specific measure came from a pdo connection, and which connection that was.
1 parent b18f24d commit eb69e38

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

src/DebugBar/DataCollector/PDO/PDOCollector.php

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ public function collect()
9898
);
9999

100100
foreach ($this->connections as $name => $pdo) {
101-
$pdodata = $this->collectPDO($pdo, $this->timeCollector);
101+
$pdodata = $this->collectPDO($pdo, $this->timeCollector, $name);
102102
$data['nb_statements'] += $pdodata['nb_statements'];
103103
$data['nb_failed_statements'] += $pdodata['nb_failed_statements'];
104104
$data['accumulated_duration'] += $pdodata['accumulated_duration'];
@@ -120,10 +120,16 @@ public function collect()
120120
*
121121
* @param TraceablePDO $pdo
122122
* @param TimeDataCollector $timeCollector
123+
* @param string|null $connectionName the pdo connection (eg default | read | write)
123124
* @return array
124125
*/
125-
protected function collectPDO(TraceablePDO $pdo, TimeDataCollector $timeCollector = null)
126+
protected function collectPDO(TraceablePDO $pdo, TimeDataCollector $timeCollector = null, $connectionName = null)
126127
{
128+
if (empty($connectionName) || $connectionName == 'default') {
129+
$connectionName = 'pdo';
130+
} else {
131+
$connectionName = 'pdo ' . $connectionName;
132+
}
127133
$stmts = array();
128134
foreach ($pdo->getExecutedStatements() as $stmt) {
129135
$stmts[] = array(
@@ -143,7 +149,7 @@ protected function collectPDO(TraceablePDO $pdo, TimeDataCollector $timeCollecto
143149
'error_message' => $stmt->getErrorMessage()
144150
);
145151
if ($timeCollector !== null) {
146-
$timeCollector->addMeasure($stmt->getSql(), $stmt->getStartTime(), $stmt->getEndTime());
152+
$timeCollector->addMeasure($stmt->getSql(), $stmt->getStartTime(), $stmt->getEndTime(), array(), $connectionName);
147153
}
148154
}
149155

0 commit comments

Comments
 (0)