Ori.livneh has uploaded a new change for review. https://gerrit.wikimedia.org/r/212578
Change subject: ProfilerOutputStats: allow a key prefix to be specified ...................................................................... ProfilerOutputStats: allow a key prefix to be specified If one wants to nest all metrics emitted by the profiler under a metric namespace, one can now set the 'prefix' param. Task: T66301 Change-Id: I6c52f20e39017f4c818ca6623bb7f48683fc8abc --- M includes/profiler/output/ProfilerOutputStats.php 1 file changed, 20 insertions(+), 5 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/core refs/changes/78/212578/1 diff --git a/includes/profiler/output/ProfilerOutputStats.php b/includes/profiler/output/ProfilerOutputStats.php index a635793..2e7ff49 100644 --- a/includes/profiler/output/ProfilerOutputStats.php +++ b/includes/profiler/output/ProfilerOutputStats.php @@ -32,19 +32,34 @@ class ProfilerOutputStats extends ProfilerOutput { /** + * Make a metric key safe for Graphite + * + * @param string $key + */ + private static function sanitizeMetricKey( $key ) { + $key = str_replace( '::', '.', $key ); + $key = preg_replace( '/[^a-z.]+/i', '_', $key ); + $key = trim( $key, '_.' ); + $key = str_replace( array( '._', '_.' ), '.', $key ); + return $key; + } + + /** * Flush profiling data to the current profiling context's stats buffer. * * @param array $stats */ public function log( array $stats ) { + if ( isset( $this->params['prefix'] ) ) { + $prefix = self::sanitizeMetricKey( $this->params['prefix'] ); + } else { + $prefix = ''; + } + $contextStats = $this->collector->getContext()->getStats(); foreach ( $stats as $stat ) { - // Sanitize the key - $key = str_replace( '::', '.', $stat['name'] ); - $key = preg_replace( '/[^a-z.]+/i', '_', $key ); - $key = trim( $key, '_.' ); - $key = str_replace( array( '._', '_.' ), '.', $key ); + $key = self::sanitizeMetricKey( "{$prefix}.{$stat['name']}" ); // Convert fractional seconds to whole milliseconds $cpu = round( $stat['cpu'] * 1000 ); -- To view, visit https://gerrit.wikimedia.org/r/212578 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I6c52f20e39017f4c818ca6623bb7f48683fc8abc Gerrit-PatchSet: 1 Gerrit-Project: mediawiki/core Gerrit-Branch: master Gerrit-Owner: Ori.livneh <o...@wikimedia.org> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits