1 | <?php |
||
16 | class Manager |
||
17 | { |
||
18 | use CondorcetVersion; |
||
19 | |||
20 | protected $_globalTimer = 0.0; |
||
21 | protected $_lastTimer; |
||
22 | protected $_lastChronoTimestamp = null; |
||
23 | protected $_startDeclare = null; |
||
24 | protected $_history = []; |
||
25 | |||
26 | 5 | public function addTime ( Chrono $chrono ) |
|
27 | { |
||
28 | 5 | if ($this->_lastChronoTimestamp === null && $chrono->getStart() !== $this->_startDeclare) : |
|
29 | return; |
||
30 | endif; |
||
31 | |||
32 | 5 | if ($chrono->getTimerManager() === $this) : |
|
33 | 5 | $m = microtime(true); |
|
34 | |||
35 | 5 | if ( $this->_lastChronoTimestamp > $chrono->getStart() ) : |
|
36 | 5 | $c = $this->_lastChronoTimestamp; |
|
37 | else : |
||
38 | 5 | $c = $chrono->getStart(); |
|
39 | 5 | $this->_history[] = [ 'role' => $chrono->getRole(), |
|
40 | 5 | 'process_in' => ($m - $c), |
|
41 | 5 | 'timer_start' => $c, |
|
42 | 5 | 'timer_end' => $m |
|
43 | ]; |
||
44 | endif; |
||
45 | |||
46 | 5 | $this->_globalTimer += ($m - $c); |
|
47 | |||
48 | 5 | $this->_lastTimer = ($m - $chrono->getStart()); |
|
49 | 5 | $this->_lastChronoTimestamp = $m; |
|
50 | else : |
||
51 | throw new CondorcetException (0, 'Only chrono linked to this Manager can be used'); |
||
52 | endif; |
||
53 | 5 | } |
|
54 | |||
55 | 1 | public function getGlobalTimer (bool $float = false) |
|
59 | |||
60 | 2 | public function getLastTimer (bool $float = false) |
|
64 | |||
65 | 1 | public function getHistory () : array |
|
69 | |||
70 | 5 | public function startDeclare (Chrono $chrono) |
|
76 | } |
||
77 |