From e606537090ebbd93cc0413d74e8347869336e7d0 Mon Sep 17 00:00:00 2001 From: daniel Date: Tue, 13 Nov 2012 17:51:32 +0100 Subject: [PATCH] Log profiling data when tests have finished. Previously, no profiling data was recorded from unit test runs. That made it impossible to a) use unit tests for selective profiling of individual functions, and b) made it impossibel to profile the tests themselves. This change fixes this problem by calling wfLogProfilingData() after the test runner has finished. Thaks to Hashar for some ideas, especially the fix in GlobalFunctions. Change-Id: Iaa295115f3c4eb3b529388dcd953fe8932448b3e --- includes/GlobalFunctions.php | 11 ++++++++++- tests/phpunit/MediaWikiPHPUnitCommand.php | 16 ++++++++++++++++ 2 files changed, 26 insertions(+), 1 deletion(-) diff --git a/includes/GlobalFunctions.php b/includes/GlobalFunctions.php index 3de25e716d..4763c4af9b 100644 --- a/includes/GlobalFunctions.php +++ b/includes/GlobalFunctions.php @@ -1214,9 +1214,18 @@ function wfLogProfilingData() { if ( $wgUser->isItemLoaded( 'id' ) && $wgUser->isAnon() ) { $forward .= ' anon'; } + + // Command line script uses a FauxRequest object which does not have + // any knowledge about an URL and throw an exception instead. + try { + $requestUrl = $wgRequest->getRequestURL(); + } catch ( MWException $e ) { + $requestUrl = 'n/a'; + } + $log = sprintf( "%s\t%04.3f\t%s\n", gmdate( 'YmdHis' ), $elapsed, - urldecode( $wgRequest->getRequestURL() . $forward ) ); + urldecode( $requestUrl . $forward ) ); wfErrorLog( $log . $profiler->getOutput(), $wgDebugLogFile ); } diff --git a/tests/phpunit/MediaWikiPHPUnitCommand.php b/tests/phpunit/MediaWikiPHPUnitCommand.php index fca325154a..473e6413b7 100644 --- a/tests/phpunit/MediaWikiPHPUnitCommand.php +++ b/tests/phpunit/MediaWikiPHPUnitCommand.php @@ -53,6 +53,22 @@ class MediaWikiPHPUnitCommand extends PHPUnit_TextUI_Command { } } + public function run( array $argv, $exit = true ) { + $ret = parent::run( $argv, false ); + + // Return to real wiki db, so profiling data is preserved + MediaWikiTestCase::teardownTestDB(); + + // Log profiling data, e.g. in the database or UDP + wfLogProfilingData(); + + if ( $exit ) { + exit( $ret ); + } else { + return $ret; + } + } + public function showHelp() { parent::showHelp(); -- 2.20.1