Author: stefan2
Date: Tue Dec  9 12:23:01 2014
New Revision: 1644037

URL: http://svn.apache.org/r1644037
Log:
In the 'svnfsfs stats' output, print the size ranges in histograms in a more
user friendly format like "128k .. < 256k" instead of "[2^17..2^18)".

* subversion/svnfsfs/stats-cmd.c
  (print_two_power): New.
  (print_histogram): Call the new function to format size ranges;
                     adjust the format string to accomodate larger sums.

Modified:
    subversion/trunk/subversion/svnfsfs/stats-cmd.c

Modified: subversion/trunk/subversion/svnfsfs/stats-cmd.c
URL: 
http://svn.apache.org/viewvc/subversion/trunk/subversion/svnfsfs/stats-cmd.c?rev=1644037&r1=1644036&r2=1644037&view=diff
==============================================================================
--- subversion/trunk/subversion/svnfsfs/stats-cmd.c (original)
+++ subversion/trunk/subversion/svnfsfs/stats-cmd.c Tue Dec  9 12:23:01 2014
@@ -31,6 +31,35 @@
 #include "svn_private_config.h"
 #include "svnfsfs.h"
 
+/* Return the string, allocated in RESULT_POOL, describing the value 2**I.
+ */
+static const char *
+print_two_power(int i,
+                apr_pool_t *result_pool)
+{
+  /* These are the SI prefixes for base-1000, the binary ones with base-1024
+     are too clumsy and require appending B for "byte" to be intelligible,
+     e.g. "MiB".
+
+     Therefore, we ignore the official standard and revert to the traditional
+     contextual use were the base-1000 prefixes are understood as base-1024
+     when it came to data sizes.
+   */
+  const char *si_prefixes = " kMGTPEZY";
+
+  int number = (1 << (i % 10));
+  int thousands = i / 10;
+
+  char si_prefix = ((thousands >= 0) && (thousands < strlen(si_prefixes)))
+                 ? si_prefixes[thousands]
+                 : '?';
+
+  if (si_prefix == ' ')
+    return apr_psprintf(result_pool, "%d", number);
+
+  return apr_psprintf(result_pool, "%d%c", number, si_prefix);
+}
+
 /* Print statistics for the given group of representations to console.
  * Use POOL for allocations.
  */
@@ -88,8 +117,8 @@ print_histogram(svn_fs_fs__histogram_t *
 
   /* display histogram lines */
   for (i = last; i >= first; --i)
-    printf(_("  [2^%2d, 2^%2d)   %15s (%2d%%) bytes in %12s (%2d%%) items\n"),
-           i-1, i,
+    printf(_("  %4s .. < %-4s %19s (%2d%%) bytes in %12s (%2d%%) items\n"),
+           print_two_power(i-1, pool), print_two_power(i, pool),
            svn__ui64toa_sep(histogram->lines[i].sum, ',', pool),
            (int)(histogram->lines[i].sum * 100 / histogram->total.sum),
            svn__ui64toa_sep(histogram->lines[i].count, ',', pool),


Reply via email to