Follows-up I8808cad03418 which added this option, but I neglected to actually test it. When trying it out with a patched wmf-config on a mwdebug server, the following issue surfaced: > Fatal TypeError: Argument 1 passed to XhprofData::__construct() must > be of type array, null given, called in ProfilerXhprof.php:90 This is because ProfilerXhprof::disable() actually has its own state tracking which refuses to even try calling tideways_xhprof_disable() unless its state says it was in control of enabling it. Remove this check and reduce the class to just abstracting the calls to the PHP extension. Also, remove the useless null return which is incompatible with the callers to this function as evidenced by above Fatal TypeError. The PHP extensions already default to an empty array, which is now documented. Test Plan: * Local wiki with php-tideways installed, on this pach applied. Note that MediaWiki-Docker now has php-tideways pre-installed! * In LocalSettings, configure profiling as per <https://www.mediawiki.org/wiki/MediaWiki-Docker/Recipes/Profiling> $wgProfiler = [ 'class' => ProfilerXhprof::class, 'output' => 'text', ]; * At load.php?forceprofile=1, there are valid percentages (100% "main"). * Add `tideways_xhprof_enable();` and `$wgProfiler['running'] = true;` to LocalSettings. The percentages are still valid, and the profile is now longer with additional coverage of early code such as MediaWikiServices. * Switching to master, there is a fatal error with these settings. Bug: T247332 Change-Id: Iaad88a0c46d39aee1374e5b02a77251bfa4c6f09
112 lines
2.7 KiB
PHP
112 lines
2.7 KiB
PHP
<?php
|
|
/**
|
|
* This program is free software; you can redistribute it and/or modify
|
|
* it under the terms of the GNU General Public License as published by
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
* (at your option) any later version.
|
|
*
|
|
* This program is distributed in the hope that it will be useful,
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
* GNU General Public License for more details.
|
|
*
|
|
* You should have received a copy of the GNU General Public License along
|
|
* with this program; if not, write to the Free Software Foundation, Inc.,
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
* http://www.gnu.org/copyleft/gpl.html
|
|
*
|
|
* @file
|
|
*/
|
|
|
|
/**
|
|
* @covers Xhprof
|
|
*/
|
|
class XhprofTest extends PHPUnit\Framework\TestCase {
|
|
|
|
use MediaWikiCoversValidator;
|
|
|
|
/**
|
|
* @dataProvider provideCallAny
|
|
*/
|
|
public function testCallAny( array $functions, array $args, $expectedResult ) {
|
|
$xhprof = new ReflectionClass( Xhprof::class );
|
|
$callAny = $xhprof->getMethod( 'callAny' );
|
|
$callAny->setAccessible( true );
|
|
|
|
$this->assertEquals( $expectedResult,
|
|
$callAny->invoke( null, $functions, $args ) );
|
|
}
|
|
|
|
/**
|
|
* Data provider for callAny(), which calls the first function found.
|
|
*/
|
|
public function provideCallAny() {
|
|
return [
|
|
[
|
|
[ 'wfTestCallAny_func1', 'wfTestCallAny_func2', 'wfTestCallAny_func3' ],
|
|
[ 3, 4 ],
|
|
12
|
|
],
|
|
[
|
|
[ 'wfTestCallAny_nosuchfunc1', 'wfTestCallAny_func2', 'wfTestCallAny_func3' ],
|
|
[ 3, 4 ],
|
|
7
|
|
],
|
|
[
|
|
[ 'wfTestCallAny_nosuchfunc1', 'wfTestCallAny_nosuchfunc2', 'wfTestCallAny_func3' ],
|
|
[ 3, 4 ],
|
|
-1
|
|
]
|
|
|
|
];
|
|
}
|
|
|
|
/**
|
|
* callAny() throws an exception when all functions are unavailable.
|
|
*
|
|
* @covers Xhprof::callAny
|
|
*/
|
|
public function testCallAnyNoneAvailable() {
|
|
$xhprof = new ReflectionClass( Xhprof::class );
|
|
$callAny = $xhprof->getMethod( 'callAny' );
|
|
$callAny->setAccessible( true );
|
|
|
|
$this->expectException( Exception::class );
|
|
$this->expectExceptionMessage( "Neither xhprof nor tideways are installed" );
|
|
$callAny->invoke( $xhprof, [
|
|
'wfTestCallAny_nosuchfunc1',
|
|
'wfTestCallAny_nosuchfunc2',
|
|
'wfTestCallAny_nosuchfunc3'
|
|
] );
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Test function #1 for XhprofTest::testCallAny
|
|
* @param int $a
|
|
* @param int $b
|
|
* @return int
|
|
*/
|
|
function wfTestCallAny_func1( $a, $b ) {
|
|
return $a * $b;
|
|
}
|
|
|
|
/**
|
|
* Test function #2 for XhprofTest::testCallAny
|
|
* @param int $a
|
|
* @param int $b
|
|
* @return int
|
|
*/
|
|
function wfTestCallAny_func2( $a, $b ) {
|
|
return $a + $b;
|
|
}
|
|
|
|
/**
|
|
* Test function #3 for XhprofTest::testCallAny
|
|
* @param int $a
|
|
* @param int $b
|
|
* @return int
|
|
*/
|
|
function wfTestCallAny_func3( $a, $b ) {
|
|
return $a - $b;
|
|
}
|