@@ -15,86 +15,86 @@ |
||
| 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 = '') |
|
| 43 | - { |
|
| 44 | - $memory = memory_get_usage(); |
|
| 45 | - if (!is_null($object)) { |
|
| 46 | - $memory = strlen(serialize($object)); |
|
| 47 | - } |
|
| 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 = '') |
|
| 43 | + { |
|
| 44 | + $memory = memory_get_usage(); |
|
| 45 | + if (!is_null($object)) { |
|
| 46 | + $memory = strlen(serialize($object)); |
|
| 47 | + } |
|
| 48 | 48 | |
| 49 | - array_push($this->store, array( |
|
| 50 | - 'name' => $name, |
|
| 51 | - 'data' => $memory, |
|
| 52 | - 'data_type' => gettype($object), |
|
| 53 | - 'type' => 'memory' |
|
| 54 | - )); |
|
| 55 | - } |
|
| 49 | + array_push($this->store, array( |
|
| 50 | + 'name' => $name, |
|
| 51 | + 'data' => $memory, |
|
| 52 | + 'data_type' => gettype($object), |
|
| 53 | + 'type' => 'memory' |
|
| 54 | + )); |
|
| 55 | + } |
|
| 56 | 56 | |
| 57 | - /** |
|
| 58 | - * Logs exception with optional message override |
|
| 59 | - * |
|
| 60 | - * @param Exception $exception |
|
| 61 | - * @param string $message |
|
| 62 | - */ |
|
| 63 | - public function logError(Exception $exception, $message = '') |
|
| 64 | - { |
|
| 65 | - if (empty($message)) { |
|
| 66 | - $message = $exception->getMessage(); |
|
| 67 | - } |
|
| 57 | + /** |
|
| 58 | + * Logs exception with optional message override |
|
| 59 | + * |
|
| 60 | + * @param Exception $exception |
|
| 61 | + * @param string $message |
|
| 62 | + */ |
|
| 63 | + public function logError(Exception $exception, $message = '') |
|
| 64 | + { |
|
| 65 | + if (empty($message)) { |
|
| 66 | + $message = $exception->getMessage(); |
|
| 67 | + } |
|
| 68 | 68 | |
| 69 | - array_push($this->store, array( |
|
| 70 | - 'data' => $message, |
|
| 71 | - 'file' => $exception->getFile(), |
|
| 72 | - 'line' => $exception->getLine(), |
|
| 73 | - 'type' => 'error' |
|
| 74 | - )); |
|
| 75 | - } |
|
| 69 | + array_push($this->store, array( |
|
| 70 | + 'data' => $message, |
|
| 71 | + 'file' => $exception->getFile(), |
|
| 72 | + 'line' => $exception->getLine(), |
|
| 73 | + 'type' => 'error' |
|
| 74 | + )); |
|
| 75 | + } |
|
| 76 | 76 | |
| 77 | - /** |
|
| 78 | - * Logs current time with optional message |
|
| 79 | - * |
|
| 80 | - * @param string $name |
|
| 81 | - */ |
|
| 82 | - public function logSpeed($name = 'Point in Time') |
|
| 83 | - { |
|
| 84 | - array_push($this->store, array( |
|
| 85 | - 'data' => microtime(true), |
|
| 86 | - 'name' => $name, |
|
| 87 | - 'type' => 'speed' |
|
| 88 | - )); |
|
| 89 | - } |
|
| 77 | + /** |
|
| 78 | + * Logs current time with optional message |
|
| 79 | + * |
|
| 80 | + * @param string $name |
|
| 81 | + */ |
|
| 82 | + public function logSpeed($name = 'Point in Time') |
|
| 83 | + { |
|
| 84 | + array_push($this->store, array( |
|
| 85 | + 'data' => microtime(true), |
|
| 86 | + 'name' => $name, |
|
| 87 | + 'type' => 'speed' |
|
| 88 | + )); |
|
| 89 | + } |
|
| 90 | 90 | |
| 91 | - /** |
|
| 92 | - * Returns the collected logs |
|
| 93 | - * |
|
| 94 | - * @returns array |
|
| 95 | - */ |
|
| 96 | - public function getLogs() |
|
| 97 | - { |
|
| 98 | - return $this->store; |
|
| 99 | - } |
|
| 91 | + /** |
|
| 92 | + * Returns the collected logs |
|
| 93 | + * |
|
| 94 | + * @returns array |
|
| 95 | + */ |
|
| 96 | + public function getLogs() |
|
| 97 | + { |
|
| 98 | + return $this->store; |
|
| 99 | + } |
|
| 100 | 100 | } |
@@ -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 | } |
@@ -22,7 +22,7 @@ |
||
| 22 | 22 | protected $startTime; |
| 23 | 23 | |
| 24 | 24 | /** |
| 25 | - * @param Particletree\Pqp\Console $console |
|
| 25 | + * @param Console $console |
|
| 26 | 26 | * @param integer $startTime |
| 27 | 27 | */ |
| 28 | 28 | public function __construct(Console $console, $startTime = null) |
@@ -15,76 +15,76 @@ 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 | 38 | /*------------------------------------------- |
| 39 | 39 | FORMAT THE DIFFERENT TYPES OF LOGS |
| 40 | 40 | -------------------------------------------*/ |
| 41 | 41 | |
| 42 | 42 | public function gatherConsoleData() { |
| 43 | - $console = array( |
|
| 44 | - 'messages' => array(), |
|
| 45 | - 'totals' => array( |
|
| 46 | - 'log' => 0, |
|
| 47 | - 'memory' => 0, |
|
| 48 | - 'error' => 0, |
|
| 49 | - 'speed' => 0 |
|
| 50 | - )); |
|
| 51 | - $logs = $this->console->getLogs(); |
|
| 52 | - foreach($logs as $log) { |
|
| 53 | - if($log['type'] == 'log') { |
|
| 54 | - $message = array( |
|
| 55 | - 'data' => print_r($log['data'], true), |
|
| 56 | - 'type' => 'log' |
|
| 57 | - ); |
|
| 58 | - $console['totals']['log']++; |
|
| 59 | - } |
|
| 60 | - elseif($log['type'] == 'memory') { |
|
| 61 | - $message = array( |
|
| 62 | - 'name' => $log['name'], |
|
| 63 | - 'data_type' => $log['data_type'], |
|
| 64 | - 'data' => $this->getReadableFileSize($log['data']), |
|
| 65 | - 'type' => 'memory' |
|
| 66 | - ); |
|
| 67 | - $console['totals']['memory']++; |
|
| 68 | - } |
|
| 69 | - elseif($log['type'] == 'speed') { |
|
| 70 | - $message = array( |
|
| 71 | - 'name' => $log['name'], |
|
| 72 | - 'data' => $this->getReadableTime(($log['data'] - $this->startTime) * 1000), |
|
| 73 | - 'type' => 'speed' |
|
| 74 | - ); |
|
| 75 | - $console['totals']['speed']++; |
|
| 76 | - } else { |
|
| 77 | - $message = array( |
|
| 78 | - 'data' => $log['data'], |
|
| 79 | - 'type' => 'error', |
|
| 80 | - 'file' => $log['file'], |
|
| 81 | - 'line' => $log['line'] |
|
| 82 | - ); |
|
| 83 | - $console['totals']['error']++; |
|
| 84 | - } |
|
| 85 | - array_push($console['messages'], $message); |
|
| 86 | - } |
|
| 87 | - $this->output['logs'] = array('console' => $console); |
|
| 43 | + $console = array( |
|
| 44 | + 'messages' => array(), |
|
| 45 | + 'totals' => array( |
|
| 46 | + 'log' => 0, |
|
| 47 | + 'memory' => 0, |
|
| 48 | + 'error' => 0, |
|
| 49 | + 'speed' => 0 |
|
| 50 | + )); |
|
| 51 | + $logs = $this->console->getLogs(); |
|
| 52 | + foreach($logs as $log) { |
|
| 53 | + if($log['type'] == 'log') { |
|
| 54 | + $message = array( |
|
| 55 | + 'data' => print_r($log['data'], true), |
|
| 56 | + 'type' => 'log' |
|
| 57 | + ); |
|
| 58 | + $console['totals']['log']++; |
|
| 59 | + } |
|
| 60 | + elseif($log['type'] == 'memory') { |
|
| 61 | + $message = array( |
|
| 62 | + 'name' => $log['name'], |
|
| 63 | + 'data_type' => $log['data_type'], |
|
| 64 | + 'data' => $this->getReadableFileSize($log['data']), |
|
| 65 | + 'type' => 'memory' |
|
| 66 | + ); |
|
| 67 | + $console['totals']['memory']++; |
|
| 68 | + } |
|
| 69 | + elseif($log['type'] == 'speed') { |
|
| 70 | + $message = array( |
|
| 71 | + 'name' => $log['name'], |
|
| 72 | + 'data' => $this->getReadableTime(($log['data'] - $this->startTime) * 1000), |
|
| 73 | + 'type' => 'speed' |
|
| 74 | + ); |
|
| 75 | + $console['totals']['speed']++; |
|
| 76 | + } else { |
|
| 77 | + $message = array( |
|
| 78 | + 'data' => $log['data'], |
|
| 79 | + 'type' => 'error', |
|
| 80 | + 'file' => $log['file'], |
|
| 81 | + 'line' => $log['line'] |
|
| 82 | + ); |
|
| 83 | + $console['totals']['error']++; |
|
| 84 | + } |
|
| 85 | + array_push($console['messages'], $message); |
|
| 86 | + } |
|
| 87 | + $this->output['logs'] = array('console' => $console); |
|
| 88 | 88 | } |
| 89 | 89 | |
| 90 | 90 | /*------------------------------------------- |
@@ -92,28 +92,28 @@ discard block |
||
| 92 | 92 | -------------------------------------------*/ |
| 93 | 93 | |
| 94 | 94 | public function gatherFileData() { |
| 95 | - $files = get_included_files(); |
|
| 96 | - $fileList = array(); |
|
| 97 | - $fileTotals = array( |
|
| 98 | - "count" => count($files), |
|
| 99 | - "size" => 0, |
|
| 100 | - "largest" => 0, |
|
| 101 | - ); |
|
| 95 | + $files = get_included_files(); |
|
| 96 | + $fileList = array(); |
|
| 97 | + $fileTotals = array( |
|
| 98 | + "count" => count($files), |
|
| 99 | + "size" => 0, |
|
| 100 | + "largest" => 0, |
|
| 101 | + ); |
|
| 102 | 102 | |
| 103 | - foreach($files as $key => $file) { |
|
| 104 | - $size = filesize($file); |
|
| 105 | - $fileList[] = array( |
|
| 106 | - 'name' => $file, |
|
| 107 | - 'size' => $this->getReadableFileSize($size) |
|
| 108 | - ); |
|
| 109 | - $fileTotals['size'] += $size; |
|
| 110 | - if($size > $fileTotals['largest']) $fileTotals['largest'] = $size; |
|
| 111 | - } |
|
| 103 | + foreach($files as $key => $file) { |
|
| 104 | + $size = filesize($file); |
|
| 105 | + $fileList[] = array( |
|
| 106 | + 'name' => $file, |
|
| 107 | + 'size' => $this->getReadableFileSize($size) |
|
| 108 | + ); |
|
| 109 | + $fileTotals['size'] += $size; |
|
| 110 | + if($size > $fileTotals['largest']) $fileTotals['largest'] = $size; |
|
| 111 | + } |
|
| 112 | 112 | |
| 113 | - $fileTotals['size'] = $this->getReadableFileSize($fileTotals['size']); |
|
| 114 | - $fileTotals['largest'] = $this->getReadableFileSize($fileTotals['largest']); |
|
| 115 | - $this->output['files'] = $fileList; |
|
| 116 | - $this->output['fileTotals'] = $fileTotals; |
|
| 113 | + $fileTotals['size'] = $this->getReadableFileSize($fileTotals['size']); |
|
| 114 | + $fileTotals['largest'] = $this->getReadableFileSize($fileTotals['largest']); |
|
| 115 | + $this->output['files'] = $fileList; |
|
| 116 | + $this->output['fileTotals'] = $fileTotals; |
|
| 117 | 117 | } |
| 118 | 118 | |
| 119 | 119 | /*------------------------------------------- |
@@ -121,10 +121,10 @@ discard block |
||
| 121 | 121 | -------------------------------------------*/ |
| 122 | 122 | |
| 123 | 123 | public function gatherMemoryData() { |
| 124 | - $memoryTotals = array(); |
|
| 125 | - $memoryTotals['used'] = $this->getReadableFileSize(memory_get_peak_usage()); |
|
| 126 | - $memoryTotals['total'] = ini_get("memory_limit"); |
|
| 127 | - $this->output['memoryTotals'] = $memoryTotals; |
|
| 124 | + $memoryTotals = array(); |
|
| 125 | + $memoryTotals['used'] = $this->getReadableFileSize(memory_get_peak_usage()); |
|
| 126 | + $memoryTotals['total'] = ini_get("memory_limit"); |
|
| 127 | + $this->output['memoryTotals'] = $memoryTotals; |
|
| 128 | 128 | } |
| 129 | 129 | |
| 130 | 130 | /*-------------------------------------------------------- |
@@ -132,24 +132,24 @@ discard block |
||
| 132 | 132 | ----------------------------------------------------------*/ |
| 133 | 133 | |
| 134 | 134 | public function gatherQueryData() { |
| 135 | - $queryTotals = array(); |
|
| 136 | - $queryTotals['count'] = 0; |
|
| 137 | - $queryTotals['time'] = 0; |
|
| 138 | - $queries = array(); |
|
| 135 | + $queryTotals = array(); |
|
| 136 | + $queryTotals['count'] = 0; |
|
| 137 | + $queryTotals['time'] = 0; |
|
| 138 | + $queries = array(); |
|
| 139 | 139 | |
| 140 | - if($this->db != '') { |
|
| 141 | - $queryTotals['count'] += $this->db->queryCount; |
|
| 142 | - foreach($this->db->queries as $key => $query) { |
|
| 143 | - $query = $this->attemptToExplainQuery($query); |
|
| 144 | - $queryTotals['time'] += $query['time']; |
|
| 145 | - $query['time'] = $this->getReadableTime($query['time']); |
|
| 146 | - $queries[] = $query; |
|
| 147 | - } |
|
| 148 | - } |
|
| 140 | + if($this->db != '') { |
|
| 141 | + $queryTotals['count'] += $this->db->queryCount; |
|
| 142 | + foreach($this->db->queries as $key => $query) { |
|
| 143 | + $query = $this->attemptToExplainQuery($query); |
|
| 144 | + $queryTotals['time'] += $query['time']; |
|
| 145 | + $query['time'] = $this->getReadableTime($query['time']); |
|
| 146 | + $queries[] = $query; |
|
| 147 | + } |
|
| 148 | + } |
|
| 149 | 149 | |
| 150 | - $queryTotals['time'] = $this->getReadableTime($queryTotals['time']); |
|
| 151 | - $this->output['queries'] = $queries; |
|
| 152 | - $this->output['queryTotals'] = $queryTotals; |
|
| 150 | + $queryTotals['time'] = $this->getReadableTime($queryTotals['time']); |
|
| 151 | + $this->output['queries'] = $queries; |
|
| 152 | + $this->output['queryTotals'] = $queryTotals; |
|
| 153 | 153 | } |
| 154 | 154 | |
| 155 | 155 | /*-------------------------------------------------------- |
@@ -157,16 +157,16 @@ discard block |
||
| 157 | 157 | ----------------------------------------------------------*/ |
| 158 | 158 | |
| 159 | 159 | function attemptToExplainQuery($query) { |
| 160 | - try { |
|
| 161 | - $sql = 'EXPLAIN '.$query['sql']; |
|
| 162 | - $rs = $this->db->query($sql); |
|
| 163 | - } |
|
| 164 | - catch(Exception $e) {} |
|
| 165 | - if($rs) { |
|
| 166 | - $row = mysql_fetch_array($rs, MYSQL_ASSOC); |
|
| 167 | - $query['explain'] = $row; |
|
| 168 | - } |
|
| 169 | - return $query; |
|
| 160 | + try { |
|
| 161 | + $sql = 'EXPLAIN '.$query['sql']; |
|
| 162 | + $rs = $this->db->query($sql); |
|
| 163 | + } |
|
| 164 | + catch(Exception $e) {} |
|
| 165 | + if($rs) { |
|
| 166 | + $row = mysql_fetch_array($rs, MYSQL_ASSOC); |
|
| 167 | + $query['explain'] = $row; |
|
| 168 | + } |
|
| 169 | + return $query; |
|
| 170 | 170 | } |
| 171 | 171 | |
| 172 | 172 | /*------------------------------------------- |
@@ -174,10 +174,10 @@ discard block |
||
| 174 | 174 | -------------------------------------------*/ |
| 175 | 175 | |
| 176 | 176 | public function gatherSpeedData() { |
| 177 | - $speedTotals = array(); |
|
| 178 | - $speedTotals['total'] = $this->getReadableTime((microtime(true) - $this->startTime)*1000); |
|
| 179 | - $speedTotals['allowed'] = ini_get("max_execution_time"); |
|
| 180 | - $this->output['speedTotals'] = $speedTotals; |
|
| 177 | + $speedTotals = array(); |
|
| 178 | + $speedTotals['total'] = $this->getReadableTime((microtime(true) - $this->startTime)*1000); |
|
| 179 | + $speedTotals['allowed'] = ini_get("max_execution_time"); |
|
| 180 | + $this->output['speedTotals'] = $speedTotals; |
|
| 181 | 181 | } |
| 182 | 182 | |
| 183 | 183 | /*------------------------------------------- |
@@ -185,35 +185,35 @@ discard block |
||
| 185 | 185 | -------------------------------------------*/ |
| 186 | 186 | |
| 187 | 187 | public function getReadableFileSize($size, $retstring = null) { |
| 188 | - // adapted from code at http://aidanlister.com/repos/v/function.size_readable.php |
|
| 189 | - $sizes = array('bytes', 'kB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB'); |
|
| 188 | + // adapted from code at http://aidanlister.com/repos/v/function.size_readable.php |
|
| 189 | + $sizes = array('bytes', 'kB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB'); |
|
| 190 | 190 | |
| 191 | - if ($retstring === null) { $retstring = '%01.2f %s'; } |
|
| 191 | + if ($retstring === null) { $retstring = '%01.2f %s'; } |
|
| 192 | 192 | |
| 193 | - $lastsizestring = end($sizes); |
|
| 193 | + $lastsizestring = end($sizes); |
|
| 194 | 194 | |
| 195 | - foreach ($sizes as $sizestring) { |
|
| 196 | - if ($size < 1024) { break; } |
|
| 197 | - if ($sizestring != $lastsizestring) { $size /= 1024; } |
|
| 198 | - } |
|
| 199 | - if ($sizestring == $sizes[0]) { $retstring = '%01d %s'; } // Bytes aren't normally fractional |
|
| 200 | - return sprintf($retstring, $size, $sizestring); |
|
| 195 | + foreach ($sizes as $sizestring) { |
|
| 196 | + if ($size < 1024) { break; } |
|
| 197 | + if ($sizestring != $lastsizestring) { $size /= 1024; } |
|
| 198 | + } |
|
| 199 | + if ($sizestring == $sizes[0]) { $retstring = '%01d %s'; } // Bytes aren't normally fractional |
|
| 200 | + return sprintf($retstring, $size, $sizestring); |
|
| 201 | 201 | } |
| 202 | 202 | |
| 203 | 203 | public function getReadableTime($time) { |
| 204 | - $ret = $time; |
|
| 205 | - $formatter = 0; |
|
| 206 | - $formats = array('ms', 's', 'm'); |
|
| 207 | - if($time >= 1000 && $time < 60000) { |
|
| 208 | - $formatter = 1; |
|
| 209 | - $ret = ($time / 1000); |
|
| 210 | - } |
|
| 211 | - if($time >= 60000) { |
|
| 212 | - $formatter = 2; |
|
| 213 | - $ret = ($time / 1000) / 60; |
|
| 214 | - } |
|
| 215 | - $ret = number_format($ret,3,'.','') . ' ' . $formats[$formatter]; |
|
| 216 | - return $ret; |
|
| 204 | + $ret = $time; |
|
| 205 | + $formatter = 0; |
|
| 206 | + $formats = array('ms', 's', 'm'); |
|
| 207 | + if($time >= 1000 && $time < 60000) { |
|
| 208 | + $formatter = 1; |
|
| 209 | + $ret = ($time / 1000); |
|
| 210 | + } |
|
| 211 | + if($time >= 60000) { |
|
| 212 | + $formatter = 2; |
|
| 213 | + $ret = ($time / 1000) / 60; |
|
| 214 | + } |
|
| 215 | + $ret = number_format($ret,3,'.','') . ' ' . $formats[$formatter]; |
|
| 216 | + return $ret; |
|
| 217 | 217 | } |
| 218 | 218 | |
| 219 | 219 | /*--------------------------------------------------------- |
@@ -221,14 +221,14 @@ discard block |
||
| 221 | 221 | -----------------------------------------------------------*/ |
| 222 | 222 | |
| 223 | 223 | public function display($db = '', $master_db = '') { |
| 224 | - $this->db = $db; |
|
| 225 | - $this->master_db = $master_db; |
|
| 226 | - $this->gatherConsoleData(); |
|
| 227 | - $this->gatherFileData(); |
|
| 228 | - $this->gatherMemoryData(); |
|
| 229 | - $this->gatherQueryData(); |
|
| 230 | - $this->gatherSpeedData(); |
|
| 231 | - require_once __DIR__ . '/../display.php'; |
|
| 232 | - displayPqp($this->output); |
|
| 224 | + $this->db = $db; |
|
| 225 | + $this->master_db = $master_db; |
|
| 226 | + $this->gatherConsoleData(); |
|
| 227 | + $this->gatherFileData(); |
|
| 228 | + $this->gatherMemoryData(); |
|
| 229 | + $this->gatherQueryData(); |
|
| 230 | + $this->gatherSpeedData(); |
|
| 231 | + require_once __DIR__ . '/../display.php'; |
|
| 232 | + displayPqp($this->output); |
|
| 233 | 233 | } |
| 234 | 234 | } |
@@ -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 | } |