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
This commit is contained in:
Chad Horohoe 2011-04-16 19:00:54 +00:00
parent c962c5c35c
commit 5a6d1ee2d3
11 changed files with 57 additions and 68 deletions

View file

@ -65,6 +65,8 @@ PHP if you have not done so prior to upgrading MediaWiki.
math conversion after upgrading, obtain the Math extension from SVN or from
http://www.mediawiki.org/wiki/Extension:Math and add to LocalSettings.php:
require_once "$IP/extensions/Math/Math.php";
* $wgProfiler is now a configuration array, see StartProfiler.sample for details
* $wgProfiling has been removed
=== New features in 1.18 ===
* (bug 8130) Query pages should limit to content namespaces, not just main

View file

@ -6,15 +6,13 @@ require_once( dirname(__FILE__).'/includes/ProfilerStub.php' );
* To use a profiler, copy this file to StartProfiler.php,
* delete the PHP line above, and add something like this:
*
* require_once( dirname(__FILE__).'/includes/Profiler.php' );
* $wgProfiler = new Profiler;
* $wgProfiler['class'] = 'Profiler';
*
* Or for a sampling profiler:
* if ( !mt_rand( 0, 100 ) ) {
* require_once( dirname(__FILE__).'/includes/Profiler.php' );
* $wgProfiler = new Profiler;
* $wgProfiler['class'] = 'Profiler';
* } else {
* require_once( dirname(__FILE__).'/includes/ProfilerStub.php' );
* $wgProfiler['class'] = 'ProfilerStub';
* }
*
* Configuration of the profiler output can be done in LocalSettings.php

View file

@ -89,19 +89,18 @@ if ( !defined( 'MW_COMPILED' ) ) {
# Get MWInit class
require_once( "$IP/includes/Init.php" );
# Start the autoloader, so that extensions can derive classes from core files
require_once( "$IP/includes/AutoLoader.php" );
# Start profiler
# FIXME: rewrite wfProfileIn/wfProfileOut so that they can work in compiled mode
require_once( "$IP/includes/profiler/Profiler.php" );
if ( file_exists( "$IP/StartProfiler.php" ) ) {
require_once( "$IP/StartProfiler.php" );
} else {
require_once( "$IP/includes/profiler/ProfilerStub.php" );
}
# Load up some global defines.
require_once( "$IP/includes/Defines.php" );
# Start the autoloader, so that extensions can derive classes from core files
require_once( "$IP/includes/AutoLoader.php" );
}
wfProfileIn( 'WebStart.php-conf' );

View file

@ -7,16 +7,21 @@
* This file is only included if profiling is enabled
*/
/** backward compatibility */
$wgProfiling = true;
/**
* Default profiling configuration. Permitted keys are:
* class : Name of Profiler or subclass to use for profiling
* visible : Whether to output the profile info [ProfilerSimpleText only]
*/
$wgProfiler = array(
'class' => 'ProfilerStub',
);
/**
* Begin profiling of a function
* @param $functionname String: name of the function we will profile
*/
function wfProfileIn( $functionname ) {
global $wgProfiler;
$wgProfiler->profileIn( $functionname );
Profiler::instance()->profileIn( $functionname );
}
/**
@ -24,24 +29,21 @@ function wfProfileIn( $functionname ) {
* @param $functionname String: name of the function we have profiled
*/
function wfProfileOut( $functionname = 'missing' ) {
global $wgProfiler;
$wgProfiler->profileOut( $functionname );
Profiler::instance()->profileOut( $functionname );
}
/**
* Returns a profiling output to be stored in debug file
*/
function wfGetProfilingOutput() {
global $wgProfiler;
return $wgProfiler->getOutput();
Profiler::instance()->getOutput();
}
/**
* Close opened profiling sections
*/
function wfProfileClose() {
global $wgProfiler;
$wgProfiler->close();
Profiler::instance()->close();
}
if (!function_exists('memory_get_usage')) {
@ -59,6 +61,7 @@ class Profiler {
var $mStack = array (), $mWorkStack = array (), $mCollated = array ();
var $mCalls = array (), $mTotals = array ();
var $mTemplated = false;
private static $__instance = null;
function __construct() {
// Push an entry for the pre-profile setup time onto the stack
@ -71,14 +74,33 @@ class Profiler {
}
}
/**
* Singleton
* @return Profiler
*/
public static function instance() {
if( is_null( self::$__instance ) ) {
global $wgProfiler;
if( is_array( $wgProfiler ) ) {
$class = $wgProfiler['class'];
self::$__instance = new $class( $wgProfiler );
} elseif( $wgProfiler instanceof Profiler ) {
self::$__instance = $wgProfiler; // back-compat
} else {
throw new MWException( '$wgProfiler set to bogus value' );
}
}
return self::$__instance;
}
/**
* Called by wfProfieIn()
*
* @param $functionname String
*/
public function profileIn( $functionname ) {
global $wgDebugFunctionEntry, $wgProfiling;
if( !$wgProfiling ) return;
global $wgDebugFunctionEntry;
if( $wgDebugFunctionEntry ){
$this->debug( str_repeat( ' ', count( $this->mWorkStack ) ) . 'Entering ' . $functionname . "\n" );
}
@ -92,8 +114,7 @@ class Profiler {
* @param $functionname String
*/
public function profileOut($functionname) {
global $wgDebugFunctionEntry, $wgProfiling;
if( !$wgProfiling ) return;
global $wgDebugFunctionEntry;
$memory = memory_get_usage();
$time = $this->getTime();
@ -128,12 +149,6 @@ class Profiler {
* called by wfProfileClose()
*/
public function close() {
global $wgProfiling;
# Avoid infinite loop
if( !$wgProfiling )
return;
while( count( $this->mWorkStack ) ){
$this->profileOut( 'close' );
}

View file

@ -4,10 +4,6 @@
* @ingroup Profiler
*/
if ( !class_exists( 'Profiler' ) ) {
require_once( dirname( __FILE__ ) . '/Profiler.php' );
}
/**
* Simple profiler base class.
* @todo document methods (?)

View file

@ -4,18 +4,13 @@
* @ingroup Profiler
*/
if ( !class_exists( 'ProfilerSimple' ) ) {
require_once( dirname( __FILE__ ) . '/ProfilerSimple.php' );
}
/**
* The least sophisticated profiler output class possible, view your source! :)
*
* Put the following 3 lines in StartProfiler.php:
* Put the following 2 lines in StartProfiler.php:
*
* require_once( dirname( __FILE__ ) . '/includes/ProfilerSimpleText.php' );
* $wgProfiler = new ProfilerSimpleText;
* $wgProfiler->visible=true;
* $wgProfiler['class'] = 'ProfilerSimpleText';
* $wgProfiler['visible'] = true;
*
* @ingroup Profiler
*/
@ -23,6 +18,13 @@ class ProfilerSimpleText extends ProfilerSimple {
public $visible=false; /* Show as <PRE> or <!-- ? */
static private $out;
public function __construct( $profileConfig ) {
if( isset( $profileConfig['visible'] ) && $profileConfig['visible'] ) {
$this->visible = true;
}
parent::__construct();
}
function getFunctionReport() {
if($this->mTemplated) {
uasort($this->mCollated,array('self','sort'));

View file

@ -4,10 +4,6 @@
* @ingroup Profiler
*/
if ( !class_exists( 'ProfilerSimple' ) ) {
require_once( dirname( __FILE__ ) . '/ProfilerSimple.php' );
}
/**
* Execution trace
* @todo document methods (?)

View file

@ -4,10 +4,6 @@
* @ingroup Profiler
*/
if ( !class_exists( 'ProfilerSimple' ) ) {
require_once( dirname( __FILE__ ) . '/ProfilerSimple.php' );
}
/**
* ProfilerSimpleUDP class, that sends out messages for 'udpprofile' daemon
* (the one from mediawiki/trunk/udpprofile SVN )

View file

@ -4,10 +4,6 @@
* @file
* @ingroup Profiler
*/
if ( !class_exists( 'Profiler' ) ) {
require_once( dirname( __FILE__ ) . '/Profiler.php' );
}
class ProfilerStub extends Profiler {
/**
@ -59,7 +55,3 @@ class ProfilerStub extends Profiler {
public function getOutput() {}
public function close() {}
}
/** backward compatibility */
$wgProfiling = false;
$wgProfiler = new ProfilerStub();

View file

@ -803,7 +803,7 @@ abstract class Maintenance {
*/
public function finalSetup() {
global $wgCommandLineMode, $wgShowSQLErrors, $wgServer;
global $wgProfiling, $wgDBadminuser, $wgDBadminpassword;
global $wgDBadminuser, $wgDBadminpassword;
global $wgDBuser, $wgDBpassword, $wgDBservers, $wgLBFactoryConf;
# Turn off output buffering again, it might have been turned on in the settings files
@ -848,8 +848,6 @@ abstract class Maintenance {
$wgShowSQLErrors = true;
@set_time_limit( 0 );
$this->adjustMemoryLimit();
$wgProfiling = false; // only for Profiler.php mode; avoids OOM errors
}
/**

View file

@ -69,13 +69,8 @@ if ( !defined( 'MW_COMPILED' ) ) {
require_once( "$IP/includes/Init.php" );
}
# Setup the profiler
global $IP;
if ( !defined( 'MW_COMPILED' ) && file_exists( "$IP/StartProfiler.php" ) ) {
require_once( "$IP/StartProfiler.php" );
} else {
require_once( MWInit::compiledPath( 'includes/profiler/ProfilerStub.php' ) );
}
# Stub the profiler
require_once( MWInit::compiledPath( 'includes/profiler/Profiler.php' ) );
// Some other requires
if ( !defined( 'MW_COMPILED' ) ) {