* Added Profiler::addInitialStack() to separate definitions of local variables and...
authorAlexandre Emsenhuber <ialex.wiki@gmail.com>
Fri, 23 Mar 2012 15:25:22 +0000 (16:25 +0100)
committerAlexandre Emsenhuber <ialex.wiki@gmail.com>
Fri, 23 Mar 2012 15:25:22 +0000 (16:25 +0100)
* Use it in ProfilerSimple and call $this->profileOut() there to factorise common code

Change-Id: I2eb74088c6087a7c2dd32af1a1f600f327178c67

includes/profiler/Profiler.php
includes/profiler/ProfilerSimple.php

index b1ed9b6..f6d8b3a 100644 (file)
@@ -48,14 +48,7 @@ class Profiler {
                        $this->mProfileID = $params['profileID'];
                }
 
-               // Push an entry for the pre-profile setup time onto the stack
-               $initial = $this->getInitialTime();
-               if ( $initial !== null ) {
-                       $this->mWorkStack[] = array( '-total', 0, $initial, 0 );
-                       $this->mStack[] = array( '-setup', 1, $initial, 0, $this->getTime(), 0 );
-               } else {
-                       $this->profileIn( '-total' );
-               }
+               $this->addInitialStack();
        }
 
        /**
@@ -114,6 +107,20 @@ class Profiler {
                }
        }
 
+       /**
+        * Add the inital item in the stack.
+        */
+       protected function addInitialStack() {
+               // Push an entry for the pre-profile setup time onto the stack
+               $initial = $this->getInitialTime();
+               if ( $initial !== null ) {
+                       $this->mWorkStack[] = array( '-total', 0, $initial, 0 );
+                       $this->mStack[] = array( '-setup', 1, $initial, 0, $this->getTime(), 0 );
+               } else {
+                       $this->profileIn( '-total' );
+               }
+       }
+
        /**
         * Called by wfProfieIn()
         *
index 055a0ea..df37363 100644 (file)
@@ -15,32 +15,20 @@ class ProfilerSimple extends Profiler {
        var $zeroEntry = array('cpu'=> 0.0, 'cpu_sq' => 0.0, 'real' => 0.0, 'real_sq' => 0.0, 'count' => 0);
        var $errorEntry;
 
-       function __construct( $params ) {
+       protected function addInitialStack() {
                global $wgRequestTime, $wgRUstart;
-               parent::__construct( $params );
 
                $this->errorEntry = $this->zeroEntry;
                $this->errorEntry['count'] = 1;
 
-               if (!empty($wgRequestTime) && !empty($wgRUstart)) {
-                       # Remove the -total entry from parent::__construct
-                       $this->mWorkStack = array();
+               if ( !empty( $wgRequestTime ) && !empty( $wgRUstart ) ) {
+                       $initialCpu = $this->getCpuTime( $wgRUstart );
+                       $this->mWorkStack[] = array( '-total', 0, $wgRequestTime, $initialCpu );
+                       $this->mWorkStack[] = array( '-setup', 1, $wgRequestTime, $initialCpu );
 
-                       $this->mWorkStack[] = array( '-total', 0, $wgRequestTime,$this->getCpuTime($wgRUstart));
-
-                       $elapsedcpu = $this->getCpuTime() - $this->getCpuTime($wgRUstart);
-                       $elapsedreal = microtime(true) - $wgRequestTime;
-
-                       $entry =& $this->mCollated["-setup"];
-                       if (!is_array($entry)) {
-                               $entry = $this->zeroEntry;
-                               $this->mCollated["-setup"] =& $entry;
-                       }
-                       $entry['cpu'] += $elapsedcpu;
-                       $entry['cpu_sq'] += $elapsedcpu*$elapsedcpu;
-                       $entry['real'] += $elapsedreal;
-                       $entry['real_sq'] += $elapsedreal*$elapsedreal;
-                       $entry['count']++;
+                       $this->profileOut( '-setup' );
+               } else {
+                       $this->profileIn( '-total' );
                }
        }