mctest.php: nicely align server names
authorAntoine Musso <hashar@free.fr>
Wed, 31 Jul 2013 12:25:30 +0000 (14:25 +0200)
committerAntoine Musso <hashar@free.fr>
Thu, 1 Aug 2013 09:09:33 +0000 (11:09 +0200)
The servers entries being made of an IP address and a port, they would
often have different lenghts which clutter the output indentation.

Previously the output columns would be slightly misaligned:

$ mwscript mctest.php --wiki=enwiki
10.4.1.255:11211 set: 100   time: 0.17192602157593
10.4.1.1:11211 set: 100   time: 0.19056081771851
$

With this patch:

$ mwscript mctest.php --wiki=enwiki
10.4.1.255:11211 set: 100   time: 0.17192602157593
10.4.1.1:11211   set: 100   time: 0.19056081771851
$

Change-Id: I80199a229ed6310686411f08e0344c7d906414ea

maintenance/mctest.php

index 26e1e18..28b041a 100644 (file)
@@ -61,8 +61,15 @@ class mcTest extends Maintenance {
                        $this->error( "MediaWiki isn't configured for Memcached usage", 1 );
                }
 
+               # find out the longest server string to nicely align output later on
+               $maxSrvLen = $servers ? max( array_map( 'strlen', $servers ) ) : 0;
+
                foreach ( $servers as $server ) {
-                       $this->output( $server . " ", $server );
+                       $this->output(
+                               str_pad( $server, $maxSrvLen ),
+                               $server  # output channel
+                       );
+
                        $mcc = new MemCachedClientforWiki( array(
                                'persistant' => true,
                                'timeout' => $wgMemCachedTimeout
@@ -90,7 +97,7 @@ class mcTest extends Maintenance {
                        }
                        $exectime = $this->microtime_float() - $time_start;
 
-                       $this->output( "set: $set   incr: $incr   get: $get time: $exectime", $server );
+                       $this->output( " set: $set   incr: $incr   get: $get time: $exectime", $server );
                }
        }