diff options
15 files changed, 41 insertions, 73 deletions
diff --git a/logd/src/logd/watcher.cpp b/logd/src/logd/watcher.cpp index 00cfb4def16..e481d64f721 100644 --- a/logd/src/logd/watcher.cpp +++ b/logd/src/logd/watcher.cpp @@ -6,10 +6,10 @@ #include "watcher.h" #include <vespa/vespalib/util/sig_catch.h> #include <vespa/vespalib/util/time.h> +#include <thread> #include <fcntl.h> #include <glob.h> #include <sys/stat.h> -#include <sys/time.h> #include <unistd.h> #include <vespa/log/log.h> @@ -19,42 +19,14 @@ namespace logdemon { namespace { // wait until 1 second has passed since "start" -void snooze(const struct timeval &start) +void snooze(vespalib::Timer & timer) { - struct timeval sincestart; - gettimeofday(&sincestart, 0); - // compute time elapsed since start: - sincestart.tv_sec -= start.tv_sec; - sincestart.tv_usec -= start.tv_usec; - - // how many microseconds to wait: - long wait_usecs = (1000000 - sincestart.tv_usec); - wait_usecs -= (1000000 * sincestart.tv_sec); - - if (wait_usecs <= 0) { + if (timer.elapsed() > 1000ms) { // already used enough time, no sleep return; } - struct timespec tsp; - tsp.tv_sec = (wait_usecs / 1000000); - tsp.tv_nsec = (wait_usecs % 1000000) * 1000; - - if (nanosleep(&tsp, nullptr) != 0 && errno != EINTR) { - LOG(error, "nanosleep %ld s %ld ns failed: %s", - (long)tsp.tv_sec, (long)tsp.tv_nsec, strerror(errno)); - throw SomethingBad("nanosleep failed"); - } -} - -int elapsed(struct timeval &start) { - struct timeval now; - gettimeofday(&now, 0); - int diffsecs = now.tv_sec - start.tv_sec; - if (now.tv_usec < start.tv_usec) { - --diffsecs; - } - return diffsecs; + std::this_thread::sleep_for(1000ms - timer.elapsed()); } constexpr size_t G_BUFSIZE = 1024*1024; @@ -178,7 +150,7 @@ Watcher::watchfile() vespalib::Timer rotTimer; off_t offset = 0; - while (1) { + while (true) { struct stat sb; if (fstat(_wfd, &sb) != 0) { LOG(error, "fstat(%s) failed: %s", filename, strerror(errno)); @@ -204,8 +176,7 @@ Watcher::watchfile() return; } - struct timeval tickStart; - gettimeofday(&tickStart, 0); + vespalib::Timer timer; if (sb.st_size > offset) { lseek(_wfd, offset, SEEK_SET); @@ -219,7 +190,7 @@ Watcher::watchfile() LOG(error, "no newline in %ld bytes, skipping", static_cast<long>(rsize)); offset += rsize; } - while (nnl != nullptr && elapsed(tickStart) < 1) { + while (nnl != nullptr && (timer.elapsed() < 1000ms)) { ++nnl; _forwarder.forwardLine(std::string_view(l, (nnl - l) - 1)); ssize_t wsize = nnl - l; @@ -272,7 +243,7 @@ Watcher::watchfile() char newfn[FILENAME_MAX]; int l = strlen(filename); strcpy(newfn, filename); - time_t seconds = vespalib::to_s(now.time_since_epoch()); + time_t seconds = vespalib::count_s(now.time_since_epoch()); struct tm *nowtm = gmtime(&seconds); if (strftime(newfn+l, FILENAME_MAX-l-1, "-%Y-%m-%d.%H-%M-%S", nowtm) < 10) { @@ -299,7 +270,7 @@ Watcher::watchfile() if (catcher.receivedStopSignal()) { throw SigTermException("caught signal"); } - snooze(tickStart); + snooze(timer); if (catcher.receivedStopSignal()) { throw SigTermException("caught signal"); } diff --git a/metrics/src/vespa/metrics/metricmanager.cpp b/metrics/src/vespa/metrics/metricmanager.cpp index 41c8b52d731..fd1c0f10d27 100644 --- a/metrics/src/vespa/metrics/metricmanager.cpp +++ b/metrics/src/vespa/metrics/metricmanager.cpp @@ -26,7 +26,7 @@ MetricManager::ConsumerSpec::~ConsumerSpec() = default; time_t MetricManager::Timer::getTime() const { - return vespalib::to_s(vespalib::steady_clock::now().time_since_epoch()); + return vespalib::count_s(vespalib::steady_clock::now().time_since_epoch()); } void @@ -70,9 +70,9 @@ MetricManager::MetricManager(std::unique_ptr<Timer> timer) _consumerConfig(), _logPeriod(5 * 60, 0), _snapshots(), - _totalMetrics(MetricSnapshot::SP(new MetricSnapshot( + _totalMetrics(std::make_shared<MetricSnapshot>( "Empty metrics before init", 0, _activeMetrics.getMetrics(), - false))), + false)), _timer(std::move(timer)), _lastProcessedTime(0), _forceEventLogging(false), diff --git a/metrics/src/vespa/metrics/state_api_adapter.cpp b/metrics/src/vespa/metrics/state_api_adapter.cpp index 6abc4336446..ec5705eed91 100644 --- a/metrics/src/vespa/metrics/state_api_adapter.cpp +++ b/metrics/src/vespa/metrics/state_api_adapter.cpp @@ -29,7 +29,7 @@ StateApiAdapter::getTotalMetrics(const vespalib::string &consumer) _manager.updateMetrics(true); metrics::MetricLockGuard guard(_manager.getMetricLock()); _manager.checkMetricsAltered(guard); - time_t currentTime = vespalib::to_s(vespalib::steady_clock::now().time_since_epoch()); + time_t currentTime = vespalib::count_s(vespalib::steady_clock::now().time_since_epoch()); auto generated = std::make_unique<metrics::MetricSnapshot>( "Total metrics from start until current time", 0, _manager.getTotalMetricSnapshot(guard).getMetrics(), diff --git a/searchcore/src/vespa/searchcore/proton/docsummary/summarymanagerinitializer.cpp b/searchcore/src/vespa/searchcore/proton/docsummary/summarymanagerinitializer.cpp index 415d13314a2..2f29231577a 100644 --- a/searchcore/src/vespa/searchcore/proton/docsummary/summarymanagerinitializer.cpp +++ b/searchcore/src/vespa/searchcore/proton/docsummary/summarymanagerinitializer.cpp @@ -28,8 +28,8 @@ SummaryManagerInitializer(const search::GrowStrategy &grow, _tuneFile(tuneFile), _fileHeaderContext(fileHeaderContext), _tlSyncer(tlSyncer), - _bucketizer(bucketizer), - _result(result) + _bucketizer(std::move(bucketizer)), + _result(std::move(result)) { } SummaryManagerInitializer::~SummaryManagerInitializer() = default; diff --git a/searchcore/src/vespa/searchcore/proton/matching/queryenvironment.cpp b/searchcore/src/vespa/searchcore/proton/matching/queryenvironment.cpp index ec48ee7164b..fe0f6aaff91 100644 --- a/searchcore/src/vespa/searchcore/proton/matching/queryenvironment.cpp +++ b/searchcore/src/vespa/searchcore/proton/matching/queryenvironment.cpp @@ -39,7 +39,7 @@ const search::fef::ITermData * QueryEnvironment::getTerm(uint32_t idx) const { if (idx >= _terms.size()) { - return 0; + return nullptr; } return _terms[idx]; } diff --git a/searchcore/src/vespa/searchcore/proton/matching/queryenvironment.h b/searchcore/src/vespa/searchcore/proton/matching/queryenvironment.h index 8f958870d52..575694ae079 100644 --- a/searchcore/src/vespa/searchcore/proton/matching/queryenvironment.h +++ b/searchcore/src/vespa/searchcore/proton/matching/queryenvironment.h @@ -80,7 +80,7 @@ public: // inherited from search::fef::IQueryEnvironment const search::fef::IIndexEnvironment & getIndexEnvironment() const override; - ~QueryEnvironment(); + ~QueryEnvironment() override; }; } diff --git a/searchcore/src/vespa/searchcore/proton/server/searchabledocsubdb.cpp b/searchcore/src/vespa/searchcore/proton/server/searchabledocsubdb.cpp index fc21621bee3..77852dcc918 100644 --- a/searchcore/src/vespa/searchcore/proton/server/searchabledocsubdb.cpp +++ b/searchcore/src/vespa/searchcore/proton/server/searchabledocsubdb.cpp @@ -13,13 +13,10 @@ #include <vespa/searchcore/proton/matching/sessionmanager.h> #include <vespa/searchcore/proton/reference/document_db_reference.h> #include <vespa/searchcore/proton/reference/gid_to_lid_change_handler.h> -#include <vespa/searchcorespi/plugin/iindexmanagerfactory.h> #include <vespa/searchlib/fef/indexproperties.h> #include <vespa/searchlib/fef/properties.h> -#include <vespa/vespalib/io/fileutil.h> #include <vespa/vespalib/util/closuretask.h> #include <vespa/eval/tensor/default_tensor_engine.h> -#include <vespa/vespalib/util/exceptions.h> using vespa::config::search::RankProfilesConfig; using proton::matching::MatchingStats; @@ -30,7 +27,6 @@ using search::GrowStrategy; using search::TuneFileDocumentDB; using search::index::Schema; using search::SerialNum; -using vespalib::IllegalStateException; using vespalib::ThreadStackExecutorBase; using namespace searchcorespi; @@ -320,7 +316,7 @@ SearchableDocSubDB::getSearchableStats() const IDocumentRetriever::UP SearchableDocSubDB::getDocumentRetriever() { - return IDocumentRetriever::UP(new FastAccessDocumentRetriever(_rFeedView.get(), _rSearchView.get()->getAttributeManager())); + return std::make_unique<FastAccessDocumentRetriever>(_rFeedView.get(), _rSearchView.get()->getAttributeManager()); } MatchingStats diff --git a/searchcore/src/vespa/searchcore/proton/server/storeonlydocsubdb.cpp b/searchcore/src/vespa/searchcore/proton/server/storeonlydocsubdb.cpp index 954f7f3c7f7..646346d53ad 100644 --- a/searchcore/src/vespa/searchcore/proton/server/storeonlydocsubdb.cpp +++ b/searchcore/src/vespa/searchcore/proton/server/storeonlydocsubdb.cpp @@ -18,7 +18,6 @@ #include <vespa/searchcore/proton/flushengine/threadedflushtarget.h> #include <vespa/searchcore/proton/index/index_writer.h> #include <vespa/searchcore/proton/matching/sessionmanager.h> -#include <vespa/searchcore/proton/metrics/metricswireservice.h> #include <vespa/searchcore/proton/reference/dummy_gid_to_lid_change_handler.h> #include <vespa/searchlib/attribute/configconverter.h> #include <vespa/searchlib/docstore/document_store_visitor_progress.h> @@ -86,7 +85,7 @@ StoreOnlyDocSubDB::Context::Context(IDocumentSubDBOwner &owner, _getSerialNum(getSerialNum), _fileHeaderContext(fileHeaderContext), _writeService(writeService), - _bucketDB(bucketDB), + _bucketDB(std::move(bucketDB)), _bucketDBHandlerInitializer(bucketDBHandlerInitializer), _metrics(metrics), _configMutex(configMutex), @@ -231,13 +230,13 @@ createSummaryManagerInitializer(const search::LogDocumentStore::Config & storeCf vespalib::string baseDir(_baseDir + "/summary"); return std::make_shared<SummaryManagerInitializer> (grow, baseDir, getSubDbName(), _docTypeName, _writeService.shared(), - storeCfg, tuneFile, _fileHeaderContext, _tlSyncer, bucketizer, result); + storeCfg, tuneFile, _fileHeaderContext, _tlSyncer, std::move(bucketizer), std::move(result)); } void StoreOnlyDocSubDB::setupSummaryManager(SummaryManager::SP summaryManager) { - _rSummaryMgr = summaryManager; + _rSummaryMgr = std::move(summaryManager); _iSummaryMgr = _rSummaryMgr; // Upcast allowed with std::shared_ptr _flushedDocumentStoreSerialNum = _iSummaryMgr->getBackingStore().lastSyncToken(); _summaryAdapter.reset(new SummaryAdapter(_rSummaryMgr)); @@ -316,7 +315,7 @@ StoreOnlyDocSubDB::setup(const DocumentSubDbInitializerResult &initResult) { setupDocumentMetaStore(initResult.documentMetaStore()); setupSummaryManager(initResult.summaryManager()); - _lidReuseDelayer.reset(new LidReuseDelayer(_writeService, *_dms)); + _lidReuseDelayer = std::make_unique<LidReuseDelayer>(_writeService, *_dms); updateLidReuseDelayer(initResult.lidReuseDelayerConfig()); } @@ -393,7 +392,7 @@ StoreOnlyDocSubDB::updateLidReuseDelayer(const DocumentDBConfig * newConfigSnaps void StoreOnlyDocSubDB::updateLidReuseDelayer(const LidReuseDelayerConfig &config) { - bool immediateCommit = config.visibilityDelay() == vespalib::duration::zero(); + bool immediateCommit = (config.visibilityDelay() == vespalib::duration::zero()); /* * The lid reuse delayer should not have any pending lids stored at this * time, since DocumentDB::applyConfig() calls forceCommit() on the diff --git a/searchlib/src/tests/fef/phrasesplitter/benchmark.cpp b/searchlib/src/tests/fef/phrasesplitter/benchmark.cpp index 8b3fc81efb9..419b5261510 100644 --- a/searchlib/src/tests/fef/phrasesplitter/benchmark.cpp +++ b/searchlib/src/tests/fef/phrasesplitter/benchmark.cpp @@ -73,7 +73,7 @@ Benchmark::Main() run(numRuns, numPositions); std::cout << "TET: " << vespalib::count_ms(_sample) << " (ms)" << std::endl; - std::cout << "ETPD: " << std::fixed << std::setprecision(10) << vespalib::count_ms(_sample) / numRuns << " (ms)" << std::endl; + std::cout << "ETPD: " << std::fixed << std::setprecision(10) << (vespalib::count_ns(_sample) / (numRuns * 1000000.0)) << " (ms)" << std::endl; TEST_DONE(); } diff --git a/searchlib/src/vespa/searchlib/features/attributematchfeature.cpp b/searchlib/src/vespa/searchlib/features/attributematchfeature.cpp index ff4ca91beb9..4776437a14b 100644 --- a/searchlib/src/vespa/searchlib/features/attributematchfeature.cpp +++ b/searchlib/src/vespa/searchlib/features/attributematchfeature.cpp @@ -30,7 +30,7 @@ bool hasAttribute(const IQueryEnvironment &env, const ITermData &term_data) for (FRA iter(term_data); iter.valid(); iter.next()) { const FieldInfo *info = env.getIndexEnvironment().getField(iter.get().getFieldId()); - if (info != 0 && info->type() == FieldType::ATTRIBUTE) { + if (info != nullptr && info->type() == FieldType::ATTRIBUTE) { return true; } } @@ -38,8 +38,7 @@ bool hasAttribute(const IQueryEnvironment &env, const ITermData &term_data) } } // namespace -namespace search { -namespace features { +namespace search::features { template <typename T> AttributeMatchExecutor<T>::Computer::Computer(const IQueryEnvironment & env, AttributeMatchParams params) : @@ -70,7 +69,7 @@ AttributeMatchExecutor<T>::Computer::Computer(const IQueryEnvironment & env, Att _numAttrTerms++; _totalAttrTermWeight += qt.termData()->getWeight().percent(); const ITermFieldData *field = qt.termData()->lookupField(_params.attrInfo->id()); - if (field != 0) { + if (field != nullptr) { qt.fieldHandle(field->getHandle()); _queryTerms.push_back(qt); } @@ -338,7 +337,7 @@ FeatureExecutor & AttributeMatchBlueprint::createExecutor(const IQueryEnvironment & env, vespalib::Stash &stash) const { const IAttributeVector * attribute = env.getAttributeContext().getAttribute(_params.attrInfo->name()); - if (attribute == NULL) { + if (attribute == nullptr) { LOG(error, "The attribute vector '%s' was not found in the attribute manager.", _params.attrInfo->name().c_str()); std::vector<feature_t> values; values.push_back(0.0); // completeness @@ -368,6 +367,4 @@ AttributeMatchBlueprint::createExecutor(const IQueryEnvironment & env, vespalib: } } - -} // namespace features -} // namespace search +} diff --git a/searchlib/src/vespa/searchlib/features/attributematchfeature.h b/searchlib/src/vespa/searchlib/features/attributematchfeature.h index 2946521c9f0..4566a417e47 100644 --- a/searchlib/src/vespa/searchlib/features/attributematchfeature.h +++ b/searchlib/src/vespa/searchlib/features/attributematchfeature.h @@ -9,7 +9,7 @@ namespace search::features { struct AttributeMatchParams { AttributeMatchParams() : - attrInfo(NULL), attribute(NULL), weightedSet(false), maxWeight(256), fieldCompletenessImportance(0.05f) {} + attrInfo(nullptr), attribute(nullptr), weightedSet(false), maxWeight(256), fieldCompletenessImportance(0.05f) {} const fef::FieldInfo * attrInfo; const attribute::IAttributeVector * attribute; bool weightedSet; diff --git a/searchlib/src/vespa/searchlib/features/queryterm.cpp b/searchlib/src/vespa/searchlib/features/queryterm.cpp index 84423493eb5..a6b1a6a8f2a 100644 --- a/searchlib/src/vespa/searchlib/features/queryterm.cpp +++ b/searchlib/src/vespa/searchlib/features/queryterm.cpp @@ -9,7 +9,7 @@ using search::feature_t; namespace search::features { QueryTerm::QueryTerm() : - _termData(NULL), + _termData(nullptr), _handle(IllegalHandle), _significance(0), _connectedness(0) diff --git a/searchsummary/src/tests/extractkeywords/extractkeywordstest.cpp b/searchsummary/src/tests/extractkeywords/extractkeywordstest.cpp index fcdd910fc17..9b2510ac3df 100644 --- a/searchsummary/src/tests/extractkeywords/extractkeywordstest.cpp +++ b/searchsummary/src/tests/extractkeywords/extractkeywordstest.cpp @@ -109,7 +109,7 @@ ExtractKeywordsTest::Main() } // Print time taken - double timeTaken = vespalib::count_ms(timer.elapsed()); + double timeTaken = vespalib::to_s(timer.elapsed())*1000.0; printf("Time taken : %f ms\n", timeTaken); printf("Number of tests run: %d\n", testCnt); diff --git a/vespalib/src/tests/time/time_test.cpp b/vespalib/src/tests/time/time_test.cpp index 40542b6ca62..352835ea101 100644 --- a/vespalib/src/tests/time/time_test.cpp +++ b/vespalib/src/tests/time/time_test.cpp @@ -40,10 +40,11 @@ TEST(TimeTest, timeval_conversion_works_as_expected) { } TEST(TimeTest, unit_counting_works_as_expected) { - auto d = 3ms + 5us + 7ns; - EXPECT_EQ(count_ns(d), 3005007); - EXPECT_EQ(count_us(d), 3005); - EXPECT_EQ(count_ms(d), 3); + auto d = 7s + 3ms + 5us + 7ns; + EXPECT_EQ(count_ns(d), 7003005007); + EXPECT_EQ(count_us(d), 7003005); + EXPECT_EQ(count_ms(d), 7003); + EXPECT_EQ(count_s(d), 7); } GTEST_MAIN_RUN_ALL_TESTS() diff --git a/vespalib/src/vespa/vespalib/util/time.h b/vespalib/src/vespa/vespalib/util/time.h index f6841c70258..187d62001ae 100644 --- a/vespalib/src/vespa/vespalib/util/time.h +++ b/vespalib/src/vespa/vespalib/util/time.h @@ -46,6 +46,10 @@ constexpr duration from_s(double seconds) { return std::chrono::duration_cast<duration>(std::chrono::duration<double>(seconds)); } +constexpr int64_t count_s(duration d) { + return std::chrono::duration_cast<std::chrono::seconds>(d).count(); +} + constexpr int64_t count_ms(duration d) { return std::chrono::duration_cast<std::chrono::milliseconds>(d).count(); } |