r51154 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r51153‎ | r51154 | r51155 >
Date:16:48, 29 May 2009
Author:ialex
Status:deferred
Tags:
Comment:
Tweaks to profileinfo.php:
* whitespaces fixes
* changed "<form method="profiling.php">" to "<form method="get" action="profileinfo.php">" since "method" should be either "get" or "post" and the script's name was incorrect
Modified paths:
  • /trunk/phase3/profileinfo.php (modified) (history)

Diff [purge]

Index: trunk/phase3/profileinfo.php
@@ -65,14 +65,14 @@
6666 <body>
6767 <?php
6868
69 -if (!$wgEnableProfileInfo) {
 69+if ( !$wgEnableProfileInfo ) {
7070 echo "disabled\n";
7171 exit( 1 );
7272 }
7373
7474 $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 )
7777 $expand[$f] = true;
7878
7979 class profile_point {
@@ -81,7 +81,7 @@
8282 var $time;
8383 var $children;
8484
85 - function profile_point($name, $count, $time, $memory ) {
 85+ function profile_point( $name, $count, $time, $memory ) {
8686 $this->name = $name;
8787 $this->count = $count;
8888 $this->time = $time;
@@ -89,35 +89,35 @@
9090 $this->children = array();
9191 }
9292
93 - function add_child($child) {
 93+ function add_child( $child ) {
9494 $this->children[] = $child;
9595 }
9696
9797 function display($indent = 0.0) {
9898 global $expand, $totaltime, $totalmemory, $totalcount;
99 - usort($this->children, "compare_point");
 99+ usort( $this->children, 'compare_point' );
100100
101101 $extet = '';
102 - if (isset($expand[$this->name()]))
 102+ if ( isset( $expand[$this->name()] ) )
103103 $ex = true;
104104 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 ) );
108108 $extet = " <a href=\"$url\">[+]</a>";
109109 } else $extet = '';
110110 } else {
111111 $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 );
115115
116 - $extet = " <a href=\"" . makeurl(false, false, $e) . "\">[&ndash;]</a>";
 116+ $extet = " <a href=\"" . makeurl( false, false, $e ) . "\">[&ndash;]</a>";
117117 }
118118 ?>
119119 <tr>
120120 <td class="name" style="padding-left: <?php echo $indent ?>em;">
121 - <?php echo htmlspecialchars($this->name()) . $extet ?>
 121+ <?php echo htmlspecialchars( $this->name() ) . $extet ?>
122122 </td>
123123 <td class="timep"><?php echo @wfPercent( $this->time() / $totaltime * 100 ) ?></td>
124124 <td class="memoryp"><?php echo @wfPercent( $this->memory() / $totalmemory * 100 ) ?></td>
@@ -129,9 +129,9 @@
130130 <td class="mpr"><?php echo @round( sprintf( '%.2f' ,$this->memory() / $totalcount / 1024 ), 2 ) ?></td>
131131 </tr>
132132 <?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 );
136136 }
137137 }
138138 }
@@ -153,38 +153,38 @@
154154 }
155155
156156 function timePerCall() {
157 - return @($this->time / $this->count);
 157+ return @( $this->time / $this->count );
158158 }
159159
160160 function memoryPerCall() {
161 - return @($this->memory / $this->count);
 161+ return @( $this->memory / $this->count );
162162 }
163163
164164 function callsPerRequest() {
165165 global $totalcount;
166 - return @($this->count / $totalcount);
 166+ return @( $this->count / $totalcount );
167167 }
168168
169169 function timePerRequest() {
170170 global $totalcount;
171 - return @($this->time / $totalcount);
 171+ return @( $this->time / $totalcount );
172172 }
173173
174174 function memoryPerRequest() {
175175 global $totalcount;
176 - return @($this->memory / $totalcount);
 176+ return @( $this->memory / $totalcount );
177177 }
178178
179179 function fmttime() {
180 - return sprintf("%5.02f", $this->time);
 180+ return sprintf( "%5.02f", $this->time );
181181 }
182182 };
183183
184 -function compare_point($a, $b) {
 184+function compare_point( $a, $b ) {
185185 global $sort;
186 - switch ($sort) {
 186+ switch ( $sort ) {
187187 case "name":
188 - return strcmp($a->name(), $b->name());
 188+ return strcmp( $a->name(), $b->name() );
189189 case "time":
190190 return $a->time() > $b->time() ? -1 : 1;
191191 case "memory":
@@ -204,21 +204,23 @@
205205 }
206206 }
207207
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' );
209210 $sort = 'time';
210 -if (isset($_REQUEST['sort']) && in_array($_REQUEST['sort'], $sorts))
 211+if ( isset( $_REQUEST['sort'] ) && in_array( $_REQUEST['sort'], $sorts ) )
211212 $sort = $_REQUEST['sort'];
212213
213214
214215 $dbr = wfGetDB( DB_SLAVE );
215216 $res = $dbr->select( 'profiling', '*', array(), 'profileinfo.php', array( 'ORDER BY' => 'pf_name ASC' ) );
216217
217 -if (isset($_REQUEST['filter']))
 218+if (isset( $_REQUEST['filter'] ) )
218219 $filter = $_REQUEST['filter'];
219 -else $filter = '';
 220+else
 221+ $filter = '';
220222
221223 ?>
222 -<form method="profiling.php">
 224+<form method="get" action="profileinfo.php">
223225 <p>
224226 <input type="text" name="filter" value="<?php echo htmlspecialchars($filter)?>"/>
225227 <input type="hidden" name="sort" value="<?php echo htmlspecialchars($sort)?>"/>
@@ -229,30 +231,30 @@
230232
231233 <table cellspacing="0" border="1">
232234 <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>
242244 </tr>
243245 <?php
244246 $totaltime = 0.0;
245247 $totalcount = 0;
246248 $totalmemory = 0.0;
247249
248 -function makeurl($_filter = false, $_sort = false, $_expand = false) {
 250+function makeurl( $_filter = false, $_sort = false, $_expand = false ) {
249251 global $filter, $sort, $expand;
250252
251 - if ($_expand === false)
 253+ if ( $_expand === false )
252254 $_expand = $expand;
253255
254256 $nfilter = $_filter ? $_filter : $filter;
255257 $nsort = $_sort ? $_sort : $sort;
256 - $exp = urlencode(implode(',', array_keys($_expand)));
 258+ $exp = urlencode( implode( ',', array_keys( $_expand ) ) );
257259 return "?filter=$nfilter&amp;sort=$nsort&amp;expand=$exp";
258260 }
259261
@@ -262,20 +264,20 @@
263265
264266 $last = false;
265267 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 );
267269 if( $next->name() == '-total' ) {
268270 $totaltime = $next->time();
269271 $totalcount = $next->count();
270272 $totalmemory = $next->memory();
271273 }
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() ) ) {
274276 $last->add_child($next);
275277 continue;
276278 }
277279 }
278280 $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() ) ) {
280282 $sqltotal += $next->time();
281283 $queries[] = $next;
282284 } else {
@@ -283,15 +285,15 @@
284286 }
285287 }
286288
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 )
289291 $s->add_child($q);
290292 $points[] = $s;
291293
292 -usort($points, "compare_point");
 294+usort( $points, "compare_point" );
293295
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 ) )
296298 continue;
297299
298300 $point->display();

Status & tagging log