This is an automated email from the ASF dual-hosted git repository.

alexey pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/kudu.git

commit 4aef722348a39f0038a5669f41706052ca678619
Author: Abhishek Chennaka <[email protected]>
AuthorDate: Thu Oct 21 12:30:39 2021 -0400

    KUDU-3330 Define operator<< for MonoTime
    
    This patch implements the operator<< for MonoTime. This is needed for
    CHECK_XX and DCHECK_XX on MonoTime.
    
    Change-Id: I729c8a81c52ad800680187b89db1d224b7aec769
    Reviewed-on: http://gerrit.cloudera.org:8080/17961
    Reviewed-by: Alexey Serbin <[email protected]>
    Reviewed-by: Bankim Bhavsar <[email protected]>
    Tested-by: Kudu Jenkins
---
 src/kudu/util/monotime.cc |  8 ++++++++
 src/kudu/util/monotime.h  | 16 ++++++++++++++++
 2 files changed, 24 insertions(+)

diff --git a/src/kudu/util/monotime.cc b/src/kudu/util/monotime.cc
index 743f824..da7a6c5 100644
--- a/src/kudu/util/monotime.cc
+++ b/src/kudu/util/monotime.cc
@@ -21,6 +21,7 @@
 
 #include <ctime>
 #include <limits>
+#include <ostream>
 
 #include <glog/logging.h>
 
@@ -349,4 +350,11 @@ MonoDelta operator-(const MonoTime& t_end, const MonoTime& 
t_beg) {
   return MonoDelta(delta);
 }
 
+std::ostream& operator<<(std::ostream& os, const kudu::MonoTime& time) {
+  struct timespec ts;
+  time.ToTimeSpec(&ts);
+  os << ts.tv_nsec << "ns";
+  return os;
+}
+
 } // namespace kudu
diff --git a/src/kudu/util/monotime.h b/src/kudu/util/monotime.h
index d29a005..474dde1 100644
--- a/src/kudu/util/monotime.h
+++ b/src/kudu/util/monotime.h
@@ -21,6 +21,7 @@
 //       to be processed by a compiler lacking C++11 support.
 #include <stdint.h>
 
+#include <iosfwd>
 #include <string>
 
 #ifdef KUDU_HEADERS_NO_STUBS
@@ -490,6 +491,21 @@ MonoTime KUDU_EXPORT operator-(const MonoTime& t, const 
MonoDelta& delta);
 MonoDelta KUDU_EXPORT operator-(const MonoTime& t_end, const MonoTime& 
t_begin);
 ///@}
 
+/// @cond PRIVATE_API
+
+/// Allow the use of MonoTime with DCHECK_XX.
+///
+/// Private API.
+///
+/// @param [out] os
+///   An ostream output object.
+/// @param [in] time
+///   A MonoTime object to output.
+/// @return An ostream object containing the nanosecond point in time value
+///   of the Monotime object.
+std::ostream& operator<<(std::ostream& os, const kudu::MonoTime& time);
+/// @endcond
+
 } // namespace kudu
 
 #endif

Reply via email to