From 36fe3f01e68a681f3990ba0fa67cd42d74f87ca8 Mon Sep 17 00:00:00 2001 From: Alexandre Emsenhuber Date: Wed, 18 Jan 2012 20:01:46 +0000 Subject: [PATCH] Make time of '-total' item correct if using 'user' time metric --- includes/profiler/Profiler.php | 35 ++++++++++++++++++++++++++-------- 1 file changed, 27 insertions(+), 8 deletions(-) diff --git a/includes/profiler/Profiler.php b/includes/profiler/Profiler.php index 6deac89333..dadd14267f 100644 --- a/includes/profiler/Profiler.php +++ b/includes/profiler/Profiler.php @@ -41,20 +41,21 @@ class Profiler { private static $__instance = null; function __construct( $params ) { - // Push an entry for the pre-profile setup time onto the stack - global $wgRequestTime; - if ( !empty( $wgRequestTime ) ) { - $this->mWorkStack[] = array( '-total', 0, $wgRequestTime, 0 ); - $this->mStack[] = array( '-setup', 1, $wgRequestTime, 0, microtime(true), 0 ); - } else { - $this->profileIn( '-total' ); - } if ( isset( $params['timeMetric'] ) ) { $this->mTimeMetric = $params['timeMetric']; } if ( isset( $params['profileID'] ) ) { $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' ); + } } /** @@ -274,6 +275,24 @@ class Profiler { return $ru['ru_utime.tv_sec'] + $ru['ru_utime.tv_usec'] / 1e6; } + private function getInitialTime() { + global $wgRequestTime, $wgRUstart; + + if ( $this->mTimeMetric === 'user' ) { + if ( count( $wgRUstart ) ) { + return $wgRUstart['ru_utime.tv_sec'] + $wgRUstart['ru_utime.tv_usec'] / 1e6; + } else { + return null; + } + } else { + if ( empty( $wgRequestTime ) ) { + return null; + } else { + return $wgRequestTime; + } + } + } + protected function collateData() { if ( $this->mCollateDone ) { return; -- 2.20.1