Index: trunk/phase3/StartProfiler.sample |
— | — | @@ -1,10 +1,8 @@ |
2 | 2 | <?php |
3 | 3 | |
4 | | -require_once( dirname( __FILE__ ) . '/includes/profiler/ProfilerStub.php' ); |
5 | | - |
6 | 4 | /** |
7 | 5 | * 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: |
9 | 7 | * |
10 | 8 | * $wgProfiler['class'] = 'Profiler'; |
11 | 9 | * |
Index: trunk/phase3/includes/profiler/ProfilerStub.php |
— | — | @@ -5,57 +5,11 @@ |
6 | 6 | * @ingroup Profiler |
7 | 7 | */ |
8 | 8 | 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 | | - |
24 | 9 | public function isStub() { |
25 | 10 | return true; |
26 | 11 | } |
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 ) {} |
60 | 14 | public function getOutput() {} |
61 | 15 | public function close() {} |
62 | 16 | } |
Index: trunk/phase3/includes/profiler/Profiler.php |
— | — | @@ -8,20 +8,14 @@ |
9 | 9 | */ |
10 | 10 | |
11 | 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 | | -); |
19 | | - |
20 | | -/** |
21 | 12 | * Begin profiling of a function |
22 | 13 | * @param $functionname String: name of the function we will profile |
23 | 14 | */ |
24 | 15 | function wfProfileIn( $functionname ) { |
25 | | - Profiler::instance()->profileIn( $functionname ); |
| 16 | + global $wgProfiler; |
| 17 | + if ( isset( $wgProfiler['class'] ) ) { |
| 18 | + Profiler::instance()->profileIn( $functionname ); |
| 19 | + } |
26 | 20 | } |
27 | 21 | |
28 | 22 | /** |
— | — | @@ -29,7 +23,10 @@ |
30 | 24 | * @param $functionname String: name of the function we have profiled |
31 | 25 | */ |
32 | 26 | function wfProfileOut( $functionname = 'missing' ) { |
33 | | - Profiler::instance()->profileOut( $functionname ); |
| 27 | + global $wgProfiler; |
| 28 | + if ( isset( $wgProfiler['class'] ) ) { |
| 29 | + Profiler::instance()->profileOut( $functionname ); |
| 30 | + } |
34 | 31 | } |
35 | 32 | |
36 | 33 | /** |
— | — | @@ -40,11 +37,12 @@ |
41 | 38 | var $mStack = array (), $mWorkStack = array (), $mCollated = array (); |
42 | 39 | var $mCalls = array (), $mTotals = array (); |
43 | 40 | var $mTemplated = false; |
| 41 | + var $mTimeMetric = 'wall'; |
44 | 42 | private $mCollateDone = false; |
45 | 43 | protected $mProfileID = false; |
46 | 44 | private static $__instance = null; |
47 | 45 | |
48 | | - function __construct() { |
| 46 | + function __construct( $params ) { |
49 | 47 | // Push an entry for the pre-profile setup time onto the stack |
50 | 48 | global $wgRequestTime; |
51 | 49 | if ( !empty( $wgRequestTime ) ) { |
— | — | @@ -53,6 +51,9 @@ |
54 | 52 | } else { |
55 | 53 | $this->profileIn( '-total' ); |
56 | 54 | } |
| 55 | + if ( isset( $params['timeMetric'] ) ) { |
| 56 | + $this->mTimeMetric = $params['timeMetric']; |
| 57 | + } |
57 | 58 | } |
58 | 59 | |
59 | 60 | /** |
— | — | @@ -63,14 +64,13 @@ |
64 | 65 | if( is_null( self::$__instance ) ) { |
65 | 66 | global $wgProfiler; |
66 | 67 | if( is_array( $wgProfiler ) ) { |
67 | | - $class = $wgProfiler['class']; |
| 68 | + $class = isset( $wgProfiler['class'] ) ? $wgProfiler['class'] : 'ProfilerStub'; |
68 | 69 | self::$__instance = new $class( $wgProfiler ); |
69 | 70 | } elseif( $wgProfiler instanceof Profiler ) { |
70 | 71 | self::$__instance = $wgProfiler; // back-compat |
71 | 72 | } else { |
72 | 73 | self::$__instance = new ProfilerStub; |
73 | 74 | } |
74 | | - |
75 | 75 | } |
76 | 76 | return self::$__instance; |
77 | 77 | } |
— | — | @@ -253,8 +253,11 @@ |
254 | 254 | } |
255 | 255 | |
256 | 256 | 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 | + } |
259 | 262 | } |
260 | 263 | |
261 | 264 | function getUserTime() { |
— | — | @@ -474,7 +477,7 @@ |
475 | 478 | * @param $s String to output |
476 | 479 | */ |
477 | 480 | function debug( $s ) { |
478 | | - if( function_exists( 'wfDebug' ) ) { |
| 481 | + if( defined( 'MW_COMPILED' ) || function_exists( 'wfDebug' ) ) { |
479 | 482 | wfDebug( $s ); |
480 | 483 | } |
481 | 484 | } |
Index: trunk/phase3/includes/WebStart.php |
— | — | @@ -81,17 +81,19 @@ |
82 | 82 | # Start the autoloader, so that extensions can derive classes from core files |
83 | 83 | require_once( "$IP/includes/AutoLoader.php" ); |
84 | 84 | |
85 | | - # Start profiler |
86 | | - # @todo FIXME: Rewrite wfProfileIn/wfProfileOut so that they can work in compiled mode |
| 85 | + # Load the profiler |
87 | 86 | require_once( "$IP/includes/profiler/Profiler.php" ); |
88 | | - if ( file_exists( "$IP/StartProfiler.php" ) ) { |
89 | | - require_once( "$IP/StartProfiler.php" ); |
90 | | - } |
91 | 87 | |
92 | 88 | # Load up some global defines. |
93 | 89 | require_once( "$IP/includes/Defines.php" ); |
94 | 90 | } |
95 | 91 | |
| 92 | +# Start the profiler |
| 93 | +$wgProfiler = array(); |
| 94 | +if ( file_exists( "$IP/StartProfiler.php" ) ) { |
| 95 | + require( "$IP/StartProfiler.php" ); |
| 96 | +} |
| 97 | + |
96 | 98 | wfProfileIn( 'WebStart.php-conf' ); |
97 | 99 | |
98 | 100 | # Load default settings |