|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
use Slim\Slim; |
|
4
|
|
|
|
|
5
|
|
|
class Xhgui_Controller_Waterfall extends Xhgui_Controller |
|
6
|
|
|
{ |
|
7
|
|
|
/** |
|
8
|
|
|
* @var Xhgui_Searcher_Interface |
|
9
|
|
|
*/ |
|
10
|
|
|
protected $searcher; |
|
11
|
|
|
|
|
12
|
|
|
public function __construct(Slim $app, Xhgui_Searcher_Interface $searcher) |
|
13
|
|
|
{ |
|
14
|
|
|
parent::__construct($app); |
|
15
|
|
|
$this->searcher = $searcher; |
|
16
|
|
|
} |
|
17
|
|
|
|
|
18
|
|
|
public function index() |
|
19
|
|
|
{ |
|
20
|
|
|
$request = $this->app->request(); |
|
21
|
|
|
$search = array(); |
|
22
|
|
|
$keys = array('remote_addr', 'request_start', 'request_end'); |
|
23
|
|
|
foreach ($keys as $key) { |
|
24
|
|
|
if ($request->get($key)) { |
|
25
|
|
|
$search[$key] = trim($request->get($key)); |
|
26
|
|
|
} |
|
27
|
|
|
} |
|
28
|
|
|
$result = $this->searcher->getAll(array( |
|
29
|
|
|
'sort' => 'time', |
|
30
|
|
|
'direction' => 'asc', |
|
31
|
|
|
'conditions' => $search, |
|
32
|
|
|
'projection' => true |
|
33
|
|
|
)); |
|
34
|
|
|
|
|
35
|
|
|
$paging = array( |
|
36
|
|
|
'total_pages' => $result['totalPages'], |
|
37
|
|
|
'page' => $result['page'], |
|
38
|
|
|
'sort' => 'asc', |
|
39
|
|
|
'direction' => $result['direction'] |
|
40
|
|
|
); |
|
41
|
|
|
|
|
42
|
|
|
$this->_template = 'waterfall/list.twig'; |
|
43
|
|
|
$this->set(array( |
|
44
|
|
|
'runs' => $result['results'], |
|
45
|
|
|
'search' => $search, |
|
46
|
|
|
'paging' => $paging, |
|
47
|
|
|
'base_url' => 'waterfall.list', |
|
48
|
|
|
)); |
|
49
|
|
|
} |
|
50
|
|
|
|
|
51
|
|
|
public function query() |
|
52
|
|
|
{ |
|
53
|
|
|
$request = $this->app->request(); |
|
54
|
|
|
$response = $this->app->response(); |
|
55
|
|
|
$search = array(); |
|
56
|
|
|
$keys = array('remote_addr', 'request_start', 'request_end'); |
|
57
|
|
|
foreach ($keys as $key) { |
|
58
|
|
|
$search[$key] = $request->get($key); |
|
59
|
|
|
} |
|
60
|
|
|
$result = $this->searcher->getAll(array( |
|
61
|
|
|
'sort' => 'time', |
|
62
|
|
|
'direction' => 'asc', |
|
63
|
|
|
'conditions' => $search, |
|
64
|
|
|
'projection' => TRUE |
|
65
|
|
|
)); |
|
66
|
|
|
$datas = array(); |
|
67
|
|
|
/** @var Xhgui_Profile $r */ |
|
68
|
|
|
foreach ($result['results'] as $r) { |
|
69
|
|
|
$duration = $r->get('main()', 'wt'); |
|
70
|
|
|
$start = $r->getMeta('SERVER.REQUEST_TIME_FLOAT'); |
|
71
|
|
|
$title = $r->getMeta('url'); |
|
72
|
|
|
$datas[] = array( |
|
73
|
|
|
'id' => $r->getId(), |
|
74
|
|
|
'title' => $title, |
|
75
|
|
|
'start' => $start * 1000, |
|
76
|
|
|
'duration' => $duration / 1000 // Convert to correct scale |
|
77
|
|
|
); |
|
78
|
|
|
} |
|
79
|
|
|
$response->body(json_encode($datas)); |
|
80
|
|
|
$response['Content-Type'] = 'application/json'; |
|
81
|
|
|
} |
|
82
|
|
|
|
|
83
|
|
|
} |
|
84
|
|
|
|