1 | <?php |
||
12 | class Profiler implements ProfilerInterface |
||
13 | { |
||
14 | /** |
||
15 | * @var BenchmarkInterface[] |
||
16 | */ |
||
17 | protected $benchmarks = []; |
||
18 | |||
19 | /** |
||
20 | * @var AggregatorInterface[] |
||
21 | */ |
||
22 | protected $aggregators = []; |
||
23 | |||
24 | /** |
||
25 | * @var double Starting time |
||
26 | */ |
||
27 | protected $start; |
||
28 | |||
29 | /** |
||
30 | * Save start time on construction |
||
31 | */ |
||
32 | 4 | public function __construct() |
|
36 | |||
37 | /** |
||
38 | * Start a new benchmark |
||
39 | * |
||
40 | * @param string $name Unique identifier like e.g. Class::Method (\Foobar\MyClass::doSomething) |
||
41 | * @param array $metadata Additional metadata |
||
42 | * @param string $component Name of the component which triggered the benchmark, e.g. "App", "Database" |
||
43 | * @return BenchmarkInterface The started benchmark |
||
44 | */ |
||
45 | 1 | public function start($name, array $metadata = [], $component = null) |
|
56 | |||
57 | /** |
||
58 | * Stop a running benchmark |
||
59 | * If no benchmark provided, the last started benchmark is stopped |
||
60 | * |
||
61 | * @param BenchmarkInterface $benchmark Benchmark identifier |
||
62 | * @param array $metadata Additional metadata |
||
63 | * @throws UnknownBenchmarkException |
||
64 | * @return BenchmarkInterface $benchmark |
||
65 | */ |
||
66 | 4 | public function stop(BenchmarkInterface $benchmark = null, array $metadata = []) |
|
81 | |||
82 | /** |
||
83 | * @param BenchmarkInterface $benchmark |
||
84 | * @return $this |
||
85 | */ |
||
86 | 1 | public function addBenchmark(BenchmarkInterface $benchmark) |
|
92 | |||
93 | /** |
||
94 | * Get the total number of elapsed time in milliseconds |
||
95 | * |
||
96 | * @return double Total number of elapsed milliseconds |
||
97 | */ |
||
98 | 2 | public function getDuration() |
|
105 | |||
106 | /** |
||
107 | * Get the start of the profiler in microtime |
||
108 | * |
||
109 | * @return double Timestamp in microtime |
||
110 | */ |
||
111 | 1 | public function getStartTime() |
|
115 | |||
116 | /** |
||
117 | * Return all measured benchmarks |
||
118 | * |
||
119 | * @return BenchmarkInterface[] |
||
120 | */ |
||
121 | 1 | public function getBenchmarks() |
|
125 | |||
126 | /** |
||
127 | * @return BenchmarkInterface |
||
128 | * @throws UnknownBenchmarkException |
||
129 | */ |
||
130 | 3 | public function getLastBenchmark() |
|
139 | |||
140 | /** |
||
141 | * Add an aggregator to the profiler |
||
142 | * |
||
143 | * @param AggregatorInterface $aggregator |
||
144 | * @return $this |
||
145 | */ |
||
146 | 2 | public function addAggregator(AggregatorInterface $aggregator) |
|
150 | |||
151 | /** |
||
152 | * @return AggregatorInterface[] |
||
153 | */ |
||
154 | 2 | public function getAggregators() |
|
158 | |||
159 | /** |
||
160 | * @param BenchmarkInterface $benchmark |
||
161 | */ |
||
162 | 1 | public function aggregate(BenchmarkInterface $benchmark) |
|
168 | |||
169 | /** |
||
170 | * Get the total number of benchmarks |
||
171 | * |
||
172 | * @return int Total number of benchmarks |
||
173 | */ |
||
174 | 1 | public function count() |
|
178 | |||
179 | /** |
||
180 | * Return the current benchmark |
||
181 | * |
||
182 | * @return BenchmarkInterface|bool |
||
183 | */ |
||
184 | 1 | public function current() |
|
188 | |||
189 | /** |
||
190 | * Move forward to next benchmark |
||
191 | * |
||
192 | * @return void |
||
193 | */ |
||
194 | 1 | public function next() |
|
198 | |||
199 | /** |
||
200 | * Return the key of the current Benchmark |
||
201 | * |
||
202 | * @return string |
||
203 | */ |
||
204 | 1 | public function key() |
|
208 | |||
209 | /** |
||
210 | * Checks if current position is valid |
||
211 | * |
||
212 | * @return bool |
||
213 | */ |
||
214 | 1 | public function valid() |
|
224 | |||
225 | /** |
||
226 | * Rewind the Iterator to the first benchmark |
||
227 | * |
||
228 | * @return void |
||
229 | */ |
||
230 | 1 | public function rewind() |
|
234 | } |
||
235 |