MediaWiki
REL1_22
|
00001 <?php 00029 class ProfilerSimple extends Profiler { 00030 var $mMinimumTime = 0; 00031 00032 var $zeroEntry = array( 'cpu' => 0.0, 'cpu_sq' => 0.0, 'real' => 0.0, 'real_sq' => 0.0, 'count' => 0 ); 00033 var $errorEntry; 00034 00035 public function isPersistent() { 00036 /* Implement in output subclasses */ 00037 return false; 00038 } 00039 00040 protected function addInitialStack() { 00041 $this->errorEntry = $this->zeroEntry; 00042 $this->errorEntry['count'] = 1; 00043 00044 $initialTime = $this->getInitialTime(); 00045 $initialCpu = $this->getInitialTime( 'cpu' ); 00046 if ( $initialTime !== null && $initialCpu !== null ) { 00047 $this->mWorkStack[] = array( '-total', 0, $initialTime, $initialCpu ); 00048 $this->mWorkStack[] = array( '-setup', 1, $initialTime, $initialCpu ); 00049 00050 $this->profileOut( '-setup' ); 00051 } else { 00052 $this->profileIn( '-total' ); 00053 } 00054 } 00055 00056 function setMinimum( $min ) { 00057 $this->mMinimumTime = $min; 00058 } 00059 00060 function profileIn( $functionname ) { 00061 global $wgDebugFunctionEntry; 00062 if ( $wgDebugFunctionEntry ) { 00063 $this->debug( str_repeat( ' ', count( $this->mWorkStack ) ) . 'Entering ' . $functionname . "\n" ); 00064 } 00065 $this->mWorkStack[] = array( $functionname, count( $this->mWorkStack ), $this->getTime(), $this->getTime( 'cpu' ) ); 00066 } 00067 00068 function profileOut( $functionname ) { 00069 global $wgDebugFunctionEntry; 00070 00071 if ( $wgDebugFunctionEntry ) { 00072 $this->debug( str_repeat( ' ', count( $this->mWorkStack ) - 1 ) . 'Exiting ' . $functionname . "\n" ); 00073 } 00074 00075 list( $ofname, /* $ocount */, $ortime, $octime ) = array_pop( $this->mWorkStack ); 00076 00077 if ( !$ofname ) { 00078 $this->debug( "Profiling error: $functionname\n" ); 00079 } else { 00080 if ( $functionname == 'close' ) { 00081 $message = "Profile section ended by close(): {$ofname}"; 00082 $functionname = $ofname; 00083 $this->debug( "$message\n" ); 00084 $this->mCollated[$message] = $this->errorEntry; 00085 } 00086 elseif ( $ofname != $functionname ) { 00087 $message = "Profiling error: in({$ofname}), out($functionname)"; 00088 $this->debug( "$message\n" ); 00089 $this->mCollated[$message] = $this->errorEntry; 00090 } 00091 $entry =& $this->mCollated[$functionname]; 00092 $elapsedcpu = $this->getTime( 'cpu' ) - $octime; 00093 $elapsedreal = $this->getTime() - $ortime; 00094 if ( !is_array( $entry ) ) { 00095 $entry = $this->zeroEntry; 00096 $this->mCollated[$functionname] =& $entry; 00097 } 00098 $entry['cpu'] += $elapsedcpu; 00099 $entry['cpu_sq'] += $elapsedcpu * $elapsedcpu; 00100 $entry['real'] += $elapsedreal; 00101 $entry['real_sq'] += $elapsedreal * $elapsedreal; 00102 $entry['count']++; 00103 00104 $this->updateTrxProfiling( $functionname, $elapsedreal ); 00105 } 00106 } 00107 00108 public function getFunctionReport() { 00109 /* Implement in output subclasses */ 00110 return ''; 00111 } 00112 00113 public function logData() { 00114 /* Implement in subclasses */ 00115 } 00116 00123 function getCpuTime( $ru = null ) { 00124 wfDeprecated( __METHOD__, '1.20' ); 00125 00126 if ( $ru === null ) { 00127 return $this->getTime( 'cpu' ); 00128 } else { 00129 # It theory we should use $ru here, but it always $wgRUstart that is passed here 00130 return $this->getInitialTime( 'cpu' ); 00131 } 00132 } 00133 }