@@ -5,29 +5,29 @@ |
||
5 | 5 | class DisplayTest extends PHPUnit_Framework_TestCase |
6 | 6 | { |
7 | 7 | |
8 | - public function testGetReadableTime() |
|
9 | - { |
|
10 | - $test_input = array( |
|
11 | - '.032432' => '32.432 ms', |
|
12 | - '24.3781' => '24.378 s', |
|
13 | - '145.123' => '2.419 m' |
|
14 | - ); |
|
8 | + public function testGetReadableTime() |
|
9 | + { |
|
10 | + $test_input = array( |
|
11 | + '.032432' => '32.432 ms', |
|
12 | + '24.3781' => '24.378 s', |
|
13 | + '145.123' => '2.419 m' |
|
14 | + ); |
|
15 | 15 | |
16 | - foreach ($test_input as $input => $expected_return) { |
|
17 | - $this->assertEquals($expected_return, Display::getReadableTime($input)); |
|
18 | - } |
|
19 | - } |
|
16 | + foreach ($test_input as $input => $expected_return) { |
|
17 | + $this->assertEquals($expected_return, Display::getReadableTime($input)); |
|
18 | + } |
|
19 | + } |
|
20 | 20 | |
21 | - public function testGetReadableMemory() |
|
22 | - { |
|
23 | - $test_input = array( |
|
24 | - '314' => '314 b', |
|
25 | - '7403' => '7.23 k', |
|
26 | - '2589983' => '2.47 M' |
|
27 | - ); |
|
21 | + public function testGetReadableMemory() |
|
22 | + { |
|
23 | + $test_input = array( |
|
24 | + '314' => '314 b', |
|
25 | + '7403' => '7.23 k', |
|
26 | + '2589983' => '2.47 M' |
|
27 | + ); |
|
28 | 28 | |
29 | - foreach ($test_input as $input => $expected_return) { |
|
30 | - $this->assertEquals($expected_return, Display::getReadableMemory($input)); |
|
31 | - } |
|
32 | - } |
|
29 | + foreach ($test_input as $input => $expected_return) { |
|
30 | + $this->assertEquals($expected_return, Display::getReadableMemory($input)); |
|
31 | + } |
|
32 | + } |
|
33 | 33 | } |
@@ -14,154 +14,154 @@ |
||
14 | 14 | class Display |
15 | 15 | { |
16 | 16 | |
17 | - /** @var array */ |
|
18 | - protected $output; |
|
17 | + /** @var array */ |
|
18 | + protected $output; |
|
19 | 19 | |
20 | - public function __construct() |
|
21 | - { |
|
22 | - } |
|
20 | + public function __construct() |
|
21 | + { |
|
22 | + } |
|
23 | 23 | |
24 | - public function setConsole(Console $console) |
|
25 | - { |
|
26 | - $console_data = array( |
|
27 | - 'messages' => array(), |
|
28 | - 'count' => array( |
|
29 | - 'log' => 0, |
|
30 | - 'memory' => 0, |
|
31 | - 'error' => 0, |
|
32 | - 'speed' => 0 |
|
33 | - ) |
|
34 | - ); |
|
35 | - foreach ($console->getLogs() as $log) { |
|
36 | - switch($log['type']) { |
|
37 | - case 'log': |
|
38 | - $message = array( |
|
39 | - 'data' => print_r($log['data'], true), |
|
40 | - 'type' => 'log' |
|
41 | - ); |
|
42 | - $console_data['count']['log']++; |
|
43 | - break; |
|
44 | - case 'memory': |
|
45 | - $message = array( |
|
46 | - 'name' => $log['name'], |
|
47 | - 'data' => self::getReadableMemory($log['data']), |
|
48 | - 'type' => 'memory' |
|
49 | - ); |
|
50 | - if (!empty($log['data_type'])) { |
|
51 | - $message['data_type'] = $log['data_type']; |
|
52 | - } |
|
53 | - $console_data['count']['memory']++; |
|
54 | - break; |
|
55 | - case 'error': |
|
56 | - $message = array( |
|
57 | - 'data' => $log['data'], |
|
58 | - 'file' => $log['file'], |
|
59 | - 'line' => $log['line'], |
|
60 | - 'type' => 'error' |
|
61 | - ); |
|
62 | - $console_data['count']['error']++; |
|
63 | - break; |
|
64 | - case 'speed': |
|
65 | - $elapsedTime = $log['data'] - $this->startTime; |
|
66 | - $message = array( |
|
67 | - 'name' => $log['name'], |
|
68 | - 'data' => self::getReadableTime($elapsedTime), |
|
69 | - 'type' => 'speed' |
|
70 | - ); |
|
71 | - $console_data['count']['speed']++; |
|
72 | - break; |
|
73 | - default: |
|
74 | - $message = array( |
|
75 | - 'data' => "Unrecognized console log type: {$log['type']}", |
|
76 | - 'type' => 'error' |
|
77 | - ); |
|
78 | - $console_data['count']['error']++; |
|
79 | - break; |
|
80 | - } |
|
81 | - array_push($console_data['messages'], $message); |
|
82 | - } |
|
83 | - $this->output['console'] = $console_data; |
|
84 | - } |
|
24 | + public function setConsole(Console $console) |
|
25 | + { |
|
26 | + $console_data = array( |
|
27 | + 'messages' => array(), |
|
28 | + 'count' => array( |
|
29 | + 'log' => 0, |
|
30 | + 'memory' => 0, |
|
31 | + 'error' => 0, |
|
32 | + 'speed' => 0 |
|
33 | + ) |
|
34 | + ); |
|
35 | + foreach ($console->getLogs() as $log) { |
|
36 | + switch($log['type']) { |
|
37 | + case 'log': |
|
38 | + $message = array( |
|
39 | + 'data' => print_r($log['data'], true), |
|
40 | + 'type' => 'log' |
|
41 | + ); |
|
42 | + $console_data['count']['log']++; |
|
43 | + break; |
|
44 | + case 'memory': |
|
45 | + $message = array( |
|
46 | + 'name' => $log['name'], |
|
47 | + 'data' => self::getReadableMemory($log['data']), |
|
48 | + 'type' => 'memory' |
|
49 | + ); |
|
50 | + if (!empty($log['data_type'])) { |
|
51 | + $message['data_type'] = $log['data_type']; |
|
52 | + } |
|
53 | + $console_data['count']['memory']++; |
|
54 | + break; |
|
55 | + case 'error': |
|
56 | + $message = array( |
|
57 | + 'data' => $log['data'], |
|
58 | + 'file' => $log['file'], |
|
59 | + 'line' => $log['line'], |
|
60 | + 'type' => 'error' |
|
61 | + ); |
|
62 | + $console_data['count']['error']++; |
|
63 | + break; |
|
64 | + case 'speed': |
|
65 | + $elapsedTime = $log['data'] - $this->startTime; |
|
66 | + $message = array( |
|
67 | + 'name' => $log['name'], |
|
68 | + 'data' => self::getReadableTime($elapsedTime), |
|
69 | + 'type' => 'speed' |
|
70 | + ); |
|
71 | + $console_data['count']['speed']++; |
|
72 | + break; |
|
73 | + default: |
|
74 | + $message = array( |
|
75 | + 'data' => "Unrecognized console log type: {$log['type']}", |
|
76 | + 'type' => 'error' |
|
77 | + ); |
|
78 | + $console_data['count']['error']++; |
|
79 | + break; |
|
80 | + } |
|
81 | + array_push($console_data['messages'], $message); |
|
82 | + } |
|
83 | + $this->output['console'] = $console_data; |
|
84 | + } |
|
85 | 85 | |
86 | - public function setFileData(array $file_data) |
|
87 | - { |
|
88 | - $this->output['files'] = $file_data['files']; |
|
89 | - $this->output['fileTotals'] = $file_data['fileTotals']; |
|
90 | - } |
|
86 | + public function setFileData(array $file_data) |
|
87 | + { |
|
88 | + $this->output['files'] = $file_data['files']; |
|
89 | + $this->output['fileTotals'] = $file_data['fileTotals']; |
|
90 | + } |
|
91 | 91 | |
92 | - /** |
|
93 | - * Sets memory data |
|
94 | - * |
|
95 | - * @param array $data |
|
96 | - */ |
|
97 | - public function setMemoryData(array $data) |
|
98 | - { |
|
99 | - $this->output['memory'] = array( |
|
100 | - 'used' => self::getReadableMemory($data['used']), |
|
101 | - 'allowed' => $data['allowed'] |
|
102 | - ); |
|
103 | - } |
|
92 | + /** |
|
93 | + * Sets memory data |
|
94 | + * |
|
95 | + * @param array $data |
|
96 | + */ |
|
97 | + public function setMemoryData(array $data) |
|
98 | + { |
|
99 | + $this->output['memory'] = array( |
|
100 | + 'used' => self::getReadableMemory($data['used']), |
|
101 | + 'allowed' => $data['allowed'] |
|
102 | + ); |
|
103 | + } |
|
104 | 104 | |
105 | - public function setQueryData(array $query_data) |
|
106 | - { |
|
107 | - // the void |
|
108 | - } |
|
105 | + public function setQueryData(array $query_data) |
|
106 | + { |
|
107 | + // the void |
|
108 | + } |
|
109 | 109 | |
110 | - /** |
|
111 | - * Sets speed data |
|
112 | - * |
|
113 | - * @param array $data |
|
114 | - */ |
|
115 | - public function setSpeedData(array $data) |
|
116 | - { |
|
117 | - $this->output['speed'] = array( |
|
118 | - 'elapsed' => self::getReadableTime($data['elapsed']), |
|
119 | - 'allowed' => self::getReadableTime($data['allowed'], 0) |
|
120 | - ); |
|
121 | - } |
|
110 | + /** |
|
111 | + * Sets speed data |
|
112 | + * |
|
113 | + * @param array $data |
|
114 | + */ |
|
115 | + public function setSpeedData(array $data) |
|
116 | + { |
|
117 | + $this->output['speed'] = array( |
|
118 | + 'elapsed' => self::getReadableTime($data['elapsed']), |
|
119 | + 'allowed' => self::getReadableTime($data['allowed'], 0) |
|
120 | + ); |
|
121 | + } |
|
122 | 122 | |
123 | - /** |
|
124 | - * Static formatter for human-readable time |
|
125 | - * Only handles time up to 60 minutes gracefully |
|
126 | - * |
|
127 | - * @param double $time |
|
128 | - * @param integer $decimals |
|
129 | - * @return string |
|
130 | - */ |
|
131 | - public static function getReadableTime($time, $decimals = 3) |
|
132 | - { |
|
133 | - $unit = 's'; |
|
134 | - if ($time < 1) { |
|
135 | - $time *= 1000; |
|
136 | - $unit = 'ms'; |
|
137 | - } else if ($time > 60) { |
|
138 | - $time /= 60; |
|
139 | - $unit = 'm'; |
|
140 | - } |
|
141 | - $time = number_format($time, $decimals); |
|
142 | - return "{$time} {$unit}"; |
|
143 | - } |
|
123 | + /** |
|
124 | + * Static formatter for human-readable time |
|
125 | + * Only handles time up to 60 minutes gracefully |
|
126 | + * |
|
127 | + * @param double $time |
|
128 | + * @param integer $decimals |
|
129 | + * @return string |
|
130 | + */ |
|
131 | + public static function getReadableTime($time, $decimals = 3) |
|
132 | + { |
|
133 | + $unit = 's'; |
|
134 | + if ($time < 1) { |
|
135 | + $time *= 1000; |
|
136 | + $unit = 'ms'; |
|
137 | + } else if ($time > 60) { |
|
138 | + $time /= 60; |
|
139 | + $unit = 'm'; |
|
140 | + } |
|
141 | + $time = number_format($time, $decimals); |
|
142 | + return "{$time} {$unit}"; |
|
143 | + } |
|
144 | 144 | |
145 | - /** |
|
146 | - * Static formatter for human-readable memory |
|
147 | - * |
|
148 | - * @param double $size |
|
149 | - * @param integer $decimals |
|
150 | - */ |
|
151 | - public static function getReadableMemory($size, $decimals = 2) |
|
152 | - { |
|
153 | - $unitOptions = array('b', 'k', 'M', 'G'); |
|
145 | + /** |
|
146 | + * Static formatter for human-readable memory |
|
147 | + * |
|
148 | + * @param double $size |
|
149 | + * @param integer $decimals |
|
150 | + */ |
|
151 | + public static function getReadableMemory($size, $decimals = 2) |
|
152 | + { |
|
153 | + $unitOptions = array('b', 'k', 'M', 'G'); |
|
154 | 154 | |
155 | - $base = log($size, 1024); |
|
155 | + $base = log($size, 1024); |
|
156 | 156 | |
157 | - $memory = round(pow(1024, $base - floor($base)), $decimals); |
|
158 | - $unit = $unitOptions[floor($base)]; |
|
159 | - return "{$memory} {$unit}"; |
|
160 | - } |
|
157 | + $memory = round(pow(1024, $base - floor($base)), $decimals); |
|
158 | + $unit = $unitOptions[floor($base)]; |
|
159 | + return "{$memory} {$unit}"; |
|
160 | + } |
|
161 | 161 | |
162 | - public function __invoke() |
|
163 | - { |
|
164 | - $output = $this->output; |
|
165 | - require_once __DIR__ .'/../asset/display.tpl.php'; |
|
166 | - } |
|
162 | + public function __invoke() |
|
163 | + { |
|
164 | + $output = $this->output; |
|
165 | + require_once __DIR__ .'/../asset/display.tpl.php'; |
|
166 | + } |
|
167 | 167 | } |
@@ -33,7 +33,7 @@ discard block |
||
33 | 33 | ) |
34 | 34 | ); |
35 | 35 | foreach ($console->getLogs() as $log) { |
36 | - switch($log['type']) { |
|
36 | + switch ($log['type']) { |
|
37 | 37 | case 'log': |
38 | 38 | $message = array( |
39 | 39 | 'data' => print_r($log['data'], true), |
@@ -162,6 +162,6 @@ discard block |
||
162 | 162 | public function __invoke() |
163 | 163 | { |
164 | 164 | $output = $this->output; |
165 | - require_once __DIR__ .'/../asset/display.tpl.php'; |
|
165 | + require_once __DIR__.'/../asset/display.tpl.php'; |
|
166 | 166 | } |
167 | 167 | } |
@@ -15,96 +15,96 @@ discard block |
||
15 | 15 | class PhpQuickProfiler |
16 | 16 | { |
17 | 17 | |
18 | - /** @var Particletree\Pqp\Console */ |
|
19 | - protected $console; |
|
20 | - |
|
21 | - /** @var integer */ |
|
22 | - protected $startTime; |
|
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; |
|
31 | - |
|
32 | - if (is_null($startTime)) { |
|
33 | - $startTime = microtime(true); |
|
34 | - } |
|
35 | - $this->startTime = $startTime; |
|
36 | - } |
|
18 | + /** @var Particletree\Pqp\Console */ |
|
19 | + protected $console; |
|
20 | + |
|
21 | + /** @var integer */ |
|
22 | + protected $startTime; |
|
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; |
|
31 | + |
|
32 | + if (is_null($startTime)) { |
|
33 | + $startTime = microtime(true); |
|
34 | + } |
|
35 | + $this->startTime = $startTime; |
|
36 | + } |
|
37 | 37 | |
38 | 38 | /*------------------------------------------- |
39 | 39 | AGGREGATE DATA ON THE FILES INCLUDED |
40 | 40 | -------------------------------------------*/ |
41 | 41 | |
42 | 42 | public function gatherFileData() { |
43 | - $files = get_included_files(); |
|
44 | - $fileList = array(); |
|
45 | - $fileTotals = array( |
|
46 | - "count" => count($files), |
|
47 | - "size" => 0, |
|
48 | - "largest" => 0, |
|
49 | - ); |
|
50 | - |
|
51 | - foreach($files as $file) { |
|
52 | - $size = filesize($file); |
|
53 | - $fileList[] = array( |
|
54 | - 'name' => $file, |
|
55 | - 'size' => $this->getReadableFileSize($size) |
|
56 | - ); |
|
57 | - $fileTotals['size'] += $size; |
|
58 | - if($size > $fileTotals['largest']) $fileTotals['largest'] = $size; |
|
59 | - } |
|
43 | + $files = get_included_files(); |
|
44 | + $fileList = array(); |
|
45 | + $fileTotals = array( |
|
46 | + "count" => count($files), |
|
47 | + "size" => 0, |
|
48 | + "largest" => 0, |
|
49 | + ); |
|
50 | + |
|
51 | + foreach($files as $file) { |
|
52 | + $size = filesize($file); |
|
53 | + $fileList[] = array( |
|
54 | + 'name' => $file, |
|
55 | + 'size' => $this->getReadableFileSize($size) |
|
56 | + ); |
|
57 | + $fileTotals['size'] += $size; |
|
58 | + if($size > $fileTotals['largest']) $fileTotals['largest'] = $size; |
|
59 | + } |
|
60 | 60 | |
61 | - $fileTotals['size'] = $this->getReadableFileSize($fileTotals['size']); |
|
62 | - $fileTotals['largest'] = $this->getReadableFileSize($fileTotals['largest']); |
|
61 | + $fileTotals['size'] = $this->getReadableFileSize($fileTotals['size']); |
|
62 | + $fileTotals['largest'] = $this->getReadableFileSize($fileTotals['largest']); |
|
63 | 63 | |
64 | - return array( |
|
65 | - 'files' => $fileList, |
|
66 | - 'fileTotals' => $fileTotals |
|
67 | - ); |
|
64 | + return array( |
|
65 | + 'files' => $fileList, |
|
66 | + 'fileTotals' => $fileTotals |
|
67 | + ); |
|
68 | 68 | } |
69 | 69 | |
70 | - /** |
|
71 | - * Get data about memory usage of the application |
|
72 | - * |
|
73 | - * @returns array |
|
74 | - */ |
|
75 | - public function gatherMemoryData() |
|
76 | - { |
|
77 | - $usedMemory = memory_get_peak_usage(); |
|
78 | - $allowedMemory = ini_get('memory_limit'); |
|
79 | - return array( |
|
80 | - 'used' => $usedMemory, |
|
81 | - 'allowed' => $allowedMemory |
|
82 | - ); |
|
83 | - } |
|
70 | + /** |
|
71 | + * Get data about memory usage of the application |
|
72 | + * |
|
73 | + * @returns array |
|
74 | + */ |
|
75 | + public function gatherMemoryData() |
|
76 | + { |
|
77 | + $usedMemory = memory_get_peak_usage(); |
|
78 | + $allowedMemory = ini_get('memory_limit'); |
|
79 | + return array( |
|
80 | + 'used' => $usedMemory, |
|
81 | + 'allowed' => $allowedMemory |
|
82 | + ); |
|
83 | + } |
|
84 | 84 | |
85 | 85 | /*-------------------------------------------------------- |
86 | 86 | QUERY DATA -- DATABASE OBJECT WITH LOGGING REQUIRED |
87 | 87 | ----------------------------------------------------------*/ |
88 | 88 | |
89 | 89 | public function gatherQueryData() { |
90 | - $queryTotals = array(); |
|
91 | - $queryTotals['count'] = 0; |
|
92 | - $queryTotals['time'] = 0; |
|
93 | - $queries = array(); |
|
90 | + $queryTotals = array(); |
|
91 | + $queryTotals['count'] = 0; |
|
92 | + $queryTotals['time'] = 0; |
|
93 | + $queries = array(); |
|
94 | 94 | |
95 | - if($this->db != '') { |
|
96 | - $queryTotals['count'] += $this->db->queryCount; |
|
97 | - foreach($this->db->queries as $query) { |
|
98 | - $query = $this->attemptToExplainQuery($query); |
|
99 | - $queryTotals['time'] += $query['time']; |
|
100 | - $query['time'] = $this->getReadableTime($query['time']); |
|
101 | - $queries[] = $query; |
|
102 | - } |
|
103 | - } |
|
95 | + if($this->db != '') { |
|
96 | + $queryTotals['count'] += $this->db->queryCount; |
|
97 | + foreach($this->db->queries as $query) { |
|
98 | + $query = $this->attemptToExplainQuery($query); |
|
99 | + $queryTotals['time'] += $query['time']; |
|
100 | + $query['time'] = $this->getReadableTime($query['time']); |
|
101 | + $queries[] = $query; |
|
102 | + } |
|
103 | + } |
|
104 | 104 | |
105 | - $queryTotals['time'] = $this->getReadableTime($queryTotals['time']); |
|
106 | - $this->output['queries'] = $queries; |
|
107 | - $this->output['queryTotals'] = $queryTotals; |
|
105 | + $queryTotals['time'] = $this->getReadableTime($queryTotals['time']); |
|
106 | + $this->output['queries'] = $queries; |
|
107 | + $this->output['queryTotals'] = $queryTotals; |
|
108 | 108 | } |
109 | 109 | |
110 | 110 | /*-------------------------------------------------------- |
@@ -112,90 +112,90 @@ discard block |
||
112 | 112 | ----------------------------------------------------------*/ |
113 | 113 | |
114 | 114 | function attemptToExplainQuery($query) { |
115 | - try { |
|
116 | - $sql = 'EXPLAIN '.$query['sql']; |
|
117 | - $rs = $this->db->query($sql); |
|
118 | - } |
|
119 | - catch(Exception $e) {} |
|
120 | - if($rs) { |
|
121 | - $row = mysql_fetch_array($rs, MYSQL_ASSOC); |
|
122 | - $query['explain'] = $row; |
|
123 | - } |
|
124 | - return $query; |
|
115 | + try { |
|
116 | + $sql = 'EXPLAIN '.$query['sql']; |
|
117 | + $rs = $this->db->query($sql); |
|
118 | + } |
|
119 | + catch(Exception $e) {} |
|
120 | + if($rs) { |
|
121 | + $row = mysql_fetch_array($rs, MYSQL_ASSOC); |
|
122 | + $query['explain'] = $row; |
|
123 | + } |
|
124 | + return $query; |
|
125 | 125 | } |
126 | 126 | |
127 | - /** |
|
128 | - * Get data about speed of the application |
|
129 | - * |
|
130 | - * @returns array |
|
131 | - */ |
|
132 | - public function gatherSpeedData() |
|
133 | - { |
|
134 | - $elapsedTime = microtime(true) - $this->startTime; |
|
135 | - $allowedTime = ini_get('max_execution_time'); |
|
136 | - return array( |
|
137 | - 'elapsed' => $elapsedTime, |
|
138 | - 'allowed' => $allowedTime |
|
139 | - ); |
|
140 | - } |
|
127 | + /** |
|
128 | + * Get data about speed of the application |
|
129 | + * |
|
130 | + * @returns array |
|
131 | + */ |
|
132 | + public function gatherSpeedData() |
|
133 | + { |
|
134 | + $elapsedTime = microtime(true) - $this->startTime; |
|
135 | + $allowedTime = ini_get('max_execution_time'); |
|
136 | + return array( |
|
137 | + 'elapsed' => $elapsedTime, |
|
138 | + 'allowed' => $allowedTime |
|
139 | + ); |
|
140 | + } |
|
141 | 141 | |
142 | 142 | /*------------------------------------------- |
143 | 143 | HELPER FUNCTIONS TO FORMAT DATA |
144 | 144 | -------------------------------------------*/ |
145 | 145 | |
146 | 146 | public function getReadableFileSize($size, $retstring = null) { |
147 | - // adapted from code at http://aidanlister.com/repos/v/function.size_readable.php |
|
148 | - $sizes = array('bytes', 'kB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB'); |
|
147 | + // adapted from code at http://aidanlister.com/repos/v/function.size_readable.php |
|
148 | + $sizes = array('bytes', 'kB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB'); |
|
149 | 149 | |
150 | - if ($retstring === null) { $retstring = '%01.2f %s'; } |
|
150 | + if ($retstring === null) { $retstring = '%01.2f %s'; } |
|
151 | 151 | |
152 | - $lastsizestring = end($sizes); |
|
152 | + $lastsizestring = end($sizes); |
|
153 | 153 | |
154 | - foreach ($sizes as $sizestring) { |
|
155 | - if ($size < 1024) { break; } |
|
156 | - if ($sizestring != $lastsizestring) { $size /= 1024; } |
|
157 | - } |
|
158 | - if ($sizestring == $sizes[0]) { $retstring = '%01d %s'; } // Bytes aren't normally fractional |
|
159 | - return sprintf($retstring, $size, $sizestring); |
|
154 | + foreach ($sizes as $sizestring) { |
|
155 | + if ($size < 1024) { break; } |
|
156 | + if ($sizestring != $lastsizestring) { $size /= 1024; } |
|
157 | + } |
|
158 | + if ($sizestring == $sizes[0]) { $retstring = '%01d %s'; } // Bytes aren't normally fractional |
|
159 | + return sprintf($retstring, $size, $sizestring); |
|
160 | 160 | } |
161 | 161 | |
162 | - /** |
|
163 | - * Static formatter for human-readable time |
|
164 | - * Only handles time up to 60 minutes gracefully |
|
165 | - * |
|
166 | - * @param integer $time time in seconds |
|
167 | - * @return string |
|
168 | - */ |
|
169 | - public static function getReadableTime($time) |
|
170 | - { |
|
171 | - $unit = 's'; |
|
172 | - |
|
173 | - if ($time < 1) { |
|
174 | - $time *= 1000; |
|
175 | - $unit = 'ms'; |
|
176 | - } else if ($time > 60) { |
|
177 | - $time /= 60; |
|
178 | - $unit = 'm'; |
|
179 | - } |
|
180 | - |
|
181 | - $time = number_format($time, 3); |
|
182 | - return "{$time} {$unit}"; |
|
183 | - } |
|
162 | + /** |
|
163 | + * Static formatter for human-readable time |
|
164 | + * Only handles time up to 60 minutes gracefully |
|
165 | + * |
|
166 | + * @param integer $time time in seconds |
|
167 | + * @return string |
|
168 | + */ |
|
169 | + public static function getReadableTime($time) |
|
170 | + { |
|
171 | + $unit = 's'; |
|
172 | + |
|
173 | + if ($time < 1) { |
|
174 | + $time *= 1000; |
|
175 | + $unit = 'ms'; |
|
176 | + } else if ($time > 60) { |
|
177 | + $time /= 60; |
|
178 | + $unit = 'm'; |
|
179 | + } |
|
180 | + |
|
181 | + $time = number_format($time, 3); |
|
182 | + return "{$time} {$unit}"; |
|
183 | + } |
|
184 | 184 | |
185 | 185 | |
186 | - /** |
|
187 | - * Triggers end display of the profiling data |
|
188 | - * |
|
189 | - * @param Display $display |
|
190 | - */ |
|
191 | - public function display(Display $display) |
|
192 | - { |
|
193 | - $display->setConsole($this->console); |
|
194 | - $display->setFileData($this->gatherFileData()); |
|
195 | - $display->setMemoryData($this->gatherMemoryData()); |
|
196 | - $display->setQueryData($this->gatherQueryData()); |
|
197 | - $display->setSpeedData($this->gatherSpeedData()); |
|
198 | - |
|
199 | - $display(); |
|
200 | - } |
|
186 | + /** |
|
187 | + * Triggers end display of the profiling data |
|
188 | + * |
|
189 | + * @param Display $display |
|
190 | + */ |
|
191 | + public function display(Display $display) |
|
192 | + { |
|
193 | + $display->setConsole($this->console); |
|
194 | + $display->setFileData($this->gatherFileData()); |
|
195 | + $display->setMemoryData($this->gatherMemoryData()); |
|
196 | + $display->setQueryData($this->gatherQueryData()); |
|
197 | + $display->setSpeedData($this->gatherSpeedData()); |
|
198 | + |
|
199 | + $display(); |
|
200 | + } |
|
201 | 201 | } |
@@ -48,14 +48,14 @@ discard block |
||
48 | 48 | "largest" => 0, |
49 | 49 | ); |
50 | 50 | |
51 | - foreach($files as $file) { |
|
51 | + foreach ($files as $file) { |
|
52 | 52 | $size = filesize($file); |
53 | 53 | $fileList[] = array( |
54 | 54 | 'name' => $file, |
55 | 55 | 'size' => $this->getReadableFileSize($size) |
56 | 56 | ); |
57 | 57 | $fileTotals['size'] += $size; |
58 | - if($size > $fileTotals['largest']) $fileTotals['largest'] = $size; |
|
58 | + if ($size > $fileTotals['largest']) $fileTotals['largest'] = $size; |
|
59 | 59 | } |
60 | 60 | |
61 | 61 | $fileTotals['size'] = $this->getReadableFileSize($fileTotals['size']); |
@@ -92,9 +92,9 @@ discard block |
||
92 | 92 | $queryTotals['time'] = 0; |
93 | 93 | $queries = array(); |
94 | 94 | |
95 | - if($this->db != '') { |
|
95 | + if ($this->db != '') { |
|
96 | 96 | $queryTotals['count'] += $this->db->queryCount; |
97 | - foreach($this->db->queries as $query) { |
|
97 | + foreach ($this->db->queries as $query) { |
|
98 | 98 | $query = $this->attemptToExplainQuery($query); |
99 | 99 | $queryTotals['time'] += $query['time']; |
100 | 100 | $query['time'] = $this->getReadableTime($query['time']); |
@@ -116,8 +116,8 @@ discard block |
||
116 | 116 | $sql = 'EXPLAIN '.$query['sql']; |
117 | 117 | $rs = $this->db->query($sql); |
118 | 118 | } |
119 | - catch(Exception $e) {} |
|
120 | - if($rs) { |
|
119 | + catch (Exception $e) {} |
|
120 | + if ($rs) { |
|
121 | 121 | $row = mysql_fetch_array($rs, MYSQL_ASSOC); |
122 | 122 | $query['explain'] = $row; |
123 | 123 | } |