ProfilerOutputStats: tweak stat key normalization
authorOri Livneh <ori@wikimedia.org>
Thu, 14 May 2015 21:49:51 +0000 (14:49 -0700)
committerOri Livneh <ori@wikimedia.org>
Thu, 14 May 2015 21:49:51 +0000 (14:49 -0700)
When we convert a profiler entry to a statsd metric key, we replace
nonalphabetic characters with slashes. When part of the key is a file path with
a leading or trailing slash, this can result in keys that look like:
'MediaWiki._srv_mediawiki_foo_.bar', which is a bit ugly. This patch trims
leading and trailing underscores from each dot-separated key segment.

Change-Id: I71172b956f5a6120a75981a15dedf372d3893b88

includes/profiler/output/ProfilerOutputStats.php

index ef6ef7c..a635793 100644 (file)
@@ -44,6 +44,7 @@ class ProfilerOutputStats extends ProfilerOutput {
                        $key = str_replace( '::', '.', $stat['name'] );
                        $key = preg_replace( '/[^a-z.]+/i', '_', $key );
                        $key = trim( $key, '_.' );
+                       $key = str_replace( array( '._', '_.' ), '.', $key );
 
                        // Convert fractional seconds to whole milliseconds
                        $cpu = round( $stat['cpu'] * 1000 );