1
|
|
|
<?php declare(strict_types=1); |
2
|
|
|
|
3
|
|
|
namespace AlecRabbit\Accessories\MemoryUsage; |
4
|
|
|
|
5
|
|
|
use AlecRabbit\Accessories\MemoryUsage; |
6
|
|
|
|
7
|
|
|
class MemoryUsageReport implements MemoryUsageReportInterface |
8
|
|
|
{ |
9
|
|
|
/** @var int */ |
10
|
|
|
protected $usage; |
11
|
|
|
|
12
|
|
|
/** @var int */ |
13
|
|
|
protected $peakUsage; |
14
|
|
|
|
15
|
|
|
/** @var int */ |
16
|
|
|
protected $usageReal; |
17
|
|
|
|
18
|
|
|
/** @var int */ |
19
|
|
|
protected $peakUsageReal; |
20
|
|
|
|
21
|
|
|
/** |
22
|
|
|
* MemoryUsageReport constructor. |
23
|
|
|
* @param int $usage |
24
|
|
|
* @param int $peakUsage |
25
|
|
|
* @param int $usageReal |
26
|
|
|
* @param int $peakUsageReal |
27
|
|
|
*/ |
28
|
5 |
|
public function __construct(int $usage, int $peakUsage, int $usageReal, int $peakUsageReal) |
29
|
|
|
{ |
30
|
5 |
|
$this->usage = $usage; |
31
|
5 |
|
$this->peakUsage = $peakUsage; |
32
|
5 |
|
$this->usageReal = $usageReal; |
33
|
5 |
|
$this->peakUsageReal = $peakUsageReal; |
34
|
5 |
|
} |
35
|
|
|
|
36
|
3 |
|
public function __toString(): string |
37
|
|
|
{ |
38
|
3 |
|
return MemoryUsage::getFormatter()->process($this); |
39
|
|
|
} |
40
|
|
|
|
41
|
|
|
/** |
42
|
|
|
* {@inheritdoc} |
43
|
|
|
*/ |
44
|
5 |
|
public function getUsage(): int |
45
|
|
|
{ |
46
|
5 |
|
return $this->usage; |
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
/** |
50
|
|
|
* {@inheritdoc} |
51
|
|
|
*/ |
52
|
5 |
|
public function getPeakUsage(): int |
53
|
|
|
{ |
54
|
5 |
|
return $this->peakUsage; |
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
/** |
58
|
|
|
* {@inheritdoc} |
59
|
|
|
*/ |
60
|
5 |
|
public function getUsageReal(): int |
61
|
|
|
{ |
62
|
5 |
|
return $this->usageReal; |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
/** |
66
|
|
|
* {@inheritdoc} |
67
|
|
|
*/ |
68
|
5 |
|
public function getPeakUsageReal(): int |
69
|
|
|
{ |
70
|
5 |
|
return $this->peakUsageReal; |
71
|
|
|
} |
72
|
|
|
|
73
|
|
|
/** |
74
|
|
|
* {@inheritdoc} |
75
|
|
|
*/ |
76
|
1 |
|
public function getUsageString(?string $unit = null, ?int $decimals = null): string |
77
|
|
|
{ |
78
|
|
|
return |
79
|
1 |
|
MemoryUsage::getFormatter()->getUsageString($this, $unit, $decimals); |
80
|
|
|
} |
81
|
|
|
|
82
|
|
|
/** |
83
|
|
|
* {@inheritdoc} |
84
|
|
|
*/ |
85
|
1 |
|
public function getPeakUsageString(?string $unit = null, ?int $decimals = null): string |
86
|
|
|
{ |
87
|
|
|
return |
88
|
1 |
|
MemoryUsage::getFormatter()->getPeakUsageString($this, $unit, $decimals); |
89
|
|
|
} |
90
|
|
|
|
91
|
|
|
/** |
92
|
|
|
* {@inheritdoc} |
93
|
|
|
*/ |
94
|
1 |
|
public function getUsageRealString(?string $unit = null, ?int $decimals = null): string |
95
|
|
|
{ |
96
|
|
|
return |
97
|
1 |
|
MemoryUsage::getFormatter()->getUsageRealString($this, $unit, $decimals); |
98
|
|
|
} |
99
|
|
|
|
100
|
|
|
/** |
101
|
|
|
* {@inheritdoc} |
102
|
|
|
*/ |
103
|
1 |
|
public function getPeakUsageRealString(?string $unit = null, ?int $decimals = null): string |
104
|
|
|
{ |
105
|
|
|
return |
106
|
1 |
|
MemoryUsage::getFormatter()->getPeakUsageRealString($this, $unit, $decimals); |
107
|
|
|
} |
108
|
|
|
} |
109
|
|
|
|