@@ -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 | } |
@@ -20,15 +20,15 @@ discard block |
||
| 20 | 20 | class Display |
| 21 | 21 | { |
| 22 | 22 | |
| 23 | - protected $console_data; |
|
| 23 | + protected $console_data; |
|
| 24 | 24 | |
| 25 | - public function __construct($console_data) |
|
| 26 | - { |
|
| 27 | - $this->console_data = $console_data; |
|
| 28 | - } |
|
| 25 | + public function __construct($console_data) |
|
| 26 | + { |
|
| 27 | + $this->console_data = $console_data; |
|
| 28 | + } |
|
| 29 | 29 | |
| 30 | - public function __invoke($output) |
|
| 31 | - { |
|
| 30 | + public function __invoke($output) |
|
| 31 | + { |
|
| 32 | 32 | |
| 33 | 33 | $css = file_get_contents(__DIR__ . '/../css/pQp.css'); |
| 34 | 34 | |
@@ -187,10 +187,10 @@ discard block |
||
| 187 | 187 | } |
| 188 | 188 | elseif($log['type'] == 'memory') { |
| 189 | 189 | echo '<div><pre>'.$log['data'].'</pre>'; |
| 190 | - if (!empty($log['data_type'])) { |
|
| 191 | - echo '<em>'.$log['data_type'].'</em>: '; |
|
| 192 | - } |
|
| 193 | - echo $log['name'].' </div>'; |
|
| 190 | + if (!empty($log['data_type'])) { |
|
| 191 | + echo '<em>'.$log['data_type'].'</em>: '; |
|
| 192 | + } |
|
| 193 | + echo $log['name'].' </div>'; |
|
| 194 | 194 | } |
| 195 | 195 | elseif($log['type'] == 'speed') { |
| 196 | 196 | echo '<div><pre>'.$log['data'].'</pre> <em>'.$log['name'].'</em></div>'; |
@@ -291,10 +291,10 @@ discard block |
||
| 291 | 291 | if($log['type'] == 'memory') { |
| 292 | 292 | echo '<tr class="log-'.$log['type'].'">'; |
| 293 | 293 | echo '<td class="'.$class.'"><b>'.$log['data'].'</b>'; |
| 294 | - if ($log['data_type']) { |
|
| 295 | - echo '<em>'.$log['data_type'].'</em>: '; |
|
| 296 | - } |
|
| 297 | - echo $log['name'].'</td>'; |
|
| 294 | + if ($log['data_type']) { |
|
| 295 | + echo '<em>'.$log['data_type'].'</em>: '; |
|
| 296 | + } |
|
| 297 | + echo $log['name'].'</td>'; |
|
| 298 | 298 | echo '</tr>'; |
| 299 | 299 | if($class == '') $class = 'alt'; |
| 300 | 300 | else $class = ''; |
@@ -30,7 +30,7 @@ discard block |
||
| 30 | 30 | public function __invoke($output) |
| 31 | 31 | { |
| 32 | 32 | |
| 33 | -$css = file_get_contents(__DIR__ . '/../css/pQp.css'); |
|
| 33 | +$css = file_get_contents(__DIR__.'/../css/pQp.css'); |
|
| 34 | 34 | |
| 35 | 35 | echo <<<JAVASCRIPT |
| 36 | 36 | <!-- JavaScript --> |
@@ -161,7 +161,7 @@ discard block |
||
| 161 | 161 | |
| 162 | 162 | echo '<div id="pqp-console" class="pqp-box">'; |
| 163 | 163 | |
| 164 | -if($logCount == 0) { |
|
| 164 | +if ($logCount == 0) { |
|
| 165 | 165 | echo '<h3>This panel has no log items.</h3>'; |
| 166 | 166 | } |
| 167 | 167 | else { |
@@ -178,29 +178,29 @@ discard block |
||
| 178 | 178 | <table class="main" cellspacing="0">'; |
| 179 | 179 | |
| 180 | 180 | $class = ''; |
| 181 | - foreach($this->console_data['messages'] as $log) { |
|
| 181 | + foreach ($this->console_data['messages'] as $log) { |
|
| 182 | 182 | echo '<tr class="log-'.$log['type'].'"> |
| 183 | 183 | <td class="type">'.$log['type'].'</td> |
| 184 | 184 | <td class="'.$class.'">'; |
| 185 | - if($log['type'] == 'log') { |
|
| 185 | + if ($log['type'] == 'log') { |
|
| 186 | 186 | echo '<div><pre>'.$log['data'].'</pre></div>'; |
| 187 | 187 | } |
| 188 | - elseif($log['type'] == 'memory') { |
|
| 188 | + elseif ($log['type'] == 'memory') { |
|
| 189 | 189 | echo '<div><pre>'.$log['data'].'</pre>'; |
| 190 | 190 | if (!empty($log['data_type'])) { |
| 191 | 191 | echo '<em>'.$log['data_type'].'</em>: '; |
| 192 | 192 | } |
| 193 | 193 | echo $log['name'].' </div>'; |
| 194 | 194 | } |
| 195 | - elseif($log['type'] == 'speed') { |
|
| 195 | + elseif ($log['type'] == 'speed') { |
|
| 196 | 196 | echo '<div><pre>'.$log['data'].'</pre> <em>'.$log['name'].'</em></div>'; |
| 197 | 197 | } |
| 198 | - elseif($log['type'] == 'error') { |
|
| 198 | + elseif ($log['type'] == 'error') { |
|
| 199 | 199 | echo '<div><em>Line '.$log['line'].'</em> : '.$log['data'].' <pre>'.$log['file'].'</pre></div>'; |
| 200 | 200 | } |
| 201 | 201 | |
| 202 | 202 | echo '</td></tr>'; |
| 203 | - if($class == '') $class = 'alt'; |
|
| 203 | + if ($class == '') $class = 'alt'; |
|
| 204 | 204 | else $class = ''; |
| 205 | 205 | } |
| 206 | 206 | |
@@ -211,7 +211,7 @@ discard block |
||
| 211 | 211 | |
| 212 | 212 | echo '<div id="pqp-speed" class="pqp-box">'; |
| 213 | 213 | |
| 214 | -if($this->console_data['count']['speed'] == 0) { |
|
| 214 | +if ($this->console_data['count']['speed'] == 0) { |
|
| 215 | 215 | echo '<h3>This panel has no log items.</h3>'; |
| 216 | 216 | } |
| 217 | 217 | else { |
@@ -222,13 +222,13 @@ discard block |
||
| 222 | 222 | <table class="main" cellspacing="0">'; |
| 223 | 223 | |
| 224 | 224 | $class = ''; |
| 225 | - foreach($this->console_data['messages'] as $log) { |
|
| 226 | - if($log['type'] == 'speed') { |
|
| 225 | + foreach ($this->console_data['messages'] as $log) { |
|
| 226 | + if ($log['type'] == 'speed') { |
|
| 227 | 227 | echo '<tr class="log-'.$log['type'].'"> |
| 228 | 228 | <td class="'.$class.'">'; |
| 229 | 229 | echo '<div><pre>'.$log['data'].'</pre> <em>'.$log['name'].'</em></div>'; |
| 230 | 230 | echo '</td></tr>'; |
| 231 | - if($class == '') $class = 'alt'; |
|
| 231 | + if ($class == '') $class = 'alt'; |
|
| 232 | 232 | else $class = ''; |
| 233 | 233 | } |
| 234 | 234 | } |
@@ -240,7 +240,7 @@ discard block |
||
| 240 | 240 | |
| 241 | 241 | echo '<div id="pqp-queries" class="pqp-box">'; |
| 242 | 242 | |
| 243 | -if($output['queryTotals']['count'] == 0) { |
|
| 243 | +if ($output['queryTotals']['count'] == 0) { |
|
| 244 | 244 | echo '<h3>This panel has no log items.</h3>'; |
| 245 | 245 | } |
| 246 | 246 | else { |
@@ -252,10 +252,10 @@ discard block |
||
| 252 | 252 | <table class="main" cellspacing="0">'; |
| 253 | 253 | |
| 254 | 254 | $class = ''; |
| 255 | - foreach($output['queries'] as $query) { |
|
| 255 | + foreach ($output['queries'] as $query) { |
|
| 256 | 256 | echo '<tr> |
| 257 | 257 | <td class="'.$class.'">'.$query['sql']; |
| 258 | - if($query['explain']) { |
|
| 258 | + if ($query['explain']) { |
|
| 259 | 259 | echo '<em> |
| 260 | 260 | Possible keys: <b>'.$query['explain']['possible_keys'].'</b> · |
| 261 | 261 | Key Used: <b>'.$query['explain']['key'].'</b> · |
@@ -265,7 +265,7 @@ discard block |
||
| 265 | 265 | </em>'; |
| 266 | 266 | } |
| 267 | 267 | echo '</td></tr>'; |
| 268 | - if($class == '') $class = 'alt'; |
|
| 268 | + if ($class == '') $class = 'alt'; |
|
| 269 | 269 | else $class = ''; |
| 270 | 270 | } |
| 271 | 271 | |
@@ -276,7 +276,7 @@ discard block |
||
| 276 | 276 | |
| 277 | 277 | echo '<div id="pqp-memory" class="pqp-box">'; |
| 278 | 278 | |
| 279 | -if($this->console_data['count']['memory'] == 0) { |
|
| 279 | +if ($this->console_data['count']['memory'] == 0) { |
|
| 280 | 280 | echo '<h3>This panel has no log items.</h3>'; |
| 281 | 281 | } |
| 282 | 282 | else { |
@@ -287,8 +287,8 @@ discard block |
||
| 287 | 287 | <table class="main" cellspacing="0">'; |
| 288 | 288 | |
| 289 | 289 | $class = ''; |
| 290 | - foreach($this->console_data['messages'] as $log) { |
|
| 291 | - if($log['type'] == 'memory') { |
|
| 290 | + foreach ($this->console_data['messages'] as $log) { |
|
| 291 | + if ($log['type'] == 'memory') { |
|
| 292 | 292 | echo '<tr class="log-'.$log['type'].'">'; |
| 293 | 293 | echo '<td class="'.$class.'"><b>'.$log['data'].'</b>'; |
| 294 | 294 | if ($log['data_type']) { |
@@ -296,7 +296,7 @@ discard block |
||
| 296 | 296 | } |
| 297 | 297 | echo $log['name'].'</td>'; |
| 298 | 298 | echo '</tr>'; |
| 299 | - if($class == '') $class = 'alt'; |
|
| 299 | + if ($class == '') $class = 'alt'; |
|
| 300 | 300 | else $class = ''; |
| 301 | 301 | } |
| 302 | 302 | } |
@@ -308,7 +308,7 @@ discard block |
||
| 308 | 308 | |
| 309 | 309 | echo '<div id="pqp-files" class="pqp-box">'; |
| 310 | 310 | |
| 311 | -if($output['fileTotals']['count'] == 0) { |
|
| 311 | +if ($output['fileTotals']['count'] == 0) { |
|
| 312 | 312 | echo '<h3>This panel has no log items.</h3>'; |
| 313 | 313 | } |
| 314 | 314 | else { |
@@ -319,10 +319,10 @@ discard block |
||
| 319 | 319 | </table> |
| 320 | 320 | <table class="main" cellspacing="0">'; |
| 321 | 321 | |
| 322 | - $class =''; |
|
| 323 | - foreach($output['files'] as $file) { |
|
| 322 | + $class = ''; |
|
| 323 | + foreach ($output['files'] as $file) { |
|
| 324 | 324 | echo '<tr><td class="'.$class.'"><b>'.$file['size'].'</b> '.$file['name'].'</td></tr>'; |
| 325 | - if($class == '') $class = 'alt'; |
|
| 325 | + if ($class == '') $class = 'alt'; |
|
| 326 | 326 | else $class = ''; |
| 327 | 327 | } |
| 328 | 328 | |
@@ -15,121 +15,121 @@ discard block |
||
| 15 | 15 | class PhpQuickProfiler |
| 16 | 16 | { |
| 17 | 17 | |
| 18 | - /** @var Particletree\Pqp\Console */ |
|
| 19 | - protected $console; |
|
| 18 | + /** @var Particletree\Pqp\Console */ |
|
| 19 | + protected $console; |
|
| 20 | 20 | |
| 21 | - /** @var integer */ |
|
| 22 | - protected $startTime; |
|
| 21 | + /** @var integer */ |
|
| 22 | + protected $startTime; |
|
| 23 | 23 | |
| 24 | - /** |
|
| 25 | - * @param Particletree\Pqp\Console $console |
|
| 26 | - * @param integer $startTime |
|
| 27 | - */ |
|
| 28 | - public function __construct(Console $console, $startTime = null) |
|
| 29 | - { |
|
| 30 | - $this->console = $console; |
|
| 24 | + /** |
|
| 25 | + * @param Particletree\Pqp\Console $console |
|
| 26 | + * @param integer $startTime |
|
| 27 | + */ |
|
| 28 | + public function __construct(Console $console, $startTime = null) |
|
| 29 | + { |
|
| 30 | + $this->console = $console; |
|
| 31 | 31 | |
| 32 | - if (is_null($startTime)) { |
|
| 33 | - $startTime = microtime(true); |
|
| 34 | - } |
|
| 35 | - $this->startTime = $startTime; |
|
| 36 | - } |
|
| 32 | + if (is_null($startTime)) { |
|
| 33 | + $startTime = microtime(true); |
|
| 34 | + } |
|
| 35 | + $this->startTime = $startTime; |
|
| 36 | + } |
|
| 37 | 37 | |
| 38 | - /** |
|
| 39 | - * Formats the logs from the console |
|
| 40 | - * |
|
| 41 | - * @return array |
|
| 42 | - */ |
|
| 43 | - protected function gatherConsoleData() |
|
| 44 | - { |
|
| 45 | - $console = array( |
|
| 46 | - 'messages' => array(), |
|
| 47 | - 'count' => array( |
|
| 48 | - 'log' => 0, |
|
| 49 | - 'memory' => 0, |
|
| 50 | - 'error' => 0, |
|
| 51 | - 'speed' => 0 |
|
| 52 | - ) |
|
| 53 | - ); |
|
| 38 | + /** |
|
| 39 | + * Formats the logs from the console |
|
| 40 | + * |
|
| 41 | + * @return array |
|
| 42 | + */ |
|
| 43 | + protected function gatherConsoleData() |
|
| 44 | + { |
|
| 45 | + $console = array( |
|
| 46 | + 'messages' => array(), |
|
| 47 | + 'count' => array( |
|
| 48 | + 'log' => 0, |
|
| 49 | + 'memory' => 0, |
|
| 50 | + 'error' => 0, |
|
| 51 | + 'speed' => 0 |
|
| 52 | + ) |
|
| 53 | + ); |
|
| 54 | 54 | |
| 55 | - foreach ($this->console->getLogs() as $log) { |
|
| 56 | - switch($log['type']) { |
|
| 57 | - case 'log': |
|
| 58 | - $message = array( |
|
| 59 | - 'data' => print_r($log['data'], true), |
|
| 60 | - 'type' => 'log' |
|
| 61 | - ); |
|
| 62 | - $console['count']['log']++; |
|
| 63 | - break; |
|
| 64 | - case 'memory': |
|
| 65 | - $message = array( |
|
| 66 | - 'name' => $log['name'], |
|
| 67 | - 'data' => self::getReadableFileSize($log['data']), |
|
| 68 | - 'type' => 'memory' |
|
| 69 | - ); |
|
| 70 | - if (!empty($log['data_type'])) { |
|
| 71 | - $message['data_type'] = $log['data_type']; |
|
| 72 | - } |
|
| 73 | - $console['count']['memory']++; |
|
| 74 | - break; |
|
| 75 | - case 'error': |
|
| 76 | - $message = array( |
|
| 77 | - 'data' => $log['data'], |
|
| 78 | - 'file' => $log['file'], |
|
| 79 | - 'line' => $log['line'], |
|
| 80 | - 'type' => 'error' |
|
| 81 | - ); |
|
| 82 | - $console['count']['error']++; |
|
| 83 | - break; |
|
| 84 | - case 'speed': |
|
| 85 | - $elapsedTime = $log['data'] - $this->startTime; |
|
| 86 | - $message = array( |
|
| 87 | - 'name' => $log['name'], |
|
| 88 | - 'data' => self::getReadableTime($elapsedTime), |
|
| 89 | - 'type' => 'speed' |
|
| 90 | - ); |
|
| 91 | - $console['count']['speed']++; |
|
| 92 | - break; |
|
| 93 | - default: |
|
| 94 | - $message = array( |
|
| 95 | - 'data' => "Unrecognized console log type: {$log['type']}", |
|
| 96 | - 'type' => 'error' |
|
| 97 | - ); |
|
| 98 | - $console['count']['error']++; |
|
| 99 | - break; |
|
| 100 | - } |
|
| 101 | - array_push($console['messages'], $message); |
|
| 102 | - } |
|
| 103 | - return $console; |
|
| 104 | - } |
|
| 55 | + foreach ($this->console->getLogs() as $log) { |
|
| 56 | + switch($log['type']) { |
|
| 57 | + case 'log': |
|
| 58 | + $message = array( |
|
| 59 | + 'data' => print_r($log['data'], true), |
|
| 60 | + 'type' => 'log' |
|
| 61 | + ); |
|
| 62 | + $console['count']['log']++; |
|
| 63 | + break; |
|
| 64 | + case 'memory': |
|
| 65 | + $message = array( |
|
| 66 | + 'name' => $log['name'], |
|
| 67 | + 'data' => self::getReadableFileSize($log['data']), |
|
| 68 | + 'type' => 'memory' |
|
| 69 | + ); |
|
| 70 | + if (!empty($log['data_type'])) { |
|
| 71 | + $message['data_type'] = $log['data_type']; |
|
| 72 | + } |
|
| 73 | + $console['count']['memory']++; |
|
| 74 | + break; |
|
| 75 | + case 'error': |
|
| 76 | + $message = array( |
|
| 77 | + 'data' => $log['data'], |
|
| 78 | + 'file' => $log['file'], |
|
| 79 | + 'line' => $log['line'], |
|
| 80 | + 'type' => 'error' |
|
| 81 | + ); |
|
| 82 | + $console['count']['error']++; |
|
| 83 | + break; |
|
| 84 | + case 'speed': |
|
| 85 | + $elapsedTime = $log['data'] - $this->startTime; |
|
| 86 | + $message = array( |
|
| 87 | + 'name' => $log['name'], |
|
| 88 | + 'data' => self::getReadableTime($elapsedTime), |
|
| 89 | + 'type' => 'speed' |
|
| 90 | + ); |
|
| 91 | + $console['count']['speed']++; |
|
| 92 | + break; |
|
| 93 | + default: |
|
| 94 | + $message = array( |
|
| 95 | + 'data' => "Unrecognized console log type: {$log['type']}", |
|
| 96 | + 'type' => 'error' |
|
| 97 | + ); |
|
| 98 | + $console['count']['error']++; |
|
| 99 | + break; |
|
| 100 | + } |
|
| 101 | + array_push($console['messages'], $message); |
|
| 102 | + } |
|
| 103 | + return $console; |
|
| 104 | + } |
|
| 105 | 105 | |
| 106 | 106 | /*------------------------------------------- |
| 107 | 107 | AGGREGATE DATA ON THE FILES INCLUDED |
| 108 | 108 | -------------------------------------------*/ |
| 109 | 109 | |
| 110 | 110 | public function gatherFileData() { |
| 111 | - $files = get_included_files(); |
|
| 112 | - $fileList = array(); |
|
| 113 | - $fileTotals = array( |
|
| 114 | - "count" => count($files), |
|
| 115 | - "size" => 0, |
|
| 116 | - "largest" => 0, |
|
| 117 | - ); |
|
| 111 | + $files = get_included_files(); |
|
| 112 | + $fileList = array(); |
|
| 113 | + $fileTotals = array( |
|
| 114 | + "count" => count($files), |
|
| 115 | + "size" => 0, |
|
| 116 | + "largest" => 0, |
|
| 117 | + ); |
|
| 118 | 118 | |
| 119 | - foreach($files as $file) { |
|
| 120 | - $size = filesize($file); |
|
| 121 | - $fileList[] = array( |
|
| 122 | - 'name' => $file, |
|
| 123 | - 'size' => $this->getReadableFileSize($size) |
|
| 124 | - ); |
|
| 125 | - $fileTotals['size'] += $size; |
|
| 126 | - if($size > $fileTotals['largest']) $fileTotals['largest'] = $size; |
|
| 127 | - } |
|
| 119 | + foreach($files as $file) { |
|
| 120 | + $size = filesize($file); |
|
| 121 | + $fileList[] = array( |
|
| 122 | + 'name' => $file, |
|
| 123 | + 'size' => $this->getReadableFileSize($size) |
|
| 124 | + ); |
|
| 125 | + $fileTotals['size'] += $size; |
|
| 126 | + if($size > $fileTotals['largest']) $fileTotals['largest'] = $size; |
|
| 127 | + } |
|
| 128 | 128 | |
| 129 | - $fileTotals['size'] = $this->getReadableFileSize($fileTotals['size']); |
|
| 130 | - $fileTotals['largest'] = $this->getReadableFileSize($fileTotals['largest']); |
|
| 131 | - $this->output['files'] = $fileList; |
|
| 132 | - $this->output['fileTotals'] = $fileTotals; |
|
| 129 | + $fileTotals['size'] = $this->getReadableFileSize($fileTotals['size']); |
|
| 130 | + $fileTotals['largest'] = $this->getReadableFileSize($fileTotals['largest']); |
|
| 131 | + $this->output['files'] = $fileList; |
|
| 132 | + $this->output['fileTotals'] = $fileTotals; |
|
| 133 | 133 | } |
| 134 | 134 | |
| 135 | 135 | /*------------------------------------------- |
@@ -137,10 +137,10 @@ discard block |
||
| 137 | 137 | -------------------------------------------*/ |
| 138 | 138 | |
| 139 | 139 | public function gatherMemoryData() { |
| 140 | - $memoryTotals = array(); |
|
| 141 | - $memoryTotals['used'] = $this->getReadableFileSize(memory_get_peak_usage()); |
|
| 142 | - $memoryTotals['total'] = ini_get("memory_limit"); |
|
| 143 | - $this->output['memoryTotals'] = $memoryTotals; |
|
| 140 | + $memoryTotals = array(); |
|
| 141 | + $memoryTotals['used'] = $this->getReadableFileSize(memory_get_peak_usage()); |
|
| 142 | + $memoryTotals['total'] = ini_get("memory_limit"); |
|
| 143 | + $this->output['memoryTotals'] = $memoryTotals; |
|
| 144 | 144 | } |
| 145 | 145 | |
| 146 | 146 | /*-------------------------------------------------------- |
@@ -148,24 +148,24 @@ discard block |
||
| 148 | 148 | ----------------------------------------------------------*/ |
| 149 | 149 | |
| 150 | 150 | public function gatherQueryData() { |
| 151 | - $queryTotals = array(); |
|
| 152 | - $queryTotals['count'] = 0; |
|
| 153 | - $queryTotals['time'] = 0; |
|
| 154 | - $queries = array(); |
|
| 151 | + $queryTotals = array(); |
|
| 152 | + $queryTotals['count'] = 0; |
|
| 153 | + $queryTotals['time'] = 0; |
|
| 154 | + $queries = array(); |
|
| 155 | 155 | |
| 156 | - if($this->db != '') { |
|
| 157 | - $queryTotals['count'] += $this->db->queryCount; |
|
| 158 | - foreach($this->db->queries as $query) { |
|
| 159 | - $query = $this->attemptToExplainQuery($query); |
|
| 160 | - $queryTotals['time'] += $query['time']; |
|
| 161 | - $query['time'] = $this->getReadableTime($query['time']); |
|
| 162 | - $queries[] = $query; |
|
| 163 | - } |
|
| 164 | - } |
|
| 156 | + if($this->db != '') { |
|
| 157 | + $queryTotals['count'] += $this->db->queryCount; |
|
| 158 | + foreach($this->db->queries as $query) { |
|
| 159 | + $query = $this->attemptToExplainQuery($query); |
|
| 160 | + $queryTotals['time'] += $query['time']; |
|
| 161 | + $query['time'] = $this->getReadableTime($query['time']); |
|
| 162 | + $queries[] = $query; |
|
| 163 | + } |
|
| 164 | + } |
|
| 165 | 165 | |
| 166 | - $queryTotals['time'] = $this->getReadableTime($queryTotals['time']); |
|
| 167 | - $this->output['queries'] = $queries; |
|
| 168 | - $this->output['queryTotals'] = $queryTotals; |
|
| 166 | + $queryTotals['time'] = $this->getReadableTime($queryTotals['time']); |
|
| 167 | + $this->output['queries'] = $queries; |
|
| 168 | + $this->output['queryTotals'] = $queryTotals; |
|
| 169 | 169 | } |
| 170 | 170 | |
| 171 | 171 | /*-------------------------------------------------------- |
@@ -173,16 +173,16 @@ discard block |
||
| 173 | 173 | ----------------------------------------------------------*/ |
| 174 | 174 | |
| 175 | 175 | function attemptToExplainQuery($query) { |
| 176 | - try { |
|
| 177 | - $sql = 'EXPLAIN '.$query['sql']; |
|
| 178 | - $rs = $this->db->query($sql); |
|
| 179 | - } |
|
| 180 | - catch(Exception $e) {} |
|
| 181 | - if($rs) { |
|
| 182 | - $row = mysql_fetch_array($rs, MYSQL_ASSOC); |
|
| 183 | - $query['explain'] = $row; |
|
| 184 | - } |
|
| 185 | - return $query; |
|
| 176 | + try { |
|
| 177 | + $sql = 'EXPLAIN '.$query['sql']; |
|
| 178 | + $rs = $this->db->query($sql); |
|
| 179 | + } |
|
| 180 | + catch(Exception $e) {} |
|
| 181 | + if($rs) { |
|
| 182 | + $row = mysql_fetch_array($rs, MYSQL_ASSOC); |
|
| 183 | + $query['explain'] = $row; |
|
| 184 | + } |
|
| 185 | + return $query; |
|
| 186 | 186 | } |
| 187 | 187 | |
| 188 | 188 | /*------------------------------------------- |
@@ -190,10 +190,10 @@ discard block |
||
| 190 | 190 | -------------------------------------------*/ |
| 191 | 191 | |
| 192 | 192 | public function gatherSpeedData() { |
| 193 | - $speedTotals = array(); |
|
| 194 | - $speedTotals['total'] = self::getReadableTime((microtime(true) - $this->startTime)); |
|
| 195 | - $speedTotals['allowed'] = ini_get("max_execution_time"); |
|
| 196 | - $this->output['speedTotals'] = $speedTotals; |
|
| 193 | + $speedTotals = array(); |
|
| 194 | + $speedTotals['total'] = self::getReadableTime((microtime(true) - $this->startTime)); |
|
| 195 | + $speedTotals['allowed'] = ini_get("max_execution_time"); |
|
| 196 | + $this->output['speedTotals'] = $speedTotals; |
|
| 197 | 197 | } |
| 198 | 198 | |
| 199 | 199 | /*------------------------------------------- |
@@ -201,56 +201,56 @@ discard block |
||
| 201 | 201 | -------------------------------------------*/ |
| 202 | 202 | |
| 203 | 203 | public function getReadableFileSize($size, $retstring = null) { |
| 204 | - // adapted from code at http://aidanlister.com/repos/v/function.size_readable.php |
|
| 205 | - $sizes = array('bytes', 'kB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB'); |
|
| 204 | + // adapted from code at http://aidanlister.com/repos/v/function.size_readable.php |
|
| 205 | + $sizes = array('bytes', 'kB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB'); |
|
| 206 | 206 | |
| 207 | - if ($retstring === null) { $retstring = '%01.2f %s'; } |
|
| 207 | + if ($retstring === null) { $retstring = '%01.2f %s'; } |
|
| 208 | 208 | |
| 209 | - $lastsizestring = end($sizes); |
|
| 209 | + $lastsizestring = end($sizes); |
|
| 210 | 210 | |
| 211 | - foreach ($sizes as $sizestring) { |
|
| 212 | - if ($size < 1024) { break; } |
|
| 213 | - if ($sizestring != $lastsizestring) { $size /= 1024; } |
|
| 214 | - } |
|
| 215 | - if ($sizestring == $sizes[0]) { $retstring = '%01d %s'; } // Bytes aren't normally fractional |
|
| 216 | - return sprintf($retstring, $size, $sizestring); |
|
| 211 | + foreach ($sizes as $sizestring) { |
|
| 212 | + if ($size < 1024) { break; } |
|
| 213 | + if ($sizestring != $lastsizestring) { $size /= 1024; } |
|
| 214 | + } |
|
| 215 | + if ($sizestring == $sizes[0]) { $retstring = '%01d %s'; } // Bytes aren't normally fractional |
|
| 216 | + return sprintf($retstring, $size, $sizestring); |
|
| 217 | 217 | } |
| 218 | 218 | |
| 219 | - /** |
|
| 220 | - * Static formatter for human-readable time |
|
| 221 | - * Only handles time up to 60 minutes gracefully |
|
| 222 | - * |
|
| 223 | - * @param integer $time time in seconds |
|
| 224 | - * @return string |
|
| 225 | - */ |
|
| 226 | - public static function getReadableTime($time) |
|
| 227 | - { |
|
| 228 | - $unit = 's'; |
|
| 219 | + /** |
|
| 220 | + * Static formatter for human-readable time |
|
| 221 | + * Only handles time up to 60 minutes gracefully |
|
| 222 | + * |
|
| 223 | + * @param integer $time time in seconds |
|
| 224 | + * @return string |
|
| 225 | + */ |
|
| 226 | + public static function getReadableTime($time) |
|
| 227 | + { |
|
| 228 | + $unit = 's'; |
|
| 229 | 229 | |
| 230 | - if ($time < 1) { |
|
| 231 | - $time *= 1000; |
|
| 232 | - $unit = 'ms'; |
|
| 233 | - } else if ($time > 60) { |
|
| 234 | - $time /= 60; |
|
| 235 | - $unit = 'm'; |
|
| 236 | - } |
|
| 230 | + if ($time < 1) { |
|
| 231 | + $time *= 1000; |
|
| 232 | + $unit = 'ms'; |
|
| 233 | + } else if ($time > 60) { |
|
| 234 | + $time /= 60; |
|
| 235 | + $unit = 'm'; |
|
| 236 | + } |
|
| 237 | 237 | |
| 238 | - $time = number_format($time, 3); |
|
| 239 | - return "{$time} {$unit}"; |
|
| 240 | - } |
|
| 238 | + $time = number_format($time, 3); |
|
| 239 | + return "{$time} {$unit}"; |
|
| 240 | + } |
|
| 241 | 241 | |
| 242 | 242 | /*--------------------------------------------------------- |
| 243 | 243 | DISPLAY TO THE SCREEN -- CALL WHEN CODE TERMINATING |
| 244 | 244 | -----------------------------------------------------------*/ |
| 245 | 245 | |
| 246 | 246 | public function display($db = '') { |
| 247 | - $this->db = $db; |
|
| 248 | - $console = $this->gatherConsoleData(); |
|
| 249 | - $this->gatherFileData(); |
|
| 250 | - $this->gatherMemoryData(); |
|
| 251 | - $this->gatherQueryData(); |
|
| 252 | - $this->gatherSpeedData(); |
|
| 253 | - $display = new Display($console); |
|
| 254 | - $display($this->output); |
|
| 247 | + $this->db = $db; |
|
| 248 | + $console = $this->gatherConsoleData(); |
|
| 249 | + $this->gatherFileData(); |
|
| 250 | + $this->gatherMemoryData(); |
|
| 251 | + $this->gatherQueryData(); |
|
| 252 | + $this->gatherSpeedData(); |
|
| 253 | + $display = new Display($console); |
|
| 254 | + $display($this->output); |
|
| 255 | 255 | } |
| 256 | 256 | } |
@@ -53,7 +53,7 @@ discard block |
||
| 53 | 53 | ); |
| 54 | 54 | |
| 55 | 55 | foreach ($this->console->getLogs() as $log) { |
| 56 | - switch($log['type']) { |
|
| 56 | + switch ($log['type']) { |
|
| 57 | 57 | case 'log': |
| 58 | 58 | $message = array( |
| 59 | 59 | 'data' => print_r($log['data'], true), |
@@ -116,14 +116,14 @@ discard block |
||
| 116 | 116 | "largest" => 0, |
| 117 | 117 | ); |
| 118 | 118 | |
| 119 | - foreach($files as $file) { |
|
| 119 | + foreach ($files as $file) { |
|
| 120 | 120 | $size = filesize($file); |
| 121 | 121 | $fileList[] = array( |
| 122 | 122 | 'name' => $file, |
| 123 | 123 | 'size' => $this->getReadableFileSize($size) |
| 124 | 124 | ); |
| 125 | 125 | $fileTotals['size'] += $size; |
| 126 | - if($size > $fileTotals['largest']) $fileTotals['largest'] = $size; |
|
| 126 | + if ($size > $fileTotals['largest']) $fileTotals['largest'] = $size; |
|
| 127 | 127 | } |
| 128 | 128 | |
| 129 | 129 | $fileTotals['size'] = $this->getReadableFileSize($fileTotals['size']); |
@@ -153,9 +153,9 @@ discard block |
||
| 153 | 153 | $queryTotals['time'] = 0; |
| 154 | 154 | $queries = array(); |
| 155 | 155 | |
| 156 | - if($this->db != '') { |
|
| 156 | + if ($this->db != '') { |
|
| 157 | 157 | $queryTotals['count'] += $this->db->queryCount; |
| 158 | - foreach($this->db->queries as $query) { |
|
| 158 | + foreach ($this->db->queries as $query) { |
|
| 159 | 159 | $query = $this->attemptToExplainQuery($query); |
| 160 | 160 | $queryTotals['time'] += $query['time']; |
| 161 | 161 | $query['time'] = $this->getReadableTime($query['time']); |
@@ -177,8 +177,8 @@ discard block |
||
| 177 | 177 | $sql = 'EXPLAIN '.$query['sql']; |
| 178 | 178 | $rs = $this->db->query($sql); |
| 179 | 179 | } |
| 180 | - catch(Exception $e) {} |
|
| 181 | - if($rs) { |
|
| 180 | + catch (Exception $e) {} |
|
| 181 | + if ($rs) { |
|
| 182 | 182 | $row = mysql_fetch_array($rs, MYSQL_ASSOC); |
| 183 | 183 | $query['explain'] = $row; |
| 184 | 184 | } |
@@ -123,7 +123,9 @@ discard block |
||
| 123 | 123 | 'size' => $this->getReadableFileSize($size) |
| 124 | 124 | ); |
| 125 | 125 | $fileTotals['size'] += $size; |
| 126 | - if($size > $fileTotals['largest']) $fileTotals['largest'] = $size; |
|
| 126 | + if($size > $fileTotals['largest']) { |
|
| 127 | + $fileTotals['largest'] = $size; |
|
| 128 | + } |
|
| 127 | 129 | } |
| 128 | 130 | |
| 129 | 131 | $fileTotals['size'] = $this->getReadableFileSize($fileTotals['size']); |
@@ -176,8 +178,7 @@ discard block |
||
| 176 | 178 | try { |
| 177 | 179 | $sql = 'EXPLAIN '.$query['sql']; |
| 178 | 180 | $rs = $this->db->query($sql); |
| 179 | - } |
|
| 180 | - catch(Exception $e) {} |
|
| 181 | + } catch(Exception $e) {} |
|
| 181 | 182 | if($rs) { |
| 182 | 183 | $row = mysql_fetch_array($rs, MYSQL_ASSOC); |
| 183 | 184 | $query['explain'] = $row; |
@@ -6,31 +6,31 @@ |
||
| 6 | 6 | class PhpQuickProfilerTest extends PHPUnit_Framework_TestCase |
| 7 | 7 | { |
| 8 | 8 | |
| 9 | - public function __construct() |
|
| 10 | - { |
|
| 11 | - } |
|
| 12 | - |
|
| 13 | - public function testConstruct() |
|
| 14 | - { |
|
| 15 | - $console = new Console(); |
|
| 16 | - $startTime = microtime(true); |
|
| 17 | - |
|
| 18 | - $profiler = new PhpQuickProfiler($console, $startTime); |
|
| 19 | - |
|
| 20 | - $this->assertAttributeSame($console, 'console', $profiler); |
|
| 21 | - $this->assertAttributeEquals($startTime, 'startTime', $profiler); |
|
| 22 | - } |
|
| 23 | - |
|
| 24 | - public function testGetReadableTime() |
|
| 25 | - { |
|
| 26 | - $test_input = array( |
|
| 27 | - '.032432' => '32.432 ms', |
|
| 28 | - '24.3781' => '24.378 s', |
|
| 29 | - '145.123' => '2.419 m' |
|
| 30 | - ); |
|
| 31 | - |
|
| 32 | - foreach ($test_input as $input => $expected_return) { |
|
| 33 | - $this->assertEquals($expected_return, PhpQuickProfiler::getReadableTime($input)); |
|
| 34 | - } |
|
| 35 | - } |
|
| 9 | + public function __construct() |
|
| 10 | + { |
|
| 11 | + } |
|
| 12 | + |
|
| 13 | + public function testConstruct() |
|
| 14 | + { |
|
| 15 | + $console = new Console(); |
|
| 16 | + $startTime = microtime(true); |
|
| 17 | + |
|
| 18 | + $profiler = new PhpQuickProfiler($console, $startTime); |
|
| 19 | + |
|
| 20 | + $this->assertAttributeSame($console, 'console', $profiler); |
|
| 21 | + $this->assertAttributeEquals($startTime, 'startTime', $profiler); |
|
| 22 | + } |
|
| 23 | + |
|
| 24 | + public function testGetReadableTime() |
|
| 25 | + { |
|
| 26 | + $test_input = array( |
|
| 27 | + '.032432' => '32.432 ms', |
|
| 28 | + '24.3781' => '24.378 s', |
|
| 29 | + '145.123' => '2.419 m' |
|
| 30 | + ); |
|
| 31 | + |
|
| 32 | + foreach ($test_input as $input => $expected_return) { |
|
| 33 | + $this->assertEquals($expected_return, PhpQuickProfiler::getReadableTime($input)); |
|
| 34 | + } |
|
| 35 | + } |
|
| 36 | 36 | } |