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