From 7b5b52e9329266a289526e8588227a543033282c Mon Sep 17 00:00:00 2001 From: Richard Fuchs Date: Thu, 23 Dec 2021 15:34:33 -0500 Subject: [PATCH] TT#156052 add MOS stats to stats output Change-Id: I9dd3847ae772ba0851239c3f230de72a2ed207ee --- daemon/ssrc.c | 8 +- daemon/statistics.c | 24 ++++ include/counter_stats_fields.inc | 3 + include/statistics.h | 6 +- t/test-payload-tracker.c | 12 +- t/test-stats.c | 189 +++++++++++++++++++++++++++++++ 6 files changed, 239 insertions(+), 3 deletions(-) diff --git a/daemon/ssrc.c b/daemon/ssrc.c index 27224090f..b00bd7e71 100644 --- a/daemon/ssrc.c +++ b/daemon/ssrc.c @@ -396,7 +396,13 @@ void ssrc_receiver_report(struct call_media *m, const struct ssrc_receiver_repor }; other_e->packets_lost = rr->packets_lost; mos_calc(ssb); - ilog(LOG_DEBUG, "Calculated MOS from RR for %s%x%s is %.1f", FMT_M(rr->from), (double) ssb->mos / 10.0); + if (ssb->mos) { + ilog(LOG_DEBUG, "Calculated MOS from RR for %s%x%s is %.1f", FMT_M(rr->from), + (double) ssb->mos / 10.0); + RTPE_STATS_ADD(mos, ssb->mos); + RTPE_STATS_ADD(mos2, ssb->mos * ssb->mos); + RTPE_STATS_INC(mos_num); + } // got a new stats block, add it to reporting ssrc mutex_lock(&other_e->h.lock); diff --git a/daemon/statistics.c b/daemon/statistics.c index d7e0a2100..75949cd1e 100644 --- a/daemon/statistics.c +++ b/daemon/statistics.c @@ -1,3 +1,4 @@ +#include #include "call.h" #include "statistics.h" #include "graphite.h" @@ -515,6 +516,29 @@ GQueue *statistics_gather_metrics(void) { HEADER(NULL, ""); HEADER("}", ""); + + HEADER("mos", "MOS statistics:"); + HEADER("{", ""); + uint64_t mos_num = atomic64_get(&rtpe_stats_cumulative.mos_num); + uint64_t mos_tot = atomic64_get(&rtpe_stats_cumulative.mos); + uint64_t mos2_tot = atomic64_get(&rtpe_stats_cumulative.mos2); + double mos_mean = mos_num ? (double) mos_tot / (double) mos_num : 0.0; + double mos_variance = mos_num + ? fabs((double) mos2_tot / (double) mos_num - mos_mean * mos_mean) + : 0.0; + METRIC("mos_total", "Sum of all MOS values sampled", "%.6f", "%.6f", + (double) mos_tot / 10.0); + PROM("mos_total", "counter"); + METRIC("mos2_total", "Sum of all MOS square values sampled", "%.6f", "%.6f", + (double) mos2_tot / 100.0); + PROM("mos2_total", "counter"); + METRIC("mos_samples_total", "Total number of MOS samples", UINT64F, UINT64F, mos_num); + PROM("mos_samples_total", "counter"); + METRIC("mos_average", "Average MOS", "%.6f", "%.6f", mos_mean / 10.0); + METRIC("mos_stddev", "MOS standard deviation", "%.6f", "%.6f", sqrt(mos_variance) / 10.0); + HEADER(NULL, ""); + HEADER("}", ""); + HEADER("controlstatistics", "Control statistics:"); HEADER("{", ""); HEADER("proxies", NULL); diff --git a/include/counter_stats_fields.inc b/include/counter_stats_fields.inc index e9faae38a..48ab64058 100644 --- a/include/counter_stats_fields.inc +++ b/include/counter_stats_fields.inc @@ -18,3 +18,6 @@ F(nopacket_relayed_sess) F(oneway_stream_sess) F(call_duration) F(total_calls_duration_intv) +F(mos) +F(mos2) +F(mos_num) diff --git a/include/statistics.h b/include/statistics.h index 79a99f507..356f7f8b4 100644 --- a/include/statistics.h +++ b/include/statistics.h @@ -4,7 +4,6 @@ #include "aux.h" #include "bencode.h" #include "rtpengine_config.h" -#include "control_ng.h" struct call; struct packet_stream; @@ -20,6 +19,11 @@ struct stream_stats { #endif }; + + +#include "control_ng.h" + + // "gauge" style stats struct global_stats_gauge { // F(x) : real gauge that has a continuous value diff --git a/t/test-payload-tracker.c b/t/test-payload-tracker.c index b5575e499..4c5acfcc0 100644 --- a/t/test-payload-tracker.c +++ b/t/test-payload-tracker.c @@ -3,9 +3,19 @@ #include #include "ssrc.h" #include "main.h" +#include "statistics.h" struct rtpengine_config rtpe_config; - +struct global_stats_gauge rtpe_stats_gauge; +struct global_stats_gauge_min_max rtpe_stats_gauge_graphite_min_max; +struct global_stats_gauge_min_max rtpe_stats_gauge_graphite_min_max_interval; +struct global_stats_ax rtpe_stats; +struct global_stats_counter rtpe_stats_interval; +struct global_stats_counter rtpe_stats_cumulative; +struct global_stats_ax rtpe_stats_graphite; +struct global_stats_counter rtpe_stats_graphite_interval; +struct global_stats_min_max rtpe_stats_graphite_min_max; +struct global_stats_min_max rtpe_stats_graphite_min_max_interval; static void most_cmp(struct payload_tracker *t, const char *cmp, const char *file, int line) { diff --git a/t/test-stats.c b/t/test-stats.c index 7f176a920..4215d6921 100644 --- a/t/test-stats.c +++ b/t/test-stats.c @@ -840,6 +840,33 @@ int main(void) { "\n" "\n" "}\n" + "MOS statistics:\n" + "mos\n" + "\n" + "{\n" + "Sum of all MOS values sampled\n" + "mos_total\n" + "0.000000\n" + "0.000000\n" + "Sum of all MOS square values sampled\n" + "mos2_total\n" + "0.000000\n" + "0.000000\n" + "Total number of MOS samples\n" + "mos_samples_total\n" + "0\n" + "0\n" + "Average MOS\n" + "mos_average\n" + "0.000000\n" + "0.000000\n" + "MOS standard deviation\n" + "mos_stddev\n" + "0.000000\n" + "0.000000\n" + "\n" + "\n" + "}\n" "Control statistics:\n" "controlstatistics\n" "\n" @@ -1682,6 +1709,33 @@ int main(void) { "\n" "\n" "}\n" + "MOS statistics:\n" + "mos\n" + "\n" + "{\n" + "Sum of all MOS values sampled\n" + "mos_total\n" + "0.000000\n" + "0.000000\n" + "Sum of all MOS square values sampled\n" + "mos2_total\n" + "0.000000\n" + "0.000000\n" + "Total number of MOS samples\n" + "mos_samples_total\n" + "0\n" + "0\n" + "Average MOS\n" + "mos_average\n" + "0.000000\n" + "0.000000\n" + "MOS standard deviation\n" + "mos_stddev\n" + "0.000000\n" + "0.000000\n" + "\n" + "\n" + "}\n" "Control statistics:\n" "controlstatistics\n" "\n" @@ -2521,6 +2575,33 @@ int main(void) { "\n" "\n" "}\n" + "MOS statistics:\n" + "mos\n" + "\n" + "{\n" + "Sum of all MOS values sampled\n" + "mos_total\n" + "0.000000\n" + "0.000000\n" + "Sum of all MOS square values sampled\n" + "mos2_total\n" + "0.000000\n" + "0.000000\n" + "Total number of MOS samples\n" + "mos_samples_total\n" + "0\n" + "0\n" + "Average MOS\n" + "mos_average\n" + "0.000000\n" + "0.000000\n" + "MOS standard deviation\n" + "mos_stddev\n" + "0.000000\n" + "0.000000\n" + "\n" + "\n" + "}\n" "Control statistics:\n" "controlstatistics\n" "\n" @@ -3373,6 +3454,33 @@ int main(void) { "\n" "\n" "}\n" + "MOS statistics:\n" + "mos\n" + "\n" + "{\n" + "Sum of all MOS values sampled\n" + "mos_total\n" + "0.000000\n" + "0.000000\n" + "Sum of all MOS square values sampled\n" + "mos2_total\n" + "0.000000\n" + "0.000000\n" + "Total number of MOS samples\n" + "mos_samples_total\n" + "0\n" + "0\n" + "Average MOS\n" + "mos_average\n" + "0.000000\n" + "0.000000\n" + "MOS standard deviation\n" + "mos_stddev\n" + "0.000000\n" + "0.000000\n" + "\n" + "\n" + "}\n" "Control statistics:\n" "controlstatistics\n" "\n" @@ -4220,6 +4328,33 @@ int main(void) { "\n" "\n" "}\n" + "MOS statistics:\n" + "mos\n" + "\n" + "{\n" + "Sum of all MOS values sampled\n" + "mos_total\n" + "0.000000\n" + "0.000000\n" + "Sum of all MOS square values sampled\n" + "mos2_total\n" + "0.000000\n" + "0.000000\n" + "Total number of MOS samples\n" + "mos_samples_total\n" + "0\n" + "0\n" + "Average MOS\n" + "mos_average\n" + "0.000000\n" + "0.000000\n" + "MOS standard deviation\n" + "mos_stddev\n" + "0.000000\n" + "0.000000\n" + "\n" + "\n" + "}\n" "Control statistics:\n" "controlstatistics\n" "\n" @@ -5062,6 +5197,33 @@ int main(void) { "\n" "\n" "}\n" + "MOS statistics:\n" + "mos\n" + "\n" + "{\n" + "Sum of all MOS values sampled\n" + "mos_total\n" + "0.000000\n" + "0.000000\n" + "Sum of all MOS square values sampled\n" + "mos2_total\n" + "0.000000\n" + "0.000000\n" + "Total number of MOS samples\n" + "mos_samples_total\n" + "0\n" + "0\n" + "Average MOS\n" + "mos_average\n" + "0.000000\n" + "0.000000\n" + "MOS standard deviation\n" + "mos_stddev\n" + "0.000000\n" + "0.000000\n" + "\n" + "\n" + "}\n" "Control statistics:\n" "controlstatistics\n" "\n" @@ -5906,6 +6068,33 @@ int main(void) { "\n" "\n" "}\n" + "MOS statistics:\n" + "mos\n" + "\n" + "{\n" + "Sum of all MOS values sampled\n" + "mos_total\n" + "0.000000\n" + "0.000000\n" + "Sum of all MOS square values sampled\n" + "mos2_total\n" + "0.000000\n" + "0.000000\n" + "Total number of MOS samples\n" + "mos_samples_total\n" + "0\n" + "0\n" + "Average MOS\n" + "mos_average\n" + "0.000000\n" + "0.000000\n" + "MOS standard deviation\n" + "mos_stddev\n" + "0.000000\n" + "0.000000\n" + "\n" + "\n" + "}\n" "Control statistics:\n" "controlstatistics\n" "\n"