Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
Y
yii2
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
PSDI Army
yii2
Commits
a89d0db5
Commit
a89d0db5
authored
Feb 03, 2014
by
Qiang Xue
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #2282 from Ragazzo/debug_module_feature
added total queries monitoring
parents
81042fc1
47425145
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
39 additions
and
3 deletions
+39
-3
Module.php
extensions/debug/Module.php
+2
-1
DbPanel.php
extensions/debug/panels/DbPanel.php
+18
-0
index.php
extensions/debug/views/default/index.php
+19
-2
No files found.
extensions/debug/Module.php
View file @
a89d0db5
...
...
@@ -11,6 +11,7 @@ use Yii;
use
yii\base\Application
;
use
yii\web\View
;
use
yii\web\ForbiddenHttpException
;
use
yii\helpers\ArrayHelper
;
/**
* The Yii Debug Module provides the debug toolbar and debugger
...
...
@@ -63,7 +64,7 @@ class Module extends \yii\base\Module
Yii
::
$app
->
getView
()
->
on
(
View
::
EVENT_END_BODY
,
[
$this
,
'renderToolbar'
]);
});
$this
->
panels
=
array_
merge
(
$this
->
corePanels
(),
$this
->
panels
);
$this
->
panels
=
ArrayHelper
::
merge
(
$this
->
corePanels
(),
$this
->
panels
);
foreach
(
$this
->
panels
as
$id
=>
$config
)
{
$config
[
'module'
]
=
$this
;
$config
[
'id'
]
=
$id
;
...
...
extensions/debug/panels/DbPanel.php
View file @
a89d0db5
...
...
@@ -21,6 +21,12 @@ use yii\debug\models\search\Db;
class
DbPanel
extends
Panel
{
/**
* @var integer the threshold for determining whether the request has involved
* critical number of DB queries. If the number of queries exceeds this number,
* the execution is considered taking critical number of DB queries.
*/
public
$criticalQueryThreshold
;
/**
* @var array db queries info extracted to array as models, to use with data provider.
*/
private
$_models
;
...
...
@@ -147,4 +153,16 @@ class DbPanel extends Panel
preg_match
(
'/^([a-zA-z]*)/'
,
$timing
,
$matches
);
return
count
(
$matches
)
?
$matches
[
0
]
:
''
;
}
/**
* Check if given queries count is critical according settings.
*
* @param integer $count queries count
* @return boolean
*/
public
function
isQueryCountCritical
(
$count
)
{
return
((
$this
->
criticalQueryThreshold
!==
null
)
&&
(
$count
>
$this
->
criticalQueryThreshold
));
}
}
extensions/debug/views/default/index.php
View file @
a89d0db5
...
...
@@ -32,7 +32,9 @@ echo GridView::widget([
'dataProvider'
=>
$dataProvider
,
'filterModel'
=>
$searchModel
,
'rowOptions'
=>
function
(
$model
,
$key
,
$index
,
$grid
)
use
(
$searchModel
)
{
if
(
$searchModel
->
isCodeCritical
(
$model
[
'statusCode'
]))
{
$dbPanel
=
$this
->
context
->
module
->
panels
[
'db'
];
if
(
$searchModel
->
isCodeCritical
(
$model
[
'statusCode'
])
||
$dbPanel
->
isQueryCountCritical
(
$model
[
'sqlCount'
]))
{
return
[
'class'
=>
'danger'
];
}
else
{
return
[];
...
...
@@ -58,7 +60,22 @@ echo GridView::widget([
'ip'
,
[
'attribute'
=>
'sqlCount'
,
'label'
=>
'Total queries count'
'label'
=>
'Total queries count'
,
'value'
=>
function
(
$data
)
{
$dbPanel
=
$this
->
context
->
module
->
panels
[
'db'
];
if
(
$dbPanel
->
isQueryCountCritical
(
$data
[
'sqlCount'
]))
{
$content
=
Html
::
tag
(
'b'
,
$data
[
'sqlCount'
])
.
' '
.
Html
::
tag
(
'span'
,
''
,[
'class'
=>
'glyphicon glyphicon-exclamation-sign'
]);
return
Html
::
a
(
$content
,
$dbPanel
->
getUrl
(),
[
'title'
=>
'Too many queries. Allowed count is '
.
$dbPanel
->
criticalQueryThreshold
,
]);
}
else
{
return
$data
[
'sqlCount'
];
}
},
'format'
=>
'html'
,
],
[
'attribute'
=>
'method'
,
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment