From: Tim Starling Date: Tue, 20 Sep 2011 11:06:46 +0000 (+0000) Subject: * Fixed notices issued from ProfilerSimpleUDP which were due to ProfilerSimple::profi... X-Git-Tag: 1.31.0-rc.0~27536 X-Git-Url: https://git.cyclocoop.org/%242?a=commitdiff_plain;h=f6cfcd59a42438fbfd3c3dde9b7c4bd18b0989a3;p=lhc%2Fweb%2Fwiklou.git * Fixed notices issued from ProfilerSimpleUDP which were due to ProfilerSimple::profileOut() not adding a complete entry to $this->mCollated for a profile error. * 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. --- diff --git a/includes/profiler/ProfilerSimple.php b/includes/profiler/ProfilerSimple.php index 2bfc5e02d4..bbdbec8e10 100644 --- a/includes/profiler/ProfilerSimple.php +++ b/includes/profiler/ProfilerSimple.php @@ -12,10 +12,20 @@ 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;