Index: trunk/phase3/profileinfo.php |
— | — | @@ -65,14 +65,14 @@ |
66 | 66 | <body> |
67 | 67 | <?php |
68 | 68 | |
69 | | -if (!$wgEnableProfileInfo) { |
| 69 | +if ( !$wgEnableProfileInfo ) { |
70 | 70 | echo "disabled\n"; |
71 | 71 | exit( 1 ); |
72 | 72 | } |
73 | 73 | |
74 | 74 | $expand = array(); |
75 | | -if (isset($_REQUEST['expand'])) |
76 | | - foreach(explode(",", $_REQUEST['expand']) as $f) |
| 75 | +if ( isset( $_REQUEST['expand'] ) ) |
| 76 | + foreach( explode( ',', $_REQUEST['expand'] ) as $f ) |
77 | 77 | $expand[$f] = true; |
78 | 78 | |
79 | 79 | class profile_point { |
— | — | @@ -81,7 +81,7 @@ |
82 | 82 | var $time; |
83 | 83 | var $children; |
84 | 84 | |
85 | | - function profile_point($name, $count, $time, $memory ) { |
| 85 | + function profile_point( $name, $count, $time, $memory ) { |
86 | 86 | $this->name = $name; |
87 | 87 | $this->count = $count; |
88 | 88 | $this->time = $time; |
— | — | @@ -89,35 +89,35 @@ |
90 | 90 | $this->children = array(); |
91 | 91 | } |
92 | 92 | |
93 | | - function add_child($child) { |
| 93 | + function add_child( $child ) { |
94 | 94 | $this->children[] = $child; |
95 | 95 | } |
96 | 96 | |
97 | 97 | function display($indent = 0.0) { |
98 | 98 | global $expand, $totaltime, $totalmemory, $totalcount; |
99 | | - usort($this->children, "compare_point"); |
| 99 | + usort( $this->children, 'compare_point' ); |
100 | 100 | |
101 | 101 | $extet = ''; |
102 | | - if (isset($expand[$this->name()])) |
| 102 | + if ( isset( $expand[$this->name()] ) ) |
103 | 103 | $ex = true; |
104 | 104 | else $ex = false; |
105 | | - if (!$ex) { |
106 | | - if (count($this->children)) { |
107 | | - $url = makeurl(false, false, $expand + array($this->name() => true)); |
| 105 | + if ( !$ex ) { |
| 106 | + if ( count( $this->children ) ) { |
| 107 | + $url = makeurl( false, false, $expand + array( $this->name() => true ) ); |
108 | 108 | $extet = " <a href=\"$url\">[+]</a>"; |
109 | 109 | } else $extet = ''; |
110 | 110 | } else { |
111 | 111 | $e = array(); |
112 | | - foreach ($expand as $name => $ep) |
113 | | - if ($name != $this->name()) |
114 | | - $e += array($name => $ep); |
| 112 | + foreach ( $expand as $name => $ep ) |
| 113 | + if ( $name != $this->name() ) |
| 114 | + $e += array( $name => $ep ); |
115 | 115 | |
116 | | - $extet = " <a href=\"" . makeurl(false, false, $e) . "\">[–]</a>"; |
| 116 | + $extet = " <a href=\"" . makeurl( false, false, $e ) . "\">[–]</a>"; |
117 | 117 | } |
118 | 118 | ?> |
119 | 119 | <tr> |
120 | 120 | <td class="name" style="padding-left: <?php echo $indent ?>em;"> |
121 | | - <?php echo htmlspecialchars($this->name()) . $extet ?> |
| 121 | + <?php echo htmlspecialchars( $this->name() ) . $extet ?> |
122 | 122 | </td> |
123 | 123 | <td class="timep"><?php echo @wfPercent( $this->time() / $totaltime * 100 ) ?></td> |
124 | 124 | <td class="memoryp"><?php echo @wfPercent( $this->memory() / $totalmemory * 100 ) ?></td> |
— | — | @@ -129,9 +129,9 @@ |
130 | 130 | <td class="mpr"><?php echo @round( sprintf( '%.2f' ,$this->memory() / $totalcount / 1024 ), 2 ) ?></td> |
131 | 131 | </tr> |
132 | 132 | <?php |
133 | | - if ($ex) { |
134 | | - foreach ($this->children as $child) { |
135 | | - $child->display($indent + 2); |
| 133 | + if ( $ex ) { |
| 134 | + foreach ( $this->children as $child ) { |
| 135 | + $child->display( $indent + 2 ); |
136 | 136 | } |
137 | 137 | } |
138 | 138 | } |
— | — | @@ -153,38 +153,38 @@ |
154 | 154 | } |
155 | 155 | |
156 | 156 | function timePerCall() { |
157 | | - return @($this->time / $this->count); |
| 157 | + return @( $this->time / $this->count ); |
158 | 158 | } |
159 | 159 | |
160 | 160 | function memoryPerCall() { |
161 | | - return @($this->memory / $this->count); |
| 161 | + return @( $this->memory / $this->count ); |
162 | 162 | } |
163 | 163 | |
164 | 164 | function callsPerRequest() { |
165 | 165 | global $totalcount; |
166 | | - return @($this->count / $totalcount); |
| 166 | + return @( $this->count / $totalcount ); |
167 | 167 | } |
168 | 168 | |
169 | 169 | function timePerRequest() { |
170 | 170 | global $totalcount; |
171 | | - return @($this->time / $totalcount); |
| 171 | + return @( $this->time / $totalcount ); |
172 | 172 | } |
173 | 173 | |
174 | 174 | function memoryPerRequest() { |
175 | 175 | global $totalcount; |
176 | | - return @($this->memory / $totalcount); |
| 176 | + return @( $this->memory / $totalcount ); |
177 | 177 | } |
178 | 178 | |
179 | 179 | function fmttime() { |
180 | | - return sprintf("%5.02f", $this->time); |
| 180 | + return sprintf( "%5.02f", $this->time ); |
181 | 181 | } |
182 | 182 | }; |
183 | 183 | |
184 | | -function compare_point($a, $b) { |
| 184 | +function compare_point( $a, $b ) { |
185 | 185 | global $sort; |
186 | | - switch ($sort) { |
| 186 | + switch ( $sort ) { |
187 | 187 | case "name": |
188 | | - return strcmp($a->name(), $b->name()); |
| 188 | + return strcmp( $a->name(), $b->name() ); |
189 | 189 | case "time": |
190 | 190 | return $a->time() > $b->time() ? -1 : 1; |
191 | 191 | case "memory": |
— | — | @@ -204,21 +204,23 @@ |
205 | 205 | } |
206 | 206 | } |
207 | 207 | |
208 | | -$sorts = array("time","memory","count","calls_per_req","name","time_per_call","memory_per_call","time_per_req","memory_per_req"); |
| 208 | +$sorts = array( 'time', 'memory', 'count', 'calls_per_req', 'name', |
| 209 | + 'time_per_call', 'memory_per_call', 'time_per_req', 'memory_per_req' ); |
209 | 210 | $sort = 'time'; |
210 | | -if (isset($_REQUEST['sort']) && in_array($_REQUEST['sort'], $sorts)) |
| 211 | +if ( isset( $_REQUEST['sort'] ) && in_array( $_REQUEST['sort'], $sorts ) ) |
211 | 212 | $sort = $_REQUEST['sort']; |
212 | 213 | |
213 | 214 | |
214 | 215 | $dbr = wfGetDB( DB_SLAVE ); |
215 | 216 | $res = $dbr->select( 'profiling', '*', array(), 'profileinfo.php', array( 'ORDER BY' => 'pf_name ASC' ) ); |
216 | 217 | |
217 | | -if (isset($_REQUEST['filter'])) |
| 218 | +if (isset( $_REQUEST['filter'] ) ) |
218 | 219 | $filter = $_REQUEST['filter']; |
219 | | -else $filter = ''; |
| 220 | +else |
| 221 | + $filter = ''; |
220 | 222 | |
221 | 223 | ?> |
222 | | -<form method="profiling.php"> |
| 224 | +<form method="get" action="profileinfo.php"> |
223 | 225 | <p> |
224 | 226 | <input type="text" name="filter" value="<?php echo htmlspecialchars($filter)?>"/> |
225 | 227 | <input type="hidden" name="sort" value="<?php echo htmlspecialchars($sort)?>"/> |
— | — | @@ -229,30 +231,30 @@ |
230 | 232 | |
231 | 233 | <table cellspacing="0" border="1"> |
232 | 234 | <tr id="top"> |
233 | | -<th><a href="<?php echo makeurl(false, "name") ?>">Name</a></th> |
234 | | -<th><a href="<?php echo makeurl(false, "time") ?>">Time (%)</a></th> |
235 | | -<th><a href="<?php echo makeurl(false, "memory") ?>">Memory (%)</a></th> |
236 | | -<th><a href="<?php echo makeurl(false, "count") ?>">Count</a></th> |
237 | | -<th><a href="<?php echo makeurl(false, "calls_per_req") ?>">Calls/req</a></th> |
238 | | -<th><a href="<?php echo makeurl(false, "time_per_call") ?>">ms/call</a></th> |
239 | | -<th><a href="<?php echo makeurl(false, "memory_per_call") ?>">kb/call</a></th> |
240 | | -<th><a href="<?php echo makeurl(false, "time_per_req") ?>">ms/req</a></th> |
241 | | -<th><a href="<?php echo makeurl(false, "memory_per_req") ?>">kb/req</a></th> |
| 235 | +<th><a href="<?php echo makeurl( false, 'name' ) ?>">Name</a></th> |
| 236 | +<th><a href="<?php echo makeurl( false, 'time' ) ?>">Time (%)</a></th> |
| 237 | +<th><a href="<?php echo makeurl( false, 'memory' ) ?>">Memory (%)</a></th> |
| 238 | +<th><a href="<?php echo makeurl( false, 'count' ) ?>">Count</a></th> |
| 239 | +<th><a href="<?php echo makeurl( false, 'calls_per_req' ) ?>">Calls/req</a></th> |
| 240 | +<th><a href="<?php echo makeurl( false, 'time_per_call' ) ?>">ms/call</a></th> |
| 241 | +<th><a href="<?php echo makeurl( false, 'memory_per_call' ) ?>">kb/call</a></th> |
| 242 | +<th><a href="<?php echo makeurl( false, 'time_per_req' ) ?>">ms/req</a></th> |
| 243 | +<th><a href="<?php echo makeurl( false, 'memory_per_req' ) ?>">kb/req</a></th> |
242 | 244 | </tr> |
243 | 245 | <?php |
244 | 246 | $totaltime = 0.0; |
245 | 247 | $totalcount = 0; |
246 | 248 | $totalmemory = 0.0; |
247 | 249 | |
248 | | -function makeurl($_filter = false, $_sort = false, $_expand = false) { |
| 250 | +function makeurl( $_filter = false, $_sort = false, $_expand = false ) { |
249 | 251 | global $filter, $sort, $expand; |
250 | 252 | |
251 | | - if ($_expand === false) |
| 253 | + if ( $_expand === false ) |
252 | 254 | $_expand = $expand; |
253 | 255 | |
254 | 256 | $nfilter = $_filter ? $_filter : $filter; |
255 | 257 | $nsort = $_sort ? $_sort : $sort; |
256 | | - $exp = urlencode(implode(',', array_keys($_expand))); |
| 258 | + $exp = urlencode( implode( ',', array_keys( $_expand ) ) ); |
257 | 259 | return "?filter=$nfilter&sort=$nsort&expand=$exp"; |
258 | 260 | } |
259 | 261 | |
— | — | @@ -262,20 +264,20 @@ |
263 | 265 | |
264 | 266 | $last = false; |
265 | 267 | foreach( $res as $o ) { |
266 | | - $next = new profile_point($o->pf_name, $o->pf_count, $o->pf_time, $o->pf_memory); |
| 268 | + $next = new profile_point( $o->pf_name, $o->pf_count, $o->pf_time, $o->pf_memory ); |
267 | 269 | if( $next->name() == '-total' ) { |
268 | 270 | $totaltime = $next->time(); |
269 | 271 | $totalcount = $next->count(); |
270 | 272 | $totalmemory = $next->memory(); |
271 | 273 | } |
272 | | - if ($last !== false) { |
273 | | - if (preg_match("/^".preg_quote($last->name(), "/")."/", $next->name())) { |
| 274 | + if ( $last !== false ) { |
| 275 | + if ( preg_match( "/^".preg_quote( $last->name(), "/" )."/", $next->name() ) ) { |
274 | 276 | $last->add_child($next); |
275 | 277 | continue; |
276 | 278 | } |
277 | 279 | } |
278 | 280 | $last = $next; |
279 | | - if (preg_match("/^query: /", $next->name()) || preg_match("/^query-m: /", $next->name())) { |
| 281 | + if ( preg_match( "/^query: /", $next->name() ) || preg_match( "/^query-m: /", $next->name() ) ) { |
280 | 282 | $sqltotal += $next->time(); |
281 | 283 | $queries[] = $next; |
282 | 284 | } else { |
— | — | @@ -283,15 +285,15 @@ |
284 | 286 | } |
285 | 287 | } |
286 | 288 | |
287 | | -$s = new profile_point("SQL Queries", 0, $sqltotal, 0, 0); |
288 | | -foreach ($queries as $q) |
| 289 | +$s = new profile_point( "SQL Queries", 0, $sqltotal, 0, 0 ); |
| 290 | +foreach ( $queries as $q ) |
289 | 291 | $s->add_child($q); |
290 | 292 | $points[] = $s; |
291 | 293 | |
292 | | -usort($points, "compare_point"); |
| 294 | +usort( $points, "compare_point" ); |
293 | 295 | |
294 | | -foreach ($points as $point) { |
295 | | - if (strlen($filter) && !strstr($point->name(), $filter)) |
| 296 | +foreach ( $points as $point ) { |
| 297 | + if ( strlen( $filter ) && !strstr( $point->name(), $filter ) ) |
296 | 298 | continue; |
297 | 299 | |
298 | 300 | $point->display(); |