From: Kefu Chai Date: Thu, 7 Jan 2021 03:55:48 +0000 (+0800) Subject: common/ceph_time: format duration using libfmt X-Git-Tag: v16.1.0~70^2~5 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=6e1d42ca004ae191c445dac41606142c376124b1;p=ceph.git common/ceph_time: format duration using libfmt for better readability. Signed-off-by: Kefu Chai --- 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 +#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