diff options
author | Henning Baldersheim <balder@yahoo-inc.com> | 2019-11-19 23:22:55 +0000 |
---|---|---|
committer | Henning Baldersheim <balder@yahoo-inc.com> | 2019-11-20 21:55:01 +0000 |
commit | cf3b20dba22718b533eac6854cde86b6538958af (patch) | |
tree | 9a0e795cd74d2721140c48012f794298dfef7420 | |
parent | 64b7c822099d7cda921699e380c4d95608a1ab00 (diff) |
FastOS_Time -> std::chrono.
69 files changed, 419 insertions, 529 deletions
diff --git a/config/src/tests/api/api.cpp b/config/src/tests/api/api.cpp index a68b7e676db..4db66761444 100644 --- a/config/src/tests/api/api.cpp +++ b/config/src/tests/api/api.cpp @@ -13,9 +13,9 @@ TEST("require that can subscribe with empty config id") { set.addBuilder("", &builder); ConfigSubscriber subscriber(ctx); ConfigHandle<MyConfig>::UP handle = subscriber.subscribe<MyConfig>(""); - ASSERT_TRUE(subscriber.nextConfig(0)); + ASSERT_TRUE(subscriber.nextConfigNow()); std::unique_ptr<MyConfig> cfg(handle->getConfig()); - ASSERT_TRUE(cfg.get() != NULL); + ASSERT_TRUE(cfg); ASSERT_EQUAL("myfoo", cfg->myField); } diff --git a/config/src/tests/configagent/configagent.cpp b/config/src/tests/configagent/configagent.cpp index 328959fb34d..a7cc95ab883 100644 --- a/config/src/tests/configagent/configagent.cpp +++ b/config/src/tests/configagent/configagent.cpp @@ -10,6 +10,7 @@ #include <config-my.h> using namespace config; +using namespace std::chrono_literals; class MyConfigRequest : public ConfigRequest { @@ -65,17 +66,17 @@ public: static ConfigResponse::UP createOKResponse(const ConfigKey & key, const ConfigValue & value, uint64_t timestamp = 10, const vespalib::string & md5 = "a") { - return ConfigResponse::UP(new MyConfigResponse(key, value, true, timestamp, md5, "", 0, false)); + return std::make_unique<MyConfigResponse>(key, value, true, timestamp, md5, "", 0, false); } static ConfigResponse::UP createServerErrorResponse(const ConfigKey & key, const ConfigValue & value) { - return ConfigResponse::UP(new MyConfigResponse(key, value, true, 10, "a", "whinewhine", 2, true)); + return std::make_unique<MyConfigResponse>(key, value, true, 10, "a", "whinewhine", 2, true); } static ConfigResponse::UP createConfigErrorResponse(const ConfigKey & key, const ConfigValue & value) { - return ConfigResponse::UP(new MyConfigResponse(key, value, false, 10, "a", "", 0, false)); + return std::make_unique<MyConfigResponse>(key, value, false, 10, "a", "", 0, false); } }; @@ -92,7 +93,7 @@ public: return std::move(_update); } - bool wait(uint64_t timeout) override + bool wait(milliseconds timeout) override { (void) timeout; return true; @@ -124,7 +125,7 @@ static TimingValues testTimingValues( 2000, // successTimeout 500, // errorTimeout 500, // initialTimeout - 4000, // subscribeTimeout + 4000ms, // subscribeTimeout 0, // fixedDelay 250, // successDelay 250, // unconfiguredDelay diff --git a/config/src/tests/configfetcher/configfetcher.cpp b/config/src/tests/configfetcher/configfetcher.cpp index 5a2943f7512..607ab0a29a5 100644 --- a/config/src/tests/configfetcher/configfetcher.cpp +++ b/config/src/tests/configfetcher/configfetcher.cpp @@ -2,8 +2,7 @@ #include <vespa/vespalib/testkit/test_kit.h> #include <vespa/config/helper/configfetcher.h> #include <vespa/vespalib/util/exception.h> -#include <vespa/fastos/time.h> -#include <fstream> +#include <vespa/fastos/timestamp.h> #include "config-my.h" #include <atomic> @@ -66,15 +65,14 @@ TEST("requireThatConfigUpdatesArePerformed") { writeFile("test1.cfg", "bar"); cb._configured = false; - FastOS_Time timer; - timer.SetNow(); - while (!cb._configured && timer.MilliSecsToNow() < 20000.0) { + fastos::StopWatch timer; + while (!cb._configured && timer.elapsed().ms() < 20000.0) { if (cb._configured) break; FastOS_Thread::Sleep(1000); } ASSERT_TRUE(cb._configured); - ASSERT_TRUE(cb._config.get() != NULL); + ASSERT_TRUE(cb._config); ASSERT_EQUAL("my", cb._config->defName()); ASSERT_EQUAL("bar", cb._config->myField); } @@ -99,8 +97,8 @@ TEST("requireThatFetcherCanHandleMultipleConfigs") { ASSERT_TRUE(cb1._configured); ASSERT_TRUE(cb2._configured); - ASSERT_TRUE(cb1._config.get() != NULL); - ASSERT_TRUE(cb2._config.get() != NULL); + ASSERT_TRUE(cb1._config); + ASSERT_TRUE(cb2._config); ASSERT_EQUAL("my", cb1._config->defName()); ASSERT_EQUAL("foo", cb1._config->myField); ASSERT_EQUAL("my", cb2._config->defName()); @@ -147,9 +145,8 @@ TEST_F("verify that config generation can be obtained from config fetcher", Conf f1.builder.myField = "bar"; cb._configured = false; f1.context->reload(); - FastOS_Time timer; - timer.SetNow(); - while (timer.MilliSecsToNow() < 120000) { + fastos::StopWatch timer; + while (timer.elapsed().ms() < 120000) { if (cb._configured) { break; } diff --git a/config/src/tests/configholder/configholder.cpp b/config/src/tests/configholder/configholder.cpp index a488cca705a..ce7e4f0531d 100644 --- a/config/src/tests/configholder/configholder.cpp +++ b/config/src/tests/configholder/configholder.cpp @@ -1,14 +1,15 @@ // Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. #include <vespa/vespalib/testkit/test_kit.h> #include <vespa/config/common/configholder.h> +#include <vespa/fastos/timestamp.h> using namespace config; using namespace std::chrono_literals; namespace { -constexpr double ONE_SEC = 1000.0; -constexpr double ONE_MINUTE = 60 * ONE_SEC; +constexpr long ONE_SEC = 1000; +constexpr long ONE_MINUTE = 60 * ONE_SEC; } @@ -33,11 +34,10 @@ TEST("Require that waiting is done") ConfigValue value; ConfigHolder holder; - FastOS_Time timer; - timer.SetNow(); + fastos::StopWatch timer; holder.wait(1000ms); - EXPECT_GREATER_EQUAL(timer.MilliSecsToNow(), ONE_SEC); - EXPECT_LESS(timer.MilliSecsToNow(), ONE_MINUTE); + EXPECT_GREATER_EQUAL(timer.elapsed().ms(), ONE_SEC); + EXPECT_LESS(timer.elapsed().ms(), ONE_MINUTE); holder.handle(std::make_unique<ConfigUpdate>(value, true, 0)); ASSERT_TRUE(holder.wait(100ms)); @@ -57,25 +57,23 @@ TEST("Require that polling for elements work") TEST("Require that negative time does not mean forever.") { ConfigHolder holder; - FastOS_Time timer; - timer.SetNow(); + fastos::StopWatch timer; ASSERT_FALSE(holder.poll()); - ASSERT_FALSE(holder.wait(10)); - ASSERT_FALSE(holder.wait(0)); - ASSERT_FALSE(holder.wait(-1)); - ASSERT_FALSE(holder.wait(-7)); - EXPECT_LESS(timer.MilliSecsToNow(), ONE_MINUTE); + ASSERT_FALSE(holder.wait(10ms)); + ASSERT_FALSE(holder.wait(0ms)); + ASSERT_FALSE(holder.wait(-1ms)); + ASSERT_FALSE(holder.wait(-7ms)); + EXPECT_LESS(timer.elapsed().ms(), ONE_MINUTE); } TEST_MT_F("Require that wait is interrupted", 2, ConfigHolder) { if (thread_id == 0) { - FastOS_Time timer; - timer.SetNow(); + fastos::StopWatch timer; TEST_BARRIER(); f.wait(1000ms); - EXPECT_LESS(timer.MilliSecsToNow(), ONE_MINUTE); - EXPECT_GREATER(timer.MilliSecsToNow(), 400.0); + EXPECT_LESS(timer.elapsed().ms(), ONE_MINUTE); + EXPECT_GREATER(timer.elapsed().ms(), 400.0); TEST_BARRIER(); } else { TEST_BARRIER(); diff --git a/config/src/tests/configmanager/configmanager.cpp b/config/src/tests/configmanager/configmanager.cpp index 43f194883c3..2a7e4999829 100644 --- a/config/src/tests/configmanager/configmanager.cpp +++ b/config/src/tests/configmanager/configmanager.cpp @@ -10,6 +10,7 @@ #include "config-my.h" using namespace config; +using namespace std::chrono_literals; namespace { @@ -91,7 +92,7 @@ namespace { 2000, // successTimeout 500, // errorTimeout 500, // initialTimeout - 4000, // unsubscribeTimeout + 4000ms, // unsubscribeTimeout 0, // fixedDelay 250, // successDelay 250, // unconfiguredDelay @@ -111,7 +112,7 @@ namespace { void subscribe() { - sub = _mgr.subscribe(key, 5000); + sub = _mgr.subscribe(key, 5000ms); } }; diff --git a/config/src/tests/configretriever/configretriever.cpp b/config/src/tests/configretriever/configretriever.cpp index 944b0d45da0..fc921a324af 100644 --- a/config/src/tests/configretriever/configretriever.cpp +++ b/config/src/tests/configretriever/configretriever.cpp @@ -2,7 +2,6 @@ #include <vespa/vespalib/testkit/test_kit.h> #include <vespa/vespalib/data/slime/slime.h> -#include <vespa/config/config.h> #include <vespa/config/print.h> #include <vespa/config/retriever/configretriever.h> #include <vespa/config/retriever/simpleconfigretriever.h> @@ -10,7 +9,7 @@ #include <vespa/config/common/configholder.h> #include <vespa/config/subscription/configsubscription.h> #include <vespa/config/common/exceptions.h> -#include <vespa/fastos/time.h> +#include <vespa/fastos/timestamp.h> #include "config-bootstrap.h" #include "config-foo.h" #include "config-bar.h" @@ -20,6 +19,7 @@ using namespace config; using namespace std; using namespace vespalib::slime; using namespace vespalib; +using namespace std::chrono_literals; struct ComponentFixture { typedef std::shared_ptr<ComponentFixture> SP; @@ -119,8 +119,8 @@ struct SubscriptionFixture : holder(new ConfigHolder()), sub(new ConfigSubscription(0, key, holder, Source::UP(new MySource()))) { - holder->handle(ConfigUpdate::UP(new ConfigUpdate(value, 3, 3))); - ASSERT_TRUE(sub->nextUpdate(0, 0)); + holder->handle(std::make_unique<ConfigUpdate>(value, 3, 3)); + ASSERT_TRUE(sub->nextUpdate(0, 0ms)); sub->flip(); } }; @@ -246,9 +246,8 @@ public: configured = true; } bool waitUntilConfigured(int64_t timeoutInMillis) { - FastOS_Time timer; - timer.SetNow(); - while (timer.MilliSecsToNow() < timeoutInMillis) { + fastos::StopWatch timer; + while (timer.elapsed().ms() < timeoutInMillis) { if (configured) { return true; } @@ -386,14 +385,14 @@ TEST_FFF("require that snapshots can produce subsets", SubscriptionFixture(Confi ASSERT_EQUAL(3, subset1.getGeneration()); ASSERT_EQUAL(1u, subset1.size()); std::unique_ptr<FooConfig> cfg1(subset1.getConfig<FooConfig>("id")); - ASSERT_TRUE(cfg1.get() != NULL); + ASSERT_TRUE(cfg1); ConfigSnapshot subset2(parent.subset(ConfigKeySet().add<BarConfig>("id"))); ASSERT_FALSE(subset2.empty()); ASSERT_EQUAL(3, subset2.getGeneration()); ASSERT_EQUAL(1u, subset2.size()); std::unique_ptr<BarConfig> cfg2(subset2.getConfig<BarConfig>("id")); - ASSERT_TRUE(cfg2.get() != NULL); + ASSERT_TRUE(cfg2); ConfigSnapshot subset3(parent.subset(ConfigKeySet().add<BarConfig>("doesnotexist"))); ASSERT_TRUE(subset3.empty()); @@ -405,9 +404,9 @@ TEST_FFF("require that snapshots can produce subsets", SubscriptionFixture(Confi ASSERT_EQUAL(3, subset4.getGeneration()); ASSERT_EQUAL(2u, subset4.size()); cfg1 = subset4.getConfig<FooConfig>("id"); - ASSERT_TRUE(cfg1.get() != NULL); + ASSERT_TRUE(cfg1); cfg2 = subset4.getConfig<BarConfig>("id"); - ASSERT_TRUE(cfg2.get() != NULL); + ASSERT_TRUE(cfg2); } TEST_FFF("require that snapshots can be serialized", SubscriptionFixture(ConfigKey::create<FooConfig>("id"), createKeyValueV2("fooValue", "bar")), diff --git a/config/src/tests/configuri/configuri_test.cpp b/config/src/tests/configuri/configuri_test.cpp index 3a0dafffc17..c813761e763 100644 --- a/config/src/tests/configuri/configuri_test.cpp +++ b/config/src/tests/configuri/configuri_test.cpp @@ -38,9 +38,8 @@ TEST("Require that URI can be created from instance") { b.myField = "rabarbra"; ConfigUri uri(ConfigUri::createFromInstance(b)); ConfigSubscriber subscriber(uri.getContext()); - ConfigHandle<MyConfig>::UP handle = - subscriber.subscribe<MyConfig>(uri.getConfigId()); - ASSERT_TRUE(subscriber.nextConfig(0)); + ConfigHandle<MyConfig>::UP handle = subscriber.subscribe<MyConfig>(uri.getConfigId()); + ASSERT_TRUE(subscriber.nextConfigNow()); ASSERT_TRUE(handle->isChanged()); std::unique_ptr<MyConfig> cfg = handle->getConfig(); ASSERT_EQUAL(b.myField, cfg->myField); diff --git a/config/src/tests/failover/failover.cpp b/config/src/tests/failover/failover.cpp index d05c948b5d6..17fa264fd32 100644 --- a/config/src/tests/failover/failover.cpp +++ b/config/src/tests/failover/failover.cpp @@ -15,6 +15,7 @@ using vespalib::Barrier; using namespace config::protocol::v2; using namespace vespalib::slime; using namespace vespalib; +using namespace std::chrono_literals; namespace { @@ -173,7 +174,7 @@ TimingValues testTimingValues( 500, // successTimeout 500, // errorTimeout 500, // initialTimeout - 400, // unsubscribeTimeout + 400ms, // unsubscribeTimeout 0, // fixedDelay 250, // successDelay 250, // unconfiguredDelay diff --git a/config/src/tests/file_subscription/file_subscription.cpp b/config/src/tests/file_subscription/file_subscription.cpp index 69090f4bb8e..9c40e2ffd77 100644 --- a/config/src/tests/file_subscription/file_subscription.cpp +++ b/config/src/tests/file_subscription/file_subscription.cpp @@ -5,7 +5,6 @@ #include <vespa/config/file/filesource.h> #include <vespa/config/common/exceptions.h> #include <vespa/vespalib/util/sync.h> -#include <vespa/fastos/time.h> #include <fstream> #include <config-my.h> #include <config-foo.h> @@ -13,9 +12,12 @@ #include <config-bar.h> #include <config-foobar.h> #include <vespa/log/log.h> +#include <vespa/fastos/timestamp.h> + LOG_SETUP(".filesubscription_test"); using namespace config; +using namespace std::chrono_literals; namespace { @@ -60,15 +62,15 @@ TEST("requireThatFileSpecGivesCorrectSource") { FileSpec spec("my.cfg"); SourceFactory::UP factory(spec.createSourceFactory(TimingValues())); - ASSERT_TRUE(factory.get() != NULL); + ASSERT_TRUE(factory); IConfigHolder::SP holder(new ConfigHolder()); Source::UP src = factory->createSource(holder, ConfigKey("my", "my", "bar", "foo")); - ASSERT_TRUE(src.get() != NULL); + ASSERT_TRUE(src); src->getConfig(); ASSERT_TRUE(holder->poll()); ConfigUpdate::UP update(holder->provide()); - ASSERT_TRUE(update.get() != NULL); + ASSERT_TRUE(update); const ConfigValue & value(update->getValue()); ASSERT_EQUAL(1u, value.numLines()); ASSERT_EQUAL("myField \"foobar\"", value.getLine(0)); @@ -78,12 +80,12 @@ TEST("requireThatFileSubscriptionReturnsCorrectConfig") { writeFile("my.cfg", "foobar"); ConfigSubscriber s(FileSpec("my.cfg")); std::unique_ptr<ConfigHandle<MyConfig> > handle = s.subscribe<MyConfig>("my"); - s.nextConfig(0); + s.nextConfigNow(); std::unique_ptr<MyConfig> cfg = handle->getConfig(); - ASSERT_TRUE(cfg.get() != NULL); + ASSERT_TRUE(cfg); ASSERT_EQUAL("foobar", cfg->myField); ASSERT_EQUAL("my", cfg->defName()); - ASSERT_FALSE(s.nextConfig(100)); + ASSERT_FALSE(s.nextConfig(100ms)); } TEST("requireThatReconfigIsCalledWhenConfigChanges") { @@ -92,28 +94,27 @@ TEST("requireThatReconfigIsCalledWhenConfigChanges") { IConfigContext::SP context(new ConfigContext(FileSpec("my.cfg"))); ConfigSubscriber s(context); std::unique_ptr<ConfigHandle<MyConfig> > handle = s.subscribe<MyConfig>(""); - s.nextConfig(0); + s.nextConfigNow(); std::unique_ptr<MyConfig> cfg = handle->getConfig(); - ASSERT_TRUE(cfg.get() != NULL); + ASSERT_TRUE(cfg); ASSERT_EQUAL("foo", cfg->myField); ASSERT_EQUAL("my", cfg->defName()); - ASSERT_FALSE(s.nextConfig(3000)); + ASSERT_FALSE(s.nextConfig(3000ms)); writeFile("my.cfg", "bar"); context->reload(); bool correctValue = false; - FastOS_Time timer; - timer.SetNow(); - while (!correctValue && timer.MilliSecsToNow() < 20000.0) { + fastos::StopWatch timer; + while (!correctValue && timer.elapsed().ms() < 20000.0) { LOG(info, "Testing value..."); - if (s.nextConfig(1000)) { + if (s.nextConfig(1000ms)) { break; } } cfg = handle->getConfig(); - ASSERT_TRUE(cfg.get() != NULL); + ASSERT_TRUE(cfg); ASSERT_EQUAL("bar", cfg->myField); ASSERT_EQUAL("my", cfg->defName()); - ASSERT_FALSE(s.nextConfig(1000)); + ASSERT_FALSE(s.nextConfig(1000ms)); } } @@ -123,10 +124,10 @@ TEST("requireThatMultipleSubscribersCanSubscribeToSameFile") { { ConfigSubscriber s1(spec); std::unique_ptr<ConfigHandle<MyConfig> > h1 = s1.subscribe<MyConfig>(""); - ASSERT_TRUE(s1.nextConfig(0)); + ASSERT_TRUE(s1.nextConfigNow()); ConfigSubscriber s2(spec); std::unique_ptr<ConfigHandle<MyConfig> > h2 = s2.subscribe<MyConfig>(""); - ASSERT_TRUE(s2.nextConfig(0)); + ASSERT_TRUE(s2.nextConfigNow()); } } @@ -135,13 +136,13 @@ TEST("requireThatCanSubscribeToDirectory") { ConfigSubscriber s(spec); ConfigHandle<FooConfig>::UP fooHandle = s.subscribe<FooConfig>(""); ConfigHandle<BarConfig>::UP barHandle = s.subscribe<BarConfig>(""); - ASSERT_TRUE(s.nextConfig(0)); + ASSERT_TRUE(s.nextConfigNow()); ASSERT_TRUE(fooHandle->isChanged()); ASSERT_TRUE(barHandle->isChanged()); std::unique_ptr<FooConfig> fooCfg = fooHandle->getConfig(); std::unique_ptr<BarConfig> barCfg = barHandle->getConfig(); - ASSERT_TRUE(fooCfg.get() != NULL); - ASSERT_TRUE(barCfg.get() != NULL); + ASSERT_TRUE(fooCfg); + ASSERT_TRUE(barCfg); ASSERT_EQUAL("foofoo", fooCfg->fooValue); ASSERT_EQUAL("barbar", barCfg->barValue); } @@ -151,13 +152,13 @@ TEST("requireThatCanSubscribeToDirectoryWithEmptyCfgFile") { ConfigSubscriber s(spec); ConfigHandle<FoodefaultConfig>::UP fooHandle = s.subscribe<FoodefaultConfig>(""); ConfigHandle<BarConfig>::UP barHandle = s.subscribe<BarConfig>(""); - ASSERT_TRUE(s.nextConfig(0)); + ASSERT_TRUE(s.nextConfigNow()); ASSERT_TRUE(fooHandle->isChanged()); ASSERT_TRUE(barHandle->isChanged()); std::unique_ptr<FoodefaultConfig> fooCfg = fooHandle->getConfig(); std::unique_ptr<BarConfig> barCfg = barHandle->getConfig(); - ASSERT_TRUE(fooCfg.get() != NULL); - ASSERT_TRUE(barCfg.get() != NULL); + ASSERT_TRUE(fooCfg); + ASSERT_TRUE(barCfg); ASSERT_EQUAL("per", fooCfg->fooValue); ASSERT_EQUAL("barbar", barCfg->barValue); } @@ -167,13 +168,13 @@ TEST("requireThatCanSubscribeToDirectoryWithNonExistingCfgFile") { ConfigSubscriber s(spec); ConfigHandle<FoodefaultConfig>::UP fooHandle = s.subscribe<FoodefaultConfig>(""); ConfigHandle<BarConfig>::UP barHandle = s.subscribe<BarConfig>(""); - ASSERT_TRUE(s.nextConfig(0)); + ASSERT_TRUE(s.nextConfigNow()); ASSERT_TRUE(fooHandle->isChanged()); ASSERT_TRUE(barHandle->isChanged()); std::unique_ptr<FoodefaultConfig> fooCfg = fooHandle->getConfig(); std::unique_ptr<BarConfig> barCfg = barHandle->getConfig(); - ASSERT_TRUE(fooCfg.get() != NULL); - ASSERT_TRUE(barCfg.get() != NULL); + ASSERT_TRUE(fooCfg); + ASSERT_TRUE(barCfg); ASSERT_EQUAL("per", fooCfg->fooValue); ASSERT_EQUAL("barbar", barCfg->barValue); } @@ -183,11 +184,11 @@ TEST_F("requireThatDirSpecDoesNotMixNames", ConfigSubscriber s(f); ConfigHandle<BarConfig>::UP barHandle = s.subscribe<BarConfig>(""); ConfigHandle<FoobarConfig>::UP foobarHandle = s.subscribe<FoobarConfig>(""); - s.nextConfig(0); + s.nextConfigNow(); std::unique_ptr<BarConfig> bar = barHandle->getConfig(); std::unique_ptr<FoobarConfig> foobar = foobarHandle->getConfig(); - ASSERT_TRUE(bar.get() != NULL); - ASSERT_TRUE(foobar.get() != NULL); + ASSERT_TRUE(bar); + ASSERT_TRUE(foobar); ASSERT_EQUAL("barbar", bar->barValue); ASSERT_EQUAL("foobarlol", foobar->fooBarValue); } @@ -197,11 +198,11 @@ TEST_F("require that can subscribe multiple config ids of same config", ConfigSubscriber s(f1); ConfigHandle<BarConfig>::UP fooHandle = s.subscribe<BarConfig>("foo"); ConfigHandle<BarConfig>::UP barHandle = s.subscribe<BarConfig>("bar"); - s.nextConfig(0); + s.nextConfigNow(); std::unique_ptr<BarConfig> bar1 = fooHandle->getConfig(); std::unique_ptr<BarConfig> bar2 = barHandle->getConfig(); - ASSERT_TRUE(bar1.get() != NULL); - ASSERT_TRUE(bar2.get() != NULL); + ASSERT_TRUE(bar1); + ASSERT_TRUE(bar2); ASSERT_EQUAL("barbar", bar1->barValue); ASSERT_EQUAL("foobarlol", bar2->barValue); } diff --git a/config/src/tests/frt/frt.cpp b/config/src/tests/frt/frt.cpp index b89ffe749b0..ba8279a1999 100644 --- a/config/src/tests/frt/frt.cpp +++ b/config/src/tests/frt/frt.cpp @@ -14,7 +14,7 @@ #include <vespa/fnet/frt/frt.h> #include <vespa/fnet/frt/error.h> #include <vespa/config/frt/protocol.h> -#include <vespa/fastos/time.h> +#include <vespa/fastos/timestamp.h> #include <lz4.h> #include "config-my.h" #include "config-bar.h" @@ -39,15 +39,14 @@ namespace { { } ConfigUpdate::UP provide() override { return ConfigUpdate::UP(); } void handle(ConfigUpdate::UP u) override { update = std::move(u); } - bool wait(uint64_t timeoutInMillis) override { (void) timeoutInMillis; return notified; } + bool wait(milliseconds timeoutInMillis) override { (void) timeoutInMillis; return notified; } bool poll() override { return notified; } void interrupt() override { } bool waitUntilResponse(int timeoutInMillis) { - FastOS_Time timer; - timer.SetNow(); - while (timer.MilliSecsToNow() < timeoutInMillis) { + fastos::StopWatch timer; + while (timer.elapsed().ms() < timeoutInMillis) { if (notified) break; FastOS_Thread::Sleep(100); @@ -256,9 +255,8 @@ TEST_FF("require that request is config task is scheduled", SourceFixture(), FRT f2.src.getConfig(); ASSERT_TRUE(f2.result.notified); f2.result.notified = false; - FastOS_Time timer; - timer.SetNow(); - while (timer.MilliSecsToNow() < 10000) { + fastos::StopWatch timer; + while (timer.elapsed().ms() < 10000) { f1.conn.scheduler.CheckTasks(); if (f2.result.notified) break; diff --git a/config/src/tests/functiontest/functiontest.cpp b/config/src/tests/functiontest/functiontest.cpp index 7fe87775f74..f7a57d6359b 100644 --- a/config/src/tests/functiontest/functiontest.cpp +++ b/config/src/tests/functiontest/functiontest.cpp @@ -110,7 +110,7 @@ struct TestFixture : public LazyTestFixture TestFixture(const std::string & dirName) : LazyTestFixture(dirName) { - ASSERT_TRUE(_subscriber.nextConfig(0)); + ASSERT_TRUE(_subscriber.nextConfigNow()); _config = _handle->getConfig(); } }; @@ -120,7 +120,7 @@ struct ErrorFixture LazyTestFixture & f; ErrorFixture(LazyTestFixture & f1) : f(f1) { } void run() { - f._subscriber.nextConfig(0); + f._subscriber.nextConfigNow(); bool thrown = false; try { f._handle->getConfig(); @@ -153,7 +153,7 @@ void attemptLacking(const std::string& param, bool isArray) { RawSpec spec(config.str()); ConfigSubscriber subscriber(spec); ConfigHandle<FunctionTestConfig>::UP handle = subscriber.subscribe<FunctionTestConfig>("foo"); - ASSERT_TRUE(subscriber.nextConfig(0)); + ASSERT_TRUE(subscriber.nextConfigNow()); std::unique_ptr<FunctionTestConfig> cfg = handle->getConfig(); if (isArray) { // Arrays are empty by default diff --git a/config/src/tests/raw_subscription/raw_subscription.cpp b/config/src/tests/raw_subscription/raw_subscription.cpp index 6a3b5967f0c..478b4611bac 100644 --- a/config/src/tests/raw_subscription/raw_subscription.cpp +++ b/config/src/tests/raw_subscription/raw_subscription.cpp @@ -11,15 +11,15 @@ TEST("require that raw spec can create source factory") { RawSpec spec("myField \"foo\"\n"); SourceFactory::UP raw = spec.createSourceFactory(TimingValues()); - ASSERT_TRUE(raw.get() != NULL); + ASSERT_TRUE(raw); IConfigHolder::SP holder(new ConfigHolder()); Source::UP src = raw->createSource(holder, ConfigKey("myid", "my", "bar", "foo")); - ASSERT_TRUE(src.get() != NULL); + ASSERT_TRUE(src); src->getConfig(); ASSERT_TRUE(holder->poll()); ConfigUpdate::UP update(holder->provide()); - ASSERT_TRUE(update.get() != NULL); + ASSERT_TRUE(update); const ConfigValue & value(update->getValue()); ASSERT_EQUAL(1u, value.numLines()); ASSERT_EQUAL("myField \"foo\"", value.getLine(0)); @@ -30,9 +30,9 @@ TEST("requireThatRawSubscriptionReturnsCorrectConfig") RawSpec spec("myField \"foo\"\n"); ConfigSubscriber s(spec); std::unique_ptr<ConfigHandle<MyConfig> > handle = s.subscribe<MyConfig>("myid"); - s.nextConfig(0); + s.nextConfigNow(); std::unique_ptr<MyConfig> cfg = handle->getConfig(); - ASSERT_TRUE(cfg.get() != NULL); + ASSERT_TRUE(cfg); ASSERT_EQUAL("foo", cfg->myField); ASSERT_EQUAL("my", cfg->defName()); } diff --git a/config/src/tests/subscriber/subscriber.cpp b/config/src/tests/subscriber/subscriber.cpp index 5663b145100..0c14928521e 100644 --- a/config/src/tests/subscriber/subscriber.cpp +++ b/config/src/tests/subscriber/subscriber.cpp @@ -5,14 +5,14 @@ #include <vespa/config/common/configholder.h> #include <vespa/config/subscription/configsubscription.h> #include <vespa/config/common/exceptions.h> -#include <vespa/fastos/time.h> -#include <fstream> +#include <vespa/fastos/timestamp.h> #include "config-foo.h" #include "config-bar.h" #include "config-baz.h" using namespace config; using namespace vespalib; +using namespace std::chrono_literals; namespace { @@ -78,13 +78,12 @@ namespace { MyManager() : idCounter(0), numCancel(0) { } - ConfigSubscription::SP subscribe(const ConfigKey & key, uint64_t timeoutInMillis) override { + ConfigSubscription::SP subscribe(const ConfigKey & key, milliseconds timeoutInMillis) override { (void) timeoutInMillis; IConfigHolder::SP holder(new ConfigHolder()); _holders.push_back(holder); - ConfigSubscription::SP s(new ConfigSubscription(0, key, holder, Source::UP(new MySource()))); - return s; + return std::make_shared<ConfigSubscription>(0, key, holder, std::make_unique<MySource>()); } void unsubscribe(const ConfigSubscription::SP & subscription) override { (void) subscription; @@ -93,7 +92,7 @@ namespace { void updateValue(size_t index, const ConfigValue & value, int64_t generation) { ASSERT_TRUE(index < _holders.size()); - _holders[index]->handle(ConfigUpdate::UP(new ConfigUpdate(value, true, generation))); + _holders[index]->handle(std::make_unique<ConfigUpdate>(value, true, generation)); } void updateGeneration(size_t index, int64_t generation) { @@ -103,7 +102,7 @@ namespace { if (_holders[index]->poll()) { value = _holders[index]->provide()->getValue(); } - _holders[index]->handle(ConfigUpdate::UP(new ConfigUpdate(value, false, generation))); + _holders[index]->handle(std::make_unique<ConfigUpdate>(value, false, generation)); } void reload(int64_t generation) override @@ -151,7 +150,7 @@ namespace { h2 = s.subscribe<BarConfig>("myid"); f1.updateValue(0, createFooValue("foo"), 1); f1.updateValue(1, createBarValue("bar"), 1); - ASSERT_TRUE(s.nextConfig(0)); + ASSERT_TRUE(s.nextConfigNow()); verifyConfig("foo", h1->getConfig()); verifyConfig("bar", h2->getConfig()); } @@ -174,7 +173,7 @@ TEST_F("requireThatSubscriberCanGetMultipleTypes", SimpleFixture()) { ConfigSubscriber s(f.set); ConfigHandle<FooConfig>::UP h1 = s.subscribe<FooConfig>("myid"); ConfigHandle<BarConfig>::UP h2 = s.subscribe<BarConfig>("myid"); - ASSERT_TRUE(s.nextConfig(0)); + ASSERT_TRUE(s.nextConfigNow()); std::unique_ptr<FooConfig> foo = h1->getConfig(); std::unique_ptr<BarConfig> bar = h2->getConfig(); ASSERT_EQUAL("bar", foo->fooValue); @@ -196,7 +195,7 @@ TEST_F("requireThatNextConfigMustBeCalled", SimpleFixture()) { TEST_F("requireThatSubscriptionsCannotBeAddedWhenFrozen", SimpleFixture()) { ConfigSubscriber s(f.set); ConfigHandle<FooConfig>::UP h1 = s.subscribe<FooConfig>("myid"); - ASSERT_TRUE(s.nextConfig(0)); + ASSERT_TRUE(s.nextConfigNow()); bool thrown = false; try { ConfigHandle<BarConfig>::UP h2 = s.subscribe<BarConfig>("myid"); @@ -210,19 +209,19 @@ TEST_FF("requireThatNextConfigReturnsFalseUntilSubscriptionHasSucceeded", MyMana ConfigSubscriber s(IConfigContext::SP(new APIFixture(f2))); ConfigHandle<FooConfig>::UP h1 = s.subscribe<FooConfig>("myid"); ConfigHandle<BarConfig>::UP h2 = s.subscribe<BarConfig>("myid"); - ASSERT_FALSE(s.nextConfig(0)); - ASSERT_FALSE(s.nextConfig(100)); + ASSERT_FALSE(s.nextConfigNow()); + ASSERT_FALSE(s.nextConfig(100ms)); f1.updateValue(0, createFooValue("foo"), 1); - ASSERT_FALSE(s.nextConfig(100)); + ASSERT_FALSE(s.nextConfig(100ms)); f1.updateValue(1, createBarValue("bar"), 1); - ASSERT_TRUE(s.nextConfig(100)); + ASSERT_TRUE(s.nextConfig(100ms)); } TEST_FFF("requireThatNewGenerationIsFetchedOnReload", MyManager, APIFixture(f1), StandardFixture(f1, f2)) { verifyConfig("foo", f3.h1->getConfig()); verifyConfig("bar", f3.h2->getConfig()); - ASSERT_FALSE(f3.s.nextConfig(1000)); + ASSERT_FALSE(f3.s.nextConfig(1000ms)); verifyConfig("foo", f3.h1->getConfig()); verifyConfig("bar", f3.h2->getConfig()); @@ -230,7 +229,7 @@ TEST_FFF("requireThatNewGenerationIsFetchedOnReload", MyManager, APIFixture(f1), f1.updateValue(0, createFooValue("foo2"), 3); f1.updateValue(1, createBarValue("bar2"), 3); - ASSERT_TRUE(f3.s.nextConfig(1000)); + ASSERT_TRUE(f3.s.nextConfig(1000ms)); verifyConfig("foo2", f3.h1->getConfig()); verifyConfig("bar2", f3.h2->getConfig()); @@ -238,26 +237,26 @@ TEST_FFF("requireThatNewGenerationIsFetchedOnReload", MyManager, APIFixture(f1), TEST_FFF("requireThatAllConfigsMustGetTimestampUpdate", MyManager, APIFixture(f1), StandardFixture(f1, f2)) { f1.updateValue(0, createFooValue("foo2"), 2); - ASSERT_FALSE(f3.s.nextConfig(100)); + ASSERT_FALSE(f3.s.nextConfig(100ms)); verifyConfig("foo", f3.h1->getConfig()); verifyConfig("bar", f3.h2->getConfig()); f1.updateValue(0, createFooValue("foo2"), 3); f1.updateGeneration(1, 3); - ASSERT_TRUE(f3.s.nextConfig(0)); + ASSERT_TRUE(f3.s.nextConfigNow()); verifyConfig("foo2", f3.h1->getConfig()); verifyConfig("bar", f3.h2->getConfig()); } TEST_FFF("requireThatNextConfigMaySucceedIfInTheMiddleOfConfigUpdate", MyManager, APIFixture(f1), StandardFixture(f1, f2)) { f1.updateValue(0, createFooValue("foo2"), 2); - ASSERT_FALSE(f3.s.nextConfig(1000)); + ASSERT_FALSE(f3.s.nextConfig(1000ms)); verifyConfig("foo", f3.h1->getConfig()); verifyConfig("bar", f3.h2->getConfig()); f1.updateGeneration(1, 2); - ASSERT_TRUE(f3.s.nextConfig(0)); + ASSERT_TRUE(f3.s.nextConfigNow()); verifyConfig("foo2", f3.h1->getConfig()); verifyConfig("bar", f3.h2->getConfig()); } @@ -265,21 +264,20 @@ TEST_FFF("requireThatNextConfigMaySucceedIfInTheMiddleOfConfigUpdate", MyManager TEST_FFF("requireThatCorrectConfigIsReturnedAfterTimestampUpdate", MyManager, APIFixture(f1), StandardFixture(f1, f2)) { f1.updateGeneration(0, 2); f1.updateGeneration(1, 2); - ASSERT_FALSE(f3.s.nextConfig(1000)); + ASSERT_FALSE(f3.s.nextConfig(1000ms)); verifyConfig("foo", f3.h1->getConfig()); verifyConfig("bar", f3.h2->getConfig()); - ASSERT_TRUE(f3.s.nextGeneration(0)); + ASSERT_TRUE(f3.s.nextGenerationNow()); verifyConfig("foo", f3.h1->getConfig()); verifyConfig("bar", f3.h2->getConfig()); } TEST_MT_FFF("requireThatConfigIsReturnedWhenUpdatedDuringNextConfig", 2, MyManager, APIFixture(f1), StandardFixture(f1, f2)) { if (thread_id == 0) { - FastOS_Time timer; - timer.SetNow(); - ASSERT_TRUE(f3.s.nextConfig(10000)); - ASSERT_TRUE(timer.MilliSecsToNow() > 250); - ASSERT_TRUE(timer.MilliSecsToNow() <= 5000); + fastos::StopWatch timer; + ASSERT_TRUE(f3.s.nextConfig(10000ms)); + ASSERT_TRUE(timer.elapsed().ms() > 250); + ASSERT_TRUE(timer.elapsed().ms() <= 5000); verifyConfig("foo2", f3.h1->getConfig()); verifyConfig("bar", f3.h2->getConfig()); } else { @@ -291,15 +289,14 @@ TEST_MT_FFF("requireThatConfigIsReturnedWhenUpdatedDuringNextConfig", 2, MyManag } TEST_FFF("requireThatConfigIsReturnedWhenUpdatedBeforeNextConfig", MyManager, APIFixture(f1), StandardFixture(f1, f2)) { - FastOS_Time timer; - timer.SetNow(); - ASSERT_FALSE(f3.s.nextConfig(1000)); - ASSERT_TRUE(timer.MilliSecsToNow() > 850); + fastos::StopWatch timer; + ASSERT_FALSE(f3.s.nextConfig(1000ms)); + ASSERT_TRUE(timer.elapsed().ms() > 850); f1.updateGeneration(0, 2); f1.updateGeneration(1, 2); - timer.SetNow(); - ASSERT_TRUE(f3.s.nextGeneration(10000)); - ASSERT_TRUE(timer.MilliSecsToNow() <= 5000); + timer.restart(); + ASSERT_TRUE(f3.s.nextGeneration(10000ms)); + ASSERT_TRUE(timer.elapsed().ms() <= 5000); verifyConfig("foo", f3.h1->getConfig()); verifyConfig("bar", f3.h2->getConfig()); } @@ -315,7 +312,7 @@ TEST_FFF("requireThatNothingCanBeCalledAfterClose", MyManager, APIFixture(f1), S ASSERT_FALSE(f3.s.isClosed()); f3.s.close(); ASSERT_TRUE(f3.s.isClosed()); - ASSERT_FALSE(f3.s.nextConfig(100)); + ASSERT_FALSE(f3.s.nextConfig(100ms)); bool thrown = false; try { f3.h1->getConfig(); @@ -327,11 +324,10 @@ TEST_FFF("requireThatNothingCanBeCalledAfterClose", MyManager, APIFixture(f1), S TEST_MT_FFF("requireThatNextConfigIsInterruptedOnClose", 2, MyManager, APIFixture(f1), StandardFixture(f1, f2)) { if (thread_id == 0) { - FastOS_Time timer; - timer.SetNow(); - ASSERT_FALSE(f3.s.nextConfig(5000)); - ASSERT_TRUE(timer.MilliSecsToNow() >= 500.0); - ASSERT_TRUE(timer.MilliSecsToNow() < 60000.0); + fastos::StopWatch timer; + ASSERT_FALSE(f3.s.nextConfig(5000ms)); + ASSERT_TRUE(timer.elapsed().ms() >= 500.0); + ASSERT_TRUE(timer.elapsed().ms() < 60000.0); } else { std::this_thread::sleep_for(std::chrono::milliseconds(1000)); f3.s.close(); @@ -342,20 +338,20 @@ TEST_FF("requireThatHandlesAreMarkedAsChanged", MyManager, APIFixture(f1)) { ConfigSubscriber s(IConfigContext::SP(new APIFixture(f2))); ConfigHandle<FooConfig>::UP h1 = s.subscribe<FooConfig>("myid2"); ConfigHandle<BarConfig>::UP h2 = s.subscribe<BarConfig>("myid2"); - EXPECT_FALSE(s.nextConfig(0)); + EXPECT_FALSE(s.nextConfigNow()); f1.updateValue(0, createFooValue("foo"), 1); f1.updateValue(1, createFooValue("bar"), 1); - EXPECT_TRUE(s.nextConfig(100)); + EXPECT_TRUE(s.nextConfig(100ms)); EXPECT_TRUE(h1->isChanged()); EXPECT_TRUE(h2->isChanged()); - EXPECT_FALSE(s.nextConfig(100)); + EXPECT_FALSE(s.nextConfig(100ms)); EXPECT_FALSE(h1->isChanged()); EXPECT_FALSE(h2->isChanged()); f1.updateValue(0, createFooValue("bar"), 2); f1.updateGeneration(1, 2); - EXPECT_TRUE(s.nextConfig(100)); + EXPECT_TRUE(s.nextConfig(100ms)); EXPECT_TRUE(h1->isChanged()); EXPECT_FALSE(h2->isChanged()); } @@ -366,19 +362,19 @@ TEST_FF("requireThatNextGenerationMarksChanged", MyManager, APIFixture(f1)) { ConfigHandle<BarConfig>::UP h2 = s.subscribe<BarConfig>("myid2"); f1.updateValue(0, createFooValue("foo"), 1); f1.updateValue(1, createFooValue("bar"), 1); - ASSERT_TRUE(s.nextGeneration(0)); + ASSERT_TRUE(s.nextGenerationNow()); ASSERT_TRUE(h1->isChanged()); ASSERT_TRUE(h2->isChanged()); f1.updateValue(0, createFooValue("bar"), 2); f1.updateGeneration(1, 2); - ASSERT_TRUE(s.nextGeneration(0)); + ASSERT_TRUE(s.nextGenerationNow()); ASSERT_TRUE(h1->isChanged()); ASSERT_FALSE(h2->isChanged()); f1.updateGeneration(0, 3); f1.updateGeneration(1, 3); - ASSERT_TRUE(s.nextGeneration(0)); + ASSERT_TRUE(s.nextGenerationNow()); ASSERT_FALSE(h1->isChanged()); ASSERT_FALSE(h2->isChanged()); } @@ -389,23 +385,23 @@ TEST_FF("requireThatgetGenerationIsSet", MyManager, APIFixture(f1)) { ConfigHandle<BarConfig>::UP h2 = s.subscribe<BarConfig>("myid2"); f1.updateValue(0, createFooValue("foo"), 1); f1.updateValue(1, createFooValue("bar"), 1); - ASSERT_TRUE(s.nextGeneration(0)); + ASSERT_TRUE(s.nextGenerationNow()); ASSERT_EQUAL(1, s.getGeneration()); ASSERT_TRUE(h1->isChanged()); ASSERT_TRUE(h2->isChanged()); - ASSERT_FALSE(s.nextGeneration(0)); + ASSERT_FALSE(s.nextGenerationNow()); f1.updateGeneration(1, 2); - ASSERT_FALSE(s.nextGeneration(0)); + ASSERT_FALSE(s.nextGenerationNow()); ASSERT_EQUAL(1, s.getGeneration()); f1.updateGeneration(0, 2); - ASSERT_TRUE(s.nextGeneration(0)); + ASSERT_TRUE(s.nextGenerationNow()); ASSERT_EQUAL(2, s.getGeneration()); } TEST_FFF("requireThatConfigHandleStillHasConfigOnTimestampUpdate", MyManager, APIFixture(f1), StandardFixture(f1, f2)) { f1.updateGeneration(0, 2); f1.updateGeneration(1, 2); - ASSERT_TRUE(f3.s.nextGeneration(0)); + ASSERT_TRUE(f3.s.nextGenerationNow()); verifyConfig("foo", f3.h1->getConfig()); verifyConfig("bar", f3.h2->getConfig()); } @@ -418,7 +414,7 @@ TEST_FF("requireThatTimeStamp0Works", MyManager, APIFixture(f1)) { f1.updateValue(0, createBarValue("bar"), 0); f1.updateValue(1, createFooValue("foo"), 0); f1.updateValue(2, createBazValue("baz"), 0); - ASSERT_TRUE(s.nextConfig(0)); + ASSERT_TRUE(s.nextConfigNow()); verifyConfig("bar", h2->getConfig()); verifyConfig("foo", h1->getConfig()); verifyConfig("baz", h3->getConfig()); @@ -432,58 +428,58 @@ TEST_FF("requireThatNextGenerationWorksWithManyConfigs", MyManager, APIFixture(f f1.updateValue(0, createBarValue("bar"), 1); f1.updateValue(1, createFooValue("foo"), 1); f1.updateValue(2, createBazValue("baz"), 1); - ASSERT_TRUE(s.nextGeneration(100)); + ASSERT_TRUE(s.nextGeneration(100ms)); verifyConfig("bar", h2->getConfig()); verifyConfig("foo", h1->getConfig()); verifyConfig("baz", h3->getConfig()); int generation = 2; f1.updateGeneration(0, generation); - ASSERT_FALSE(s.nextGeneration(0)); + ASSERT_FALSE(s.nextGenerationNow()); f1.updateGeneration(1, generation); - ASSERT_FALSE(s.nextGeneration(0)); + ASSERT_FALSE(s.nextGenerationNow()); f1.updateGeneration(2, generation); - ASSERT_TRUE(s.nextGeneration(100)); + ASSERT_TRUE(s.nextGeneration(100ms)); generation++; f1.updateGeneration(0, generation); - ASSERT_FALSE(s.nextGeneration(0)); + ASSERT_FALSE(s.nextGenerationNow()); f1.updateGeneration(2, generation); - ASSERT_FALSE(s.nextGeneration(0)); + ASSERT_FALSE(s.nextGenerationNow()); f1.updateGeneration(1, generation); - ASSERT_TRUE(s.nextGeneration(100)); + ASSERT_TRUE(s.nextGeneration(100ms)); generation++; f1.updateGeneration(1, generation); - ASSERT_FALSE(s.nextGeneration(0)); + ASSERT_FALSE(s.nextGenerationNow()); f1.updateGeneration(0, generation); - ASSERT_FALSE(s.nextGeneration(0)); + ASSERT_FALSE(s.nextGenerationNow()); f1.updateGeneration(2, generation); - ASSERT_TRUE(s.nextGeneration(100)); + ASSERT_TRUE(s.nextGeneration(100ms)); generation++; f1.updateGeneration(1, generation); - ASSERT_FALSE(s.nextGeneration(0)); + ASSERT_FALSE(s.nextGenerationNow()); f1.updateGeneration(2, generation); - ASSERT_FALSE(s.nextGeneration(0)); + ASSERT_FALSE(s.nextGenerationNow()); f1.updateGeneration(0, generation); - ASSERT_TRUE(s.nextGeneration(100)); + ASSERT_TRUE(s.nextGeneration(100ms)); generation++; f1.updateGeneration(2, generation); - ASSERT_FALSE(s.nextGeneration(0)); + ASSERT_FALSE(s.nextGenerationNow()); f1.updateGeneration(0, generation); - ASSERT_FALSE(s.nextGeneration(0)); + ASSERT_FALSE(s.nextGenerationNow()); f1.updateGeneration(1, generation); - ASSERT_TRUE(s.nextGeneration(100)); + ASSERT_TRUE(s.nextGeneration(100ms)); generation++; f1.updateGeneration(2, generation); - ASSERT_FALSE(s.nextGeneration(0)); + ASSERT_FALSE(s.nextGenerationNow()); f1.updateGeneration(1, generation); - ASSERT_FALSE(s.nextGeneration(0)); + ASSERT_FALSE(s.nextGenerationNow()); f1.updateGeneration(0, generation); - ASSERT_TRUE(s.nextGeneration(100)); + ASSERT_TRUE(s.nextGeneration(100ms)); } TEST_FF("requireThatConfigSubscriberHandlesProxyCache", MyManager, APIFixture(f1)) { @@ -491,13 +487,13 @@ TEST_FF("requireThatConfigSubscriberHandlesProxyCache", MyManager, APIFixture(f1 ConfigHandle<FooConfig>::UP h1 = s.subscribe<FooConfig>("myid"); f1.updateValue(0, createFooValue("foo"), 1); f1.updateGeneration(0, 2); - ASSERT_TRUE(s.nextConfig(0)); + ASSERT_TRUE(s.nextConfigNow()); ASSERT_EQUAL(2, s.getGeneration()); ASSERT_TRUE(h1->isChanged()); verifyConfig("foo", h1->getConfig()); f1.updateGeneration(0, 3); - ASSERT_TRUE(s.nextGeneration(0)); + ASSERT_TRUE(s.nextGenerationNow()); ASSERT_EQUAL(3, s.getGeneration()); ASSERT_FALSE(h1->isChanged()); verifyConfig("foo", h1->getConfig()); @@ -508,11 +504,11 @@ TEST_MT_FF("requireThatConfigSubscriberWaitsUntilNextConfigSucceeds", 2, MyManag ConfigSubscriber s(IConfigContext::SP(new APIFixture(f2))); ConfigHandle<FooConfig>::UP h1 = s.subscribe<FooConfig>("myid"); f1.updateValue(0, createFooValue("foo"), 1); - ASSERT_TRUE(s.nextConfig(0)); + ASSERT_TRUE(s.nextConfigNow()); f1.updateGeneration(0, 2); - ASSERT_FALSE(s.nextConfig(1000)); + ASSERT_FALSE(s.nextConfig(1000ms)); TEST_BARRIER(); - ASSERT_TRUE(s.nextConfig(2000)); + ASSERT_TRUE(s.nextConfig(2000ms)); verifyConfig("foo2", h1->getConfig()); // First update is skipped } else { TEST_BARRIER(); diff --git a/config/src/tests/subscription/subscription.cpp b/config/src/tests/subscription/subscription.cpp index bfa341fa982..5b8fc22bf4e 100644 --- a/config/src/tests/subscription/subscription.cpp +++ b/config/src/tests/subscription/subscription.cpp @@ -3,10 +3,11 @@ #include <vespa/config/common/misc.h> #include <vespa/config/common/configholder.h> #include <vespa/config/subscription/configsubscription.h> -#include <vespa/fastos/time.h> +#include <vespa/fastos/timestamp.h> #include <config-my.h> using namespace config; +using namespace std::chrono_literals; namespace { @@ -55,33 +56,31 @@ TEST_FF("requireThatKeyIsReturned", ConfigKey("foo", "bar", "bim", "boo"), Subsc TEST_F("requireThatUpdateReturns", SubscriptionFixture(ConfigKey::create<MyConfig>("myid"))) { - f1.holder->handle(ConfigUpdate::UP(new ConfigUpdate(ConfigValue(), 1, 1))); - ASSERT_TRUE(f1.sub.nextUpdate(0, 0)); + f1.holder->handle(std::make_unique<ConfigUpdate>(ConfigValue(), 1, 1)); + ASSERT_TRUE(f1.sub.nextUpdate(0, 0ms)); ASSERT_TRUE(f1.sub.hasChanged()); ASSERT_EQUAL(1, f1.sub.getGeneration()); } TEST_F("requireThatNextUpdateBlocks", SubscriptionFixture(ConfigKey::create<MyConfig>("myid"))) { - ASSERT_FALSE(f1.sub.nextUpdate(0, 0)); - f1.holder->handle(ConfigUpdate::UP(new ConfigUpdate(ConfigValue(), 1, 1))); - FastOS_Time timer; - timer.SetNow(); - ASSERT_FALSE(f1.sub.nextUpdate(1, 500)); - ASSERT_TRUE(timer.MilliSecsToNow() > 400.0); + ASSERT_FALSE(f1.sub.nextUpdate(0, 0ms)); + f1.holder->handle(std::make_unique<ConfigUpdate>(ConfigValue(), 1, 1)); + fastos::StopWatch timer; + ASSERT_FALSE(f1.sub.nextUpdate(1, 500ms)); + ASSERT_TRUE(timer.elapsed().ms() > 400.0); } TEST_MT_F("requireThatNextUpdateReturnsWhenNotified", 2, SubscriptionFixture(ConfigKey::create<MyConfig>("myid"))) { if (thread_id == 0) { - FastOS_Time timer; - timer.SetNow(); - f1.holder->handle(ConfigUpdate::UP(new ConfigUpdate(ConfigValue(), 1, 1))); - ASSERT_TRUE(f1.sub.nextUpdate(2, 5000)); - ASSERT_TRUE(timer.MilliSecsToNow() > 200.0); + fastos::StopWatch timer; + f1.holder->handle(std::make_unique<ConfigUpdate>(ConfigValue(), 1, 1)); + ASSERT_TRUE(f1.sub.nextUpdate(2, 5000ms)); + ASSERT_TRUE(timer.elapsed().ms() > 200.0); } else { std::this_thread::sleep_for(std::chrono::milliseconds(500)); - f1.holder->handle(ConfigUpdate::UP(new ConfigUpdate(ConfigValue(), 1, 1))); + f1.holder->handle(std::make_unique<ConfigUpdate>(ConfigValue(), 1, 1)); } } @@ -89,11 +88,10 @@ TEST_MT_F("requireThatNextUpdateReturnsWhenNotified", 2, SubscriptionFixture(Con TEST_MT_F("requireThatNextUpdateReturnsInterrupted", 2, SubscriptionFixture(ConfigKey::create<MyConfig>("myid"))) { if (thread_id == 0) { - FastOS_Time timer; - timer.SetNow(); - f1.holder->handle(ConfigUpdate::UP(new ConfigUpdate(ConfigValue(), 1, 1))); - ASSERT_TRUE(f1.sub.nextUpdate(1, 5000)); - ASSERT_TRUE(timer.MilliSecsToNow() > 300.0); + fastos::StopWatch timer; + f1.holder->handle(std::make_unique<ConfigUpdate>(ConfigValue(), 1, 1)); + ASSERT_TRUE(f1.sub.nextUpdate(1, 5000ms)); + ASSERT_TRUE(timer.elapsed().ms() > 300.0); } else { std::this_thread::sleep_for(std::chrono::milliseconds(500)); f1.sub.close(); @@ -102,16 +100,16 @@ TEST_MT_F("requireThatNextUpdateReturnsInterrupted", 2, SubscriptionFixture(Conf TEST_F("Require that isChanged takes generation into account", SubscriptionFixture(ConfigKey::create<MyConfig>("myid"))) { - f1.holder->handle(ConfigUpdate::UP(new ConfigUpdate(ConfigValue(std::vector<vespalib::string>(), "a"), true, 1))); - ASSERT_TRUE(f1.sub.nextUpdate(0, 0)); + f1.holder->handle(std::make_unique<ConfigUpdate>(ConfigValue(std::vector<vespalib::string>(), "a"), true, 1)); + ASSERT_TRUE(f1.sub.nextUpdate(0, 0ms)); f1.sub.flip(); ASSERT_EQUAL(1, f1.sub.getLastGenerationChanged()); - f1.holder->handle(ConfigUpdate::UP(new ConfigUpdate(ConfigValue(std::vector<vespalib::string>(), "b"), true, 2))); - ASSERT_TRUE(f1.sub.nextUpdate(1, 0)); + f1.holder->handle(std::make_unique<ConfigUpdate>(ConfigValue(std::vector<vespalib::string>(), "b"), true, 2)); + ASSERT_TRUE(f1.sub.nextUpdate(1, 0ms)); f1.sub.flip(); ASSERT_EQUAL(2, f1.sub.getLastGenerationChanged()); - f1.holder->handle(ConfigUpdate::UP(new ConfigUpdate(ConfigValue(), false, 3))); - ASSERT_TRUE(f1.sub.nextUpdate(2, 0)); + f1.holder->handle(std::make_unique<ConfigUpdate>(ConfigValue(), false, 3)); + ASSERT_TRUE(f1.sub.nextUpdate(2, 0ms)); f1.sub.flip(); ASSERT_EQUAL(2, f1.sub.getLastGenerationChanged()); } diff --git a/config/src/vespa/config/helper/configgetter.h b/config/src/vespa/config/helper/configgetter.h index 610b00cb66f..eb19715e3a5 100644 --- a/config/src/vespa/config/helper/configgetter.h +++ b/config/src/vespa/config/helper/configgetter.h @@ -17,10 +17,11 @@ template <typename ConfigType> class ConfigGetter { public: + using milliseconds = std::chrono::milliseconds; static std::unique_ptr<ConfigType> getConfig(int64_t &generation, const std::string & configId, const SourceSpec & spec = ServerSpec()); - static std::unique_ptr<ConfigType> getConfig(int64_t &generation, const std::string & configId, const std::shared_ptr<IConfigContext> & context, uint64_t subscribeTimeout = DEFAULT_SUBSCRIBE_TIMEOUT); + static std::unique_ptr<ConfigType> getConfig(int64_t &generation, const std::string & configId, const std::shared_ptr<IConfigContext> & context, milliseconds subscribeTimeout = DEFAULT_SUBSCRIBE_TIMEOUT); static std::unique_ptr<ConfigType> getConfig(const std::string & configId, const SourceSpec & spec = ServerSpec()); - static std::unique_ptr<ConfigType> getConfig(const std::string & configId, const std::shared_ptr<IConfigContext> & context, uint64_t subscribeTimeout = DEFAULT_SUBSCRIBE_TIMEOUT); + static std::unique_ptr<ConfigType> getConfig(const std::string & configId, const std::shared_ptr<IConfigContext> & context, milliseconds subscribeTimeout = DEFAULT_SUBSCRIBE_TIMEOUT); }; } // namespace config diff --git a/config/src/vespa/config/helper/configgetter.hpp b/config/src/vespa/config/helper/configgetter.hpp index 6d1f6fe78e5..588744144c2 100644 --- a/config/src/vespa/config/helper/configgetter.hpp +++ b/config/src/vespa/config/helper/configgetter.hpp @@ -18,7 +18,7 @@ ConfigGetter<ConfigType>::getConfig(int64_t &generation, const std::string & con template <typename ConfigType> std::unique_ptr<ConfigType> -ConfigGetter<ConfigType>::getConfig(int64_t &generation, const std::string & configId, const IConfigContext::SP & context, uint64_t subscribeTimeout) +ConfigGetter<ConfigType>::getConfig(int64_t &generation, const std::string & configId, const IConfigContext::SP & context, milliseconds subscribeTimeout) { ConfigSubscriber s(context); std::unique_ptr< ConfigHandle<ConfigType> > h = s.subscribe<ConfigType>(configId, subscribeTimeout); @@ -37,7 +37,7 @@ ConfigGetter<ConfigType>::getConfig(const std::string & configId, const SourceSp template <typename ConfigType> std::unique_ptr<ConfigType> -ConfigGetter<ConfigType>::getConfig(const std::string & configId, const IConfigContext::SP & context, uint64_t subscribeTimeout) +ConfigGetter<ConfigType>::getConfig(const std::string & configId, const IConfigContext::SP & context, milliseconds subscribeTimeout) { int64_t ignoreGeneration; return getConfig(ignoreGeneration, configId, context, subscribeTimeout); diff --git a/configd/src/apps/sentinel/config-handler.cpp b/configd/src/apps/sentinel/config-handler.cpp index 19e31755400..3e7b9ef0ea0 100644 --- a/configd/src/apps/sentinel/config-handler.cpp +++ b/configd/src/apps/sentinel/config-handler.cpp @@ -3,10 +3,9 @@ #include "config-handler.h" #include "output-connection.h" -#include <vespa/vespalib/net/simple_metric_snapshot.h> #include <vespa/vespalib/net/socket_address.h> #include <vespa/vespalib/util/exceptions.h> -#include <vespa/fastos/time.h> +#include <vespa/fastos/timestamp.h> #include <string> #include <fcntl.h> #include <sys/wait.h> @@ -121,9 +120,9 @@ ConfigHandler::terminate() } void -ConfigHandler::subscribe(const std::string & configId, uint64_t timeoutMS) +ConfigHandler::subscribe(const std::string & configId, std::chrono::milliseconds timeout) { - _sentinelHandle = _subscriber.subscribe<SentinelConfig>(configId, timeoutMS); + _sentinelHandle = _subscriber.subscribe<SentinelConfig>(configId, timeout); } void @@ -173,7 +172,7 @@ ConfigHandler::doWork() { // Return true if there are any running services, false if not. - if (_subscriber.nextGeneration(0)) { + if (_subscriber.nextGenerationNow()) { doConfigure(); } handleRestarts(); diff --git a/configd/src/apps/sentinel/config-handler.h b/configd/src/apps/sentinel/config-handler.h index 0af19a6363a..463e9e7ce6a 100644 --- a/configd/src/apps/sentinel/config-handler.h +++ b/configd/src/apps/sentinel/config-handler.h @@ -61,7 +61,7 @@ private: public: ConfigHandler(); virtual ~ConfigHandler(); - void subscribe(const std::string & configId, uint64_t timeoutMS); + void subscribe(const std::string & configId, std::chrono::milliseconds timeout); bool terminate(); int doWork(); void updateActiveFdset(fd_set *fds, int *maxNum); diff --git a/configd/src/apps/sentinel/sentinel.cpp b/configd/src/apps/sentinel/sentinel.cpp index 126c59d42f3..b062d7526b6 100644 --- a/configd/src/apps/sentinel/sentinel.cpp +++ b/configd/src/apps/sentinel/sentinel.cpp @@ -1,7 +1,6 @@ // Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. #include <vespa/config/common/exceptions.h> -#include <csignal> #include <unistd.h> #include <sys/time.h> #include <vespa/vespalib/util/signalhandler.h> @@ -14,7 +13,7 @@ LOG_SETUP("config-sentinel"); using namespace config; -constexpr uint64_t CONFIG_TIMEOUT_MS = 3 * 60 * 1000; +constexpr std::chrono::milliseconds CONFIG_TIMEOUT_MS(3 * 60 * 1000); static bool stop() { diff --git a/configutil/src/lib/configstatus.cpp b/configutil/src/lib/configstatus.cpp index 920de52dad7..1831a39b18a 100644 --- a/configutil/src/lib/configstatus.cpp +++ b/configutil/src/lib/configstatus.cpp @@ -107,7 +107,7 @@ public: } }; -MyHttpHandler::~MyHttpHandler() {} +MyHttpHandler::~MyHttpHandler() = default; ConfigStatus::ConfigStatus(Flags flags, const config::ConfigUri uri) : _cfg(), _flags(flags), _generation(0) @@ -120,7 +120,7 @@ ConfigStatus::ConfigStatus(Flags flags, const config::ConfigUri uri) config::ConfigSubscriber subscriber(uri.getContext()); config::ConfigHandle<cloud::config::ModelConfig>::UP handle = subscriber.subscribe<cloud::config::ModelConfig>(uri.getConfigId()); - subscriber.nextConfig(0); + subscriber.nextConfigNow(); _cfg = handle->getConfig(); _generation = subscriber.getGeneration(); } catch(config::ConfigRuntimeException &e) { @@ -133,7 +133,7 @@ ConfigStatus::ConfigStatus(Flags flags, const config::ConfigUri uri) } } -ConfigStatus::~ConfigStatus() {} +ConfigStatus::~ConfigStatus() = default; int ConfigStatus::action() diff --git a/logd/src/logd/watcher.cpp b/logd/src/logd/watcher.cpp index f7e90811465..2bb8973f052 100644 --- a/logd/src/logd/watcher.cpp +++ b/logd/src/logd/watcher.cpp @@ -6,7 +6,7 @@ #include "watcher.h" #include <vespa/log/log.h> #include <vespa/vespalib/util/sig_catch.h> -#include <vespa/fastos/time.h> +#include <vespa/fastos/timestamp.h> #include <fcntl.h> #include <glob.h> #include <sys/stat.h> diff --git a/logforwarder/src/apps/vespa-logforwarder-start/cf-handler.cpp b/logforwarder/src/apps/vespa-logforwarder-start/cf-handler.cpp index af8b527e227..addf9125508 100644 --- a/logforwarder/src/apps/vespa-logforwarder-start/cf-handler.cpp +++ b/logforwarder/src/apps/vespa-logforwarder-start/cf-handler.cpp @@ -13,16 +13,15 @@ #include <vespa/log/log.h> LOG_SETUP(".cf-handler"); -CfHandler::CfHandler() : _subscriber() {} -CfHandler::~CfHandler() -{ -} +CfHandler::CfHandler() = default; + +CfHandler::~CfHandler() = default; void -CfHandler::subscribe(const std::string & configId, uint64_t timeoutMS) +CfHandler::subscribe(const std::string & configId, std::chrono::milliseconds timeout) { - _handle = _subscriber.subscribe<LogforwarderConfig>(configId, timeoutMS); + _handle = _subscriber.subscribe<LogforwarderConfig>(configId, timeout); } namespace { @@ -89,12 +88,12 @@ CfHandler::doConfigure() void CfHandler::check() { - if (_subscriber.nextConfig(0)) { + if (_subscriber.nextConfigNow()) { doConfigure(); } } -constexpr uint64_t CONFIG_TIMEOUT_MS = 30 * 1000; +constexpr std::chrono::milliseconds CONFIG_TIMEOUT_MS(30 * 1000); void CfHandler::start(const char *configId) diff --git a/logforwarder/src/apps/vespa-logforwarder-start/cf-handler.h b/logforwarder/src/apps/vespa-logforwarder-start/cf-handler.h index 0dcf2be7058..0aa977467b5 100644 --- a/logforwarder/src/apps/vespa-logforwarder-start/cf-handler.h +++ b/logforwarder/src/apps/vespa-logforwarder-start/cf-handler.h @@ -12,7 +12,7 @@ private: ChildHandler childHandler; config::ConfigSubscriber _subscriber; config::ConfigHandle<LogforwarderConfig>::UP _handle; - void subscribe(const std::string & configId, uint64_t timeoutMS); + void subscribe(const std::string & configId, std::chrono::milliseconds timeout); void doConfigure(); public: CfHandler(); diff --git a/messagebus_test/src/tests/speed/cpp-client.cpp b/messagebus_test/src/tests/speed/cpp-client.cpp index 7bb30f1f6ff..43d030b519b 100644 --- a/messagebus_test/src/tests/speed/cpp-client.cpp +++ b/messagebus_test/src/tests/speed/cpp-client.cpp @@ -23,7 +23,7 @@ private: static uint64_t _seq; public: Client(MessageBus &bus, const SourceSessionParams ¶ms); - ~Client(); + ~Client() override; void send(); void send(uint64_t seq); void sample(uint32_t &okCnt, uint32_t &failCnt); diff --git a/searchcore/src/apps/proton/proton.cpp b/searchcore/src/apps/proton/proton.cpp index 7d63d8910ba..a805506b381 100644 --- a/searchcore/src/apps/proton/proton.cpp +++ b/searchcore/src/apps/proton/proton.cpp @@ -27,7 +27,7 @@ struct Params ~Params(); }; -Params::~Params() {} +Params::~Params() = default; class App : public FastOS_Application { @@ -174,7 +174,7 @@ App::Main() std::unique_ptr<search::StateFile> stateFile; std::unique_ptr<search::SigBusHandler> sigBusHandler; std::unique_ptr<search::IOErrorHandler> ioErrorHandler; - protonUP = std::make_unique<proton::Proton>(params.identity, _argc > 0 ? _argv[0] : "proton", params.subscribeTimeout); + protonUP = std::make_unique<proton::Proton>(params.identity, _argc > 0 ? _argv[0] : "proton", std::chrono::milliseconds(params.subscribeTimeout)); proton::Proton & proton = *protonUP; proton::BootstrapConfig::SP configSnapshot = proton.init(); if (proton.hasAbortedInit()) { @@ -220,7 +220,7 @@ App::Main() std::unique_ptr<ProtonServiceLayerProcess> spiProton; if ( ! params.serviceidentity.empty()) { spiProton.reset(new ProtonServiceLayerProcess(params.serviceidentity, proton, downPersistence.get())); - spiProton->setupConfig(params.subscribeTimeout); + spiProton->setupConfig(std::chrono::milliseconds(params.subscribeTimeout)); spiProton->createNode(); EV_STARTED("servicelayer"); } diff --git a/searchcore/src/apps/tests/persistenceconformance_test.cpp b/searchcore/src/apps/tests/persistenceconformance_test.cpp index 98ed9e3c4f3..ba0d2047b88 100644 --- a/searchcore/src/apps/tests/persistenceconformance_test.cpp +++ b/searchcore/src/apps/tests/persistenceconformance_test.cpp @@ -42,6 +42,7 @@ using namespace cloud::config::filedistribution; using namespace vespa::config::search::core; using namespace vespa::config::search::summary; using namespace vespa::config::search; +using namespace std::chrono_literals; using vespa::config::content::core::BucketspacesConfig; using std::shared_ptr; @@ -189,7 +190,7 @@ public: std::make_shared<BucketspacesConfig>(), tuneFileDocDB, HwInfo())); mgr.forwardConfig(b); - mgr.nextGeneration(0); + mgr.nextGeneration(0ms); return DocumentDB::SP( new DocumentDB(_baseDir, mgr.getConfig(), diff --git a/searchcore/src/tests/proton/docsummary/docsummary.cpp b/searchcore/src/tests/proton/docsummary/docsummary.cpp index 26abd6be914..7db4b6fc9dd 100644 --- a/searchcore/src/tests/proton/docsummary/docsummary.cpp +++ b/searchcore/src/tests/proton/docsummary/docsummary.cpp @@ -45,6 +45,7 @@ using namespace search::engine; using namespace search::index; using namespace search::transactionlog; using namespace search; +using namespace std::chrono_literals; using document::DocumenttypesConfig; using document::test::makeBucketSpace; @@ -210,7 +211,7 @@ public: std::make_shared<BucketspacesConfig>(), _tuneFileDocumentDB, _hwInfo); _configMgr.forwardConfig(b); - _configMgr.nextGeneration(0); + _configMgr.nextGeneration(0ms); if (! FastOS_File::MakeDirectory((std::string("tmpdb/") + docTypeName).c_str())) { LOG_ABORT("should not be reached"); } diff --git a/searchcore/src/tests/proton/documentdb/document_subdbs/document_subdbs_test.cpp b/searchcore/src/tests/proton/documentdb/document_subdbs/document_subdbs_test.cpp index 76b6bf55534..c26bb975a7a 100644 --- a/searchcore/src/tests/proton/documentdb/document_subdbs/document_subdbs_test.cpp +++ b/searchcore/src/tests/proton/documentdb/document_subdbs/document_subdbs_test.cpp @@ -43,6 +43,7 @@ using namespace search::transactionlog; using namespace search; using namespace searchcorespi; using namespace vespalib; +using namespace std::chrono_literals; using document::test::makeBucketSpace; using proton::bucketdb::BucketDBHandler; @@ -278,7 +279,7 @@ struct MyConfigSnapshot config::DirSpec spec(cfgDir); DocumentDBConfigHelper mgr(spec, "searchdocument"); mgr.forwardConfig(_bootstrap); - mgr.nextGeneration(1); + mgr.nextGeneration(1ms); _cfg = mgr.getConfig(); } }; diff --git a/searchcore/src/tests/proton/documentdb/documentdb_test.cpp b/searchcore/src/tests/proton/documentdb/documentdb_test.cpp index 2c9a2b300eb..4064fc24105 100644 --- a/searchcore/src/tests/proton/documentdb/documentdb_test.cpp +++ b/searchcore/src/tests/proton/documentdb/documentdb_test.cpp @@ -6,7 +6,6 @@ #include <vespa/fastos/file.h> #include <vespa/document/test/make_bucket_space.h> #include <vespa/searchcore/proton/attribute/flushableattribute.h> -#include <vespa/searchcore/proton/common/feedtoken.h> #include <vespa/searchcore/proton/common/statusreport.h> #include <vespa/searchcore/proton/docsummary/summaryflushtarget.h> #include <vespa/searchcore/proton/documentmetastore/documentmetastoreflushtarget.h> @@ -31,6 +30,7 @@ using namespace cloud::config::filedistribution; using namespace proton; using namespace vespalib::slime; +using namespace std::chrono_literals; using document::DocumentType; using document::DocumentTypeRepo; @@ -103,7 +103,7 @@ Fixture::Fixture() std::make_shared<BucketspacesConfig>(), tuneFileDocumentDB, HwInfo())); mgr.forwardConfig(b); - mgr.nextGeneration(0); + mgr.nextGeneration(0ms); _db.reset(new DocumentDB(".", mgr.getConfig(), "tcp/localhost:9014", _queryLimiter, _clock, DocTypeName("typea"), makeBucketSpace(), *b->getProtonConfigSP(), _myDBOwner, _summaryExecutor, _summaryExecutor, _tls, _dummy, diff --git a/searchcore/src/tests/proton/documentdb/fileconfigmanager/fileconfigmanager_test.cpp b/searchcore/src/tests/proton/documentdb/fileconfigmanager/fileconfigmanager_test.cpp index 581db62fce5..d2d9f573326 100644 --- a/searchcore/src/tests/proton/documentdb/fileconfigmanager/fileconfigmanager_test.cpp +++ b/searchcore/src/tests/proton/documentdb/fileconfigmanager/fileconfigmanager_test.cpp @@ -25,6 +25,7 @@ using namespace search::index; using namespace search; using namespace vespa::config::search::core; using namespace vespa::config::search; +using namespace std::chrono_literals; using vespa::config::content::core::BucketspacesConfig; using proton::matching::RankingConstants; @@ -48,10 +49,10 @@ makeBaseConfigSnapshot() std::make_shared<BucketspacesConfig>(), std::make_shared<TuneFileDocumentDB>(), HwInfo())); dbcm.forwardConfig(b); - dbcm.nextGeneration(0); + dbcm.nextGeneration(0ms); DocumentDBConfig::SP snap = dbcm.getConfig(); snap->setConfigId(myId); - ASSERT_TRUE(snap.get() != NULL); + ASSERT_TRUE(snap); return snap; } diff --git a/searchcore/src/tests/proton/documentdb/maintenancecontroller/maintenancecontroller_test.cpp b/searchcore/src/tests/proton/documentdb/maintenancecontroller/maintenancecontroller_test.cpp index e6df649af93..c732da58dd7 100644 --- a/searchcore/src/tests/proton/documentdb/maintenancecontroller/maintenancecontroller_test.cpp +++ b/searchcore/src/tests/proton/documentdb/maintenancecontroller/maintenancecontroller_test.cpp @@ -26,8 +26,6 @@ #include <vespa/searchcore/proton/test/disk_mem_usage_notifier.h> #include <vespa/searchcore/proton/test/mock_attribute_manager.h> #include <vespa/searchcore/proton/test/test.h> -#include <vespa/searchlib/attribute/attributecontext.h> -#include <vespa/searchlib/attribute/attributeguard.h> #include <vespa/searchlib/common/gatecallback.h> #include <vespa/searchlib/common/idocumentmetastore.h> #include <vespa/searchlib/index/docbuilder.h> @@ -70,8 +68,7 @@ typedef std::set<BucketId> BucketIdSet; constexpr int TIMEOUT_MS = 60000; constexpr double TIMEOUT_SEC = 60.0; -namespace -{ +namespace { void sampleThreadId(FastOS_ThreadId *threadId) @@ -806,12 +803,9 @@ MyExecutor::isIdle() bool MyExecutor::waitIdle(double timeout) { - FastOS_Time startTime; - startTime.SetNow(); + fastos::StopWatch timer; while (!isIdle()) { - FastOS_Time cTime; - cTime.SetNow(); - if (cTime.Secs() - startTime.Secs() >= timeout) + if (timer.elapsed().sec() >= timeout) return false; } return true; diff --git a/searchcore/src/tests/proton/proton_config_fetcher/proton_config_fetcher_test.cpp b/searchcore/src/tests/proton/proton_config_fetcher/proton_config_fetcher_test.cpp index fb80f6f55b4..d86a750794f 100644 --- a/searchcore/src/tests/proton/proton_config_fetcher/proton_config_fetcher_test.cpp +++ b/searchcore/src/tests/proton/proton_config_fetcher/proton_config_fetcher_test.cpp @@ -13,7 +13,7 @@ #include <vespa/fileacquirer/config-filedistributorrpc.h> #include <vespa/vespalib/util/varholder.h> #include <vespa/vespalib/testkit/testapp.h> -#include <vespa/fastos/time.h> +#include <vespa/fastos/timestamp.h> #include <vespa/config-bucketspaces.h> #include <vespa/config-attributes.h> #include <vespa/config-imported-fields.h> @@ -29,6 +29,7 @@ using namespace vespa::config::search::core; using namespace vespa::config::search::summary; using namespace vespa::config::search; using namespace cloud::config::filedistribution; +using namespace std::chrono_literals; using vespa::config::content::core::BucketspacesConfig; using vespa::config::content::core::BucketspacesConfigBuilder; @@ -169,10 +170,9 @@ struct ProtonConfigOwner : public proton::IProtonConfigurer VarHolder<std::shared_ptr<ProtonConfigSnapshot>> _config; ProtonConfigOwner() : _configured(false), _config() { } - bool waitUntilConfigured(int timeout) { - FastOS_Time timer; - timer.SetNow(); - while (timer.MilliSecsToNow() < timeout) { + bool waitUntilConfigured(int64_t timeout) { + fastos::StopWatch timer; + while (timer.elapsed().ms() < timeout) { if (getConfigured()) return true; FastOS_Thread::Sleep(100); @@ -290,7 +290,7 @@ TEST_FF("require that documentdb config manager builds schema with imported attr TEST_FFF("require that proton config fetcher follows changes to bootstrap", ConfigTestFixture("search"), ProtonConfigOwner(), - ProtonConfigFetcher(ConfigUri(f1.configId, f1.context), f2, 60000)) { + ProtonConfigFetcher(ConfigUri(f1.configId, f1.context), f2, 60000ms)) { f3.start(); ASSERT_TRUE(f2._configured); ASSERT_TRUE(f1.configEqual(f2.getBootstrapConfig())); @@ -305,7 +305,7 @@ TEST_FFF("require that proton config fetcher follows changes to bootstrap", TEST_FFF("require that proton config fetcher follows changes to doctypes", ConfigTestFixture("search"), ProtonConfigOwner(), - ProtonConfigFetcher(ConfigUri(f1.configId, f1.context), f2, 60000)) { + ProtonConfigFetcher(ConfigUri(f1.configId, f1.context), f2, 60000ms)) { f3.start(); f2._configured = false; @@ -325,7 +325,7 @@ TEST_FFF("require that proton config fetcher follows changes to doctypes", TEST_FFF("require that proton config fetcher reconfigures dbowners", ConfigTestFixture("search"), ProtonConfigOwner(), - ProtonConfigFetcher(ConfigUri(f1.configId, f1.context), f2, 60000)) { + ProtonConfigFetcher(ConfigUri(f1.configId, f1.context), f2, 60000ms)) { f3.start(); ASSERT_FALSE(f2.getDocumentDBConfig("typea")); diff --git a/searchcore/src/vespa/searchcore/proton/attribute/attribute_directory.h b/searchcore/src/vespa/searchcore/proton/attribute/attribute_directory.h index 19f89466e39..24d922418b8 100644 --- a/searchcore/src/vespa/searchcore/proton/attribute/attribute_directory.h +++ b/searchcore/src/vespa/searchcore/proton/attribute/attribute_directory.h @@ -5,10 +5,9 @@ #include <vespa/vespalib/stllike/string.h> #include <vespa/searchlib/common/indexmetainfo.h> #include <vespa/searchlib/common/serialnum.h> -#include <memory> +#include <vespa/fastos/timestamp.h> #include <mutex> #include <condition_variable> -#include <vespa/fastos/time.h> namespace proton { diff --git a/searchcore/src/vespa/searchcore/proton/common/hw_info_sampler.cpp b/searchcore/src/vespa/searchcore/proton/common/hw_info_sampler.cpp index 642d5a40ac7..ed5ce24143d 100644 --- a/searchcore/src/vespa/searchcore/proton/common/hw_info_sampler.cpp +++ b/searchcore/src/vespa/searchcore/proton/common/hw_info_sampler.cpp @@ -1,9 +1,7 @@ // Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. #include "hw_info_sampler.h" -#include <vespa/config/common/configholder.h> #include <vespa/config/config.h> -#include <vespa/config/file/filesource.h> #include <vespa/config/print/fileconfigwriter.h> #include <vespa/fastos/file.h> #include <vespa/searchcore/config/config-hwinfo.h> @@ -59,7 +57,7 @@ std::unique_ptr<HwinfoConfig> readConfig(const vespalib::string &path) { FileSpec spec(path + "/" + "hwinfo.cfg"); ConfigSubscriber s(spec); std::unique_ptr<ConfigHandle<HwinfoConfig>> handle = s.subscribe<HwinfoConfig>("hwinfo"); - s.nextConfig(0); + s.nextConfigNow(); return handle->getConfig(); } diff --git a/searchcore/src/vespa/searchcore/proton/server/documentdbconfigmanager.cpp b/searchcore/src/vespa/searchcore/proton/server/documentdbconfigmanager.cpp index ef31da34683..20d11c43a68 100644 --- a/searchcore/src/vespa/searchcore/proton/server/documentdbconfigmanager.cpp +++ b/searchcore/src/vespa/searchcore/proton/server/documentdbconfigmanager.cpp @@ -10,7 +10,6 @@ #include <vespa/config/file_acquirer/file_acquirer.h> #include <vespa/config/helper/legacy.h> #include <vespa/config-attributes.h> -#include <vespa/config-imported-fields.h> #include <vespa/config-indexschema.h> #include <vespa/config-summary.h> #include <vespa/searchcommon/common/schemaconfigurer.h> @@ -378,7 +377,7 @@ DocumentDBConfigHelper::DocumentDBConfigHelper(const DirSpec &spec, const vespal DocumentDBConfigHelper::~DocumentDBConfigHelper() = default; bool -DocumentDBConfigHelper::nextGeneration(int timeoutInMillis) +DocumentDBConfigHelper::nextGeneration(std::chrono::milliseconds timeoutInMillis) { ConfigSnapshot snapshot(_retriever->getBootstrapConfigs(timeoutInMillis)); if (snapshot.empty()) diff --git a/searchcore/src/vespa/searchcore/proton/server/documentdbconfigmanager.h b/searchcore/src/vespa/searchcore/proton/server/documentdbconfigmanager.h index bd1cb66de43..c4dabe7e563 100644 --- a/searchcore/src/vespa/searchcore/proton/server/documentdbconfigmanager.h +++ b/searchcore/src/vespa/searchcore/proton/server/documentdbconfigmanager.h @@ -53,7 +53,7 @@ public: DocumentDBConfigHelper(const config::DirSpec &spec, const vespalib::string &docTypeName); ~DocumentDBConfigHelper(); - bool nextGeneration(int timeoutInMillis); + bool nextGeneration(std::chrono::milliseconds timeoutInMillis); DocumentDBConfig::SP getConfig() const; void forwardConfig(const std::shared_ptr<BootstrapConfig> & config); private: diff --git a/searchcore/src/vespa/searchcore/proton/server/fileconfigmanager.cpp b/searchcore/src/vespa/searchcore/proton/server/fileconfigmanager.cpp index 748c02503f1..395eb5a0ea2 100644 --- a/searchcore/src/vespa/searchcore/proton/server/fileconfigmanager.cpp +++ b/searchcore/src/vespa/searchcore/proton/server/fileconfigmanager.cpp @@ -42,6 +42,7 @@ using vespa::config::content::core::BucketspacesConfig; using vespalib::nbostream; typedef IndexMetaInfo::SnapshotList SnapshotList; +using namespace std::chrono_literals; namespace proton { @@ -381,7 +382,7 @@ FileConfigManager::loadConfig(const DocumentDBConfig ¤tSnapshot, bucketspaces,currentSnapshot.getTuneFileDocumentDBSP(), sampler.hwInfo()); dbc.forwardConfig(bootstrap); - dbc.nextGeneration(0); + dbc.nextGeneration(0ms); loadedSnapshot = dbc.getConfig(); loadedSnapshot->setConfigId(_configId); diff --git a/searchcore/src/vespa/searchcore/proton/server/proton.cpp b/searchcore/src/vespa/searchcore/proton/server/proton.cpp index a8f5cb32375..6e0a3991001 100644 --- a/searchcore/src/vespa/searchcore/proton/server/proton.cpp +++ b/searchcore/src/vespa/searchcore/proton/server/proton.cpp @@ -175,7 +175,7 @@ Proton::ProtonFileHeaderContext::setClusterName(const vespalib::string & cluster Proton::Proton(const config::ConfigUri & configUri, const vespalib::string &progName, - uint64_t subscribeTimeout) + std::chrono::milliseconds subscribeTimeout) : IProtonConfigurerOwner(), search::engine::MonitorServer(), IDocumentDBOwner(), @@ -221,12 +221,10 @@ Proton::Proton(const config::ConfigUri & configUri, _initStarted(false), _initComplete(false), _initDocumentDbsInSequence(false), - _documentDBReferenceRegistry(), + _documentDBReferenceRegistry(std::make_shared<DocumentDBReferenceRegistry>()), _nodeUpLock(), _nodeUp() -{ - _documentDBReferenceRegistry = std::make_shared<DocumentDBReferenceRegistry>(); -} +{ } BootstrapConfig::SP Proton::init() diff --git a/searchcore/src/vespa/searchcore/proton/server/proton.h b/searchcore/src/vespa/searchcore/proton/server/proton.h index 487a596e7e6..410f45162e4 100644 --- a/searchcore/src/vespa/searchcore/proton/server/proton.h +++ b/searchcore/src/vespa/searchcore/proton/server/proton.h @@ -155,7 +155,7 @@ public: Proton(const config::ConfigUri & configUri, const vespalib::string &progName, - uint64_t subscribeTimeout); + std::chrono::milliseconds subscribeTimeout); ~Proton() override; /** diff --git a/searchcore/src/vespa/searchcore/proton/server/proton_config_fetcher.cpp b/searchcore/src/vespa/searchcore/proton/server/proton_config_fetcher.cpp index ff39ed89999..ef0185e60b3 100644 --- a/searchcore/src/vespa/searchcore/proton/server/proton_config_fetcher.cpp +++ b/searchcore/src/vespa/searchcore/proton/server/proton_config_fetcher.cpp @@ -17,7 +17,7 @@ using namespace std::chrono_literals; namespace proton { -ProtonConfigFetcher::ProtonConfigFetcher(const config::ConfigUri & configUri, IProtonConfigurer &owner, uint64_t subscribeTimeout) +ProtonConfigFetcher::ProtonConfigFetcher(const config::ConfigUri & configUri, IProtonConfigurer &owner, std::chrono::milliseconds subscribeTimeout) : _bootstrapConfigManager(configUri.getConfigId()), _retriever(_bootstrapConfigManager.createConfigKeySet(), configUri.getContext(), subscribeTimeout), _owner(owner), @@ -111,7 +111,7 @@ ProtonConfigFetcher::fetchConfigs() LOG(debug, "Waiting for new config generation"); bool configured = false; while (!configured) { - ConfigSnapshot bootstrapSnapshot = _retriever.getBootstrapConfigs(5000); + ConfigSnapshot bootstrapSnapshot = _retriever.getBootstrapConfigs(5000ms); if (_retriever.isClosed()) return; LOG(debug, "Fetching snapshot"); @@ -162,7 +162,7 @@ void ProtonConfigFetcher::start() { fetchConfigs(); - if (_threadPool.NewThread(this, NULL) == NULL) { + if (_threadPool.NewThread(this, nullptr) == nullptr) { throw vespalib::IllegalStateException( "Failed starting thread for proton config fetcher"); } @@ -182,7 +182,6 @@ ProtonConfigFetcher::rememberDocumentTypeRepo(std::shared_ptr<const document::Do { // Ensure that previous document type repo is kept alive, and also // any document type repo that was current within last 10 minutes. - using namespace std::chrono_literals; if (repo == _currentDocumentTypeRepo) { return; // no change } diff --git a/searchcore/src/vespa/searchcore/proton/server/proton_config_fetcher.h b/searchcore/src/vespa/searchcore/proton/server/proton_config_fetcher.h index 252d8e6dc0e..13582a6f96c 100644 --- a/searchcore/src/vespa/searchcore/proton/server/proton_config_fetcher.h +++ b/searchcore/src/vespa/searchcore/proton/server/proton_config_fetcher.h @@ -27,8 +27,8 @@ class ProtonConfigFetcher : public FastOS_Runnable public: using BootstrapConfigSP = std::shared_ptr<BootstrapConfig>; - ProtonConfigFetcher(const config::ConfigUri & configUri, IProtonConfigurer &owner, uint64_t subscribeTimeout); - ~ProtonConfigFetcher(); + ProtonConfigFetcher(const config::ConfigUri & configUri, IProtonConfigurer &owner, std::chrono::milliseconds subscribeTimeout); + ~ProtonConfigFetcher() override; /** * Get the current config generation. */ diff --git a/searchlib/src/tests/aggregator/perdocexpr.cpp b/searchlib/src/tests/aggregator/perdocexpr.cpp index b8584980cf9..c078282c442 100644 --- a/searchlib/src/tests/aggregator/perdocexpr.cpp +++ b/searchlib/src/tests/aggregator/perdocexpr.cpp @@ -694,10 +694,9 @@ TEST("testDebugFunction") { DebugWaitFunctionNode n(std::move(add), 1.3, false); n.prepare(false); - FastOS_Time time; - time.SetNow(); + fastos::StopWatch timer; n.execute(); - EXPECT_TRUE(time.MilliSecsToNow() > 1000.0); + EXPECT_TRUE(timer.elapsed().ms() > 1000.0); EXPECT_EQUAL(static_cast<const Int64ResultNode &>(n.getResult()).get(), 7); } { @@ -707,10 +706,9 @@ TEST("testDebugFunction") { DebugWaitFunctionNode n(std::move(add), 1.3, true); n.prepare(false); - FastOS_Time time; - time.SetNow(); + fastos::StopWatch timer; n.execute(); - EXPECT_TRUE(time.MilliSecsToNow() > 1000.0); + EXPECT_TRUE(timer.elapsed().ms() > 1000.0); EXPECT_EQUAL(static_cast<const Int64ResultNode &>(n.getResult()).get(), 7); } } diff --git a/searchlib/src/tests/attribute/benchmark/attributesearcher.h b/searchlib/src/tests/attribute/benchmark/attributesearcher.h index adc63266489..66bb6467194 100644 --- a/searchlib/src/tests/attribute/benchmark/attributesearcher.h +++ b/searchlib/src/tests/attribute/benchmark/attributesearcher.h @@ -63,7 +63,7 @@ protected: typedef AttributeVector::SP AttributePtr; const AttributePtr & _attrPtr; - FastOS_Time _timer; + fastos::StopWatch _timer; AttributeSearcherStatus _status; public: @@ -114,14 +114,14 @@ public: { _status._numQueries = numQueries; } - virtual void doRun() override; + void doRun() override; }; template <typename T> void AttributeFindSearcher<T>::doRun() { - _timer.SetNow(); + _timer.restart(); for (uint32_t i = 0; i < _status._numQueries; ++i) { // build simple term query vespalib::asciistream ss; @@ -134,12 +134,12 @@ AttributeFindSearcher<T>::doRun() attribute::SearchContextParams()); searchContext->fetchPostings(true); - std::unique_ptr<queryeval::SearchIterator> iterator = searchContext->createIterator(NULL, true); + std::unique_ptr<queryeval::SearchIterator> iterator = searchContext->createIterator(nullptr, true); std::unique_ptr<ResultSet> results = performSearch(*iterator, _attrPtr->getNumDocs()); _status._totalHitCount += results->getNumHits(); } - _status._totalSearchTime += _timer.MilliSecsToNow(); + _status._totalSearchTime += _timer.elapsed().ms(); } @@ -192,13 +192,13 @@ public: { _status._numQueries = numQueries; } - virtual void doRun() override; + void doRun() override; }; void AttributeRangeSearcher::doRun() { - _timer.SetNow(); + _timer.restart(); RangeIterator iter(_spec); for (uint32_t i = 0; i < _status._numQueries; ++i, ++iter) { // build simple range term query @@ -212,12 +212,12 @@ AttributeRangeSearcher::doRun() attribute::SearchContextParams()); searchContext->fetchPostings(true); - std::unique_ptr<queryeval::SearchIterator> iterator = searchContext->createIterator(NULL, true); + std::unique_ptr<queryeval::SearchIterator> iterator = searchContext->createIterator(nullptr, true); std::unique_ptr<ResultSet> results = performSearch(*iterator, _attrPtr->getNumDocs()); _status._totalHitCount += results->getNumHits(); } - _status._totalSearchTime += _timer.MilliSecsToNow(); + _status._totalSearchTime += _timer.elapsed().ms(); } @@ -234,13 +234,13 @@ public: { _status._numQueries = numQueries; } - virtual void doRun() override; + void doRun() override; }; void AttributePrefixSearcher::doRun() { - _timer.SetNow(); + _timer.restart(); for (uint32_t i = 0; i < _status._numQueries; ++i) { // build simple prefix term query buildTermQuery(_query, _attrPtr->getName(), _values[i % _values.size()].c_str(), true); @@ -251,15 +251,12 @@ AttributePrefixSearcher::doRun() attribute::SearchContextParams()); searchContext->fetchPostings(true); - std::unique_ptr<queryeval::SearchIterator> iterator = searchContext->createIterator(NULL, true); + std::unique_ptr<queryeval::SearchIterator> iterator = searchContext->createIterator(nullptr, true); std::unique_ptr<ResultSet> results = performSearch(*iterator, _attrPtr->getNumDocs()); _status._totalHitCount += results->getNumHits(); } - _status._totalSearchTime += _timer.MilliSecsToNow(); + _status._totalSearchTime += _timer.elapsed().ms(); } - - } // search - diff --git a/searchlib/src/tests/attribute/benchmark/attributeupdater.h b/searchlib/src/tests/attribute/benchmark/attributeupdater.h index 1dad2cb563d..c56c809457b 100644 --- a/searchlib/src/tests/attribute/benchmark/attributeupdater.h +++ b/searchlib/src/tests/attribute/benchmark/attributeupdater.h @@ -98,7 +98,7 @@ protected: std::vector<BT> _getBuffer; RandomGenerator & _rndGen; AttributeCommit _expected; - FastOS_Time _timer; + fastos::StopWatch _timer; AttributeUpdaterStatus _status; AttributeValidator _validator; @@ -267,7 +267,7 @@ template <typename Vector, typename T, typename BT> void AttributeUpdater<Vector, T, BT>::populate() { - _timer.SetNow(); + _timer.restart(); for (uint32_t doc = 0; doc < _attrPtr->getNumDocs(); ++doc) { updateValues(doc); if (doc % _commitFreq == (_commitFreq - 1)) { @@ -275,7 +275,7 @@ AttributeUpdater<Vector, T, BT>::populate() } } commit(); - _status._totalUpdateTime += _timer.MilliSecsToNow(); + _status._totalUpdateTime += _timer.elapsed().ms(); } @@ -283,7 +283,7 @@ template <typename Vector, typename T, typename BT> void AttributeUpdater<Vector, T, BT>::update(uint32_t numUpdates) { - _timer.SetNow(); + _timer.restart(); for (uint32_t i = 0; i < numUpdates; ++i) { uint32_t doc = getRandomDoc(); updateValues(doc); @@ -292,7 +292,7 @@ AttributeUpdater<Vector, T, BT>::update(uint32_t numUpdates) } } commit(); - _status._totalUpdateTime += _timer.MilliSecsToNow(); + _status._totalUpdateTime += _timer.elapsed().ms(); } @@ -300,7 +300,7 @@ template <typename Vector, typename T, typename BT> void AttributeUpdaterThread<Vector, T, BT>::doRun() { - this->_timer.SetNow(); + this->_timer.restart(); while(!_done) { uint32_t doc = this->getRandomDoc(); this->updateValues(doc); @@ -309,7 +309,7 @@ AttributeUpdaterThread<Vector, T, BT>::doRun() } } this->commit(); - this->_status._totalUpdateTime += this->_timer.MilliSecsToNow(); + this->_status._totalUpdateTime += this->_timer.elapsed().ms(); } diff --git a/searchlib/src/tests/diskindex/fieldwriter/fieldwriter_test.cpp b/searchlib/src/tests/diskindex/fieldwriter/fieldwriter_test.cpp index eb3218468ae..18bcde35020 100644 --- a/searchlib/src/tests/diskindex/fieldwriter/fieldwriter_test.cpp +++ b/searchlib/src/tests/diskindex/fieldwriter/fieldwriter_test.cpp @@ -1,31 +1,27 @@ // Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. #include <vespa/searchlib/common/bitvector.h> -#include <vespa/searchlib/common/resultset.h> #include <vespa/searchlib/util/rand48.h> #include <vespa/searchlib/test/fakedata/fakeword.h> #include <vespa/searchlib/test/fakedata/fakewordset.h> #include <vespa/searchlib/index/docidandfeatures.h> #include <vespa/searchlib/index/field_length_info.h> #include <vespa/searchlib/index/postinglisthandle.h> -#include <vespa/searchlib/diskindex/zcposocc.h> #include <vespa/searchlib/diskindex/zcposoccrandread.h> #include <vespa/searchlib/index/dummyfileheadercontext.h> #include <vespa/searchlib/index/schemautil.h> #include <vespa/searchlib/diskindex/fieldwriter.h> #include <vespa/searchlib/diskindex/fieldreader.h> #include <vespa/vespalib/io/fileutil.h> -#include <vespa/searchlib/util/dirtraverse.h> #include <vespa/searchlib/diskindex/pagedict4file.h> #include <vespa/searchlib/diskindex/pagedict4randread.h> #include <vespa/vespalib/stllike/asciistream.h> -#include <vespa/fastos/time.h> +#include <vespa/fastos/timestamp.h> #include <openssl/sha.h> #include <vespa/fastos/app.h> #include <vespa/log/log.h> LOG_SETUP("fieldwriter_test"); -using search::ResultSet; using search::TuneFileRandRead; using search::TuneFileSeqRead; using search::TuneFileSeqWrite; @@ -362,18 +358,13 @@ writeField(FakeWordSet &wordSet, { const char *dynamicKStr = dynamicK ? "true" : "false"; - FastOS_Time tv; - double before; - double after; - LOG(info, "enter writeField, " "namepref=%s, dynamicK=%s, encode_interleaved_features=%s", namepref.c_str(), dynamicKStr, bool_to_str(encode_interleaved_features)); - tv.SetNow(); - before = tv.Secs(); + fastos::StopWatch tv; WrappedFieldWriter ostate(namepref, dynamicK, encode_interleaved_features, wordSet.getNumWords(), docIdLimit); @@ -390,8 +381,6 @@ writeField(FakeWordSet &wordSet, } ostate.close(); - tv.SetNow(); - after = tv.Secs(); LOG(info, "leave writeField, " "namepref=%s, dynamicK=%s, encode_interleaved_features=%s" @@ -399,7 +388,7 @@ writeField(FakeWordSet &wordSet, namepref.c_str(), dynamicKStr, bool_to_str(encode_interleaved_features), - after - before); + tv.elapsed().sec()); } @@ -413,19 +402,11 @@ readField(FakeWordSet &wordSet, { const char *dynamicKStr = dynamicK ? "true" : "false"; - FastOS_Time tv; - double before; - double after; - WrappedFieldReader istate(namepref, wordSet.getNumWords(), - docIdLimit); - LOG(info, - "enter readField, " - "namepref=%s, dynamicK=%s, decode_interleaved_features=%s", - namepref.c_str(), - dynamicKStr, - bool_to_str(decode_interleaved_features)); - tv.SetNow(); - before = tv.Secs(); + WrappedFieldReader istate(namepref, wordSet.getNumWords(), docIdLimit); + LOG(info, "enter readField, namepref=%s, dynamicK=%s, decode_interleaved_features=%s", + namepref.c_str(), dynamicKStr, bool_to_str(decode_interleaved_features)); + + fastos::StopWatch tv; istate.open(); if (istate._fieldReader->isValid()) istate._fieldReader->read(); @@ -448,16 +429,10 @@ readField(FakeWordSet &wordSet, } istate.close(); - tv.SetNow(); - after = tv.Secs(); - LOG(info, - "leave readField, " - "namepref=%s, dynamicK=%s, decode_interleaved_features=%s" - " elapsed=%10.6f", - namepref.c_str(), - dynamicKStr, + LOG(info, "leave readField, namepref=%s, dynamicK=%s, decode_interleaved_features=%s elapsed=%10.6f", + namepref.c_str(), dynamicKStr, bool_to_str(decode_interleaved_features), - after - before); + tv.elapsed().sec()); } @@ -470,19 +445,12 @@ randReadField(FakeWordSet &wordSet, { const char *dynamicKStr = dynamicK ? "true" : "false"; - FastOS_Time tv; - double before; - double after; PostingListCounts counts; - LOG(info, - "enter randReadField," - " namepref=%s, dynamicK=%s, decode_interleaved_features=%s", - namepref.c_str(), - dynamicKStr, - bool_to_str(decode_interleaved_features)); - tv.SetNow(); - before = tv.Secs(); + LOG(info, "enter randReadField, namepref=%s, dynamicK=%s, decode_interleaved_features=%s", + namepref.c_str(), dynamicKStr, bool_to_str(decode_interleaved_features)); + + fastos::StopWatch tv; std::string cname = dirprefix + namepref; cname += "dictionary"; @@ -490,15 +458,12 @@ randReadField(FakeWordSet &wordSet, std::unique_ptr<search::index::DictionaryFileRandRead> dictFile; dictFile.reset(new PageDict4RandRead); - search::index::PostingListFileRandRead *postingFile = NULL; + search::index::PostingListFileRandRead *postingFile = nullptr; if (dynamicK) - postingFile = - new search::diskindex::ZcPosOccRandRead; + postingFile = new search::diskindex::ZcPosOccRandRead; else - postingFile = - new search::diskindex::Zc4PosOccRandRead; + postingFile = new search::diskindex::Zc4PosOccRandRead; - TuneFileSeqRead tuneFileRead; TuneFileRandRead tuneFileRandRead; bool openCntRes = dictFile->open(cname, tuneFileRandRead); assert(openCntRes); @@ -560,16 +525,11 @@ randReadField(FakeWordSet &wordSet, dictFile->close(); delete postingFile; dictFile.reset(); - tv.SetNow(); - after = tv.Secs(); - LOG(info, - "leave randReadField, namepref=%s," - " dynamicK=%s, decode_interleaved_features=%s, " - "elapsed=%10.6f", + LOG(info, "leave randReadField, namepref=%s, dynamicK=%s, decode_interleaved_features=%s, elapsed=%10.6f", namepref.c_str(), dynamicKStr, bool_to_str(decode_interleaved_features), - after - before); + tv.elapsed().sec()); } @@ -595,16 +555,10 @@ fusionField(uint32_t numWordIds, rawStr, dynamicKStr, bool_to_str(encode_interleaved_features)); - FastOS_Time tv; - double before; - double after; - WrappedFieldWriter ostate(opref, - dynamicK, encode_interleaved_features, - numWordIds, docIdLimit); + WrappedFieldWriter ostate(opref, dynamicK, encode_interleaved_features, numWordIds, docIdLimit); WrappedFieldReader istate(ipref, numWordIds, docIdLimit); - tv.SetNow(); - before = tv.Secs(); + fastos::StopWatch tv; ostate.open(); istate.open(); @@ -624,8 +578,7 @@ fusionField(uint32_t numWordIds, } istate.close(); ostate.close(); - tv.SetNow(); - after = tv.Secs(); + LOG(info, "leave fusionField, ipref=%s, opref=%s," " raw=%s dynamicK=%s, encode_interleaved_features=%s," @@ -634,7 +587,7 @@ fusionField(uint32_t numWordIds, opref.c_str(), rawStr, dynamicKStr, bool_to_str(encode_interleaved_features), - after - before); + tv.elapsed().sec()); } @@ -754,7 +707,7 @@ main(int argc, char **argv) { fieldwriter::FieldWriterTest app; - setvbuf(stdout, NULL, _IOLBF, 32768); + setvbuf(stdout, nullptr, _IOLBF, 32768); app._rnd.srand48(32); return app.Entry(argc, argv); } diff --git a/searchlib/src/tests/features/featurebenchmark.cpp b/searchlib/src/tests/features/featurebenchmark.cpp index 2c0014e21f6..43b1e38f4a4 100644 --- a/searchlib/src/tests/features/featurebenchmark.cpp +++ b/searchlib/src/tests/features/featurebenchmark.cpp @@ -105,11 +105,11 @@ public: private: search::fef::BlueprintFactory _factory; - FastOS_Time _timer; - double _sample; + fastos::StopWatch _timer; + fastos::TimeStamp _sample; - void start() { _timer.SetNow(); } - void sample() { _sample = _timer.MilliSecsToNow(); } + void start() { _timer.restart(); } + void sample() { _sample = _timer.elapsed(); } void setupPropertyMap(Properties & props, const KeyValueVector & values); void runFieldMatch(Config & cfg); void runRankingExpression(Config & cfg); @@ -648,8 +648,8 @@ Benchmark::Main() std::cout << "feature case '" << cfg.getCase() << "' is not known" << std::endl; } - std::cout << "TET: " << _sample << " (ms)" << std::endl; - std::cout << "ETPD: " << std::fixed << std::setprecision(10) << _sample / cfg.getNumRuns() << " (ms)" << std::endl; + std::cout << "TET: " << _sample.ms() << " (ms)" << std::endl; + std::cout << "ETPD: " << std::fixed << std::setprecision(10) << _sample.ms() / cfg.getNumRuns() << " (ms)" << std::endl; std::cout << "**** '" << cfg.getFeature() << "' ****" << std::endl; TEST_DONE(); diff --git a/searchlib/src/tests/fef/phrasesplitter/benchmark.cpp b/searchlib/src/tests/fef/phrasesplitter/benchmark.cpp index c789fb582ec..bed5d656b93 100644 --- a/searchlib/src/tests/fef/phrasesplitter/benchmark.cpp +++ b/searchlib/src/tests/fef/phrasesplitter/benchmark.cpp @@ -6,7 +6,7 @@ #include <vespa/searchlib/fef/matchdatalayout.h> #include <vespa/searchlib/fef/phrasesplitter.h> #include <vespa/searchlib/fef/test/queryenvironment.h> -#include <vespa/fastos/time.h> +#include <vespa/fastos/timestamp.h> #include <vespa/log/log.h> LOG_SETUP("phrasesplitter_test"); @@ -16,11 +16,11 @@ namespace search::fef { class Benchmark : public vespalib::TestApp { private: - FastOS_Time _timer; - double _sample; + fastos::StopWatch _timer; + fastos::TimeStamp _sample; - void start() { _timer.SetNow(); } - void sample() { _sample = _timer.MilliSecsToNow(); } + void start() { _timer.restart(); } + void sample() { _sample = _timer.elapsed(); } void run(size_t numRuns, size_t numPositions); public: @@ -69,13 +69,13 @@ Benchmark::Main() return 0; } - size_t numRuns = strtoull(_argv[1], NULL, 10); - size_t numPositions = strtoull(_argv[2], NULL, 10); + size_t numRuns = strtoull(_argv[1], nullptr, 10); + size_t numPositions = strtoull(_argv[2], nullptr, 10); run(numRuns, numPositions); - std::cout << "TET: " << _sample << " (ms)" << std::endl; - std::cout << "ETPD: " << std::fixed << std::setprecision(10) << _sample / numRuns << " (ms)" << std::endl; + std::cout << "TET: " << _sample.ms() << " (ms)" << std::endl; + std::cout << "ETPD: " << std::fixed << std::setprecision(10) << _sample.ms() / numRuns << " (ms)" << std::endl; TEST_DONE(); } diff --git a/searchlib/src/tests/grouping/grouping_test.cpp b/searchlib/src/tests/grouping/grouping_test.cpp index 0750d30f60d..237c8035b86 100644 --- a/searchlib/src/tests/grouping/grouping_test.cpp +++ b/searchlib/src/tests/grouping/grouping_test.cpp @@ -1896,12 +1896,11 @@ Test::testNanSorting() EXPECT_FALSE(0.2 < myNan); EXPECT_FALSE(0.2 > myNan); - FastOS_Time timer; - timer.SetNow(); + fastos::StopWatch timer; std::vector<double> groups; - while (timer.MilliSecsToNow() < 60000.0) { + while (timer.elapsed().ms() < 60000.0) { std::vector<double> vec; - srand((unsigned int)timer.MilliSecs()); + srand((unsigned int)timer.elapsed().us()); size_t limit = 2345678; size_t mod = rand() % limit; for (size_t i = 0; i < limit; i++) { diff --git a/searchlib/src/tests/groupingengine/groupingengine_test.cpp b/searchlib/src/tests/groupingengine/groupingengine_test.cpp index da9b8d62305..11a661a743e 100644 --- a/searchlib/src/tests/groupingengine/groupingengine_test.cpp +++ b/searchlib/src/tests/groupingengine/groupingengine_test.cpp @@ -1894,12 +1894,11 @@ Test::testNanSorting() EXPECT_FALSE(0.2 < myNan); EXPECT_FALSE(0.2 > myNan); - FastOS_Time timer; - timer.SetNow(); + fastos::StopWatch timer; std::vector<double> groups; - while (timer.MilliSecsToNow() < 60000.0) { + while (timer.elapsed().ms()() < 60000.0) { std::vector<double> vec; - srand((unsigned int)timer.MilliSecs()); + srand((unsigned int)timer.elapsed.us()()); size_t limit = 2345678; size_t mod = rand() % limit; for (size_t i = 0; i < limit; i++) { diff --git a/searchlib/src/tests/postinglistbm/stress_runner.cpp b/searchlib/src/tests/postinglistbm/stress_runner.cpp index a2a2968c13c..53b683cd7fd 100644 --- a/searchlib/src/tests/postinglistbm/stress_runner.cpp +++ b/searchlib/src/tests/postinglistbm/stress_runner.cpp @@ -3,16 +3,10 @@ #include "stress_runner.h" #include <vespa/fastos/thread.h> -#include <vespa/fastos/time.h> -#include <vespa/searchlib/common/bitvector.h> #include <vespa/searchlib/test/fakedata/fake_match_loop.h> -#include <vespa/searchlib/test/fakedata/fakeegcompr64filterocc.h> -#include <vespa/searchlib/test/fakedata/fakefilterocc.h> #include <vespa/searchlib/test/fakedata/fakeposting.h> #include <vespa/searchlib/test/fakedata/fakeword.h> #include <vespa/searchlib/test/fakedata/fakewordset.h> -#include <vespa/searchlib/test/fakedata/fakezcbfilterocc.h> -#include <vespa/searchlib/test/fakedata/fakezcfilterocc.h> #include <vespa/searchlib/test/fakedata/fpfactory.h> #include <condition_variable> #include <mutex> @@ -236,12 +230,8 @@ StressMaster::makePostingsHelper(FPFactory *postingFactory, const std::string &postingFormat, bool validate, bool verbose) { - FastOS_Time tv; - double before; - double after; + fastos::StopWatch tv; - tv.SetNow(); - before = tv.Secs(); postingFactory->setup(_wordSet); for (size_t i = 0; i < _wordSet.words().size(); ++i) makeSomePostings(postingFactory, @@ -249,11 +239,10 @@ StressMaster::makePostingsHelper(FPFactory *postingFactory, _stride, validate, verbose); - tv.SetNow(); - after = tv.Secs(); + LOG(info, "StressMaster::makePostingsHelper() elapsed %10.6f s for %s format", - after - before, + tv.elapsed().sec(), postingFormat.c_str()); } @@ -323,12 +312,8 @@ StressMaster::run() double StressMaster::runWorkers(const std::string &postingFormat) { - FastOS_Time tv; - double before; - double after; + fastos::StopWatch tv; - tv.SetNow(); - before = tv.Secs(); uint32_t numWorkers = 8; for (uint32_t i = 0; i < numWorkers; ++i) { if (_operatorType == StressRunner::OperatorType::Direct) { @@ -350,15 +335,14 @@ StressMaster::runWorkers(const std::string &postingFormat) _taskCond.wait(taskGuard); } } - tv.SetNow(); - after = tv.Secs(); + LOG(info, "StressMaster::run() elapsed %10.6f s for workers %s format", - after - before, + tv.elapsed().sec(), postingFormat.c_str()); _workers.clear(); _workersDone = 0; - return after - before; + return tv.elapsed().sec(); } StressWorker::StressWorker(StressMaster& master, uint32_t id) diff --git a/searchlib/src/tests/queryeval/sparse_vector_benchmark/sparse_vector_benchmark_test.cpp b/searchlib/src/tests/queryeval/sparse_vector_benchmark/sparse_vector_benchmark_test.cpp index 38d6483f21a..7d2efc5f2bc 100644 --- a/searchlib/src/tests/queryeval/sparse_vector_benchmark/sparse_vector_benchmark_test.cpp +++ b/searchlib/src/tests/queryeval/sparse_vector_benchmark/sparse_vector_benchmark_test.cpp @@ -9,7 +9,6 @@ #include <vespa/searchlib/queryeval/andnotsearch.h> #include <vespa/searchlib/queryeval/andsearch.h> #include <vespa/searchlib/queryeval/dot_product_search.h> -#include <vespa/searchlib/queryeval/fake_search.h> #include <vespa/searchlib/util/rand48.h> #include <vespa/searchlib/queryeval/orsearch.h> #include <vespa/searchlib/queryeval/simpleresult.h> @@ -334,13 +333,12 @@ Result run_single_benchmark(FilterStrategy &filterStrategy, SparseVectorFactory SearchIterator::UP search(filterStrategy.createRoot(vectorFactory, childFactory, childCnt, limit)); SearchIterator &sb = *search; uint32_t num_hits = 0; - FastOS_Time timer; - timer.SetNow(); + fastos::StopWatch timer; for (sb.seek(1); !sb.isAtEnd(); sb.seek(sb.getDocId() + 1)) { ++num_hits; sb.unpack(sb.getDocId()); } - return Result(timer.MilliSecsToNow(), num_hits); + return Result(timer.elapsed().ms(), num_hits); } //----------------------------------------------------------------------------- diff --git a/searchlib/src/tests/queryeval/weak_and/wand_bench_setup.hpp b/searchlib/src/tests/queryeval/weak_and/wand_bench_setup.hpp index 42df9fb0091..65890f81e16 100644 --- a/searchlib/src/tests/queryeval/weak_and/wand_bench_setup.hpp +++ b/searchlib/src/tests/queryeval/weak_and/wand_bench_setup.hpp @@ -195,13 +195,12 @@ struct Setup { void perform() { SearchIterator::UP search = create(); SearchIterator &sb = *search; - FastOS_Time timer; - timer.SetNow(); + fastos::StopWatch timer; for (sb.seek(1); !sb.isAtEnd(); sb.seek(sb.getDocId() + 1)) { stats.hit(); sb.unpack(sb.getDocId()); } - double ms = timer.MilliSecsToNow(); + double ms = timer.elapsed().ms(); if (ms < minTimeMs) { minTimeMs = ms; } diff --git a/searchlib/src/tests/sortspec/multilevelsort.cpp b/searchlib/src/tests/sortspec/multilevelsort.cpp index 65c4cd7da95..640e6f45e80 100644 --- a/searchlib/src/tests/sortspec/multilevelsort.cpp +++ b/searchlib/src/tests/sortspec/multilevelsort.cpp @@ -263,10 +263,9 @@ MultilevelSortTest::sortAndCheck(const std::vector<Spec> &spec, uint32_t num, } } - FastOS_Time timer; - timer.SetNow(); + fastos::StopWatch timer; sorter.sortResults(hits, num, num); - LOG(info, "sort time = %f ms", timer.MilliSecsToNow()); + LOG(info, "sort time = %ld ms", timer.elapsed().ms()); uint32_t *offsets = new uint32_t[num + 1]; char *buf = new char[sorter.getSortDataSize(0, num)]; diff --git a/searchlib/src/tests/transactionlogstress/translogstress.cpp b/searchlib/src/tests/transactionlogstress/translogstress.cpp index 095cc29984b..a047c5e1657 100644 --- a/searchlib/src/tests/transactionlogstress/translogstress.cpp +++ b/searchlib/src/tests/transactionlogstress/translogstress.cpp @@ -7,7 +7,7 @@ #include <vespa/searchlib/util/runnable.h> #include <vespa/searchlib/index/dummyfileheadercontext.h> #include <vespa/fastos/app.h> -#include <vespa/fastos/time.h> +#include <vespa/fastos/timestamp.h> #include <iostream> #include <stdexcept> #include <sstream> @@ -199,7 +199,7 @@ private: Packet _packet; SerialNum _current; SerialNum _lastCommited; - FastOS_Time _timer; + fastos::StopWatch _timer; void commitPacket(); bool addEntry(const Packet::Entry & e); @@ -208,7 +208,7 @@ public: FeederThread(const std::string & tlsSpec, const std::string & domain, const EntryGenerator & generator, uint32_t feedRate, size_t packetSize); ~FeederThread(); - virtual void doRun() override; + void doRun() override; SerialNumRange getRange() const { return SerialNumRange(1, _lastCommited); } }; @@ -217,7 +217,7 @@ FeederThread::FeederThread(const std::string & tlsSpec, const std::string & doma : _tlsSpec(tlsSpec), _domain(domain), _client(tlsSpec), _session(), _generator(generator), _feedRate(feedRate), _packet(packetSize), _current(1), _lastCommited(1), _timer() {} -FeederThread::~FeederThread() {} +FeederThread::~FeederThread() = default; void FeederThread::commitPacket() @@ -251,7 +251,7 @@ FeederThread::doRun() while (!_done) { if (_feedRate != 0) { - _timer.SetNow(); + _timer.restart(); for (uint32_t i = 0; i < _feedRate; ++i) { Packet::Entry entry = _generator.getRandomEntry(_current++); if (!addEntry(entry)) { @@ -264,7 +264,7 @@ FeederThread::doRun() } commitPacket(); - uint64_t milliSecsUsed = static_cast<uint64_t>(_timer.MilliSecsToNow()); + int64_t milliSecsUsed = _timer.elapsed().ms(); if (milliSecsUsed < 1000) { //LOG(info, "FeederThread: sleep %u ms", 1000 - milliSecsUsed); FastOS_Thread::Sleep(1000 - milliSecsUsed); @@ -395,7 +395,7 @@ VisitorAgent::start(SerialNum from, SerialNum to) _to = to; _next = from + 1; _visitor = _client.createVisitor(_domain, *this); - if (_visitor.get() == NULL) { + if ( ! _visitor) { throw std::runtime_error(vespalib::make_string ("VisitorAgent[%u]: Could not open visitor to %s", _id, _tlsSpec.c_str())); } @@ -458,8 +458,8 @@ private: std::vector<std::shared_ptr<VisitorAgent> > _visitors; std::vector<std::shared_ptr<VisitorAgent> > _rndVisitors; uint64_t _visitorInterval; // in milliseconds - uint64_t _pruneInterval; // in milliseconds - FastOS_Time _pruneTimer; + int64_t _pruneInterval; // in milliseconds + fastos::StopWatch _pruneTimer; SerialNum _begin; SerialNum _end; size_t _count; @@ -518,7 +518,7 @@ ControllerThread::doRun() throw std::runtime_error(vespalib::make_string("ControllerThread: Could not open session to %s", _tlsSpec.c_str())); } - _pruneTimer.SetNow(); + _pruneTimer.restart(); while (!_done) { // set finished visitors as idle for (size_t i = 0; i < _visitors.size(); ++i) { @@ -538,7 +538,7 @@ ControllerThread::doRun() } } // prune transaction log server - if (_pruneTimer.MilliSecsToNow() > _pruneInterval) { + if (_pruneTimer.elapsed().ms() > _pruneInterval) { getStatus(); SerialNum safePrune = _end; for (size_t i = 0; i < _visitors.size(); ++i) { @@ -551,7 +551,7 @@ ControllerThread::doRun() if (!_session->erase(safePrune)) { throw std::runtime_error(vespalib::make_string("ControllerThread: Could not erase up to %" PRIu64, safePrune)); } - _pruneTimer.SetNow(); + _pruneTimer.restart(); } FastOS_Thread::Sleep(_visitorInterval); } diff --git a/searchlib/src/vespa/searchlib/attribute/attributevector.h b/searchlib/src/vespa/searchlib/attribute/attributevector.h index 99fd5a88e48..39423ef74c4 100644 --- a/searchlib/src/vespa/searchlib/attribute/attributevector.h +++ b/searchlib/src/vespa/searchlib/attribute/attributevector.h @@ -20,7 +20,7 @@ #include <vespa/vespalib/stllike/asciistream.h> #include <vespa/vespalib/util/address_space.h> #include <vespa/vespalib/util/rcuvector.h> -#include <vespa/fastos/time.h> +#include <vespa/fastos/timestamp.h> #include <cmath> #include <mutex> #include <shared_mutex> diff --git a/searchlib/src/vespa/searchlib/features/random_normal_stable_feature.cpp b/searchlib/src/vespa/searchlib/features/random_normal_stable_feature.cpp index 5e93173abac..bde0cedaed0 100644 --- a/searchlib/src/vespa/searchlib/features/random_normal_stable_feature.cpp +++ b/searchlib/src/vespa/searchlib/features/random_normal_stable_feature.cpp @@ -3,7 +3,6 @@ #include "random_normal_stable_feature.h" #include "utils.h" #include <vespa/searchlib/fef/properties.h> -#include <vespa/fastos/time.h> #include <vespa/log/log.h> LOG_SETUP(".features.randomnormalstablefeature"); diff --git a/searchlib/src/vespa/searchlib/test/fakedata/fakewordset.cpp b/searchlib/src/vespa/searchlib/test/fakedata/fakewordset.cpp index 1be2ea65796..1eec8261bf8 100644 --- a/searchlib/src/vespa/searchlib/test/fakedata/fakewordset.cpp +++ b/searchlib/src/vespa/searchlib/test/fakedata/fakewordset.cpp @@ -2,7 +2,7 @@ #include "fakewordset.h" #include "fakeword.h" -#include <vespa/fastos/time.h> +#include <vespa/fastos/timestamp.h> #include <vespa/searchlib/bitcompression/posocc_fields_params.h> #include <sstream> @@ -96,15 +96,11 @@ FakeWordSet::setupWords(search::Rand48 &rnd, std::string common = "common"; std::string medium = "medium"; std::string rare = "rare"; - FastOS_Time tv; - double before; - double after; - _numDocs = numDocs; LOG(info, "enter setupWords"); - tv.SetNow(); - before = tv.Secs(); + fastos::StopWatch tv; + uint32_t packedIndex = _fieldsParams.size() - 1; for (uint32_t i = 0; i < numWordsPerWordClass; ++i) { std::ostringstream vi; @@ -125,9 +121,8 @@ FakeWordSet::setupWords(search::Rand48 &rnd, _fieldsParams[packedIndex], packedIndex)); } - tv.SetNow(); - after = tv.Secs(); - LOG(info, "leave setupWords, elapsed %10.6f s", after - before); + + LOG(info, "leave setupWords, elapsed %10.6f s", tv.elapsed().sec()); } int diff --git a/slobrok/src/vespa/slobrok/cfg.cpp b/slobrok/src/vespa/slobrok/cfg.cpp index a1f165fa7ea..03b2b12803e 100644 --- a/slobrok/src/vespa/slobrok/cfg.cpp +++ b/slobrok/src/vespa/slobrok/cfg.cpp @@ -21,7 +21,7 @@ extract(const cloud::config::SlobroksConfig &cfg) bool Configurator::poll() { - bool retval = _subscriber.nextGeneration(0); + bool retval = _subscriber.nextGenerationNow(); if (retval) { std::unique_ptr<cloud::config::SlobroksConfig> cfg = _handle->getConfig(); _target.setup(extract(*cfg)); @@ -58,8 +58,7 @@ ConfiguratorFactory::ConfiguratorFactory(const std::vector<std::string> & spec) Configurator::UP ConfiguratorFactory::create(Configurable& target) const { - Configurator::UP r(new Configurator(target, _uri)); - return r; + return std::make_unique<Configurator>(target, _uri); } } // namespace slobrok diff --git a/storageserver/src/apps/storaged/storage.cpp b/storageserver/src/apps/storaged/storage.cpp index b1eafcbad93..0748cc3cb1e 100644 --- a/storageserver/src/apps/storaged/storage.cpp +++ b/storageserver/src/apps/storaged/storage.cpp @@ -11,21 +11,21 @@ * application, but as little as possible else. */ -#include <csignal> +#include "forcelink.h" #include <vespa/persistence/spi/exceptions.h> -#include <vespa/storage/storageutil/utils.h> #include <vespa/storageserver/app/distributorprocess.h> -#include "forcelink.h" #include <vespa/storageserver/app/dummyservicelayerprocess.h> #include <vespa/vespalib/util/programoptions.h> #include <vespa/vespalib/util/shutdownguard.h> -#include <iostream> #include <vespa/config/helper/configgetter.hpp> #include <vespa/fastos/app.h> +#include <iostream> +#include <csignal> #include <vespa/log/log.h> LOG_SETUP("vds.application"); +using namespace std::chrono_literals; namespace storage { namespace { @@ -39,7 +39,7 @@ Process::UP createProcess(vespalib::stringref configId) { } else switch (serverConfig->persistenceProvider.type) { case vespa::config::content::core::StorServerConfig::PersistenceProvider::Type::STORAGE: case vespa::config::content::core::StorServerConfig::PersistenceProvider::Type::DUMMY: - return Process::UP(new DummyServiceLayerProcess(configId)); + return std::make_unique<DummyServiceLayerProcess>(configId); default: throw vespalib::IllegalStateException("Unknown persistence provider.", VESPA_STRLOC); } @@ -59,7 +59,7 @@ class StorageApp : public FastOS_Application, public: StorageApp(); - ~StorageApp(); + ~StorageApp() override; void handleSignal(int signal) { LOG(info, "Got signal %d, waiting for lock", signal); @@ -96,7 +96,7 @@ StorageApp::StorageApp() "abruptly killing the process."); } -StorageApp::~StorageApp() {} +StorageApp::~StorageApp() = default; bool StorageApp::Init() { @@ -118,13 +118,13 @@ bool StorageApp::Init() } namespace { - storage::StorageApp *sigtramp = 0; + storage::StorageApp *sigtramp = nullptr; uint32_t _G_signalCount = 0; void killHandler(int sig) { if (_G_signalCount == 0) { _G_signalCount++; - if (sigtramp == 0) _exit(EXIT_FAILURE); + if (sigtramp == nullptr) _exit(EXIT_FAILURE); // note: this is not totally safe, sigtramp is not protected by a lock sigtramp->handleSignal(sig); } else if (_G_signalCount > 2) { @@ -143,8 +143,8 @@ namespace { usr_action.sa_handler = killHandler; usr_action.sa_mask = block_mask; usr_action.sa_flags = 0; - sigaction (SIGTERM, &usr_action, NULL); - sigaction (SIGINT, &usr_action, NULL); + sigaction (SIGTERM, &usr_action, nullptr); + sigaction (SIGINT, &usr_action, nullptr); } } @@ -162,7 +162,7 @@ int StorageApp::Main() { try{ _process = createProcess(_configId); - _process->setupConfig(600000); + _process->setupConfig(600000ms); _process->createNode(); } catch (const spi::HandledException & e) { LOG(warning, "Died due to known cause: %s", e.what()); @@ -192,7 +192,7 @@ int StorageApp::Main() } // Wait until we get a kill signal. vespalib::MonitorGuard lock(_signalLock); - lock.wait(1000); + lock.wait(1000ms); handleSignals(); } LOG(debug, "Server was attempted stopped, shutting down"); @@ -200,7 +200,7 @@ int StorageApp::Main() // time than given timeout. vespalib::ShutdownGuard shutdownGuard(_maxShutdownTime); LOG(debug, "Attempting proper shutdown"); - _process.reset(0); + _process.reset(); LOG(debug, "Completed controlled shutdown."); return 0; } @@ -212,7 +212,7 @@ int main(int argc, char **argv) storage::StorageApp app; storage::sigtramp = &app; int retval = app.Entry(argc,argv); - storage::sigtramp = NULL; + storage::sigtramp = nullptr; LOG(debug, "Exiting"); return retval; } diff --git a/storageserver/src/tests/storageservertest.cpp b/storageserver/src/tests/storageservertest.cpp index 5e50fff8f94..2f165c69470 100644 --- a/storageserver/src/tests/storageservertest.cpp +++ b/storageserver/src/tests/storageservertest.cpp @@ -11,6 +11,8 @@ LOG_SETUP(".storageservertest"); +using namespace std::chrono_literals; + namespace storage { struct StorageServerTest : public ::testing::Test { @@ -61,7 +63,7 @@ struct Storage : public Node { Distributor::Distributor(vdstestlib::DirConfig& config) : _process(config.getConfigId()) { - _process.setupConfig(60000); + _process.setupConfig(60000ms); _process.createNode(); } @@ -70,7 +72,7 @@ Distributor::~Distributor() = default; Storage::Storage(vdstestlib::DirConfig& config) : _process(config.getConfigId()) { - _process.setupConfig(60000); + _process.setupConfig(60000ms); _process.createNode(); _component.reset(new StorageComponent( getContext().getComponentRegister(), "test")); diff --git a/storageserver/src/vespa/storageserver/app/distributorprocess.cpp b/storageserver/src/vespa/storageserver/app/distributorprocess.cpp index ff4b2e98cca..938ca63b50f 100644 --- a/storageserver/src/vespa/storageserver/app/distributorprocess.cpp +++ b/storageserver/src/vespa/storageserver/app/distributorprocess.cpp @@ -28,7 +28,7 @@ DistributorProcess::shutdown() } void -DistributorProcess::setupConfig(uint64_t subscribeTimeout) +DistributorProcess::setupConfig(milliseconds subscribeTimeout) { using vespa::config::content::core::StorServerConfig; using vespa::config::content::core::StorDistributormanagerConfig; @@ -39,13 +39,10 @@ DistributorProcess::setupConfig(uint64_t subscribeTimeout) if (stor_config->persistenceProvider.type != StorServerConfig::PersistenceProvider::Type::STORAGE) { _activeFlag = DistributorNode::NEED_ACTIVE_BUCKET_STATES_SET; } - auto dist_config = config::ConfigGetter<StorDistributormanagerConfig>::getConfig( - _configUri.getConfigId(), _configUri.getContext(), subscribeTimeout); + auto dist_config = config::ConfigGetter<StorDistributormanagerConfig>::getConfig(_configUri.getConfigId(), _configUri.getContext(), subscribeTimeout); _use_btree_database = dist_config->useBtreeDatabase; - _distributorConfigHandler - = _configSubscriber.subscribe<StorDistributormanagerConfig>(_configUri.getConfigId(), subscribeTimeout); - _visitDispatcherConfigHandler - = _configSubscriber.subscribe<StorVisitordispatcherConfig>(_configUri.getConfigId(), subscribeTimeout); + _distributorConfigHandler = _configSubscriber.subscribe<StorDistributormanagerConfig>(_configUri.getConfigId(), subscribeTimeout); + _visitDispatcherConfigHandler = _configSubscriber.subscribe<StorVisitordispatcherConfig>(_configUri.getConfigId(), subscribeTimeout); Process::setupConfig(subscribeTimeout); } diff --git a/storageserver/src/vespa/storageserver/app/distributorprocess.h b/storageserver/src/vespa/storageserver/app/distributorprocess.h index 57193f77e42..48fa331ba54 100644 --- a/storageserver/src/vespa/storageserver/app/distributorprocess.h +++ b/storageserver/src/vespa/storageserver/app/distributorprocess.h @@ -27,7 +27,7 @@ public: ~DistributorProcess() override; void shutdown() override; - void setupConfig(uint64_t subscribeTimeout) override; + void setupConfig(milliseconds subscribeTimeout) override; void createNode() override; bool configUpdated() override; void updateConfig() override; diff --git a/storageserver/src/vespa/storageserver/app/process.cpp b/storageserver/src/vespa/storageserver/app/process.cpp index 0ebce27eebb..df5e8f4a10e 100644 --- a/storageserver/src/vespa/storageserver/app/process.cpp +++ b/storageserver/src/vespa/storageserver/app/process.cpp @@ -19,7 +19,7 @@ Process::Process(const config::ConfigUri & configUri) { } void -Process::setupConfig(uint64_t subscribeTimeout) +Process::setupConfig(milliseconds subscribeTimeout) { _documentHandler = _configSubscriber.subscribe<document::DocumenttypesConfig>(_configUri.getConfigId(), subscribeTimeout); if (!_configSubscriber.nextConfig()) { @@ -32,7 +32,7 @@ Process::setupConfig(uint64_t subscribeTimeout) bool Process::configUpdated() { - _configSubscriber.nextGeneration(0); + _configSubscriber.nextGenerationNow(); if (_documentHandler->isChanged()) { LOG(info, "Document config detected changed"); return true; diff --git a/storageserver/src/vespa/storageserver/app/process.h b/storageserver/src/vespa/storageserver/app/process.h index e8f7fd62ccf..a5c5b656677 100644 --- a/storageserver/src/vespa/storageserver/app/process.h +++ b/storageserver/src/vespa/storageserver/app/process.h @@ -38,12 +38,13 @@ private: std::vector<DocumentTypeRepoSP> _repos; public: - typedef std::unique_ptr<Process> UP; + using UP = std::unique_ptr<Process>; + using milliseconds = std::chrono::milliseconds; Process(const config::ConfigUri & configUri); virtual ~Process() {} - virtual void setupConfig(uint64_t subscribeTimeout); + virtual void setupConfig(milliseconds subscribeTimeout); virtual void createNode() = 0; virtual bool configUpdated(); virtual void updateConfig(); @@ -54,7 +55,7 @@ public: virtual StorageNode& getNode() = 0; virtual StorageNodeContext& getContext() = 0; - virtual int64_t getGeneration() const override; + int64_t getGeneration() const override; }; } // storage diff --git a/vespalib/src/tests/executor/stress_test.cpp b/vespalib/src/tests/executor/stress_test.cpp index 702991fd779..bbe754be2bd 100644 --- a/vespalib/src/tests/executor/stress_test.cpp +++ b/vespalib/src/tests/executor/stress_test.cpp @@ -4,7 +4,7 @@ #include <vespa/vespalib/util/executor.h> #include <vespa/vespalib/util/threadstackexecutor.h> #include <vespa/vespalib/locale/c.h> -#include <vespa/fastos/time.h> +#include <vespa/fastos/timestamp.h> using namespace vespalib; using namespace std::literals; @@ -60,29 +60,28 @@ uint32_t Test::calibrate(double wanted_ms) { uint32_t n = 0; - FastOS_Time t0; - FastOS_Time t1; + fastos::StopWatch t0; + fastos::StopWatch t1; { // calibration of calibration loop uint32_t result = 0; - t0.SetNow(); double ms; do { result += doStuff(++n); - t1.SetNow(); - ms = (t1.MilliSecs() - t0.MilliSecs()); + t1.restart(); + ms = (t1.elapsed().ms() - t0.elapsed().ms()); } while (ms < 1000.0); _result += result; } { // calibrate loop - t0.SetNow(); + t0.restart(); uint32_t result = 0; for (uint32_t i = 0; i < n; ++i) { result += doStuff(i); } _result += result; - t1.SetNow(); + t1.restart(); } - double ms = (t1.MilliSecs() - t0.MilliSecs()); + double ms = (t1.elapsed().ms() - t0.elapsed().ms()); double size = (((double)n) / ms) * wanted_ms; return (uint32_t) std::round(size); } @@ -122,22 +121,19 @@ Test::Main() fprintf(stderr, "all threads have been accounted for...\n"); } { - FastOS_Time t0; - FastOS_Time t1; + fastos::StopWatch t0; fprintf(stderr, "starting task submission...\n"); - t0.SetNow(); uint32_t result = 0; for (uint32_t i = 0; i < tasks; ++i) { Executor::Task::UP t(new CPUTask(taskSize, result)); t = executor.execute(std::move(t)); - while (t.get() != 0) { + while (t) { std::this_thread::sleep_for(10ms); t = executor.execute(std::move(t)); } } executor.sync(); - t1.SetNow(); - double ms = (t1.MilliSecs() - t0.MilliSecs()); + double ms = t0.elapsed().ms(); fprintf(stderr, "total execution wall time: %g ms\n", ms); _result += result; } diff --git a/vespalib/src/tests/left_right_heap/left_right_heap_bench.cpp b/vespalib/src/tests/left_right_heap/left_right_heap_bench.cpp index e6fdab7d773..c43d0ec1c29 100644 --- a/vespalib/src/tests/left_right_heap/left_right_heap_bench.cpp +++ b/vespalib/src/tests/left_right_heap/left_right_heap_bench.cpp @@ -3,7 +3,7 @@ #include <vespa/vespalib/util/left_right_heap.h> #include <vespa/vespalib/util/stringfmt.h> #include <vespa/vespalib/util/inline.h> -#include <vespa/fastos/time.h> +#include <vespa/fastos/timestamp.h> using namespace vespalib; @@ -36,11 +36,11 @@ struct MyInvCmp { struct Timer { double minTime; - FastOS_Time timer; + fastos::StopWatch timer; Timer() : minTime(1.0e10), timer() {} - void start() { timer.SetNow(); } + void start() { timer.restart(); } void stop() { - double ms = timer.MilliSecsToNow(); + double ms = timer.elapsed().ms(); minTime = std::min(minTime, ms); } }; diff --git a/vespalib/src/tests/simple_thread_bundle/threading_speed_test.cpp b/vespalib/src/tests/simple_thread_bundle/threading_speed_test.cpp index b113e7a2284..5b6df6eef4e 100644 --- a/vespalib/src/tests/simple_thread_bundle/threading_speed_test.cpp +++ b/vespalib/src/tests/simple_thread_bundle/threading_speed_test.cpp @@ -2,7 +2,7 @@ #include <vespa/vespalib/testkit/test_kit.h> #include <vespa/vespalib/util/simple_thread_bundle.h> #include <vespa/vespalib/util/box.h> -#include <vespa/fastos/time.h> +#include <vespa/fastos/timestamp.h> using namespace vespalib; @@ -57,12 +57,11 @@ TEST("estimate cost of thread bundle fork/join") { } double minTime = 1000000.0; for (size_t samples = 0; samples < 32; ++samples) { - FastOS_Time t; - t.SetNow(); + fastos::StopWatch timer; for (size_t n = 0; n < fork; ++n) { threadBundle.run(targets); } - double time = t.MilliSecsToNow(); + double time = timer.elapsed().ms(); if (time < minTime) { minTime = time; } diff --git a/vespalib/src/tests/slime/summary-feature-benchmark/summary-feature-benchmark.cpp b/vespalib/src/tests/slime/summary-feature-benchmark/summary-feature-benchmark.cpp index 2a58f1df382..61ba2593eb3 100644 --- a/vespalib/src/tests/slime/summary-feature-benchmark/summary-feature-benchmark.cpp +++ b/vespalib/src/tests/slime/summary-feature-benchmark/summary-feature-benchmark.cpp @@ -2,7 +2,7 @@ #include <vespa/vespalib/testkit/test_kit.h> #include <vespa/vespalib/util/stringfmt.h> #include <vespa/vespalib/data/slime/slime.h> -#include <vespa/fastos/time.h> +#include <vespa/fastos/timestamp.h> using namespace vespalib; using namespace vespalib::slime::convenience; @@ -22,7 +22,7 @@ struct MyBuffer : public Output { } }; -MyBuffer::~MyBuffer() { } +MyBuffer::~MyBuffer() = default; std::string make_name(size_t idx) { return make_string("summary_feature_%zu", idx); @@ -47,13 +47,12 @@ TEST_F("slime -> json speed", FeatureFixture()) { double minTime = 1000000.0; MyBuffer buffer; for (size_t i = 0; i < 16; ++i) { - FastOS_Time timer; - timer.SetNow(); + fastos::StopWatch timer; for (size_t j = 0; j < 256; ++j) { buffer.used = 0; slime::JsonFormat::encode(f1.slime, buffer, true); } - minTime = std::min(minTime, timer.MilliSecsToNow() / 256.0); + minTime = std::min(minTime, timer.elapsed().ms() / 256.0); size = buffer.used; } fprintf(stderr, "time: %g ms (size: %zu bytes)\n", minTime, size); @@ -64,13 +63,12 @@ TEST_F("slime -> binary speed", FeatureFixture()) { double minTime = 1000000.0; MyBuffer buffer; for (size_t i = 0; i < 16; ++i) { - FastOS_Time timer; - timer.SetNow(); + fastos::StopWatch timer; for (size_t j = 0; j < 256; ++j) { buffer.used = 0; slime::BinaryFormat::encode(f1.slime, buffer); } - minTime = std::min(minTime, timer.MilliSecsToNow() / 256.0); + minTime = std::min(minTime, timer.elapsed().ms() / 256.0); size = buffer.used; } fprintf(stderr, "time: %g ms (size: %zu bytes)\n", minTime, size); diff --git a/vespalog/src/test/threads/testthreads.cpp b/vespalog/src/test/threads/testthreads.cpp index 802514285b6..d23e00930fd 100644 --- a/vespalog/src/test/threads/testthreads.cpp +++ b/vespalog/src/test/threads/testthreads.cpp @@ -1,6 +1,6 @@ // Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. #include <vespa/fastos/app.h> -#include <vespa/fastos/time.h> +#include <vespa/fastos/timestamp.h> #include <vespa/fastos/thread.h> #include <vespa/log/bufferedlogger.h> #include <array> @@ -104,11 +104,10 @@ ThreadTester::Main() pool.NewThread(loggers[i].get()); } - FastOS_Time start; - start.SetNow(); + fastos::StopWatch timer; // Reduced runtime to half as the test now repeats itself to test with // buffering. (To avoid test taking a minute) - while (start.MilliSecsToNow() < 15 * 1000) { + while (timer.elapsed().ms() < 15 * 1000) { unlink(_argv[1]); std::this_thread::sleep_for(1ms); } @@ -116,8 +115,8 @@ ThreadTester::Main() for (int i = 0; i < numLoggers; i++) { loggers[i]->_useLogBuffer = true; } - start.SetNow(); - while (start.MilliSecsToNow() < 15 * 1000) { + timer.restart(); + while (timer.elapsed().ms() < 15 * 1000) { unlink(_argv[1]); std::this_thread::sleep_for(1ms); } |