1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* @author @fabfuel <[email protected]> |
4
|
|
|
* @created 21.06.15 15:39 |
5
|
|
|
*/ |
6
|
|
|
|
7
|
|
|
namespace Fabfuel\Prophiler\Aggregator; |
8
|
|
|
|
9
|
|
|
use Fabfuel\Prophiler\Benchmark\BenchmarkInterface; |
10
|
|
|
|
11
|
|
|
class Aggregation implements AggregationInterface |
12
|
|
|
{ |
13
|
|
|
/** |
14
|
|
|
* @var string |
15
|
|
|
*/ |
16
|
|
|
private $command = ''; |
17
|
|
|
|
18
|
|
|
/** |
19
|
|
|
* @var int |
20
|
|
|
*/ |
21
|
|
|
private $totalExecutions = 0; |
22
|
|
|
|
23
|
|
|
/** |
24
|
|
|
* @var float |
25
|
|
|
*/ |
26
|
|
|
private $totalDuration = 0.0; |
27
|
|
|
|
28
|
|
|
/** |
29
|
|
|
* @var float |
30
|
|
|
*/ |
31
|
|
|
private $minDuration = 0.0; |
32
|
|
|
|
33
|
|
|
/** |
34
|
|
|
* @var float |
35
|
|
|
*/ |
36
|
|
|
private $maxDuration = 0.0; |
37
|
|
|
|
38
|
|
|
/** |
39
|
|
|
* @var float |
40
|
|
|
*/ |
41
|
|
|
private $avgDuration = 0.0; |
42
|
|
|
|
43
|
|
|
/** |
44
|
|
|
* @var array |
45
|
|
|
*/ |
46
|
|
|
private $benchmarks = []; |
47
|
|
|
|
48
|
|
|
/** |
49
|
|
|
* @param string $command |
50
|
|
|
*/ |
51
|
1 |
|
public function __construct($command) |
52
|
|
|
{ |
53
|
1 |
|
$this->command = $command; |
54
|
1 |
|
} |
55
|
|
|
|
56
|
|
|
/** |
57
|
|
|
* @param BenchmarkInterface $benchmark |
58
|
|
|
*/ |
59
|
1 |
|
public function aggregate(BenchmarkInterface $benchmark) |
60
|
|
|
{ |
61
|
1 |
|
$this->totalExecutions += 1; |
62
|
1 |
|
$this->totalDuration += (float) $benchmark->getDuration(); |
63
|
|
|
|
64
|
1 |
|
$this->avgDuration = (float) $this->totalDuration / $this->totalExecutions; |
65
|
|
|
|
66
|
1 |
|
if ($benchmark->getDuration() > $this->maxDuration) { |
67
|
1 |
|
$this->maxDuration = (float) $benchmark->getDuration(); |
68
|
1 |
|
} |
69
|
|
|
|
70
|
1 |
|
if ($benchmark->getDuration() < $this->minDuration || !$this->minDuration) { |
71
|
1 |
|
$this->minDuration = (float) $benchmark->getDuration(); |
72
|
1 |
|
} |
73
|
|
|
|
74
|
1 |
|
$this->benchmarks[] = $benchmark; |
75
|
1 |
|
} |
76
|
|
|
|
77
|
|
|
/** |
78
|
|
|
* @return string |
79
|
|
|
*/ |
80
|
1 |
|
public function getCommand() |
81
|
|
|
{ |
82
|
1 |
|
return $this->command; |
83
|
|
|
} |
84
|
|
|
|
85
|
|
|
/** |
86
|
|
|
* @return BenchmarkInterface[] |
87
|
|
|
*/ |
88
|
1 |
|
public function getBenchmarks() |
89
|
|
|
{ |
90
|
1 |
|
return $this->benchmarks; |
91
|
|
|
} |
92
|
|
|
|
93
|
|
|
/** |
94
|
|
|
* @return int |
95
|
|
|
*/ |
96
|
1 |
|
public function getTotalExecutions() |
97
|
|
|
{ |
98
|
1 |
|
return $this->totalExecutions; |
99
|
|
|
} |
100
|
|
|
|
101
|
|
|
/** |
102
|
|
|
* @return float |
103
|
|
|
*/ |
104
|
1 |
|
public function getTotalDuration() |
105
|
|
|
{ |
106
|
1 |
|
return $this->totalDuration; |
107
|
|
|
} |
108
|
|
|
|
109
|
|
|
/** |
110
|
|
|
* @return float |
111
|
|
|
*/ |
112
|
1 |
|
public function getAvgDuration() |
113
|
|
|
{ |
114
|
1 |
|
return $this->avgDuration; |
115
|
|
|
} |
116
|
|
|
|
117
|
|
|
/** |
118
|
|
|
* @return float |
119
|
|
|
*/ |
120
|
1 |
|
public function getMinDuration() |
121
|
|
|
{ |
122
|
1 |
|
return $this->minDuration; |
123
|
|
|
} |
124
|
|
|
|
125
|
|
|
/** |
126
|
|
|
* @return float |
127
|
|
|
*/ |
128
|
1 |
|
public function getMaxDuration() |
129
|
|
|
{ |
130
|
1 |
|
return $this->maxDuration; |
131
|
|
|
} |
132
|
|
|
} |
133
|
|
|
|