http://www.mediawiki.org/wiki/Special:Code/MediaWiki/89206
Revision: 89206
Author: tstarling
Date: 2011-05-31 06:05:05 +0000 (Tue, 31 May 2011)
Log Message:
-----------
* Made the profiler work in HipHop:
** Don't try to set a global variable in the same file as a class definition
(Profiler.php). Set it in WebStart.php instead.
** In StartProfiler.sample, don't use require_once() to get ProfilerStub.
* Removed the setproctitle() stuff from ProfilerStub, the extension is not
maintained and doesn't work with Apache 2.x
* Added an optimisation to wfProfileIn() and wfProfileOut() to reduce the
overhead when profiling is not enabled
* Added the ability to configure in StartProfiler.php whether CPU time or
wall-clock time is used, avoiding recompilation
Modified Paths:
--------------
trunk/phase3/StartProfiler.sample
trunk/phase3/includes/WebStart.php
trunk/phase3/includes/profiler/Profiler.php
trunk/phase3/includes/profiler/ProfilerStub.php
Modified: trunk/phase3/StartProfiler.sample
===================================================================
--- trunk/phase3/StartProfiler.sample 2011-05-31 05:55:06 UTC (rev 89205)
+++ trunk/phase3/StartProfiler.sample 2011-05-31 06:05:05 UTC (rev 89206)
@@ -1,10 +1,8 @@
<?php
-require_once( dirname( __FILE__ ) . '/includes/profiler/ProfilerStub.php' );
-
/**
* To use a profiler, copy this file to StartProfiler.php,
- * delete the PHP line above, and add something like this:
+ * and add something like this:
*
* $wgProfiler['class'] = 'Profiler';
*
Modified: trunk/phase3/includes/WebStart.php
===================================================================
--- trunk/phase3/includes/WebStart.php 2011-05-31 05:55:06 UTC (rev 89205)
+++ trunk/phase3/includes/WebStart.php 2011-05-31 06:05:05 UTC (rev 89206)
@@ -81,17 +81,19 @@
# Start the autoloader, so that extensions can derive classes from core
files
require_once( "$IP/includes/AutoLoader.php" );
- # Start profiler
- # @todo FIXME: Rewrite wfProfileIn/wfProfileOut so that they can work
in compiled mode
+ # Load the profiler
require_once( "$IP/includes/profiler/Profiler.php" );
- if ( file_exists( "$IP/StartProfiler.php" ) ) {
- require_once( "$IP/StartProfiler.php" );
- }
# Load up some global defines.
require_once( "$IP/includes/Defines.php" );
}
+# Start the profiler
+$wgProfiler = array();
+if ( file_exists( "$IP/StartProfiler.php" ) ) {
+ require( "$IP/StartProfiler.php" );
+}
+
wfProfileIn( 'WebStart.php-conf' );
# Load default settings
Modified: trunk/phase3/includes/profiler/Profiler.php
===================================================================
--- trunk/phase3/includes/profiler/Profiler.php 2011-05-31 05:55:06 UTC (rev
89205)
+++ trunk/phase3/includes/profiler/Profiler.php 2011-05-31 06:05:05 UTC (rev
89206)
@@ -8,20 +8,14 @@
*/
/**
- * 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 ) {
- Profiler::instance()->profileIn( $functionname );
+ global $wgProfiler;
+ if ( isset( $wgProfiler['class'] ) ) {
+ Profiler::instance()->profileIn( $functionname );
+ }
}
/**
@@ -29,7 +23,10 @@
* @param $functionname String: name of the function we have profiled
*/
function wfProfileOut( $functionname = 'missing' ) {
- Profiler::instance()->profileOut( $functionname );
+ global $wgProfiler;
+ if ( isset( $wgProfiler['class'] ) ) {
+ Profiler::instance()->profileOut( $functionname );
+ }
}
/**
@@ -40,11 +37,12 @@
var $mStack = array (), $mWorkStack = array (), $mCollated = array ();
var $mCalls = array (), $mTotals = array ();
var $mTemplated = false;
+ var $mTimeMetric = 'wall';
private $mCollateDone = false;
protected $mProfileID = false;
private static $__instance = null;
- function __construct() {
+ function __construct( $params ) {
// Push an entry for the pre-profile setup time onto the stack
global $wgRequestTime;
if ( !empty( $wgRequestTime ) ) {
@@ -53,6 +51,9 @@
} else {
$this->profileIn( '-total' );
}
+ if ( isset( $params['timeMetric'] ) ) {
+ $this->mTimeMetric = $params['timeMetric'];
+ }
}
/**
@@ -63,14 +64,13 @@
if( is_null( self::$__instance ) ) {
global $wgProfiler;
if( is_array( $wgProfiler ) ) {
- $class = $wgProfiler['class'];
+ $class = isset( $wgProfiler['class'] ) ?
$wgProfiler['class'] : 'ProfilerStub';
self::$__instance = new $class( $wgProfiler );
} elseif( $wgProfiler instanceof Profiler ) {
self::$__instance = $wgProfiler; // back-compat
} else {
self::$__instance = new ProfilerStub;
}
-
}
return self::$__instance;
}
@@ -253,8 +253,11 @@
}
function getTime() {
- return microtime(true);
- #return $this->getUserTime();
+ if ( $this->mTimeMetric === 'user' ) {
+ return $this->getUserTime();
+ } else {
+ return microtime(true);
+ }
}
function getUserTime() {
@@ -474,7 +477,7 @@
* @param $s String to output
*/
function debug( $s ) {
- if( function_exists( 'wfDebug' ) ) {
+ if( defined( 'MW_COMPILED' ) || function_exists( 'wfDebug' ) ) {
wfDebug( $s );
}
}
Modified: trunk/phase3/includes/profiler/ProfilerStub.php
===================================================================
--- trunk/phase3/includes/profiler/ProfilerStub.php 2011-05-31 05:55:06 UTC
(rev 89205)
+++ trunk/phase3/includes/profiler/ProfilerStub.php 2011-05-31 06:05:05 UTC
(rev 89206)
@@ -5,57 +5,11 @@
* @ingroup Profiler
*/
class ProfilerStub extends Profiler {
-
- /**
- * is setproctitle function available?
- * @var bool
- */
- private $haveProctitle;
- private $hackWhere = array();
-
- /**
- * Constructor. Check for proctitle.
- */
- public function __construct() {
- $this->haveProctitle = function_exists( 'setproctitle' );
- }
-
public function isStub() {
return true;
}
-
- /**
- * Begin profiling of a function
- * @param $fn string
- */
- public function profileIn( $fn ) {
- global $wgDBname;
- if( $this->haveProctitle ){
- $this->hackWhere[] = $fn;
- setproctitle( $fn . " [$wgDBname]" );
- }
- }
-
- /**
- * Stop profiling of a function
- * @param $fn string
- */
- public function profileOut( $fn ) {
- global $wgDBname;
- if( !$this->haveProctitle ) {
- return;
- }
- if( count( $this->hackWhere ) ) {
- array_pop( $this->hackWhere );
- }
- if( count( $this->hackWhere ) ) {
- setproctitle( $this->hackWhere[count( $this->hackWhere
)-1] . " [$wgDBname]" );
- }
- }
-
- /**
- * Does nothing, just for compatibility
- */
+ public function profileIn( $fn ) {}
+ public function profileOut( $fn ) {}
public function getOutput() {}
public function close() {}
}
_______________________________________________
MediaWiki-CVS mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-cvs