diff options
author | Henning Baldersheim <balder@yahoo-inc.com> | 2019-12-09 17:43:24 +0000 |
---|---|---|
committer | Henning Baldersheim <balder@yahoo-inc.com> | 2019-12-16 23:48:46 +0000 |
commit | 6a807615c7ee6364362a9a14d725165e948c5585 (patch) | |
tree | 3981eab5e1a943e68f9a0bd7b738d506dc1ca01d | |
parent | 225be01d5405c179584eb7fc08309c8f4a08fb22 (diff) |
Drop all of TimeStamp too.
12 files changed, 77 insertions, 123 deletions
diff --git a/fastos/src/vespa/fastos/timestamp.cpp b/fastos/src/vespa/fastos/timestamp.cpp index d8e89dcf99f..5268453901d 100644 --- a/fastos/src/vespa/fastos/timestamp.cpp +++ b/fastos/src/vespa/fastos/timestamp.cpp @@ -1,43 +1,11 @@ // 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 <sys/time.h> +#include <chrono> using std::chrono::system_clock; -using std::chrono::steady_clock; -using std::chrono::nanoseconds; -using std::chrono::duration_cast; namespace fastos { -const TimeStamp::TimeT TimeStamp::MILLI; -const TimeStamp::TimeT TimeStamp::MICRO; -const TimeStamp::TimeT TimeStamp::NANO; -const TimeStamp::TimeT TimeStamp::SEC; - -using seconds = std::chrono::duration<double>; - -std::string -TimeStamp::asString(double timeInSeconds) -{ - double intpart; - double fractpart = std::modf(timeInSeconds, &intpart); - time_t timeStamp = (time_t)intpart; - struct tm timeStruct; - gmtime_r(&timeStamp, &timeStruct); - char timeString[128]; - strftime(timeString, sizeof(timeString), "%F %T", &timeStruct); - char retval[160]; - uint32_t milliSeconds = std::min((uint32_t)(fractpart * 1000.0), 999u); - snprintf(retval, sizeof(retval), "%s.%03u UTC", timeString, milliSeconds); - return std::string(retval); -} - -std::string -TimeStamp::asString(std::chrono::system_clock::time_point ns) { - return asString(seconds(ns.time_since_epoch()).count()); -} - time_t time() { return system_clock::to_time_t(system_clock::now()); diff --git a/fastos/src/vespa/fastos/timestamp.h b/fastos/src/vespa/fastos/timestamp.h index 37587f4dc3e..e050fe1bcbb 100644 --- a/fastos/src/vespa/fastos/timestamp.h +++ b/fastos/src/vespa/fastos/timestamp.h @@ -1,50 +1,10 @@ // Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. #pragma once -#include <cstdint> -#include <limits> -#include <string> -#include <chrono> +#include <ctime> namespace fastos { -class TimeStamp -{ -public: - typedef int64_t TimeT; - static const TimeT MILLI = 1000LL; - static const TimeT MICRO = 1000*MILLI; - static const TimeT NANO = 1000*MICRO; - static const TimeT SEC = NANO; - TimeStamp() : _time(0) { } - TimeStamp(const timeval & tv) : _time(tv.tv_sec*SEC + tv.tv_usec*MILLI) { } - TimeStamp(int v) : _time(v) { } - TimeStamp(unsigned int v) : _time(v) { } - TimeStamp(long v) : _time(v) { } - TimeStamp(unsigned long v) : _time(v) { } - TimeStamp(long long v) : _time(v) { } - TimeStamp(unsigned long long v) : _time(v) { } - TimeT val() const { return _time; } - operator TimeT () const { return val(); } - TimeStamp & operator += (TimeStamp b) { _time += b._time; return *this; } - TimeStamp & operator -= (TimeStamp b) { _time -= b._time; return *this; } - TimeT time() const { return val()/NANO; } - TimeT ms() const { return val()/1000000; } - TimeT us() const { return val()/1000; } - TimeT ns() const { return val(); } - double sec() const { return val()/1000000000.0; } - std::string toString() const { return asString(sec()); } - static std::string asString(double timeInSeconds); - static std::string asString(std::chrono::system_clock::time_point time); -private: - TimeT _time; -}; - -inline TimeStamp operator +(TimeStamp a, TimeStamp b) { return TimeStamp(a.val() + b.val()); } -inline TimeStamp operator -(TimeStamp a, TimeStamp b) { return TimeStamp(a.val() - b.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())); } - time_t time(); } diff --git a/searchcommon/src/vespa/searchcommon/common/schema.cpp b/searchcommon/src/vespa/searchcommon/common/schema.cpp index fb0ea74d3e9..19d69b0c541 100644 --- a/searchcommon/src/vespa/searchcommon/common/schema.cpp +++ b/searchcommon/src/vespa/searchcommon/common/schema.cpp @@ -224,7 +224,7 @@ Schema::Schema(const Schema & rhs) = default; Schema & Schema::operator=(const Schema & rhs) = default; Schema::Schema(Schema && rhs) = default; Schema & Schema::operator=(Schema && rhs) = default; -Schema::~Schema() { } +Schema::~Schema() = default; bool Schema::loadFromFile(const vespalib::string & fileName) @@ -479,10 +479,8 @@ template <> 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(); - for (std::vector<vespalib::string>::const_iterator - i = fields.begin(), ie = fields.end(); i != ie; ++i) { - if (schema->getIndexFieldId(*i) == Schema::UNKNOWN_FIELD_ID) { + for (const vespalib::string & field : f1.getFields()) { + if (schema->getIndexFieldId(field) == Schema::UNKNOWN_FIELD_ID) { return false; } } @@ -491,11 +489,10 @@ bool IntersectHelper::is_matching(const Schema::FieldSet &f1, const Schema::Fiel template <typename T, typename 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()) { - name2id_map[it->getName()] = v.size(); - v.push_back(*it); + for (const T & key : entries) { + if (name2id_map.find(key.getName()) == name2id_map.end()) { + name2id_map[key.getName()] = v.size(); + v.push_back(key); } } } @@ -503,11 +500,10 @@ void addEntries(const std::vector<T> &entries, std::vector<T> &v, Map &name2id_m template <typename T, typename Map> void difference(const std::vector<T> &minuend, const Map &subtrahend_map, std::vector<T> &diff, Map &diff_map) { - for (typename std::vector<T>::const_iterator - it = minuend.begin(); it != minuend.end(); ++it) { - if (subtrahend_map.find(it->getName()) == subtrahend_map.end()) { - diff_map[it->getName()] = diff.size(); - diff.push_back(*it); + for (const T & key : minuend){ + if (subtrahend_map.find(key.getName()) == subtrahend_map.end()) { + diff_map[key.getName()] = diff.size(); + diff.push_back(key); } } } diff --git a/searchcore/src/vespa/searchcore/proton/flushengine/flush_engine_explorer.cpp b/searchcore/src/vespa/searchcore/proton/flushengine/flush_engine_explorer.cpp index 0df6cc758f7..3fd9abb6744 100644 --- a/searchcore/src/vespa/searchcore/proton/flushengine/flush_engine_explorer.cpp +++ b/searchcore/src/vespa/searchcore/proton/flushengine/flush_engine_explorer.cpp @@ -21,7 +21,7 @@ convertToSlime(const FlushEngine::FlushMetaSet &flushingTargets, Cursor &array) for (const auto &target : flushingTargets) { Cursor &object = array.addObject(); object.setString("name", target.getName()); - object.setString("startTime", fastos::TimeStamp::asString(target.getStart())); + object.setString("startTime", vespalib::to_string(target.getStart())); object.setDouble("elapsedTime", vespalib::to_s(target.elapsed())); } } @@ -48,7 +48,7 @@ convertToSlime(const FlushContext::List &allTargets, object.setLong("flushedSerialNum", target->getFlushedSerialNum()); object.setLong("memoryGain", target->getApproxMemoryGain().gain()); object.setLong("diskGain", target->getApproxDiskGain().gain()); - object.setString("lastFlushTime", fastos::TimeStamp::asString(target->getLastFlushTime())); + object.setString("lastFlushTime", vespalib::to_string(target->getLastFlushTime())); vespalib::duration timeSinceLastFlush = now - target->getLastFlushTime(); object.setDouble("timeSinceLastFlush", vespalib::to_s(timeSinceLastFlush)); object.setBool("needUrgentFlush", target->needUrgentFlush()); diff --git a/searchcore/src/vespa/searchcore/proton/matching/session_manager_explorer.cpp b/searchcore/src/vespa/searchcore/proton/matching/session_manager_explorer.cpp index 785ceadba9a..c2835d2bb76 100644 --- a/searchcore/src/vespa/searchcore/proton/matching/session_manager_explorer.cpp +++ b/searchcore/src/vespa/searchcore/proton/matching/session_manager_explorer.cpp @@ -31,8 +31,8 @@ public: for (const auto &session: sessions) { Cursor &entry = array.addObject(); entry.setString("id", session.id); - entry.setString("created", fastos::TimeStamp::asString(vespalib::to_utc(session.created))); - entry.setString("doom", fastos::TimeStamp::asString(vespalib::to_utc(session.doom))); + entry.setString("created", vespalib::to_string(vespalib::to_utc(session.created))); + entry.setString("doom", vespalib::to_string(vespalib::to_utc(session.doom))); } } } diff --git a/searchlib/src/tests/grouping/grouping_test.cpp b/searchlib/src/tests/grouping/grouping_test.cpp index 4c94e4a2641..94d3afd619b 100644 --- a/searchlib/src/tests/grouping/grouping_test.cpp +++ b/searchlib/src/tests/grouping/grouping_test.cpp @@ -1896,7 +1896,7 @@ Test::testNanSorting() EXPECT_FALSE(0.2 < myNan); EXPECT_FALSE(0.2 > myNan); - fastos::Timer timer; + vespalib::Timer timer; std::vector<double> groups; while (timer.elapsed() < 60s) { std::vector<double> vec; diff --git a/searchlib/src/vespa/searchlib/engine/trace.cpp b/searchlib/src/vespa/searchlib/engine/trace.cpp index 95d6c967369..705bd5782ab 100644 --- a/searchlib/src/vespa/searchlib/engine/trace.cpp +++ b/searchlib/src/vespa/searchlib/engine/trace.cpp @@ -39,10 +39,11 @@ Trace::Trace(const RelativeTime & relativeTime, uint32_t level) void Trace::start(int level, bool useUTC) { if (shouldTrace(level) && !hasTrace()) { - vespalib::duration since_epoch = useUTC - ? vespalib::to_utc(_relativeTime.timeOfDawn()).time_since_epoch() - : _relativeTime.timeOfDawn().time_since_epoch(); - root().setString("start_time", fastos::TimeStamp::asString(vespalib::to_s(since_epoch))); + if (useUTC) { + root().setString("start_time", vespalib::to_string(vespalib::to_utc(_relativeTime.timeOfDawn()))); + } else { + root().setString("start_time", vespalib::to_string(_relativeTime.timeOfDawn())); + } } } diff --git a/searchlib/src/vespa/searchlib/transactionlog/trans_log_server_explorer.cpp b/searchlib/src/vespa/searchlib/transactionlog/trans_log_server_explorer.cpp index 2cb546395d3..b88133c0bf9 100644 --- a/searchlib/src/vespa/searchlib/transactionlog/trans_log_server_explorer.cpp +++ b/searchlib/src/vespa/searchlib/transactionlog/trans_log_server_explorer.cpp @@ -2,8 +2,8 @@ #include "trans_log_server_explorer.h" #include <vespa/vespalib/data/slime/slime.h> +#include <vespa/vespalib/util/time.h> #include <vespa/fastos/file.h> -#include <vespa/fastos/timestamp.h> using vespalib::slime::Inserter; @@ -16,7 +16,7 @@ namespace { struct DomainExplorer : vespalib::StateExplorer { Domain::SP domain; DomainExplorer(Domain::SP domain_in) : domain(std::move(domain_in)) {} - virtual void get_state(const Inserter &inserter, bool full) const override { + void get_state(const Inserter &inserter, bool full) const override { Cursor &state = inserter.insertObject(); DomainInfo info = domain->getDomainInfo(); state.setLong("from", info.range.from()); @@ -35,7 +35,7 @@ struct DomainExplorer : vespalib::StateExplorer { { FastOS_StatInfo stat_info; FastOS_File::Stat(part_in.file.c_str(), &stat_info); - part.setString("lastModified", fastos::TimeStamp::asString(stat_info._modifiedTime)); + part.setString("lastModified", vespalib::to_string(std::chrono::nanoseconds(stat_info._modifiedTimeNS))); } } } diff --git a/staging_vespalib/src/tests/benchmark/testbase.cpp b/staging_vespalib/src/tests/benchmark/testbase.cpp index eb714039ef5..ff83d1ee9d8 100644 --- a/staging_vespalib/src/tests/benchmark/testbase.cpp +++ b/staging_vespalib/src/tests/benchmark/testbase.cpp @@ -1,12 +1,13 @@ // Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. #include "testbase.h" -#include <vespa/fastos/timestamp.h> #include <vespa/vespalib/util/time.h> #include <cassert> #include <vespa/log/log.h> LOG_SETUP(".testbase"); +using namespace std::chrono; + namespace vespalib { IMPLEMENT_IDENTIFIABLE_ABSTRACT_NS(vespalib, Benchmark, Identifiable); @@ -180,13 +181,13 @@ size_t ClockREALTIME::onRun() int foo = clock_gettime(CLOCK_REALTIME, &ts); assert(foo == 0); (void) foo; - fastos::TimeStamp start(ts.tv_sec*1000L*1000L*1000L + ts.tv_nsec); - fastos::TimeStamp end(start); + nanoseconds start(ts.tv_sec*1000L*1000L*1000L + ts.tv_nsec); + nanoseconds end(start); for (size_t i=0; i < 1000; i++) { clock_gettime(CLOCK_REALTIME, &ts); - end = ts.tv_sec*1000L*1000L*1000L + ts.tv_nsec; + end = nanoseconds(ts.tv_sec*1000L*1000L*1000L + ts.tv_nsec); } - return (start - end).ns(); + return count_ns(start - end); } size_t ClockMONOTONIC::onRun() @@ -195,13 +196,13 @@ size_t ClockMONOTONIC::onRun() int foo = clock_gettime(CLOCK_MONOTONIC, &ts); assert(foo == 0); (void) foo; - fastos::TimeStamp start(ts.tv_sec*1000L*1000L*1000L + ts.tv_nsec); - fastos::TimeStamp end(start); + nanoseconds start(ts.tv_sec*1000L*1000L*1000L + ts.tv_nsec); + nanoseconds end(start); for (size_t i=0; i < 1000; i++) { clock_gettime(CLOCK_MONOTONIC, &ts); - end = ts.tv_sec*1000L*1000L*1000L + ts.tv_nsec; + end = nanoseconds(ts.tv_sec*1000L*1000L*1000L + ts.tv_nsec); } - return (start - end).ns(); + return count_ns(start - end);; } ClockMONOTONIC_RAW::ClockMONOTONIC_RAW() @@ -221,13 +222,13 @@ size_t ClockMONOTONIC_RAW::onRun() int foo = clock_gettime(CLOCK_MONOTONIC_RAW, &ts); assert(foo == 0); (void) foo; - fastos::TimeStamp start(ts.tv_sec*1000L*1000L*1000L + ts.tv_nsec); - fastos::TimeStamp end(start); + nanoseconds start(ts.tv_sec*1000L*1000L*1000L + ts.tv_nsec); + nanoseconds end(start); for (size_t i=0; i < 1000; i++) { clock_gettime(CLOCK_MONOTONIC_RAW, &ts); - end = ts.tv_sec*1000L*1000L*1000L + ts.tv_nsec; + end = nanoseconds(ts.tv_sec*1000L*1000L*1000L + ts.tv_nsec); } - return (start - end).ns(); + return count_ns(start - end); } size_t ClockPROCESS_CPUTIME_ID::onRun() @@ -236,13 +237,13 @@ size_t ClockPROCESS_CPUTIME_ID::onRun() int foo = clock_gettime(CLOCK_PROCESS_CPUTIME_ID, &ts); assert(foo == 0); (void) foo; - fastos::TimeStamp start(ts.tv_sec*1000L*1000L*1000L + ts.tv_nsec); - fastos::TimeStamp end(start); + nanoseconds start(ts.tv_sec*1000L*1000L*1000L + ts.tv_nsec); + nanoseconds end(start); for (size_t i=0; i < 1000; i++) { clock_gettime(CLOCK_PROCESS_CPUTIME_ID, &ts); - end = ts.tv_sec*1000L*1000L*1000L + ts.tv_nsec; + end =nanoseconds(ts.tv_sec*1000L*1000L*1000L + ts.tv_nsec); } - return (start - end).ns(); + return count_ns(start - end); } size_t ClockTHREAD_CPUTIME_ID::onRun() @@ -251,13 +252,13 @@ size_t ClockTHREAD_CPUTIME_ID::onRun() int foo = clock_gettime(CLOCK_THREAD_CPUTIME_ID, &ts); assert(foo == 0); (void) foo; - fastos::TimeStamp start(ts.tv_sec*1000L*1000L*1000L + ts.tv_nsec); - fastos::TimeStamp end(start); + nanoseconds start(ts.tv_sec*1000L*1000L*1000L + ts.tv_nsec); + nanoseconds end(start); for (size_t i=0; i < 1000; i++) { clock_gettime(CLOCK_THREAD_CPUTIME_ID, &ts); - end = ts.tv_sec*1000L*1000L*1000L + ts.tv_nsec; + end = nanoseconds(ts.tv_sec*1000L*1000L*1000L + ts.tv_nsec); } - return (start - end).ns(); + return count_ns(start - end); } size_t CreateVespalibString::onRun() diff --git a/vespalib/src/tests/closure/closure_test.cpp b/vespalib/src/tests/closure/closure_test.cpp index 5ba6ecf2a56..9faabb56fc5 100644 --- a/vespalib/src/tests/closure/closure_test.cpp +++ b/vespalib/src/tests/closure/closure_test.cpp @@ -6,7 +6,6 @@ using std::shared_ptr; using std::unique_ptr; -using std::string; using namespace vespalib; namespace { diff --git a/vespalib/src/vespa/vespalib/util/time.cpp b/vespalib/src/vespa/vespalib/util/time.cpp index 01f40152029..fd5d3e3055e 100644 --- a/vespalib/src/vespa/vespalib/util/time.cpp +++ b/vespalib/src/vespa/vespalib/util/time.cpp @@ -12,6 +12,30 @@ to_utc(steady_time ts) { return system_time(nowUtc.time_since_epoch() - nowSteady.time_since_epoch() + ts.time_since_epoch()); } +string +to_string(duration dur) +{ + time_t timeStamp = std::chrono::duration_cast<std::chrono::seconds>(dur).count(); + struct tm timeStruct; + gmtime_r(&timeStamp, &timeStruct); + char timeString[128]; + strftime(timeString, sizeof(timeString), "%F %T", &timeStruct); + char retval[160]; + uint32_t milliSeconds = count_ms(dur)%1000; + snprintf(retval, sizeof(retval), "%s.%03u UTC", timeString, milliSeconds); + return std::string(retval); +} + +string +to_string(system_time time) { + return to_string(time.time_since_epoch()); +} + +string +to_string(steady_time time) { + return to_string(time.time_since_epoch()); +} + Timer::~Timer() = default; void diff --git a/vespalib/src/vespa/vespalib/util/time.h b/vespalib/src/vespa/vespalib/util/time.h index 47dc54d40c2..f6841c70258 100644 --- a/vespalib/src/vespa/vespalib/util/time.h +++ b/vespalib/src/vespa/vespalib/util/time.h @@ -3,6 +3,7 @@ #pragma once #include <chrono> +#include <vespa/vespalib/stllike/string.h> // Guidelines: // @@ -61,6 +62,10 @@ constexpr duration from_timeval(const timeval & tv) { return duration(tv.tv_sec*1000000000L + tv.tv_usec*1000L); } +vespalib::string to_string(system_time time); +vespalib::string to_string(steady_time time); +vespalib::string to_string(duration time); + /** * Simple utility class used to measure how much time has elapsed * since it was constructed. |