diff options
author | Sage Weil <sage@inktank.com> | 2013-08-13 16:12:08 -0700 |
---|---|---|
committer | Sage Weil <sage@inktank.com> | 2013-08-13 16:51:56 -0700 |
commit | 9b94f90e0031957717afde16bd056322782232cb (patch) | |
tree | ff0ce0c11b79e64aed5d419e29dbba5bae4ffbc1 | |
parent | 1860ed97ef054df5ff67e8aae1893a307b995a43 (diff) | |
download | ceph-9b94f90e0031957717afde16bd056322782232cb.tar.gz |
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 <sage@inktank.com>
-rw-r--r-- | src/include/types.h | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/src/include/types.h b/src/include/types.h index bed00175dd4..7e6ddb7117e 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) {} |