From: Sage Weil Date: Mon, 8 Jul 2019 22:12:49 +0000 (-0500) Subject: common/ceph_time: make operator<< for timespan less useless X-Git-Tag: v15.1.0~2136^2 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=353a0e5fac060aa24d3ff4261d16b8800badb5e6;p=ceph.git common/ceph_time: make operator<< for timespan less useless - not a floating point value, which will revert to scientific notation once it gets big. - behave for negative spans Signed-off-by: Sage Weil --- diff --git a/src/common/ceph_time.cc b/src/common/ceph_time.cc index 7b5d52415dcb..f831e78b9d3c 100644 --- a/src/common/ceph_time.cc +++ b/src/common/ceph_time.cc @@ -100,7 +100,20 @@ namespace ceph { } std::ostream& operator<<(std::ostream& m, const timespan& t) { - return m << std::chrono::duration(t).count() << "s"; + int64_t ns = t.count(); + if (ns < 0) { + ns = -ns; + m << "-"; + } + m << (ns / 1000000000ll); + ns %= 1000000000ll; + if (ns) { + char oldfill = m.fill(); + m.fill('0'); + m << '.' << std::setw(9) << ns; + m.fill(oldfill); + } + return m << "s"; } template