r86228 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r86227‎ | r86228 | r86229 >
Date:19:00, 16 April 2011
Author:demon
Status:ok
Tags:
Comment:
More profiler cleanup:
* Move autoloader up a little bit so the profiler classes can use it
* Make Profiler into a singleton so it's lazy-constructed, $wgProfiler is now a configuration array (used 'visible' in ProfilerSimpleText as an example of other globals we can move into this array). If $wgProfiler is set to an object, it'll use that for back-compat
* Maintenance: rather than setting up the profiler and then disabling it, just disable it from the start
* Kill $wgProfiling -> now that ProfilerStub overrides profileIn() and profileOut(), it's not needed
* dumpHTML needs some fixes still
Modified paths:
  • /trunk/phase3/RELEASE-NOTES (modified) (history)
  • /trunk/phase3/StartProfiler.sample (modified) (history)
  • /trunk/phase3/includes/WebStart.php (modified) (history)
  • /trunk/phase3/includes/profiler/Profiler.php (modified) (history)
  • /trunk/phase3/includes/profiler/ProfilerSimple.php (modified) (history)
  • /trunk/phase3/includes/profiler/ProfilerSimpleText.php (modified) (history)
  • /trunk/phase3/includes/profiler/ProfilerSimpleTrace.php (modified) (history)
  • /trunk/phase3/includes/profiler/ProfilerSimpleUDP.php (modified) (history)
  • /trunk/phase3/includes/profiler/ProfilerStub.php (modified) (history)
  • /trunk/phase3/maintenance/Maintenance.php (modified) (history)
  • /trunk/phase3/maintenance/doMaintenance.php (modified) (history)

Diff [purge]

Index: trunk/phase3/StartProfiler.sample
@@ -6,15 +6,13 @@
77 * To use a profiler, copy this file to StartProfiler.php,
88 * delete the PHP line above, and add something like this:
99 *
10 - * require_once( dirname(__FILE__).'/includes/Profiler.php' );
11 - * $wgProfiler = new Profiler;
 10+ * $wgProfiler['class'] = 'Profiler';
1211 *
1312 * Or for a sampling profiler:
1413 * if ( !mt_rand( 0, 100 ) ) {
15 - * require_once( dirname(__FILE__).'/includes/Profiler.php' );
16 - * $wgProfiler = new Profiler;
 14+ * $wgProfiler['class'] = 'Profiler';
1715 * } else {
18 - * require_once( dirname(__FILE__).'/includes/ProfilerStub.php' );
 16+ * $wgProfiler['class'] = 'ProfilerStub';
1917 * }
2018 *
2119 * Configuration of the profiler output can be done in LocalSettings.php
Index: trunk/phase3/maintenance/doMaintenance.php
@@ -69,13 +69,8 @@
7070 require_once( "$IP/includes/Init.php" );
7171 }
7272
73 -# Setup the profiler
74 -global $IP;
75 -if ( !defined( 'MW_COMPILED' ) && file_exists( "$IP/StartProfiler.php" ) ) {
76 - require_once( "$IP/StartProfiler.php" );
77 -} else {
78 - require_once( MWInit::compiledPath( 'includes/profiler/ProfilerStub.php' ) );
79 -}
 73+# Stub the profiler
 74+require_once( MWInit::compiledPath( 'includes/profiler/Profiler.php' ) );
8075
8176 // Some other requires
8277 if ( !defined( 'MW_COMPILED' ) ) {
Index: trunk/phase3/maintenance/Maintenance.php
@@ -803,7 +803,7 @@
804804 */
805805 public function finalSetup() {
806806 global $wgCommandLineMode, $wgShowSQLErrors, $wgServer;
807 - global $wgProfiling, $wgDBadminuser, $wgDBadminpassword;
 807+ global $wgDBadminuser, $wgDBadminpassword;
808808 global $wgDBuser, $wgDBpassword, $wgDBservers, $wgLBFactoryConf;
809809
810810 # Turn off output buffering again, it might have been turned on in the settings files
@@ -848,8 +848,6 @@
849849 $wgShowSQLErrors = true;
850850 @set_time_limit( 0 );
851851 $this->adjustMemoryLimit();
852 -
853 - $wgProfiling = false; // only for Profiler.php mode; avoids OOM errors
854852 }
855853
856854 /**
Index: trunk/phase3/includes/profiler/ProfilerSimpleTrace.php
@@ -4,10 +4,6 @@
55 * @ingroup Profiler
66 */
77
8 -if ( !class_exists( 'ProfilerSimple' ) ) {
9 - require_once( dirname( __FILE__ ) . '/ProfilerSimple.php' );
10 -}
11 -
128 /**
139 * Execution trace
1410 * @todo document methods (?)
Index: trunk/phase3/includes/profiler/ProfilerSimple.php
@@ -4,10 +4,6 @@
55 * @ingroup Profiler
66 */
77
8 -if ( !class_exists( 'Profiler' ) ) {
9 - require_once( dirname( __FILE__ ) . '/Profiler.php' );
10 -}
11 -
128 /**
139 * Simple profiler base class.
1410 * @todo document methods (?)
Index: trunk/phase3/includes/profiler/ProfilerStub.php
@@ -4,10 +4,6 @@
55 * @file
66 * @ingroup Profiler
77 */
8 -if ( !class_exists( 'Profiler' ) ) {
9 - require_once( dirname( __FILE__ ) . '/Profiler.php' );
10 -}
11 -
128 class ProfilerStub extends Profiler {
139
1410 /**
@@ -59,7 +55,3 @@
6056 public function getOutput() {}
6157 public function close() {}
6258 }
63 -
64 -/** backward compatibility */
65 -$wgProfiling = false;
66 -$wgProfiler = new ProfilerStub();
Index: trunk/phase3/includes/profiler/ProfilerSimpleText.php
@@ -4,18 +4,13 @@
55 * @ingroup Profiler
66 */
77
8 -if ( !class_exists( 'ProfilerSimple' ) ) {
9 - require_once( dirname( __FILE__ ) . '/ProfilerSimple.php' );
10 -}
11 -
128 /**
139 * The least sophisticated profiler output class possible, view your source! :)
1410 *
15 - * Put the following 3 lines in StartProfiler.php:
 11+ * Put the following 2 lines in StartProfiler.php:
1612 *
17 - * require_once( dirname( __FILE__ ) . '/includes/ProfilerSimpleText.php' );
18 - * $wgProfiler = new ProfilerSimpleText;
19 - * $wgProfiler->visible=true;
 13+ * $wgProfiler['class'] = 'ProfilerSimpleText';
 14+ * $wgProfiler['visible'] = true;
2015 *
2116 * @ingroup Profiler
2217 */
@@ -23,6 +18,13 @@
2419 public $visible=false; /* Show as <PRE> or <!-- ? */
2520 static private $out;
2621
 22+ public function __construct( $profileConfig ) {
 23+ if( isset( $profileConfig['visible'] ) && $profileConfig['visible'] ) {
 24+ $this->visible = true;
 25+ }
 26+ parent::__construct();
 27+ }
 28+
2729 function getFunctionReport() {
2830 if($this->mTemplated) {
2931 uasort($this->mCollated,array('self','sort'));
Index: trunk/phase3/includes/profiler/Profiler.php
@@ -7,16 +7,21 @@
88 * This file is only included if profiling is enabled
99 */
1010
11 -/** backward compatibility */
12 -$wgProfiling = true;
 11+/**
 12+ * Default profiling configuration. Permitted keys are:
 13+ * class : Name of Profiler or subclass to use for profiling
 14+ * visible : Whether to output the profile info [ProfilerSimpleText only]
 15+ */
 16+$wgProfiler = array(
 17+ 'class' => 'ProfilerStub',
 18+);
1319
1420 /**
1521 * Begin profiling of a function
1622 * @param $functionname String: name of the function we will profile
1723 */
1824 function wfProfileIn( $functionname ) {
19 - global $wgProfiler;
20 - $wgProfiler->profileIn( $functionname );
 25+ Profiler::instance()->profileIn( $functionname );
2126 }
2227
2328 /**
@@ -24,24 +29,21 @@
2530 * @param $functionname String: name of the function we have profiled
2631 */
2732 function wfProfileOut( $functionname = 'missing' ) {
28 - global $wgProfiler;
29 - $wgProfiler->profileOut( $functionname );
 33+ Profiler::instance()->profileOut( $functionname );
3034 }
3135
3236 /**
3337 * Returns a profiling output to be stored in debug file
3438 */
3539 function wfGetProfilingOutput() {
36 - global $wgProfiler;
37 - return $wgProfiler->getOutput();
 40+ Profiler::instance()->getOutput();
3841 }
3942
4043 /**
4144 * Close opened profiling sections
4245 */
4346 function wfProfileClose() {
44 - global $wgProfiler;
45 - $wgProfiler->close();
 47+ Profiler::instance()->close();
4648 }
4749
4850 if (!function_exists('memory_get_usage')) {
@@ -59,6 +61,7 @@
6062 var $mStack = array (), $mWorkStack = array (), $mCollated = array ();
6163 var $mCalls = array (), $mTotals = array ();
6264 var $mTemplated = false;
 65+ private static $__instance = null;
6366
6467 function __construct() {
6568 // Push an entry for the pre-profile setup time onto the stack
@@ -72,13 +75,32 @@
7376 }
7477
7578 /**
 79+ * Singleton
 80+ * @return Profiler
 81+ */
 82+ public static function instance() {
 83+ if( is_null( self::$__instance ) ) {
 84+ global $wgProfiler;
 85+ if( is_array( $wgProfiler ) ) {
 86+ $class = $wgProfiler['class'];
 87+ self::$__instance = new $class( $wgProfiler );
 88+ } elseif( $wgProfiler instanceof Profiler ) {
 89+ self::$__instance = $wgProfiler; // back-compat
 90+ } else {
 91+ throw new MWException( '$wgProfiler set to bogus value' );
 92+ }
 93+
 94+ }
 95+ return self::$__instance;
 96+ }
 97+
 98+ /**
7699 * Called by wfProfieIn()
77100 *
78101 * @param $functionname String
79102 */
80103 public function profileIn( $functionname ) {
81 - global $wgDebugFunctionEntry, $wgProfiling;
82 - if( !$wgProfiling ) return;
 104+ global $wgDebugFunctionEntry;
83105 if( $wgDebugFunctionEntry ){
84106 $this->debug( str_repeat( ' ', count( $this->mWorkStack ) ) . 'Entering ' . $functionname . "\n" );
85107 }
@@ -92,8 +114,7 @@
93115 * @param $functionname String
94116 */
95117 public function profileOut($functionname) {
96 - global $wgDebugFunctionEntry, $wgProfiling;
97 - if( !$wgProfiling ) return;
 118+ global $wgDebugFunctionEntry;
98119 $memory = memory_get_usage();
99120 $time = $this->getTime();
100121
@@ -128,12 +149,6 @@
129150 * called by wfProfileClose()
130151 */
131152 public function close() {
132 - global $wgProfiling;
133 -
134 - # Avoid infinite loop
135 - if( !$wgProfiling )
136 - return;
137 -
138153 while( count( $this->mWorkStack ) ){
139154 $this->profileOut( 'close' );
140155 }
Index: trunk/phase3/includes/profiler/ProfilerSimpleUDP.php
@@ -4,10 +4,6 @@
55 * @ingroup Profiler
66 */
77
8 -if ( !class_exists( 'ProfilerSimple' ) ) {
9 - require_once( dirname( __FILE__ ) . '/ProfilerSimple.php' );
10 -}
11 -
128 /**
139 * ProfilerSimpleUDP class, that sends out messages for 'udpprofile' daemon
1410 * (the one from mediawiki/trunk/udpprofile SVN )
Index: trunk/phase3/includes/WebStart.php
@@ -89,19 +89,18 @@
9090 # Get MWInit class
9191 require_once( "$IP/includes/Init.php" );
9292
 93+ # Start the autoloader, so that extensions can derive classes from core files
 94+ require_once( "$IP/includes/AutoLoader.php" );
 95+
9396 # Start profiler
9497 # FIXME: rewrite wfProfileIn/wfProfileOut so that they can work in compiled mode
 98+ require_once( "$IP/includes/profiler/Profiler.php" );
9599 if ( file_exists( "$IP/StartProfiler.php" ) ) {
96100 require_once( "$IP/StartProfiler.php" );
97 - } else {
98 - require_once( "$IP/includes/profiler/ProfilerStub.php" );
99101 }
100102
101103 # Load up some global defines.
102104 require_once( "$IP/includes/Defines.php" );
103 -
104 - # Start the autoloader, so that extensions can derive classes from core files
105 - require_once( "$IP/includes/AutoLoader.php" );
106105 }
107106
108107 wfProfileIn( 'WebStart.php-conf' );
Index: trunk/phase3/RELEASE-NOTES
@@ -65,6 +65,8 @@
6666 math conversion after upgrading, obtain the Math extension from SVN or from
6767 http://www.mediawiki.org/wiki/Extension:Math and add to LocalSettings.php:
6868 require_once "$IP/extensions/Math/Math.php";
 69+* $wgProfiler is now a configuration array, see StartProfiler.sample for details
 70+* $wgProfiling has been removed
6971
7072 === New features in 1.18 ===
7173 * (bug 8130) Query pages should limit to content namespaces, not just main

Follow-up revisions

RevisionCommit summaryAuthorDate
r86231Followup r86228 (profiling cleanup):...demon19:23, 16 April 2011
r86232Followup r86228 (profiling cleanup):...demon19:30, 16 April 2011
r86233Various profiler fixes for dumpHTML (needs r86175, r86228, r86231, r86232)demon19:34, 16 April 2011

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r86175First step of reorganizing profiling files:...demon02:19, 16 April 2011

Status & tagging log