Skip to content

Commit

Permalink
Added call stack display for DB debug panel.
Browse files Browse the repository at this point in the history
  • Loading branch information
qiangxue committed Jul 24, 2013
1 parent 915a3cd commit e330899
Showing 1 changed file with 13 additions and 4 deletions.
17 changes: 13 additions & 4 deletions framework/yii/debug/panels/DbPanel.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,16 @@ public function getDetail()
$rows = array();
foreach ($timings as $timing) {
$duration = sprintf('%.1f ms', $timing[3] * 1000);
$procedure = str_repeat('<span class="indent">→</span>', $timing[0]) . Html::encode($timing[1]);
$procedure = Html::encode($timing[1]);
$traces = $timing[4];
if (!empty($traces)) {
$procedure .= Html::ul($traces, array(
'class' => 'trace',
'item' => function ($trace) {
return "<li>{$trace['file']}({$trace['line']})</li>";
},
));
}
$rows[] = "<tr><td style=\"width: 80px;\">$duration</td><td>$procedure</td>";
}
$rows = implode("\n", $rows);
Expand Down Expand Up @@ -85,20 +94,20 @@ protected function calculateTimings()
$stack = array();
foreach ($messages as $i => $log) {
list($token, $level, $category, $timestamp) = $log;
$log[4] = $i;
$log[5] = $i;
if ($level == Logger::LEVEL_PROFILE_BEGIN) {
$stack[] = $log;
} elseif ($level == Logger::LEVEL_PROFILE_END) {
if (($last = array_pop($stack)) !== null && $last[0] === $token) {
$timings[$last[4]] = array(count($stack), $token, $last[3], $timestamp - $last[3]);
$timings[$last[5]] = array(count($stack), $token, $last[3], $timestamp - $last[3], $last[4]);
}
}
}

$now = microtime(true);
while (($last = array_pop($stack)) !== null) {
$delta = $now - $last[3];
$timings[$last[4]] = array(count($stack), $last[0], $last[2], $delta);
$timings[$last[5]] = array(count($stack), $last[0], $last[2], $delta, $last[4]);
}
ksort($timings);
return $this->_timings = $timings;
Expand Down

0 comments on commit e330899

Please sign in to comment.