r89206 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r89205‎ | r89206 | r89207 >
Date:06:05, 31 May 2011
Author:tstarling
Status:resolved (Comments)
Tags:
Comment:
* 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 (modified) (history)
  • /trunk/phase3/includes/WebStart.php (modified) (history)
  • /trunk/phase3/includes/profiler/Profiler.php (modified) (history)
  • /trunk/phase3/includes/profiler/ProfilerStub.php (modified) (history)

Diff [purge]

Index: trunk/phase3/StartProfiler.sample
@@ -1,10 +1,8 @@
22 <?php
33
4 -require_once( dirname( __FILE__ ) . '/includes/profiler/ProfilerStub.php' );
5 -
64 /**
75 * To use a profiler, copy this file to StartProfiler.php,
8 - * delete the PHP line above, and add something like this:
 6+ * and add something like this:
97 *
108 * $wgProfiler['class'] = 'Profiler';
119 *
Index: trunk/phase3/includes/profiler/ProfilerStub.php
@@ -5,57 +5,11 @@
66 * @ingroup Profiler
77 */
88 class ProfilerStub extends Profiler {
9 -
10 - /**
11 - * is setproctitle function available?
12 - * @var bool
13 - */
14 - private $haveProctitle;
15 - private $hackWhere = array();
16 -
17 - /**
18 - * Constructor. Check for proctitle.
19 - */
20 - public function __construct() {
21 - $this->haveProctitle = function_exists( 'setproctitle' );
22 - }
23 -
249 public function isStub() {
2510 return true;
2611 }
27 -
28 - /**
29 - * Begin profiling of a function
30 - * @param $fn string
31 - */
32 - public function profileIn( $fn ) {
33 - global $wgDBname;
34 - if( $this->haveProctitle ){
35 - $this->hackWhere[] = $fn;
36 - setproctitle( $fn . " [$wgDBname]" );
37 - }
38 - }
39 -
40 - /**
41 - * Stop profiling of a function
42 - * @param $fn string
43 - */
44 - public function profileOut( $fn ) {
45 - global $wgDBname;
46 - if( !$this->haveProctitle ) {
47 - return;
48 - }
49 - if( count( $this->hackWhere ) ) {
50 - array_pop( $this->hackWhere );
51 - }
52 - if( count( $this->hackWhere ) ) {
53 - setproctitle( $this->hackWhere[count( $this->hackWhere )-1] . " [$wgDBname]" );
54 - }
55 - }
56 -
57 - /**
58 - * Does nothing, just for compatibility
59 - */
 12+ public function profileIn( $fn ) {}
 13+ public function profileOut( $fn ) {}
6014 public function getOutput() {}
6115 public function close() {}
6216 }
Index: trunk/phase3/includes/profiler/Profiler.php
@@ -8,20 +8,14 @@
99 */
1010
1111 /**
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 -);
19 -
20 -/**
2112 * Begin profiling of a function
2213 * @param $functionname String: name of the function we will profile
2314 */
2415 function wfProfileIn( $functionname ) {
25 - Profiler::instance()->profileIn( $functionname );
 16+ global $wgProfiler;
 17+ if ( isset( $wgProfiler['class'] ) ) {
 18+ Profiler::instance()->profileIn( $functionname );
 19+ }
2620 }
2721
2822 /**
@@ -29,7 +23,10 @@
3024 * @param $functionname String: name of the function we have profiled
3125 */
3226 function wfProfileOut( $functionname = 'missing' ) {
33 - Profiler::instance()->profileOut( $functionname );
 27+ global $wgProfiler;
 28+ if ( isset( $wgProfiler['class'] ) ) {
 29+ Profiler::instance()->profileOut( $functionname );
 30+ }
3431 }
3532
3633 /**
@@ -40,11 +37,12 @@
4138 var $mStack = array (), $mWorkStack = array (), $mCollated = array ();
4239 var $mCalls = array (), $mTotals = array ();
4340 var $mTemplated = false;
 41+ var $mTimeMetric = 'wall';
4442 private $mCollateDone = false;
4543 protected $mProfileID = false;
4644 private static $__instance = null;
4745
48 - function __construct() {
 46+ function __construct( $params ) {
4947 // Push an entry for the pre-profile setup time onto the stack
5048 global $wgRequestTime;
5149 if ( !empty( $wgRequestTime ) ) {
@@ -53,6 +51,9 @@
5452 } else {
5553 $this->profileIn( '-total' );
5654 }
 55+ if ( isset( $params['timeMetric'] ) ) {
 56+ $this->mTimeMetric = $params['timeMetric'];
 57+ }
5758 }
5859
5960 /**
@@ -63,14 +64,13 @@
6465 if( is_null( self::$__instance ) ) {
6566 global $wgProfiler;
6667 if( is_array( $wgProfiler ) ) {
67 - $class = $wgProfiler['class'];
 68+ $class = isset( $wgProfiler['class'] ) ? $wgProfiler['class'] : 'ProfilerStub';
6869 self::$__instance = new $class( $wgProfiler );
6970 } elseif( $wgProfiler instanceof Profiler ) {
7071 self::$__instance = $wgProfiler; // back-compat
7172 } else {
7273 self::$__instance = new ProfilerStub;
7374 }
74 -
7575 }
7676 return self::$__instance;
7777 }
@@ -253,8 +253,11 @@
254254 }
255255
256256 function getTime() {
257 - return microtime(true);
258 - #return $this->getUserTime();
 257+ if ( $this->mTimeMetric === 'user' ) {
 258+ return $this->getUserTime();
 259+ } else {
 260+ return microtime(true);
 261+ }
259262 }
260263
261264 function getUserTime() {
@@ -474,7 +477,7 @@
475478 * @param $s String to output
476479 */
477480 function debug( $s ) {
478 - if( function_exists( 'wfDebug' ) ) {
 481+ if( defined( 'MW_COMPILED' ) || function_exists( 'wfDebug' ) ) {
479482 wfDebug( $s );
480483 }
481484 }
Index: trunk/phase3/includes/WebStart.php
@@ -81,17 +81,19 @@
8282 # Start the autoloader, so that extensions can derive classes from core files
8383 require_once( "$IP/includes/AutoLoader.php" );
8484
85 - # Start profiler
86 - # @todo FIXME: Rewrite wfProfileIn/wfProfileOut so that they can work in compiled mode
 85+ # Load the profiler
8786 require_once( "$IP/includes/profiler/Profiler.php" );
88 - if ( file_exists( "$IP/StartProfiler.php" ) ) {
89 - require_once( "$IP/StartProfiler.php" );
90 - }
9187
9288 # Load up some global defines.
9389 require_once( "$IP/includes/Defines.php" );
9490 }
9591
 92+# Start the profiler
 93+$wgProfiler = array();
 94+if ( file_exists( "$IP/StartProfiler.php" ) ) {
 95+ require( "$IP/StartProfiler.php" );
 96+}
 97+
9698 wfProfileIn( 'WebStart.php-conf' );
9799
98100 # Load default settings

Follow-up revisions

RevisionCommit summaryAuthorDate
r89241Fix for r89206, r89218: always supply constructor parameterststarling23:50, 31 May 2011
r97575Back-compat for $wgProfiler set as a class. Fix for r89206demon23:25, 19 September 2011

Comments

#Comment by Platonides (talk | contribs)   15:54, 31 May 2011

PHP Warning: Missing argument 1 for Profiler::__construct(), called in phase3/includes/profiler/Profiler.php on line 72 and defined in trunk/phase3/includes/profiler/Profiler.php on line 45

Maybe it should be function __construct( $params = array() ) ?

What about delaying profiler initialization a few lines and setting $wgProfiler['class'] = 'Profiler'; in LocalSettings instead?

#Comment by Tim Starling (talk | contribs)   23:42, 31 May 2011

LocalSettings.php can easily take the majority of the CPU time on a website, so it's important to profile it.

#Comment by Tim Starling (talk | contribs)   23:51, 31 May 2011

The PHP warning should be fixed now.

Status & tagging log