r109429 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r109428‎ | r109429 | r109430 >
Date:20:01, 18 January 2012
Author:ialex
Status:ok
Tags:
Comment:
Make time of '-total' item correct if using 'user' time metric
Modified paths:
  • /trunk/phase3/includes/profiler/Profiler.php (modified) (history)

Diff [purge]

Index: trunk/phase3/includes/profiler/Profiler.php
@@ -41,20 +41,21 @@
4242 private static $__instance = null;
4343
4444 function __construct( $params ) {
45 - // Push an entry for the pre-profile setup time onto the stack
46 - global $wgRequestTime;
47 - if ( !empty( $wgRequestTime ) ) {
48 - $this->mWorkStack[] = array( '-total', 0, $wgRequestTime, 0 );
49 - $this->mStack[] = array( '-setup', 1, $wgRequestTime, 0, microtime(true), 0 );
50 - } else {
51 - $this->profileIn( '-total' );
52 - }
5345 if ( isset( $params['timeMetric'] ) ) {
5446 $this->mTimeMetric = $params['timeMetric'];
5547 }
5648 if ( isset( $params['profileID'] ) ) {
5749 $this->mProfileID = $params['profileID'];
5850 }
 51+
 52+ // Push an entry for the pre-profile setup time onto the stack
 53+ $initial = $this->getInitialTime();
 54+ if ( $initial !== null ) {
 55+ $this->mWorkStack[] = array( '-total', 0, $initial, 0 );
 56+ $this->mStack[] = array( '-setup', 1, $initial, 0, $this->getTime(), 0 );
 57+ } else {
 58+ $this->profileIn( '-total' );
 59+ }
5960 }
6061
6162 /**
@@ -274,6 +275,24 @@
275276 return $ru['ru_utime.tv_sec'] + $ru['ru_utime.tv_usec'] / 1e6;
276277 }
277278
 279+ private function getInitialTime() {
 280+ global $wgRequestTime, $wgRUstart;
 281+
 282+ if ( $this->mTimeMetric === 'user' ) {
 283+ if ( count( $wgRUstart ) ) {
 284+ return $wgRUstart['ru_utime.tv_sec'] + $wgRUstart['ru_utime.tv_usec'] / 1e6;
 285+ } else {
 286+ return null;
 287+ }
 288+ } else {
 289+ if ( empty( $wgRequestTime ) ) {
 290+ return null;
 291+ } else {
 292+ return $wgRequestTime;
 293+ }
 294+ }
 295+ }
 296+
278297 protected function collateData() {
279298 if ( $this->mCollateDone ) {
280299 return;

Status & tagging log