From 811a084abfedf2a5a797911c6a988b881f7d8b10 Mon Sep 17 00:00:00 2001 From: Alexandre Emsenhuber Date: Sat, 15 Mar 2014 21:43:39 +0100 Subject: [PATCH] New 'profileerror' log group for profiling errors Easier to catch them than if they are in the default debug log. Added Profiler::debugGroup() as wrapper to wfDebugLog(), as there already is Profiler::debug() for wfDebug(), so that there won't be a fatal error if the error happens before the inclusion of GlobalFunctions.php and converted other calls to wfDebugLog() to use it. Change-Id: Ie8481a2e13a94efa0248dd5a36b6b1a22811817e --- includes/profiler/Profiler.php | 26 ++++++++++++++++++++------ includes/profiler/ProfilerMwprof.php | 2 +- includes/profiler/ProfilerSimple.php | 17 +++++++++-------- 3 files changed, 30 insertions(+), 15 deletions(-) diff --git a/includes/profiler/Profiler.php b/includes/profiler/Profiler.php index 235a5ad142..a26ef68609 100644 --- a/includes/profiler/Profiler.php +++ b/includes/profiler/Profiler.php @@ -227,15 +227,17 @@ class Profiler { $bit = array_pop( $this->mWorkStack ); if ( !$bit ) { - $this->debug( "Profiling error, !\$bit: $functionname\n" ); + $this->debugGroup( 'profileerror', "Profiling error, !\$bit: $functionname" ); } else { if ( $functionname == 'close' ) { - $message = "Profile section ended by close(): {$bit[0]}"; - $this->debug( "$message\n" ); - $this->mStack[] = array( $message, 0, 0.0, 0, 0.0, 0 ); + if ( $bit[0] != '-total' ) { + $message = "Profile section ended by close(): {$bit[0]}"; + $this->debugGroup( 'profileerror', $message ); + $this->mStack[] = array( $message, 0, 0.0, 0, 0.0, 0 ); + } } elseif ( $bit[0] != $functionname ) { $message = "Profiling error: in({$bit[0]}), out($functionname)"; - $this->debug( "$message\n" ); + $this->debugGroup( 'profileerror', $message ); $this->mStack[] = array( $message, 0, 0.0, 0, 0.0, 0 ); } $bit[] = $time; @@ -324,7 +326,7 @@ class Profiler { list( $method, $realtime ) = $info; $msg .= sprintf( "%d\t%.6f\t%s\n", $i, $realtime, $method ); } - wfDebugLog( 'DBPerformance', $msg ); + $this->debugGroup( 'DBPerformance', $msg ); } unset( $this->mDBTrxHoldingLocks[$name] ); unset( $this->mDBTrxMethodTimes[$name] ); @@ -720,6 +722,18 @@ class Profiler { } } + /** + * Add an entry in the debug log group + * + * @param string $group Group to send the message to + * @param string $s to output + */ + function debugGroup( $group, $s ) { + if ( function_exists( 'wfDebugLog' ) ) { + wfDebugLog( $group, $s ); + } + } + /** * Get the content type sent out to the client. * Used for profilers that output instead of store data. diff --git a/includes/profiler/ProfilerMwprof.php b/includes/profiler/ProfilerMwprof.php index e81c6ecc8c..5ecfc21037 100644 --- a/includes/profiler/ProfilerMwprof.php +++ b/includes/profiler/ProfilerMwprof.php @@ -90,7 +90,7 @@ class ProfilerMwprof extends Profiler { // Check for unbalanced profileIn / profileOut calls. // Bad entries are logged but not sent. if ( $inName !== $outName ) { - wfDebugLog( 'ProfilerUnbalanced', json_encode( array( $inName, $outName ) ) ); + $this->debugGroup( 'ProfilerUnbalanced', json_encode( array( $inName, $outName ) ) ); return; } diff --git a/includes/profiler/ProfilerSimple.php b/includes/profiler/ProfilerSimple.php index ee92c177ab..7d78e36913 100644 --- a/includes/profiler/ProfilerSimple.php +++ b/includes/profiler/ProfilerSimple.php @@ -102,17 +102,18 @@ class ProfilerSimple extends Profiler { list( $ofname, /* $ocount */, $ortime, $octime ) = array_pop( $this->mWorkStack ); if ( !$ofname ) { - $this->debug( "Profiling error: $functionname\n" ); + $this->debugGroup( 'profileerror', "Profiling error: $functionname" ); } else { if ( $functionname == 'close' ) { - $message = "Profile section ended by close(): {$ofname}"; - $functionname = $ofname; - $this->debug( "$message\n" ); - $this->mCollated[$message] = $this->errorEntry; - } - elseif ( $ofname != $functionname ) { + if ( $ofname != '-total' ) { + $message = "Profile section ended by close(): {$ofname}"; + $functionname = $ofname; + $this->debugGroup( 'profileerror', $message ); + $this->mCollated[$message] = $this->errorEntry; + } + } elseif ( $ofname != $functionname ) { $message = "Profiling error: in({$ofname}), out($functionname)"; - $this->debug( "$message\n" ); + $this->debugGroup( 'profileerror', $message ); $this->mCollated[$message] = $this->errorEntry; } $elapsedcpu = $this->getTime( 'cpu' ) - $octime; -- 2.20.1