Mark
11 years ago
7 changed files with 182 additions and 46 deletions
@ -0,0 +1,75 @@ |
|||||||
|
<?php |
||||||
|
|
||||||
|
namespace yii\debug\models\search; |
||||||
|
|
||||||
|
use yii\data\ArrayDataProvider; |
||||||
|
use yii\debug\components\search\Filter; |
||||||
|
|
||||||
|
/** |
||||||
|
* Profile represents the model behind the search form about current request profiling log. |
||||||
|
*/ |
||||||
|
class Profile extends Base |
||||||
|
{ |
||||||
|
|
||||||
|
/** |
||||||
|
* @var string method attribute input search value |
||||||
|
*/ |
||||||
|
public $category; |
||||||
|
|
||||||
|
/** |
||||||
|
* @var integer info attribute input search value |
||||||
|
*/ |
||||||
|
public $info; |
||||||
|
|
||||||
|
public function rules() |
||||||
|
{ |
||||||
|
return [ |
||||||
|
[['category', 'info'], 'safe'], |
||||||
|
]; |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* @inheritdoc |
||||||
|
*/ |
||||||
|
public function attributeLabels() |
||||||
|
{ |
||||||
|
return [ |
||||||
|
'category' => 'Category', |
||||||
|
'info' => 'Info', |
||||||
|
]; |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* Returns data provider with filled models. Filter applied if needed. |
||||||
|
* @param array $params |
||||||
|
* @param array $models |
||||||
|
* @return \yii\data\ArrayDataProvider |
||||||
|
*/ |
||||||
|
public function search($params, $models) |
||||||
|
{ |
||||||
|
$dataProvider = new ArrayDataProvider([ |
||||||
|
'allModels' => $models, |
||||||
|
'pagination' => [ |
||||||
|
'pageSize' => 10, |
||||||
|
], |
||||||
|
'sort' => [ |
||||||
|
'attributes' => ['category','info','duration'], |
||||||
|
'defaultOrder' => [ |
||||||
|
'duration' => SORT_DESC, |
||||||
|
], |
||||||
|
], |
||||||
|
]); |
||||||
|
|
||||||
|
if (!($this->load($params) && $this->validate())) { |
||||||
|
return $dataProvider; |
||||||
|
} |
||||||
|
|
||||||
|
$filter = new Filter(); |
||||||
|
$this->addCondition($filter, 'category', true); |
||||||
|
$this->addCondition($filter, 'info', true); |
||||||
|
$dataProvider->allModels = $filter->filter($models); |
||||||
|
|
||||||
|
return $dataProvider; |
||||||
|
} |
||||||
|
|
||||||
|
} |
@ -1,6 +1,6 @@ |
|||||||
<?php if ($queryCount): ?> |
<?php if ($queryCount): ?> |
||||||
<div class="yii-debug-toolbar-block"> |
<div class="yii-debug-toolbar-block"> |
||||||
<a href="$url" title="Executed <?php echo $queryCount; ?> database queries which took <?php echo $queryTime; ?>.">
|
<a href="<?php echo $panel->getUrl();?>" title="Executed <?php echo $queryCount; ?> database queries which took <?php echo $queryTime; ?>.">
|
||||||
DB <span class="label"><?php echo $queryCount; ?></span> <span class="label"><?php echo $queryTime; ?></span>
|
DB <span class="label"><?php echo $queryCount; ?></span> <span class="label"><?php echo $queryTime; ?></span>
|
||||||
</a> |
</a> |
||||||
</div> |
</div> |
||||||
|
@ -0,0 +1,34 @@ |
|||||||
|
<?php
|
||||||
|
use yii\grid\GridView; |
||||||
|
?> |
||||||
|
<h1>Performance Profiling</h1> |
||||||
|
<p>Total processing time: <b><?php echo $time; ?></b>; Peak memory: <b><?php echo $memory; ?></b>.</p>
|
||||||
|
<?php |
||||||
|
echo GridView::widget([ |
||||||
|
'dataProvider' => $dataProvider, |
||||||
|
'id' => 'profile-panel-detailed-grid', |
||||||
|
'filterModel' => $searchModel, |
||||||
|
'filterUrl' => $panel->getUrl(), |
||||||
|
'columns' => [ |
||||||
|
['class' => 'yii\grid\SerialColumn'], |
||||||
|
[ |
||||||
|
'attribute' => 'duration', |
||||||
|
'value' => function ($data) |
||||||
|
{ |
||||||
|
return sprintf('%.1f ms',$data['duration']); |
||||||
|
}, |
||||||
|
], |
||||||
|
'category', |
||||||
|
[ |
||||||
|
'attribute' => 'info', |
||||||
|
'value' => function ($data) |
||||||
|
{ |
||||||
|
return str_repeat('<span class="indent">→</span>', $data['level']) . $data['info']; |
||||||
|
}, |
||||||
|
'options' => [ |
||||||
|
'width' => '60%', |
||||||
|
], |
||||||
|
], |
||||||
|
], |
||||||
|
]); |
||||||
|
?> |
@ -0,0 +1,6 @@ |
|||||||
|
<div class="yii-debug-toolbar-block"> |
||||||
|
<a href="<?php echo $panel->getUrl(); ?>" title="Total request processing time was <?php echo $time; ?>">Time <span class="label"><?php echo $time; ?></span></a>
|
||||||
|
</div> |
||||||
|
<div class="yii-debug-toolbar-block"> |
||||||
|
<a href="<?php echo $panel->getUrl(); ?>" title="Peak memory consumption">Memory <span class="label"><?php echo $memory; ?></span></a>
|
||||||
|
</div> |
Loading…
Reference in new issue