<?
# This file is only included if profiling is enabled
-$wgDebugProfiling = true;
-
function wfProfileIn( $functionname )
{
global $wgProfiler;
function profileIn( $functionname )
{
+ global $wgDebugFunctionEntry;
+ if ( $wgDebugFunctionEntry && function_exists( "wfDebug" ) ) {
+ wfDebug( "Entering $functionname\n" );
+ }
array_push( $this->mWorkStack, array($functionname, count( $this->mWorkStack ), microtime() ) );
}
function profileOut( $functionname)
{
- global $wgDebugProfiling;
+ global $wgDebugProfiling, $wgDebugFunctionEntry;
+ if ( $wgDebugFunctionEntry && function_exists( "wfDebug" ) ) {
+ wfDebug( "Exiting $functionname\n" );
+ }
+
$bit = array_pop( $this->mWorkStack );
- if ( $wgDebugProfiling ) {
- if ( $functionname == "close" ) {
- wfDebug( "Profile section ended by close(): {$bit[0]}\n" );
- } elseif ( $bit[0] != $functionname ) {
- wfDebug( "Profiling error: in({$bit[0]}), out($functionname)\n" );
+ if ( !$bit ) {
+ wfDebug( "Profiling error, !\$bit: $functionname\n" );
+ } else {
+ if ( $wgDebugProfiling ) {
+ if ( $functionname == "close" ) {
+ wfDebug( "Profile section ended by close(): {$bit[0]}\n" );
+ } elseif ( $bit[0] != $functionname ) {
+ wfDebug( "Profiling error: in({$bit[0]}), out($functionname)\n" );
+ }
}
+ array_push( $bit, microtime() );
+ array_push( $this->mStack, $bit );
}
- array_push( $bit, microtime() );
- array_push( $this->mStack, $bit );
}
function close()
if( !count( $this->mStack ) ) {
return "No profiling output\n";
}
-
- $format = "%-49s %6d %6.3f %6.3f %6.3f%%\n";
- $titleFormat = "%-49s %9s %9s %9s %9s\n";
+ $width = 125;
+ $format = "%-" . ($width - 28) . "s %6d %6.3f %6.3f %6.3f%%\n";
+ $titleFormat = "%-" . ($width - 28) . "s %9s %9s %9s %9s\n";
$prof = "\nProfiling data\n";
$prof .= sprintf( $titleFormat, "Name", "Calls", "Total", "Each", "%" );
$this->mCollated = array();
$this->mCalls = array();
- $total = 0;
# Estimate profiling overhead
$profileCount = count( $this->mStack );
+ wfProfileIn( "-overhead-total" );
for ($i=0; $i<$profileCount ; $i++) {
- wfProfileIn( "--profiling overhead--" );
- wfProfileOut( "--profiling overhead--" );
+ wfProfileIn( "-overhead-internal" );
+ wfProfileOut( "-overhead-internal" );
}
+ wfProfileOut( "-overhead-total" );
# Collate
foreach ( $this->mStack as $entry ) {
$elapsed = $end - $start;
$this->mCollated[$fname] += $elapsed;
$this->mCalls[$fname] ++;
-
- if ( $fname != "--profiling overhead--" ) {
- $total += $elapsed;
- }
}
-
- $overhead = $this->mCollated["--profiling overhead--"] / $this->mCalls["--profiling overhead--"];
-
+
+ $total = $this->mCollated["-total"];
+ $overhead = $this->mCollated["-overhead-internal"] / $profileCount;
+ $this->mCalls["-overhead-total"] = $profileCount;
+
# Output
foreach ( $this->mCollated as $fname => $elapsed ) {
$calls = $this->mCalls[$fname];
# Adjust for overhead
- if ( $fname != "--profiling overhead--" ) {
+ if ( $fname[0] != "-" ) {
$elapsed -= $overhead * $calls;
}
}
$wgProfiler = new Profiler();
+$wgProfiler->profileIn( "-total" );
?>