|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* User: alec |
|
4
|
|
|
* Date: 29.11.18 |
|
5
|
|
|
* Time: 21:02 |
|
6
|
|
|
*/ |
|
7
|
|
|
|
|
8
|
|
|
namespace AlecRabbit\Tools\Reports; |
|
9
|
|
|
|
|
10
|
|
|
use AlecRabbit\Tools\Reports\Base\Report; |
|
11
|
|
|
use AlecRabbit\Tools\Timer; |
|
12
|
|
|
use AlecRabbit\Tools\Traits\TimerFields; |
|
13
|
|
|
use function AlecRabbit\format_time; |
|
14
|
|
|
use const AlecRabbit\Constants\Accessories\DEFAULT_NAME; |
|
|
|
|
|
|
15
|
|
|
|
|
16
|
|
|
class TimerReport extends Report |
|
17
|
|
|
{ |
|
18
|
|
|
use TimerFields; |
|
19
|
|
|
|
|
20
|
|
|
/** |
|
21
|
|
|
* TimerReport constructor. |
|
22
|
|
|
* @param Timer $timer |
|
23
|
|
|
*/ |
|
24
|
7 |
|
public function __construct(Timer $timer) |
|
25
|
|
|
{ |
|
26
|
7 |
|
$count = $timer->getCount(); |
|
27
|
7 |
|
$this->name = $timer->getName(); |
|
28
|
7 |
|
$this->previous = $timer->getPrevious(); |
|
29
|
7 |
|
$this->creation = $timer->getCreation(); |
|
30
|
7 |
|
$this->start = $timer->getStart(); |
|
31
|
7 |
|
$this->elapsed = $timer->getElapsed(); |
|
32
|
7 |
|
$this->stopped = $timer->isStopped(); |
|
33
|
7 |
|
$this->currentValue = $timer->getLastValue(); |
|
34
|
7 |
|
$this->minValueIteration = $timer->getMinValueIteration(); |
|
35
|
7 |
|
$this->maxValueIteration = $timer->getMaxValueIteration(); |
|
36
|
7 |
|
$this->avgValue = $timer->getAverageValue(); |
|
37
|
7 |
|
$this->minValue = ($count === 1) ? $timer->getLastValue() : $timer->getMinValue(); |
|
38
|
7 |
|
$this->maxValue = $timer->getMaxValue(); |
|
39
|
7 |
|
$this->count = $count; |
|
40
|
7 |
|
} |
|
41
|
|
|
|
|
42
|
|
|
/** |
|
43
|
|
|
* @return string |
|
44
|
|
|
*/ |
|
45
|
1 |
|
public function __toString(): string |
|
46
|
|
|
{ |
|
47
|
1 |
|
if (DEFAULT_NAME === $name = $this->getName()) { |
|
48
|
|
|
return |
|
49
|
1 |
|
sprintf( |
|
50
|
1 |
|
'Elapsed: %s %s', |
|
51
|
1 |
|
format_time($this->getElapsed()), |
|
52
|
1 |
|
PHP_EOL |
|
53
|
|
|
); |
|
54
|
|
|
} |
|
55
|
|
|
return |
|
56
|
1 |
|
sprintf( |
|
57
|
1 |
|
'Timer:[%s] Average: %s, Last: %s, Min(%s): %s, Max(%s): %s, Count: %s' . PHP_EOL, |
|
58
|
1 |
|
$name, |
|
59
|
1 |
|
format_time($this->getAverageValue()), |
|
60
|
1 |
|
format_time($this->getLastValue()), |
|
61
|
1 |
|
$this->getMinValueIteration(), |
|
62
|
1 |
|
format_time($this->getMinValue()), |
|
63
|
1 |
|
$this->getMaxValueIteration(), |
|
64
|
1 |
|
format_time($this->getMaxValue()), |
|
65
|
1 |
|
$this->getCount() |
|
66
|
|
|
); |
|
67
|
|
|
} |
|
68
|
|
|
} |
|
69
|
|
|
|