Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions core/include/prometheus/gauge.h
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,8 @@ class PROMETHEUS_CPP_CORE_EXPORT Gauge {
private:
void Change(double);
std::atomic<double> value_{0.0};
std::atomic<std::chrono::system_clock::time_point> time_{
std::chrono::system_clock::now()};
std::atomic<std::chrono::system_clock::duration> time_{
std::chrono::system_clock::now().time_since_epoch()};
};

/// \brief Return a builder to configure and register a Gauge metric.
Expand Down
8 changes: 4 additions & 4 deletions core/src/gauge.cc
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ void Gauge::Decrement(const double value) { Change(-1.0 * value); }

void Gauge::Set(const double value) {
value_.store(value);
time_.store(std::chrono::system_clock::now());
time_.store(std::chrono::system_clock::now().time_since_epoch());
}

void Gauge::Change(const double value) {
Expand All @@ -25,7 +25,7 @@ void Gauge::Change(const double value) {
while (!value_.compare_exchange_weak(current, current + value)) {
// intentionally empty block
}
time_.store(std::chrono::system_clock::now());
time_.store(std::chrono::system_clock::now().time_since_epoch());
}

void Gauge::SetToCurrentTime() {
Expand All @@ -43,8 +43,8 @@ ClientMetric Gauge::Collect() const {

bool Gauge::Expired(const std::chrono::system_clock::time_point& time,
const std::chrono::seconds& ttl) const {
return std::chrono::duration_cast<std::chrono::seconds>(time -
time_.load()) >= ttl;
return std::chrono::duration_cast<std::chrono::seconds>(
time.time_since_epoch() - time_.load()) >= ttl;
}

} // namespace prometheus