Security update for permissions_by_term
[yaffs-website] / vendor / behat / behat / src / Behat / Testwork / Counter / Memory.php
1 <?php
2
3 /*
4  * This file is part of the Behat Testwork.
5  * (c) Konstantin Kudryashov <ever.zet@gmail.com>
6  *
7  * For the full copyright and license information, please view the LICENSE
8  * file that was distributed with this source code.
9  */
10
11 namespace Behat\Testwork\Counter;
12
13 /**
14  * Counts amount of system memory being used.
15  *
16  * @author Konstantin Kudryashov <ever.zet@gmail.com>
17  */
18 final class Memory
19 {
20     /**
21      * @var string[]
22      */
23     private $units = array('B', 'Kb', 'Mb', 'Gb', 'Tb');
24
25     /**
26      * Returns current memory usage.
27      *
28      * @return integer
29      */
30     public function getMemoryUsage()
31     {
32         return memory_get_usage();
33     }
34
35     /**
36      * Presents memory usage in human-readable form.
37      *
38      * @return string
39      */
40     public function __toString()
41     {
42         return $this->humanize($this->getMemoryUsage());
43     }
44
45     /**
46      * Humanizes usage information.
47      *
48      * @param integer $bytes
49      *
50      * @return string
51      */
52     private function humanize($bytes)
53     {
54         $e = intval(floor(log($bytes) / log(1024)));
55
56         if (!isset($this->units[$e])) {
57             return 'Can not calculate memory usage';
58         }
59
60         return sprintf('%.2f%s', ($bytes / pow(1024, floor($e))), $this->units[$e]);
61     }
62 }