-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathPanel.php
More file actions
executable file
·162 lines (148 loc) · 3.91 KB
/
Panel.php
File metadata and controls
executable file
·162 lines (148 loc) · 3.91 KB
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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
<?php
namespace Zarganwar\PerformancePanel;
use Tracy\IBarPanel;
/**
* Description of Panel
*
* @author Martin Jirasek
*/
class Panel implements IBarPanel
{
/**
*
* @return string
*/
protected function getHeaderString()
{
return "<tr>"
. "<th><b>Breakpoint</b></th>"
. "<th><b>Previous breakpoint</b></th>"
. "<th>Current memory [MB]</th>"
. "<th>Peak memory from previous [MB]</th>"
. "<th>Memory from previous [MB]</th>"
. "<th>Time from previous [ms]</th>"
. "</tr>";
}
/**
*
* @return string
*/
protected function getBaseRowString()
{
return "<tr title='%s'>"
. "<td><b>%s</b></td>"
. "<td><b>%s</b></td>"
. "<td>%s</td><td>%s</td>"
. "<td>%s</td><td>%s</td>"
. "</tr>";
}
/**
*
* @return string
* @todo Draw time vs. memory graph
*/
public function getPanel()
{
return ''
. '<h1>Performance between breakpoints</h1>'
. '<div class="tracy-inner">'
. '<p><i>'
. 'Add breakpoint: Zarganwar\PerformancePanel\Register::add([name], [parent]);'
. '</i></p>'
. '<p>'
. '<table>' . $this->getRowsString() . '<tr><th><b>Total breakpoints</b></th><th colspan="4">' . $this->countBreakpoints() . '</th></tr></table>'
. '</p>'
. '</div>';
}
/**
*
* @return string
*/
public function getTab()
{
return ''
. '<style>'
. '#performance-panel svg
{
width: 1.93em !important;
}'
. '</style>'
. '<span id="performance-panel" title="Performance Tracy Panel">'
. '<svg version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px"
viewBox="0 0 33.1 11.7" enable-background="new 0 0 33.1 11.7" xml:space="preserve">
<linearGradient id="PerformancePanelGradient" gradientUnits="userSpaceOnUse" x1="5.8319" y1="0.5" x2="5.8319" y2="11.1638">
<stop offset="0" style="stop-color:#FFFFFF"/>
<stop offset="1" style="stop-color:#F7A69E"/>
</linearGradient>
<rect x="0.5" y="0.5" fill="url(#PerformancePanelGradient)" stroke="#773B37" width="10.7" height="10.7"/>
<rect x="22" y="0.5" fill="url(#PerformancePanelGradient)" stroke="#773B37" width="10.7" height="10.7"/>
<polygon fill="#9ADAEA" stroke="#28A0DA" points="16.5,8.1 14,8.1 14,10.5 9,5.9 14,1.2 14,3.6 16.5,3.6 "/>
<polygon fill="#9ADAEA" stroke="#28A0DA" points="16.5,8.1 19,8.1 19,10.5 24.1,5.7 19.1,1.2 19.1,3.6 16.5,3.6 "/>'
. '</svg>'
. '</span>'
;
}
/**
*
* @return int
*/
protected function countBreakpoints()
{
return count(Register::getNames());
}
/**
*
* @return string
*/
protected function getRowsString()
{
$return = $this->getHeaderString();
$namePrevious = null;
$data = Register::getData();
foreach ($data as $name => $current) {
$memory = $time = $peakMemory = null;
$possibleParent = Register::getParent($name);
if ($possibleParent) {
$namePrevious = $possibleParent;
}
if ($namePrevious !== null) {
$previous = $data[$namePrevious];
$memory = $current[Register::MEMORY] - $previous[Register::MEMORY];
$peakMemory = $current[Register::MEMORY_PEAK] - $previous[Register::MEMORY_PEAK];
$time = $current[Register::TIME] - $previous[Register::TIME];
}
$row = $this->getBaseRowString();
$backtrace = $current[Register::BACKTRACE][0];
$return .= sprintf(
$row,
$backtrace['file'] . ':' . $backtrace['line'],
$name,
$namePrevious,
$this->memoryToNumber($current[Register::MEMORY]),
$this->memoryToNumber($peakMemory),
$this->memoryToNumber($memory),
$this->timeToNumber($time)
);
$namePrevious = $name;
}
return $return;
}
/**
*
* @param int $value
* @return string
*/
protected function memoryToNumber($value)
{
return number_format($value / 1000000, 3, '.', ' ');
}
/**
*
* @param int $value
* @return string
*/
protected function timeToNumber($value)
{
return number_format($value * 1000, 0, '.', ' ');
}
}