From f5f29e1c59f4f3430b3fb95f0b1bb7638a65540a Mon Sep 17 00:00:00 2001 From: Richard Fuchs Date: Tue, 31 Aug 2021 15:56:11 -0400 Subject: [PATCH] TT#101150 add min/max/avg tracking for gauge stats Change-Id: I6a682f2bb98673361a8454f419f8a0fb7d37ef75 --- daemon/call.c | 2 ++ include/call.h | 5 ++++- include/statistics.h | 15 +++++++++++++++ 3 files changed, 21 insertions(+), 1 deletion(-) diff --git a/daemon/call.c b/daemon/call.c index 27d74d49f..32700d8b7 100644 --- a/daemon/call.c +++ b/daemon/call.c @@ -64,6 +64,8 @@ struct xmlrpc_helper { struct global_stats_gauge rtpe_stats_gauge; +struct global_stats_gauge_min_max rtpe_stats_gauge_graphite_min_max; + struct global_stats_ax rtpe_stats; struct global_stats_counter rtpe_stats_interval; struct global_stats_counter rtpe_stats_cumulative; diff --git a/include/call.h b/include/call.h index 3de93caec..012d74d45 100644 --- a/include/call.h +++ b/include/call.h @@ -542,14 +542,17 @@ extern GHashTable *rtpe_callhash; extern struct call_iterator_list rtpe_call_iterators[NUM_CALL_ITERATORS]; extern struct global_stats_gauge rtpe_stats_gauge; +extern struct global_stats_gauge_min_max rtpe_stats_gauge_graphite_min_max; #define RTPE_GAUGE_SET(field, num) \ do { \ atomic64_set(&rtpe_stats_gauge.field, num); \ + RTPE_GAUGE_SET_MIN_MAX(field, rtpe_stats_gauge_graphite_min_max, num); \ } while (0) #define RTPE_GAUGE_ADD(field, num) \ do { \ - atomic64_add(&rtpe_stats_gauge.field, num); \ + uint64_t __old = atomic64_add(&rtpe_stats_gauge.field, num); \ + RTPE_GAUGE_SET_MIN_MAX(field, rtpe_stats_gauge_graphite_min_max, __old + num); \ } while (0) #define RTPE_GAUGE_INC(field) RTPE_GAUGE_ADD(field, 1) #define RTPE_GAUGE_DEC(field) RTPE_GAUGE_ADD(field, -1) diff --git a/include/statistics.h b/include/statistics.h index bd59f9782..770eea891 100644 --- a/include/statistics.h +++ b/include/statistics.h @@ -26,6 +26,13 @@ struct global_stats_gauge { #undef F }; +struct global_stats_gauge_min_max { + struct global_stats_gauge min; + struct global_stats_gauge max; + struct global_stats_gauge avg; // sum while accumulation is running + struct global_stats_gauge count; +}; + // "counter" style stats that are incremental and are kept cumulative or per-interval struct global_stats_counter { #define F(x) atomic64 x; @@ -177,6 +184,14 @@ INLINE void stats_counters_min_max_reset(struct global_stats_min_max *mm, struct #undef F } +#define RTPE_GAUGE_SET_MIN_MAX(field, min_max_struct, val) \ + do { \ + atomic64_min(&min_max_struct.min.field, val); \ + atomic64_max(&min_max_struct.max.field, val); \ + atomic64_add(&min_max_struct.avg.field, val); \ + atomic64_inc(&min_max_struct.count.field); \ + } while (0) + void statistics_init(void); void statistics_free(void);