From e376ee65f705f6c9ee93a3d7332fd2d1d9622651 Mon Sep 17 00:00:00 2001 From: Chad Horohoe Date: Sat, 16 Apr 2011 02:19:40 +0000 Subject: [PATCH] First step of reorganizing profiling files: * Move them all to includes/profiling/* - If you're using StartProfiler, you'll need to update that * Make ProfileStub subclass the Profiler rather than duplicating function definitions conditionally * Removed unused params to wfGetProfilingOutput(), only used in the stub, and they didn't do anything with them * TODO: Kill $wgProfiling, make $wgProfiler a config array and move the various options to that. Also make into a singleton, rather than global (not much calls it outside of core) --- includes/AutoLoader.php | 11 ++-- includes/ProfilerStub.php | 52 --------------- includes/WebStart.php | 2 +- includes/{ => profiler}/Profiler.php | 15 ++--- includes/{ => profiler}/ProfilerSimple.php | 2 +- .../{ => profiler}/ProfilerSimpleText.php | 4 +- .../{ => profiler}/ProfilerSimpleTrace.php | 2 +- includes/{ => profiler}/ProfilerSimpleUDP.php | 4 +- includes/profiler/ProfilerStub.php | 65 +++++++++++++++++++ maintenance/doMaintenance.php | 2 +- 10 files changed, 88 insertions(+), 71 deletions(-) delete mode 100644 includes/ProfilerStub.php rename includes/{ => profiler}/Profiler.php (97%) rename includes/{ => profiler}/ProfilerSimple.php (98%) rename includes/{ => profiler}/ProfilerSimpleText.php (90%) rename includes/{ => profiler}/ProfilerSimpleTrace.php (96%) rename includes/{ => profiler}/ProfilerSimpleUDP.php (91%) create mode 100644 includes/profiler/ProfilerStub.php diff --git a/includes/AutoLoader.php b/includes/AutoLoader.php index eb03d94f76..840a25844a 100644 --- a/includes/AutoLoader.php +++ b/includes/AutoLoader.php @@ -185,10 +185,6 @@ $wgAutoloadLocalClasses = array( 'PoolCounterWork' => 'includes/PoolCounter.php', 'Preferences' => 'includes/Preferences.php', 'PrefixSearch' => 'includes/PrefixSearch.php', - 'Profiler' => 'includes/Profiler.php', - 'ProfilerSimple' => 'includes/ProfilerSimple.php', - 'ProfilerSimpleText' => 'includes/ProfilerSimpleText.php', - 'ProfilerSimpleUDP' => 'includes/ProfilerSimpleUDP.php', 'ProtectionForm' => 'includes/ProtectionForm.php', 'QueryPage' => 'includes/QueryPage.php', 'QuickTemplate' => 'includes/SkinTemplate.php', @@ -599,6 +595,13 @@ $wgAutoloadLocalClasses = array( 'StripState' => 'includes/parser/StripState.php', 'MWTidy' => 'includes/parser/Tidy.php', + # includes/profiler + 'Profiler' => 'includes/Profiler.php', + 'ProfilerSimple' => 'includes/ProfilerSimple.php', + 'ProfilerSimpleText' => 'includes/ProfilerSimpleText.php', + 'ProfilerSimpleUDP' => 'includes/ProfilerSimpleUDP.php', + 'ProfilerStub' => 'includes/ProfilerStub.php', + # includes/search 'MySQLSearchResultSet' => 'includes/search/SearchMySQL.php', 'PostgresSearchResult' => 'includes/search/SearchPostgres.php', diff --git a/includes/ProfilerStub.php b/includes/ProfilerStub.php deleted file mode 100644 index e624e6f019..0000000000 --- a/includes/ProfilerStub.php +++ /dev/null @@ -1,52 +0,0 @@ -getOutput( $start, $elapsed ); + return $wgProfiler->getOutput(); } /** @@ -79,7 +76,7 @@ class Profiler { * * @param $functionname String */ - function profileIn( $functionname ) { + public function profileIn( $functionname ) { global $wgDebugFunctionEntry, $wgProfiling; if( !$wgProfiling ) return; if( $wgDebugFunctionEntry ){ @@ -94,7 +91,7 @@ class Profiler { * * @param $functionname String */ - function profileOut($functionname) { + public function profileOut($functionname) { global $wgDebugFunctionEntry, $wgProfiling; if( !$wgProfiling ) return; $memory = memory_get_usage(); @@ -130,7 +127,7 @@ class Profiler { /** * called by wfProfileClose() */ - function close() { + public function close() { global $wgProfiling; # Avoid infinite loop @@ -154,7 +151,7 @@ class Profiler { /** * Called by wfGetProfilingOutput() */ - function getOutput() { + public function getOutput() { global $wgDebugFunctionEntry, $wgProfileCallTree; $wgDebugFunctionEntry = false; diff --git a/includes/ProfilerSimple.php b/includes/profiler/ProfilerSimple.php similarity index 98% rename from includes/ProfilerSimple.php rename to includes/profiler/ProfilerSimple.php index 8aab1ecc32..975b0ed837 100644 --- a/includes/ProfilerSimple.php +++ b/includes/profiler/ProfilerSimple.php @@ -5,7 +5,7 @@ */ if ( !class_exists( 'Profiler' ) ) { - require_once(dirname(__FILE__).'/Profiler.php'); + require_once( dirname( __FILE__ ) . '/Profiler.php' ); } /** diff --git a/includes/ProfilerSimpleText.php b/includes/profiler/ProfilerSimpleText.php similarity index 90% rename from includes/ProfilerSimpleText.php rename to includes/profiler/ProfilerSimpleText.php index db4b6053c2..66b49b5d6c 100644 --- a/includes/ProfilerSimpleText.php +++ b/includes/profiler/ProfilerSimpleText.php @@ -4,7 +4,9 @@ * @ingroup Profiler */ -require_once( dirname( __FILE__ ) . '/ProfilerSimple.php' ); +if ( !class_exists( 'ProfilerSimple' ) ) { + require_once( dirname( __FILE__ ) . '/ProfilerSimple.php' ); +} /** * The least sophisticated profiler output class possible, view your source! :) diff --git a/includes/ProfilerSimpleTrace.php b/includes/profiler/ProfilerSimpleTrace.php similarity index 96% rename from includes/ProfilerSimpleTrace.php rename to includes/profiler/ProfilerSimpleTrace.php index 8f6a2a1ca6..b1876235ae 100644 --- a/includes/ProfilerSimpleTrace.php +++ b/includes/profiler/ProfilerSimpleTrace.php @@ -5,7 +5,7 @@ */ if ( !class_exists( 'ProfilerSimple' ) ) { - require_once(dirname(__FILE__).'/ProfilerSimple.php'); + require_once( dirname( __FILE__ ) . '/ProfilerSimple.php' ); } /** diff --git a/includes/ProfilerSimpleUDP.php b/includes/profiler/ProfilerSimpleUDP.php similarity index 91% rename from includes/ProfilerSimpleUDP.php rename to includes/profiler/ProfilerSimpleUDP.php index 67ad97f654..32ab60eb94 100644 --- a/includes/ProfilerSimpleUDP.php +++ b/includes/profiler/ProfilerSimpleUDP.php @@ -4,7 +4,9 @@ * @ingroup Profiler */ -require_once(dirname(__FILE__).'/ProfilerSimple.php'); +if ( !class_exists( 'ProfilerSimple' ) ) { + require_once( dirname( __FILE__ ) . '/ProfilerSimple.php' ); +} /** * ProfilerSimpleUDP class, that sends out messages for 'udpprofile' daemon diff --git a/includes/profiler/ProfilerStub.php b/includes/profiler/ProfilerStub.php new file mode 100644 index 0000000000..6117bda5df --- /dev/null +++ b/includes/profiler/ProfilerStub.php @@ -0,0 +1,65 @@ +haveProctitle = function_exists( 'setproctitle' ); + } + + /** + * Begin profiling of a function + * @param $fn string + */ + public function profileIn( $fn = '' ) { + global $wgDBname; + if( $this->haveProctitle ){ + $this->hackWhere[] = $fn; + setproctitle( $fn . " [$wgDBname]" ); + } + } + + /** + * Stop profiling of a function + * @param $fn string + */ + public function profileOut( $fn = '' ) { + global $wgDBname; + if( !$this->haveProctitle ) { + return; + } + if( count( $this->hackWhere ) ) { + array_pop( $this->hackWhere ); + } + if( count( $this->hackWhere ) ) { + setproctitle( $this->hackWhere[count( $this->hackWhere )-1] . " [$wgDBname]" ); + } + } + + /** + * Does nothing, just for compatibility + */ + public function getOutput() {} + public function close() {} +} + +/** backward compatibility */ +$wgProfiling = false; +$wgProfiler = new ProfilerStub(); diff --git a/maintenance/doMaintenance.php b/maintenance/doMaintenance.php index 437ca83c32..cdbc36a25d 100644 --- a/maintenance/doMaintenance.php +++ b/maintenance/doMaintenance.php @@ -74,7 +74,7 @@ global $IP; if ( !defined( 'MW_COMPILED' ) && file_exists( "$IP/StartProfiler.php" ) ) { require_once( "$IP/StartProfiler.php" ); } else { - require_once( MWInit::compiledPath( 'includes/ProfilerStub.php' ) ); + require_once( MWInit::compiledPath( 'includes/profiler/ProfilerStub.php' ) ); } // Some other requires -- 2.20.1