Log profiling data when tests have finished.
authordaniel <daniel.kinzler@wikimedia.de>
Tue, 13 Nov 2012 16:51:32 +0000 (17:51 +0100)
committerdaniel <daniel.kinzler@wikimedia.de>
Fri, 16 Nov 2012 19:14:29 +0000 (20:14 +0100)
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
tests/phpunit/MediaWikiPHPUnitCommand.php

index 3de25e7..4763c4a 100644 (file)
@@ -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 );
 }
index fca3251..473e641 100644 (file)
@@ -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();