Forked from mariushoch/gist:72bb5edeca5ccd5c2eca
Last active
August 29, 2015 14:19
-
-
Save JanZerebecki/593d5d16ecd584dffe62 to your computer and use it in GitHub Desktop.
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 a5b984f1a09ec234f10d2f9458145451d2ca4f92 Mon Sep 17 00:00:00 2001 | |
From: Marius Hoch <[email protected]> | |
Date: Fri, 24 Apr 2015 17:40:43 +0200 | |
Subject: [PATCH] Add --profile-tests to phpunit.php | |
Change-Id: I54499dad929221510634b6316c5794b869812fe0 | |
--- | |
tests/phpunit/phpunit.php | 32 +++++++++++++++++++++++++++++++- | |
1 file changed, 31 insertions(+), 1 deletion(-) | |
diff --git a/tests/phpunit/phpunit.php b/tests/phpunit/phpunit.php | |
index d18ab73..f4389a8 100755 | |
--- a/tests/phpunit/phpunit.php | |
+++ b/tests/phpunit/phpunit.php | |
@@ -42,6 +42,14 @@ class PHPUnitMaintClass extends Maintenance { | |
false, # not required | |
false # no arg needed | |
); | |
+ | |
+ $this->addOption( | |
+ 'profile-tests', | |
+ 'Output profiling information after the test run (using Xhprof).', | |
+ false, # not required | |
+ false # no arg needed | |
+ ); | |
+ | |
$this->addOption( 'regex', 'Only run parser tests that match the given regex.', false, true ); | |
$this->addOption( 'file', 'File describing parser tests.', false, true ); | |
$this->addOption( 'use-filebackend', 'Use filebackend', false, true ); | |
@@ -238,4 +246,26 @@ if ( $puVersion !== '@package_version@' && version_compare( $puVersion, '3.7.0', | |
exit( 1 ); | |
} | |
-PHPUnit_TextUI_Command::main(); | |
+$key = array_search( '--profile-tests', $_SERVER['argv'] ); | |
+if ( $key ) { | |
+ $params = array( | |
+ 'threshold' => $wgProfileLimit, | |
+ 'class' => defined( 'XHPROF_FLAGS_NO_BUILTINS' ) ? 'ProfilerXhprof' : 'ProfilerStub', | |
+ 'output' => array() | |
+ ); | |
+ $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(); | |
\ No newline at end of file | |
-- | |
2.1.0 | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment