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