]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
common/ceph_time: make operator<< for timespan less useless 29052/head
authorSage Weil <sage@redhat.com>
Mon, 8 Jul 2019 22:12:49 +0000 (17:12 -0500)
committerSage Weil <sage@redhat.com>
Mon, 15 Jul 2019 18:34:36 +0000 (13:34 -0500)
- not a floating point value, which will revert to scientific notation once
  it gets big.
- behave for negative spans

Signed-off-by: Sage Weil <sage@redhat.com>
src/common/ceph_time.cc

index 7b5d52415dcb1e106d3afc55e1087005022ae52e..f831e78b9d3cf9f07f2118a2f63b11a880f67590 100644 (file)
@@ -100,7 +100,20 @@ namespace ceph {
   }
 
   std::ostream& operator<<(std::ostream& m, const timespan& t) {
-    return m << std::chrono::duration<double>(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<typename Clock,