-
Notifications
You must be signed in to change notification settings - Fork 1
/
XHProfPanel.php
90 lines (76 loc) · 2.91 KB
/
XHProfPanel.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
<?php
/**
* Debug panel for Yii2Debug extension for fast access to XHProf results and list of previous runs with ability
* to compare results between each others.
*
* @author Vadym Stepanov <vadim.stepanov.ua@gmail.com>
*/
class XHProfPanel extends Yii2DebugPanel
{
public function getName()
{
return 'XHProf';
}
public function getDetail()
{
if (Yii::app()->getComponent('xhprof', false) === null) {
return $this->render(__DIR__ . '/views/details_disabled_component.php');
}
$reports = Yii::app()->xhprof->loadReports();
rsort($reports);
$urlTemplates = array(
'report' => Yii::app()->xhprof->getReportBaseUrl() . '/' . XHProf::$urlTemplates['report'],
'callgraph' => Yii::app()->xhprof->getReportBaseUrl() . '/' . XHProf::$urlTemplates['callgraph'],
'diff' => Yii::app()->xhprof->getReportBaseUrl() . '/' . XHProf::$urlTemplates['diff']
);
$js = <<<EOD
XHProf.urlReportTemplate = '{$urlTemplates['report']}';
XHProf.urlCallgraphTemplate = '{$urlTemplates['callgraph']}';
XHProf.urlDiffTemplate = '{$urlTemplates['diff']}';
EOD;
$assetPath = Yii::app()->assetManager->publish(__DIR__ . '/assets');
/** @var CClientScript $cs */
$cs = Yii::app()->clientScript;
$cs->registerScriptFile($assetPath . '/xhprof.js', CClientScript::POS_HEAD);
$cs->registerScript('xhprof_init', $js, CClientScript::POS_END);
$urls = array();
$data = $this->getData();
if ($data['enabled']) {
$urls['report'] = XHProf::getInstance()->getReportUrl($data['runId'], $data['ns']);
$urls['callgraph'] = XHProf::getInstance()->getCallgraphUrl($data['runId'], $data['ns']);
}
return $this->render(__DIR__ . '/views/details.php', array(
'enabled' => $data['enabled'],
'run' => array(
'id' => $data['runId'],
'ns' => $data['ns']
),
'urls' => $urls,
'reports' => $reports
));
}
public function getSummary()
{
if (Yii::app()->getComponent('xhprof', false) === null) {
return null;
}
XHProf::getInstance()->setHtmlUrlPath(Yii::app()->xhprof->getReportBaseUrl());
$urls = array();
$data = $this->getData();
if ($data['enabled']) {
$urls['report'] = XHProf::getInstance()->getReportUrl($data['runId'], $data['ns']);
$urls['callgraph'] = XHProf::getInstance()->getCallgraphUrl($data['runId'], $data['ns']);
}
return $this->render(__DIR__ . '/views/panel.php', array(
'enabled' => $data['enabled'],
'urls' => $urls
));
}
public function save()
{
if (Yii::app()->getComponent('xhprof', false) === null) {
return null;
}
return Yii::app()->xhprof->getReportInfo();
}
}