From 36920de1711901ba7b5b19e890ae0ff739409767 Mon Sep 17 00:00:00 2001 From: Sage Weil Date: Mon, 6 Aug 2018 13:31:53 -0500 Subject: [PATCH 1/2] include/types: render SI units adjacent to number 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 --- src/include/types.h | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/include/types.h b/src/include/types.h index f239823dde0..af3b8d18039 100644 --- a/src/include/types.h +++ b/src/include/types.h @@ -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(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; From aa485c9b4139d6c8a003e537782056533165565c Mon Sep 17 00:00:00 2001 From: Sage Weil Date: Tue, 7 Aug 2018 08:48:45 -0500 Subject: [PATCH 2/2] mon/PGMap: fix spacing around pretty-printed SI units "1k foo" not "1kfoo" Signed-off-by: Sage Weil --- qa/workunits/cephtool/test.sh | 2 +- src/mon/PGMap.cc | 18 +++++++++--------- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/qa/workunits/cephtool/test.sh b/qa/workunits/cephtool/test.sh index b7209de0ed9..d433c180539 100755 --- a/qa/workunits/cephtool/test.sh +++ b/qa/workunits/cephtool/test.sh @@ -1786,7 +1786,7 @@ function test_mon_osd_pool_quota() # get quotas # ceph osd pool get-quota tmp-quota-pool | grep 'max bytes.*10 B' - ceph osd pool get-quota tmp-quota-pool | grep 'max objects.*10 M objects' + ceph osd pool get-quota tmp-quota-pool | grep 'max objects.*10.*M objects' # # set valid quotas with unit prefix # diff --git a/src/mon/PGMap.cc b/src/mon/PGMap.cc index 1c622625eb1..a1b8c709574 100644 --- a/src/mon/PGMap.cc +++ b/src/mon/PGMap.cc @@ -376,7 +376,7 @@ void PGMapDigest::print_oneline_summary(Formatter *f, ostream *out) const } int64_t iops = (pos_delta.stats.sum.num_rd + pos_delta.stats.sum.num_wr) / (double)stamp_delta; if (out) - *out << si_u_t(iops) << "op/s"; + *out << si_u_t(iops) << " op/s"; if (f) f->dump_unsigned("io_sec", iops); } @@ -470,8 +470,8 @@ void PGMapDigest::recovery_rate_summary(Formatter *f, ostream *out, } else { *out << byte_u_t(bps) << "/s"; if (pos_delta.stats.sum.num_keys_recovered) - *out << ", " << si_u_t(kps) << "keys/s"; - *out << ", " << si_u_t(objps) << "objects/s"; + *out << ", " << si_u_t(kps) << " keys/s"; + *out << ", " << si_u_t(objps) << " objects/s"; } } } @@ -538,7 +538,7 @@ void PGMapDigest::client_io_rate_summary(Formatter *f, ostream *out, f->dump_int("read_op_per_sec", iops_rd); f->dump_int("write_op_per_sec", iops_wr); } else { - *out << si_u_t(iops_rd) << "op/s rd, " << si_u_t(iops_wr) << "op/s wr"; + *out << si_u_t(iops_rd) << " op/s rd, " << si_u_t(iops_wr) << " op/s wr"; } } } @@ -595,7 +595,7 @@ void PGMapDigest::cache_io_rate_summary(Formatter *f, ostream *out, } else { if (have_output) *out << ", "; - *out << si_u_t(promote) << "op/s promote"; + *out << si_u_t(promote) << " op/s promote"; have_output = true; } } @@ -605,7 +605,7 @@ void PGMapDigest::cache_io_rate_summary(Formatter *f, ostream *out, } else { if (have_output) *out << ", "; - *out << si_u_t(pos_delta.stats.sum.num_flush_mode_low) << "PG(s) flushing"; + *out << si_u_t(pos_delta.stats.sum.num_flush_mode_low) << " PGs flushing"; have_output = true; } } @@ -615,7 +615,7 @@ void PGMapDigest::cache_io_rate_summary(Formatter *f, ostream *out, } else { if (have_output) *out << ", "; - *out << si_u_t(pos_delta.stats.sum.num_flush_mode_high) << "PG(s) flushing (high)"; + *out << si_u_t(pos_delta.stats.sum.num_flush_mode_high) << " PGs flushing (high)"; have_output = true; } } @@ -625,7 +625,7 @@ void PGMapDigest::cache_io_rate_summary(Formatter *f, ostream *out, } else { if (have_output) *out << ", "; - *out << si_u_t(pos_delta.stats.sum.num_evict_mode_some) << "PG(s) evicting"; + *out << si_u_t(pos_delta.stats.sum.num_evict_mode_some) << " PGs evicting"; have_output = true; } } @@ -635,7 +635,7 @@ void PGMapDigest::cache_io_rate_summary(Formatter *f, ostream *out, } else { if (have_output) *out << ", "; - *out << si_u_t(pos_delta.stats.sum.num_evict_mode_full) << "PG(s) evicting (full)"; + *out << si_u_t(pos_delta.stats.sum.num_evict_mode_full) << " PGs evicting (full)"; } } }