@@ -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 | } |