|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/* |
|
4
|
|
|
* This file is part of the FOSElasticaBundle package. |
|
5
|
|
|
* |
|
6
|
|
|
* (c) FriendsOfSymfony <http://friendsofsymfony.github.com/> |
|
7
|
|
|
* |
|
8
|
|
|
* For the full copyright and license information, please view the LICENSE |
|
9
|
|
|
* file that was distributed with this source code. |
|
10
|
|
|
*/ |
|
11
|
|
|
|
|
12
|
|
|
namespace FOS\ElasticaBundle\DataCollector; |
|
13
|
|
|
|
|
14
|
|
|
use FOS\ElasticaBundle\Logger\ElasticaLogger; |
|
15
|
|
|
use Symfony\Component\HttpFoundation\Request; |
|
16
|
|
|
use Symfony\Component\HttpFoundation\Response; |
|
17
|
|
|
use Symfony\Component\HttpKernel\DataCollector\DataCollector; |
|
18
|
|
|
|
|
19
|
|
|
/** |
|
20
|
|
|
* Data collector collecting elastica statistics. |
|
21
|
|
|
* |
|
22
|
|
|
* @author Gordon Franke <[email protected]> |
|
23
|
|
|
*/ |
|
24
|
|
|
class ElasticaDataCollector extends DataCollector |
|
25
|
|
|
{ |
|
26
|
|
|
protected $logger; |
|
27
|
|
|
|
|
28
|
4 |
|
public function __construct(ElasticaLogger $logger) |
|
29
|
|
|
{ |
|
30
|
4 |
|
$this->logger = $logger; |
|
31
|
4 |
|
} |
|
32
|
|
|
|
|
33
|
3 |
|
public function collect(Request $request, Response $response, \Exception $exception = null) |
|
34
|
|
|
{ |
|
35
|
3 |
|
$this->data['nb_queries'] = $this->logger->getNbQueries(); |
|
36
|
3 |
|
$this->data['queries'] = $this->logger->getQueries(); |
|
37
|
3 |
|
} |
|
38
|
|
|
|
|
39
|
|
|
/** |
|
40
|
|
|
* @return mixed |
|
41
|
|
|
*/ |
|
42
|
1 |
|
public function getQueryCount() |
|
43
|
|
|
{ |
|
44
|
1 |
|
return $this->data['nb_queries']; |
|
45
|
|
|
} |
|
46
|
|
|
|
|
47
|
|
|
/** |
|
48
|
|
|
* @return mixed |
|
49
|
|
|
*/ |
|
50
|
1 |
|
public function getQueries() |
|
51
|
|
|
{ |
|
52
|
1 |
|
return $this->data['queries']; |
|
53
|
|
|
} |
|
54
|
|
|
|
|
55
|
|
|
/** |
|
56
|
|
|
* @return int |
|
57
|
|
|
*/ |
|
58
|
1 |
|
public function getTime() |
|
59
|
|
|
{ |
|
60
|
1 |
|
$time = 0; |
|
61
|
1 |
|
foreach ($this->data['queries'] as $query) { |
|
62
|
1 |
|
$time += $query['engineMS']; |
|
63
|
|
|
} |
|
64
|
|
|
|
|
65
|
1 |
|
return $time; |
|
66
|
|
|
} |
|
67
|
|
|
|
|
68
|
|
|
/** |
|
69
|
|
|
* @return int |
|
70
|
|
|
*/ |
|
71
|
|
|
public function getExecutionTime() |
|
72
|
|
|
{ |
|
73
|
|
|
$time = 0; |
|
74
|
|
|
foreach ($this->data['queries'] as $query) { |
|
75
|
|
|
$time += $query['executionMS']; |
|
76
|
|
|
} |
|
77
|
|
|
|
|
78
|
|
|
return $time; |
|
79
|
|
|
} |
|
80
|
|
|
|
|
81
|
1 |
|
public function getName() |
|
82
|
|
|
{ |
|
83
|
1 |
|
return 'elastica'; |
|
84
|
|
|
} |
|
85
|
|
|
|
|
86
|
|
|
public function reset() |
|
87
|
|
|
{ |
|
88
|
|
|
$this->logger->reset(); |
|
89
|
|
|
$this->data = []; |
|
90
|
|
|
} |
|
91
|
|
|
} |
|
92
|
|
|
|