From d817a7407ee9cef2684a9777a0b5d33c6b35a5f3 Mon Sep 17 00:00:00 2001 From: Henning Baldersheim Date: Fri, 15 Nov 2019 09:42:09 +0000 Subject: Use steady_clock --- fastos/src/vespa/fastos/timestamp.cpp | 16 +++++++++++++--- fastos/src/vespa/fastos/timestamp.h | 6 ++++++ .../tests/groupingengine/groupingengine_benchmark.cpp | 4 ++-- .../src/tests/array/allocinarray_benchmark.cpp | 2 +- staging_vespalib/src/tests/array/sort_benchmark.cpp | 2 +- staging_vespalib/src/tests/rusage/rusage_test.cpp | 2 +- staging_vespalib/src/vespa/vespalib/util/rusage.cpp | 4 ++-- 7 files changed, 26 insertions(+), 10 deletions(-) diff --git a/fastos/src/vespa/fastos/timestamp.cpp b/fastos/src/vespa/fastos/timestamp.cpp index 553d44ac59b..8f8480d09ab 100644 --- a/fastos/src/vespa/fastos/timestamp.cpp +++ b/fastos/src/vespa/fastos/timestamp.cpp @@ -32,7 +32,8 @@ TimeStamp::asString(double timeInSeconds) return std::string(retval); } -int64_t ClockSystem::now() +int64_t +ClockSystem::now() { struct timeval timeNow; gettimeofday(&timeNow, nullptr); @@ -42,17 +43,26 @@ int64_t ClockSystem::now() return ns; } -time_t time() { +time_t +time() { return system_clock::to_time_t(system_clock::now()); } namespace { -TimeStamp steady_now() { +int64_t +steady_now() { return duration_cast(steady_clock::now().time_since_epoch()).count(); } } + +int64_t +ClockSteady::now() +{ + return steady_now(); +} + void StopWatch::start() { _startTime = steady_now(); diff --git a/fastos/src/vespa/fastos/timestamp.h b/fastos/src/vespa/fastos/timestamp.h index 6df83457258..21ef9d6df75 100644 --- a/fastos/src/vespa/fastos/timestamp.h +++ b/fastos/src/vespa/fastos/timestamp.h @@ -61,6 +61,12 @@ public: static int64_t now(); }; +class ClockSteady +{ +public: + static int64_t now(); +}; + class StopWatch { public: diff --git a/searchlib/src/tests/groupingengine/groupingengine_benchmark.cpp b/searchlib/src/tests/groupingengine/groupingengine_benchmark.cpp index 37aa9cc3268..46af181c26b 100644 --- a/searchlib/src/tests/groupingengine/groupingengine_benchmark.cpp +++ b/searchlib/src/tests/groupingengine/groupingengine_benchmark.cpp @@ -131,7 +131,7 @@ public: AggregationContext::AggregationContext() : _attrMan(), _result(), _attrCtx(_attrMan.createContext()) {} -AggregationContext::~AggregationContext() {} +AggregationContext::~AggregationContext() = default; //----------------------------------------------------------------------------- class Test : public TestApp @@ -277,7 +277,7 @@ Test::Main() LOG(info, "sizeof(CountAggregationResult) = %ld", sizeof(CountAggregationResult)); LOG(info, "sizeof(Int64ResultNode) = %ld", sizeof(Int64ResultNode)); - fastos::TimeStamp start(fastos::ClockSystem::now()); + fastos::TimeStamp start(fastos::ClockSteady::now()); if (idType == "int") { if (aggrType == "sum") { benchmarkIntegerSum(useEngine, numDocs, numQueries, maxGroups); diff --git a/staging_vespalib/src/tests/array/allocinarray_benchmark.cpp b/staging_vespalib/src/tests/array/allocinarray_benchmark.cpp index d222a26c496..5e208864502 100644 --- a/staging_vespalib/src/tests/array/allocinarray_benchmark.cpp +++ b/staging_vespalib/src/tests/array/allocinarray_benchmark.cpp @@ -111,7 +111,7 @@ Test::Main() count = strtol(_argv[2], NULL, 0); } TEST_INIT("allocinarray_benchmark"); - fastos::TimeStamp start(fastos::ClockSystem::now()); + fastos::TimeStamp start(fastos::ClockSteady::now()); if (type == "direct") { benchmarkTree(count); } else { diff --git a/staging_vespalib/src/tests/array/sort_benchmark.cpp b/staging_vespalib/src/tests/array/sort_benchmark.cpp index 1914e3ead9e..bdb96567f9e 100644 --- a/staging_vespalib/src/tests/array/sort_benchmark.cpp +++ b/staging_vespalib/src/tests/array/sort_benchmark.cpp @@ -100,7 +100,7 @@ Test::Main() payLoad = strtol(_argv[3], NULL, 0); } TEST_INIT("sort_benchmark"); - fastos::TimeStamp start(fastos::ClockSystem::now()); + fastos::TimeStamp start(fastos::ClockSteady::now()); if (payLoad < 8) { typedef TT<8> T; if (type == "sortdirect") { diff --git a/staging_vespalib/src/tests/rusage/rusage_test.cpp b/staging_vespalib/src/tests/rusage/rusage_test.cpp index 32dc5b42116..503018ee70d 100644 --- a/staging_vespalib/src/tests/rusage/rusage_test.cpp +++ b/staging_vespalib/src/tests/rusage/rusage_test.cpp @@ -30,7 +30,7 @@ Test::testRUsage() RUsage diff = r2-r1; EXPECT_EQUAL(diff.toString(), r2.toString()); { - RUsage then = RUsage::createSelf(17765895674); + RUsage then = RUsage::createSelf(7); RUsage now = RUsage::createSelf(); EXPECT_NOT_EQUAL(now.toString(), then.toString()); } diff --git a/staging_vespalib/src/vespa/vespalib/util/rusage.cpp b/staging_vespalib/src/vespa/vespalib/util/rusage.cpp index 62d0158f784..96a9c7ef206 100644 --- a/staging_vespalib/src/vespa/vespalib/util/rusage.cpp +++ b/staging_vespalib/src/vespa/vespalib/util/rusage.cpp @@ -43,7 +43,7 @@ RUsage RUsage::createChildren() RUsage RUsage::createSelf(const fastos::TimeStamp & since) { RUsage r; - r._time = fastos::TimeStamp(fastos::ClockSystem::now()) - since; + r._time = fastos::TimeStamp(fastos::ClockSteady::now()) - since; if (getrusage(RUSAGE_SELF, &r) != 0) { throw std::runtime_error(vespalib::make_string("getrusage failed with errno = %d", errno).c_str()); } @@ -53,7 +53,7 @@ RUsage RUsage::createSelf(const fastos::TimeStamp & since) RUsage RUsage::createChildren(const fastos::TimeStamp & since) { RUsage r; - r._time = fastos::TimeStamp(fastos::ClockSystem::now()) - since; + r._time = fastos::TimeStamp(fastos::ClockSteady::now()) - since; if (getrusage(RUSAGE_CHILDREN, &r) != 0) { throw std::runtime_error(vespalib::make_string("getrusage failed with errno = %d", errno).c_str()); } -- cgit v1.2.3