From 49b79e8b2fd9c7f130979d7791a6a7d926636054 Mon Sep 17 00:00:00 2001 From: Richard Fuchs Date: Thu, 23 Dec 2021 14:23:39 -0500 Subject: [PATCH] TT#156052 use `destroyed` timestamp for call duration stats Change-Id: I464269ffc85c7552e38abdbe326c8675b3175f19 --- daemon/statistics.c | 12 +++++++----- t/test-stats.c | 4 ++-- 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/daemon/statistics.c b/daemon/statistics.c index 8272f5233..04f7d653a 100644 --- a/daemon/statistics.c +++ b/daemon/statistics.c @@ -111,7 +111,6 @@ void statistics_update_oneway(struct call* c) { GList *k, *o; int found = 0; GList *l; - struct timeval tim_result_duration; // --- for statistics getting one way stream or no relay at all int total_nopacket_relayed_sess = 0; @@ -159,8 +158,6 @@ void statistics_update_oneway(struct call* c) { if (c->monologues.head) { ml = c->monologues.head->data; - timeval_subtract(&tim_result_duration, &rtpe_now, &ml->started); - if (IS_OWN_CALL(c)) { if (ml->term_reason==TIMEOUT) RTPE_STATS_INC(timeout_sess); @@ -173,8 +170,12 @@ void statistics_update_oneway(struct call* c) { else if (ml->term_reason==FORCED) RTPE_STATS_INC(forced_term_sess); - RTPE_STATS_ADD(call_duration, timeval_us(&tim_result_duration)); RTPE_STATS_INC(managed_sess); + + if (!c->destroyed.tv_sec) + c->destroyed = rtpe_now; + long long duration = timeval_diff(&c->destroyed, &c->created); + RTPE_STATS_ADD(call_duration, duration); } if (ml->term_reason==FINAL_TIMEOUT) @@ -387,7 +388,8 @@ GQueue *statistics_gather_metrics(void) { PROMLAB("type=\"mixed\""); num_sessions = atomic64_get(&rtpe_stats_cumulative.managed_sess); - long long avg_us = num_sessions ? atomic64_get(&rtpe_stats_cumulative.call_duration) / num_sessions : 0; + uint64_t total_duration = atomic64_get(&rtpe_stats_cumulative.call_duration); + long long avg_us = num_sessions ? total_duration / num_sessions : 0; timeval_from_us(&avg, avg_us); HEADER("}", ""); diff --git a/t/test-stats.c b/t/test-stats.c index d9df7af76..bfdde2499 100644 --- a/t/test-stats.c +++ b/t/test-stats.c @@ -3434,8 +3434,8 @@ int main(void) { struct call_monologue *ml1 = call_get_or_create_monologue(call1, &callid1); struct call *call2 = call_get_or_create(&callid2, false, true); struct call_monologue *ml2 = call_get_or_create_monologue(call2, &callid2); - ml1->started = (struct timeval) {157,0}; - ml2->started = (struct timeval) {57,0}; + call1->created = ml1->started = (struct timeval) {157,0}; + call2->created = ml2->started = (struct timeval) {57,0}; graph_str = print_graphite_data(); assert_g_string_eq(graph_str,