|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/* |
|
4
|
|
|
* This file is part of the JarvisBundle package. |
|
5
|
|
|
* |
|
6
|
|
|
* For the full copyright and license information, please view the LICENSE |
|
7
|
|
|
* file that was distributed with this source code. |
|
8
|
|
|
*/ |
|
9
|
|
|
|
|
10
|
|
|
namespace LinkValue\JarvisBundle\DataCollector; |
|
11
|
|
|
|
|
12
|
|
|
use LinkValue\JarvisBundle\Profiler\ClientProfilerInterface; |
|
13
|
|
|
use Symfony\Component\HttpFoundation\Request; |
|
14
|
|
|
use Symfony\Component\HttpFoundation\Response; |
|
15
|
|
|
use Symfony\Component\HttpKernel\DataCollector\DataCollector; |
|
16
|
|
|
|
|
17
|
|
|
/** |
|
18
|
|
|
* ClientDataCollector. |
|
19
|
|
|
* |
|
20
|
|
|
* @package JarvisBundle |
|
21
|
|
|
* @author Jamal Youssefi <[email protected]> |
|
22
|
|
|
* @author Valentin Coulon <[email protected]> |
|
23
|
|
|
*/ |
|
24
|
|
|
class ClientDataCollector extends DataCollector |
|
25
|
|
|
{ |
|
26
|
|
|
/** |
|
27
|
|
|
* @var ClientProfilerInterface |
|
28
|
|
|
*/ |
|
29
|
|
|
private $profiler; |
|
30
|
|
|
|
|
31
|
|
|
/** |
|
32
|
|
|
* @param ClientProfilerInterface $profiler |
|
33
|
|
|
*/ |
|
34
|
|
|
public function __construct(ClientProfilerInterface $profiler) |
|
35
|
|
|
{ |
|
36
|
|
|
$this->profiler = $profiler; |
|
37
|
|
|
} |
|
38
|
|
|
|
|
39
|
|
|
/** |
|
40
|
|
|
* @return string |
|
41
|
|
|
*/ |
|
42
|
|
|
public function getName() |
|
43
|
|
|
{ |
|
44
|
|
|
return 'link_value_jarvis'; |
|
45
|
|
|
} |
|
46
|
|
|
|
|
47
|
|
|
/** |
|
48
|
|
|
* @param Request $request |
|
49
|
|
|
* @param Response $response |
|
50
|
|
|
* @param \Exception|null $exception |
|
51
|
|
|
*/ |
|
52
|
|
|
public function collect(Request $request, Response $response, \Exception $exception = null) |
|
53
|
|
|
{ |
|
54
|
|
|
$this->data['push_calls'] = $this->profiler->getCalls(); |
|
55
|
|
|
} |
|
56
|
|
|
|
|
57
|
|
|
/** |
|
58
|
|
|
* @return mixed |
|
59
|
|
|
*/ |
|
60
|
|
|
public function getCalls() |
|
61
|
|
|
{ |
|
62
|
|
|
return $this->data['push_calls']; |
|
63
|
|
|
} |
|
64
|
|
|
|
|
65
|
|
|
/** |
|
66
|
|
|
* @return int |
|
67
|
|
|
*/ |
|
68
|
|
|
public function getCountCalls() |
|
69
|
|
|
{ |
|
70
|
|
|
return count($this->data['push_calls']); |
|
71
|
|
|
} |
|
72
|
|
|
|
|
73
|
|
|
/** |
|
74
|
|
|
* @return int |
|
75
|
|
|
*/ |
|
76
|
|
|
public function getCountErrors() |
|
77
|
|
|
{ |
|
78
|
|
|
$errors = 0; |
|
79
|
|
|
foreach ($this->data['push_calls'] as $call) { |
|
80
|
|
|
if ($call['error'] == true) { |
|
81
|
|
|
++$errors; |
|
82
|
|
|
} |
|
83
|
|
|
} |
|
84
|
|
|
|
|
85
|
|
|
return $errors; |
|
86
|
|
|
} |
|
87
|
|
|
|
|
88
|
|
|
/** |
|
89
|
|
|
* @return int |
|
90
|
|
|
*/ |
|
91
|
|
|
public function getTotalTime() |
|
92
|
|
|
{ |
|
93
|
|
|
$time = 0; |
|
94
|
|
|
foreach ($this->data['push_calls'] as $call) { |
|
95
|
|
|
$time += $call['duration']; |
|
96
|
|
|
} |
|
97
|
|
|
|
|
98
|
|
|
return $time; |
|
99
|
|
|
} |
|
100
|
|
|
|
|
101
|
|
|
/** |
|
102
|
|
|
* @return int |
|
103
|
|
|
*/ |
|
104
|
|
|
public function getMemoryUsage() |
|
105
|
|
|
{ |
|
106
|
|
|
$memory = 0; |
|
107
|
|
|
foreach ($this->data['push_calls'] as $call) { |
|
108
|
|
|
$memory += $call['memory_use']; |
|
109
|
|
|
} |
|
110
|
|
|
|
|
111
|
|
|
return $memory; |
|
112
|
|
|
} |
|
113
|
|
|
} |
|
114
|
|
|
|