1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
class Xhgui_Controller_Run extends Xhgui_Controller |
|
|
|
|
4
|
|
|
{ |
5
|
|
|
public function __construct($app, $profiles, $watches) |
6
|
|
|
{ |
7
|
|
|
$this->_app = $app; |
|
|
|
|
8
|
|
|
$this->_profiles = $profiles; |
|
|
|
|
9
|
|
|
$this->_watches = $watches; |
|
|
|
|
10
|
|
|
} |
11
|
|
|
|
12
|
|
|
public function index() |
13
|
|
|
{ |
14
|
|
|
$request = $this->_app->request(); |
15
|
|
|
|
16
|
|
|
$search = array(); |
17
|
|
|
$keys = array('date_start', 'date_end', 'url'); |
18
|
|
|
foreach ($keys as $key) { |
19
|
|
|
if ($request->get($key)) { |
20
|
|
|
$search[$key] = $request->get($key); |
21
|
|
|
} |
22
|
|
|
} |
23
|
|
|
$sort = $request->get('sort'); |
24
|
|
|
|
25
|
|
|
$result = $this->_profiles->getAll(array( |
26
|
|
|
'sort' => $sort, |
27
|
|
|
'page' => $request->get('page'), |
28
|
|
|
'direction' => $request->get('direction'), |
29
|
|
|
'perPage' => $this->_app->config('page.limit'), |
30
|
|
|
'conditions' => $search, |
31
|
|
|
'projection' => true, |
32
|
|
|
)); |
33
|
|
|
|
34
|
|
|
$title = 'Recent runs'; |
35
|
|
|
$titleMap = array( |
36
|
|
|
'wt' => 'Longest wall time', |
37
|
|
|
'cpu' => 'Most CPU time', |
38
|
|
|
'mu' => 'Highest memory use', |
39
|
|
|
); |
40
|
|
|
if (isset($titleMap[$sort])) { |
41
|
|
|
$title = $titleMap[$sort]; |
42
|
|
|
} |
43
|
|
|
|
44
|
|
|
$paging = array( |
45
|
|
|
'total_pages' => $result['totalPages'], |
46
|
|
|
'page' => $result['page'], |
47
|
|
|
'sort' => $sort, |
48
|
|
|
'direction' => $result['direction'] |
49
|
|
|
); |
50
|
|
|
|
51
|
|
|
$this->_template = 'runs/list.twig'; |
52
|
|
|
$this->set(array( |
53
|
|
|
'paging' => $paging, |
54
|
|
|
'base_url' => 'home', |
55
|
|
|
'runs' => $result['results'], |
56
|
|
|
'date_format' => $this->_app->config('date.format'), |
57
|
|
|
'search' => $search, |
58
|
|
|
'has_search' => strlen(implode('', $search)) > 0, |
59
|
|
|
'title' => $title |
60
|
|
|
)); |
61
|
|
|
} |
62
|
|
|
|
63
|
|
|
public function view() |
64
|
|
|
{ |
65
|
|
|
$request = $this->_app->request(); |
66
|
|
|
$detailCount = $this->_app->config('detail.count'); |
67
|
|
|
$result = $this->_profiles->get($request->get('id')); |
68
|
|
|
|
69
|
|
|
$result->calculateSelf(); |
70
|
|
|
|
71
|
|
|
// Self wall time graph |
72
|
|
|
$timeChart = $result->extractDimension('ewt', $detailCount); |
73
|
|
|
|
74
|
|
|
// Memory Block |
75
|
|
|
$memoryChart = $result->extractDimension('emu', $detailCount); |
76
|
|
|
|
77
|
|
|
// Watched Functions Block |
78
|
|
|
$watchedFunctions = array(); |
79
|
|
|
foreach ($this->_watches->getAll() as $watch) { |
80
|
|
|
$matches = $result->getWatched($watch['name']); |
81
|
|
|
if ($matches) { |
82
|
|
|
$watchedFunctions = array_merge($watchedFunctions, $matches); |
83
|
|
|
} |
84
|
|
|
} |
85
|
|
|
|
86
|
|
|
$profile = $result->sort('ewt', $result->getProfile()); |
87
|
|
|
|
88
|
|
|
$this->_template = 'runs/view.twig'; |
89
|
|
|
$this->set(array( |
90
|
|
|
'profile' => $profile, |
91
|
|
|
'result' => $result, |
92
|
|
|
'wall_time' => $timeChart, |
93
|
|
|
'memory' => $memoryChart, |
94
|
|
|
'watches' => $watchedFunctions, |
95
|
|
|
'date_format' => $this->_app->config('date.format'), |
96
|
|
|
)); |
97
|
|
|
} |
98
|
|
|
|
99
|
|
|
public function url() |
100
|
|
|
{ |
101
|
|
|
$request = $this->_app->request(); |
102
|
|
|
$pagination = array( |
103
|
|
|
'sort' => $request->get('sort'), |
104
|
|
|
'direction' => $request->get('direction'), |
105
|
|
|
'page' => $request->get('page'), |
106
|
|
|
'perPage' => $this->_app->config('page.limit'), |
107
|
|
|
); |
108
|
|
|
|
109
|
|
|
$search = array(); |
110
|
|
|
$keys = array('date_start', 'date_end', 'limit', 'limit_custom'); |
111
|
|
|
foreach ($keys as $key) { |
112
|
|
|
$search[$key] = $request->get($key); |
113
|
|
|
} |
114
|
|
|
|
115
|
|
|
$runs = $this->_profiles->getForUrl( |
116
|
|
|
$request->get('url'), |
117
|
|
|
$pagination, |
118
|
|
|
$search |
119
|
|
|
); |
120
|
|
|
|
121
|
|
|
if (isset($search['limit_custom']) && strlen($search['limit_custom']) > 0 && $search['limit_custom'][0] == 'P') { |
122
|
|
|
$search['limit'] = $search['limit_custom']; |
123
|
|
|
} |
124
|
|
|
|
125
|
|
|
$chartData = $this->_profiles->getPercentileForUrl( |
126
|
|
|
90, |
127
|
|
|
$request->get('url'), |
128
|
|
|
$search |
129
|
|
|
); |
130
|
|
|
|
131
|
|
|
$paging = array( |
132
|
|
|
'total_pages' => $runs['totalPages'], |
133
|
|
|
'sort' => $pagination['sort'], |
134
|
|
|
'page' => $runs['page'], |
135
|
|
|
'direction' => $runs['direction'] |
136
|
|
|
); |
137
|
|
|
|
138
|
|
|
$this->_template = 'runs/url.twig'; |
139
|
|
|
$this->set(array( |
140
|
|
|
'paging' => $paging, |
141
|
|
|
'base_url' => 'url.view', |
142
|
|
|
'runs' => $runs['results'], |
143
|
|
|
'url' => $request->get('url'), |
144
|
|
|
'chart_data' => $chartData, |
145
|
|
|
'date_format' => $this->_app->config('date.format'), |
146
|
|
|
'search' => array_merge($search, array('url' => $request->get('url'))), |
147
|
|
|
)); |
148
|
|
|
} |
149
|
|
|
|
150
|
|
|
public function compare() |
151
|
|
|
{ |
152
|
|
|
$request = $this->_app->request(); |
153
|
|
|
|
154
|
|
|
$baseRun = $headRun = $candidates = $comparison = null; |
155
|
|
|
$paging = array(); |
156
|
|
|
|
157
|
|
|
if ($request->get('base')) { |
158
|
|
|
$baseRun = $this->_profiles->get($request->get('base')); |
159
|
|
|
} |
160
|
|
|
|
161
|
|
|
if ($baseRun && !$request->get('head')) { |
162
|
|
|
$pagination = array( |
163
|
|
|
'direction' => $request->get('direction'), |
164
|
|
|
'sort' => $request->get('sort'), |
165
|
|
|
'page' => $request->get('page'), |
166
|
|
|
'perPage' => $this->_app->config('page.limit'), |
167
|
|
|
); |
168
|
|
|
$candidates = $this->_profiles->getForUrl( |
169
|
|
|
$baseRun->getMeta('simple_url'), |
170
|
|
|
$pagination |
171
|
|
|
); |
172
|
|
|
|
173
|
|
|
$paging = array( |
174
|
|
|
'total_pages' => $candidates['totalPages'], |
175
|
|
|
'sort' => $pagination['sort'], |
176
|
|
|
'page' => $candidates['page'], |
177
|
|
|
'direction' => $candidates['direction'] |
178
|
|
|
); |
179
|
|
|
} |
180
|
|
|
|
181
|
|
|
if ($request->get('head')) { |
182
|
|
|
$headRun = $this->_profiles->get($request->get('head')); |
183
|
|
|
} |
184
|
|
|
|
185
|
|
|
if ($baseRun && $headRun) { |
186
|
|
|
$comparison = $baseRun->compare($headRun); |
187
|
|
|
} |
188
|
|
|
|
189
|
|
|
$this->_template = 'runs/compare.twig'; |
190
|
|
|
$this->set(array( |
191
|
|
|
'base_url' => 'run.compare', |
192
|
|
|
'base_run' => $baseRun, |
193
|
|
|
'head_run' => $headRun, |
194
|
|
|
'candidates' => $candidates, |
195
|
|
|
'url_params' => $request->get(), |
196
|
|
|
'date_format' => $this->_app->config('date.format'), |
197
|
|
|
'comparison' => $comparison, |
198
|
|
|
'paging' => $paging, |
199
|
|
|
'search' => array( |
200
|
|
|
'base' => $request->get('base'), |
201
|
|
|
'head' => $request->get('head'), |
202
|
|
|
) |
203
|
|
|
)); |
204
|
|
|
} |
205
|
|
|
|
206
|
|
|
public function symbol() |
207
|
|
|
{ |
208
|
|
|
$request = $this->_app->request(); |
209
|
|
|
$id = $request->get('id'); |
210
|
|
|
$symbol = $request->get('symbol'); |
211
|
|
|
|
212
|
|
|
$profile = $this->_profiles->get($id); |
213
|
|
|
$profile->calculateSelf(); |
214
|
|
|
list($parents, $current, $children) = $profile->getRelatives($symbol); |
215
|
|
|
|
216
|
|
|
$this->_template = 'runs/symbol.twig'; |
217
|
|
|
$this->set(array( |
218
|
|
|
'symbol' => $symbol, |
219
|
|
|
'id' => $id, |
220
|
|
|
'main' => $profile->get('main()'), |
221
|
|
|
'parents' => $parents, |
222
|
|
|
'current' => $current, |
223
|
|
|
'children' => $children, |
224
|
|
|
)); |
225
|
|
|
} |
226
|
|
|
|
227
|
|
|
public function symbolShort() |
228
|
|
|
{ |
229
|
|
|
$request = $this->_app->request(); |
230
|
|
|
$id = $request->get('id'); |
231
|
|
|
$threshold = $request->get('threshold'); |
232
|
|
|
$symbol = $request->get('symbol'); |
233
|
|
|
$metric = $request->get('metric'); |
234
|
|
|
|
235
|
|
|
$profile = $this->_profiles->get($id); |
236
|
|
|
$profile->calculateSelf(); |
237
|
|
|
list($parents, $current, $children) = $profile->getRelatives($symbol, $metric, $threshold); |
238
|
|
|
|
239
|
|
|
$this->_template = 'runs/symbol-short.twig'; |
240
|
|
|
$this->set(array( |
241
|
|
|
'symbol' => $symbol, |
242
|
|
|
'id' => $id, |
243
|
|
|
'main' => $profile->get('main()'), |
244
|
|
|
'parents' => $parents, |
245
|
|
|
'current' => $current, |
246
|
|
|
'children' => $children, |
247
|
|
|
)); |
248
|
|
|
} |
249
|
|
|
|
250
|
|
View Code Duplication |
public function callgraph() |
|
|
|
|
251
|
|
|
{ |
252
|
|
|
$request = $this->_app->request(); |
253
|
|
|
$profile = $this->_profiles->get($request->get('id')); |
254
|
|
|
|
255
|
|
|
$this->_template = 'runs/callgraph.twig'; |
256
|
|
|
$this->set(array( |
257
|
|
|
'profile' => $profile, |
258
|
|
|
'date_format' => $this->_app->config('date.format'), |
259
|
|
|
)); |
260
|
|
|
} |
261
|
|
|
|
262
|
|
View Code Duplication |
public function callgraphData() |
|
|
|
|
263
|
|
|
{ |
264
|
|
|
$request = $this->_app->request(); |
265
|
|
|
$response = $this->_app->response(); |
266
|
|
|
$profile = $this->_profiles->get($request->get('id')); |
267
|
|
|
$metric = $request->get('metric') ?: 'wt'; |
268
|
|
|
$threshold = (float)$request->get('threshold') ?: 0.01; |
269
|
|
|
$callgraph = $profile->getCallgraph($metric, $threshold); |
270
|
|
|
|
271
|
|
|
$response['Content-Type'] = 'application/json'; |
272
|
|
|
return $response->body(json_encode($callgraph)); |
|
|
|
|
273
|
|
|
} |
274
|
|
|
|
275
|
|
View Code Duplication |
public function flamegraph() |
|
|
|
|
276
|
|
|
{ |
277
|
|
|
$request = $this->_app->request(); |
278
|
|
|
$profile = $this->_profiles->get($request->get('id')); |
279
|
|
|
|
280
|
|
|
$this->_template = 'runs/flamegraph.twig'; |
281
|
|
|
$this->set(array( |
282
|
|
|
'profile' => $profile, |
283
|
|
|
'date_format' => $this->_app->config('date.format'), |
284
|
|
|
)); |
285
|
|
|
} |
286
|
|
|
|
287
|
|
View Code Duplication |
public function flamegraphData() |
|
|
|
|
288
|
|
|
{ |
289
|
|
|
$request = $this->_app->request(); |
290
|
|
|
$response = $this->_app->response(); |
291
|
|
|
$profile = $this->_profiles->get($request->get('id')); |
292
|
|
|
$metric = $request->get('metric') ?: 'wt'; |
293
|
|
|
$threshold = (float)$request->get('threshold') ?: 0.01; |
294
|
|
|
$flamegraph = $profile->getFlamegraph($metric, $threshold); |
295
|
|
|
|
296
|
|
|
$response['Content-Type'] = 'application/json'; |
297
|
|
|
return $response->body(json_encode($flamegraph)); |
|
|
|
|
298
|
|
|
} |
299
|
|
|
|
300
|
|
View Code Duplication |
public function callgraphDataDot() |
|
|
|
|
301
|
|
|
{ |
302
|
|
|
$request = $this->_app->request(); |
303
|
|
|
$response = $this->_app->response(); |
304
|
|
|
$profile = $this->_profiles->get($request->get('id')); |
305
|
|
|
$metric = $request->get('metric') ?: 'wt'; |
306
|
|
|
$threshold = (float)$request->get('threshold') ?: 0.01; |
307
|
|
|
$callgraph = $profile->getCallgraphNodes($metric, $threshold); |
308
|
|
|
|
309
|
|
|
$response['Content-Type'] = 'application/json'; |
310
|
|
|
return $response->body(json_encode($callgraph)); |
|
|
|
|
311
|
|
|
} |
312
|
|
|
} |
313
|
|
|
|
You can fix this by adding a namespace to your class:
When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.