Add more TODOs
This commit is contained in:
@@ -105,8 +105,6 @@ template <> struct hash<metric::LabelsKey> {
|
|||||||
|
|
||||||
namespace metric {
|
namespace metric {
|
||||||
|
|
||||||
using AtomicWord = std::atomic<uint64_t>;
|
|
||||||
|
|
||||||
// DESIGN: Store doubles in atomic<uint64_t> for lock-free operations
|
// DESIGN: Store doubles in atomic<uint64_t> for lock-free operations
|
||||||
// - Preserves full IEEE 754 double precision (no truncation)
|
// - Preserves full IEEE 754 double precision (no truncation)
|
||||||
// - Allows atomic load/store without locks
|
// - Allows atomic load/store without locks
|
||||||
@@ -154,9 +152,10 @@ struct Counter::State {
|
|||||||
friend struct Metric;
|
friend struct Metric;
|
||||||
};
|
};
|
||||||
|
|
||||||
// Gauge: Global, can increase/decrease, multiple writers (uses atomic CAS)
|
// Gauge: Global, can increase/decrease, multiple writers (uses atomic CAS).
|
||||||
|
// TODO slow under contention.
|
||||||
struct Gauge::State {
|
struct Gauge::State {
|
||||||
AtomicWord value; // Stores double as uint64_t bits, lock-free
|
std::atomic<uint64_t> value; // Stores double as uint64_t bits, lock-free
|
||||||
friend struct Metric;
|
friend struct Metric;
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -166,8 +165,10 @@ struct Histogram::State {
|
|||||||
thresholds; // Bucket boundaries (sorted, deduplicated, includes +Inf)
|
thresholds; // Bucket boundaries (sorted, deduplicated, includes +Inf)
|
||||||
std::vector<uint64_t> counts; // Count per bucket - single writer, malloc
|
std::vector<uint64_t> counts; // Count per bucket - single writer, malloc
|
||||||
// provides 16-byte alignment
|
// provides 16-byte alignment
|
||||||
AtomicWord sum; // Sum of observations (double stored as uint64_t bits)
|
// TODO this should just be a double like in counter
|
||||||
AtomicWord observations; // Total observation count (uint64_t)
|
std::atomic<uint64_t>
|
||||||
|
sum; // Sum of observations (double stored as uint64_t bits)
|
||||||
|
std::atomic<uint64_t> observations; // Total observation count (uint64_t)
|
||||||
friend struct Metric;
|
friend struct Metric;
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -190,7 +191,10 @@ struct Metric {
|
|||||||
// Thread registration happens lazily when metrics are created
|
// Thread registration happens lazily when metrics are created
|
||||||
}
|
}
|
||||||
~ThreadInit() {
|
~ThreadInit() {
|
||||||
// Clean up this thread's storage from all families
|
// TODO we need to accumulate this threads counts into a global. Otherwise
|
||||||
|
// it can go backwards when we destroy a thread.
|
||||||
|
|
||||||
|
// Clean up this thread's storage from all families
|
||||||
std::unique_lock<std::mutex> _{mutex};
|
std::unique_lock<std::mutex> _{mutex};
|
||||||
auto thread_id = std::this_thread::get_id();
|
auto thread_id = std::this_thread::get_id();
|
||||||
|
|
||||||
@@ -375,6 +379,8 @@ update_histogram_buckets(const std::vector<double> &thresholds,
|
|||||||
: "x"(updated_counts) // Input: xmm register
|
: "x"(updated_counts) // Input: xmm register
|
||||||
: "memory" // Memory clobber
|
: "memory" // Memory clobber
|
||||||
);
|
);
|
||||||
|
// We don't actually need it to be atomic across 128-bits, but that's
|
||||||
|
// sufficient to guarantee each 64 bit half is atomic.
|
||||||
}
|
}
|
||||||
|
|
||||||
// Handle remainder with atomic stores
|
// Handle remainder with atomic stores
|
||||||
|
|||||||
Reference in New Issue
Block a user