From 35b5b2ef5d78aa3984d51ae1b7c705575a8b513d Mon Sep 17 00:00:00 2001 From: Qiang Xue Date: Tue, 31 Dec 2013 17:08:50 -0500 Subject: [PATCH] fixed profiling panel sorting. --- extensions/yii/debug/models/search/Profile.php | 4 ++-- extensions/yii/debug/panels/ProfilingPanel.php | 24 +++++++++++----------- .../debug/views/default/panels/profile/detail.php | 16 +++++++++++++-- 3 files changed, 28 insertions(+), 16 deletions(-) diff --git a/extensions/yii/debug/models/search/Profile.php b/extensions/yii/debug/models/search/Profile.php index ef630a3..945683b 100644 --- a/extensions/yii/debug/models/search/Profile.php +++ b/extensions/yii/debug/models/search/Profile.php @@ -53,9 +53,9 @@ class Profile extends Base 'pageSize' => 10, ], 'sort' => [ - 'attributes' => ['category', 'info', 'duration'], + 'attributes' => ['category', 'seq', 'duration', 'info'], 'defaultOrder' => [ - 'duration' => SORT_DESC, + 'seq' => SORT_ASC, ], ], ]); diff --git a/extensions/yii/debug/panels/ProfilingPanel.php b/extensions/yii/debug/panels/ProfilingPanel.php index 71b76aa..740a98c 100644 --- a/extensions/yii/debug/panels/ProfilingPanel.php +++ b/extensions/yii/debug/panels/ProfilingPanel.php @@ -61,7 +61,7 @@ class ProfilingPanel extends Panel /** * Calculates given request profile messages timings. - * @return array timings + * @return array timings [token, category, timestamp, traces, nesting level, elapsed time] */ protected function calculateTimings() { @@ -75,21 +75,19 @@ class ProfilingPanel extends Panel foreach ($messages as $i => $log) { list($token, $level, $category, $timestamp, $traces) = $log; + $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[] = [count($stack), $token, $category, $timestamp - $last[3], $traces]; + $timings[$last[5]] = [$last[0], $last[2], $last[3], $last[4], count($stack), $timestamp - $last[3]]; } } } - $now = microtime(true); - while (($last = array_pop($stack)) !== null) { - $timings[] = [count($stack), $last[0], $last[2], $now - $last[3], $last[4]]; - } + ksort($timings); - return $this->_timings = $timings; + return $this->_timings = array_values($timings); } public function save() @@ -113,12 +111,14 @@ class ProfilingPanel extends Panel $this->_models = []; $timings = $this->calculateTimings(); - foreach($timings as $profileTiming) { + foreach($timings as $seq => $profileTiming) { $this->_models[] = [ - 'duration' => $profileTiming[3] * 1000, #in milliseconds - 'category' => $profileTiming[2], - 'info' => $profileTiming[1], - 'level' => $profileTiming[0], + 'duration' => $profileTiming[5] * 1000, // in milliseconds + 'category' => $profileTiming[1], + 'info' => $profileTiming[0], + 'level' => $profileTiming[4], + 'timestamp' => $profileTiming[2], + 'seq' => $seq, ]; } } diff --git a/extensions/yii/debug/views/default/panels/profile/detail.php b/extensions/yii/debug/views/default/panels/profile/detail.php index fdae596..485d6af 100644 --- a/extensions/yii/debug/views/default/panels/profile/detail.php +++ b/extensions/yii/debug/views/default/panels/profile/detail.php @@ -1,4 +1,4 @@ - @@ -13,10 +13,22 @@ echo GridView::widget([ 'columns' => [ ['class' => 'yii\grid\SerialColumn'], [ + 'attribute' => 'seq', + 'label' => 'Time', + 'value' => function ($data) { + $timeInSeconds = $data['timestamp'] / 1000; + $millisecondsDiff = (int)(($timeInSeconds - (int)$timeInSeconds) * 1000); + return date('H:i:s.',$timeInSeconds) . sprintf('%03d',$millisecondsDiff); + }, + ], + [ 'attribute' => 'duration', 'value' => function ($data) { return sprintf('%.1f ms',$data['duration']); }, + 'options' => [ + 'width' => '10%', + ], ], 'category', [ @@ -31,4 +43,4 @@ echo GridView::widget([ ], ], ]); -?> \ No newline at end of file +?>