Index: trunk/phase3/StartProfiler.sample |
— | — | @@ -6,15 +6,13 @@ |
7 | 7 | * To use a profiler, copy this file to StartProfiler.php, |
8 | 8 | * delete the PHP line above, and add something like this: |
9 | 9 | * |
10 | | - * require_once( dirname(__FILE__).'/includes/Profiler.php' ); |
11 | | - * $wgProfiler = new Profiler; |
| 10 | + * $wgProfiler['class'] = 'Profiler'; |
12 | 11 | * |
13 | 12 | * Or for a sampling profiler: |
14 | 13 | * if ( !mt_rand( 0, 100 ) ) { |
15 | | - * require_once( dirname(__FILE__).'/includes/Profiler.php' ); |
16 | | - * $wgProfiler = new Profiler; |
| 14 | + * $wgProfiler['class'] = 'Profiler'; |
17 | 15 | * } else { |
18 | | - * require_once( dirname(__FILE__).'/includes/ProfilerStub.php' ); |
| 16 | + * $wgProfiler['class'] = 'ProfilerStub'; |
19 | 17 | * } |
20 | 18 | * |
21 | 19 | * Configuration of the profiler output can be done in LocalSettings.php |
Index: trunk/phase3/maintenance/doMaintenance.php |
— | — | @@ -69,13 +69,8 @@ |
70 | 70 | require_once( "$IP/includes/Init.php" ); |
71 | 71 | } |
72 | 72 | |
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' ) ); |
80 | 75 | |
81 | 76 | // Some other requires |
82 | 77 | if ( !defined( 'MW_COMPILED' ) ) { |
Index: trunk/phase3/maintenance/Maintenance.php |
— | — | @@ -803,7 +803,7 @@ |
804 | 804 | */ |
805 | 805 | public function finalSetup() { |
806 | 806 | global $wgCommandLineMode, $wgShowSQLErrors, $wgServer; |
807 | | - global $wgProfiling, $wgDBadminuser, $wgDBadminpassword; |
| 807 | + global $wgDBadminuser, $wgDBadminpassword; |
808 | 808 | global $wgDBuser, $wgDBpassword, $wgDBservers, $wgLBFactoryConf; |
809 | 809 | |
810 | 810 | # Turn off output buffering again, it might have been turned on in the settings files |
— | — | @@ -848,8 +848,6 @@ |
849 | 849 | $wgShowSQLErrors = true; |
850 | 850 | @set_time_limit( 0 ); |
851 | 851 | $this->adjustMemoryLimit(); |
852 | | - |
853 | | - $wgProfiling = false; // only for Profiler.php mode; avoids OOM errors |
854 | 852 | } |
855 | 853 | |
856 | 854 | /** |
Index: trunk/phase3/includes/profiler/ProfilerSimpleTrace.php |
— | — | @@ -4,10 +4,6 @@ |
5 | 5 | * @ingroup Profiler |
6 | 6 | */ |
7 | 7 | |
8 | | -if ( !class_exists( 'ProfilerSimple' ) ) { |
9 | | - require_once( dirname( __FILE__ ) . '/ProfilerSimple.php' ); |
10 | | -} |
11 | | - |
12 | 8 | /** |
13 | 9 | * Execution trace |
14 | 10 | * @todo document methods (?) |
Index: trunk/phase3/includes/profiler/ProfilerSimple.php |
— | — | @@ -4,10 +4,6 @@ |
5 | 5 | * @ingroup Profiler |
6 | 6 | */ |
7 | 7 | |
8 | | -if ( !class_exists( 'Profiler' ) ) { |
9 | | - require_once( dirname( __FILE__ ) . '/Profiler.php' ); |
10 | | -} |
11 | | - |
12 | 8 | /** |
13 | 9 | * Simple profiler base class. |
14 | 10 | * @todo document methods (?) |
Index: trunk/phase3/includes/profiler/ProfilerStub.php |
— | — | @@ -4,10 +4,6 @@ |
5 | 5 | * @file |
6 | 6 | * @ingroup Profiler |
7 | 7 | */ |
8 | | -if ( !class_exists( 'Profiler' ) ) { |
9 | | - require_once( dirname( __FILE__ ) . '/Profiler.php' ); |
10 | | -} |
11 | | - |
12 | 8 | class ProfilerStub extends Profiler { |
13 | 9 | |
14 | 10 | /** |
— | — | @@ -59,7 +55,3 @@ |
60 | 56 | public function getOutput() {} |
61 | 57 | public function close() {} |
62 | 58 | } |
63 | | - |
64 | | -/** backward compatibility */ |
65 | | -$wgProfiling = false; |
66 | | -$wgProfiler = new ProfilerStub(); |
Index: trunk/phase3/includes/profiler/ProfilerSimpleText.php |
— | — | @@ -4,18 +4,13 @@ |
5 | 5 | * @ingroup Profiler |
6 | 6 | */ |
7 | 7 | |
8 | | -if ( !class_exists( 'ProfilerSimple' ) ) { |
9 | | - require_once( dirname( __FILE__ ) . '/ProfilerSimple.php' ); |
10 | | -} |
11 | | - |
12 | 8 | /** |
13 | 9 | * The least sophisticated profiler output class possible, view your source! :) |
14 | 10 | * |
15 | | - * Put the following 3 lines in StartProfiler.php: |
| 11 | + * Put the following 2 lines in StartProfiler.php: |
16 | 12 | * |
17 | | - * require_once( dirname( __FILE__ ) . '/includes/ProfilerSimpleText.php' ); |
18 | | - * $wgProfiler = new ProfilerSimpleText; |
19 | | - * $wgProfiler->visible=true; |
| 13 | + * $wgProfiler['class'] = 'ProfilerSimpleText'; |
| 14 | + * $wgProfiler['visible'] = true; |
20 | 15 | * |
21 | 16 | * @ingroup Profiler |
22 | 17 | */ |
— | — | @@ -23,6 +18,13 @@ |
24 | 19 | public $visible=false; /* Show as <PRE> or <!-- ? */ |
25 | 20 | static private $out; |
26 | 21 | |
| 22 | + public function __construct( $profileConfig ) { |
| 23 | + if( isset( $profileConfig['visible'] ) && $profileConfig['visible'] ) { |
| 24 | + $this->visible = true; |
| 25 | + } |
| 26 | + parent::__construct(); |
| 27 | + } |
| 28 | + |
27 | 29 | function getFunctionReport() { |
28 | 30 | if($this->mTemplated) { |
29 | 31 | uasort($this->mCollated,array('self','sort')); |
Index: trunk/phase3/includes/profiler/Profiler.php |
— | — | @@ -7,16 +7,21 @@ |
8 | 8 | * This file is only included if profiling is enabled |
9 | 9 | */ |
10 | 10 | |
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 | +); |
13 | 19 | |
14 | 20 | /** |
15 | 21 | * Begin profiling of a function |
16 | 22 | * @param $functionname String: name of the function we will profile |
17 | 23 | */ |
18 | 24 | function wfProfileIn( $functionname ) { |
19 | | - global $wgProfiler; |
20 | | - $wgProfiler->profileIn( $functionname ); |
| 25 | + Profiler::instance()->profileIn( $functionname ); |
21 | 26 | } |
22 | 27 | |
23 | 28 | /** |
— | — | @@ -24,24 +29,21 @@ |
25 | 30 | * @param $functionname String: name of the function we have profiled |
26 | 31 | */ |
27 | 32 | function wfProfileOut( $functionname = 'missing' ) { |
28 | | - global $wgProfiler; |
29 | | - $wgProfiler->profileOut( $functionname ); |
| 33 | + Profiler::instance()->profileOut( $functionname ); |
30 | 34 | } |
31 | 35 | |
32 | 36 | /** |
33 | 37 | * Returns a profiling output to be stored in debug file |
34 | 38 | */ |
35 | 39 | function wfGetProfilingOutput() { |
36 | | - global $wgProfiler; |
37 | | - return $wgProfiler->getOutput(); |
| 40 | + Profiler::instance()->getOutput(); |
38 | 41 | } |
39 | 42 | |
40 | 43 | /** |
41 | 44 | * Close opened profiling sections |
42 | 45 | */ |
43 | 46 | function wfProfileClose() { |
44 | | - global $wgProfiler; |
45 | | - $wgProfiler->close(); |
| 47 | + Profiler::instance()->close(); |
46 | 48 | } |
47 | 49 | |
48 | 50 | if (!function_exists('memory_get_usage')) { |
— | — | @@ -59,6 +61,7 @@ |
60 | 62 | var $mStack = array (), $mWorkStack = array (), $mCollated = array (); |
61 | 63 | var $mCalls = array (), $mTotals = array (); |
62 | 64 | var $mTemplated = false; |
| 65 | + private static $__instance = null; |
63 | 66 | |
64 | 67 | function __construct() { |
65 | 68 | // Push an entry for the pre-profile setup time onto the stack |
— | — | @@ -72,13 +75,32 @@ |
73 | 76 | } |
74 | 77 | |
75 | 78 | /** |
| 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 | + /** |
76 | 99 | * Called by wfProfieIn() |
77 | 100 | * |
78 | 101 | * @param $functionname String |
79 | 102 | */ |
80 | 103 | public function profileIn( $functionname ) { |
81 | | - global $wgDebugFunctionEntry, $wgProfiling; |
82 | | - if( !$wgProfiling ) return; |
| 104 | + global $wgDebugFunctionEntry; |
83 | 105 | if( $wgDebugFunctionEntry ){ |
84 | 106 | $this->debug( str_repeat( ' ', count( $this->mWorkStack ) ) . 'Entering ' . $functionname . "\n" ); |
85 | 107 | } |
— | — | @@ -92,8 +114,7 @@ |
93 | 115 | * @param $functionname String |
94 | 116 | */ |
95 | 117 | public function profileOut($functionname) { |
96 | | - global $wgDebugFunctionEntry, $wgProfiling; |
97 | | - if( !$wgProfiling ) return; |
| 118 | + global $wgDebugFunctionEntry; |
98 | 119 | $memory = memory_get_usage(); |
99 | 120 | $time = $this->getTime(); |
100 | 121 | |
— | — | @@ -128,12 +149,6 @@ |
129 | 150 | * called by wfProfileClose() |
130 | 151 | */ |
131 | 152 | public function close() { |
132 | | - global $wgProfiling; |
133 | | - |
134 | | - # Avoid infinite loop |
135 | | - if( !$wgProfiling ) |
136 | | - return; |
137 | | - |
138 | 153 | while( count( $this->mWorkStack ) ){ |
139 | 154 | $this->profileOut( 'close' ); |
140 | 155 | } |
Index: trunk/phase3/includes/profiler/ProfilerSimpleUDP.php |
— | — | @@ -4,10 +4,6 @@ |
5 | 5 | * @ingroup Profiler |
6 | 6 | */ |
7 | 7 | |
8 | | -if ( !class_exists( 'ProfilerSimple' ) ) { |
9 | | - require_once( dirname( __FILE__ ) . '/ProfilerSimple.php' ); |
10 | | -} |
11 | | - |
12 | 8 | /** |
13 | 9 | * ProfilerSimpleUDP class, that sends out messages for 'udpprofile' daemon |
14 | 10 | * (the one from mediawiki/trunk/udpprofile SVN ) |
Index: trunk/phase3/includes/WebStart.php |
— | — | @@ -89,19 +89,18 @@ |
90 | 90 | # Get MWInit class |
91 | 91 | require_once( "$IP/includes/Init.php" ); |
92 | 92 | |
| 93 | + # Start the autoloader, so that extensions can derive classes from core files |
| 94 | + require_once( "$IP/includes/AutoLoader.php" ); |
| 95 | + |
93 | 96 | # Start profiler |
94 | 97 | # FIXME: rewrite wfProfileIn/wfProfileOut so that they can work in compiled mode |
| 98 | + require_once( "$IP/includes/profiler/Profiler.php" ); |
95 | 99 | if ( file_exists( "$IP/StartProfiler.php" ) ) { |
96 | 100 | require_once( "$IP/StartProfiler.php" ); |
97 | | - } else { |
98 | | - require_once( "$IP/includes/profiler/ProfilerStub.php" ); |
99 | 101 | } |
100 | 102 | |
101 | 103 | # Load up some global defines. |
102 | 104 | 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" ); |
106 | 105 | } |
107 | 106 | |
108 | 107 | wfProfileIn( 'WebStart.php-conf' ); |
Index: trunk/phase3/RELEASE-NOTES |
— | — | @@ -65,6 +65,8 @@ |
66 | 66 | math conversion after upgrading, obtain the Math extension from SVN or from |
67 | 67 | http://www.mediawiki.org/wiki/Extension:Math and add to LocalSettings.php: |
68 | 68 | require_once "$IP/extensions/Math/Math.php"; |
| 69 | +* $wgProfiler is now a configuration array, see StartProfiler.sample for details |
| 70 | +* $wgProfiling has been removed |
69 | 71 | |
70 | 72 | === New features in 1.18 === |
71 | 73 | * (bug 8130) Query pages should limit to content namespaces, not just main |