From f560ac1736d67d0f543b8fae7aba10e8cfda8594 Mon Sep 17 00:00:00 2001 From: Andrew Noyes Date: Sat, 30 Aug 2025 18:59:44 -0400 Subject: [PATCH] Use snake_case --- src/metric.cpp | 42 +++++++++++++++++++++--------------------- 1 file changed, 21 insertions(+), 21 deletions(-) diff --git a/src/metric.cpp b/src/metric.cpp index f131bcf..a0f9c2f 100644 --- a/src/metric.cpp +++ b/src/metric.cpp @@ -126,11 +126,11 @@ template <> struct Family::State { struct PerThreadState { std::unordered_map> instances; }; - std::unordered_map perThreadState; + std::unordered_map per_thread_state; // Global accumulation state for destroyed threads std::unordered_map> - globalAccumulatedValues; + global_accumulated_values; // Callback-based metrics (global, not per-thread) std::unordered_map> callbacks; @@ -153,11 +153,11 @@ template <> struct Family::State { struct PerThreadState { std::unordered_map> instances; }; - std::unordered_map perThreadState; + std::unordered_map per_thread_state; // Global accumulation state for destroyed threads std::unordered_map> - globalAccumulatedValues; + global_accumulated_values; // Note: No callbacks map - histograms don't support callback-based metrics }; @@ -225,14 +225,14 @@ struct Metric { // Accumulate counter families for (auto &[name, family] : Metric::get_counter_families()) { - auto thread_it = family->perThreadState.find(thread_id); - if (thread_it != family->perThreadState.end()) { + auto thread_it = family->per_thread_state.find(thread_id); + if (thread_it != family->per_thread_state.end()) { for (auto &[labels_key, instance] : thread_it->second.instances) { // Get current thread-local value double current_value = instance->value; // Ensure global accumulator exists - auto &global_state = family->globalAccumulatedValues[labels_key]; + auto &global_state = family->global_accumulated_values[labels_key]; if (!global_state) { global_state = std::make_unique(); global_state->value = 0.0; @@ -241,20 +241,20 @@ struct Metric { // Add thread-local value to global accumulator (mutex already held) global_state->value += current_value; } - family->perThreadState.erase(thread_it); + family->per_thread_state.erase(thread_it); } } // Accumulate histogram families for (auto &[name, family] : Metric::get_histogram_families()) { - auto thread_it = family->perThreadState.find(thread_id); - if (thread_it != family->perThreadState.end()) { + auto thread_it = family->per_thread_state.find(thread_id); + if (thread_it != family->per_thread_state.end()) { for (auto &[labels_key, instance] : thread_it->second.instances) { // Acquire lock to get consistent snapshot std::lock_guard lock(instance->mutex); // Ensure global accumulator exists - auto &global_state = family->globalAccumulatedValues[labels_key]; + auto &global_state = family->global_accumulated_values[labels_key]; if (!global_state) { global_state = std::make_unique(); global_state->thresholds = instance->thresholds; @@ -273,7 +273,7 @@ struct Metric { global_state->sum += instance->sum; global_state->observations += instance->observations; } - family->perThreadState.erase(thread_it); + family->per_thread_state.erase(thread_it); } } @@ -300,13 +300,13 @@ struct Metric { key.labels.empty() ? "(no labels)" : key.labels[0].first.c_str()); auto &ptr = - family->p->perThreadState[std::this_thread::get_id()].instances[key]; + family->p->per_thread_state[std::this_thread::get_id()].instances[key]; if (!ptr) { ptr = std::make_unique(); ptr->value = 0.0; // Ensure global accumulator exists for this label set - auto &global_state = family->p->globalAccumulatedValues[key]; + auto &global_state = family->p->global_accumulated_values[key]; if (!global_state) { global_state = std::make_unique(); global_state->value = 0.0; @@ -348,7 +348,7 @@ struct Metric { std::unique_lock _{mutex}; LabelsKey key{labels}; auto &ptr = - family->p->perThreadState[std::this_thread::get_id()].instances[key]; + family->p->per_thread_state[std::this_thread::get_id()].instances[key]; if (!ptr) { ptr = std::make_unique(); // DESIGN: Prometheus-compatible histogram buckets @@ -361,7 +361,7 @@ struct Metric { ptr->observations = 0; // Ensure global accumulator exists for this label set - auto &global_state = family->p->globalAccumulatedValues[key]; + auto &global_state = family->p->global_accumulated_values[key]; if (!global_state) { global_state = std::make_unique(); global_state->thresholds = ptr->thresholds; @@ -756,7 +756,7 @@ std::span render(ArenaAllocator &arena) { std::unordered_map aggregated_values; // First, add thread-local values - for (const auto &[thread_id, per_thread] : family->perThreadState) { + for (const auto &[thread_id, per_thread] : family->per_thread_state) { for (const auto &[labels_key, instance] : per_thread.instances) { // Atomic read to match atomic store in Counter::inc() double value; @@ -767,7 +767,7 @@ std::span render(ArenaAllocator &arena) { // Then, add globally accumulated values from destroyed threads for (const auto &[labels_key, global_state] : - family->globalAccumulatedValues) { + family->global_accumulated_values) { if (global_state) { aggregated_values[labels_key] += global_state->value; } @@ -834,7 +834,7 @@ std::span render(ArenaAllocator &arena) { std::vector> bucket_labels_sv; // First, collect thread-local histogram data - for (const auto &[thread_id, per_thread] : family->perThreadState) { + for (const auto &[thread_id, per_thread] : family->per_thread_state) { for (const auto &[labels_key, instance] : per_thread.instances) { // Extract data under lock - minimize critical section // Pre-allocate vectors to avoid malloc inside critical section @@ -881,7 +881,7 @@ std::span render(ArenaAllocator &arena) { // Then, add globally accumulated values from destroyed threads for (const auto &[labels_key, global_state] : - family->globalAccumulatedValues) { + family->global_accumulated_values) { if (global_state) { auto &[thresholds, counts, sum, observations] = aggregated_histograms[labels_key]; @@ -963,7 +963,7 @@ void Family::register_callback( LabelsKey key{std::move(labels)}; // Validate that labels aren't already in use by create() calls - for (const auto &[thread_id, per_thread] : p->perThreadState) { + for (const auto &[thread_id, per_thread] : p->per_thread_state) { validate_or_abort( per_thread.instances.find(key) == per_thread.instances.end(), "labels already registered as static instance",