Measure per metric in render scale bench

This commit is contained in:
2025-09-03 12:51:49 -04:00
parent 52b0cb3e6e
commit 0ac4c31a53
2 changed files with 40 additions and 62 deletions

View File

@@ -1695,30 +1695,26 @@ void reset_metrics_for_testing() {
std::lock_guard _{Metric::mutex};
++Metric::registration_version;
// WARNING: This function assumes no metric objects are in use!
// Clear all family maps - this will leak the Family::State objects but
// that's acceptable for testing since they were allocated in the global arena
Metric::get_counter_families().clear();
Metric::get_gauge_families().clear();
Metric::get_histogram_families().clear();
Metric::get_interned_labels().clear();
Metric::get_interned_static_text().clear();
// Get references to the maps
auto &counter_families = Metric::get_counter_families();
auto &gauge_families = Metric::get_gauge_families();
auto &histogram_families = Metric::get_histogram_families();
auto &interned_labels = Metric::get_interned_labels();
// Clear all family registrations
counter_families.clear();
gauge_families.clear();
histogram_families.clear();
interned_labels.clear();
// Clear interned static text
auto &interned_static_text = Metric::get_interned_static_text();
interned_static_text.clear();
// Reset the global arena - this will invalidate all arena-allocated strings
// but since we're clearing everything, that's OK
Metric::get_global_arena().reset();
auto reset_arena = [](auto &m) {
using M = std::decay_t<decltype(m)>;
using A = M::allocator_type;
m = M{A{&Metric::get_global_arena()}};
};
reset_arena(Metric::get_counter_families());
reset_arena(Metric::get_gauge_families());
reset_arena(Metric::get_histogram_families());
reset_arena(Metric::get_interned_labels());
reset_arena(Metric::get_interned_static_text());
// Note: Thread-local arenas will be cleaned up by ThreadInit destructors
// when threads exit naturally
}