| Total Complexity | 6 |
| Total Lines | 46 |
| Duplicated Lines | 0 % |
| Coverage | 100% |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
| 1 | <?php |
||
| 14 | class Memory |
||
| 15 | { |
||
| 16 | 1 | public function __construct() |
|
| 17 | { |
||
| 18 | 1 | } |
|
| 19 | |||
| 20 | /** |
||
| 21 | * $real=true shows allocated memory (-> system monitoring) |
||
| 22 | * $real=null|false shows memory used by script (-> memory leak search) |
||
| 23 | * Do not take PHP external resources into account (remote/DB connection, SimpleXML, etc) |
||
| 24 | * See http://drib.tech/programming/get-real-amount-memory-allocated-php. |
||
| 25 | * |
||
| 26 | * @param bool|null $real |
||
| 27 | * |
||
| 28 | * @return string |
||
| 29 | * @return string |
||
| 30 | */ |
||
| 31 | 1 | public function getMemory(?bool $real = null): string |
|
| 32 | { |
||
| 33 | 1 | return sprintf( |
|
| 34 | 1 | "Memory %s: %s %s \n", |
|
| 35 | 1 | ($real) ? '(true)' : '', |
|
| 36 | 1 | $this->memoryUsage(), |
|
| 37 | 1 | $this->memoryPeak() |
|
| 38 | ); |
||
| 39 | } |
||
| 40 | |||
| 41 | 1 | public function memoryUsage(?bool $real = null): string |
|
| 42 | { |
||
| 43 | 1 | $memUsage = memory_get_usage($real); |
|
| 44 | |||
| 45 | 1 | return sprintf('usage: %s', $this->convert($memUsage)); |
|
| 46 | } |
||
| 47 | |||
| 48 | 1 | public function memoryPeak(?bool $real = null): string |
|
| 53 | } |
||
| 54 | |||
| 55 | 1 | private function convert(int $size): string |
|
| 60 | } |
||
| 61 | } |
||
| 62 |