@@ -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 | } |
@@ -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 | } |
@@ -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 | } |
@@ -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 = ''; |
@@ -14,42 +14,42 @@ |
||
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 setConsoleData(array $console_data) |
|
25 | - { |
|
26 | - $this->output['console'] = $console_data; |
|
27 | - } |
|
28 | - |
|
29 | - public function setFileData(array $file_data) |
|
30 | - { |
|
31 | - $this->output['files'] = $file_data['files']; |
|
32 | - $this->output['fileTotals'] = $file_data['fileTotals']; |
|
33 | - } |
|
34 | - |
|
35 | - public function setMemoryData(array $memory_data) |
|
36 | - { |
|
37 | - $this->output['memoryTotals'] = $memory_data; |
|
38 | - } |
|
39 | - |
|
40 | - public function setQueryData(array $query_data) |
|
41 | - { |
|
42 | - // the void |
|
43 | - } |
|
44 | - |
|
45 | - public function setSpeedData(array $speed_data) |
|
46 | - { |
|
47 | - $this->output['speedTotals'] = $speed_data; |
|
48 | - } |
|
49 | - |
|
50 | - public function __invoke() |
|
51 | - { |
|
52 | - $output = $this->output; |
|
53 | - require_once __DIR__ .'/../asset/display.tpl.php'; |
|
54 | - } |
|
17 | + /** @var array */ |
|
18 | + protected $output; |
|
19 | + |
|
20 | + public function __construct() |
|
21 | + { |
|
22 | + } |
|
23 | + |
|
24 | + public function setConsoleData(array $console_data) |
|
25 | + { |
|
26 | + $this->output['console'] = $console_data; |
|
27 | + } |
|
28 | + |
|
29 | + public function setFileData(array $file_data) |
|
30 | + { |
|
31 | + $this->output['files'] = $file_data['files']; |
|
32 | + $this->output['fileTotals'] = $file_data['fileTotals']; |
|
33 | + } |
|
34 | + |
|
35 | + public function setMemoryData(array $memory_data) |
|
36 | + { |
|
37 | + $this->output['memoryTotals'] = $memory_data; |
|
38 | + } |
|
39 | + |
|
40 | + public function setQueryData(array $query_data) |
|
41 | + { |
|
42 | + // the void |
|
43 | + } |
|
44 | + |
|
45 | + public function setSpeedData(array $speed_data) |
|
46 | + { |
|
47 | + $this->output['speedTotals'] = $speed_data; |
|
48 | + } |
|
49 | + |
|
50 | + public function __invoke() |
|
51 | + { |
|
52 | + $output = $this->output; |
|
53 | + require_once __DIR__ .'/../asset/display.tpl.php'; |
|
54 | + } |
|
55 | 55 | } |
@@ -15,124 +15,124 @@ 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']); |
|
129 | + $fileTotals['size'] = $this->getReadableFileSize($fileTotals['size']); |
|
130 | + $fileTotals['largest'] = $this->getReadableFileSize($fileTotals['largest']); |
|
131 | 131 | |
132 | - return array( |
|
133 | - 'files' => $fileList, |
|
134 | - 'fileTotals' => $fileTotals |
|
135 | - ); |
|
132 | + return array( |
|
133 | + 'files' => $fileList, |
|
134 | + 'fileTotals' => $fileTotals |
|
135 | + ); |
|
136 | 136 | } |
137 | 137 | |
138 | 138 | /*------------------------------------------- |
@@ -140,10 +140,10 @@ discard block |
||
140 | 140 | -------------------------------------------*/ |
141 | 141 | |
142 | 142 | public function gatherMemoryData() { |
143 | - $memoryTotals = array(); |
|
144 | - $memoryTotals['used'] = $this->getReadableFileSize(memory_get_peak_usage()); |
|
145 | - $memoryTotals['total'] = ini_get("memory_limit"); |
|
146 | - return $memoryTotals; |
|
143 | + $memoryTotals = array(); |
|
144 | + $memoryTotals['used'] = $this->getReadableFileSize(memory_get_peak_usage()); |
|
145 | + $memoryTotals['total'] = ini_get("memory_limit"); |
|
146 | + return $memoryTotals; |
|
147 | 147 | } |
148 | 148 | |
149 | 149 | /*-------------------------------------------------------- |
@@ -151,24 +151,24 @@ discard block |
||
151 | 151 | ----------------------------------------------------------*/ |
152 | 152 | |
153 | 153 | public function gatherQueryData() { |
154 | - $queryTotals = array(); |
|
155 | - $queryTotals['count'] = 0; |
|
156 | - $queryTotals['time'] = 0; |
|
157 | - $queries = array(); |
|
154 | + $queryTotals = array(); |
|
155 | + $queryTotals['count'] = 0; |
|
156 | + $queryTotals['time'] = 0; |
|
157 | + $queries = array(); |
|
158 | 158 | |
159 | - if($this->db != '') { |
|
160 | - $queryTotals['count'] += $this->db->queryCount; |
|
161 | - foreach($this->db->queries as $query) { |
|
162 | - $query = $this->attemptToExplainQuery($query); |
|
163 | - $queryTotals['time'] += $query['time']; |
|
164 | - $query['time'] = $this->getReadableTime($query['time']); |
|
165 | - $queries[] = $query; |
|
166 | - } |
|
167 | - } |
|
159 | + if($this->db != '') { |
|
160 | + $queryTotals['count'] += $this->db->queryCount; |
|
161 | + foreach($this->db->queries as $query) { |
|
162 | + $query = $this->attemptToExplainQuery($query); |
|
163 | + $queryTotals['time'] += $query['time']; |
|
164 | + $query['time'] = $this->getReadableTime($query['time']); |
|
165 | + $queries[] = $query; |
|
166 | + } |
|
167 | + } |
|
168 | 168 | |
169 | - $queryTotals['time'] = $this->getReadableTime($queryTotals['time']); |
|
170 | - $this->output['queries'] = $queries; |
|
171 | - $this->output['queryTotals'] = $queryTotals; |
|
169 | + $queryTotals['time'] = $this->getReadableTime($queryTotals['time']); |
|
170 | + $this->output['queries'] = $queries; |
|
171 | + $this->output['queryTotals'] = $queryTotals; |
|
172 | 172 | } |
173 | 173 | |
174 | 174 | /*-------------------------------------------------------- |
@@ -176,16 +176,16 @@ discard block |
||
176 | 176 | ----------------------------------------------------------*/ |
177 | 177 | |
178 | 178 | function attemptToExplainQuery($query) { |
179 | - try { |
|
180 | - $sql = 'EXPLAIN '.$query['sql']; |
|
181 | - $rs = $this->db->query($sql); |
|
182 | - } |
|
183 | - catch(Exception $e) {} |
|
184 | - if($rs) { |
|
185 | - $row = mysql_fetch_array($rs, MYSQL_ASSOC); |
|
186 | - $query['explain'] = $row; |
|
187 | - } |
|
188 | - return $query; |
|
179 | + try { |
|
180 | + $sql = 'EXPLAIN '.$query['sql']; |
|
181 | + $rs = $this->db->query($sql); |
|
182 | + } |
|
183 | + catch(Exception $e) {} |
|
184 | + if($rs) { |
|
185 | + $row = mysql_fetch_array($rs, MYSQL_ASSOC); |
|
186 | + $query['explain'] = $row; |
|
187 | + } |
|
188 | + return $query; |
|
189 | 189 | } |
190 | 190 | |
191 | 191 | /*------------------------------------------- |
@@ -193,10 +193,10 @@ discard block |
||
193 | 193 | -------------------------------------------*/ |
194 | 194 | |
195 | 195 | public function gatherSpeedData() { |
196 | - $speedTotals = array(); |
|
197 | - $speedTotals['total'] = self::getReadableTime((microtime(true) - $this->startTime)); |
|
198 | - $speedTotals['allowed'] = ini_get("max_execution_time"); |
|
199 | - return $speedTotals; |
|
196 | + $speedTotals = array(); |
|
197 | + $speedTotals['total'] = self::getReadableTime((microtime(true) - $this->startTime)); |
|
198 | + $speedTotals['allowed'] = ini_get("max_execution_time"); |
|
199 | + return $speedTotals; |
|
200 | 200 | } |
201 | 201 | |
202 | 202 | /*------------------------------------------- |
@@ -204,58 +204,58 @@ discard block |
||
204 | 204 | -------------------------------------------*/ |
205 | 205 | |
206 | 206 | public function getReadableFileSize($size, $retstring = null) { |
207 | - // adapted from code at http://aidanlister.com/repos/v/function.size_readable.php |
|
208 | - $sizes = array('bytes', 'kB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB'); |
|
207 | + // adapted from code at http://aidanlister.com/repos/v/function.size_readable.php |
|
208 | + $sizes = array('bytes', 'kB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB'); |
|
209 | 209 | |
210 | - if ($retstring === null) { $retstring = '%01.2f %s'; } |
|
210 | + if ($retstring === null) { $retstring = '%01.2f %s'; } |
|
211 | 211 | |
212 | - $lastsizestring = end($sizes); |
|
212 | + $lastsizestring = end($sizes); |
|
213 | 213 | |
214 | - foreach ($sizes as $sizestring) { |
|
215 | - if ($size < 1024) { break; } |
|
216 | - if ($sizestring != $lastsizestring) { $size /= 1024; } |
|
217 | - } |
|
218 | - if ($sizestring == $sizes[0]) { $retstring = '%01d %s'; } // Bytes aren't normally fractional |
|
219 | - return sprintf($retstring, $size, $sizestring); |
|
214 | + foreach ($sizes as $sizestring) { |
|
215 | + if ($size < 1024) { break; } |
|
216 | + if ($sizestring != $lastsizestring) { $size /= 1024; } |
|
217 | + } |
|
218 | + if ($sizestring == $sizes[0]) { $retstring = '%01d %s'; } // Bytes aren't normally fractional |
|
219 | + return sprintf($retstring, $size, $sizestring); |
|
220 | 220 | } |
221 | 221 | |
222 | - /** |
|
223 | - * Static formatter for human-readable time |
|
224 | - * Only handles time up to 60 minutes gracefully |
|
225 | - * |
|
226 | - * @param integer $time time in seconds |
|
227 | - * @return string |
|
228 | - */ |
|
229 | - public static function getReadableTime($time) |
|
230 | - { |
|
231 | - $unit = 's'; |
|
222 | + /** |
|
223 | + * Static formatter for human-readable time |
|
224 | + * Only handles time up to 60 minutes gracefully |
|
225 | + * |
|
226 | + * @param integer $time time in seconds |
|
227 | + * @return string |
|
228 | + */ |
|
229 | + public static function getReadableTime($time) |
|
230 | + { |
|
231 | + $unit = 's'; |
|
232 | 232 | |
233 | - if ($time < 1) { |
|
234 | - $time *= 1000; |
|
235 | - $unit = 'ms'; |
|
236 | - } else if ($time > 60) { |
|
237 | - $time /= 60; |
|
238 | - $unit = 'm'; |
|
239 | - } |
|
233 | + if ($time < 1) { |
|
234 | + $time *= 1000; |
|
235 | + $unit = 'ms'; |
|
236 | + } else if ($time > 60) { |
|
237 | + $time /= 60; |
|
238 | + $unit = 'm'; |
|
239 | + } |
|
240 | 240 | |
241 | - $time = number_format($time, 3); |
|
242 | - return "{$time} {$unit}"; |
|
243 | - } |
|
241 | + $time = number_format($time, 3); |
|
242 | + return "{$time} {$unit}"; |
|
243 | + } |
|
244 | 244 | |
245 | 245 | |
246 | - /** |
|
247 | - * Triggers end display of the profiling data |
|
248 | - * |
|
249 | - * @param Display $display |
|
250 | - */ |
|
251 | - public function display(Display $display) |
|
252 | - { |
|
253 | - $display->setConsoleData($this->gatherConsoleData()); |
|
254 | - $display->setFileData($this->gatherFileData()); |
|
255 | - $display->setMemoryData($this->gatherMemoryData()); |
|
256 | - $display->setQueryData($this->gatherQueryData()); |
|
257 | - $display->setSpeedData($this->gatherSpeedData()); |
|
246 | + /** |
|
247 | + * Triggers end display of the profiling data |
|
248 | + * |
|
249 | + * @param Display $display |
|
250 | + */ |
|
251 | + public function display(Display $display) |
|
252 | + { |
|
253 | + $display->setConsoleData($this->gatherConsoleData()); |
|
254 | + $display->setFileData($this->gatherFileData()); |
|
255 | + $display->setMemoryData($this->gatherMemoryData()); |
|
256 | + $display->setQueryData($this->gatherQueryData()); |
|
257 | + $display->setSpeedData($this->gatherSpeedData()); |
|
258 | 258 | |
259 | - $display(); |
|
260 | - } |
|
259 | + $display(); |
|
260 | + } |
|
261 | 261 | } |