diff options
author | Kefu Chai <kchai@redhat.com> | 2021-01-07 04:55:48 +0100 |
---|---|---|
committer | Kefu Chai <kchai@redhat.com> | 2021-01-08 06:57:17 +0100 |
commit | 6e1d42ca004ae191c445dac41606142c376124b1 (patch) | |
tree | 89636e0b951a95ad0747c7e524c684cd31568206 /src/common/ceph_time.cc | |
parent | Merge PR #38794 into master (diff) | |
download | ceph-6e1d42ca004ae191c445dac41606142c376124b1.tar.xz ceph-6e1d42ca004ae191c445dac41606142c376124b1.zip |
common/ceph_time: format duration using libfmt
for better readability.
Signed-off-by: Kefu Chai <kchai@redhat.com>
Diffstat (limited to 'src/common/ceph_time.cc')
-rw-r--r-- | src/common/ceph_time.cc | 15 |
1 files changed, 7 insertions, 8 deletions
diff --git a/src/common/ceph_time.cc b/src/common/ceph_time.cc index c450ef9af42..aa72f65cc70 100644 --- a/src/common/ceph_time.cc +++ b/src/common/ceph_time.cc @@ -14,6 +14,10 @@ // For ceph_timespec #include "ceph_time.h" + +#include <fmt/chrono.h> +#include <fmt/ostream.h> + #include "log/LogClock.h" #include "config.h" #include "strtol.h" @@ -104,14 +108,9 @@ std::ostream& operator<<(std::ostream& m, std::ostream& operator<<(std::ostream& m, const timespan& t) { static_assert(std::is_unsigned_v<timespan::rep>); - m << std::chrono::duration_cast<std::chrono::seconds>(t).count(); - if (auto ns = (t % 1s).count(); ns > 0) { - char oldfill = m.fill(); - m.fill('0'); - m << '.' << std::setw(9) << ns; - m.fill(oldfill); - } - return m << 's'; + using seconds_t = std::chrono::duration<float>; + fmt::print(m, "{:.9}", std::chrono::duration_cast<seconds_t>(t)); + return m; } template<typename Clock, |