-
Notifications
You must be signed in to change notification settings - Fork 2
/
XHProfPanel.php
109 lines (88 loc) · 2.98 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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
<?php
namespace stevad\xhprof;
use Yii;
use yii\web\View;
/**
* Debug panel for official yii2-debug extension for fast access to XHProf results and list of previous runs with
* ability to compare results between each others.
*
* @author Vadym Stepanov <[email protected]>
* @date 16.11.2017
*/
class XHProfPanel extends \yii\debug\Panel
{
public function getName()
{
return 'XHProf';
}
public function getDetail()
{
if ($this->getComponent() === null) {
return Yii::$app->view->render('@yii2-xhprof/views/details_disabled_component.php');
}
$reports = $this->getComponent()->loadReports();
\rsort($reports);
$urlTemplates = [
'report' => $this->getComponent()->getReportBaseUrl() . '/' . XHProf::$urlTemplates['report'],
'callgraph' => $this->getComponent()->getReportBaseUrl() . '/' . XHProf::$urlTemplates['callgraph'],
'diff' => $this->getComponent()->getReportBaseUrl() . '/' . XHProf::$urlTemplates['diff'],
];
$js = <<<EOD
XHProf.urlReportTemplate = '{$urlTemplates['report']}';
XHProf.urlCallgraphTemplate = '{$urlTemplates['callgraph']}';
XHProf.urlDiffTemplate = '{$urlTemplates['diff']}';
EOD;
DebugPanelAsset::register(Yii::$app->view);
Yii::$app->view->registerJs($js, View::POS_END);
$urls = [];
$data = $this->data;
if ($data['enabled']) {
$urls['report'] = XHProf::getInstance()->getReportUrl($data['runId'], $data['ns']);
$urls['callgraph'] = XHProf::getInstance()->getCallgraphUrl($data['runId'], $data['ns']);
}
return Yii::$app->view->render('@yii2-xhprof/views/details', [
'panel' => $this,
'enabled' => $data['enabled'],
'run' => [
'id' => $data['runId'],
'ns' => $data['ns'],
],
'urls' => $urls,
'reports' => $reports,
]);
}
public function getSummary()
{
if ($this->getComponent() === null) {
return null;
}
XHProf::getInstance()->setHtmlUrlPath($this->getComponent()->getReportBaseUrl());
$urls = [];
$data = $this->data;
if ($data['enabled']) {
$urls['report'] = XHProf::getInstance()->getReportUrl($data['runId'], $data['ns']);
$urls['callgraph'] = XHProf::getInstance()->getCallgraphUrl($data['runId'], $data['ns']);
}
return Yii::$app->view->render('@yii2-xhprof/views/panel', [
'panel' => $this,
'enabled' => $data['enabled'],
'urls' => $urls,
]);
}
public function save()
{
if ($this->getComponent() === null) {
return null;
}
return $this->getComponent()->getReportInfo();
}
/**
* Get profiler component
*
* @return XHProfComponent
*/
public function getComponent()
{
return Yii::$app->get('xhprof', false);
}
}