Skip to content
This repository has been archived by the owner on Sep 6, 2021. It is now read-only.

add duration column with color mode for logging panel #130

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -62,5 +62,6 @@ See: [issues](https://github.com/malyshev/yii-debug-toolbar/issues)
<img src="https://dl.dropboxusercontent.com/u/6067542/yii-debug-toolbar/screenshot_1.png" alt="Screenshot1" />
<img src="https://dl.dropboxusercontent.com/u/6067542/yii-debug-toolbar/screenshot_2.png" alt="Screenshot2" />
<img src="https://dl.dropboxusercontent.com/u/6067542/yii-debug-toolbar/screenshot_3.png" alt="Screenshot3" />
<img src="https://dl.dropboxusercontent.com/sh/09k0c42xasghu6c/Zq0WrQpxw5/screenshot_4.png" alt="Screenshot4" />


63 changes: 63 additions & 0 deletions panels/YiiDebugToolbarPanelLogging.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
*
* @author Sergey Malyshev <[email protected]>
* @author Igor Golovanov <[email protected]>
* @author Nabi KaramAliZadeh <[email protected]>
* @version $Id$
* @package YiiDebugToolbar
* @since 1.1.7
Expand All @@ -34,6 +35,41 @@ class YiiDebugToolbarPanelLogging extends YiiDebugToolbarPanel
* @var array
*/
private $_logs;

/**
* Colors and max number of durations
* NOTE: all max numbers must be desc
* @author Nabi KaramAliZadeh <[email protected]>
*
* @var array
*/
public $colorsDuration = array(
array(
'textColor'=>'#fff',
'backgroundColor'=>'#c00',//red
'maxNumber'=>1,
),
array(
'textColor'=>'#000',
'backgroundColor'=>'#f60',//orange
'maxNumber'=>0.1,
),
array(
'textColor'=>'#000',
'backgroundColor'=>'#ff0',//yellow
'maxNumber'=>0.01,
),
array(
'textColor'=>'#000',
'backgroundColor'=>'#3c3',//green
'maxNumber'=>0.001,
),
array(
'textColor'=>'#000',
'backgroundColor'=>'#3cf',//blue
'maxNumber'=>0.0001,
),
);

/**
* {@inheritdoc}
Expand Down Expand Up @@ -114,4 +150,31 @@ protected function filterLogs()
}
return $logs;
}

/**
* Calculate duration execute between two trace
* @author Nabi KaramAliZadeh <[email protected]>
*
* @param float $new
* @param float $old
* @return array
*/
public function diffTime($new, $old)
{
$duration = $new - $old;
$duration = ($old===null) ? '-' : sprintf('%06f', $duration);
if($duration != '-'){
foreach($this->colorsDuration as $item){
if($duration >= $item['maxNumber']){
$return = $item;
break;
}
}
}else{
$return['textColor'] = '#000';
$return['backgroundColor'] = '#fff';
}
$return['duration'] = $duration;
return $return;
}
}
8 changes: 8 additions & 0 deletions views/panels/logging.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,23 @@
<th><?php echo YiiDebug::t('Level')?></th>
<th><?php echo YiiDebug::t('Category')?></th>
<th><?php echo YiiDebug::t('Time')?></th>
<th>Duration<br />
<?php foreach($this->colorsDuration as $item) :?>
<span style="background-color:<?php echo $item['backgroundColor']; ?>; width:9px; height:9px; display:block; float:left; margin:1px;"></span>
<?php endforeach; ?>
</th>
</tr>
</thead>
<tbody>
<?php $old=null; ?>
<?php foreach($logs as $id=>$entry): ?>
<?php $r=$this->diffTime($entry[3], $old); $old=$entry[3]; ?>
<tr>
<td data-ydtb-data-type="varchar"><?php echo nl2br($entry[0]) ?></td>
<td data-ydtb-data-type="char"><?php echo $entry[1]; ?></td>
<td data-ydtb-data-type="char"><?php echo $entry[2] ?></td>
<td data-ydtb-data-type="number"><?php echo date('H:i:s.',$entry[3]).sprintf('%06d',(int)(($entry[3]-(int)$entry[3])*1000000));?></td>
<td style="color:<?php echo $r['textColor']; ?>; background-color:<?php echo $r['backgroundColor']; ?>;"><?php echo $r['duration']; ?></td>
</tr>
<?php endforeach; ?>
</tbody>
Expand Down