diff options
author | Henning Baldersheim <balder@yahoo-inc.com> | 2019-12-05 06:28:38 -0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-12-05 06:28:38 -0800 |
commit | fa9c3e1bdd88b6919eaff9fba12e693262031581 (patch) | |
tree | 9d828d7a5d61b8a637f10285a85385a316915686 /config | |
parent | f3335bc568a4ba16d05d6f8e3bf9ce26e12022e5 (diff) | |
parent | 516e1e2f28180c8055ccfdd640ea2b6051e4e648 (diff) |
Merge pull request #11509 from vespa-engine/balder/use-system-time-in-trace
Balder/use system time in trace
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() {} }; |