diff options
author | Henning Baldersheim <balder@yahoo-inc.com> | 2019-12-19 15:19:07 +0000 |
---|---|---|
committer | Henning Baldersheim <balder@yahoo-inc.com> | 2019-12-19 15:19:07 +0000 |
commit | e63afccea9618396374a6488519b7a894f94ac3c (patch) | |
tree | f1a68e0f9ade37424d5a51238cdabc477061bc8e /vespalib | |
parent | d043d0587d15ddeb014cd95f7392294241fa7f05 (diff) |
Only expose to_string for system_clock
Diffstat (limited to 'vespalib')
-rw-r--r-- | vespalib/src/vespa/vespalib/util/time.cpp | 17 | ||||
-rw-r--r-- | vespalib/src/vespa/vespalib/util/time.h | 2 |
2 files changed, 9 insertions, 10 deletions
diff --git a/vespalib/src/vespa/vespalib/util/time.cpp b/vespalib/src/vespa/vespalib/util/time.cpp index fd5d3e3055e..15dc8b4c781 100644 --- a/vespalib/src/vespa/vespalib/util/time.cpp +++ b/vespalib/src/vespa/vespalib/util/time.cpp @@ -2,6 +2,7 @@ #include "time.h" #include <thread> +#include <immintrin.h> namespace vespalib { @@ -12,27 +13,25 @@ to_utc(steady_time ts) { return system_time(nowUtc.time_since_epoch() - nowSteady.time_since_epoch() + ts.time_since_epoch()); } +namespace { + string -to_string(duration dur) -{ +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; + 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) { +to_string(system_time time) { return to_string(time.time_since_epoch()); } @@ -43,7 +42,9 @@ Timer::waitAtLeast(duration dur, bool busyWait) { if (busyWait) { steady_clock::time_point deadline = steady_clock::now() + dur; while (steady_clock::now() < deadline) { - for (int i = 0; i < 1000; i++) { } + for (int i = 0; i < 1000; i++) { + _mm_pause(); + } } } else { std::this_thread::sleep_for(dur); diff --git a/vespalib/src/vespa/vespalib/util/time.h b/vespalib/src/vespa/vespalib/util/time.h index 187d62001ae..d57d722efc4 100644 --- a/vespalib/src/vespa/vespalib/util/time.h +++ b/vespalib/src/vespa/vespalib/util/time.h @@ -67,8 +67,6 @@ constexpr duration from_timeval(const timeval & tv) { } 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 |