]> git.proxmox.com Git - ceph.git/blob - ceph/src/jaegertracing/opentelemetry-cpp/third_party/prometheus-cpp/core/src/gauge.cc
update ceph source to reef 18.1.2
[ceph.git] / ceph / src / jaegertracing / opentelemetry-cpp / third_party / prometheus-cpp / core / src / gauge.cc
1 #include "prometheus/gauge.h"
2
3 #include <ctime>
4
5 namespace prometheus {
6
7 Gauge::Gauge(const double value) : value_{value} {}
8
9 void Gauge::Increment() { Increment(1.0); }
10
11 void Gauge::Increment(const double value) { Change(value); }
12
13 void Gauge::Decrement() { Decrement(1.0); }
14
15 void Gauge::Decrement(const double value) { Change(-1.0 * value); }
16
17 void Gauge::Set(const double value) { value_.store(value); }
18
19 void Gauge::Change(const double value) {
20 // C++ 20 will add std::atomic::fetch_add support for floating point types
21 auto current = value_.load();
22 while (!value_.compare_exchange_weak(current, current + value)) {
23 // intentionally empty block
24 }
25 }
26
27 void Gauge::SetToCurrentTime() {
28 const auto time = std::time(nullptr);
29 Set(static_cast<double>(time));
30 }
31
32 double Gauge::Value() const { return value_; }
33
34 ClientMetric Gauge::Collect() const {
35 ClientMetric metric;
36 metric.gauge.value = Value();
37 return metric;
38 }
39
40 } // namespace prometheus