From c7df7ade694d38cddc8ec358fe0453cffd6ef379 Mon Sep 17 00:00:00 2001 From: Alexandre Emsenhuber Date: Fri, 23 Mar 2012 16:25:22 +0100 Subject: [PATCH] * Added Profiler::addInitialStack() to separate definitions of local variables and insertion of the first stacks * Use it in ProfilerSimple and call $this->profileOut() there to factorise common code Change-Id: I2eb74088c6087a7c2dd32af1a1f600f327178c67 --- includes/profiler/Profiler.php | 23 +++++++++++++++-------- includes/profiler/ProfilerSimple.php | 28 ++++++++-------------------- 2 files changed, 23 insertions(+), 28 deletions(-) diff --git a/includes/profiler/Profiler.php b/includes/profiler/Profiler.php index b1ed9b680d..f6d8b3a293 100644 --- a/includes/profiler/Profiler.php +++ b/includes/profiler/Profiler.php @@ -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() * diff --git a/includes/profiler/ProfilerSimple.php b/includes/profiler/ProfilerSimple.php index 055a0ea0f7..df3736396d 100644 --- a/includes/profiler/ProfilerSimple.php +++ b/includes/profiler/ProfilerSimple.php @@ -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' ); } } -- 2.20.1