diff --git a/daemon/call.c b/daemon/call.c index b411d645e..7e5665856 100644 --- a/daemon/call.c +++ b/daemon/call.c @@ -532,13 +532,11 @@ void call_timer(void *ptr) { GList *i, *l; struct rtpengine_list_entry *ke; struct packet_stream *ps; - struct global_stats_counter tmpstats; int j, update; struct stream_fd *sfd; struct rtp_stats *rs; unsigned int pt; endpoint_t ep; - uint64_t offers, answers, deletes; struct timeval tv_start; long long run_diff; @@ -558,8 +556,6 @@ void call_timer(void *ptr) { // round up and make integer seconds run_diff += 499999; run_diff /= 1000000; - if (run_diff < 1) - run_diff = 1; ZERO(hlp); hlp.addr_sfd = g_hash_table_new(g_endpoint_hash, g_endpoint_eq); @@ -568,23 +564,12 @@ void call_timer(void *ptr) { call_timer_iterator(c, &hlp); ITERATE_CALL_LIST_NEXT_END(c); - atomic64_local_copy_zero_struct(&tmpstats, &rtpe_stats.ax, bytes); - atomic64_local_copy_zero_struct(&tmpstats, &rtpe_stats.ax, packets); - atomic64_local_copy_zero_struct(&tmpstats, &rtpe_stats.ax, errors); - - atomic64_set(&rtpe_stats.intv.bytes, atomic64_get_na(&tmpstats.bytes) / run_diff); - atomic64_set(&rtpe_stats.intv.packets, atomic64_get_na(&tmpstats.packets) / run_diff); - atomic64_set(&rtpe_stats.intv.errors, atomic64_get_na(&tmpstats.errors) / run_diff); + stats_counters_ax_calc_avg(&rtpe_stats, run_diff); /* update statistics regarding requests per second */ - offers = atomic64_get_set(&rtpe_stats.ax.offers, 0); - update_requests_per_second_stats(&rtpe_totalstats_interval.offers_ps, offers / run_diff); - - answers = atomic64_get_set(&rtpe_stats.ax.answers, 0); - update_requests_per_second_stats(&rtpe_totalstats_interval.answers_ps, answers / run_diff); - - deletes = atomic64_get_set(&rtpe_stats.ax.deletes, 0); - update_requests_per_second_stats(&rtpe_totalstats_interval.deletes_ps, deletes / run_diff); + update_requests_per_second_stats(&rtpe_totalstats_interval.offers_ps, atomic64_get(&rtpe_stats.intv.offers)); + update_requests_per_second_stats(&rtpe_totalstats_interval.answers_ps, atomic64_get(&rtpe_stats.intv.answers)); + update_requests_per_second_stats(&rtpe_totalstats_interval.deletes_ps, atomic64_get(&rtpe_stats.intv.deletes)); // stats derived while iterating calls atomic64_set(&rtpe_stats_gauge.transcoded_media, hlp.transcoded_media); diff --git a/include/counter_stats_fields.inc b/include/counter_stats_fields.inc new file mode 100644 index 000000000..3f77b150d --- /dev/null +++ b/include/counter_stats_fields.inc @@ -0,0 +1,6 @@ +F(packets) +F(bytes) +F(errors) +F(offers) +F(answers) +F(deletes) diff --git a/include/statistics.h b/include/statistics.h index 3854d5bd4..994794bfb 100644 --- a/include/statistics.h +++ b/include/statistics.h @@ -30,12 +30,9 @@ struct global_stats_gauge { // "counter" style stats that are incremental and are kept cumulative or per-interval struct global_stats_counter { - atomic64 packets; - atomic64 bytes; - atomic64 errors; - atomic64 offers; - atomic64 answers; - atomic64 deletes; +#define F(x) atomic64 x; +#include "counter_stats_fields.inc" +#undef F }; struct global_stats_ax { @@ -154,6 +151,20 @@ GQueue *statistics_gather_metrics(void); void statistics_free_metrics(GQueue **); const char *statistics_ng(bencode_item_t *input, bencode_item_t *output); +INLINE void stats_counters_ax_calc_avg1(atomic64 *ax_var, atomic64 *intv_var, long long run_diff) { + uint64_t tmp = atomic64_get_set(ax_var, 0); + atomic64_set(intv_var, tmp / run_diff); +} + +INLINE void stats_counters_ax_calc_avg(struct global_stats_ax *stats, long long run_diff) { + if (run_diff < 0) + run_diff = 1; + +#define F(x) stats_counters_ax_calc_avg1(&stats->ax.x, &stats->intv.x, run_diff); +#include "counter_stats_fields.inc" +#undef F +} + void statistics_init(void); void statistics_free(void);