1 | <?php |
||
7 | class ServerTiming |
||
8 | { |
||
9 | /** @var Stopwatch */ |
||
10 | protected $stopwatch; |
||
11 | |||
12 | /** @var array */ |
||
13 | protected $finishedEvents = []; |
||
14 | |||
15 | /** @var array */ |
||
16 | protected $startedEvents = []; |
||
17 | |||
18 | /** |
||
19 | * ServerTiming constructor. |
||
20 | * @param Stopwatch $stopwatch |
||
21 | */ |
||
22 | public function __construct(Stopwatch $stopwatch) |
||
26 | |||
27 | /** |
||
28 | * Add metric |
||
29 | * @param string $metric |
||
30 | * @return $this |
||
31 | */ |
||
32 | public function addMetric(string $metric) |
||
38 | |||
39 | /** |
||
40 | * Has started event |
||
41 | * @param string $key |
||
42 | * @return bool |
||
43 | */ |
||
44 | public function hasStartedEvent(string $key): bool |
||
48 | |||
49 | /** |
||
50 | * Measure |
||
51 | * @param string $key |
||
52 | * @return $this |
||
53 | */ |
||
54 | public function measure(string $key) |
||
62 | |||
63 | /** |
||
64 | * Start watching |
||
65 | * @param string $key |
||
66 | * @return $this |
||
67 | */ |
||
68 | public function start(string $key) |
||
76 | |||
77 | /** |
||
78 | * Stop watching |
||
79 | * @param string $key |
||
80 | * @return $this |
||
81 | */ |
||
82 | public function stop(string $key) |
||
94 | |||
95 | /** |
||
96 | * Stop all unfinished events |
||
97 | */ |
||
98 | public function stopAllUnfinishedEvents() |
||
104 | |||
105 | /** |
||
106 | * Set event duration |
||
107 | * @param string $key |
||
108 | * @param $duration |
||
109 | * @return $this |
||
110 | */ |
||
111 | public function setDuration(string $key, $duration) |
||
125 | |||
126 | /** |
||
127 | * Get event duration |
||
128 | * @param string $key |
||
129 | * @return mixed|null |
||
130 | */ |
||
131 | public function getDuration(string $key) |
||
135 | |||
136 | /** |
||
137 | * Get all events |
||
138 | * @return array |
||
139 | */ |
||
140 | public function events(): array |
||
144 | |||
145 | } |
||
146 |