From: Sage Weil Date: Tue, 13 Aug 2013 23:12:08 +0000 (-0700) Subject: types: pretty_si_t X-Git-Tag: v0.68~69^2~8 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=9b94f90e0031957717afde16bd056322782232cb;p=ceph.git types: pretty_si_t Similar to si_t, but leaves a space between the numbers and the units. In the degenerate case (no M, K, etc. modifier) there's simply a trailing space. For example, out << pretty_si_t(num) << "objects/sec"; will look pretty. Signed-off-by: Sage Weil --- diff --git a/src/include/types.h b/src/include/types.h index bed00175dd41..7e6ddb7117eb 100644 --- a/src/include/types.h +++ b/src/include/types.h @@ -407,6 +407,29 @@ inline ostream& operator<<(ostream& out, const si_t& b) return out << b.v; } +struct pretty_si_t { + uint64_t v; + pretty_si_t(uint64_t _v) : v(_v) {} +}; + +inline ostream& operator<<(ostream& out, const pretty_si_t& b) +{ + uint64_t bump_after = 100; + if (b.v > bump_after << 60) + return out << (b.v >> 60) << " E"; + if (b.v > bump_after << 50) + return out << (b.v >> 50) << " P"; + if (b.v > bump_after << 40) + return out << (b.v >> 40) << " T"; + if (b.v > bump_after << 30) + return out << (b.v >> 30) << " G"; + if (b.v > bump_after << 20) + return out << (b.v >> 20) << " M"; + if (b.v > bump_after << 10) + return out << (b.v >> 10) << " K"; + return out << b.v << " "; +} + struct kb_t { uint64_t v; kb_t(uint64_t _v) : v(_v) {}