Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(2005)

Unified Diff: base/time/time.cc

Issue 669083002: Add logging support for base::Time* types. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Change output for TimeTicks to bogo-microseconds. Created 6 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « base/time/time.h ('k') | base/time/time_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: base/time/time.cc
diff --git a/base/time/time.cc b/base/time/time.cc
index f7313565a3e80542599fc597642b9594a4f426db..ce9d12c0c2e5885c10b6a5ff08715ffc0bcf5ca5 100644
--- a/base/time/time.cc
+++ b/base/time/time.cc
@@ -4,12 +4,15 @@
#include "base/time/time.h"
+#include <ios>
#include <limits>
#include <ostream>
+#include <sstream>
#include "base/float_util.h"
#include "base/lazy_instance.h"
#include "base/logging.h"
+#include "base/strings/stringprintf.h"
#include "base/third_party/nspr/prtime.h"
namespace base {
@@ -94,6 +97,10 @@ int64 TimeDelta::InMicroseconds() const {
return delta_;
}
+std::ostream& operator<<(std::ostream& os, TimeDelta time_delta) {
+ return os << time_delta.InSecondsF() << "s";
+}
+
// Time -----------------------------------------------------------------------
// static
@@ -230,6 +237,20 @@ bool Time::FromStringInternal(const char* time_string,
return true;
}
+std::ostream& operator<<(std::ostream& os, Time time) {
+ Time::Exploded exploded;
+ time.UTCExplode(&exploded);
+ // Use StringPrintf because iostreams formatting is painful.
+ return os << StringPrintf("%04d-%02d-%02d %02d:%02d:%02d.%03d UTC",
+ exploded.year,
+ exploded.month,
+ exploded.day_of_month,
+ exploded.hour,
+ exploded.minute,
+ exploded.second,
+ exploded.millisecond);
+}
+
// Local helper class to hold the conversion from Time to TickTime at the
// time of the Unix epoch.
class UnixEpochSingleton {
@@ -253,6 +274,16 @@ TimeTicks TimeTicks::UnixEpoch() {
return leaky_unix_epoch_singleton_instance.Get().unix_epoch();
}
+std::ostream& operator<<(std::ostream& os, TimeTicks time_ticks) {
+ // This function formats a TimeTicks object as "bogo-microseconds".
+ // The origin and granularity of the count are platform-specific, and may very
+ // from run to run. Although bogo-microseconds usually roughly correspond to
+ // real microseconds, the only real guarantee is that the number never goes
+ // down during a single run.
+ const TimeDelta as_time_delta = time_ticks - TimeTicks();
+ return os << as_time_delta.InMicroseconds() << " bogo-microseconds";
+}
+
// Time::Exploded -------------------------------------------------------------
inline bool is_in_range(int value, int lo, int hi) {
« no previous file with comments | « base/time/time.h ('k') | base/time/time_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698