1 | <?php |
||
5 | class Benchmark |
||
6 | { |
||
7 | /** |
||
8 | * Informative label containing request method and url |
||
9 | * |
||
10 | * @var string $request |
||
11 | */ |
||
12 | private static $request; |
||
13 | |||
14 | /** |
||
15 | * Float containing amount of time as microtime |
||
16 | * |
||
17 | * @var float $runtime |
||
18 | */ |
||
19 | private static $runtime; |
||
20 | |||
21 | /** |
||
22 | * Array containing measured memory data |
||
23 | * |
||
24 | * @var array $memory |
||
25 | */ |
||
26 | private static $memory = [ |
||
27 | 'unit' => 'Kb', |
||
28 | 'pre' => null, |
||
29 | 'post' => null, |
||
30 | ]; |
||
31 | |||
32 | /** |
||
33 | * Start measuring, called before request handling |
||
34 | * |
||
35 | * @param string $request |
||
36 | */ |
||
37 | public static function start(string $request) |
||
43 | |||
44 | |||
45 | /** |
||
46 | * Stop measuring, called after request handling |
||
47 | * |
||
48 | * @throws \Exception |
||
49 | */ |
||
50 | public static function stop() |
||
56 | |||
57 | /** |
||
58 | * Log and/or store measured data |
||
59 | * |
||
60 | * @throws \Exception |
||
61 | */ |
||
62 | private static function log() |
||
79 | |||
80 | |||
81 | private static function getResult() |
||
93 | |||
94 | /** |
||
95 | * Get current memory usage for measuring |
||
96 | * |
||
97 | * @return float |
||
98 | */ |
||
99 | private static function getCurrentMemoryUsage(): float |
||
109 | |||
110 | /** |
||
111 | * Get total measured memory usage |
||
112 | * |
||
113 | * @return object |
||
114 | */ |
||
115 | private static function getTotalMemoryUsage() |
||
132 | |||
133 | /** |
||
134 | * Get time between now and start() invocation |
||
135 | * |
||
136 | * @return float |
||
137 | */ |
||
138 | private static function getTime(): float |
||
144 | |||
145 | /** |
||
146 | * Increasing measured byte $amount in magnitude Kb -> Mb etc. |
||
147 | * |
||
148 | * @param int $amount |
||
149 | * @return float |
||
150 | */ |
||
151 | private static function increaseMagnitude(int $amount): float |
||
155 | |||
156 | /** |
||
157 | * @param $result |
||
158 | * |
||
159 | * @throws \Exception |
||
160 | */ |
||
161 | private static function storeJson($result) |
||
174 | |||
175 | /** |
||
176 | * @param array $requests |
||
177 | * @return mixed |
||
178 | * @throws \Exception |
||
179 | */ |
||
180 | private static function history(array $requests) |
||
199 | |||
200 | /** |
||
201 | * @param array $history |
||
202 | * @return bool |
||
203 | */ |
||
204 | private static function maxHistoryReached(array $history): bool |
||
208 | } |
||
209 | |||
210 |