@@ -2,7 +2,6 @@ |
||
| 2 | 2 | |
| 3 | 3 | namespace CloudFramework\Tool; |
| 4 | 4 | |
| 5 | -use CloudFramework\CloudFrameworkApp; |
|
| 6 | 5 | use CloudFramework\Patterns\Singleton; |
| 7 | 6 | |
| 8 | 7 | class Performance extends Singleton |
@@ -28,10 +28,15 @@ discard block |
||
| 28 | 28 | $file = str_replace($_SERVER['DOCUMENT_ROOT'], '', $file); |
| 29 | 29 | |
| 30 | 30 | |
| 31 | - if ($type == 'note') $line = "[$type"; |
|
| 32 | - else $line = $this->data['lastIndex'] . ' ['; |
|
| 31 | + if ($type == 'note') { |
|
| 32 | + $line = "[$type"; |
|
| 33 | + } else { |
|
| 34 | + $line = $this->data['lastIndex'] . ' ['; |
|
| 35 | + } |
|
| 33 | 36 | |
| 34 | - if (strlen($file)) $file = " ($file)"; |
|
| 37 | + if (strlen($file)) { |
|
| 38 | + $file = " ($file)"; |
|
| 39 | + } |
|
| 35 | 40 | |
| 36 | 41 | $_mem = memory_get_usage() / (1024 * 1024) - $this->data['lastMemory']; |
| 37 | 42 | if ($type == 'all' || $type == 'endnote' || $type == 'memory' || $_GET['data'] == $this->data['lastIndex']) { |
@@ -48,7 +53,9 @@ discard block |
||
| 48 | 53 | $line = (($type != 'note') ? '[' . number_format(round(memory_get_usage() / (1024 * 1024), 3), 3) . ' Mb, ' |
| 49 | 54 | . (round(microtime(TRUE) - $this->data['initMicrotime'], 3)) |
| 50 | 55 | . ' secs] / ' : '') . $line . $file; |
| 51 | - if ($type == 'endnote') $line = "[$type] " . $line; |
|
| 56 | + if ($type == 'endnote') { |
|
| 57 | + $line = "[$type] " . $line; |
|
| 58 | + } |
|
| 52 | 59 | $this->data['info'][] = $line; |
| 53 | 60 | |
| 54 | 61 | if ($title) { |
@@ -79,26 +86,34 @@ discard block |
||
| 79 | 86 | $this->data['init'][$spacename][$key]['mem'] = round((memory_get_usage() - $this->data['init'][$spacename][$key]['mem']) / (1024 * 1024), 3) . ' Mb'; |
| 80 | 87 | $this->data['init'][$spacename][$key]['time'] = round(microtime(TRUE) - $this->data['init'][$spacename][$key]['time'], 3) . ' secs'; |
| 81 | 88 | $this->data['init'][$spacename][$key]['ok'] = $ok; |
| 82 | - if ($msg !== FALSE) $this->data['init'][$spacename][$key]['notes'] = $msg; |
|
| 89 | + if ($msg !== FALSE) { |
|
| 90 | + $this->data['init'][$spacename][$key]['notes'] = $msg; |
|
| 91 | + } |
|
| 83 | 92 | } |
| 84 | 93 | |
| 85 | 94 | function getLog() |
| 86 | 95 | { |
| 87 | 96 | $ret = ''; |
| 88 | 97 | $spaces = ""; |
| 89 | - if (is_array($this->data['info'])) |
|
| 90 | - foreach ($this->data['info'] as $key => $value) { |
|
| 98 | + if (is_array($this->data['info'])) { |
|
| 99 | + foreach ($this->data['info'] as $key => $value) { |
|
| 91 | 100 | if (is_string($value) && strpos($value, '[endnote]') !== FALSE) $spaces = substr($spaces, 0, -2); |
| 101 | + } |
|
| 92 | 102 | $ret .= $spaces; |
| 93 | 103 | $ret .= ((is_string($value)) ? $value : print_r($value, TRUE)) . "\n"; |
| 94 | - if (is_string($value) && strpos($value, '[note]') !== FALSE) $spaces .= " "; |
|
| 95 | - if (is_string($value) && strpos($value, '[endnote]') !== FALSE) $ret .= "\n"; |
|
| 104 | + if (is_string($value) && strpos($value, '[note]') !== FALSE) { |
|
| 105 | + $spaces .= " "; |
|
| 106 | + } |
|
| 107 | + if (is_string($value) && strpos($value, '[endnote]') !== FALSE) { |
|
| 108 | + $ret .= "\n"; |
|
| 109 | + } |
|
| 96 | 110 | |
| 97 | 111 | } |
| 98 | 112 | $ret .= "\n\nTOTALS:\n"; |
| 99 | - if (is_array($this->data['titles'])) |
|
| 100 | - foreach ($this->data['titles'] as $key => $value) { |
|
| 113 | + if (is_array($this->data['titles'])) { |
|
| 114 | + foreach ($this->data['titles'] as $key => $value) { |
|
| 101 | 115 | $ret .= "[$key] : " . round($value['mem'], 3) . ' Mb / ' . round($value['time'], 3) . " secs.\n"; |
| 116 | + } |
|
| 102 | 117 | } |
| 103 | 118 | |
| 104 | 119 | return $ret; |
@@ -126,11 +141,17 @@ discard block |
||
| 126 | 141 | echo $title; |
| 127 | 142 | $spaces = ""; |
| 128 | 143 | foreach ($__p->data['info'] as $key => $value) { |
| 129 | - if (is_string($value) && strpos($value, '[endnote]') !== FALSE) $spaces = substr($spaces, 0, -2); |
|
| 144 | + if (is_string($value) && strpos($value, '[endnote]') !== FALSE) { |
|
| 145 | + $spaces = substr($spaces, 0, -2); |
|
| 146 | + } |
|
| 130 | 147 | echo $spaces; |
| 131 | 148 | echo ((is_string($value)) ? $value : print_r($value, TRUE)) . "\n"; |
| 132 | - if (is_string($value) && strpos($value, '[note]') !== FALSE) $spaces .= " "; |
|
| 133 | - if (is_string($value) && strpos($value, '[endnote]') !== FALSE) echo "\n"; |
|
| 149 | + if (is_string($value) && strpos($value, '[note]') !== FALSE) { |
|
| 150 | + $spaces .= " "; |
|
| 151 | + } |
|
| 152 | + if (is_string($value) && strpos($value, '[endnote]') !== FALSE) { |
|
| 153 | + echo "\n"; |
|
| 154 | + } |
|
| 134 | 155 | |
| 135 | 156 | } |
| 136 | 157 | echo "\n\nTOTALS:\n"; |
@@ -144,27 +165,32 @@ discard block |
||
| 144 | 165 | function __p($title = NULL, $file = NULL, $type = 'all') |
| 145 | 166 | { |
| 146 | 167 | $__p = Performance::getInstance(); |
| 147 | - if ($title === NULL && $file == NULL) return $__p->data; |
|
| 148 | - else $__p->add($title, $file, $type); |
|
| 149 | -} |
|
| 168 | + if ($title === NULL && $file == NULL) { |
|
| 169 | + return $__p->data; |
|
| 170 | + } else { |
|
| 171 | + $__p->add($title, $file, $type); |
|
| 172 | + } |
|
| 173 | + } |
|
| 150 | 174 | |
| 151 | 175 | function __print($args) |
| 152 | 176 | { |
| 153 | 177 | echo "<pre>"; |
| 154 | 178 | for ($i = 0, $tr = count($args); $i < $tr; $i++) { |
| 155 | - if ($args[$i] === "exit") |
|
| 156 | - exit; |
|
| 179 | + if ($args[$i] === "exit") { |
|
| 180 | + exit; |
|
| 181 | + } |
|
| 157 | 182 | echo "\n<li>[$i]: "; |
| 158 | - if (is_array($args[$i])) |
|
| 159 | - echo print_r($args[$i], TRUE); |
|
| 160 | - else if (is_object($args[$i])) |
|
| 161 | - echo var_dump($args[$i]); |
|
| 162 | - else if (is_bool($args[$i])) |
|
| 163 | - echo ($args[$i]) ? 'true' : 'false'; |
|
| 164 | - else if (is_null($args[$i])) |
|
| 165 | - echo 'NULL'; |
|
| 166 | - else |
|
| 167 | - echo $args[$i]; |
|
| 183 | + if (is_array($args[$i])) { |
|
| 184 | + echo print_r($args[$i], TRUE); |
|
| 185 | + } else if (is_object($args[$i])) { |
|
| 186 | + echo var_dump($args[$i]); |
|
| 187 | + } else if (is_bool($args[$i])) { |
|
| 188 | + echo ($args[$i]) ? 'true' : 'false'; |
|
| 189 | + } else if (is_null($args[$i])) { |
|
| 190 | + echo 'NULL'; |
|
| 191 | + } else { |
|
| 192 | + echo $args[$i]; |
|
| 193 | + } |
|
| 168 | 194 | } |
| 169 | 195 | echo "</pre>"; |
| 170 | 196 | } |
@@ -13,7 +13,7 @@ discard block |
||
| 13 | 13 | function __construct() |
| 14 | 14 | { |
| 15 | 15 | // Performance Vars |
| 16 | - $this->data['initMicrotime'] = microtime(TRUE); |
|
| 16 | + $this->data['initMicrotime'] = microtime(true); |
|
| 17 | 17 | $this->data['lastMicrotime'] = $this->data['initMicrotime']; |
| 18 | 18 | $this->data['initMemory'] = memory_get_usage() / (1024 * 1024); |
| 19 | 19 | $this->data['lastMemory'] = $this->data['initMemory']; |
@@ -39,14 +39,14 @@ discard block |
||
| 39 | 39 | $this->data['lastMemory'] = memory_get_usage() / (1024 * 1024); |
| 40 | 40 | } |
| 41 | 41 | |
| 42 | - $_time = microtime(TRUE) - $this->data['lastMicrotime']; |
|
| 42 | + $_time = microtime(true) - $this->data['lastMicrotime']; |
|
| 43 | 43 | if ($type == 'all' || $type == 'endnote' || $type == 'time' || $_GET['data'] == $this->data['lastIndex']) { |
| 44 | 44 | $line .= (($line == '[') ? '' : ', ') . (round($_time, 3)) . ' secs'; |
| 45 | - $this->data['lastMicrotime'] = microtime(TRUE); |
|
| 45 | + $this->data['lastMicrotime'] = microtime(true); |
|
| 46 | 46 | } |
| 47 | 47 | $line .= '] ' . $title; |
| 48 | 48 | $line = (($type != 'note') ? '[' . number_format(round(memory_get_usage() / (1024 * 1024), 3), 3) . ' Mb, ' |
| 49 | - . (round(microtime(TRUE) - $this->data['initMicrotime'], 3)) |
|
| 49 | + . (round(microtime(true) - $this->data['initMicrotime'], 3)) |
|
| 50 | 50 | . ' secs] / ' : '') . $line . $file; |
| 51 | 51 | if ($type == 'endnote') $line = "[$type] " . $line; |
| 52 | 52 | $this->data['info'][] = $line; |
@@ -70,16 +70,16 @@ discard block |
||
| 70 | 70 | function init($spacename, $key) |
| 71 | 71 | { |
| 72 | 72 | $this->data['init'][$spacename][$key]['mem'] = memory_get_usage(); |
| 73 | - $this->data['init'][$spacename][$key]['time'] = microtime(TRUE); |
|
| 74 | - $this->data['init'][$spacename][$key]['ok'] = TRUE; |
|
| 73 | + $this->data['init'][$spacename][$key]['time'] = microtime(true); |
|
| 74 | + $this->data['init'][$spacename][$key]['ok'] = true; |
|
| 75 | 75 | } |
| 76 | 76 | |
| 77 | - function end($spacename, $key, $ok = TRUE, $msg = FALSE) |
|
| 77 | + function end($spacename, $key, $ok = true, $msg = false) |
|
| 78 | 78 | { |
| 79 | 79 | $this->data['init'][$spacename][$key]['mem'] = round((memory_get_usage() - $this->data['init'][$spacename][$key]['mem']) / (1024 * 1024), 3) . ' Mb'; |
| 80 | - $this->data['init'][$spacename][$key]['time'] = round(microtime(TRUE) - $this->data['init'][$spacename][$key]['time'], 3) . ' secs'; |
|
| 80 | + $this->data['init'][$spacename][$key]['time'] = round(microtime(true) - $this->data['init'][$spacename][$key]['time'], 3) . ' secs'; |
|
| 81 | 81 | $this->data['init'][$spacename][$key]['ok'] = $ok; |
| 82 | - if ($msg !== FALSE) $this->data['init'][$spacename][$key]['notes'] = $msg; |
|
| 82 | + if ($msg !== false) $this->data['init'][$spacename][$key]['notes'] = $msg; |
|
| 83 | 83 | } |
| 84 | 84 | |
| 85 | 85 | function getLog() |
@@ -88,11 +88,11 @@ discard block |
||
| 88 | 88 | $spaces = ""; |
| 89 | 89 | if (is_array($this->data['info'])) |
| 90 | 90 | foreach ($this->data['info'] as $key => $value) { |
| 91 | - if (is_string($value) && strpos($value, '[endnote]') !== FALSE) $spaces = substr($spaces, 0, -2); |
|
| 91 | + if (is_string($value) && strpos($value, '[endnote]') !== false) $spaces = substr($spaces, 0, -2); |
|
| 92 | 92 | $ret .= $spaces; |
| 93 | - $ret .= ((is_string($value)) ? $value : print_r($value, TRUE)) . "\n"; |
|
| 94 | - if (is_string($value) && strpos($value, '[note]') !== FALSE) $spaces .= " "; |
|
| 95 | - if (is_string($value) && strpos($value, '[endnote]') !== FALSE) $ret .= "\n"; |
|
| 93 | + $ret .= ((is_string($value)) ? $value : print_r($value, true)) . "\n"; |
|
| 94 | + if (is_string($value) && strpos($value, '[note]') !== false) $spaces .= " "; |
|
| 95 | + if (is_string($value) && strpos($value, '[endnote]') !== false) $ret .= "\n"; |
|
| 96 | 96 | |
| 97 | 97 | } |
| 98 | 98 | $ret .= "\n\nTOTALS:\n"; |
@@ -126,11 +126,11 @@ discard block |
||
| 126 | 126 | echo $title; |
| 127 | 127 | $spaces = ""; |
| 128 | 128 | foreach ($__p->data['info'] as $key => $value) { |
| 129 | - if (is_string($value) && strpos($value, '[endnote]') !== FALSE) $spaces = substr($spaces, 0, -2); |
|
| 129 | + if (is_string($value) && strpos($value, '[endnote]') !== false) $spaces = substr($spaces, 0, -2); |
|
| 130 | 130 | echo $spaces; |
| 131 | - echo ((is_string($value)) ? $value : print_r($value, TRUE)) . "\n"; |
|
| 132 | - if (is_string($value) && strpos($value, '[note]') !== FALSE) $spaces .= " "; |
|
| 133 | - if (is_string($value) && strpos($value, '[endnote]') !== FALSE) echo "\n"; |
|
| 131 | + echo ((is_string($value)) ? $value : print_r($value, true)) . "\n"; |
|
| 132 | + if (is_string($value) && strpos($value, '[note]') !== false) $spaces .= " "; |
|
| 133 | + if (is_string($value) && strpos($value, '[endnote]') !== false) echo "\n"; |
|
| 134 | 134 | |
| 135 | 135 | } |
| 136 | 136 | echo "\n\nTOTALS:\n"; |
@@ -141,10 +141,10 @@ discard block |
||
| 141 | 141 | echo $bottom; |
| 142 | 142 | } |
| 143 | 143 | |
| 144 | -function __p($title = NULL, $file = NULL, $type = 'all') |
|
| 144 | +function __p($title = null, $file = null, $type = 'all') |
|
| 145 | 145 | { |
| 146 | 146 | $__p = Performance::getInstance(); |
| 147 | - if ($title === NULL && $file == NULL) return $__p->data; |
|
| 147 | + if ($title === null && $file == null) return $__p->data; |
|
| 148 | 148 | else $__p->add($title, $file, $type); |
| 149 | 149 | } |
| 150 | 150 | |
@@ -156,7 +156,7 @@ discard block |
||
| 156 | 156 | exit; |
| 157 | 157 | echo "\n<li>[$i]: "; |
| 158 | 158 | if (is_array($args[$i])) |
| 159 | - echo print_r($args[$i], TRUE); |
|
| 159 | + echo print_r($args[$i], true); |
|
| 160 | 160 | else if (is_object($args[$i])) |
| 161 | 161 | echo var_dump($args[$i]); |
| 162 | 162 | else if (is_bool($args[$i])) |