From 1f3a03e931197c6bb35e297680e8ec1c57350c04 Mon Sep 17 00:00:00 2001 From: Artem Kharytoniuk Date: Thu, 10 Jul 2025 12:25:09 +0200 Subject: [PATCH] new approximation for merged peak stats --- src/stats.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/stats.c b/src/stats.c index 03eafb66..9714d6a8 100644 --- a/src/stats.c +++ b/src/stats.c @@ -86,11 +86,16 @@ void _mi_stat_adjust_decrease(mi_stat_count_t* stat, size_t amount) { static void mi_stat_count_add_mt(mi_stat_count_t* stat, const mi_stat_count_t* src) { if (stat==src) return; mi_atomic_void_addi64_relaxed(&stat->total, &src->total); - mi_atomic_void_addi64_relaxed(&stat->current, &src->current); + + int64_t prev_current = mi_atomic_addi64_relaxed(&stat->current, src->current); + // peak scores do really not work across threads .. we just add them - mi_atomic_void_addi64_relaxed( &stat->peak, &src->peak); + //mi_atomic_void_addi64_relaxed( &stat->peak, &src->peak); // or, take the max? // mi_atomic_maxi64_relaxed(&stat->peak, src->peak); + + // global current plus thread peak approximates new global peak + mi_atomic_maxi64_relaxed(&stat->peak, prev_current + src->peak); } static void mi_stat_counter_add_mt(mi_stat_counter_t* stat, const mi_stat_counter_t* src) {