From b0ebe9ba1bc472fc64e47832f278b9bf500b0fe5 Mon Sep 17 00:00:00 2001 From: Richard Fuchs Date: Tue, 21 Sep 2021 14:57:25 -0400 Subject: [PATCH] TT#101150 move start timestamp to global var Change-Id: I03efdbf02b5fbf16616d26010cb79b0932cd4e00 --- daemon/statistics.c | 6 ++++-- include/statistics.h | 4 ++-- t/test-stats.c | 2 +- 3 files changed, 7 insertions(+), 5 deletions(-) diff --git a/daemon/statistics.c b/daemon/statistics.c index e9a35a60b..becf18317 100644 --- a/daemon/statistics.c +++ b/daemon/statistics.c @@ -10,6 +10,8 @@ struct totalstats rtpe_totalstats_interval; mutex_t rtpe_totalstats_lastinterval_lock; struct totalstats rtpe_totalstats_lastinterval; +struct timeval rtpe_started; + mutex_t rtpe_codec_stats_lock; GHashTable *rtpe_codec_stats; @@ -413,7 +415,7 @@ GQueue *statistics_gather_metrics(void) { HEADER("totalstatistics", "Total statistics (does not include current running sessions):"); HEADER("{", ""); - METRIC("uptime", "Uptime of rtpengine", "%llu", "%llu seconds", (long long) rtpe_now.tv_sec-rtpe_totalstats.started); + METRIC("uptime", "Uptime of rtpengine", "%llu", "%llu seconds", (long long) timeval_diff(&rtpe_now, &rtpe_started) / 1000000); PROM("uptime_seconds", "gauge"); METRIC("managedsessions", "Total managed sessions", UINT64F, UINT64F, num_sessions); @@ -698,7 +700,7 @@ static void codec_stats_free(void *p) { void statistics_init() { mutex_init(&rtpe_totalstats_interval.total_calls_duration_lock); - time(&rtpe_totalstats.started); + gettimeofday(&rtpe_started, NULL); //rtpe_totalstats_interval.managed_sess_min = 0; // already zeroed //rtpe_totalstats_interval.managed_sess_max = 0; diff --git a/include/statistics.h b/include/statistics.h index 55cdfd7af..f2c5d6a39 100644 --- a/include/statistics.h +++ b/include/statistics.h @@ -63,8 +63,6 @@ struct global_stats_min_max { struct totalstats { - time_t started; - mutex_t total_calls_duration_lock; /* for these two below */ struct timeval total_calls_duration_interval; }; @@ -116,6 +114,8 @@ extern struct totalstats rtpe_totalstats_interval; extern mutex_t rtpe_totalstats_lastinterval_lock; extern struct totalstats rtpe_totalstats_lastinterval; +extern struct timeval rtpe_started; + extern mutex_t rtpe_codec_stats_lock; extern GHashTable *rtpe_codec_stats; diff --git a/t/test-stats.c b/t/test-stats.c index a9aac3124..2b3b2a006 100644 --- a/t/test-stats.c +++ b/t/test-stats.c @@ -69,7 +69,7 @@ int main(void) { // fake current time rtpe_now = (struct timeval) {150,0}; - rtpe_totalstats.started = 80; + rtpe_started = (struct timeval) {80,0}; // test cmd_time_min/max/avg