diff options
-rw-r--r-- | metrics/src/tests/metricmanagertest.cpp | 14 | ||||
-rw-r--r-- | metrics/src/tests/summetrictest.cpp | 5 | ||||
-rw-r--r-- | metrics/src/vespa/metrics/jsonwriter.cpp | 4 | ||||
-rw-r--r-- | metrics/src/vespa/metrics/metricmanager.cpp | 66 | ||||
-rw-r--r-- | metrics/src/vespa/metrics/metricmanager.h | 4 | ||||
-rw-r--r-- | metrics/src/vespa/metrics/metricsnapshot.cpp | 67 | ||||
-rw-r--r-- | metrics/src/vespa/metrics/metricsnapshot.h | 51 | ||||
-rw-r--r-- | metrics/src/vespa/metrics/state_api_adapter.cpp | 4 | ||||
-rw-r--r-- | metrics/src/vespa/metrics/textwriter.cpp | 6 | ||||
-rw-r--r-- | storage/src/vespa/storage/common/statusmetricconsumer.cpp | 20 | ||||
-rw-r--r-- | storage/src/vespa/storage/storageserver/statereporter.cpp | 5 |
11 files changed, 125 insertions, 121 deletions
diff --git a/metrics/src/tests/metricmanagertest.cpp b/metrics/src/tests/metricmanagertest.cpp index 6d6f21ea7b0..e398e252a36 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(), timeToProcess); + mm.takeSnapshots(mm.getMetricLock(), system_time(vespalib::from_s(timeToProcess))); } }; @@ -547,7 +547,7 @@ TEST_F(MetricManagerTest, test_snapshots) ASSERT_VALUES(mm, 0 * 60, "6,5,5,2,8,11,2,2,10,3,13"); // Test that reset works - mm.reset(1000); + mm.reset(system_time(1000s)); ASSERT_VALUES(mm, -1, "0,0,0,0,0,0,0,0,0,0,0"); ASSERT_VALUES(mm, 5 * 60, "0,0,0,0,0,0,0,0,0,0,0"); ASSERT_VALUES(mm, 60 * 60, "0,0,0,0,0,0,0,0,0,0,0"); @@ -902,7 +902,7 @@ TEST_F(MetricManagerTest, test_text_output) "consumer[1].tags[1]\n" "consumer[1].tags[0] snaptest\n")); std::string expected( - "snapshot \"Active metrics showing updates since last snapshot\" from 1000 to 0 period 0\n" + "snapshot \"Active metrics showing updates since last snapshot\" from 1970-01-01 00:16:40.000 UTC to 1970-01-01 00:00:00.000 UTC period 0\n" "temp.val6 average=2 last=2 min=2 max=2 count=1 total=2\n" "temp.sub.val1 average=4 last=4 min=4 max=4 count=1 total=4\n" "temp.sub.valsum average=4 last=4 min=4 max=4 count=1 total=4\n" @@ -938,11 +938,9 @@ TEST_F(MetricManagerTest, text_output_supports_dimensions) fixture.takeSnapshotsOnce(); std::string actual = fixture.renderLastSnapshotAsText("outer.*temp.*val"); std::string expected( - "snapshot \"5 minute\" from 1000 to 1300 period 300\n" - "outer{fancy:stuff}.temp{bar:hyperbar,foo:megafoo}.val1 " - "average=2 last=2 min=2 max=2 count=1 total=2\n" - "outer{fancy:stuff}.temp{bar:hyperbar,foo:megafoo}.val2" - "{baz:superbaz} count=1"); + "snapshot \"5 minute\" from 1970-01-01 00:16:40.000 UTC to 1970-01-01 00:21:40.000 UTC period 300\n" + "outer{fancy:stuff}.temp{bar:hyperbar,foo:megafoo}.val1 average=2 last=2 min=2 max=2 count=1 total=2\n" + "outer{fancy:stuff}.temp{bar:hyperbar,foo:megafoo}.val2{baz:superbaz} count=1"); EXPECT_EQ(expected, actual); } diff --git a/metrics/src/tests/summetrictest.cpp b/metrics/src/tests/summetrictest.cpp index 09495ff038d..8e988b65b96 100644 --- a/metrics/src/tests/summetrictest.cpp +++ b/metrics/src/tests/summetrictest.cpp @@ -104,8 +104,7 @@ TEST(SumMetricTest, test_remove) TEST(SumMetricTest, test_start_value) { MetricSnapshot snapshot("active"); - SumMetric<LongValueMetric> sum("foo", {}, "foodesc", - &snapshot.getMetrics()); + SumMetric<LongValueMetric> sum("foo", {}, "foodesc", &snapshot.getMetrics()); LongValueMetric start("start", {}, "", 0); start.set(50); sum.setStartValue(start); @@ -115,7 +114,7 @@ TEST(SumMetricTest, test_start_value) MetricSnapshot copy("copy"); copy.recreateSnapshot(snapshot.getMetrics(), true); - snapshot.addToSnapshot(copy, 100); + snapshot.addToSnapshot(copy, system_time(100s)); LongValueMetric value("value", {}, "", &snapshot.getMetrics()); sum.addMetricToSum(value); diff --git a/metrics/src/vespa/metrics/jsonwriter.cpp b/metrics/src/vespa/metrics/jsonwriter.cpp index c0d227b8f5a..0c9ed306ec9 100644 --- a/metrics/src/vespa/metrics/jsonwriter.cpp +++ b/metrics/src/vespa/metrics/jsonwriter.cpp @@ -23,8 +23,8 @@ JsonWriter::visitSnapshot(const MetricSnapshot& snapshot) { _stream << Object() << "snapshot" << Object() - << "from" << snapshot.getFromTime() - << "to" << snapshot.getToTime() + << "from" << vespalib::count_s(snapshot.getFromTime().time_since_epoch()) + << "to" << vespalib::count_s(snapshot.getToTime().time_since_epoch()) << End() << "values" << Array(); _flag = SNAPSHOT_STARTED; diff --git a/metrics/src/vespa/metrics/metricmanager.cpp b/metrics/src/vespa/metrics/metricmanager.cpp index df83001a4e2..52dca20694f 100644 --- a/metrics/src/vespa/metrics/metricmanager.cpp +++ b/metrics/src/vespa/metrics/metricmanager.cpp @@ -28,6 +28,7 @@ using vespalib::make_string_short::fmt; using vespalib::count_ms; using vespalib::count_s; using vespalib::from_s; +using vespalib::to_string; MetricManager::ConsumerSpec::ConsumerSpec() = default; MetricManager::ConsumerSpec::~ConsumerSpec() = default; @@ -464,9 +465,9 @@ MetricManager::configure(const MetricLockGuard & , std::unique_ptr<Config> confi LOG(debug, "Initializing snapshots as this is first configure call"); std::vector<SnapSpec> snapshotPeriods(createSnapshotPeriods(*config)); - // Set up snapshots only first time. We don't allow live reconfig - // of snapshot periods. - time_t currentTime = count_s(_timer->getTime().time_since_epoch()); + // Set up snapshots only first time. We don't allow live reconfig + // of snapshot periods. + time_point currentTime = _timer->getTime(); _activeMetrics.setFromTime(currentTime); uint32_t count = 1; for (uint32_t i = 0; i< snapshotPeriods.size(); ++i) { @@ -482,7 +483,7 @@ MetricManager::configure(const MetricLockGuard & , std::unique_ptr<Config> confi _activeMetrics.getMetrics(), _snapshotUnsetMetrics)); count = nextCount; } - // Add all time snapshot. + // Add all time snapshot. _totalMetrics = std::make_shared<MetricSnapshot>("All time snapshot", 0, _activeMetrics.getMetrics(), _snapshotUnsetMetrics); _totalMetrics->reset(currentTime); } @@ -709,7 +710,7 @@ MetricManager::forceEventLogging() } void -MetricManager::reset(time_t currentTime) +MetricManager::reset(system_time currentTime) { time_point preTime = _timer->getTimeInMilliSecs(); // Resetting implies visiting metrics, which needs to grab metric lock @@ -733,21 +734,21 @@ MetricManager::run() // we constantly add next time to do something from the last timer. // For that to work, we need to initialize timers on first iteration // to set them to current time. - time_t currentTime = count_s(_timer->getTime().time_since_epoch()); + system_time currentTime = _timer->getTime(); for (auto & snapshot : _snapshots) { snapshot->setFromTime(currentTime); } for (auto hook : _periodicUpdateHooks) { - hook->_nextCall = currentTime; + hook->_nextCall = count_s(currentTime.time_since_epoch()); } // Ensure correct time for first snapshot _snapshots[0]->getSnapshot().setToTime(currentTime); while (!stop_requested()) { - time_point now = _timer->getTime(); - currentTime = count_s(now.time_since_epoch()); - time_t next = tick(sync, currentTime); - if (currentTime < next) { - vespalib::duration wait_time = from_s(next - currentTime); + currentTime = _timer->getTime(); + time_t currentTimeS = count_s(currentTime.time_since_epoch()); + time_t next = tick(sync, currentTimeS); + if (currentTimeS < next) { + vespalib::duration wait_time = from_s(next - currentTimeS); _cond.wait_for(sync, wait_time); _sleepTimes.addValue(count_ms(wait_time)); } else { @@ -772,7 +773,7 @@ MetricManager::tick(const MetricLockGuard & guard, time_t currentTime) checkMetricsAltered(guard); // Set next work time to the time we want to take next snapshot. - time_t nextWorkTime = _snapshots[0]->getToTime() + _snapshots[0]->getPeriod(); + time_t nextWorkTime = count_s(_snapshots[0]->getToTime().time_since_epoch()) + _snapshots[0]->getPeriod(); time_t nextUpdateHookTime; if (nextWorkTime <= currentTime) { // If taking a new snapshot or logging, force calls to all @@ -787,41 +788,40 @@ MetricManager::tick(const MetricLockGuard & guard, time_t currentTime) nextUpdateHookTime = updatePeriodicMetrics(guard, currentTime, false); } // Do snapshotting if it is time - if (nextWorkTime <= currentTime) takeSnapshots(guard, nextWorkTime); + if (nextWorkTime <= currentTime) takeSnapshots(guard, system_time(from_s(nextWorkTime))); _lastProcessedTime.store(nextWorkTime <= currentTime ? nextWorkTime : currentTime, std::memory_order_relaxed); LOG(spam, "Worker thread done with processing for time %" PRIu64 ".", static_cast<uint64_t>(_lastProcessedTime.load(std::memory_order_relaxed))); - time_t next = _snapshots[0]->getPeriod() + _snapshots[0]->getToTime(); + time_t next = count_s(_snapshots[0]->getToTime().time_since_epoch()) + _snapshots[0]->getPeriod(); next = std::min(next, nextUpdateHookTime); return next; } void -MetricManager::takeSnapshots(const MetricLockGuard & guard, time_t timeToProcess) +MetricManager::takeSnapshots(const MetricLockGuard & guard, system_time timeToProcess) { assertMetricLockLocked(guard); // If not time to do dump data from active snapshot yet, nothing to do if (!_snapshots[0]->timeForAnotherSnapshot(timeToProcess)) { - LOG(spam, "Not time to process snapshot %s at time %" PRIu64 ". Current " - "first period (%u) snapshot goes from %" PRIu64 " to %" PRIu64, - _snapshots[0]->getName().c_str(), static_cast<uint64_t>(timeToProcess), - _snapshots[0]->getPeriod(), static_cast<uint64_t>(_snapshots[0]->getFromTime()), - static_cast<uint64_t>(_snapshots[0]->getToTime())); + LOG(spam, "Not time to process snapshot %s at time %s. Current " + "first period (%u) snapshot goes from %s to %s", + _snapshots[0]->getName().c_str(), to_string(timeToProcess).c_str(), + _snapshots[0]->getPeriod(), to_string(_snapshots[0]->getFromTime()).c_str(), + to_string(_snapshots[0]->getToTime()).c_str()); return; } time_point preTime = _timer->getTimeInMilliSecs(); - LOG(debug, "Updating %s snapshot and total metrics at time %" PRIu64 ".", - _snapshots[0]->getName().c_str(), static_cast<uint64_t>(timeToProcess)); + LOG(debug, "Updating %s snapshot and total metrics at time %s.", + _snapshots[0]->getName().c_str(), to_string(timeToProcess).c_str()); MetricSnapshot& firstTarget(_snapshots[0]->getNextTarget()); firstTarget.reset(_activeMetrics.getFromTime()); _activeMetrics.addToSnapshot(firstTarget, false, timeToProcess); _activeMetrics.addToSnapshot(*_totalMetrics, false, timeToProcess); _activeMetrics.reset(timeToProcess); - LOG(debug, "After snapshotting, active metrics goes from %" PRIu64 " to %" PRIu64", " - "and 5 minute metrics goes from %" PRIu64 " to %" PRIu64".", - static_cast<uint64_t>(_activeMetrics.getFromTime()), static_cast<uint64_t>(_activeMetrics.getToTime()), - static_cast<uint64_t>(firstTarget.getFromTime()), static_cast<uint64_t>(firstTarget.getToTime())); + LOG(debug, "After snapshotting, active metrics goes from %s to %s, and 5 minute metrics goes from %s to %s.", + to_string(_activeMetrics.getFromTime()).c_str(), to_string(_activeMetrics.getToTime()).c_str(), + to_string(firstTarget.getFromTime()).c_str(), to_string(firstTarget.getToTime()).c_str()); // Update later snapshots if it is time for it for (uint32_t i=1; i<_snapshots.size(); ++i) { @@ -831,15 +831,15 @@ MetricManager::takeSnapshots(const MetricLockGuard & guard, time_t timeToProcess _snapshots[i-1]->getSnapshot().addToSnapshot(target, false, timeToProcess); target.setToTime(timeToProcess); if (!_snapshots[i]->haveCompletedNewPeriod(timeToProcess)) { - LOG(debug, "Not time to roll snapshot %s yet. %u of %u snapshot taken at time %" PRIu64 ", and period of %u " - "is not up yet as we're currently processing for time %" PRIu64 ".", + LOG(debug, "Not time to roll snapshot %s yet. %u of %u snapshot taken at time %s, and period of %u " + "is not up yet as we're currently processing for time %s.", _snapshots[i]->getName().c_str(), _snapshots[i]->getBuilderCount(), _snapshots[i]->getCount(), - static_cast<uint64_t>(_snapshots[i]->getBuilderCount() * _snapshots[i]->getPeriod() + _snapshots[i]->getFromTime()), - _snapshots[i]->getPeriod(), static_cast<uint64_t>(timeToProcess)); + to_string(_snapshots[i]->getBuilderCount() * from_s(_snapshots[i]->getPeriod()) + _snapshots[i]->getFromTime()).c_str(), + _snapshots[i]->getPeriod(), to_string(timeToProcess).c_str()); break; } else { - LOG(debug, "Rolled snapshot %s at time %" PRIu64 ".", - _snapshots[i]->getName().c_str(), static_cast<uint64_t>(timeToProcess)); + LOG(debug, "Rolled snapshot %s at time %s.", + _snapshots[i]->getName().c_str(), to_string(timeToProcess).c_str()); } } time_point postTime = _timer->getTimeInMilliSecs(); diff --git a/metrics/src/vespa/metrics/metricmanager.h b/metrics/src/vespa/metrics/metricmanager.h index c3ce37b451f..e793ef80b7f 100644 --- a/metrics/src/vespa/metrics/metricmanager.h +++ b/metrics/src/vespa/metrics/metricmanager.h @@ -191,7 +191,7 @@ public: * Reset all metrics including all snapshots. * This function can not be called from an update hook callback. */ - void reset(time_t currentTime); + void reset(system_time currentTime); /** * Read configuration. Before reading config, all metrics should be set @@ -267,7 +267,7 @@ public: bool isInitialized() const; private: - void takeSnapshots(const MetricLockGuard &, time_t timeToProcess); + void takeSnapshots(const MetricLockGuard &, system_time timeToProcess); friend struct MetricManagerTest; friend struct SnapshotTest; diff --git a/metrics/src/vespa/metrics/metricsnapshot.cpp b/metrics/src/vespa/metrics/metricsnapshot.cpp index 1580f340f0e..d8c87ce52d9 100644 --- a/metrics/src/vespa/metrics/metricsnapshot.cpp +++ b/metrics/src/vespa/metrics/metricsnapshot.cpp @@ -6,13 +6,18 @@ #include <vespa/log/log.h> LOG_SETUP(".metrics.snapshot"); +using vespalib::to_string; + + namespace metrics { +static constexpr system_time system_time_epoch = system_time(); + MetricSnapshot::MetricSnapshot(const Metric::String& name) : _name(name), _period(0), - _fromTime(0), - _toTime(0), + _fromTime(system_time_epoch), + _toTime(system_time_epoch), _snapshot(new MetricSet("top", {}, "", nullptr)), _metrics() { @@ -21,8 +26,8 @@ MetricSnapshot::MetricSnapshot(const Metric::String& name) MetricSnapshot::MetricSnapshot(const Metric::String& name, uint32_t period, const MetricSet& source, bool copyUnset) : _name(name), _period(period), - _fromTime(0), - _toTime(0), + _fromTime(system_time_epoch), + _toTime(system_time_epoch), _snapshot(), _metrics() { @@ -35,10 +40,14 @@ MetricSnapshot::MetricSnapshot(const Metric::String& name, uint32_t period, cons MetricSnapshot::~MetricSnapshot() = default; void -MetricSnapshot::reset(time_t currentTime) +MetricSnapshot::reset() { + reset(system_time_epoch); +} +void +MetricSnapshot::reset(system_time currentTime) { _fromTime = currentTime; - _toTime = 0; + _toTime = system_time_epoch; _snapshot->reset(); } @@ -61,22 +70,19 @@ MetricSnapshot::addMemoryUsage(MemoryConsumption& mc) const { ++mc._snapshotCount; mc._snapshotName += mc.getStringMemoryUsage(_name, mc._snapshotNameUnique); - mc._snapshotMeta += sizeof(MetricSnapshot) - + _metrics.capacity() * sizeof(Metric::SP); + mc._snapshotMeta += sizeof(MetricSnapshot) + _metrics.capacity() * sizeof(Metric::SP); _snapshot->addMemoryUsage(mc); } -MetricSnapshotSet::MetricSnapshotSet( - const Metric::String& name, uint32_t period, - uint32_t count, const MetricSet& source, bool snapshotUnsetMetrics) +MetricSnapshotSet::MetricSnapshotSet(const Metric::String& name, uint32_t period, uint32_t count, + const MetricSet& source, bool snapshotUnsetMetrics) : _count(count), _builderCount(0), - _current(new MetricSnapshot(name, period, source, snapshotUnsetMetrics)), - _building(count == 1 ? 0 : new MetricSnapshot( - name, period, source, snapshotUnsetMetrics)) + _current(std::make_unique<MetricSnapshot>(name, period, source, snapshotUnsetMetrics)), + _building(count == 1 ? nullptr : new MetricSnapshot(name, period, source, snapshotUnsetMetrics)) { - _current->reset(0); - if (_building.get()) _building->reset(0); + _current->reset(); + if (_building.get()) _building->reset(); } MetricSnapshot& @@ -87,16 +93,16 @@ MetricSnapshotSet::getNextTarget() } bool -MetricSnapshotSet::haveCompletedNewPeriod(time_t newFromTime) +MetricSnapshotSet::haveCompletedNewPeriod(system_time newFromTime) { if (_count == 1) { _current->setToTime(newFromTime); return true; } _building->setToTime(newFromTime); - // If not time to roll yet, just return + // If not time to roll yet, just return if (++_builderCount < _count) return false; - // Building buffer done. Use that as current and reset current. + // Building buffer done. Use that as current and reset current. MetricSnapshot::UP tmp(std::move(_current)); _current = std::move(_building); _building = std::move(tmp); @@ -106,16 +112,15 @@ MetricSnapshotSet::haveCompletedNewPeriod(time_t newFromTime) } bool -MetricSnapshotSet::timeForAnotherSnapshot(time_t currentTime) { - time_t lastTime = getToTime(); - if (currentTime >= lastTime + getPeriod()) { - if (currentTime >= lastTime + 2 * getPeriod()) { - LOG(warning, "Metric snapshot set %s was asked if it was time for " - "another snapshot, a whole period beyond when it " - "should have been done (Last update was at time %lu" - ", current time is %lu and period is %u). " - "Clearing data and updating time to current time.", - getName().c_str(), lastTime, currentTime, getPeriod()); +MetricSnapshotSet::timeForAnotherSnapshot(system_time currentTime) { + system_time lastTime = getToTime(); + vespalib::duration period = vespalib::from_s(getPeriod()); + if (currentTime >= lastTime + period) { + if (currentTime >= lastTime + 2 * period) { + LOG(warning, "Metric snapshot set %s was asked if it was time for another snapshot, a whole period beyond " + "when it should have been done (Last update was at time %s, current time is %s and period " + "is %u). Clearing data and updating time to current time.", + getName().c_str(), to_string(lastTime).c_str(), to_string(currentTime).c_str(), getPeriod()); reset(currentTime); } return true; @@ -124,7 +129,7 @@ MetricSnapshotSet::timeForAnotherSnapshot(time_t currentTime) { } void -MetricSnapshotSet::reset(time_t currentTime) { +MetricSnapshotSet::reset(system_time currentTime) { if (_count != 1) _building->reset(currentTime); _current->reset(currentTime); _builderCount = 0; @@ -147,7 +152,7 @@ MetricSnapshotSet::addMemoryUsage(MemoryConsumption& mc) const } void -MetricSnapshotSet::setFromTime(time_t fromTime) +MetricSnapshotSet::setFromTime(system_time fromTime) { if (_count != 1) _building->setFromTime(fromTime); _current->setFromTime(fromTime); diff --git a/metrics/src/vespa/metrics/metricsnapshot.h b/metrics/src/vespa/metrics/metricsnapshot.h index cc6ec4cbb2e..16b46760957 100644 --- a/metrics/src/vespa/metrics/metricsnapshot.h +++ b/metrics/src/vespa/metrics/metricsnapshot.h @@ -15,6 +15,8 @@ namespace metrics { +using system_time = vespalib::system_time; + class MetricManager; class MetricSnapshot @@ -23,9 +25,9 @@ class MetricSnapshot // Period length of this snapshot uint32_t _period; // Time this snapshot was last updated. - time_t _fromTime; + system_time _fromTime; // If set to 0, use _fromTime + _period. - time_t _toTime; + system_time _toTime; // Keeps the metrics set view of the snapshot std::unique_ptr<MetricSet> _snapshot; // Snapshots must own their own metrics @@ -42,27 +44,26 @@ public: const MetricSet& source, bool copyUnset); virtual ~MetricSnapshot(); - void addToSnapshot(MetricSnapshot& other, bool reset_, time_t currentTime) { + void addToSnapshot(MetricSnapshot& other, bool reset_, system_time currentTime) { _snapshot->addToSnapshot(other.getMetrics(), other._metrics); if (reset_) reset(currentTime); other._toTime = currentTime; } - void addToSnapshot(MetricSnapshot& other, time_t currentTime) const { + void addToSnapshot(MetricSnapshot& other, system_time currentTime) const { _snapshot->addToSnapshot(other.getMetrics(), other._metrics); other._toTime = currentTime; } - void setFromTime(time_t fromTime) { _fromTime = fromTime; } - void setToTime(time_t toTime) { _toTime = toTime; } + void setFromTime(system_time fromTime) { _fromTime = fromTime; } + void setToTime(system_time toTime) { _toTime = toTime; } const Metric::String& getName() const { return _name; } uint32_t getPeriod() const { return _period; } - time_t getFromTime() const { return _fromTime; } - time_t getToTime() const { return _toTime; } - time_t getLength() const - { return (_toTime != 0 ? _toTime - _fromTime : _fromTime + _period); } + system_time getFromTime() const { return _fromTime; } + system_time getToTime() const { return _toTime; } const MetricSet& getMetrics() const { return *_snapshot; } MetricSet& getMetrics() { return *_snapshot; } - void reset(time_t currentTime); + void reset(system_time currentTime); + void reset(); /** * Recreate snapshot by cloning given metric set and then add the data * from the old one. New metrics have been added. @@ -82,32 +83,32 @@ class MetricSnapshotSet { public: using SP = std::shared_ptr<MetricSnapshotSet>; - MetricSnapshotSet(const Metric::String& name, uint32_t period, - uint32_t count, const MetricSet& source, - bool snapshotUnsetMetrics); + MetricSnapshotSet(const Metric::String& name, uint32_t period, uint32_t count, + const MetricSet& source, bool snapshotUnsetMetrics); const Metric::String& getName() const { return _current->getName(); } uint32_t getPeriod() const { return _current->getPeriod(); } - time_t getFromTime() const { return _current->getFromTime(); } - time_t getToTime() const { return _current->getToTime(); } + system_time getFromTime() const { return _current->getFromTime(); } + system_time getToTime() const { return _current->getToTime(); } uint32_t getCount() const { return _count; } uint32_t getBuilderCount() const { return _builderCount; } - bool hasTemporarySnapshot() const { return (_building.get() != 0); } - MetricSnapshot& getSnapshot(bool temporary = false) - { return *((temporary && _count > 1) ? _building : _current); } - const MetricSnapshot& getSnapshot(bool temporary = false) const - { return *((temporary && _count > 1) ? _building : _current); } + MetricSnapshot& getSnapshot(bool temporary = false) { + return *((temporary && _count > 1) ? _building : _current); + } + const MetricSnapshot& getSnapshot(bool temporary = false) const { + return *((temporary && _count > 1) ? _building : _current); + } MetricSnapshot& getNextTarget(); - bool timeForAnotherSnapshot(time_t currentTime); - bool haveCompletedNewPeriod(time_t newFromTime); - void reset(time_t currentTime); + bool timeForAnotherSnapshot(system_time currentTime); + bool haveCompletedNewPeriod(system_time newFromTime); + void reset(system_time currentTime); /** * Recreate snapshot by cloning given metric set and then add the data * from the old one. New metrics have been added. */ void recreateSnapshot(const MetricSet& metrics, bool copyUnset); void addMemoryUsage(MemoryConsumption&) const; - void setFromTime(time_t fromTime); + void setFromTime(system_time fromTime); }; } // metrics diff --git a/metrics/src/vespa/metrics/state_api_adapter.cpp b/metrics/src/vespa/metrics/state_api_adapter.cpp index 61a1ce7c2a9..793267bfbf4 100644 --- a/metrics/src/vespa/metrics/state_api_adapter.cpp +++ b/metrics/src/vespa/metrics/state_api_adapter.cpp @@ -29,8 +29,8 @@ StateApiAdapter::getTotalMetrics(const vespalib::string &consumer) _manager.updateMetrics(true); metrics::MetricLockGuard guard(_manager.getMetricLock()); _manager.checkMetricsAltered(guard); - time_t currentTime = vespalib::count_s(vespalib::steady_clock::now().time_since_epoch()); - auto generated = std::make_unique<metrics::MetricSnapshot>( + system_time currentTime = vespalib::system_clock::now(); + auto generated = std::make_unique<metrics::MetricSnapshot>( "Total metrics from start until current time", 0, _manager.getTotalMetricSnapshot(guard).getMetrics(), true); diff --git a/metrics/src/vespa/metrics/textwriter.cpp b/metrics/src/vespa/metrics/textwriter.cpp index 94a7b7df73b..cc9a68f2b3d 100644 --- a/metrics/src/vespa/metrics/textwriter.cpp +++ b/metrics/src/vespa/metrics/textwriter.cpp @@ -7,6 +7,8 @@ #include "valuemetric.h" #include <sstream> +using vespalib::to_string; + namespace metrics { TextWriter::TextWriter(std::ostream& out, uint32_t period, @@ -19,13 +21,13 @@ TextWriter::TextWriter(std::ostream& out, uint32_t period, } } -TextWriter::~TextWriter() { } +TextWriter::~TextWriter() = default; bool TextWriter::visitSnapshot(const MetricSnapshot& snapshot) { _out << "snapshot \"" << snapshot.getName() << "\" from " - << snapshot.getFromTime() << " to " << snapshot.getToTime() + << to_string(snapshot.getFromTime()) << " to " << to_string(snapshot.getToTime()) << " period " << snapshot.getPeriod(); return true; } diff --git a/storage/src/vespa/storage/common/statusmetricconsumer.cpp b/storage/src/vespa/storage/common/statusmetricconsumer.cpp index c6f73540605..5998a2fe9a9 100644 --- a/storage/src/vespa/storage/common/statusmetricconsumer.cpp +++ b/storage/src/vespa/storage/common/statusmetricconsumer.cpp @@ -61,7 +61,7 @@ StatusMetricConsumer::reportStatus(std::ostream& out, } else { LOG(debug, "Not calling update hooks as dontcallupdatehooks option has been given"); } - int64_t currentTimeS(vespalib::count_s(_component.getClock().getMonotonicTime().time_since_epoch())); + vespalib::system_time currentTime = _component.getClock().getSystemTime(); bool json = (path.getAttribute("format") == "json"); int verbosity(path.get("verbosity", 0)); @@ -72,7 +72,7 @@ StatusMetricConsumer::reportStatus(std::ostream& out, if (path.hasAttribute("task") && path.getAttribute("task") == "reset") { std::lock_guard guard(_lock); - _manager.reset(currentTimeS); + _manager.reset(currentTime); } if (path.hasAttribute("interval")) { @@ -83,7 +83,7 @@ StatusMetricConsumer::reportStatus(std::ostream& out, const metrics::MetricSnapshot* snapshot; if (interval == -2) { snapshot = &_manager.getActiveMetrics(metricLock); - _manager.getActiveMetrics(metricLock).setToTime(currentTimeS); + _manager.getActiveMetrics(metricLock).setToTime(currentTime); } else if (interval == -1) { // "Prime" the metric structure by first fetching the set of active // metrics (complete with structure) and resetting these. This @@ -94,9 +94,9 @@ StatusMetricConsumer::reportStatus(std::ostream& out, "Total metrics from start until current time", 0, _manager.getActiveMetrics(metricLock).getMetrics(), copyUnset); - generated->reset(0); - _manager.getTotalMetricSnapshot(metricLock).addToSnapshot(*generated, currentTimeS); - _manager.getActiveMetrics(metricLock).addToSnapshot(*generated, currentTimeS); + generated->reset(); + _manager.getTotalMetricSnapshot(metricLock).addToSnapshot(*generated, currentTime); + _manager.getActiveMetrics(metricLock).addToSnapshot(*generated, currentTime); generated->setFromTime(_manager.getTotalMetricSnapshot(metricLock).getFromTime()); snapshot = generated.get(); } else if (interval == 0) { @@ -104,8 +104,8 @@ StatusMetricConsumer::reportStatus(std::ostream& out, generated = std::make_unique<metrics::MetricSnapshot>( _manager.getTotalMetricSnapshot(metricLock).getName(), 0, _manager.getActiveMetrics(metricLock).getMetrics(), true); - generated->reset(0); - _manager.getTotalMetricSnapshot(metricLock).addToSnapshot(*generated, currentTimeS); + generated->reset(); + _manager.getTotalMetricSnapshot(metricLock).addToSnapshot(*generated, currentTime); snapshot = generated.get(); } else { snapshot = &_manager.getTotalMetricSnapshot(metricLock); @@ -115,9 +115,9 @@ StatusMetricConsumer::reportStatus(std::ostream& out, generated = std::make_unique<metrics::MetricSnapshot>( _manager.getMetricSnapshot(metricLock, interval).getName(), 0, _manager.getActiveMetrics(metricLock).getMetrics(), true); - generated->reset(0); + generated->reset(); _manager.getMetricSnapshot(metricLock, interval, temporarySnap) - .addToSnapshot(*generated, currentTimeS); + .addToSnapshot(*generated, currentTime); snapshot = generated.get(); } else { snapshot = &_manager.getMetricSnapshot(metricLock, interval, temporarySnap); diff --git a/storage/src/vespa/storage/storageserver/statereporter.cpp b/storage/src/vespa/storage/storageserver/statereporter.cpp index 205a2d710a6..79746f2cd63 100644 --- a/storage/src/vespa/storage/storageserver/statereporter.cpp +++ b/storage/src/vespa/storage/storageserver/statereporter.cpp @@ -81,9 +81,8 @@ StateReporter::getMetrics(const vespalib::string &consumer) _manager.getMetricSnapshot(guard, interval).getName(), interval, _manager.getActiveMetrics(guard).getMetrics(), true); - snapshot.reset(0); - _manager.getMetricSnapshot(guard, interval).addToSnapshot( - snapshot, vespalib::count_s(_component.getClock().getSystemTime().time_since_epoch())); + snapshot.reset(); + _manager.getMetricSnapshot(guard, interval).addToSnapshot(snapshot, _component.getClock().getSystemTime()); vespalib::asciistream json; vespalib::JsonStream stream(json); |