]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
include/types: render SI units adjacent to number
authorSage Weil <sage@redhat.com>
Mon, 6 Aug 2018 18:31:53 +0000 (13:31 -0500)
committerSage Weil <sage@redhat.com>
Tue, 7 Aug 2018 13:49:56 +0000 (08:49 -0500)
Make

 out << si_u_t(foo) << " objects"

result in strings like

 "0 objects"
 "123k objects"
 "3M objects"

instead of

 "0  objects"
 "0 k objects"
 "3 M objects"

Signed-off-by: Sage Weil <sage@redhat.com>
src/include/types.h

index f239823dde0220e50edb7821761d300935439caf..af3b8d18039bb995b7afcd971a95357d8fd3df96 100644 (file)
@@ -363,11 +363,11 @@ namespace {
     char buffer[32];
 
     if (index == 0) {
-      (void) snprintf(buffer, sizeof(buffer), "%" PRId64 " %s", n, u);
+      (void) snprintf(buffer, sizeof(buffer), "%" PRId64 "%s", n, u);
     } else if ((v % mult) == 0) {
       // If this is an even multiple of the base, always display
       // without any decimal fraction.
-      (void) snprintf(buffer, sizeof(buffer), "%" PRId64 " %s", n, u);
+      (void) snprintf(buffer, sizeof(buffer), "%" PRId64 "%s", n, u);
     } else {
       // We want to choose a precision that reflects the best choice
       // for fitting in 5 characters.  This can get rather tricky when
@@ -378,7 +378,7 @@ namespace {
       // easier just to try each combination in turn.
       int i;
       for (i = 2; i >= 0; i--) {
-        if (snprintf(buffer, sizeof(buffer), "%.*f %s", i,
+        if (snprintf(buffer, sizeof(buffer), "%.*f%s", i,
           static_cast<double>(v) / mult, u) <= 7)
           break;
       }
@@ -429,7 +429,7 @@ inline ostream& operator<<(ostream& out, const byte_u_t& b)
 {
   uint64_t n = b.v;
   int index = 0;
-  const char* u[] = {"B", "KiB", "MiB", "GiB", "TiB", "PiB", "EiB"};
+  const char* u[] = {" B", " KiB", " MiB", " GiB", " TiB", " PiB", " EiB"};
 
   while (n >= 1024 && index < 7) {
     n /= 1024;