summaryrefslogtreecommitdiffstats
path: root/vespalib
diff options
context:
space:
mode:
authorHenning Baldersheim <balder@yahoo-inc.com>2019-12-09 17:43:24 +0000
committerHenning Baldersheim <balder@yahoo-inc.com>2019-12-16 23:48:46 +0000
commit6a807615c7ee6364362a9a14d725165e948c5585 (patch)
tree3981eab5e1a943e68f9a0bd7b738d506dc1ca01d /vespalib
parent225be01d5405c179584eb7fc08309c8f4a08fb22 (diff)
Drop all of TimeStamp too.
Diffstat (limited to 'vespalib')
-rw-r--r--vespalib/src/tests/closure/closure_test.cpp1
-rw-r--r--vespalib/src/vespa/vespalib/util/time.cpp24
-rw-r--r--vespalib/src/vespa/vespalib/util/time.h5
3 files changed, 29 insertions, 1 deletions
diff --git a/vespalib/src/tests/closure/closure_test.cpp b/vespalib/src/tests/closure/closure_test.cpp
index 5ba6ecf2a56..9faabb56fc5 100644
--- a/vespalib/src/tests/closure/closure_test.cpp
+++ b/vespalib/src/tests/closure/closure_test.cpp
@@ -6,7 +6,6 @@
using std::shared_ptr;
using std::unique_ptr;
-using std::string;
using namespace vespalib;
namespace {
diff --git a/vespalib/src/vespa/vespalib/util/time.cpp b/vespalib/src/vespa/vespalib/util/time.cpp
index 01f40152029..fd5d3e3055e 100644
--- a/vespalib/src/vespa/vespalib/util/time.cpp
+++ b/vespalib/src/vespa/vespalib/util/time.cpp
@@ -12,6 +12,30 @@ to_utc(steady_time ts) {
return system_time(nowUtc.time_since_epoch() - nowSteady.time_since_epoch() + ts.time_since_epoch());
}
+string
+to_string(duration dur)
+{
+ time_t timeStamp = std::chrono::duration_cast<std::chrono::seconds>(dur).count();
+ struct tm timeStruct;
+ gmtime_r(&timeStamp, &timeStruct);
+ char timeString[128];
+ strftime(timeString, sizeof(timeString), "%F %T", &timeStruct);
+ char retval[160];
+ uint32_t milliSeconds = count_ms(dur)%1000;
+ snprintf(retval, sizeof(retval), "%s.%03u UTC", timeString, milliSeconds);
+ return std::string(retval);
+}
+
+string
+to_string(system_time time) {
+ return to_string(time.time_since_epoch());
+}
+
+string
+to_string(steady_time time) {
+ return to_string(time.time_since_epoch());
+}
+
Timer::~Timer() = default;
void
diff --git a/vespalib/src/vespa/vespalib/util/time.h b/vespalib/src/vespa/vespalib/util/time.h
index 47dc54d40c2..f6841c70258 100644
--- a/vespalib/src/vespa/vespalib/util/time.h
+++ b/vespalib/src/vespa/vespalib/util/time.h
@@ -3,6 +3,7 @@
#pragma once
#include <chrono>
+#include <vespa/vespalib/stllike/string.h>
// Guidelines:
//
@@ -61,6 +62,10 @@ constexpr duration from_timeval(const timeval & tv) {
return duration(tv.tv_sec*1000000000L + tv.tv_usec*1000L);
}
+vespalib::string to_string(system_time time);
+vespalib::string to_string(steady_time time);
+vespalib::string to_string(duration time);
+
/**
* Simple utility class used to measure how much time has elapsed
* since it was constructed.