aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorHenning Baldersheim <balder@yahoo-inc.com>2023-03-01 17:56:51 +0100
committerGitHub <noreply@github.com>2023-03-01 17:56:51 +0100
commitb6d95fabbb3fbd85b6a572da5473a3204678d2d3 (patch)
treedfc07974f1fc8f3e00862b49908c671c4d5739f4
parentd17de6e8eae213f9e71c7fddb5b3876ff1d0a58b (diff)
Revert "Balder/enforce system time for snapshot"
-rw-r--r--metrics/src/tests/metricmanagertest.cpp14
-rw-r--r--metrics/src/tests/summetrictest.cpp5
-rw-r--r--metrics/src/vespa/metrics/jsonwriter.cpp4
-rw-r--r--metrics/src/vespa/metrics/metricmanager.cpp66
-rw-r--r--metrics/src/vespa/metrics/metricmanager.h4
-rw-r--r--metrics/src/vespa/metrics/metricsnapshot.cpp67
-rw-r--r--metrics/src/vespa/metrics/metricsnapshot.h51
-rw-r--r--metrics/src/vespa/metrics/state_api_adapter.cpp4
-rw-r--r--metrics/src/vespa/metrics/textwriter.cpp6
-rw-r--r--storage/src/vespa/storage/common/statusmetricconsumer.cpp20
-rw-r--r--storage/src/vespa/storage/storageserver/statereporter.cpp5
11 files changed, 121 insertions, 125 deletions
diff --git a/metrics/src/tests/metricmanagertest.cpp b/metrics/src/tests/metricmanagertest.cpp
index e398e252a36..6d6f21ea7b0 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(), 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(system_time(1000s));
+ mm.reset(1000);
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 1970-01-01 00:16:40.000 UTC to 1970-01-01 00:00:00.000 UTC period 0\n"
+ "snapshot \"Active metrics showing updates since last snapshot\" from 1000 to 0 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,9 +938,11 @@ TEST_F(MetricManagerTest, text_output_supports_dimensions)
fixture.takeSnapshotsOnce();
std::string actual = fixture.renderLastSnapshotAsText("outer.*temp.*val");
std::string expected(
- "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");
+ "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");
EXPECT_EQ(expected, actual);
}
diff --git a/metrics/src/tests/summetrictest.cpp b/metrics/src/tests/summetrictest.cpp
index 8e988b65b96..09495ff038d 100644
--- a/metrics/src/tests/summetrictest.cpp
+++ b/metrics/src/tests/summetrictest.cpp
@@ -104,7 +104,8 @@ 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);
@@ -114,7 +115,7 @@ TEST(SumMetricTest, test_start_value)
MetricSnapshot copy("copy");
copy.recreateSnapshot(snapshot.getMetrics(), true);
- snapshot.addToSnapshot(copy, system_time(100s));
+ snapshot.addToSnapshot(copy, 100);
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 0c9ed306ec9..c0d227b8f5a 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" << vespalib::count_s(snapshot.getFromTime().time_since_epoch())
- << "to" << vespalib::count_s(snapshot.getToTime().time_since_epoch())
+ << "from" << snapshot.getFromTime()
+ << "to" << snapshot.getToTime()
<< End()
<< "values" << Array();
_flag = SNAPSHOT_STARTED;
diff --git a/metrics/src/vespa/metrics/metricmanager.cpp b/metrics/src/vespa/metrics/metricmanager.cpp
index 52dca20694f..df83001a4e2 100644
--- a/metrics/src/vespa/metrics/metricmanager.cpp
+++ b/metrics/src/vespa/metrics/metricmanager.cpp
@@ -28,7 +28,6 @@ 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;
@@ -465,9 +464,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_point currentTime = _timer->getTime();
+ // 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());
_activeMetrics.setFromTime(currentTime);
uint32_t count = 1;
for (uint32_t i = 0; i< snapshotPeriods.size(); ++i) {
@@ -483,7 +482,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);
}
@@ -710,7 +709,7 @@ MetricManager::forceEventLogging()
}
void
-MetricManager::reset(system_time currentTime)
+MetricManager::reset(time_t currentTime)
{
time_point preTime = _timer->getTimeInMilliSecs();
// Resetting implies visiting metrics, which needs to grab metric lock
@@ -734,21 +733,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.
- system_time currentTime = _timer->getTime();
+ time_t currentTime = count_s(_timer->getTime().time_since_epoch());
for (auto & snapshot : _snapshots) {
snapshot->setFromTime(currentTime);
}
for (auto hook : _periodicUpdateHooks) {
- hook->_nextCall = count_s(currentTime.time_since_epoch());
+ hook->_nextCall = currentTime;
}
// Ensure correct time for first snapshot
_snapshots[0]->getSnapshot().setToTime(currentTime);
while (!stop_requested()) {
- 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);
+ 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);
_cond.wait_for(sync, wait_time);
_sleepTimes.addValue(count_ms(wait_time));
} else {
@@ -773,7 +772,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 = count_s(_snapshots[0]->getToTime().time_since_epoch()) + _snapshots[0]->getPeriod();
+ time_t nextWorkTime = _snapshots[0]->getToTime() + _snapshots[0]->getPeriod();
time_t nextUpdateHookTime;
if (nextWorkTime <= currentTime) {
// If taking a new snapshot or logging, force calls to all
@@ -788,40 +787,41 @@ MetricManager::tick(const MetricLockGuard & guard, time_t currentTime)
nextUpdateHookTime = updatePeriodicMetrics(guard, currentTime, false);
}
// Do snapshotting if it is time
- if (nextWorkTime <= currentTime) takeSnapshots(guard, system_time(from_s(nextWorkTime)));
+ if (nextWorkTime <= currentTime) takeSnapshots(guard, 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 = count_s(_snapshots[0]->getToTime().time_since_epoch()) + _snapshots[0]->getPeriod();
+ time_t next = _snapshots[0]->getPeriod() + _snapshots[0]->getToTime();
next = std::min(next, nextUpdateHookTime);
return next;
}
void
-MetricManager::takeSnapshots(const MetricLockGuard & guard, system_time timeToProcess)
+MetricManager::takeSnapshots(const MetricLockGuard & guard, time_t 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 %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());
+ 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()));
return;
}
time_point preTime = _timer->getTimeInMilliSecs();
- LOG(debug, "Updating %s snapshot and total metrics at time %s.",
- _snapshots[0]->getName().c_str(), to_string(timeToProcess).c_str());
+ LOG(debug, "Updating %s snapshot and total metrics at time %" PRIu64 ".",
+ _snapshots[0]->getName().c_str(), static_cast<uint64_t>(timeToProcess));
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 %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());
+ 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()));
// 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, system_time timeToPr
_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 %s, and period of %u "
- "is not up yet as we're currently processing for time %s.",
+ 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 ".",
_snapshots[i]->getName().c_str(), _snapshots[i]->getBuilderCount(), _snapshots[i]->getCount(),
- to_string(_snapshots[i]->getBuilderCount() * from_s(_snapshots[i]->getPeriod()) + _snapshots[i]->getFromTime()).c_str(),
- _snapshots[i]->getPeriod(), to_string(timeToProcess).c_str());
+ static_cast<uint64_t>(_snapshots[i]->getBuilderCount() * _snapshots[i]->getPeriod() + _snapshots[i]->getFromTime()),
+ _snapshots[i]->getPeriod(), static_cast<uint64_t>(timeToProcess));
break;
} else {
- LOG(debug, "Rolled snapshot %s at time %s.",
- _snapshots[i]->getName().c_str(), to_string(timeToProcess).c_str());
+ LOG(debug, "Rolled snapshot %s at time %" PRIu64 ".",
+ _snapshots[i]->getName().c_str(), static_cast<uint64_t>(timeToProcess));
}
}
time_point postTime = _timer->getTimeInMilliSecs();
diff --git a/metrics/src/vespa/metrics/metricmanager.h b/metrics/src/vespa/metrics/metricmanager.h
index e793ef80b7f..c3ce37b451f 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(system_time currentTime);
+ void reset(time_t currentTime);
/**
* Read configuration. Before reading config, all metrics should be set
@@ -267,7 +267,7 @@ public:
bool isInitialized() const;
private:
- void takeSnapshots(const MetricLockGuard &, system_time timeToProcess);
+ void takeSnapshots(const MetricLockGuard &, time_t timeToProcess);
friend struct MetricManagerTest;
friend struct SnapshotTest;
diff --git a/metrics/src/vespa/metrics/metricsnapshot.cpp b/metrics/src/vespa/metrics/metricsnapshot.cpp
index d8c87ce52d9..1580f340f0e 100644
--- a/metrics/src/vespa/metrics/metricsnapshot.cpp
+++ b/metrics/src/vespa/metrics/metricsnapshot.cpp
@@ -6,18 +6,13 @@
#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(system_time_epoch),
- _toTime(system_time_epoch),
+ _fromTime(0),
+ _toTime(0),
_snapshot(new MetricSet("top", {}, "", nullptr)),
_metrics()
{
@@ -26,8 +21,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(system_time_epoch),
- _toTime(system_time_epoch),
+ _fromTime(0),
+ _toTime(0),
_snapshot(),
_metrics()
{
@@ -40,14 +35,10 @@ MetricSnapshot::MetricSnapshot(const Metric::String& name, uint32_t period, cons
MetricSnapshot::~MetricSnapshot() = default;
void
-MetricSnapshot::reset() {
- reset(system_time_epoch);
-}
-void
-MetricSnapshot::reset(system_time currentTime)
+MetricSnapshot::reset(time_t currentTime)
{
_fromTime = currentTime;
- _toTime = system_time_epoch;
+ _toTime = 0;
_snapshot->reset();
}
@@ -70,19 +61,22 @@ 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(std::make_unique<MetricSnapshot>(name, period, source, snapshotUnsetMetrics)),
- _building(count == 1 ? nullptr : new MetricSnapshot(name, period, source, snapshotUnsetMetrics))
+ _current(new MetricSnapshot(name, period, source, snapshotUnsetMetrics)),
+ _building(count == 1 ? 0 : new MetricSnapshot(
+ name, period, source, snapshotUnsetMetrics))
{
- _current->reset();
- if (_building.get()) _building->reset();
+ _current->reset(0);
+ if (_building.get()) _building->reset(0);
}
MetricSnapshot&
@@ -93,16 +87,16 @@ MetricSnapshotSet::getNextTarget()
}
bool
-MetricSnapshotSet::haveCompletedNewPeriod(system_time newFromTime)
+MetricSnapshotSet::haveCompletedNewPeriod(time_t 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);
@@ -112,15 +106,16 @@ MetricSnapshotSet::haveCompletedNewPeriod(system_time newFromTime)
}
bool
-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());
+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());
reset(currentTime);
}
return true;
@@ -129,7 +124,7 @@ MetricSnapshotSet::timeForAnotherSnapshot(system_time currentTime) {
}
void
-MetricSnapshotSet::reset(system_time currentTime) {
+MetricSnapshotSet::reset(time_t currentTime) {
if (_count != 1) _building->reset(currentTime);
_current->reset(currentTime);
_builderCount = 0;
@@ -152,7 +147,7 @@ MetricSnapshotSet::addMemoryUsage(MemoryConsumption& mc) const
}
void
-MetricSnapshotSet::setFromTime(system_time fromTime)
+MetricSnapshotSet::setFromTime(time_t 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 16b46760957..cc6ec4cbb2e 100644
--- a/metrics/src/vespa/metrics/metricsnapshot.h
+++ b/metrics/src/vespa/metrics/metricsnapshot.h
@@ -15,8 +15,6 @@
namespace metrics {
-using system_time = vespalib::system_time;
-
class MetricManager;
class MetricSnapshot
@@ -25,9 +23,9 @@ class MetricSnapshot
// Period length of this snapshot
uint32_t _period;
// Time this snapshot was last updated.
- system_time _fromTime;
+ time_t _fromTime;
// If set to 0, use _fromTime + _period.
- system_time _toTime;
+ time_t _toTime;
// Keeps the metrics set view of the snapshot
std::unique_ptr<MetricSet> _snapshot;
// Snapshots must own their own metrics
@@ -44,26 +42,27 @@ public:
const MetricSet& source, bool copyUnset);
virtual ~MetricSnapshot();
- void addToSnapshot(MetricSnapshot& other, bool reset_, system_time currentTime) {
+ void addToSnapshot(MetricSnapshot& other, bool reset_, time_t currentTime) {
_snapshot->addToSnapshot(other.getMetrics(), other._metrics);
if (reset_) reset(currentTime);
other._toTime = currentTime;
}
- void addToSnapshot(MetricSnapshot& other, system_time currentTime) const {
+ void addToSnapshot(MetricSnapshot& other, time_t currentTime) const {
_snapshot->addToSnapshot(other.getMetrics(), other._metrics);
other._toTime = currentTime;
}
- void setFromTime(system_time fromTime) { _fromTime = fromTime; }
- void setToTime(system_time toTime) { _toTime = toTime; }
+ void setFromTime(time_t fromTime) { _fromTime = fromTime; }
+ void setToTime(time_t toTime) { _toTime = toTime; }
const Metric::String& getName() const { return _name; }
uint32_t getPeriod() const { return _period; }
- system_time getFromTime() const { return _fromTime; }
- system_time getToTime() const { return _toTime; }
+ time_t getFromTime() const { return _fromTime; }
+ time_t getToTime() const { return _toTime; }
+ time_t getLength() const
+ { return (_toTime != 0 ? _toTime - _fromTime : _fromTime + _period); }
const MetricSet& getMetrics() const { return *_snapshot; }
MetricSet& getMetrics() { return *_snapshot; }
- void reset(system_time currentTime);
- void reset();
+ void reset(time_t currentTime);
/**
* Recreate snapshot by cloning given metric set and then add the data
* from the old one. New metrics have been added.
@@ -83,32 +82,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(); }
- system_time getFromTime() const { return _current->getFromTime(); }
- system_time getToTime() const { return _current->getToTime(); }
+ time_t getFromTime() const { return _current->getFromTime(); }
+ time_t getToTime() const { return _current->getToTime(); }
uint32_t getCount() const { return _count; }
uint32_t getBuilderCount() const { return _builderCount; }
- MetricSnapshot& getSnapshot(bool temporary = false) {
- return *((temporary && _count > 1) ? _building : _current);
- }
- const MetricSnapshot& getSnapshot(bool temporary = false) const {
- return *((temporary && _count > 1) ? _building : _current);
- }
+ 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& getNextTarget();
- bool timeForAnotherSnapshot(system_time currentTime);
- bool haveCompletedNewPeriod(system_time newFromTime);
- void reset(system_time currentTime);
+ bool timeForAnotherSnapshot(time_t currentTime);
+ bool haveCompletedNewPeriod(time_t newFromTime);
+ void reset(time_t 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(system_time fromTime);
+ void setFromTime(time_t fromTime);
};
} // metrics
diff --git a/metrics/src/vespa/metrics/state_api_adapter.cpp b/metrics/src/vespa/metrics/state_api_adapter.cpp
index 793267bfbf4..61a1ce7c2a9 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);
- system_time currentTime = vespalib::system_clock::now();
- auto generated = std::make_unique<metrics::MetricSnapshot>(
+ 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(),
true);
diff --git a/metrics/src/vespa/metrics/textwriter.cpp b/metrics/src/vespa/metrics/textwriter.cpp
index cc9a68f2b3d..94a7b7df73b 100644
--- a/metrics/src/vespa/metrics/textwriter.cpp
+++ b/metrics/src/vespa/metrics/textwriter.cpp
@@ -7,8 +7,6 @@
#include "valuemetric.h"
#include <sstream>
-using vespalib::to_string;
-
namespace metrics {
TextWriter::TextWriter(std::ostream& out, uint32_t period,
@@ -21,13 +19,13 @@ TextWriter::TextWriter(std::ostream& out, uint32_t period,
}
}
-TextWriter::~TextWriter() = default;
+TextWriter::~TextWriter() { }
bool
TextWriter::visitSnapshot(const MetricSnapshot& snapshot)
{
_out << "snapshot \"" << snapshot.getName() << "\" from "
- << to_string(snapshot.getFromTime()) << " to " << to_string(snapshot.getToTime())
+ << snapshot.getFromTime() << " to " << 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 5998a2fe9a9..c6f73540605 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");
}
- vespalib::system_time currentTime = _component.getClock().getSystemTime();
+ int64_t currentTimeS(vespalib::count_s(_component.getClock().getMonotonicTime().time_since_epoch()));
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(currentTime);
+ _manager.reset(currentTimeS);
}
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(currentTime);
+ _manager.getActiveMetrics(metricLock).setToTime(currentTimeS);
} 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();
- _manager.getTotalMetricSnapshot(metricLock).addToSnapshot(*generated, currentTime);
- _manager.getActiveMetrics(metricLock).addToSnapshot(*generated, currentTime);
+ generated->reset(0);
+ _manager.getTotalMetricSnapshot(metricLock).addToSnapshot(*generated, currentTimeS);
+ _manager.getActiveMetrics(metricLock).addToSnapshot(*generated, currentTimeS);
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();
- _manager.getTotalMetricSnapshot(metricLock).addToSnapshot(*generated, currentTime);
+ generated->reset(0);
+ _manager.getTotalMetricSnapshot(metricLock).addToSnapshot(*generated, currentTimeS);
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();
+ generated->reset(0);
_manager.getMetricSnapshot(metricLock, interval, temporarySnap)
- .addToSnapshot(*generated, currentTime);
+ .addToSnapshot(*generated, currentTimeS);
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 79746f2cd63..205a2d710a6 100644
--- a/storage/src/vespa/storage/storageserver/statereporter.cpp
+++ b/storage/src/vespa/storage/storageserver/statereporter.cpp
@@ -81,8 +81,9 @@ StateReporter::getMetrics(const vespalib::string &consumer)
_manager.getMetricSnapshot(guard, interval).getName(), interval,
_manager.getActiveMetrics(guard).getMetrics(), true);
- snapshot.reset();
- _manager.getMetricSnapshot(guard, interval).addToSnapshot(snapshot, _component.getClock().getSystemTime());
+ snapshot.reset(0);
+ _manager.getMetricSnapshot(guard, interval).addToSnapshot(
+ snapshot, vespalib::count_s(_component.getClock().getSystemTime().time_since_epoch()));
vespalib::asciistream json;
vespalib::JsonStream stream(json);