MediaWiki
REL1_23
|
00001 <?php 00029 class ProfilerSimple extends Profiler { 00030 var $mMinimumTime = 0; 00031 00032 var $errorEntry; 00033 00034 public function getZeroEntry() { 00035 return array( 00036 'cpu' => 0.0, 00037 'cpu_sq' => 0.0, 00038 'real' => 0.0, 00039 'real_sq' => 0.0, 00040 'count' => 0 00041 ); 00042 } 00043 00044 public function getErrorEntry() { 00045 $entry = $this->getZeroEntry(); 00046 $entry['count'] = 1; 00047 return $entry; 00048 } 00049 00050 public function updateEntry( $name, $elapsedCpu, $elapsedReal ) { 00051 $entry =& $this->mCollated[$name]; 00052 if ( !is_array( $entry ) ) { 00053 $entry = $this->getZeroEntry(); 00054 $this->mCollated[$name] =& $entry; 00055 } 00056 $entry['cpu'] += $elapsedCpu; 00057 $entry['cpu_sq'] += $elapsedCpu * $elapsedCpu; 00058 $entry['real'] += $elapsedReal; 00059 $entry['real_sq'] += $elapsedReal * $elapsedReal; 00060 $entry['count']++; 00061 } 00062 00063 public function isPersistent() { 00064 /* Implement in output subclasses */ 00065 return false; 00066 } 00067 00068 protected function addInitialStack() { 00069 $this->errorEntry = $this->getErrorEntry(); 00070 00071 $initialTime = $this->getInitialTime(); 00072 $initialCpu = $this->getInitialTime( 'cpu' ); 00073 if ( $initialTime !== null && $initialCpu !== null ) { 00074 $this->mWorkStack[] = array( '-total', 0, $initialTime, $initialCpu ); 00075 $this->mWorkStack[] = array( '-setup', 1, $initialTime, $initialCpu ); 00076 00077 $this->profileOut( '-setup' ); 00078 } else { 00079 $this->profileIn( '-total' ); 00080 } 00081 } 00082 00083 function setMinimum( $min ) { 00084 $this->mMinimumTime = $min; 00085 } 00086 00087 function profileIn( $functionname ) { 00088 global $wgDebugFunctionEntry; 00089 if ( $wgDebugFunctionEntry ) { 00090 $this->debug( str_repeat( ' ', count( $this->mWorkStack ) ) . 'Entering ' . $functionname . "\n" ); 00091 } 00092 $this->mWorkStack[] = array( $functionname, count( $this->mWorkStack ), $this->getTime(), $this->getTime( 'cpu' ) ); 00093 } 00094 00095 function profileOut( $functionname ) { 00096 global $wgDebugFunctionEntry; 00097 00098 if ( $wgDebugFunctionEntry ) { 00099 $this->debug( str_repeat( ' ', count( $this->mWorkStack ) - 1 ) . 'Exiting ' . $functionname . "\n" ); 00100 } 00101 00102 list( $ofname, /* $ocount */, $ortime, $octime ) = array_pop( $this->mWorkStack ); 00103 00104 if ( !$ofname ) { 00105 $this->debugGroup( 'profileerror', "Profiling error: $functionname" ); 00106 } else { 00107 if ( $functionname == 'close' ) { 00108 if ( $ofname != '-total' ) { 00109 $message = "Profile section ended by close(): {$ofname}"; 00110 $this->debugGroup( 'profileerror', $message ); 00111 $this->mCollated[$message] = $this->errorEntry; 00112 } 00113 $functionname = $ofname; 00114 } elseif ( $ofname != $functionname ) { 00115 $message = "Profiling error: in({$ofname}), out($functionname)"; 00116 $this->debugGroup( 'profileerror', $message ); 00117 $this->mCollated[$message] = $this->errorEntry; 00118 } 00119 $elapsedcpu = $this->getTime( 'cpu' ) - $octime; 00120 $elapsedreal = $this->getTime() - $ortime; 00121 $this->updateEntry( $functionname, $elapsedcpu, $elapsedreal ); 00122 $this->updateTrxProfiling( $functionname, $elapsedreal ); 00123 } 00124 } 00125 00126 public function getRawData() { 00127 // Calling the method of the parent class results in fatal error. 00128 // @todo Implement this correctly. 00129 return array(); 00130 } 00131 00132 public function getFunctionReport() { 00133 /* Implement in output subclasses */ 00134 return ''; 00135 } 00136 00137 public function logData() { 00138 /* Implement in subclasses */ 00139 } 00140 }