* Fixed notices issued from ProfilerSimpleUDP which were due to ProfilerSimple::profi...
authorTim Starling <tstarling@users.mediawiki.org>
Tue, 20 Sep 2011 11:06:46 +0000 (11:06 +0000)
committerTim Starling <tstarling@users.mediawiki.org>
Tue, 20 Sep 2011 11:06:46 +0000 (11:06 +0000)
* Simplified other points in the code where $this->mCollated entries were added, by using template arrays $this->errorEntry and $this->zeroEntry.
* Fixed double-counting of -total due to a -total entry being added to $this->mWorkStack both by parent::__construct() and ProfilerSimple::__construct().
* Tested against 1.18wmf1 only.

includes/profiler/ProfilerSimple.php

index 2bfc5e0..bbdbec8 100644 (file)
 class ProfilerSimple extends Profiler {
        var $mMinimumTime = 0;
 
+       var $zeroEntry = array('cpu'=> 0.0, 'cpu_sq' => 0.0, 'real' => 0.0, 'real_sq' => 0.0, 'count' => 0);
+       var $errorEntry;
+
        function __construct( $params ) {
                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();
+
                        $this->mWorkStack[] = array( '-total', 0, $wgRequestTime,$this->getCpuTime($wgRUstart));
 
                        $elapsedcpu = $this->getCpuTime() - $this->getCpuTime($wgRUstart);
@@ -23,7 +33,7 @@ class ProfilerSimple extends Profiler {
 
                        $entry =& $this->mCollated["-setup"];
                        if (!is_array($entry)) {
-                               $entry = array('cpu'=> 0.0, 'cpu_sq' => 0.0, 'real' => 0.0, 'real_sq' => 0.0, 'count' => 0);
+                               $entry = $this->zeroEntry;
                                $this->mCollated["-setup"] =& $entry;
                        }
                        $entry['cpu'] += $elapsedcpu;
@@ -62,20 +72,18 @@ class ProfilerSimple extends Profiler {
                                $message = "Profile section ended by close(): {$ofname}";
                                $functionname = $ofname;
                                $this->debug( "$message\n" );
-                               $this->mCollated[$message] = array(
-                                       'real' => 0.0, 'count' => 1);
+                               $this->mCollated[$message] = $this->errorEntry;
                        }
                        elseif ($ofname != $functionname) {
                                $message = "Profiling error: in({$ofname}), out($functionname)";
                                $this->debug( "$message\n" );
-                               $this->mCollated[$message] = array(
-                                       'real' => 0.0, 'count' => 1);
+                               $this->mCollated[$message] = $this->errorEntry;
                        }
                        $entry =& $this->mCollated[$functionname];
                        $elapsedcpu = $this->getCpuTime() - $octime;
                        $elapsedreal = microtime(true) - $ortime;
                        if (!is_array($entry)) {
-                               $entry = array('cpu'=> 0.0, 'cpu_sq' => 0.0, 'real' => 0.0, 'real_sq' => 0.0, 'count' => 0);
+                               $entry = $this->zeroEntry;
                                $this->mCollated[$functionname] =& $entry;
                        }
                        $entry['cpu'] += $elapsedcpu;