diff options
author | Tor Egge <Tor.Egge@yahooinc.com> | 2023-03-06 10:29:40 +0100 |
---|---|---|
committer | Tor Egge <Tor.Egge@yahooinc.com> | 2023-03-06 10:29:40 +0100 |
commit | fd1d0914c7b15f8c278a39f303006897223feb83 (patch) | |
tree | 24ca88ebabb5ae63ae064d881c68653888876ae9 /metrics/src | |
parent | e22467e6500b212a611827659d79b680f1b7f805 (diff) |
Use matching duration for time_point.
Diffstat (limited to 'metrics/src')
-rw-r--r-- | metrics/src/tests/metricmanagertest.cpp | 8 | ||||
-rw-r--r-- | metrics/src/tests/snapshottest.cpp | 4 | ||||
-rw-r--r-- | metrics/src/vespa/metrics/metricmanager.cpp | 8 | ||||
-rw-r--r-- | metrics/src/vespa/metrics/metricmanager.h | 4 | ||||
-rw-r--r-- | metrics/src/vespa/metrics/metricsnapshot.cpp | 4 | ||||
-rw-r--r-- | metrics/src/vespa/metrics/metricsnapshot.h | 10 | ||||
-rw-r--r-- | metrics/src/vespa/metrics/updatehook.h | 8 |
7 files changed, 23 insertions, 23 deletions
diff --git a/metrics/src/tests/metricmanagertest.cpp b/metrics/src/tests/metricmanagertest.cpp index 52b17576c5c..9e6b0f40be3 100644 --- a/metrics/src/tests/metricmanagertest.cpp +++ b/metrics/src/tests/metricmanagertest.cpp @@ -29,7 +29,7 @@ struct MetricManagerTest : public ::testing::Test { // MetricManager that aren't accessible to "freestanding" fixtures. So we // get the test to do the necessary poking and prodding for us instead. void takeSnapshots(MetricManager& mm, time_t timeToProcess) { - mm.takeSnapshots(mm.getMetricLock(), system_time(vespalib::from_s(timeToProcess))); + mm.takeSnapshots(mm.getMetricLock(), system_time(vespalib::from_s<system_time::duration>(timeToProcess))); } }; @@ -364,7 +364,7 @@ class FakeTimer : public MetricManager::Timer { std::atomic<time_t> _time; public: FakeTimer(time_t startTime = 0) : _time(startTime) {} - time_point getTime() const override { return time_point(vespalib::from_s(load_relaxed(_time))); } + time_point getTime() const override { return time_point(vespalib::from_s<time_point::duration>(load_relaxed(_time))); } void set_time(time_t t) noexcept { store_relaxed(_time, t); } // Not safe for multiple writers, only expected to be called by test. void add_time(time_t t) noexcept { set_time(load_relaxed(_time) + t); } @@ -384,7 +384,7 @@ struct BriefValuePrinter : public MetricVisitor { } }; -bool waitForTimeProcessed(const MetricManager& mm, vespalib::duration processtime, uint32_t timeout = 120) +bool waitForTimeProcessed(const MetricManager& mm, time_point::duration processtime, uint32_t timeout = 120) { uint32_t lastchance = time(0) + timeout; while (time(0) < lastchance) { @@ -945,7 +945,7 @@ namespace { std::mutex& _output_mutex; FakeTimer& _timer; - MyUpdateHook(std::ostringstream& output, std::mutex& output_mutex, const char* name, vespalib::duration period, FakeTimer& timer) + MyUpdateHook(std::ostringstream& output, std::mutex& output_mutex, const char* name, vespalib::system_clock::duration period, FakeTimer& timer) : UpdateHook(name, period), _output(output), _output_mutex(output_mutex), diff --git a/metrics/src/tests/snapshottest.cpp b/metrics/src/tests/snapshottest.cpp index 5561825e2ba..580769bbadb 100644 --- a/metrics/src/tests/snapshottest.cpp +++ b/metrics/src/tests/snapshottest.cpp @@ -148,7 +148,7 @@ TestMetricSet::incValues() { struct FakeTimer : public MetricManager::Timer { uint32_t _timeInSecs; FakeTimer() : _timeInSecs(1) {} - time_point getTime() const override { return time_point(vespalib::from_s(_timeInSecs)); } + time_point getTime() const override { return time_point(vespalib::from_s<time_point::duration>(_timeInSecs)); } }; void ASSERT_VALUE(int32_t value, const MetricSnapshot & snapshot, const char *name) __attribute__((noinline)); @@ -166,7 +166,7 @@ void ASSERT_VALUE(int32_t value, const MetricSnapshot & snapshot, const char *na struct SnapshotTest : public ::testing::Test { void tick(MetricManager& mgr, time_t currentTime) { - mgr.tick(mgr.getMetricLock(), time_point(vespalib::from_s(currentTime))); + mgr.tick(mgr.getMetricLock(), time_point(vespalib::from_s<time_point::duration>(currentTime))); } }; diff --git a/metrics/src/vespa/metrics/metricmanager.cpp b/metrics/src/vespa/metrics/metricmanager.cpp index 606b97bda73..2f6fe4c6ba6 100644 --- a/metrics/src/vespa/metrics/metricmanager.cpp +++ b/metrics/src/vespa/metrics/metricmanager.cpp @@ -427,7 +427,7 @@ MetricManager::createSnapshotPeriods(const Config& config) } else { name << length << " seconds"; } - result.emplace_back(vespalib::from_s(length), name.str()); + result.emplace_back(vespalib::from_s<time_point::duration>(length), name.str()); } for (uint32_t i=1; i<result.size(); ++i) { if (result[i].first % result[i-1].first != vespalib::duration::zero()) { @@ -473,7 +473,7 @@ MetricManager::configure(const MetricLockGuard & , std::unique_ptr<Config> confi uint32_t nextCount = 1; if (i + 1 < snapshotPeriods.size()) { nextCount = snapshotPeriods[i + 1].first / snapshotPeriods[i].first; - if ((snapshotPeriods[i + 1].first % snapshotPeriods[i].first) != vespalib::duration::zero()) { + if ((snapshotPeriods[i + 1].first % snapshotPeriods[i].first) != time_point::duration::zero()) { throw IllegalStateException("Snapshot periods must be multiplum of each other",VESPA_STRLOC); } } @@ -570,11 +570,11 @@ MetricManager::visit(const MetricLockGuard & guard, const MetricSnapshot& snapsh visitor.doneVisiting(); } -std::vector<vespalib::duration> +std::vector<time_point::duration> MetricManager::getSnapshotPeriods(const MetricLockGuard& l) const { assertMetricLockLocked(l); - std::vector<vespalib::duration> result; + std::vector<time_point::duration> result; result.reserve(_snapshots.size()); for (const auto & snapshot : _snapshots) { result.emplace_back(snapshot->getPeriod()); diff --git a/metrics/src/vespa/metrics/metricmanager.h b/metrics/src/vespa/metrics/metricmanager.h index 99fad4f2ad3..6f40e7961f4 100644 --- a/metrics/src/vespa/metrics/metricmanager.h +++ b/metrics/src/vespa/metrics/metricmanager.h @@ -243,7 +243,7 @@ public: const MetricSnapshot& getMetricSnapshot( const MetricLockGuard&, vespalib::duration period, bool getInProgressSet) const; const MetricSnapshotSet& getMetricSnapshotSet(const MetricLockGuard&, vespalib::duration period) const; - std::vector<vespalib::duration> getSnapshotPeriods(const MetricLockGuard& l) const; + std::vector<time_point::duration> getSnapshotPeriods(const MetricLockGuard& l) const; // Public only for testing. The returned pointer is only valid while holding the lock. const ConsumerSpec * getConsumerSpec(const MetricLockGuard & guard, const Metric::String& consumer) const; @@ -290,7 +290,7 @@ private: void handleMetricsAltered(const MetricLockGuard & guard); - using SnapSpec = std::pair<vespalib::duration, std::string>; + using SnapSpec = std::pair<time_point::duration, std::string>; static std::vector<SnapSpec> createSnapshotPeriods( const MetricsmanagerConfig& config); void assertMetricLockLocked(const MetricLockGuard& g) const; }; diff --git a/metrics/src/vespa/metrics/metricsnapshot.cpp b/metrics/src/vespa/metrics/metricsnapshot.cpp index cd06fb731c2..6bcdcc60995 100644 --- a/metrics/src/vespa/metrics/metricsnapshot.cpp +++ b/metrics/src/vespa/metrics/metricsnapshot.cpp @@ -24,7 +24,7 @@ MetricSnapshot::MetricSnapshot(const Metric::String& name) { } -MetricSnapshot::MetricSnapshot(const Metric::String& name, vespalib::duration period, const MetricSet& source, bool copyUnset) +MetricSnapshot::MetricSnapshot(const Metric::String& name, system_time::duration period, const MetricSet& source, bool copyUnset) : _name(name), _period(period), _fromTime(system_time_epoch), @@ -73,7 +73,7 @@ MetricSnapshot::addMemoryUsage(MemoryConsumption& mc) const _snapshot->addMemoryUsage(mc); } -MetricSnapshotSet::MetricSnapshotSet(const Metric::String& name, vespalib::duration period, uint32_t count, +MetricSnapshotSet::MetricSnapshotSet(const Metric::String& name, system_time::duration period, uint32_t count, const MetricSet& source, bool snapshotUnsetMetrics) : _count(count), _builderCount(0), diff --git a/metrics/src/vespa/metrics/metricsnapshot.h b/metrics/src/vespa/metrics/metricsnapshot.h index 945f9dc7326..859ee4a4a97 100644 --- a/metrics/src/vespa/metrics/metricsnapshot.h +++ b/metrics/src/vespa/metrics/metricsnapshot.h @@ -23,7 +23,7 @@ class MetricSnapshot { Metric::String _name; // Period length of this snapshot - vespalib::duration _period; + system_time::duration _period; // Time this snapshot was last updated. system_time _fromTime; // If set to 0, use _fromTime + _period. @@ -37,7 +37,7 @@ public: /** Create a fresh empty top level snapshot. */ MetricSnapshot(const Metric::String& name); /** Create a snapshot of another metric source. */ - MetricSnapshot(const Metric::String& name, vespalib::duration period, + MetricSnapshot(const Metric::String& name, system_time::duration period, const MetricSet& source, bool copyUnset); ~MetricSnapshot(); @@ -54,7 +54,7 @@ public: void setToTime(system_time toTime) { _toTime = toTime; } const Metric::String& getName() const { return _name; } - vespalib::duration getPeriod() const { return _period; } + system_time::duration getPeriod() const { return _period; } system_time getFromTime() const { return _fromTime; } system_time getToTime() const { return _toTime; } const MetricSet& getMetrics() const { return *_snapshot; } @@ -78,11 +78,11 @@ class MetricSnapshotSet { std::unique_ptr<MetricSnapshot> _current; // The last full period std::unique_ptr<MetricSnapshot> _building; // The building period public: - MetricSnapshotSet(const Metric::String& name, vespalib::duration period, uint32_t count, + MetricSnapshotSet(const Metric::String& name, system_time::duration period, uint32_t count, const MetricSet& source, bool snapshotUnsetMetrics); const Metric::String& getName() const { return _current->getName(); } - vespalib::duration getPeriod() const { return _current->getPeriod(); } + system_time::duration getPeriod() const { return _current->getPeriod(); } system_time getFromTime() const { return _current->getFromTime(); } system_time getToTime() const { return _current->getToTime(); } system_time getNextWorkTime() const { return getToTime() + getPeriod(); } diff --git a/metrics/src/vespa/metrics/updatehook.h b/metrics/src/vespa/metrics/updatehook.h index 997bdf0b5a4..aced45b91c9 100644 --- a/metrics/src/vespa/metrics/updatehook.h +++ b/metrics/src/vespa/metrics/updatehook.h @@ -28,7 +28,7 @@ class MetricManager; class UpdateHook { public: using MetricLockGuard = metrics::MetricLockGuard; - UpdateHook(const char* name, vespalib::duration period) + UpdateHook(const char* name, time_point::duration period) : _name(name), _period(period), _nextCall() @@ -38,15 +38,15 @@ public: const char* getName() const { return _name; } void updateNextCall() { updateNextCall(_nextCall); } void updateNextCall(time_point now) { setNextCall(now + _period); } - bool is_periodic() const noexcept { return _period != vespalib::duration::zero(); } + bool is_periodic() const noexcept { return _period != time_point::duration::zero(); } bool expired(time_point now) { return _nextCall <= now; } bool has_valid_expiry() const noexcept { return _nextCall != time_point(); } - vespalib::duration getPeriod() const noexcept { return _period; } + time_point::duration getPeriod() const noexcept { return _period; } time_point getNextCall() const noexcept { return _nextCall; } void setNextCall(time_point now) { _nextCall = now; } private: const char* _name; - const vespalib::duration _period; + const time_point::duration _period; time_point _nextCall; }; |