From e33089960f8db67f41359c991f097b8895b24aca Mon Sep 17 00:00:00 2001 From: Qiang Xue Date: Tue, 23 Jul 2013 22:00:44 -0400 Subject: [PATCH] Added call stack display for DB debug panel. --- framework/yii/debug/panels/DbPanel.php | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/framework/yii/debug/panels/DbPanel.php b/framework/yii/debug/panels/DbPanel.php index e047f8d8909..dae155c496f 100644 --- a/framework/yii/debug/panels/DbPanel.php +++ b/framework/yii/debug/panels/DbPanel.php @@ -51,7 +51,16 @@ public function getDetail() $rows = array(); foreach ($timings as $timing) { $duration = sprintf('%.1f ms', $timing[3] * 1000); - $procedure = str_repeat('', $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 "
  • {$trace['file']}({$trace['line']})
  • "; + }, + )); + } $rows[] = "$duration$procedure"; } $rows = implode("\n", $rows); @@ -85,12 +94,12 @@ 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]); } } } @@ -98,7 +107,7 @@ protected function calculateTimings() $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;