r14647 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r14646‎ | r14647 | r14648 >
Date:20:13, 7 June 2006
Author:midom
Status:old
Tags:
Comment:
use microtime(true), properly initialize non-existing arrays (avoids warnings :)
Modified paths:
  • /trunk/phase3/includes/ProfilerSimple.php (modified) (history)

Diff [purge]

Index: trunk/phase3/includes/ProfilerSimple.php
@@ -14,12 +14,17 @@
1515 function ProfilerSimple() {
1616 global $wgRequestTime,$wgRUstart;
1717 if (!empty($wgRequestTime) && !empty($wgRUstart)) {
18 - $this->mWorkStack[] = array( '-total', 0, $this->getTime($wgRequestTime),$this->getCpuTime($wgRUstart));
 18+ $this->mWorkStack[] = array( '-total', 0, $wgRequestTime,$this->getCpuTime($wgRUstart));
1919
2020 $elapsedcpu = $this->getCpuTime() - $this->getCpuTime($wgRUstart);
21 - $elapsedreal = $this->getTime() - $this->getTime($wgRequestTime);
 21+ $elapsedreal = microtime(true) - $wgRequestTime;
2222
2323 $entry =& $this->mCollated["-setup"];
 24+ if (!is_array($entry)) {
 25+ $entry = array('cpu'=> 0.0, 'cpu_sq' => 0.0, 'real' => 0.0, 'real_sq' => 0.0, 'count' => 0);
 26+ $this->mCollated[$functionname] =& $entry;
 27+
 28+ }
2429 $entry['cpu'] += $elapsedcpu;
2530 $entry['cpu_sq'] += $elapsedcpu*$elapsedcpu;
2631 $entry['real'] += $elapsedreal;
@@ -33,7 +38,7 @@
3439 if ($wgDebugFunctionEntry) {
3540 $this->debug(str_repeat(' ', count($this->mWorkStack)).'Entering '.$functionname."\n");
3641 }
37 - $this->mWorkStack[] = array($functionname, count( $this->mWorkStack ), $this->getTime(), $this->getCpuTime());
 42+ $this->mWorkStack[] = array($functionname, count( $this->mWorkStack ), microtime(true), $this->getCpuTime());
3843 }
3944
4045 function profileOut($functionname) {
@@ -60,10 +65,13 @@
6166 $this->debug( "$message\n" );
6267 }
6368 $entry =& $this->mCollated[$functionname];
64 -
6569 $elapsedcpu = $this->getCpuTime() - $octime;
66 - $elapsedreal = $this->getTime() - $ortime;
67 -
 70+ $elapsedreal = microtime(true) - $ortime;
 71+ if (!is_array($entry)) {
 72+ $entry = array('cpu'=> 0.0, 'cpu_sq' => 0.0, 'real' => 0.0, 'real_sq' => 0.0, 'count' => 0);
 73+ $this->mCollated[$functionname] =& $entry;
 74+
 75+ }
6876 $entry['cpu'] += $elapsedcpu;
6977 $entry['cpu_sq'] += $elapsedcpu*$elapsedcpu;
7078 $entry['real'] += $elapsedreal;
@@ -83,9 +91,10 @@
8492 return ($ru['ru_utime.tv_sec']+$ru['ru_stime.tv_sec']+($ru['ru_utime.tv_usec']+$ru['ru_stime.tv_usec'])*1e-6);
8593 }
8694
 95+ /* If argument is passed, it assumes that it is dual-format time string, returns proper float time value */
8796 function getTime($time=null) {
8897 if ($time==null)
89 - $time=microtime();
 98+ return microtime(true);
9099 list($a,$b)=explode(" ",$time);
91100 return (float)($a+$b);
92101 }

Status & tagging log