diff options
19 files changed, 92 insertions, 268 deletions
diff --git a/config/src/tests/configfetcher/configfetcher.cpp b/config/src/tests/configfetcher/configfetcher.cpp index 24b943ec626..4a2a9153f52 100644 --- a/config/src/tests/configfetcher/configfetcher.cpp +++ b/config/src/tests/configfetcher/configfetcher.cpp @@ -65,8 +65,8 @@ TEST("requireThatConfigUpdatesArePerformed") { writeFile("test1.cfg", "bar"); cb._configured = false; - fastos::StopWatch timer; - while (!cb._configured && timer.elapsed().ms() < 20000.0) { + vespalib::Timer timer; + while (!cb._configured && timer.elapsed() < 20s) { if (cb._configured) break; std::this_thread::sleep_for(1s); diff --git a/fastos/src/tests/processtest.cpp b/fastos/src/tests/processtest.cpp index 5a78eff1d36..e39b6461a29 100644 --- a/fastos/src/tests/processtest.cpp +++ b/fastos/src/tests/processtest.cpp @@ -1,9 +1,9 @@ // Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. #include "tests.h" #include <vespa/fastos/process.h> -#include <vespa/fastos/timestamp.h> using namespace std::chrono_literals; +using namespace std::chrono; class MyListener : public FastOS_ProcessRedirectListener { @@ -213,7 +213,7 @@ public: if(waitKill) timeOut = 1; - fastos::StopWatch timer; + steady_clock::time_point start = steady_clock::now(); int returnCode; if(!xproc->Wait(&returnCode, timeOut)) @@ -228,11 +228,11 @@ public: } if (waitKill) { - double milliSecs = timer.elapsed().ms(); - if((milliSecs < 900) || - (milliSecs > 3500)) + nanoseconds elapsed = steady_clock::now() - start; + if((elapsed < 900ms) || + (elapsed > 3500ms)) { - Progress(false, "WaitKill time = %d", int(milliSecs)); + Progress(false, "WaitKill time = %d", duration_cast<milliseconds>(elapsed).count()); } } diff --git a/fastos/src/tests/thread_bounce_test.cpp b/fastos/src/tests/thread_bounce_test.cpp index 84506938455..488002341e9 100644 --- a/fastos/src/tests/thread_bounce_test.cpp +++ b/fastos/src/tests/thread_bounce_test.cpp @@ -3,7 +3,8 @@ #include "tests.h" #include "job.h" #include "thread_test_base.hpp" -#include <vespa/fastos/timestamp.h> + +using namespace std::chrono; class Thread_Bounce_Test : public ThreadTestBase { @@ -39,12 +40,12 @@ class Thread_Bounce_Test : public ThreadTestBase lastcntsum = -1; for (int iter = 0; iter < 8; iter++) { - fastos::StopWatch checkTime; + steady_clock::time_point start = steady_clock::now(); - int left = static_cast<int>(checkTime.elapsed().ms()); - while (left < 1000) { - std::this_thread::sleep_for(std::chrono::milliseconds(1000 - left)); - left = static_cast<int>(checkTime.elapsed().ms()); + nanoseconds left = steady_clock::now() - start; + while (left < 1000ms) { + std::this_thread::sleep_for(1000ms - left); + left = steady_clock::now() - start; } mutex1.lock(); diff --git a/fastos/src/tests/threadtest.cpp b/fastos/src/tests/threadtest.cpp index 0a8a0d2bf02..1fa9820c8d7 100644 --- a/fastos/src/tests/threadtest.cpp +++ b/fastos/src/tests/threadtest.cpp @@ -3,13 +3,15 @@ #include "tests.h" #include "job.h" #include "thread_test_base.hpp" -#include <vespa/fastos/timestamp.h> #include <cstdlib> #include <chrono> #define MUTEX_TEST_THREADS 6 #define MAX_THREADS 7 +using namespace std::chrono; +using namespace std::chrono_literals; + class ThreadTest : public ThreadTestBase { int Main () override; @@ -202,7 +204,7 @@ class ThreadTest : public ThreadTestBase Job *jobs = new Job[count]; threadsok = 0; - fastos::StopWatch timer; + steady_clock::time_point start = steady_clock::now(); for (i = 0; i < count; i++) { jobs[i].code = SILENTNOP; jobs[i].ownThread = pool->NewThread(this, &jobs[i]); @@ -225,13 +227,13 @@ class ThreadTest : public ThreadTestBase if (jobs[i].ownThread != nullptr) jobs[i].ownThread->Join(); } - fastos::TimeStamp used = timer.elapsed(); + nanoseconds used = steady_clock::now() - start; if (!silent) { - Progress(true, "Used time: %2.3f", used.sec()); + double timeused = used.count() / 1000000000.0; - double timeused = used.sec(); - ProgressFloat(true, "Threads/s: %6.1f", + Progress(true, "Used time: %2.3f", timeused); + ProgressFloat(true, "Threads/s: %6.1f", static_cast<float>(static_cast<double>(threadsok) / timeused)); } if (threadsok != ((outercount + 1) * count)) @@ -517,12 +519,13 @@ class ThreadTest : public ThreadTestBase std::mutex **mutexes = new std::mutex*[allocCount]; - fastos::StopWatch timer; + steady_clock::time_point start = steady_clock::now(); for (i=0; i<allocCount; i++) mutexes[i] = new std::mutex; - Progress(true, "Allocated %d mutexes at time: %ld ms", allocCount, timer.elapsed().ms()); + nanoseconds elapsed = steady_clock::now() - start; + Progress(true, "Allocated %d mutexes at time: %ld ms", allocCount, duration_cast<milliseconds>(elapsed).count()); for (int e=0; e<4; e++) { for(i=0; i<allocCount; i++) @@ -531,12 +534,14 @@ class ThreadTest : public ThreadTestBase for(i=0; i<allocCount; i++) mutexes[i]->unlock(); - Progress(true, "Tested %d mutexes at time: %d ms", allocCount, timer.elapsed().ms()); + elapsed = steady_clock::now() - start; + Progress(true, "Tested %d mutexes at time: %d ms", allocCount, duration_cast<milliseconds>(elapsed).count()); } for (i=0; i<allocCount; i++) delete mutexes[i]; - Progress(true, "Deleted %d mutexes at time: %d ms", allocCount, timer.elapsed().ms()); + elapsed = steady_clock::now() - start; + Progress(true, "Deleted %d mutexes at time: %d ms", allocCount, duration_cast<milliseconds>(elapsed).count()); delete [] mutexes; diff --git a/fastos/src/vespa/fastos/timestamp.cpp b/fastos/src/vespa/fastos/timestamp.cpp index ef206067900..d8e89dcf99f 100644 --- a/fastos/src/vespa/fastos/timestamp.cpp +++ b/fastos/src/vespa/fastos/timestamp.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 "timestamp.h" #include <cmath> -#include <thread> #include <sys/time.h> using std::chrono::system_clock; @@ -44,39 +43,4 @@ time() { return system_clock::to_time_t(system_clock::now()); } -namespace { - -SteadyTimeStamp -steady_now() { - return SteadyTimeStamp(duration_cast<nanoseconds>(steady_clock::now().time_since_epoch()).count()); -} - -} - -StopWatch::StopWatch() - : _startTime(steady_now()) -{ } - -void -StopWatch::restart() { - _startTime = steady_now(); -} - -TimeStamp -StopWatch::elapsed() const { - return (steady_now() - _startTime); -} - -void -StopWatch::waitAtLeast(std::chrono::microseconds us, bool busyWait) { - if (busyWait) { - steady_clock::time_point deadline = steady_clock::now() + us; - while (steady_clock::now() < deadline) { - for (int i = 0; i < 1000; i++) { } - } - } else { - std::this_thread::sleep_for(us); - } -} - } diff --git a/fastos/src/vespa/fastos/timestamp.h b/fastos/src/vespa/fastos/timestamp.h index 0d23cf7151f..37587f4dc3e 100644 --- a/fastos/src/vespa/fastos/timestamp.h +++ b/fastos/src/vespa/fastos/timestamp.h @@ -16,13 +16,6 @@ public: static const TimeT MICRO = 1000*MILLI; static const TimeT NANO = 1000*MICRO; static const TimeT SEC = NANO; - class Seconds { - public: - explicit Seconds(double v) : _v(v * NANO) {} - TimeT val() const { return _v; } - private: - TimeT _v; - }; TimeStamp() : _time(0) { } TimeStamp(const timeval & tv) : _time(tv.tv_sec*SEC + tv.tv_usec*MILLI) { } TimeStamp(int v) : _time(v) { } @@ -31,7 +24,6 @@ public: TimeStamp(unsigned long v) : _time(v) { } TimeStamp(long long v) : _time(v) { } TimeStamp(unsigned long long v) : _time(v) { } - TimeStamp(Seconds v) : _time(v.val()) { } TimeT val() const { return _time; } operator TimeT () const { return val(); } TimeStamp & operator += (TimeStamp b) { _time += b._time; return *this; } @@ -53,48 +45,6 @@ inline TimeStamp operator -(TimeStamp a, TimeStamp b) { return TimeStamp(a.val() inline TimeStamp operator *(long a, TimeStamp b) { return TimeStamp(a * b.val()); } inline TimeStamp operator *(double a, TimeStamp b) { return TimeStamp(static_cast<int64_t>(a * b.val())); } -class SteadyTimeStamp { -public: - SteadyTimeStamp() : _timeStamp() { } - explicit SteadyTimeStamp(TimeStamp timeStamp) : _timeStamp(timeStamp) { } - - friend TimeStamp operator -(SteadyTimeStamp a, SteadyTimeStamp b) { - return a._timeStamp - b._timeStamp; - } - friend SteadyTimeStamp operator -(SteadyTimeStamp a, TimeStamp b) { - return SteadyTimeStamp(a._timeStamp - b); - } - friend SteadyTimeStamp operator +(SteadyTimeStamp a, TimeStamp b) { - return SteadyTimeStamp(a._timeStamp + b); - } - friend bool operator != (SteadyTimeStamp a, SteadyTimeStamp b) { - return a._timeStamp != b._timeStamp; - } - friend bool operator == (SteadyTimeStamp a, SteadyTimeStamp b) { - return a._timeStamp == b._timeStamp; - } - friend bool operator < (SteadyTimeStamp a, SteadyTimeStamp b) { - return a._timeStamp < b._timeStamp; - } - friend bool operator > (SteadyTimeStamp a, SteadyTimeStamp b) { - return a._timeStamp > b._timeStamp; - } - std::string toString() const { return _timeStamp.toString(); }; -private: - TimeStamp _timeStamp; -}; - -class StopWatch -{ -public: - StopWatch(); - void restart(); - TimeStamp elapsed() const; - static void waitAtLeast(std::chrono::microseconds us, bool busyWait); -private: - SteadyTimeStamp _startTime; -}; - time_t time(); } diff --git a/fastos/src/vespa/fastos/unix_process.cpp b/fastos/src/vespa/fastos/unix_process.cpp index 4d4197f5354..087f800e668 100644 --- a/fastos/src/vespa/fastos/unix_process.cpp +++ b/fastos/src/vespa/fastos/unix_process.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 "process.h" #include "unix_ipc.h" -#include "timestamp.h" #include "ringbuffer.h" #include <vector> #include <cstring> @@ -41,6 +40,7 @@ extern char **environ; #endif using namespace std::chrono_literals; +using namespace std::chrono; static pid_t safe_fork () { @@ -1600,7 +1600,7 @@ FastOS_UNIX_ProcessStarter::Wait(FastOS_UNIX_Process *process, bool timeOutKillAttempted = false; - fastos::StopWatch timer; + steady_clock::time_point start = steady_clock::now(); if (pollStillRunning != nullptr) *pollStillRunning = true; @@ -1625,7 +1625,7 @@ FastOS_UNIX_ProcessStarter::Wait(FastOS_UNIX_Process *process, if ((timeOutSeconds != -1) && !timeOutKillAttempted) { - if (timer.elapsed().ms() >= (timeOutSeconds * 1000)) { + if ((steady_clock::now() - start) >= seconds(timeOutSeconds)) { process->Kill(); timeOutKillAttempted = true; } diff --git a/searchcommon/src/tests/schema/schema_test.cpp b/searchcommon/src/tests/schema/schema_test.cpp index 3d35b11a51a..ff4c22bad84 100644 --- a/searchcommon/src/tests/schema/schema_test.cpp +++ b/searchcommon/src/tests/schema/schema_test.cpp @@ -243,55 +243,16 @@ TEST(SchemaTest, test_load_and_save) } } -TEST(SchemaTest, require_that_schema_can_save_and_load_timestamps_for_fields) -{ - const fastos::TimeStamp timestamp(42); - const std::string file_name = "schema-with-timestamps.txt"; - Schema s; - Schema::IndexField f("foo", DataType::STRING); - f.setTimestamp(timestamp); - s.addIndexField(f); - ASSERT_TRUE(s.saveToFile(file_name)); - Schema s2; - ASSERT_TRUE(s2.loadFromFile(file_name)); - ASSERT_EQ(1u, s2.getNumIndexFields()); - EXPECT_EQ(timestamp, s2.getIndexField(0).getTimestamp()); -} - -TEST(SchemaTest, require_that_timestamps_are_omitted_when_0) -{ - const std::string file_name = "schema-without-timestamps.txt"; - Schema s; - s.addIndexField(Schema::IndexField("foo", DataType::STRING)); - ASSERT_TRUE(s.saveToFile(file_name)); - - std::ifstream file(file_name.c_str()); - ASSERT_TRUE(file.good()); - while (file) { - std::string line; - getline(file, line); - EXPECT_NE("indexfield[0].timestamp 0", line); - } - - Schema s2; - ASSERT_TRUE(s2.loadFromFile(file_name)); - ASSERT_EQ(1u, s2.getNumIndexFields()); -} - void -addAllFieldTypes(const string& name, Schema& schema, - fastos::TimeStamp timestamp) +addAllFieldTypes(const string& name, Schema& schema) { Schema::IndexField index_field(name, DataType::STRING); - index_field.setTimestamp(timestamp); schema.addIndexField(index_field); Schema::AttributeField attribute_field(name, DataType::STRING); - attribute_field.setTimestamp(timestamp); schema.addAttributeField(attribute_field); Schema::SummaryField summary_field(name, DataType::STRING); - summary_field.setTimestamp(timestamp); schema.addSummaryField(summary_field); schema.addFieldSet(Schema::FieldSet(name)); @@ -301,12 +262,10 @@ TEST(SchemaTest, require_that_schemas_can_be_added) { const string name1 = "foo"; const string name2 = "bar"; - const fastos::TimeStamp timestamp1(42); - const fastos::TimeStamp timestamp2(84); Schema s1; - addAllFieldTypes(name1, s1, timestamp1); + addAllFieldTypes(name1, s1); Schema s2; - addAllFieldTypes(name2, s2, timestamp2); + addAllFieldTypes(name2, s2); Schema::UP sum = Schema::make_union(s1, s2); ASSERT_EQ(2u, sum->getNumIndexFields()); @@ -334,7 +293,7 @@ TEST(SchemaTest, require_that_schemas_can_be_added) TEST(SchemaTest, require_that_S_union_S_equals_S_for_schema_S) { Schema schema; - addAllFieldTypes("foo", schema, 42); + addAllFieldTypes("foo", schema); Schema::UP sum = Schema::make_union(schema, schema); EXPECT_TRUE(schema == *sum); @@ -344,56 +303,35 @@ TEST(SchemaTest, require_that_schema_can_calculate_set_difference) { const string name1 = "foo"; const string name2 = "bar"; - const fastos::TimeStamp timestamp1(42); - const fastos::TimeStamp timestamp2(84); Schema s1; - addAllFieldTypes(name1, s1, timestamp1); - addAllFieldTypes(name2, s1, timestamp2); + addAllFieldTypes(name1, s1); + addAllFieldTypes(name2, s1); Schema s2; - addAllFieldTypes(name2, s2, timestamp2); + addAllFieldTypes(name2, s2); Schema::UP schema = Schema::set_difference(s1, s2); Schema expected; - addAllFieldTypes(name1, expected, timestamp1); + addAllFieldTypes(name1, expected); EXPECT_TRUE(expected == *schema); } -TEST(SchemaTest, require_that_get_old_fields_returns_a_subset_of_a_schema) -{ - Schema schema; - const int64_t limit_timestamp = 1000; - - addAllFieldTypes("bar", schema, fastos::TimeStamp(limit_timestamp - 1)); - addAllFieldTypes("foo", schema, fastos::TimeStamp(limit_timestamp + 1)); - - Schema::UP old_fields = - schema.getOldFields(fastos::TimeStamp(limit_timestamp)); - - EXPECT_EQ(1u, old_fields->getNumIndexFields()); - EXPECT_EQ("bar", old_fields->getIndexField(0).getName()); - EXPECT_EQ(1u, old_fields->getNumAttributeFields()); - EXPECT_EQ(1u, old_fields->getNumSummaryFields()); -} - TEST(SchemaTest, require_that_schema_can_calculate_intersection) { const string name1 = "foo"; const string name2 = "bar"; const string name3 = "baz"; - const fastos::TimeStamp timestamp1(42); - const fastos::TimeStamp timestamp2(84); Schema s1; - addAllFieldTypes(name1, s1, timestamp1); - addAllFieldTypes(name2, s1, timestamp2); + addAllFieldTypes(name1, s1); + addAllFieldTypes(name2, s1); Schema s2; - addAllFieldTypes(name2, s2, timestamp2); - addAllFieldTypes(name3, s2, timestamp2); + addAllFieldTypes(name2, s2); + addAllFieldTypes(name3, s2); Schema::UP schema = Schema::intersect(s1, s2); Schema expected; - addAllFieldTypes(name2, expected, timestamp2); + addAllFieldTypes(name2, expected); EXPECT_TRUE(expected == *schema); } diff --git a/searchcommon/src/vespa/searchcommon/common/schema.cpp b/searchcommon/src/vespa/searchcommon/common/schema.cpp index afc023a68d7..fb0ea74d3e9 100644 --- a/searchcommon/src/vespa/searchcommon/common/schema.cpp +++ b/searchcommon/src/vespa/searchcommon/common/schema.cpp @@ -72,33 +72,26 @@ const uint32_t Schema::UNKNOWN_FIELD_ID(std::numeric_limits<uint32_t>::max()); Schema::Field::Field(vespalib::stringref n, DataType dt) : _name(n), _dataType(dt), - _collectionType(schema::CollectionType::SINGLE), - _timestamp(0) + _collectionType(schema::CollectionType::SINGLE) { } -Schema::Field::Field(vespalib::stringref n, - DataType dt, CollectionType ct) +Schema::Field::Field(vespalib::stringref n, DataType dt, CollectionType ct) : _name(n), _dataType(dt), - _collectionType(ct), - _timestamp(0) + _collectionType(ct) { } // XXX: Resource leak if exception is thrown. Schema::Field::Field(const std::vector<vespalib::string> & lines) : _name(ConfigParser::parse<vespalib::string>("name", lines)), - _dataType(schema::dataTypeFromName(ConfigParser::parse<vespalib::string>( - "datatype", lines))), - _collectionType( - schema::collectionTypeFromName(ConfigParser::parse<vespalib::string>( - "collectiontype", lines))), - _timestamp(ConfigParser::parse<int64_t>("timestamp", lines, 0)) + _dataType(schema::dataTypeFromName(ConfigParser::parse<vespalib::string>("datatype", lines))), + _collectionType(schema::collectionTypeFromName(ConfigParser::parse<vespalib::string>("collectiontype", lines))) { } -Schema::Field::~Field() { } +Schema::Field::~Field() = default; void Schema::Field::write(vespalib::asciistream & os, vespalib::stringref prefix) const @@ -106,27 +99,22 @@ Schema::Field::write(vespalib::asciistream & os, vespalib::stringref prefix) con os << prefix << "name " << _name << "\n"; os << prefix << "datatype " << getTypeName(_dataType) << "\n"; os << prefix << "collectiontype " << getTypeName(_collectionType) << "\n"; - if (_timestamp) { - os << prefix << "timestamp " << _timestamp.val() << "\n"; - } } bool Schema::Field::operator==(const Field &rhs) const { return _name == rhs._name && - _dataType == rhs._dataType && - _collectionType == rhs._collectionType && - _timestamp == rhs._timestamp; + _dataType == rhs._dataType && + _collectionType == rhs._collectionType; } bool Schema::Field::operator!=(const Field &rhs) const { return _name != rhs._name || - _dataType != rhs._dataType || - _collectionType != rhs._collectionType || - _timestamp != rhs._timestamp; + _dataType != rhs._dataType || + _collectionType != rhs._collectionType; } Schema::IndexField::IndexField(vespalib::stringref name, DataType dt) @@ -488,8 +476,7 @@ struct IntersectHelper { }; template <> -bool IntersectHelper::is_matching(const Schema::FieldSet &f1, - const Schema::FieldSet &f2) { +bool IntersectHelper::is_matching(const Schema::FieldSet &f1, const Schema::FieldSet &f2) { if (f1.getFields() != f2.getFields()) return false; const std::vector<vespalib::string> fields = f1.getFields(); @@ -503,21 +490,7 @@ bool IntersectHelper::is_matching(const Schema::FieldSet &f1, } template <typename T, typename Map> -void addOldEntries(const std::vector<T> &entries, - fastos::TimeStamp limit_timestamp, - std::vector<T> &v, Map &name2id_map) { - for (typename std::vector<T>::const_iterator - it = entries.begin(); it != entries.end(); ++it) { - if (it->getTimestamp() < limit_timestamp) { - name2id_map[it->getName()] = v.size(); - v.push_back(*it); - } - } -} - -template <typename T, typename Map> -void addEntries(const std::vector<T> &entries, std::vector<T> &v, - Map &name2id_map) { +void addEntries(const std::vector<T> &entries, std::vector<T> &v, Map &name2id_map) { for (typename std::vector<T>::const_iterator it = entries.begin(); it != entries.end(); ++it) { if (name2id_map.find(it->getName()) == name2id_map.end()) { @@ -541,19 +514,6 @@ void difference(const std::vector<T> &minuend, const Map &subtrahend_map, } // namespace Schema::UP -Schema::getOldFields(fastos::TimeStamp limit_timestamp) -{ - Schema::UP schema(new Schema); - addOldEntries(_indexFields, limit_timestamp, - schema->_indexFields, schema->_indexIds); - addOldEntries(_attributeFields, limit_timestamp, - schema->_attributeFields, schema->_attributeIds); - addOldEntries(_summaryFields, limit_timestamp, - schema->_summaryFields, schema->_summaryIds); - return schema; -} - -Schema::UP Schema::intersect(const Schema &lhs, const Schema &rhs) { IntersectHelper h; diff --git a/searchcommon/src/vespa/searchcommon/common/schema.h b/searchcommon/src/vespa/searchcommon/common/schema.h index 0b675710e8b..7561bf8b741 100644 --- a/searchcommon/src/vespa/searchcommon/common/schema.h +++ b/searchcommon/src/vespa/searchcommon/common/schema.h @@ -36,7 +36,6 @@ public: vespalib::string _name; DataType _dataType; CollectionType _collectionType; - fastos::TimeStamp _timestamp; public: Field(vespalib::stringref n, DataType dt); @@ -49,8 +48,6 @@ public: virtual ~Field(); - void setTimestamp(fastos::TimeStamp ts) { _timestamp = ts; } - virtual void write(vespalib::asciistream & os, vespalib::stringref prefix) const; @@ -58,7 +55,6 @@ public: const vespalib::string &getName() const { return _name; } DataType getDataType() const { return _dataType; } CollectionType getCollectionType() const { return _collectionType; } - fastos::TimeStamp getTimestamp() const { return _timestamp; } bool matchingTypes(const Field &rhs) const { return getDataType() == rhs.getDataType() && @@ -389,8 +385,6 @@ public: void swap(Schema &rhs); void clear(); - Schema::UP getOldFields(fastos::TimeStamp limit_timestamp); - static Schema::UP intersect(const Schema &lhs, const Schema &rhs); static Schema::UP make_union(const Schema &lhs, const Schema &rhs); static Schema::UP set_difference(const Schema &lhs, const Schema &rhs); diff --git a/searchlib/src/tests/groupingengine/groupingengine_test.cpp b/searchlib/src/tests/groupingengine/groupingengine_test.cpp index 11a661a743e..d0e2d749d08 100644 --- a/searchlib/src/tests/groupingengine/groupingengine_test.cpp +++ b/searchlib/src/tests/groupingengine/groupingengine_test.cpp @@ -1894,7 +1894,7 @@ Test::testNanSorting() EXPECT_FALSE(0.2 < myNan); EXPECT_FALSE(0.2 > myNan); - fastos::StopWatch timer; + vespalib::Timer timer; std::vector<double> groups; while (timer.elapsed().ms()() < 60000.0) { std::vector<double> vec; diff --git a/searchlib/src/tests/transactionlogstress/translogstress.cpp b/searchlib/src/tests/transactionlogstress/translogstress.cpp index 5d70c32cd7d..247e1316a7b 100644 --- a/searchlib/src/tests/transactionlogstress/translogstress.cpp +++ b/searchlib/src/tests/transactionlogstress/translogstress.cpp @@ -254,7 +254,7 @@ FeederThread::doRun() while (!_done) { if (_feedRate != 0) { - _timer.restart(); + _timer = vespalib::Timer(); for (uint32_t i = 0; i < _feedRate; ++i) { Packet::Entry entry = _generator.getRandomEntry(_current++); if (!addEntry(entry)) { diff --git a/searchlib/src/vespa/searchlib/expression/debugwaitfunctionnode.cpp b/searchlib/src/vespa/searchlib/expression/debugwaitfunctionnode.cpp index c51cd444b54..aa1fdd249a7 100644 --- a/searchlib/src/vespa/searchlib/expression/debugwaitfunctionnode.cpp +++ b/searchlib/src/vespa/searchlib/expression/debugwaitfunctionnode.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 "debugwaitfunctionnode.h" -#include <vespa/fastos/timestamp.h> +#include <vespa/vespalib/util/time.h> namespace search::expression { @@ -30,7 +30,7 @@ using std::chrono::microseconds; bool DebugWaitFunctionNode::onExecute() const { - fastos::StopWatch::waitAtLeast(microseconds(long(_waitTime * 1000000)), _busyWait); + vespalib::Timer::waitAtLeast(vespalib::from_s(_waitTime), _busyWait); getArg().execute(); updateResult().assign(getArg().getResult()); diff --git a/searchlib/src/vespa/searchlib/features/debug_attribute_wait.cpp b/searchlib/src/vespa/searchlib/features/debug_attribute_wait.cpp index 975f510cd22..86a71184f43 100644 --- a/searchlib/src/vespa/searchlib/features/debug_attribute_wait.cpp +++ b/searchlib/src/vespa/searchlib/features/debug_attribute_wait.cpp @@ -1,11 +1,10 @@ // Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. #include "debug_attribute_wait.h" -#include <vespa/fastos/timestamp.h> +#include <vespa/vespalib/util/time.h> using search::attribute::IAttributeVector; using namespace search::fef; -using namespace std::chrono; namespace search::features { @@ -42,9 +41,9 @@ DebugAttributeWaitExecutor::execute(uint32_t docId) _buf.fill(*_attribute, docId); waitTime = _buf[0]; } - fastos::StopWatch timer; - fastos::StopWatch::waitAtLeast(microseconds(long(waitTime * 1000000)), _params.busyWait); - outputs().set_number(0, timer.elapsed().sec()); + vespalib::Timer timer; + vespalib::Timer::waitAtLeast(vespalib::from_s(waitTime), _params.busyWait); + outputs().set_number(0, vespalib::to_s(timer.elapsed())); } //----------------------------------------------------------------------------- diff --git a/searchlib/src/vespa/searchlib/features/debug_wait.cpp b/searchlib/src/vespa/searchlib/features/debug_wait.cpp index 79ba1678b2b..fb002564572 100644 --- a/searchlib/src/vespa/searchlib/features/debug_wait.cpp +++ b/searchlib/src/vespa/searchlib/features/debug_wait.cpp @@ -1,7 +1,7 @@ // Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. #include "debug_wait.h" -#include <vespa/fastos/timestamp.h> +#include <vespa/vespalib/util/time.h> using namespace search::fef; @@ -29,9 +29,9 @@ using namespace std::chrono; void DebugWaitExecutor::execute(uint32_t) { - fastos::StopWatch timer; - fastos::StopWatch::waitAtLeast(microseconds(long(_params.waitTime * 1000000)), _params.busyWait); - outputs().set_number(0, timer.elapsed().sec()); + vespalib::Timer timer; + vespalib::Timer::waitAtLeast(vespalib::from_s(_params.waitTime), _params.busyWait); + outputs().set_number(0, vespalib::to_s(timer.elapsed())); } //----------------------------------------------------------------------------- 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 7567e8426ae..6c643696615 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,6 @@ #include <vespa/vespalib/util/left_right_heap.h> #include <vespa/vespalib/util/stringfmt.h> #include <vespa/vespalib/util/inline.h> -#include <vespa/fastos/timestamp.h> using vespalib::RightArrayHeap; using vespalib::RightHeap; @@ -41,11 +40,11 @@ struct MyInvCmp { struct Timer { double minTime; - fastos::StopWatch timer; + vespalib::Timer timer; Timer() : minTime(1.0e10), timer() {} - void start() { timer.restart(); } + void start() { timer = vespalib::Timer(); } void stop() { - double ms = timer.elapsed().ms(); + double ms = vespalib::count_ms(timer.elapsed()); minTime = std::min(minTime, ms); } }; diff --git a/vespalib/src/vespa/vespalib/util/time.cpp b/vespalib/src/vespa/vespalib/util/time.cpp index fdd13849287..01f40152029 100644 --- a/vespalib/src/vespa/vespalib/util/time.cpp +++ b/vespalib/src/vespa/vespalib/util/time.cpp @@ -1,6 +1,7 @@ // Copyright 2019 Oath Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. #include "time.h" +#include <thread> namespace vespalib { @@ -13,4 +14,16 @@ to_utc(steady_time ts) { Timer::~Timer() = default; +void +Timer::waitAtLeast(duration dur, bool busyWait) { + if (busyWait) { + steady_clock::time_point deadline = steady_clock::now() + dur; + while (steady_clock::now() < deadline) { + for (int i = 0; i < 1000; i++) { } + } + } else { + std::this_thread::sleep_for(dur); + } +} + } diff --git a/vespalib/src/vespa/vespalib/util/time.h b/vespalib/src/vespa/vespalib/util/time.h index 3111239ffab..47dc54d40c2 100644 --- a/vespalib/src/vespa/vespalib/util/time.h +++ b/vespalib/src/vespa/vespalib/util/time.h @@ -73,6 +73,7 @@ public: Timer() : _start(steady_clock::now()) {} ~Timer(); duration elapsed() const { return (steady_clock::now() - _start); } + static void waitAtLeast(duration dur, bool busyWait); }; } diff --git a/vespalog/src/test/threads/testthreads.cpp b/vespalog/src/test/threads/testthreads.cpp index d23e00930fd..ab7ddad3da7 100644 --- a/vespalog/src/test/threads/testthreads.cpp +++ b/vespalog/src/test/threads/testthreads.cpp @@ -1,6 +1,5 @@ // 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/timestamp.h> #include <vespa/fastos/thread.h> #include <vespa/log/bufferedlogger.h> #include <array> @@ -13,6 +12,7 @@ using std::string; using namespace std::chrono_literals; +using namespace std::chrono; LOG_SETUP(".threadtest"); @@ -104,10 +104,10 @@ ThreadTester::Main() pool.NewThread(loggers[i].get()); } - fastos::StopWatch timer; + steady_clock::time_point start = steady_clock::now(); // Reduced runtime to half as the test now repeats itself to test with // buffering. (To avoid test taking a minute) - while (timer.elapsed().ms() < 15 * 1000) { + while ((steady_clock::now() - start) < 15s) { unlink(_argv[1]); std::this_thread::sleep_for(1ms); } @@ -115,8 +115,8 @@ ThreadTester::Main() for (int i = 0; i < numLoggers; i++) { loggers[i]->_useLogBuffer = true; } - timer.restart(); - while (timer.elapsed().ms() < 15 * 1000) { + start = steady_clock::now(); + while ((steady_clock::now() - start) < 15s) { unlink(_argv[1]); std::this_thread::sleep_for(1ms); } |