diff options
author | Henning Baldersheim <balder@yahoo-inc.com> | 2019-12-16 21:34:54 -0600 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-12-16 21:34:54 -0600 |
commit | 8a02ad01e25ed2483bd0f1c8abdec8eabf44634a (patch) | |
tree | 253ee93b860f20a9c1deeb4cf0f6a31945bf6bf8 /staging_vespalib | |
parent | 2f8e6f0cb74ef77a645e7543975aca736f7649a9 (diff) |
Revert "Balder/remove steadytimestamp 2"
Diffstat (limited to 'staging_vespalib')
11 files changed, 73 insertions, 60 deletions
diff --git a/staging_vespalib/src/tests/array/allocinarray_benchmark.cpp b/staging_vespalib/src/tests/array/allocinarray_benchmark.cpp index db468044e48..a9e1499f014 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"); - steady_time start(steady_clock::now()); + fastos::SteadyTimeStamp 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 3fd900503c4..03a99aa044f 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"); - steady_time start(steady_clock::now()); + fastos::SteadyTimeStamp start(fastos::ClockSteady::now()); if (payLoad < 8) { typedef TT<8> T; if (type == "sortdirect") { diff --git a/staging_vespalib/src/tests/clock/clock_benchmark.cpp b/staging_vespalib/src/tests/clock/clock_benchmark.cpp index cbf7275f06e..a9618d50682 100644 --- a/staging_vespalib/src/tests/clock/clock_benchmark.cpp +++ b/staging_vespalib/src/tests/clock/clock_benchmark.cpp @@ -10,10 +10,7 @@ #include <mutex> using vespalib::Clock; -using vespalib::steady_time; -using vespalib::steady_clock; -using vespalib::duration; -using vespalib::to_s; +using fastos::TimeStamp; struct UpdateClock { virtual ~UpdateClock() {} @@ -92,12 +89,12 @@ struct Sampler : public SamplerBase { { } void Run(FastOS_ThreadInterface *, void *) override { uint64_t samples; - steady_time prev = _func(); + fastos::SteadyTimeStamp prev = _func(); for (samples = 0; (samples < _samples); samples++) { - steady_time now = _func(); - duration diff = now - prev; - if (diff > duration::zero()) prev = now; - _count[1 + ((diff == duration::zero()) ? 0 : (diff > duration::zero()) ? 1 : -1)]++; + fastos::SteadyTimeStamp now = _func(); + fastos::TimeStamp diff = now - prev; + if (diff > 0) prev = now; + _count[1 + ((diff == 0) ? 0 : (diff > 0) ? 1 : -1)]++; } } @@ -108,7 +105,7 @@ template<typename Func> void benchmark(const char * desc, FastOS_ThreadPool & pool, uint64_t samples, uint32_t numThreads, Func func) { std::vector<std::unique_ptr<SamplerBase>> threads; threads.reserve(numThreads); - steady_time start = steady_clock::now(); + fastos::SteadyTimeStamp start = fastos::ClockSteady::now(); for (uint32_t i(0); i < numThreads; i++) { SamplerBase * sampler = new Sampler<Func>(func, i); sampler->_samples = samples; @@ -123,7 +120,7 @@ void benchmark(const char * desc, FastOS_ThreadPool & pool, uint64_t samples, ui count[i] += sampler->_count[i]; } } - printf("%s: Took %ld clock samples in %2.3f with [%ld, %ld, %ld] counts\n", desc, samples, to_s(steady_clock::now() - start), count[0], count[1], count[2]); + printf("%s: Took %ld clock samples in %2.3f with [%ld, %ld, %ld] counts\n", desc, samples, (fastos::ClockSteady::now() - start).sec(), count[0], count[1], count[2]); } int @@ -149,26 +146,26 @@ main(int , char *argv[]) return clock.getTimeNSAssumeRunning(); }); benchmark("uint64_t", pool, samples, numThreads, [&nsValue]() { - return steady_time (duration(nsValue._value)); + return fastos::SteadyTimeStamp(nsValue._value) ; }); benchmark("volatile uint64_t", pool, samples, numThreads, [&nsVolatile]() { - return steady_time(duration(nsVolatile._value)); + return fastos::SteadyTimeStamp(nsVolatile._value) ; }); benchmark("memory_order_relaxed", pool, samples, numThreads, [&nsAtomic]() { - return steady_time(duration(nsAtomic._value.load(std::memory_order_relaxed))); + return fastos::SteadyTimeStamp(nsAtomic._value.load(std::memory_order_relaxed)) ; }); benchmark("memory_order_consume", pool, samples, numThreads, [&nsAtomic]() { - return steady_time(duration(nsAtomic._value.load(std::memory_order_consume))); + return fastos::SteadyTimeStamp(nsAtomic._value.load(std::memory_order_consume)) ; }); benchmark("memory_order_acquire", pool, samples, numThreads, [&nsAtomic]() { - return steady_time(duration(nsAtomic._value.load(std::memory_order_acquire))); + return fastos::SteadyTimeStamp(nsAtomic._value.load(std::memory_order_acquire)) ; }); benchmark("memory_order_seq_cst", pool, samples, numThreads, [&nsAtomic]() { - return steady_time(duration(nsAtomic._value.load(std::memory_order_seq_cst))); + return fastos::SteadyTimeStamp(nsAtomic._value.load(std::memory_order_seq_cst)) ; }); - benchmark("vespalib::steady_time::now()", pool, samples, numThreads, []() { - return steady_clock::now(); + benchmark("fastos::ClockSteady::now()", pool, samples, numThreads, []() { + return fastos::ClockSteady::now(); }); pool.Close(); diff --git a/staging_vespalib/src/tests/clock/clock_test.cpp b/staging_vespalib/src/tests/clock/clock_test.cpp index 4a06787fce5..b5650244a45 100644 --- a/staging_vespalib/src/tests/clock/clock_test.cpp +++ b/staging_vespalib/src/tests/clock/clock_test.cpp @@ -2,11 +2,11 @@ #include <vespa/vespalib/testkit/testapp.h> #include <vespa/vespalib/util/clock.h> +#include <vespa/vespalib/util/time.h> #include <vespa/fastos/thread.h> using vespalib::Clock; -using vespalib::duration; -using vespalib::steady_time; +using fastos::TimeStamp; TEST("Test that clock is ticking forward") { @@ -14,15 +14,15 @@ TEST("Test that clock is ticking forward") { Clock clock(0.050); FastOS_ThreadPool pool(0x10000); ASSERT_TRUE(pool.NewThread(clock.getRunnable(), nullptr) != nullptr); - steady_time start = clock.getTimeNS(); + fastos::SteadyTimeStamp start = clock.getTimeNS(); std::this_thread::sleep_for(5s); - steady_time stop = clock.getTimeNS(); + fastos::SteadyTimeStamp stop = clock.getTimeNS(); EXPECT_TRUE(stop > start); std::this_thread::sleep_for(6s); clock.stop(); - steady_time stop2 = clock.getTimeNS(); + fastos::SteadyTimeStamp stop2 = clock.getTimeNS(); EXPECT_TRUE(stop2 > stop); - EXPECT_TRUE(vespalib::count_ms(stop2 - stop) > 1000); + EXPECT_TRUE((stop2 - stop)/TimeStamp::MICRO > 1000); } TEST_MAIN() { TEST_RUN_ALL(); }
\ No newline at end of file diff --git a/staging_vespalib/src/tests/rusage/rusage_test.cpp b/staging_vespalib/src/tests/rusage/rusage_test.cpp index 0f2992e09e8..23b9d4072b1 100644 --- a/staging_vespalib/src/tests/rusage/rusage_test.cpp +++ b/staging_vespalib/src/tests/rusage/rusage_test.cpp @@ -5,7 +5,23 @@ using namespace vespalib; -TEST("testRUsage") +class Test : public TestApp +{ +public: + int Main() override; + void testRUsage(); +}; + +int +Test::Main() +{ + TEST_INIT("rusage_test"); + testRUsage(); + TEST_DONE(); +} + +void +Test::testRUsage() { RUsage r1; EXPECT_EQUAL("", r1.toString()); @@ -14,12 +30,12 @@ TEST("testRUsage") RUsage diff = r2-r1; EXPECT_EQUAL(diff.toString(), r2.toString()); { - RUsage then = RUsage::createSelf(steady_time(7ns)); + RUsage then = RUsage::createSelf(fastos::SteadyTimeStamp(7)); RUsage now = RUsage::createSelf(); EXPECT_NOT_EQUAL(now.toString(), then.toString()); } { - RUsage then = RUsage::createChildren(steady_time(1337583ns)); + RUsage then = RUsage::createChildren(fastos::SteadyTimeStamp(1337583)); RUsage now = RUsage::createChildren(); EXPECT_NOT_EQUAL(now.toString(), then.toString()); } @@ -54,4 +70,4 @@ TEST("testRUsage") } } -TEST_MAIN() { TEST_RUN_ALL(); } +TEST_APPHOOK(Test) diff --git a/staging_vespalib/src/vespa/vespalib/util/clock.cpp b/staging_vespalib/src/vespa/vespalib/util/clock.cpp index 0a7f89781e8..cd2a13029ab 100644 --- a/staging_vespalib/src/vespa/vespalib/util/clock.cpp +++ b/staging_vespalib/src/vespa/vespalib/util/clock.cpp @@ -80,7 +80,7 @@ Clock::~Clock() void Clock::setTime() const { - _timeNS.store(count_ns(steady_clock::now().time_since_epoch()), std::memory_order_relaxed); + _timeNS.store(fastos::ClockSteady::now() - fastos::SteadyTimeStamp::ZERO, std::memory_order_relaxed); } void diff --git a/staging_vespalib/src/vespa/vespalib/util/clock.h b/staging_vespalib/src/vespa/vespalib/util/clock.h index d506b0c7e16..e9e1ebace3f 100644 --- a/staging_vespalib/src/vespa/vespalib/util/clock.h +++ b/staging_vespalib/src/vespa/vespalib/util/clock.h @@ -1,7 +1,7 @@ // Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. #pragma once -#include <vespa/vespalib/util/time.h> +#include <vespa/fastos/timestamp.h> #include <atomic> #include <memory> @@ -31,14 +31,14 @@ public: Clock(double timePeriod=0.100); ~Clock(); - vespalib::steady_time getTimeNS() const { + fastos::SteadyTimeStamp getTimeNS() const { if (!_running) { setTime(); } return getTimeNSAssumeRunning(); } - vespalib::steady_time getTimeNSAssumeRunning() const { - return vespalib::steady_time(std::chrono::nanoseconds(_timeNS.load(std::memory_order_relaxed))); + fastos::SteadyTimeStamp getTimeNSAssumeRunning() const { + return fastos::SteadyTimeStamp(_timeNS.load(std::memory_order_relaxed)); } void stop(); diff --git a/staging_vespalib/src/vespa/vespalib/util/doom.cpp b/staging_vespalib/src/vespa/vespalib/util/doom.cpp index 72b854338dc..87b24799721 100644 --- a/staging_vespalib/src/vespa/vespalib/util/doom.cpp +++ b/staging_vespalib/src/vespa/vespalib/util/doom.cpp @@ -4,8 +4,8 @@ namespace vespalib { -Doom::Doom(const Clock &clock, steady_time softDoom, - steady_time hardDoom, bool explicitSoftDoom) +Doom::Doom(const vespalib::Clock &clock, fastos::SteadyTimeStamp softDoom, + fastos::SteadyTimeStamp hardDoom, bool explicitSoftDoom) : _clock(clock), _softDoom(softDoom), _hardDoom(hardDoom), diff --git a/staging_vespalib/src/vespa/vespalib/util/doom.h b/staging_vespalib/src/vespa/vespalib/util/doom.h index a1280942ad7..d85c3dc9084 100644 --- a/staging_vespalib/src/vespa/vespalib/util/doom.h +++ b/staging_vespalib/src/vespa/vespalib/util/doom.h @@ -8,22 +8,22 @@ namespace vespalib { class Doom { public: - Doom(const Clock &clock, steady_time doom) + Doom(const vespalib::Clock &clock, fastos::SteadyTimeStamp doom) : Doom(clock, doom, doom, false) {} - Doom(const Clock &clock, steady_time softDoom, - steady_time hardDoom, bool explicitSoftDoom); + Doom(const vespalib::Clock &clock, fastos::SteadyTimeStamp softDoom, + fastos::SteadyTimeStamp hardDoom, bool explicitSoftDoom); bool soft_doom() const { return (_clock.getTimeNSAssumeRunning() > _softDoom); } bool hard_doom() const { return (_clock.getTimeNSAssumeRunning() > _hardDoom); } - duration soft_left() const { return _softDoom - _clock.getTimeNS(); } - duration hard_left() const { return _hardDoom - _clock.getTimeNS(); } + fastos::TimeStamp soft_left() const { return _softDoom - _clock.getTimeNS(); } + fastos::TimeStamp hard_left() const { return _hardDoom - _clock.getTimeNS(); } bool isExplicitSoftDoom() const { return _isExplicitSoftDoom; } private: - const Clock &_clock; - steady_time _softDoom; - steady_time _hardDoom; - bool _isExplicitSoftDoom; + const vespalib::Clock &_clock; + fastos::SteadyTimeStamp _softDoom; + fastos::SteadyTimeStamp _hardDoom; + bool _isExplicitSoftDoom; }; } diff --git a/staging_vespalib/src/vespa/vespalib/util/rusage.cpp b/staging_vespalib/src/vespa/vespalib/util/rusage.cpp index d5910148c79..32f76775586 100644 --- a/staging_vespalib/src/vespa/vespalib/util/rusage.cpp +++ b/staging_vespalib/src/vespa/vespalib/util/rusage.cpp @@ -33,20 +33,20 @@ RUsage::RUsage() : RUsage RUsage::createSelf() { - return createSelf(vespalib::steady_time()); + return createSelf(fastos::SteadyTimeStamp()); } RUsage RUsage::createChildren() { - return createChildren(vespalib::steady_time()); + return createChildren(fastos::SteadyTimeStamp()); } RUsage -RUsage::createSelf(vespalib::steady_time since) +RUsage::createSelf(fastos::SteadyTimeStamp since) { RUsage r; - r._time = vespalib::steady_clock::now() - since; + r._time = 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()); } @@ -54,10 +54,10 @@ RUsage::createSelf(vespalib::steady_time since) } RUsage -RUsage::createChildren(vespalib::steady_time since) +RUsage::createChildren(fastos::SteadyTimeStamp since) { RUsage r; - r._time = vespalib::steady_clock::now() - since; + r._time = 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()); } @@ -68,9 +68,9 @@ vespalib::string RUsage::toString() { vespalib::string s; - if (_time != duration::zero()) s += make_string("duration = %1.6f\n", vespalib::to_s(_time)); - if (from_timeval(ru_utime) > duration::zero()) s += make_string("user time = %1.6f\n", to_s(from_timeval(ru_utime))); - if (from_timeval(ru_stime) > duration::zero()) s += make_string("system time = %1.6f\n", to_s(from_timeval(ru_stime))); + if (_time.sec() != 0.0) s += make_string("duration = %1.6f\n", _time.sec()); + if (fastos::TimeStamp(ru_utime).sec() != 0.0) s += make_string("user time = %1.6f\n", fastos::TimeStamp(ru_utime).sec()); + if (fastos::TimeStamp(ru_stime).sec() != 0.0) s += make_string("system time = %1.6f\n", fastos::TimeStamp(ru_stime).sec()); if (ru_maxrss != 0) s += make_string("ru_maxrss = %ld\n", ru_maxrss); if (ru_ixrss != 0) s += make_string("ru_ixrss = %ld\n", ru_ixrss); if (ru_idrss != 0) s += make_string("ru_idrss = %ld\n", ru_idrss); diff --git a/staging_vespalib/src/vespa/vespalib/util/rusage.h b/staging_vespalib/src/vespa/vespalib/util/rusage.h index f2cea3ba0ab..381d4d764e7 100644 --- a/staging_vespalib/src/vespa/vespalib/util/rusage.h +++ b/staging_vespalib/src/vespa/vespalib/util/rusage.h @@ -2,7 +2,7 @@ #pragma once #include <vespa/vespalib/stllike/string.h> -#include <vespa/vespalib/util/time.h> +#include <vespa/fastos/timestamp.h> #include <sys/resource.h> namespace vespalib { @@ -17,19 +17,19 @@ public: * Will create an RUsage and initialize member with RUSAGE_SELF **/ static RUsage createSelf(); - static RUsage createSelf(vespalib::steady_time since); + static RUsage createSelf(fastos::SteadyTimeStamp since); /** * Will create an RUsage and initialize member with RUSAGE_CHILDREN **/ static RUsage createChildren(); - static RUsage createChildren(vespalib::steady_time since); + static RUsage createChildren(fastos::SteadyTimeStamp since); /** * Will create an RUsage and initialize member with RUSAGE_CHILDREN **/ vespalib::string toString(); RUsage & operator -= (const RUsage & rhs); private: - vespalib::duration _time; + fastos::TimeStamp _time; }; RUsage operator -(const RUsage & a, const RUsage & b); |