jenkins-bot has submitted this change and it was merged. Change subject: Simplify profiler output class selection ......................................................................
Simplify profiler output class selection Instead of maintaining a mapping of short names to class names ('db' => 'ProfilerOutputDb', etc.), let us adopt the convention of using the full class name to indicate the output type. We can maintain backward-compatibility by using simple string manipulation to transform short names to the full class names. Change-Id: I976e0da2873d88b9892fb41823cfe3af0a2d3974 --- M StartProfiler.sample M includes/profiler/Profiler.php 2 files changed, 27 insertions(+), 30 deletions(-) Approvals: Aaron Schulz: Looks good to me, approved jenkins-bot: Verified diff --git a/StartProfiler.sample b/StartProfiler.sample index 6681b87..7a88957 100644 --- a/StartProfiler.sample +++ b/StartProfiler.sample @@ -4,30 +4,35 @@ * To use a profiler, copy this file to StartProfiler.php and add: * $wgProfiler['class'] = 'ProfilerXhprof'; * - * For output, add: - * $wgProfiler['output'] = array( 'text' ); - * 'text' can be one (or more) of 'text' 'udp' 'db' or 'dump' - * 'db' requires creating the profiling table, see patch-profiling.sql + * For output, set the 'output' key to an array of class names, one for each + * output type you want the profiler to generate. For example: + * $wgProfiler['output'] = array( 'ProfilerOutputText' ); * - * The 'text' output will be added to the output page in a comment approriate - * to the output's mime type. For a text/html page, this display can be - * changed to a preformatted text block by setting the 'visible' configuration - * flag: + * The output classes available to you by default are ProfilerOutputDb, + * ProfilerOutputDump, ProfilerOutputStats, ProfilerOutputText, and + * ProfilerOutputUdp. + * + * ProfilerOutputStats outputs profiling data as StatsD metrics. It expects + * that you have set the $wgStatsdServer configuration variable to the host (or + * host:port) of your statsd server. + * + * ProfilerOutputText will output profiling data in the page body as a comment. + * You can make the profiling data in HTML render as part of the page content + * by setting the 'visible' configuration flag: * $wgProfiler['visible'] = true; * - * The 'db' output expects a database table that can be created by applying + * 'ProfilerOutputDb' expects a database table that can be created by applying * maintenance/archives/patch-profiling.sql to your database. * - * The 'dump' output expects a $wgProfiler['outputDir'] telling it where to + * 'ProfilerOutputDump' expects a $wgProfiler['outputDir'] telling it where to * write dump files. The files produced are compatible with the XHProf gui. - * * For a rudimentary sampling profiler: * $wgProfiler['class'] = 'ProfilerXhprof'; - * $wgProfiler['output'] = array( 'db' ); + * $wgProfiler['output'] = array( 'ProfilingOutputDb' ); * $wgProfiler['sampling'] = 50; // one every 50 requests * This will use ProfilerStub for non-sampled cases. * - * For performance, the profiler is always disabled for CLI scripts - * as they could be long running and the data would accumulate. Use - * the --profiler parameter of maintenance scripts to override this. + * For performance, the profiler is always disabled for CLI scripts as they + * could be long running and the data would accumulate. Use the '--profiler' + * parameter of maintenance scripts to override this. */ diff --git a/includes/profiler/Profiler.php b/includes/profiler/Profiler.php index 924bb03..dbf80fa 100644 --- a/includes/profiler/Profiler.php +++ b/includes/profiler/Profiler.php @@ -37,21 +37,8 @@ protected $params = array(); /** @var IContextSource Current request context */ protected $context = null; - /** @var TransactionProfiler */ protected $trxProfiler; - - /** - * @var array Mapping of output type to class name - */ - private static $outputTypes = array( - 'db' => 'ProfilerOutputDb', - 'text' => 'ProfilerOutputText', - 'udp' => 'ProfilerOutputUdp', - 'dump' => 'ProfilerOutputDump', - 'stats' => 'ProfilerOutputStats', - ); - /** @var Profiler */ private static $instance = null; @@ -201,10 +188,15 @@ private function getOutputs() { $outputs = array(); foreach ( $this->params['output'] as $outputType ) { - if ( !isset( self::$outputTypes[$outputType] ) ) { + // The class may be specified as either the full class name (for + // example, 'ProfilerOutputUdp') or (for backward compatibility) + // the trailing portion of the class name (for example, 'udp'). + $outputClass = strpos( $outputType, 'ProfilerOutput' ) === false + ? 'ProfilerOutput' . ucfirst( $outputType ) + : $outputType; + if ( !class_exists( $outputClass ) ) { throw new MWException( "'$outputType' is an invalid output type" ); } - $outputClass = self::$outputTypes[$outputType]; $outputInstance = new $outputClass( $this, $this->params ); if ( $outputInstance->canUse() ) { $outputs[] = $outputInstance; -- To view, visit https://gerrit.wikimedia.org/r/201497 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: merged Gerrit-Change-Id: I976e0da2873d88b9892fb41823cfe3af0a2d3974 Gerrit-PatchSet: 1 Gerrit-Project: mediawiki/core Gerrit-Branch: master Gerrit-Owner: Ori.livneh <o...@wikimedia.org> Gerrit-Reviewer: Aaron Schulz <asch...@wikimedia.org> Gerrit-Reviewer: jenkins-bot <> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits