From: Tim Starling Date: Tue, 31 May 2011 06:05:05 +0000 (+0000) Subject: * Made the profiler work in HipHop: X-Git-Tag: 1.31.0-rc.0~29830 X-Git-Url: http://git.cyclocoop.org/%22%20.%20generer_url_ecrire%28%22articles%22%2C%22id_article=%24id_article%22%29%20.%20%22?a=commitdiff_plain;h=a0123d05498adadd63705e04f688c288d4395aca;p=lhc%2Fweb%2Fwiklou.git * 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 --- diff --git a/StartProfiler.sample b/StartProfiler.sample index f55b4d6aaf..6bce634d4e 100644 --- a/StartProfiler.sample +++ b/StartProfiler.sample @@ -1,10 +1,8 @@ '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 @@ function wfProfileIn( $functionname ) { * @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 @@ class Profiler { 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 @@ class Profiler { } else { $this->profileIn( '-total' ); } + if ( isset( $params['timeMetric'] ) ) { + $this->mTimeMetric = $params['timeMetric']; + } } /** @@ -63,14 +64,13 @@ class Profiler { 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 @@ class Profiler { } 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 @@ class Profiler { * @param $s String to output */ function debug( $s ) { - if( function_exists( 'wfDebug' ) ) { + if( defined( 'MW_COMPILED' ) || function_exists( 'wfDebug' ) ) { wfDebug( $s ); } } diff --git a/includes/profiler/ProfilerStub.php b/includes/profiler/ProfilerStub.php index 5c826090e0..58c1975ce0 100644 --- a/includes/profiler/ProfilerStub.php +++ b/includes/profiler/ProfilerStub.php @@ -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() {} }