@@ -5,112 +5,112 @@ |
||
| 5 | 5 | class ConsoleTest extends PHPUnit_Framework_TestCase |
| 6 | 6 | { |
| 7 | 7 | |
| 8 | - public function __construct() |
|
| 9 | - { |
|
| 10 | - } |
|
| 11 | - |
|
| 12 | - public function testLog() |
|
| 13 | - { |
|
| 14 | - $data = array( |
|
| 15 | - 'key' => 'value' |
|
| 16 | - ); |
|
| 17 | - |
|
| 18 | - $console = new Console(); |
|
| 19 | - $console->log($data); |
|
| 20 | - $store = $this->getProtectedStore($console); |
|
| 21 | - $log = array_pop($store); |
|
| 22 | - |
|
| 23 | - $this->assertSame($data, $log['data']); |
|
| 24 | - $this->assertEquals('log', $log['type']); |
|
| 25 | - } |
|
| 26 | - |
|
| 27 | - public function testLogMemory() |
|
| 28 | - { |
|
| 29 | - $data = array( |
|
| 30 | - 'key' => 'value' |
|
| 31 | - ); |
|
| 32 | - $memory = strlen(serialize($data)); |
|
| 33 | - $name = 'Test Array'; |
|
| 34 | - |
|
| 35 | - $console = new Console(); |
|
| 36 | - $console->logMemory($data, $name); |
|
| 37 | - $store = $this->getProtectedStore($console); |
|
| 38 | - $log = array_pop($store); |
|
| 39 | - |
|
| 40 | - $this->assertEquals($name, $log['name']); |
|
| 41 | - $this->assertEquals($memory, $log['data']); |
|
| 42 | - $this->assertEquals('array', $log['data_type']); |
|
| 43 | - $this->assertEquals('memory', $log['type']); |
|
| 44 | - } |
|
| 45 | - |
|
| 46 | - public function testLogError() |
|
| 47 | - { |
|
| 48 | - $error = new Exception('Test Exception'); |
|
| 49 | - |
|
| 50 | - $console = new Console(); |
|
| 51 | - $console->logError($error); |
|
| 52 | - $store = $this->getProtectedStore($console); |
|
| 53 | - $log = array_pop($store); |
|
| 54 | - |
|
| 55 | - $this->assertEquals($error->getMessage(), $log['data']); |
|
| 56 | - $this->assertEquals($error->getFile(), $log['file']); |
|
| 57 | - $this->assertEquals($error->getLine(), $log['line']); |
|
| 58 | - $this->assertEquals('error', $log['type']); |
|
| 59 | - |
|
| 60 | - $error = new Exception('Test Exception'); |
|
| 61 | - $message = 'override message'; |
|
| 62 | - |
|
| 63 | - $console = new Console(); |
|
| 64 | - $console->logError($error, $message); |
|
| 65 | - $store = $this->getProtectedStore($console); |
|
| 66 | - $log = array_pop($store); |
|
| 67 | - |
|
| 68 | - $this->assertEquals($message, $log['data']); |
|
| 69 | - } |
|
| 70 | - |
|
| 71 | - public function testLogSpeed() |
|
| 72 | - { |
|
| 73 | - $name = 'Test Speed'; |
|
| 74 | - |
|
| 75 | - $console = new Console(); |
|
| 76 | - $console->logSpeed($name); |
|
| 77 | - $store = $this->getProtectedStore($console); |
|
| 78 | - $log = array_pop($store); |
|
| 79 | - |
|
| 80 | - $this->assertEquals($name, $log['name']); |
|
| 81 | - $this->assertEquals('speed', $log['type']); |
|
| 82 | - } |
|
| 83 | - |
|
| 84 | - public function testGetLogs() |
|
| 85 | - { |
|
| 86 | - $store = array( |
|
| 87 | - array( |
|
| 88 | - 'data' => 'a string', |
|
| 89 | - 'type' => 'log' |
|
| 90 | - ), |
|
| 91 | - array( |
|
| 92 | - 'name' => '', |
|
| 93 | - 'data' => 123, |
|
| 94 | - 'data_type' => 'array', |
|
| 95 | - 'type' => 'memory' |
|
| 96 | - ) |
|
| 97 | - ); |
|
| 98 | - |
|
| 99 | - $console = new Console(); |
|
| 100 | - |
|
| 101 | - $reflectedConsole = new ReflectionClass(get_class($console)); |
|
| 102 | - $reflectedProperty = $reflectedConsole->getProperty('store'); |
|
| 103 | - $reflectedProperty->setAccessible(true); |
|
| 104 | - $reflectedProperty->setValue($console, $store); |
|
| 105 | - |
|
| 106 | - $this->assertSame($store, $console->getLogs()); |
|
| 107 | - } |
|
| 108 | - |
|
| 109 | - protected function getProtectedStore(Console $console) |
|
| 110 | - { |
|
| 111 | - $reflectedConsole = new ReflectionClass(get_class($console)); |
|
| 112 | - $reflectedProperty = $reflectedConsole->getProperty('store'); |
|
| 113 | - $reflectedProperty->setAccessible(true); |
|
| 114 | - return $reflectedProperty->getValue($console); |
|
| 115 | - } |
|
| 8 | + public function __construct() |
|
| 9 | + { |
|
| 10 | + } |
|
| 11 | + |
|
| 12 | + public function testLog() |
|
| 13 | + { |
|
| 14 | + $data = array( |
|
| 15 | + 'key' => 'value' |
|
| 16 | + ); |
|
| 17 | + |
|
| 18 | + $console = new Console(); |
|
| 19 | + $console->log($data); |
|
| 20 | + $store = $this->getProtectedStore($console); |
|
| 21 | + $log = array_pop($store); |
|
| 22 | + |
|
| 23 | + $this->assertSame($data, $log['data']); |
|
| 24 | + $this->assertEquals('log', $log['type']); |
|
| 25 | + } |
|
| 26 | + |
|
| 27 | + public function testLogMemory() |
|
| 28 | + { |
|
| 29 | + $data = array( |
|
| 30 | + 'key' => 'value' |
|
| 31 | + ); |
|
| 32 | + $memory = strlen(serialize($data)); |
|
| 33 | + $name = 'Test Array'; |
|
| 34 | + |
|
| 35 | + $console = new Console(); |
|
| 36 | + $console->logMemory($data, $name); |
|
| 37 | + $store = $this->getProtectedStore($console); |
|
| 38 | + $log = array_pop($store); |
|
| 39 | + |
|
| 40 | + $this->assertEquals($name, $log['name']); |
|
| 41 | + $this->assertEquals($memory, $log['data']); |
|
| 42 | + $this->assertEquals('array', $log['data_type']); |
|
| 43 | + $this->assertEquals('memory', $log['type']); |
|
| 44 | + } |
|
| 45 | + |
|
| 46 | + public function testLogError() |
|
| 47 | + { |
|
| 48 | + $error = new Exception('Test Exception'); |
|
| 49 | + |
|
| 50 | + $console = new Console(); |
|
| 51 | + $console->logError($error); |
|
| 52 | + $store = $this->getProtectedStore($console); |
|
| 53 | + $log = array_pop($store); |
|
| 54 | + |
|
| 55 | + $this->assertEquals($error->getMessage(), $log['data']); |
|
| 56 | + $this->assertEquals($error->getFile(), $log['file']); |
|
| 57 | + $this->assertEquals($error->getLine(), $log['line']); |
|
| 58 | + $this->assertEquals('error', $log['type']); |
|
| 59 | + |
|
| 60 | + $error = new Exception('Test Exception'); |
|
| 61 | + $message = 'override message'; |
|
| 62 | + |
|
| 63 | + $console = new Console(); |
|
| 64 | + $console->logError($error, $message); |
|
| 65 | + $store = $this->getProtectedStore($console); |
|
| 66 | + $log = array_pop($store); |
|
| 67 | + |
|
| 68 | + $this->assertEquals($message, $log['data']); |
|
| 69 | + } |
|
| 70 | + |
|
| 71 | + public function testLogSpeed() |
|
| 72 | + { |
|
| 73 | + $name = 'Test Speed'; |
|
| 74 | + |
|
| 75 | + $console = new Console(); |
|
| 76 | + $console->logSpeed($name); |
|
| 77 | + $store = $this->getProtectedStore($console); |
|
| 78 | + $log = array_pop($store); |
|
| 79 | + |
|
| 80 | + $this->assertEquals($name, $log['name']); |
|
| 81 | + $this->assertEquals('speed', $log['type']); |
|
| 82 | + } |
|
| 83 | + |
|
| 84 | + public function testGetLogs() |
|
| 85 | + { |
|
| 86 | + $store = array( |
|
| 87 | + array( |
|
| 88 | + 'data' => 'a string', |
|
| 89 | + 'type' => 'log' |
|
| 90 | + ), |
|
| 91 | + array( |
|
| 92 | + 'name' => '', |
|
| 93 | + 'data' => 123, |
|
| 94 | + 'data_type' => 'array', |
|
| 95 | + 'type' => 'memory' |
|
| 96 | + ) |
|
| 97 | + ); |
|
| 98 | + |
|
| 99 | + $console = new Console(); |
|
| 100 | + |
|
| 101 | + $reflectedConsole = new ReflectionClass(get_class($console)); |
|
| 102 | + $reflectedProperty = $reflectedConsole->getProperty('store'); |
|
| 103 | + $reflectedProperty->setAccessible(true); |
|
| 104 | + $reflectedProperty->setValue($console, $store); |
|
| 105 | + |
|
| 106 | + $this->assertSame($store, $console->getLogs()); |
|
| 107 | + } |
|
| 108 | + |
|
| 109 | + protected function getProtectedStore(Console $console) |
|
| 110 | + { |
|
| 111 | + $reflectedConsole = new ReflectionClass(get_class($console)); |
|
| 112 | + $reflectedProperty = $reflectedConsole->getProperty('store'); |
|
| 113 | + $reflectedProperty->setAccessible(true); |
|
| 114 | + return $reflectedProperty->getValue($console); |
|
| 115 | + } |
|
| 116 | 116 | } |
@@ -6,18 +6,18 @@ |
||
| 6 | 6 | class PhpQuickProfilerTest extends PHPUnit_Framework_TestCase |
| 7 | 7 | { |
| 8 | 8 | |
| 9 | - public function __construct() |
|
| 10 | - { |
|
| 11 | - } |
|
| 9 | + public function __construct() |
|
| 10 | + { |
|
| 11 | + } |
|
| 12 | 12 | |
| 13 | - public function testConstruct() |
|
| 14 | - { |
|
| 15 | - $console = new Console(); |
|
| 16 | - $startTime = microtime(true); |
|
| 13 | + public function testConstruct() |
|
| 14 | + { |
|
| 15 | + $console = new Console(); |
|
| 16 | + $startTime = microtime(true); |
|
| 17 | 17 | |
| 18 | - $profiler = new PhpQuickProfiler($console, $startTime); |
|
| 18 | + $profiler = new PhpQuickProfiler($console, $startTime); |
|
| 19 | 19 | |
| 20 | - $this->assertAttributeSame($console, 'console', $profiler); |
|
| 21 | - $this->assertAttributeEquals($startTime, 'startTime', $profiler); |
|
| 22 | - } |
|
| 20 | + $this->assertAttributeSame($console, 'console', $profiler); |
|
| 21 | + $this->assertAttributeEquals($startTime, 'startTime', $profiler); |
|
| 22 | + } |
|
| 23 | 23 | } |
@@ -15,88 +15,88 @@ |
||
| 15 | 15 | class Console |
| 16 | 16 | { |
| 17 | 17 | |
| 18 | - /** @var array */ |
|
| 19 | - protected $store = array(); |
|
| 18 | + /** @var array */ |
|
| 19 | + protected $store = array(); |
|
| 20 | 20 | |
| 21 | - /** |
|
| 22 | - * Logs data to the console |
|
| 23 | - * Accepts any data type |
|
| 24 | - * |
|
| 25 | - * @param mixed $data |
|
| 26 | - */ |
|
| 27 | - public function log($data) |
|
| 28 | - { |
|
| 29 | - array_push($this->store, array( |
|
| 30 | - 'data' => $data, |
|
| 31 | - 'type' => 'log' |
|
| 32 | - )); |
|
| 33 | - } |
|
| 21 | + /** |
|
| 22 | + * Logs data to the console |
|
| 23 | + * Accepts any data type |
|
| 24 | + * |
|
| 25 | + * @param mixed $data |
|
| 26 | + */ |
|
| 27 | + public function log($data) |
|
| 28 | + { |
|
| 29 | + array_push($this->store, array( |
|
| 30 | + 'data' => $data, |
|
| 31 | + 'type' => 'log' |
|
| 32 | + )); |
|
| 33 | + } |
|
| 34 | 34 | |
| 35 | - /** |
|
| 36 | - * Logs memory usage of a variable |
|
| 37 | - * If no parameter is passed in, logs current memory usage |
|
| 38 | - * |
|
| 39 | - * @param mixed $object |
|
| 40 | - * @param string $name |
|
| 41 | - */ |
|
| 42 | - public function logMemory($object = null, $name = 'PHP') |
|
| 43 | - { |
|
| 44 | - $memory = memory_get_usage(); |
|
| 45 | - $data_type = ''; |
|
| 46 | - if (!is_null($object)) { |
|
| 47 | - $memory = strlen(serialize($object)); |
|
| 48 | - $data_type = gettype($object); |
|
| 49 | - } |
|
| 35 | + /** |
|
| 36 | + * Logs memory usage of a variable |
|
| 37 | + * If no parameter is passed in, logs current memory usage |
|
| 38 | + * |
|
| 39 | + * @param mixed $object |
|
| 40 | + * @param string $name |
|
| 41 | + */ |
|
| 42 | + public function logMemory($object = null, $name = 'PHP') |
|
| 43 | + { |
|
| 44 | + $memory = memory_get_usage(); |
|
| 45 | + $data_type = ''; |
|
| 46 | + if (!is_null($object)) { |
|
| 47 | + $memory = strlen(serialize($object)); |
|
| 48 | + $data_type = gettype($object); |
|
| 49 | + } |
|
| 50 | 50 | |
| 51 | - array_push($this->store, array( |
|
| 52 | - 'name' => $name, |
|
| 53 | - 'data' => $memory, |
|
| 54 | - 'data_type' => $data_type, |
|
| 55 | - 'type' => 'memory' |
|
| 56 | - )); |
|
| 57 | - } |
|
| 51 | + array_push($this->store, array( |
|
| 52 | + 'name' => $name, |
|
| 53 | + 'data' => $memory, |
|
| 54 | + 'data_type' => $data_type, |
|
| 55 | + 'type' => 'memory' |
|
| 56 | + )); |
|
| 57 | + } |
|
| 58 | 58 | |
| 59 | - /** |
|
| 60 | - * Logs exception with optional message override |
|
| 61 | - * |
|
| 62 | - * @param Exception $exception |
|
| 63 | - * @param string $message |
|
| 64 | - */ |
|
| 65 | - public function logError(Exception $exception, $message = '') |
|
| 66 | - { |
|
| 67 | - if (empty($message)) { |
|
| 68 | - $message = $exception->getMessage(); |
|
| 69 | - } |
|
| 59 | + /** |
|
| 60 | + * Logs exception with optional message override |
|
| 61 | + * |
|
| 62 | + * @param Exception $exception |
|
| 63 | + * @param string $message |
|
| 64 | + */ |
|
| 65 | + public function logError(Exception $exception, $message = '') |
|
| 66 | + { |
|
| 67 | + if (empty($message)) { |
|
| 68 | + $message = $exception->getMessage(); |
|
| 69 | + } |
|
| 70 | 70 | |
| 71 | - array_push($this->store, array( |
|
| 72 | - 'data' => $message, |
|
| 73 | - 'file' => $exception->getFile(), |
|
| 74 | - 'line' => $exception->getLine(), |
|
| 75 | - 'type' => 'error' |
|
| 76 | - )); |
|
| 77 | - } |
|
| 71 | + array_push($this->store, array( |
|
| 72 | + 'data' => $message, |
|
| 73 | + 'file' => $exception->getFile(), |
|
| 74 | + 'line' => $exception->getLine(), |
|
| 75 | + 'type' => 'error' |
|
| 76 | + )); |
|
| 77 | + } |
|
| 78 | 78 | |
| 79 | - /** |
|
| 80 | - * Logs current time with optional message |
|
| 81 | - * |
|
| 82 | - * @param string $name |
|
| 83 | - */ |
|
| 84 | - public function logSpeed($name = 'Point in Time') |
|
| 85 | - { |
|
| 86 | - array_push($this->store, array( |
|
| 87 | - 'data' => microtime(true), |
|
| 88 | - 'name' => $name, |
|
| 89 | - 'type' => 'speed' |
|
| 90 | - )); |
|
| 91 | - } |
|
| 79 | + /** |
|
| 80 | + * Logs current time with optional message |
|
| 81 | + * |
|
| 82 | + * @param string $name |
|
| 83 | + */ |
|
| 84 | + public function logSpeed($name = 'Point in Time') |
|
| 85 | + { |
|
| 86 | + array_push($this->store, array( |
|
| 87 | + 'data' => microtime(true), |
|
| 88 | + 'name' => $name, |
|
| 89 | + 'type' => 'speed' |
|
| 90 | + )); |
|
| 91 | + } |
|
| 92 | 92 | |
| 93 | - /** |
|
| 94 | - * Returns the collected logs |
|
| 95 | - * |
|
| 96 | - * @returns array |
|
| 97 | - */ |
|
| 98 | - public function getLogs() |
|
| 99 | - { |
|
| 100 | - return $this->store; |
|
| 101 | - } |
|
| 93 | + /** |
|
| 94 | + * Returns the collected logs |
|
| 95 | + * |
|
| 96 | + * @returns array |
|
| 97 | + */ |
|
| 98 | + public function getLogs() |
|
| 99 | + { |
|
| 100 | + return $this->store; |
|
| 101 | + } |
|
| 102 | 102 | } |
@@ -157,10 +157,10 @@ discard block |
||
| 157 | 157 | } |
| 158 | 158 | elseif($log['type'] == 'memory') { |
| 159 | 159 | echo '<div><pre>'.$log['data'].'</pre>'; |
| 160 | - if (!empty($log['data_type'])) { |
|
| 161 | - echo '<em>'.$log['data_type'].'</em>: '; |
|
| 162 | - } |
|
| 163 | - echo $log['name'].' </div>'; |
|
| 160 | + if (!empty($log['data_type'])) { |
|
| 161 | + echo '<em>'.$log['data_type'].'</em>: '; |
|
| 162 | + } |
|
| 163 | + echo $log['name'].' </div>'; |
|
| 164 | 164 | } |
| 165 | 165 | elseif($log['type'] == 'speed') { |
| 166 | 166 | echo '<div><pre>'.$log['data'].'</pre> <em>'.$log['name'].'</em></div>'; |
@@ -261,10 +261,10 @@ discard block |
||
| 261 | 261 | if($log['type'] == 'memory') { |
| 262 | 262 | echo '<tr class="log-'.$log['type'].'">'; |
| 263 | 263 | echo '<td class="'.$class.'"><b>'.$log['data'].'</b>'; |
| 264 | - if ($log['data_type']) { |
|
| 265 | - echo '<em>'.$log['data_type'].'</em>: '; |
|
| 266 | - } |
|
| 267 | - echo $log['name'].'</td>'; |
|
| 264 | + if ($log['data_type']) { |
|
| 265 | + echo '<em>'.$log['data_type'].'</em>: '; |
|
| 266 | + } |
|
| 267 | + echo $log['name'].'</td>'; |
|
| 268 | 268 | echo '</tr>'; |
| 269 | 269 | if($class == '') $class = 'alt'; |
| 270 | 270 | else $class = ''; |
@@ -167,8 +167,7 @@ discard block |
||
| 167 | 167 | |
| 168 | 168 | if($logCount == 0) { |
| 169 | 169 | echo '<h3>This panel has no log items.</h3>'; |
| 170 | -} |
|
| 171 | -else { |
|
| 170 | +} else { |
|
| 172 | 171 | echo '<table class="side" cellspacing="0"> |
| 173 | 172 | <tr> |
| 174 | 173 | <td class="alt1"><var>'.$output['logs']['logCount'].'</var><h4>Logs</h4></td> |
@@ -188,20 +187,20 @@ discard block |
||
| 188 | 187 | <td class="'.$class.'">'; |
| 189 | 188 | if($log['type'] == 'log') { |
| 190 | 189 | echo '<div><pre>'.$log['data'].'</pre></div>'; |
| 191 | - } |
|
| 192 | - elseif($log['type'] == 'memory') { |
|
| 190 | + } elseif($log['type'] == 'memory') { |
|
| 193 | 191 | echo '<div><pre>'.$log['data'].'</pre> <em>'.$log['dataType'].'</em>: '.$log['name'].' </div>'; |
| 194 | - } |
|
| 195 | - elseif($log['type'] == 'speed') { |
|
| 192 | + } elseif($log['type'] == 'speed') { |
|
| 196 | 193 | echo '<div><pre>'.$log['data'].'</pre> <em>'.$log['name'].'</em></div>'; |
| 197 | - } |
|
| 198 | - elseif($log['type'] == 'error') { |
|
| 194 | + } elseif($log['type'] == 'error') { |
|
| 199 | 195 | echo '<div><em>Line '.$log['line'].'</em> : '.$log['data'].' <pre>'.$log['file'].'</pre></div>'; |
| 200 | 196 | } |
| 201 | 197 | |
| 202 | 198 | echo '</td></tr>'; |
| 203 | - if($class == '') $class = 'alt'; |
|
| 204 | - else $class = ''; |
|
| 199 | + if($class == '') { |
|
| 200 | + $class = 'alt'; |
|
| 201 | + } else { |
|
| 202 | + $class = ''; |
|
| 203 | + } |
|
| 205 | 204 | } |
| 206 | 205 | |
| 207 | 206 | echo '</table>'; |
@@ -213,8 +212,7 @@ discard block |
||
| 213 | 212 | |
| 214 | 213 | if($output['logs']['speedCount'] == 0) { |
| 215 | 214 | echo '<h3>This panel has no log items.</h3>'; |
| 216 | -} |
|
| 217 | -else { |
|
| 215 | +} else { |
|
| 218 | 216 | echo '<table class="side" cellspacing="0"> |
| 219 | 217 | <tr><td><var>'.$output['speedTotals']['total'].'</var><h4>Load Time</h4></td></tr> |
| 220 | 218 | <tr><td class="alt"><var>'.$output['speedTotals']['allowed'].'</var> <h4>Max Execution Time</h4></td></tr> |
@@ -228,8 +226,11 @@ discard block |
||
| 228 | 226 | <td class="'.$class.'">'; |
| 229 | 227 | echo '<div><pre>'.$log['data'].'</pre> <em>'.$log['name'].'</em></div>'; |
| 230 | 228 | echo '</td></tr>'; |
| 231 | - if($class == '') $class = 'alt'; |
|
| 232 | - else $class = ''; |
|
| 229 | + if($class == '') { |
|
| 230 | + $class = 'alt'; |
|
| 231 | + } else { |
|
| 232 | + $class = ''; |
|
| 233 | + } |
|
| 233 | 234 | } |
| 234 | 235 | } |
| 235 | 236 | |
@@ -242,8 +243,7 @@ discard block |
||
| 242 | 243 | |
| 243 | 244 | if($output['queryTotals']['count'] == 0) { |
| 244 | 245 | echo '<h3>This panel has no log items.</h3>'; |
| 245 | -} |
|
| 246 | -else { |
|
| 246 | +} else { |
|
| 247 | 247 | echo '<table class="side" cellspacing="0"> |
| 248 | 248 | <tr><td><var>'.$output['queryTotals']['count'].'</var><h4>Total Queries</h4></td></tr> |
| 249 | 249 | <tr><td class="alt"><var>'.$output['queryTotals']['time'].'</var> <h4>Total Time</h4></td></tr> |
@@ -265,8 +265,11 @@ discard block |
||
| 265 | 265 | </em>'; |
| 266 | 266 | } |
| 267 | 267 | echo '</td></tr>'; |
| 268 | - if($class == '') $class = 'alt'; |
|
| 269 | - else $class = ''; |
|
| 268 | + if($class == '') { |
|
| 269 | + $class = 'alt'; |
|
| 270 | + } else { |
|
| 271 | + $class = ''; |
|
| 272 | + } |
|
| 270 | 273 | } |
| 271 | 274 | |
| 272 | 275 | echo '</table>'; |
@@ -278,8 +281,7 @@ discard block |
||
| 278 | 281 | |
| 279 | 282 | if($output['logs']['memoryCount'] == 0) { |
| 280 | 283 | echo '<h3>This panel has no log items.</h3>'; |
| 281 | -} |
|
| 282 | -else { |
|
| 284 | +} else { |
|
| 283 | 285 | echo '<table class="side" cellspacing="0"> |
| 284 | 286 | <tr><td><var>'.$output['memoryTotals']['used'].'</var><h4>Used Memory</h4></td></tr> |
| 285 | 287 | <tr><td class="alt"><var>'.$output['memoryTotals']['total'].'</var> <h4>Total Available</h4></td></tr> |
@@ -292,8 +294,11 @@ discard block |
||
| 292 | 294 | echo '<tr class="log-'.$log['type'].'">'; |
| 293 | 295 | echo '<td class="'.$class.'"><b>'.$log['data'].'</b> <em>'.$log['dataType'].'</em>: '.$log['name'].'</td>'; |
| 294 | 296 | echo '</tr>'; |
| 295 | - if($class == '') $class = 'alt'; |
|
| 296 | - else $class = ''; |
|
| 297 | + if($class == '') { |
|
| 298 | + $class = 'alt'; |
|
| 299 | + } else { |
|
| 300 | + $class = ''; |
|
| 301 | + } |
|
| 297 | 302 | } |
| 298 | 303 | } |
| 299 | 304 | |
@@ -306,8 +311,7 @@ discard block |
||
| 306 | 311 | |
| 307 | 312 | if($output['fileTotals']['count'] == 0) { |
| 308 | 313 | echo '<h3>This panel has no log items.</h3>'; |
| 309 | -} |
|
| 310 | -else { |
|
| 314 | +} else { |
|
| 311 | 315 | echo '<table class="side" cellspacing="0"> |
| 312 | 316 | <tr><td><var>'.$output['fileTotals']['count'].'</var><h4>Total Files</h4></td></tr> |
| 313 | 317 | <tr><td class="alt"><var>'.$output['fileTotals']['size'].'</var> <h4>Total Size</h4></td></tr> |
@@ -318,8 +322,11 @@ discard block |
||
| 318 | 322 | $class =''; |
| 319 | 323 | foreach($output['files'] as $file) { |
| 320 | 324 | echo '<tr><td class="'.$class.'"><b>'.$file['size'].'</b> '.$file['name'].'</td></tr>'; |
| 321 | - if($class == '') $class = 'alt'; |
|
| 322 | - else $class = ''; |
|
| 325 | + if($class == '') { |
|
| 326 | + $class = 'alt'; |
|
| 327 | + } else { |
|
| 328 | + $class = ''; |
|
| 329 | + } |
|
| 323 | 330 | } |
| 324 | 331 | |
| 325 | 332 | echo '</table>'; |
@@ -1,6 +1,6 @@ discard block |
||
| 1 | 1 | <?php |
| 2 | 2 | |
| 3 | -$css = file_get_contents(__DIR__ . '/pQp.css'); |
|
| 3 | +$css = file_get_contents(__DIR__.'/pQp.css'); |
|
| 4 | 4 | |
| 5 | 5 | echo <<<JAVASCRIPT |
| 6 | 6 | <!-- JavaScript --> |
@@ -131,7 +131,7 @@ discard block |
||
| 131 | 131 | |
| 132 | 132 | echo '<div id="pqp-console" class="pqp-box">'; |
| 133 | 133 | |
| 134 | -if(count($output['console']) == 0) { |
|
| 134 | +if (count($output['console']) == 0) { |
|
| 135 | 135 | echo '<h3>This panel has no log items.</h3>'; |
| 136 | 136 | } |
| 137 | 137 | else { |
@@ -148,29 +148,29 @@ discard block |
||
| 148 | 148 | <table class="main" cellspacing="0">'; |
| 149 | 149 | |
| 150 | 150 | $class = ''; |
| 151 | - foreach($output['console']['messages'] as $log) { |
|
| 151 | + foreach ($output['console']['messages'] as $log) { |
|
| 152 | 152 | echo '<tr class="log-'.$log['type'].'"> |
| 153 | 153 | <td class="type">'.$log['type'].'</td> |
| 154 | 154 | <td class="'.$class.'">'; |
| 155 | - if($log['type'] == 'log') { |
|
| 155 | + if ($log['type'] == 'log') { |
|
| 156 | 156 | echo '<div><pre>'.$log['data'].'</pre></div>'; |
| 157 | 157 | } |
| 158 | - elseif($log['type'] == 'memory') { |
|
| 158 | + elseif ($log['type'] == 'memory') { |
|
| 159 | 159 | echo '<div><pre>'.$log['data'].'</pre>'; |
| 160 | 160 | if (!empty($log['data_type'])) { |
| 161 | 161 | echo '<em>'.$log['data_type'].'</em>: '; |
| 162 | 162 | } |
| 163 | 163 | echo $log['name'].' </div>'; |
| 164 | 164 | } |
| 165 | - elseif($log['type'] == 'speed') { |
|
| 165 | + elseif ($log['type'] == 'speed') { |
|
| 166 | 166 | echo '<div><pre>'.$log['data'].'</pre> <em>'.$log['name'].'</em></div>'; |
| 167 | 167 | } |
| 168 | - elseif($log['type'] == 'error') { |
|
| 168 | + elseif ($log['type'] == 'error') { |
|
| 169 | 169 | echo '<div><em>Line '.$log['line'].'</em> : '.$log['data'].' <pre>'.$log['file'].'</pre></div>'; |
| 170 | 170 | } |
| 171 | 171 | |
| 172 | 172 | echo '</td></tr>'; |
| 173 | - if($class == '') $class = 'alt'; |
|
| 173 | + if ($class == '') $class = 'alt'; |
|
| 174 | 174 | else $class = ''; |
| 175 | 175 | } |
| 176 | 176 | |
@@ -181,7 +181,7 @@ discard block |
||
| 181 | 181 | |
| 182 | 182 | echo '<div id="pqp-speed" class="pqp-box">'; |
| 183 | 183 | |
| 184 | -if($output['console']['count']['speed'] == 0) { |
|
| 184 | +if ($output['console']['count']['speed'] == 0) { |
|
| 185 | 185 | echo '<h3>This panel has no log items.</h3>'; |
| 186 | 186 | } |
| 187 | 187 | else { |
@@ -192,13 +192,13 @@ discard block |
||
| 192 | 192 | <table class="main" cellspacing="0">'; |
| 193 | 193 | |
| 194 | 194 | $class = ''; |
| 195 | - foreach($output['console']['messages'] as $log) { |
|
| 196 | - if($log['type'] == 'speed') { |
|
| 195 | + foreach ($output['console']['messages'] as $log) { |
|
| 196 | + if ($log['type'] == 'speed') { |
|
| 197 | 197 | echo '<tr class="log-'.$log['type'].'"> |
| 198 | 198 | <td class="'.$class.'">'; |
| 199 | 199 | echo '<div><pre>'.$log['data'].'</pre> <em>'.$log['name'].'</em></div>'; |
| 200 | 200 | echo '</td></tr>'; |
| 201 | - if($class == '') $class = 'alt'; |
|
| 201 | + if ($class == '') $class = 'alt'; |
|
| 202 | 202 | else $class = ''; |
| 203 | 203 | } |
| 204 | 204 | } |
@@ -210,7 +210,7 @@ discard block |
||
| 210 | 210 | |
| 211 | 211 | echo '<div id="pqp-queries" class="pqp-box">'; |
| 212 | 212 | |
| 213 | -if($output['queryTotals']['count'] == 0) { |
|
| 213 | +if ($output['queryTotals']['count'] == 0) { |
|
| 214 | 214 | echo '<h3>This panel has no log items.</h3>'; |
| 215 | 215 | } |
| 216 | 216 | else { |
@@ -222,10 +222,10 @@ discard block |
||
| 222 | 222 | <table class="main" cellspacing="0">'; |
| 223 | 223 | |
| 224 | 224 | $class = ''; |
| 225 | - foreach($output['queries'] as $query) { |
|
| 225 | + foreach ($output['queries'] as $query) { |
|
| 226 | 226 | echo '<tr> |
| 227 | 227 | <td class="'.$class.'">'.$query['sql']; |
| 228 | - if($query['explain']) { |
|
| 228 | + if ($query['explain']) { |
|
| 229 | 229 | echo '<em> |
| 230 | 230 | Possible keys: <b>'.$query['explain']['possible_keys'].'</b> · |
| 231 | 231 | Key Used: <b>'.$query['explain']['key'].'</b> · |
@@ -235,7 +235,7 @@ discard block |
||
| 235 | 235 | </em>'; |
| 236 | 236 | } |
| 237 | 237 | echo '</td></tr>'; |
| 238 | - if($class == '') $class = 'alt'; |
|
| 238 | + if ($class == '') $class = 'alt'; |
|
| 239 | 239 | else $class = ''; |
| 240 | 240 | } |
| 241 | 241 | |
@@ -246,7 +246,7 @@ discard block |
||
| 246 | 246 | |
| 247 | 247 | echo '<div id="pqp-memory" class="pqp-box">'; |
| 248 | 248 | |
| 249 | -if($output['console']['count']['memory'] == 0) { |
|
| 249 | +if ($output['console']['count']['memory'] == 0) { |
|
| 250 | 250 | echo '<h3>This panel has no log items.</h3>'; |
| 251 | 251 | } |
| 252 | 252 | else { |
@@ -257,8 +257,8 @@ discard block |
||
| 257 | 257 | <table class="main" cellspacing="0">'; |
| 258 | 258 | |
| 259 | 259 | $class = ''; |
| 260 | - foreach($output['console']['messages'] as $log) { |
|
| 261 | - if($log['type'] == 'memory') { |
|
| 260 | + foreach ($output['console']['messages'] as $log) { |
|
| 261 | + if ($log['type'] == 'memory') { |
|
| 262 | 262 | echo '<tr class="log-'.$log['type'].'">'; |
| 263 | 263 | echo '<td class="'.$class.'"><b>'.$log['data'].'</b>'; |
| 264 | 264 | if ($log['data_type']) { |
@@ -266,7 +266,7 @@ discard block |
||
| 266 | 266 | } |
| 267 | 267 | echo $log['name'].'</td>'; |
| 268 | 268 | echo '</tr>'; |
| 269 | - if($class == '') $class = 'alt'; |
|
| 269 | + if ($class == '') $class = 'alt'; |
|
| 270 | 270 | else $class = ''; |
| 271 | 271 | } |
| 272 | 272 | } |
@@ -278,7 +278,7 @@ discard block |
||
| 278 | 278 | |
| 279 | 279 | echo '<div id="pqp-files" class="pqp-box">'; |
| 280 | 280 | |
| 281 | -if($output['fileTotals']['count'] == 0) { |
|
| 281 | +if ($output['fileTotals']['count'] == 0) { |
|
| 282 | 282 | echo '<h3>This panel has no log items.</h3>'; |
| 283 | 283 | } |
| 284 | 284 | else { |
@@ -289,10 +289,10 @@ discard block |
||
| 289 | 289 | </table> |
| 290 | 290 | <table class="main" cellspacing="0">'; |
| 291 | 291 | |
| 292 | - $class =''; |
|
| 293 | - foreach($output['files'] as $file) { |
|
| 292 | + $class = ''; |
|
| 293 | + foreach ($output['files'] as $file) { |
|
| 294 | 294 | echo '<tr><td class="'.$class.'"><b>'.$file['size'].'</b> '.$file['name'].'</td></tr>'; |
| 295 | - if($class == '') $class = 'alt'; |
|
| 295 | + if ($class == '') $class = 'alt'; |
|
| 296 | 296 | else $class = ''; |
| 297 | 297 | } |
| 298 | 298 | |
@@ -5,29 +5,29 @@ |
||
| 5 | 5 | class DisplayTest extends PHPUnit_Framework_TestCase |
| 6 | 6 | { |
| 7 | 7 | |
| 8 | - public function testGetReadableTime() |
|
| 9 | - { |
|
| 10 | - $test_input = array( |
|
| 11 | - '.032432' => '32.432 ms', |
|
| 12 | - '24.3781' => '24.378 s', |
|
| 13 | - '145.123' => '2.419 m' |
|
| 14 | - ); |
|
| 8 | + public function testGetReadableTime() |
|
| 9 | + { |
|
| 10 | + $test_input = array( |
|
| 11 | + '.032432' => '32.432 ms', |
|
| 12 | + '24.3781' => '24.378 s', |
|
| 13 | + '145.123' => '2.419 m' |
|
| 14 | + ); |
|
| 15 | 15 | |
| 16 | - foreach ($test_input as $input => $expected_return) { |
|
| 17 | - $this->assertEquals($expected_return, Display::getReadableTime($input)); |
|
| 18 | - } |
|
| 19 | - } |
|
| 16 | + foreach ($test_input as $input => $expected_return) { |
|
| 17 | + $this->assertEquals($expected_return, Display::getReadableTime($input)); |
|
| 18 | + } |
|
| 19 | + } |
|
| 20 | 20 | |
| 21 | - public function testGetReadableMemory() |
|
| 22 | - { |
|
| 23 | - $test_input = array( |
|
| 24 | - '314' => '314 b', |
|
| 25 | - '7403' => '7.23 k', |
|
| 26 | - '2589983' => '2.47 M' |
|
| 27 | - ); |
|
| 21 | + public function testGetReadableMemory() |
|
| 22 | + { |
|
| 23 | + $test_input = array( |
|
| 24 | + '314' => '314 b', |
|
| 25 | + '7403' => '7.23 k', |
|
| 26 | + '2589983' => '2.47 M' |
|
| 27 | + ); |
|
| 28 | 28 | |
| 29 | - foreach ($test_input as $input => $expected_return) { |
|
| 30 | - $this->assertEquals($expected_return, Display::getReadableMemory($input)); |
|
| 31 | - } |
|
| 32 | - } |
|
| 29 | + foreach ($test_input as $input => $expected_return) { |
|
| 30 | + $this->assertEquals($expected_return, Display::getReadableMemory($input)); |
|
| 31 | + } |
|
| 32 | + } |
|
| 33 | 33 | } |
@@ -33,7 +33,7 @@ discard block |
||
| 33 | 33 | ) |
| 34 | 34 | ); |
| 35 | 35 | foreach ($console->getLogs() as $log) { |
| 36 | - switch($log['type']) { |
|
| 36 | + switch ($log['type']) { |
|
| 37 | 37 | case 'log': |
| 38 | 38 | $message = array( |
| 39 | 39 | 'data' => print_r($log['data'], true), |
@@ -162,6 +162,6 @@ discard block |
||
| 162 | 162 | public function __invoke() |
| 163 | 163 | { |
| 164 | 164 | $output = $this->output; |
| 165 | - require_once __DIR__ .'/../asset/display.tpl.php'; |
|
| 165 | + require_once __DIR__.'/../asset/display.tpl.php'; |
|
| 166 | 166 | } |
| 167 | 167 | } |
@@ -14,204 +14,204 @@ |
||
| 14 | 14 | class Display |
| 15 | 15 | { |
| 16 | 16 | |
| 17 | - /** @var array */ |
|
| 18 | - protected $output; |
|
| 19 | - |
|
| 20 | - public function __construct() |
|
| 21 | - { |
|
| 22 | - } |
|
| 23 | - |
|
| 24 | - public function setConsole(Console $console) |
|
| 25 | - { |
|
| 26 | - $console_data = array( |
|
| 27 | - 'messages' => array(), |
|
| 28 | - 'count' => array( |
|
| 29 | - 'log' => 0, |
|
| 30 | - 'memory' => 0, |
|
| 31 | - 'error' => 0, |
|
| 32 | - 'speed' => 0 |
|
| 33 | - ) |
|
| 34 | - ); |
|
| 35 | - foreach ($console->getLogs() as $log) { |
|
| 36 | - switch($log['type']) { |
|
| 37 | - case 'log': |
|
| 38 | - $message = array( |
|
| 39 | - 'data' => print_r($log['data'], true), |
|
| 40 | - 'type' => 'log' |
|
| 41 | - ); |
|
| 42 | - $console_data['count']['log']++; |
|
| 43 | - break; |
|
| 44 | - case 'memory': |
|
| 45 | - $message = array( |
|
| 46 | - 'name' => $log['name'], |
|
| 47 | - 'data' => self::getReadableMemory($log['data']), |
|
| 48 | - 'type' => 'memory' |
|
| 49 | - ); |
|
| 50 | - if (!empty($log['data_type'])) { |
|
| 51 | - $message['data_type'] = $log['data_type']; |
|
| 52 | - } |
|
| 53 | - $console_data['count']['memory']++; |
|
| 54 | - break; |
|
| 55 | - case 'error': |
|
| 56 | - $message = array( |
|
| 57 | - 'data' => $log['data'], |
|
| 58 | - 'file' => $log['file'], |
|
| 59 | - 'line' => $log['line'], |
|
| 60 | - 'type' => 'error' |
|
| 61 | - ); |
|
| 62 | - $console_data['count']['error']++; |
|
| 63 | - break; |
|
| 64 | - case 'speed': |
|
| 65 | - $elapsedTime = $log['data'] - $this->startTime; |
|
| 66 | - $message = array( |
|
| 67 | - 'name' => $log['name'], |
|
| 68 | - 'data' => self::getReadableTime($elapsedTime), |
|
| 69 | - 'type' => 'speed' |
|
| 70 | - ); |
|
| 71 | - $console_data['count']['speed']++; |
|
| 72 | - break; |
|
| 73 | - default: |
|
| 74 | - $message = array( |
|
| 75 | - 'data' => "Unrecognized console log type: {$log['type']}", |
|
| 76 | - 'type' => 'error' |
|
| 77 | - ); |
|
| 78 | - $console_data['count']['error']++; |
|
| 79 | - break; |
|
| 80 | - } |
|
| 81 | - array_push($console_data['messages'], $message); |
|
| 82 | - } |
|
| 83 | - $this->output['console'] = $console_data; |
|
| 84 | - } |
|
| 85 | - |
|
| 86 | - /** |
|
| 87 | - * Sets file data |
|
| 88 | - * |
|
| 89 | - * @param array $data |
|
| 90 | - */ |
|
| 91 | - public function setFileData(array $data) |
|
| 92 | - { |
|
| 93 | - $fileData = array( |
|
| 94 | - 'fileList' => array(), |
|
| 95 | - 'fileTotals' => array( |
|
| 96 | - 'count' => count($data), |
|
| 97 | - 'size' => 0, |
|
| 98 | - 'largest' => 0 |
|
| 99 | - ) |
|
| 100 | - ); |
|
| 101 | - |
|
| 102 | - foreach ($data as $file) { |
|
| 103 | - array_push($fileData['fileList'], array( |
|
| 104 | - 'name' => $file['name'], |
|
| 105 | - 'size' => self::getReadableMemory($file['size']) |
|
| 106 | - )); |
|
| 107 | - |
|
| 108 | - $fileData['fileTotals']['size'] += $file['size']; |
|
| 109 | - if ($file['size'] > $fileData['fileTotals']['largest']) { |
|
| 110 | - $fileData['fileTotals']['largest'] = $file['size']; |
|
| 111 | - } |
|
| 112 | - } |
|
| 113 | - |
|
| 114 | - $fileData['fileTotals']['size'] = self::getReadableMemory($fileData['fileTotals']['size']); |
|
| 115 | - $fileData['fileTotals']['largest'] = self::getReadableMemory($fileData['fileTotals']['largest']); |
|
| 116 | - |
|
| 117 | - $this->output['files'] = $fileData['fileList']; |
|
| 118 | - $this->output['fileTotals'] = $fileData['fileTotals']; |
|
| 119 | - } |
|
| 120 | - |
|
| 121 | - /** |
|
| 122 | - * Sets memory data |
|
| 123 | - * |
|
| 124 | - * @param array $data |
|
| 125 | - */ |
|
| 126 | - public function setMemoryData(array $data) |
|
| 127 | - { |
|
| 128 | - $this->output['memory'] = array( |
|
| 129 | - 'used' => self::getReadableMemory($data['used']), |
|
| 130 | - 'allowed' => $data['allowed'] |
|
| 131 | - ); |
|
| 132 | - } |
|
| 133 | - |
|
| 134 | - public function setQueryData(array $data) |
|
| 135 | - { |
|
| 136 | - $queryData = array( |
|
| 137 | - 'queries' => array(), |
|
| 138 | - 'queryTotals' => array( |
|
| 139 | - 'count' => count($data), |
|
| 140 | - 'time' => 0, |
|
| 141 | - ) |
|
| 142 | - ); |
|
| 143 | - |
|
| 144 | - foreach ($data as $query) { |
|
| 145 | - array_push($queryData['queries'], array( |
|
| 146 | - 'sql' => $query['sql'], |
|
| 147 | - 'explain' => $query['explain'], |
|
| 148 | - 'time' => self::getReadableTime($query['time']) |
|
| 149 | - )); |
|
| 150 | - |
|
| 151 | - $queryData['queryTotals']['time'] += $query['time']; |
|
| 152 | - } |
|
| 153 | - |
|
| 154 | - $queryData['queryTotals']['time'] = self::getReadableTime($queryData['queryTotals']['time']); |
|
| 155 | - |
|
| 156 | - $this->output['queries'] = $queryData['queries']; |
|
| 157 | - $this->output['queryTotals'] = $queryData['queryTotals']; |
|
| 158 | - } |
|
| 159 | - |
|
| 160 | - /** |
|
| 161 | - * Sets speed data |
|
| 162 | - * |
|
| 163 | - * @param array $data |
|
| 164 | - */ |
|
| 165 | - public function setSpeedData(array $data) |
|
| 166 | - { |
|
| 167 | - $this->output['speed'] = array( |
|
| 168 | - 'elapsed' => self::getReadableTime($data['elapsed']), |
|
| 169 | - 'allowed' => self::getReadableTime($data['allowed'], 0) |
|
| 170 | - ); |
|
| 171 | - } |
|
| 172 | - |
|
| 173 | - /** |
|
| 174 | - * Static formatter for human-readable time |
|
| 175 | - * Only handles time up to 60 minutes gracefully |
|
| 176 | - * |
|
| 177 | - * @param double $time |
|
| 178 | - * @param integer $decimals |
|
| 179 | - * @return string |
|
| 180 | - */ |
|
| 181 | - public static function getReadableTime($time, $decimals = 3) |
|
| 182 | - { |
|
| 183 | - $unit = 's'; |
|
| 184 | - if ($time < 1) { |
|
| 185 | - $time *= 1000; |
|
| 186 | - $unit = 'ms'; |
|
| 187 | - } else if ($time > 60) { |
|
| 188 | - $time /= 60; |
|
| 189 | - $unit = 'm'; |
|
| 190 | - } |
|
| 191 | - $time = number_format($time, $decimals); |
|
| 192 | - return "{$time} {$unit}"; |
|
| 193 | - } |
|
| 194 | - |
|
| 195 | - /** |
|
| 196 | - * Static formatter for human-readable memory |
|
| 197 | - * |
|
| 198 | - * @param double $size |
|
| 199 | - * @param integer $decimals |
|
| 200 | - */ |
|
| 201 | - public static function getReadableMemory($size, $decimals = 2) |
|
| 202 | - { |
|
| 203 | - $unitOptions = array('b', 'k', 'M', 'G'); |
|
| 204 | - |
|
| 205 | - $base = log($size, 1024); |
|
| 206 | - |
|
| 207 | - $memory = round(pow(1024, $base - floor($base)), $decimals); |
|
| 208 | - $unit = $unitOptions[floor($base)]; |
|
| 209 | - return "{$memory} {$unit}"; |
|
| 210 | - } |
|
| 17 | + /** @var array */ |
|
| 18 | + protected $output; |
|
| 19 | + |
|
| 20 | + public function __construct() |
|
| 21 | + { |
|
| 22 | + } |
|
| 23 | + |
|
| 24 | + public function setConsole(Console $console) |
|
| 25 | + { |
|
| 26 | + $console_data = array( |
|
| 27 | + 'messages' => array(), |
|
| 28 | + 'count' => array( |
|
| 29 | + 'log' => 0, |
|
| 30 | + 'memory' => 0, |
|
| 31 | + 'error' => 0, |
|
| 32 | + 'speed' => 0 |
|
| 33 | + ) |
|
| 34 | + ); |
|
| 35 | + foreach ($console->getLogs() as $log) { |
|
| 36 | + switch($log['type']) { |
|
| 37 | + case 'log': |
|
| 38 | + $message = array( |
|
| 39 | + 'data' => print_r($log['data'], true), |
|
| 40 | + 'type' => 'log' |
|
| 41 | + ); |
|
| 42 | + $console_data['count']['log']++; |
|
| 43 | + break; |
|
| 44 | + case 'memory': |
|
| 45 | + $message = array( |
|
| 46 | + 'name' => $log['name'], |
|
| 47 | + 'data' => self::getReadableMemory($log['data']), |
|
| 48 | + 'type' => 'memory' |
|
| 49 | + ); |
|
| 50 | + if (!empty($log['data_type'])) { |
|
| 51 | + $message['data_type'] = $log['data_type']; |
|
| 52 | + } |
|
| 53 | + $console_data['count']['memory']++; |
|
| 54 | + break; |
|
| 55 | + case 'error': |
|
| 56 | + $message = array( |
|
| 57 | + 'data' => $log['data'], |
|
| 58 | + 'file' => $log['file'], |
|
| 59 | + 'line' => $log['line'], |
|
| 60 | + 'type' => 'error' |
|
| 61 | + ); |
|
| 62 | + $console_data['count']['error']++; |
|
| 63 | + break; |
|
| 64 | + case 'speed': |
|
| 65 | + $elapsedTime = $log['data'] - $this->startTime; |
|
| 66 | + $message = array( |
|
| 67 | + 'name' => $log['name'], |
|
| 68 | + 'data' => self::getReadableTime($elapsedTime), |
|
| 69 | + 'type' => 'speed' |
|
| 70 | + ); |
|
| 71 | + $console_data['count']['speed']++; |
|
| 72 | + break; |
|
| 73 | + default: |
|
| 74 | + $message = array( |
|
| 75 | + 'data' => "Unrecognized console log type: {$log['type']}", |
|
| 76 | + 'type' => 'error' |
|
| 77 | + ); |
|
| 78 | + $console_data['count']['error']++; |
|
| 79 | + break; |
|
| 80 | + } |
|
| 81 | + array_push($console_data['messages'], $message); |
|
| 82 | + } |
|
| 83 | + $this->output['console'] = $console_data; |
|
| 84 | + } |
|
| 85 | + |
|
| 86 | + /** |
|
| 87 | + * Sets file data |
|
| 88 | + * |
|
| 89 | + * @param array $data |
|
| 90 | + */ |
|
| 91 | + public function setFileData(array $data) |
|
| 92 | + { |
|
| 93 | + $fileData = array( |
|
| 94 | + 'fileList' => array(), |
|
| 95 | + 'fileTotals' => array( |
|
| 96 | + 'count' => count($data), |
|
| 97 | + 'size' => 0, |
|
| 98 | + 'largest' => 0 |
|
| 99 | + ) |
|
| 100 | + ); |
|
| 101 | + |
|
| 102 | + foreach ($data as $file) { |
|
| 103 | + array_push($fileData['fileList'], array( |
|
| 104 | + 'name' => $file['name'], |
|
| 105 | + 'size' => self::getReadableMemory($file['size']) |
|
| 106 | + )); |
|
| 107 | + |
|
| 108 | + $fileData['fileTotals']['size'] += $file['size']; |
|
| 109 | + if ($file['size'] > $fileData['fileTotals']['largest']) { |
|
| 110 | + $fileData['fileTotals']['largest'] = $file['size']; |
|
| 111 | + } |
|
| 112 | + } |
|
| 113 | + |
|
| 114 | + $fileData['fileTotals']['size'] = self::getReadableMemory($fileData['fileTotals']['size']); |
|
| 115 | + $fileData['fileTotals']['largest'] = self::getReadableMemory($fileData['fileTotals']['largest']); |
|
| 116 | + |
|
| 117 | + $this->output['files'] = $fileData['fileList']; |
|
| 118 | + $this->output['fileTotals'] = $fileData['fileTotals']; |
|
| 119 | + } |
|
| 120 | + |
|
| 121 | + /** |
|
| 122 | + * Sets memory data |
|
| 123 | + * |
|
| 124 | + * @param array $data |
|
| 125 | + */ |
|
| 126 | + public function setMemoryData(array $data) |
|
| 127 | + { |
|
| 128 | + $this->output['memory'] = array( |
|
| 129 | + 'used' => self::getReadableMemory($data['used']), |
|
| 130 | + 'allowed' => $data['allowed'] |
|
| 131 | + ); |
|
| 132 | + } |
|
| 133 | + |
|
| 134 | + public function setQueryData(array $data) |
|
| 135 | + { |
|
| 136 | + $queryData = array( |
|
| 137 | + 'queries' => array(), |
|
| 138 | + 'queryTotals' => array( |
|
| 139 | + 'count' => count($data), |
|
| 140 | + 'time' => 0, |
|
| 141 | + ) |
|
| 142 | + ); |
|
| 143 | + |
|
| 144 | + foreach ($data as $query) { |
|
| 145 | + array_push($queryData['queries'], array( |
|
| 146 | + 'sql' => $query['sql'], |
|
| 147 | + 'explain' => $query['explain'], |
|
| 148 | + 'time' => self::getReadableTime($query['time']) |
|
| 149 | + )); |
|
| 150 | + |
|
| 151 | + $queryData['queryTotals']['time'] += $query['time']; |
|
| 152 | + } |
|
| 153 | + |
|
| 154 | + $queryData['queryTotals']['time'] = self::getReadableTime($queryData['queryTotals']['time']); |
|
| 155 | + |
|
| 156 | + $this->output['queries'] = $queryData['queries']; |
|
| 157 | + $this->output['queryTotals'] = $queryData['queryTotals']; |
|
| 158 | + } |
|
| 159 | + |
|
| 160 | + /** |
|
| 161 | + * Sets speed data |
|
| 162 | + * |
|
| 163 | + * @param array $data |
|
| 164 | + */ |
|
| 165 | + public function setSpeedData(array $data) |
|
| 166 | + { |
|
| 167 | + $this->output['speed'] = array( |
|
| 168 | + 'elapsed' => self::getReadableTime($data['elapsed']), |
|
| 169 | + 'allowed' => self::getReadableTime($data['allowed'], 0) |
|
| 170 | + ); |
|
| 171 | + } |
|
| 172 | + |
|
| 173 | + /** |
|
| 174 | + * Static formatter for human-readable time |
|
| 175 | + * Only handles time up to 60 minutes gracefully |
|
| 176 | + * |
|
| 177 | + * @param double $time |
|
| 178 | + * @param integer $decimals |
|
| 179 | + * @return string |
|
| 180 | + */ |
|
| 181 | + public static function getReadableTime($time, $decimals = 3) |
|
| 182 | + { |
|
| 183 | + $unit = 's'; |
|
| 184 | + if ($time < 1) { |
|
| 185 | + $time *= 1000; |
|
| 186 | + $unit = 'ms'; |
|
| 187 | + } else if ($time > 60) { |
|
| 188 | + $time /= 60; |
|
| 189 | + $unit = 'm'; |
|
| 190 | + } |
|
| 191 | + $time = number_format($time, $decimals); |
|
| 192 | + return "{$time} {$unit}"; |
|
| 193 | + } |
|
| 194 | + |
|
| 195 | + /** |
|
| 196 | + * Static formatter for human-readable memory |
|
| 197 | + * |
|
| 198 | + * @param double $size |
|
| 199 | + * @param integer $decimals |
|
| 200 | + */ |
|
| 201 | + public static function getReadableMemory($size, $decimals = 2) |
|
| 202 | + { |
|
| 203 | + $unitOptions = array('b', 'k', 'M', 'G'); |
|
| 204 | + |
|
| 205 | + $base = log($size, 1024); |
|
| 206 | + |
|
| 207 | + $memory = round(pow(1024, $base - floor($base)), $decimals); |
|
| 208 | + $unit = $unitOptions[floor($base)]; |
|
| 209 | + return "{$memory} {$unit}"; |
|
| 210 | + } |
|
| 211 | 211 | |
| 212 | - public function __invoke() |
|
| 213 | - { |
|
| 214 | - $output = $this->output; |
|
| 215 | - require_once __DIR__ .'/../asset/display.tpl.php'; |
|
| 216 | - } |
|
| 212 | + public function __invoke() |
|
| 213 | + { |
|
| 214 | + $output = $this->output; |
|
| 215 | + require_once __DIR__ .'/../asset/display.tpl.php'; |
|
| 216 | + } |
|
| 217 | 217 | } |
@@ -15,136 +15,136 @@ |
||
| 15 | 15 | class PhpQuickProfiler |
| 16 | 16 | { |
| 17 | 17 | |
| 18 | - /** @var Console */ |
|
| 19 | - protected $console; |
|
| 20 | - |
|
| 21 | - /** @var integer */ |
|
| 22 | - protected $startTime; |
|
| 23 | - |
|
| 24 | - /** @var object */ |
|
| 25 | - protected $pdo; |
|
| 26 | - |
|
| 27 | - /** |
|
| 28 | - * @param Console $console |
|
| 29 | - * @param object $pdo |
|
| 30 | - * @param integer $startTime |
|
| 31 | - */ |
|
| 32 | - public function __construct(Console $console, $pdo = null, $startTime = null) |
|
| 33 | - { |
|
| 34 | - $this->console = $console; |
|
| 35 | - $this->pdo = $pdo; |
|
| 36 | - |
|
| 37 | - if (is_null($startTime)) { |
|
| 38 | - $startTime = microtime(true); |
|
| 39 | - } |
|
| 40 | - $this->startTime = $startTime; |
|
| 41 | - } |
|
| 42 | - |
|
| 43 | - /** |
|
| 44 | - * Get data about files loaded for the application to current point |
|
| 45 | - * |
|
| 46 | - * @returns array |
|
| 47 | - */ |
|
| 48 | - public function gatherFileData() |
|
| 49 | - { |
|
| 50 | - $files = get_included_files(); |
|
| 51 | - $data = array(); |
|
| 52 | - foreach ($files as $file) { |
|
| 53 | - array_push($data, array( |
|
| 54 | - 'name' => $file, |
|
| 55 | - 'size' => filesize($file) |
|
| 56 | - )); |
|
| 57 | - } |
|
| 58 | - return $data; |
|
| 59 | - } |
|
| 60 | - |
|
| 61 | - /** |
|
| 62 | - * Get data about memory usage of the application |
|
| 63 | - * |
|
| 64 | - * @returns array |
|
| 65 | - */ |
|
| 66 | - public function gatherMemoryData() |
|
| 67 | - { |
|
| 68 | - $usedMemory = memory_get_peak_usage(); |
|
| 69 | - $allowedMemory = ini_get('memory_limit'); |
|
| 70 | - return array( |
|
| 71 | - 'used' => $usedMemory, |
|
| 72 | - 'allowed' => $allowedMemory |
|
| 73 | - ); |
|
| 74 | - } |
|
| 75 | - |
|
| 76 | - /** |
|
| 77 | - * Get data about sql usage of the application |
|
| 78 | - * |
|
| 79 | - * @param array $profiledQueries |
|
| 80 | - * @returns array |
|
| 81 | - */ |
|
| 82 | - public function gatherQueryData(array $profiledQueries) |
|
| 83 | - { |
|
| 84 | - $data = array(); |
|
| 85 | - foreach ($profiledQueries as $query) { |
|
| 86 | - if ($query['function'] !== 'perform') { |
|
| 87 | - continue; |
|
| 88 | - } |
|
| 89 | - |
|
| 90 | - array_push($data, array( |
|
| 91 | - 'sql' => $query['statement'], |
|
| 92 | - 'explain' => $this->explainQuery($query['statement'], $query['bind_values']), |
|
| 93 | - 'time' => $query['duration'] |
|
| 94 | - )); |
|
| 95 | - } |
|
| 96 | - return $data; |
|
| 97 | - } |
|
| 98 | - |
|
| 99 | - /** |
|
| 100 | - * Attempts to explain a query |
|
| 101 | - * |
|
| 102 | - * @param string $query |
|
| 103 | - * @param array $parameters |
|
| 104 | - * @return array |
|
| 105 | - */ |
|
| 106 | - protected function explainQuery($query, $parameters) |
|
| 107 | - { |
|
| 108 | - $query = "EXPLAIN {$query}"; |
|
| 109 | - try { |
|
| 110 | - $statement = $this->pdo->prepare($query); |
|
| 111 | - $statement->execute($parameters); |
|
| 112 | - return $statement->fetch(\PDO::FETCH_ASSOC); |
|
| 113 | - } catch (\Exception $e) { |
|
| 114 | - echo $e->getMessage(); |
|
| 115 | - } |
|
| 116 | - return ''; |
|
| 117 | - } |
|
| 118 | - |
|
| 119 | - /** |
|
| 120 | - * Get data about speed of the application |
|
| 121 | - * |
|
| 122 | - * @returns array |
|
| 123 | - */ |
|
| 124 | - public function gatherSpeedData() |
|
| 125 | - { |
|
| 126 | - $elapsedTime = microtime(true) - $this->startTime; |
|
| 127 | - $allowedTime = ini_get('max_execution_time'); |
|
| 128 | - return array( |
|
| 129 | - 'elapsed' => $elapsedTime, |
|
| 130 | - 'allowed' => $allowedTime |
|
| 131 | - ); |
|
| 132 | - } |
|
| 133 | - |
|
| 134 | - /** |
|
| 135 | - * Triggers end display of the profiling data |
|
| 136 | - * |
|
| 137 | - * @param Display $display |
|
| 138 | - * @param array $profiledQueries |
|
| 139 | - */ |
|
| 140 | - public function display(Display $display, array $profiledQueries = array()) |
|
| 141 | - { |
|
| 142 | - $display->setConsole($this->console); |
|
| 143 | - $display->setFileData($this->gatherFileData()); |
|
| 144 | - $display->setMemoryData($this->gatherMemoryData()); |
|
| 145 | - $display->setQueryData($this->gatherQueryData($profiledQueries)); |
|
| 146 | - $display->setSpeedData($this->gatherSpeedData()); |
|
| 147 | - |
|
| 148 | - $display(); |
|
| 149 | - } |
|
| 18 | + /** @var Console */ |
|
| 19 | + protected $console; |
|
| 20 | + |
|
| 21 | + /** @var integer */ |
|
| 22 | + protected $startTime; |
|
| 23 | + |
|
| 24 | + /** @var object */ |
|
| 25 | + protected $pdo; |
|
| 26 | + |
|
| 27 | + /** |
|
| 28 | + * @param Console $console |
|
| 29 | + * @param object $pdo |
|
| 30 | + * @param integer $startTime |
|
| 31 | + */ |
|
| 32 | + public function __construct(Console $console, $pdo = null, $startTime = null) |
|
| 33 | + { |
|
| 34 | + $this->console = $console; |
|
| 35 | + $this->pdo = $pdo; |
|
| 36 | + |
|
| 37 | + if (is_null($startTime)) { |
|
| 38 | + $startTime = microtime(true); |
|
| 39 | + } |
|
| 40 | + $this->startTime = $startTime; |
|
| 41 | + } |
|
| 42 | + |
|
| 43 | + /** |
|
| 44 | + * Get data about files loaded for the application to current point |
|
| 45 | + * |
|
| 46 | + * @returns array |
|
| 47 | + */ |
|
| 48 | + public function gatherFileData() |
|
| 49 | + { |
|
| 50 | + $files = get_included_files(); |
|
| 51 | + $data = array(); |
|
| 52 | + foreach ($files as $file) { |
|
| 53 | + array_push($data, array( |
|
| 54 | + 'name' => $file, |
|
| 55 | + 'size' => filesize($file) |
|
| 56 | + )); |
|
| 57 | + } |
|
| 58 | + return $data; |
|
| 59 | + } |
|
| 60 | + |
|
| 61 | + /** |
|
| 62 | + * Get data about memory usage of the application |
|
| 63 | + * |
|
| 64 | + * @returns array |
|
| 65 | + */ |
|
| 66 | + public function gatherMemoryData() |
|
| 67 | + { |
|
| 68 | + $usedMemory = memory_get_peak_usage(); |
|
| 69 | + $allowedMemory = ini_get('memory_limit'); |
|
| 70 | + return array( |
|
| 71 | + 'used' => $usedMemory, |
|
| 72 | + 'allowed' => $allowedMemory |
|
| 73 | + ); |
|
| 74 | + } |
|
| 75 | + |
|
| 76 | + /** |
|
| 77 | + * Get data about sql usage of the application |
|
| 78 | + * |
|
| 79 | + * @param array $profiledQueries |
|
| 80 | + * @returns array |
|
| 81 | + */ |
|
| 82 | + public function gatherQueryData(array $profiledQueries) |
|
| 83 | + { |
|
| 84 | + $data = array(); |
|
| 85 | + foreach ($profiledQueries as $query) { |
|
| 86 | + if ($query['function'] !== 'perform') { |
|
| 87 | + continue; |
|
| 88 | + } |
|
| 89 | + |
|
| 90 | + array_push($data, array( |
|
| 91 | + 'sql' => $query['statement'], |
|
| 92 | + 'explain' => $this->explainQuery($query['statement'], $query['bind_values']), |
|
| 93 | + 'time' => $query['duration'] |
|
| 94 | + )); |
|
| 95 | + } |
|
| 96 | + return $data; |
|
| 97 | + } |
|
| 98 | + |
|
| 99 | + /** |
|
| 100 | + * Attempts to explain a query |
|
| 101 | + * |
|
| 102 | + * @param string $query |
|
| 103 | + * @param array $parameters |
|
| 104 | + * @return array |
|
| 105 | + */ |
|
| 106 | + protected function explainQuery($query, $parameters) |
|
| 107 | + { |
|
| 108 | + $query = "EXPLAIN {$query}"; |
|
| 109 | + try { |
|
| 110 | + $statement = $this->pdo->prepare($query); |
|
| 111 | + $statement->execute($parameters); |
|
| 112 | + return $statement->fetch(\PDO::FETCH_ASSOC); |
|
| 113 | + } catch (\Exception $e) { |
|
| 114 | + echo $e->getMessage(); |
|
| 115 | + } |
|
| 116 | + return ''; |
|
| 117 | + } |
|
| 118 | + |
|
| 119 | + /** |
|
| 120 | + * Get data about speed of the application |
|
| 121 | + * |
|
| 122 | + * @returns array |
|
| 123 | + */ |
|
| 124 | + public function gatherSpeedData() |
|
| 125 | + { |
|
| 126 | + $elapsedTime = microtime(true) - $this->startTime; |
|
| 127 | + $allowedTime = ini_get('max_execution_time'); |
|
| 128 | + return array( |
|
| 129 | + 'elapsed' => $elapsedTime, |
|
| 130 | + 'allowed' => $allowedTime |
|
| 131 | + ); |
|
| 132 | + } |
|
| 133 | + |
|
| 134 | + /** |
|
| 135 | + * Triggers end display of the profiling data |
|
| 136 | + * |
|
| 137 | + * @param Display $display |
|
| 138 | + * @param array $profiledQueries |
|
| 139 | + */ |
|
| 140 | + public function display(Display $display, array $profiledQueries = array()) |
|
| 141 | + { |
|
| 142 | + $display->setConsole($this->console); |
|
| 143 | + $display->setFileData($this->gatherFileData()); |
|
| 144 | + $display->setMemoryData($this->gatherMemoryData()); |
|
| 145 | + $display->setQueryData($this->gatherQueryData($profiledQueries)); |
|
| 146 | + $display->setSpeedData($this->gatherSpeedData()); |
|
| 147 | + |
|
| 148 | + $display(); |
|
| 149 | + } |
|
| 150 | 150 | } |