]> git.apps.os.sepia.ceph.com Git - ceph-ci.git/commitdiff
ceph_time: add operator<< for more clock types
authorKefu Chai <kchai@redhat.com>
Sat, 30 Apr 2016 17:12:59 +0000 (01:12 +0800)
committerKefu Chai <tchaikov@gmail.com>
Sat, 30 Apr 2016 18:55:01 +0000 (02:55 +0800)
Signed-off-by: Kefu Chai <kchai@redhat.com>
src/common/ceph_time.cc
src/common/ceph_time.h

index e93dcd97206a13bdbf1e2315946171d541cec99e..d7b512b0ac8a785886bcda155210c8c009791ed6 100644 (file)
@@ -72,7 +72,10 @@ namespace ceph {
   using std::chrono::seconds;
   using std::chrono::microseconds;
 
-  std::ostream& operator<<(std::ostream& m, const mono_time& t) {
+  template<typename Clock,
+          typename std::enable_if<Clock::is_steady>::type*>
+  std::ostream& operator<<(std::ostream& m,
+                          const std::chrono::time_point<Clock>& t) {
     return m << std::chrono::duration<double>(t.time_since_epoch()).count()
             << "s";
   }
@@ -81,14 +84,17 @@ namespace ceph {
     return m << std::chrono::duration<double>(t).count() << "s";
   }
 
-  std::ostream& operator<<(std::ostream& m, const real_time& t) {
+  template<typename Clock,
+          typename std::enable_if<!Clock::is_steady>::type*>
+  std::ostream& operator<<(std::ostream& m,
+                          const std::chrono::time_point<Clock>& t) {
     m.setf(std::ios::right);
     char oldfill = m.fill();
     m.fill('0');
     // localtime.  this looks like an absolute time.
     //  aim for http://en.wikipedia.org/wiki/ISO_8601
     struct tm bdt;
-    time_t tt = ceph::real_clock::to_time_t(t);
+    time_t tt = Clock::to_time_t(t);
     localtime_r(&tt, &bdt);
     m << std::setw(4) << (bdt.tm_year+1900)  // 2007 -> '07'
       << '-' << std::setw(2) << (bdt.tm_mon+1)
@@ -103,4 +109,13 @@ namespace ceph {
     m.unsetf(std::ios::right);
     return m;
   }
-};
+
+  template std::ostream&
+  operator<< <mono_clock>(std::ostream& m, const mono_time& t);
+  template std::ostream&
+  operator<< <real_clock>(std::ostream& m, const real_time& t);
+  template std::ostream&
+  operator<< <coarse_mono_clock>(std::ostream& m, const coarse_mono_time& t);
+  template std::ostream&
+  operator<< <coarse_real_clock>(std::ostream& m, const coarse_real_time& t);
+}
index 1cfb6b8eeb04e806b8e90565b8519aa760097e0f..e5197ba96cae66269e64ecceb4c540a1dbcb3d61 100644 (file)
@@ -403,8 +403,14 @@ namespace ceph {
   }
 
   std::ostream& operator<<(std::ostream& m, const timespan& t);
-  std::ostream& operator<<(std::ostream& m, const real_time& t);
-  std::ostream& operator<<(std::ostream& m, const mono_time& t);
+  template<typename Clock,
+          typename std::enable_if<!Clock::is_steady>::type* = nullptr>
+  std::ostream& operator<<(std::ostream& m,
+                          const std::chrono::time_point<Clock>& t);
+  template<typename Clock,
+          typename std::enable_if<Clock::is_steady>::type* = nullptr>
+  std::ostream& operator<<(std::ostream& m,
+                          const std::chrono::time_point<Clock>& t);
 
   // The way std::chrono handles the return type of subtraction is not
   // wonderful. The difference of two unsigned types SHOULD be signed.