r8108 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r8107‎ | r8108 | r8109 >
Date:10:51, 7 April 2005
Author:timstarling
Status:old
Tags:
Comment:
Ability to put profiling data in comments. Also tweaked profiling output format and fixed obsolete calling convention for wfGetProfilingOutput()
Modified paths:
  • /branches/REL1_4/phase3/includes/DefaultSettings.php (modified) (history)
  • /branches/REL1_4/phase3/includes/GlobalFunctions.php (modified) (history)
  • /branches/REL1_4/phase3/includes/OutputPage.php (modified) (history)
  • /branches/REL1_4/phase3/includes/Profiling.php (modified) (history)

Diff [purge]

Index: branches/REL1_4/phase3/includes/Profiling.php
@@ -20,9 +20,9 @@
2121 $wgProfiler->profileOut( $functionname );
2222 }
2323
24 -function wfGetProfilingOutput( $start, $elapsed ) {
 24+function wfGetProfilingOutput() {
2525 global $wgProfiler;
26 - return $wgProfiler->getOutput( $start, $elapsed );
 26+ return $wgProfiler->getOutput();
2727 }
2828
2929 function wfProfileClose() {
@@ -179,9 +179,10 @@
180180 function getFunctionReport() {
181181 $width = 125;
182182 $format = "%-" . ($width - 34) . "s %6d %6.3f %6.3f %7.3f%% %6d (%6.3f-%6.3f) [%d]\n";
183 - $titleFormat = "%-" . ($width - 34) . "s %9s %9s %9s %9s %6s\n";
 183+ $titleFormat = "%-" . ($width - 34) . "s %9s %9s %9s %9s %9s %9s %9s %9s\n";
184184 $prof = "\nProfiling data\n";
185 - $prof .= sprintf( $titleFormat, 'Name', 'Calls', 'Total', 'Each', '%', 'Mem' );
 185+ $prof .= sprintf( $titleFormat, 'Name', 'Calls', 'Total', 'Each', '%',
 186+ 'Mem', 'Min', 'Max', 'Overhead' );
186187 $this->mCollated = array();
187188 $this->mCalls = array();
188189 $this->mMemory = array();
@@ -258,12 +259,12 @@
259260 $this->mCalls['-overhead-total'] = $profileCount;
260261
261262 # Output
262 - asort( $this->mCollated, SORT_NUMERIC );
 263+ arsort( $this->mCollated, SORT_NUMERIC );
263264 foreach ( $this->mCollated as $fname => $elapsed ) {
264265 $calls = $this->mCalls[$fname];
265266 $percent = $total ? 100. * $elapsed / $total : 0;
266267 $memory = $this->mMemory[$fname];
267 - $prof .= sprintf( $format, $fname, $calls, (float)($elapsed * 1000),
 268+ $prof .= sprintf( $format, substr( $fname, 0, $width-34), $calls, (float)($elapsed * 1000),
268269 (float)($elapsed * 1000) / $calls, $percent, $memory,
269270 ($this->mMin[$fname] * 1000.0),
270271 ($this->mMax[$fname] * 1000.0),
Index: branches/REL1_4/phase3/includes/GlobalFunctions.php
@@ -292,7 +292,7 @@
293293 $start = (float)$sec + (float)$usec;
294294 $elapsed = $now - $start;
295295 if ( $wgProfiling ) {
296 - $prof = wfGetProfilingOutput( $start, $elapsed );
 296+ $prof = wfGetProfilingOutput();
297297 $forward = '';
298298 if( !empty( $_SERVER['HTTP_X_FORWARDED_FOR'] ) )
299299 $forward = ' forwarded for ' . $_SERVER['HTTP_X_FORWARDED_FOR'];
Index: branches/REL1_4/phase3/includes/OutputPage.php
@@ -486,8 +486,21 @@
487487 * This method has no side effects.
488488 */
489489 function reportTime() {
490 - global $wgRequestTime;
 490+ global $wgRequestTime, $wgProfiling, $wgProfileToCommentUser, $wgUser;
491491
 492+
 493+ if ( $wgProfiling && $wgUser && $wgProfileToCommentUser &&
 494+ $wgProfileToCommentUser == $wgUser->getName() )
 495+ {
 496+ $prof = wfGetProfilingOutput();
 497+ // Strip end of comment
 498+ $prof = str_replace( '-->', '--<', $prof );
 499+ $com = "<!--\n$prof\n-->\n";
 500+ } else {
 501+ $com = '';
 502+ }
 503+
 504+
492505 $now = wfTime();
493506 list( $usec, $sec ) = explode( ' ', $wgRequestTime );
494507 $start = (float)$sec + (float)$usec;
@@ -506,7 +519,7 @@
507520 # This may be a virtual server.
508521 $hostname = $_SERVER['SERVER_NAME'];
509522 }
510 - $com = sprintf( "<!-- Served by %s in %01.2f secs. -->",
 523+ $com .= sprintf( "<!-- Served by %s in %01.2f secs. -->\n",
511524 $hostname, $elapsed );
512525 return $com;
513526 }
Index: branches/REL1_4/phase3/includes/DefaultSettings.php
@@ -562,6 +562,7 @@
563563 $wgProfileToDatabase = false; # Log sums from profiling into "profiling" table in db.
564564 $wgProfileSampleRate = 1; # Only profile every n requests when profiling is turned on
565565 $wgProfileCallTree = false; # If true, print a raw call tree instead of per-function report
 566+$wgProfileToCommentUser = false; # Put profiling data in HTML comments in the output file, for a given user only
566567
567568 $wgDebugProfiling = false; # Detects non-matching wfProfileIn/wfProfileOut calls
568569 $wgDebugFunctionEntry = 0; # Output debug message on every wfProfileIn/wfProfileOut

Status & tagging log