diff options
Diffstat (limited to 'staging_vespalib')
11 files changed, 60 insertions, 73 deletions
diff --git a/staging_vespalib/src/tests/array/allocinarray_benchmark.cpp b/staging_vespalib/src/tests/array/allocinarray_benchmark.cpp index a9e1499f014..db468044e48 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::SteadyTimeStamp start(fastos::ClockSteady::now()); + steady_time start(steady_clock::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 03a99aa044f..3fd900503c4 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::SteadyTimeStamp start(fastos::ClockSteady::now()); + steady_time start(steady_clock::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 a9618d50682..cbf7275f06e 100644 --- a/staging_vespalib/src/tests/clock/clock_benchmark.cpp +++ b/staging_vespalib/src/tests/clock/clock_benchmark.cpp @@ -10,7 +10,10 @@ #include <mutex> using vespalib::Clock; -using fastos::TimeStamp; +using vespalib::steady_time; +using vespalib::steady_clock; +using vespalib::duration; +using vespalib::to_s; struct UpdateClock { virtual ~UpdateClock() {} @@ -89,12 +92,12 @@ struct Sampler : public SamplerBase { { } void Run(FastOS_ThreadInterface *, void *) override { uint64_t samples; - fastos::SteadyTimeStamp prev = _func(); + steady_time prev = _func(); for (samples = 0; (samples < _samples); samples++) { - fastos::SteadyTimeStamp now = _func(); - fastos::TimeStamp diff = now - prev; - if (diff > 0) prev = now; - _count[1 + ((diff == 0) ? 0 : (diff > 0) ? 1 : -1)]++; + 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)]++; } } @@ -105,7 +108,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); - fastos::SteadyTimeStamp start = fastos::ClockSteady::now(); + steady_time start = steady_clock::now(); for (uint32_t i(0); i < numThreads; i++) { SamplerBase * sampler = new Sampler<Func>(func, i); sampler->_samples = samples; @@ -120,7 +123,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, (fastos::ClockSteady::now() - start).sec(), count[0], count[1], count[2]); + 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]); } int @@ -146,26 +149,26 @@ main(int , char *argv[]) return clock.getTimeNSAssumeRunning(); }); benchmark("uint64_t", pool, samples, numThreads, [&nsValue]() { - return fastos::SteadyTimeStamp(nsValue._value) ; + return steady_time (duration(nsValue._value)); }); benchmark("volatile uint64_t", pool, samples, numThreads, [&nsVolatile]() { - return fastos::SteadyTimeStamp(nsVolatile._value) ; + return steady_time(duration(nsVolatile._value)); }); benchmark("memory_order_relaxed", pool, samples, numThreads, [&nsAtomic]() { - return fastos::SteadyTimeStamp(nsAtomic._value.load(std::memory_order_relaxed)) ; + return steady_time(duration(nsAtomic._value.load(std::memory_order_relaxed))); }); benchmark("memory_order_consume", pool, samples, numThreads, [&nsAtomic]() { - return fastos::SteadyTimeStamp(nsAtomic._value.load(std::memory_order_consume)) ; + return steady_time(duration(nsAtomic._value.load(std::memory_order_consume))); }); benchmark("memory_order_acquire", pool, samples, numThreads, [&nsAtomic]() { - return fastos::SteadyTimeStamp(nsAtomic._value.load(std::memory_order_acquire)) ; + return steady_time(duration(nsAtomic._value.load(std::memory_order_acquire))); }); benchmark("memory_order_seq_cst", pool, samples, numThreads, [&nsAtomic]() { - return fastos::SteadyTimeStamp(nsAtomic._value.load(std::memory_order_seq_cst)) ; + return steady_time(duration(nsAtomic._value.load(std::memory_order_seq_cst))); }); - benchmark("fastos::ClockSteady::now()", pool, samples, numThreads, []() { - return fastos::ClockSteady::now(); + benchmark("vespalib::steady_time::now()", pool, samples, numThreads, []() { + return steady_clock::now(); }); pool.Close(); diff --git a/staging_vespalib/src/tests/clock/clock_test.cpp b/staging_vespalib/src/tests/clock/clock_test.cpp index b5650244a45..4a06787fce5 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 fastos::TimeStamp; +using vespalib::duration; +using vespalib::steady_time; 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); - fastos::SteadyTimeStamp start = clock.getTimeNS(); + steady_time start = clock.getTimeNS(); std::this_thread::sleep_for(5s); - fastos::SteadyTimeStamp stop = clock.getTimeNS(); + steady_time stop = clock.getTimeNS(); EXPECT_TRUE(stop > start); std::this_thread::sleep_for(6s); clock.stop(); - fastos::SteadyTimeStamp stop2 = clock.getTimeNS(); + steady_time stop2 = clock.getTimeNS(); EXPECT_TRUE(stop2 > stop); - EXPECT_TRUE((stop2 - stop)/TimeStamp::MICRO > 1000); + EXPECT_TRUE(vespalib::count_ms(stop2 - stop) > 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 23b9d4072b1..0f2992e09e8 100644 --- a/staging_vespalib/src/tests/rusage/rusage_test.cpp +++ b/staging_vespalib/src/tests/rusage/rusage_test.cpp @@ -5,23 +5,7 @@ using namespace vespalib; -class Test : public TestApp -{ -public: - int Main() override; - void testRUsage(); -}; - -int -Test::Main() -{ - TEST_INIT("rusage_test"); - testRUsage(); - TEST_DONE(); -} - -void -Test::testRUsage() +TEST("testRUsage") { RUsage r1; EXPECT_EQUAL("", r1.toString()); @@ -30,12 +14,12 @@ Test::testRUsage() RUsage diff = r2-r1; EXPECT_EQUAL(diff.toString(), r2.toString()); { - RUsage then = RUsage::createSelf(fastos::SteadyTimeStamp(7)); + RUsage then = RUsage::createSelf(steady_time(7ns)); RUsage now = RUsage::createSelf(); EXPECT_NOT_EQUAL(now.toString(), then.toString()); } { - RUsage then = RUsage::createChildren(fastos::SteadyTimeStamp(1337583)); + RUsage then = RUsage::createChildren(steady_time(1337583ns)); RUsage now = RUsage::createChildren(); EXPECT_NOT_EQUAL(now.toString(), then.toString()); } @@ -70,4 +54,4 @@ Test::testRUsage() } } -TEST_APPHOOK(Test) +TEST_MAIN() { TEST_RUN_ALL(); } diff --git a/staging_vespalib/src/vespa/vespalib/util/clock.cpp b/staging_vespalib/src/vespa/vespalib/util/clock.cpp index cd2a13029ab..0a7f89781e8 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(fastos::ClockSteady::now() - fastos::SteadyTimeStamp::ZERO, std::memory_order_relaxed); + _timeNS.store(count_ns(steady_clock::now().time_since_epoch()), 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 e9e1ebace3f..d506b0c7e16 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/fastos/timestamp.h> +#include <vespa/vespalib/util/time.h> #include <atomic> #include <memory> @@ -31,14 +31,14 @@ public: Clock(double timePeriod=0.100); ~Clock(); - fastos::SteadyTimeStamp getTimeNS() const { + vespalib::steady_time getTimeNS() const { if (!_running) { setTime(); } return getTimeNSAssumeRunning(); } - fastos::SteadyTimeStamp getTimeNSAssumeRunning() const { - return fastos::SteadyTimeStamp(_timeNS.load(std::memory_order_relaxed)); + vespalib::steady_time getTimeNSAssumeRunning() const { + return vespalib::steady_time(std::chrono::nanoseconds(_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 87b24799721..72b854338dc 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 vespalib::Clock &clock, fastos::SteadyTimeStamp softDoom, - fastos::SteadyTimeStamp hardDoom, bool explicitSoftDoom) +Doom::Doom(const Clock &clock, steady_time softDoom, + steady_time 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 d85c3dc9084..a1280942ad7 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 vespalib::Clock &clock, fastos::SteadyTimeStamp doom) + Doom(const Clock &clock, steady_time doom) : Doom(clock, doom, doom, false) {} - Doom(const vespalib::Clock &clock, fastos::SteadyTimeStamp softDoom, - fastos::SteadyTimeStamp hardDoom, bool explicitSoftDoom); + Doom(const Clock &clock, steady_time softDoom, + steady_time hardDoom, bool explicitSoftDoom); bool soft_doom() const { return (_clock.getTimeNSAssumeRunning() > _softDoom); } bool hard_doom() const { return (_clock.getTimeNSAssumeRunning() > _hardDoom); } - fastos::TimeStamp soft_left() const { return _softDoom - _clock.getTimeNS(); } - fastos::TimeStamp hard_left() const { return _hardDoom - _clock.getTimeNS(); } + duration soft_left() const { return _softDoom - _clock.getTimeNS(); } + duration hard_left() const { return _hardDoom - _clock.getTimeNS(); } bool isExplicitSoftDoom() const { return _isExplicitSoftDoom; } private: - const vespalib::Clock &_clock; - fastos::SteadyTimeStamp _softDoom; - fastos::SteadyTimeStamp _hardDoom; - bool _isExplicitSoftDoom; + const Clock &_clock; + steady_time _softDoom; + steady_time _hardDoom; + bool _isExplicitSoftDoom; }; } diff --git a/staging_vespalib/src/vespa/vespalib/util/rusage.cpp b/staging_vespalib/src/vespa/vespalib/util/rusage.cpp index 32f76775586..d5910148c79 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(fastos::SteadyTimeStamp()); + return createSelf(vespalib::steady_time()); } RUsage RUsage::createChildren() { - return createChildren(fastos::SteadyTimeStamp()); + return createChildren(vespalib::steady_time()); } RUsage -RUsage::createSelf(fastos::SteadyTimeStamp since) +RUsage::createSelf(vespalib::steady_time since) { RUsage r; - r._time = fastos::ClockSteady::now() - since; + r._time = vespalib::steady_clock::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(fastos::SteadyTimeStamp since) } RUsage -RUsage::createChildren(fastos::SteadyTimeStamp since) +RUsage::createChildren(vespalib::steady_time since) { RUsage r; - r._time = fastos::ClockSteady::now() - since; + r._time = vespalib::steady_clock::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.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 (_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 (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 381d4d764e7..f2cea3ba0ab 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/fastos/timestamp.h> +#include <vespa/vespalib/util/time.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(fastos::SteadyTimeStamp since); + static RUsage createSelf(vespalib::steady_time since); /** * Will create an RUsage and initialize member with RUSAGE_CHILDREN **/ static RUsage createChildren(); - static RUsage createChildren(fastos::SteadyTimeStamp since); + static RUsage createChildren(vespalib::steady_time since); /** * Will create an RUsage and initialize member with RUSAGE_CHILDREN **/ vespalib::string toString(); RUsage & operator -= (const RUsage & rhs); private: - fastos::TimeStamp _time; + vespalib::duration _time; }; RUsage operator -(const RUsage & a, const RUsage & b); |