From 6e1d42ca004ae191c445dac41606142c376124b1 Mon Sep 17 00:00:00 2001 From: Kefu Chai Date: Thu, 7 Jan 2021 11:55:48 +0800 Subject: [PATCH] common/ceph_time: format duration using libfmt for better readability. Signed-off-by: Kefu Chai --- src/common/ceph_time.cc | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/src/common/ceph_time.cc b/src/common/ceph_time.cc index c450ef9af4218..aa72f65cc7023 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 +#include + #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); - m << std::chrono::duration_cast(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; + fmt::print(m, "{:.9}", std::chrono::duration_cast(t)); + return m; } template