Last active
February 21, 2016 20:40
-
-
Save mariushoch/72bb5edeca5ccd5c2eca to your computer and use it in GitHub Desktop.
MediaWiki: Add --profile-tests to phpunit.php
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
From 5a02248b9e8671ac80a657c2c53229c688f033dd Mon Sep 17 00:00:00 2001 | |
From: Marius Hoch <[email protected]> | |
Date: Sun, 21 Feb 2016 21:38:41 +0100 | |
Subject: [PATCH] Add --profile-tests to phpunit.php | |
Change-Id: I4c9fcd6b90151b5b3b3dff65bfc0ce8589b7da7b | |
--- | |
tests/phpunit/phpunit.php | 29 +++++++++++++++++++++++++++++ | |
1 file changed, 29 insertions(+) | |
diff --git a/tests/phpunit/phpunit.php b/tests/phpunit/phpunit.php | |
index 66e8182..6d5cc2a 100755 | |
--- a/tests/phpunit/phpunit.php | |
+++ b/tests/phpunit/phpunit.php | |
@@ -48,6 +48,13 @@ class PHPUnitMaintClass extends Maintenance { | |
false, | |
true | |
); | |
+ $this->addOption( | |
+ 'profile-tests', | |
+ 'Output profiling information after the test run (using Xhprof).', | |
+ false, # not required | |
+ false # no arg needed | |
+ ); | |
+ | |
$this->addOption( 'file', 'File describing parser tests.', false, true ); | |
$this->addOption( 'use-filebackend', 'Use filebackend', false, true ); | |
$this->addOption( 'use-bagostuff', 'Use bagostuff', false, true ); | |
@@ -298,4 +305,26 @@ echo defined( 'HHVM_VERSION' ) ? | |
'Using HHVM ' . HHVM_VERSION . ' (' . PHP_VERSION . ")\n" : | |
'Using PHP ' . PHP_VERSION . "\n"; | |
+$key = array_search( '--profile-tests', $_SERVER['argv'] ); | |
+if ( $key ) { | |
+ $params = [ | |
+ 'threshold' => $wgProfileLimit, | |
+ 'class' => defined( 'XHPROF_FLAGS_NO_BUILTINS' ) ? 'ProfilerXhprof' : 'ProfilerStub', | |
+ 'output' => [] | |
+ ]; | |
+ $params = array_merge( $params, $wgProfiler ); | |
+ | |
+ $profiler = new ProfilerXhprof( $params ); | |
+ | |
+ register_shutdown_function( function() use ( $profiler ) { | |
+ echo "\n\n"; | |
+ echo $profiler->getOutput() . PHP_EOL; | |
+ } ); | |
+ | |
+ Profiler::replaceStubInstance( $profiler ); | |
+ | |
+ unset( $_SERVER['argv'][$key] ); | |
+ $_SERVER['argv'] = array_values( $_SERVER['argv'] ); | |
+} | |
+ | |
PHPUnit_TextUI_Command::main(); | |
-- | |
2.5.0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
phpunit.php is a Maintenance script and already has: --profiler: Profiler output format (usually "text") :-}
Might want to teach Maintenance to accept XHPROF though it might already.