diff options
author | Henning Baldersheim <balder@yahoo-inc.com> | 2019-12-05 01:10:26 +0000 |
---|---|---|
committer | Henning Baldersheim <balder@yahoo-inc.com> | 2019-12-05 01:10:26 +0000 |
commit | 673d9aa646a4e99320cbeaa717e9362555fd9e8e (patch) | |
tree | 02e3d11543e76dd102a340d2ffd2a7e436f4c159 /config | |
parent | eb814155171b9d46eaa213ed3000a874aa250fa4 (diff) |
Use system_time in trace instead of int64_t count of milliseconds.
Diffstat (limited to 'config')
-rw-r--r-- | config/src/tests/trace/trace.cpp | 13 | ||||
-rw-r--r-- | config/src/vespa/config/common/trace.cpp | 7 | ||||
-rw-r--r-- | config/src/vespa/config/common/trace.h | 2 |
3 files changed, 11 insertions, 11 deletions
diff --git a/config/src/tests/trace/trace.cpp b/config/src/tests/trace/trace.cpp index 33e25fa7ba2..fdb40d40893 100644 --- a/config/src/tests/trace/trace.cpp +++ b/config/src/tests/trace/trace.cpp @@ -2,7 +2,6 @@ #include <vespa/vespalib/testkit/test_kit.h> #include <vespa/config/common/trace.h> -#include <vespa/vespalib/trace/tracenode.h> using namespace config; @@ -11,9 +10,9 @@ using namespace vespalib::slime; struct FixedClock : public Clock { - FixedClock() : currentTime(0) { } - int64_t currentTime; - int64_t currentTimeMillis() const override { return currentTime; } + FixedClock() : _currentTime(duration::zero()) { } + vespalib::system_time _currentTime; + vespalib::system_time currentTime() const override { return _currentTime; } }; TEST("that trace can be serialized and deserialized") { @@ -38,7 +37,7 @@ TEST("that trace can be serialized and deserialized") { } TEST_F("that trace level is taken into account", FixedClock) { - f1.currentTime = 3; + f1._currentTime = vespalib::system_time(3ms); Trace trace(4, f1); trace.trace(4, "foo"); trace.trace(5, "bar"); @@ -58,11 +57,13 @@ TEST("that trace can be copied") { EXPECT_EQUAL(trace.toString(), trace2.toString()); } +constexpr vespalib::system_time epoch(duration::zero()); + TEST("ensure that system clock is used by default") { Trace trace(2); trace.trace(1, "foo"); TraceNode child(trace.getRoot().getChild(0)); - EXPECT_TRUE(child.getTimestamp() > 0); + EXPECT_TRUE(child.getTimestamp() > epoch); } TEST_MAIN() { TEST_RUN_ALL(); } diff --git a/config/src/vespa/config/common/trace.cpp b/config/src/vespa/config/common/trace.cpp index e6183a9fec1..d1bb154eda9 100644 --- a/config/src/vespa/config/common/trace.cpp +++ b/config/src/vespa/config/common/trace.cpp @@ -2,7 +2,6 @@ #include "trace.h" #include <vespa/vespalib/trace/slime_trace_serializer.h> #include <vespa/vespalib/trace/slime_trace_deserializer.h> -#include <vespa/fastos/timestamp.h> using namespace vespalib; using namespace vespalib::slime; @@ -11,8 +10,8 @@ namespace config { struct SystemClock : public Clock { - int64_t currentTimeMillis() const override { - return fastos::ClockSystem::now().timeSinceEpoch().ms(); + vespalib::system_time currentTime() const override { + return vespalib::system_clock::now(); } }; @@ -73,7 +72,7 @@ void Trace::trace(uint32_t level, const vespalib::string & message) { if (shouldTrace(level)) { - _root.addChild(message, _clock.currentTimeMillis()); + _root.addChild(message, _clock.currentTime()); } } diff --git a/config/src/vespa/config/common/trace.h b/config/src/vespa/config/common/trace.h index 9cfd2b1f88e..772cdb6f31e 100644 --- a/config/src/vespa/config/common/trace.h +++ b/config/src/vespa/config/common/trace.h @@ -12,7 +12,7 @@ namespace config { * Clock interface for acquiring time. */ struct Clock { - virtual int64_t currentTimeMillis() const = 0; + virtual vespalib::system_time currentTime() const = 0; virtual ~Clock() {} }; |