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