MT#55283 refactor call_rate_stats_updater

Use the looper thread helper functions.

Change-Id: Ic3de7ebb2b1f0e42a4a488c78003020fb642035e
pull/1676/head
Richard Fuchs 3 years ago
parent a6ecfb8a80
commit 2e4dec10ea

@ -1351,8 +1351,8 @@ int main(int argc, char **argv) {
rtpe_config.idle_priority, "release closed sockets", 1000000);
/* separate thread for update of running min/max call counters */
thread_create_detach_prio(call_rate_stats_updater, NULL, rtpe_config.idle_scheduling,
rtpe_config.idle_priority, "call rate stats");
thread_create_looper(call_rate_stats_updater, rtpe_config.idle_scheduling,
rtpe_config.idle_priority, "call rate stats", 1000000);
/* separate thread for ports iterations (stats update from the kernel) functionality */
thread_create_looper(kernel_stats_updater, rtpe_config.idle_scheduling,

@ -1022,27 +1022,17 @@ const char *statistics_ng(bencode_item_t *input, bencode_item_t *output) {
/**
* Separate thread for update of running min/max call counters.
*/
void call_rate_stats_updater(void * dummy) {
bool first_run = true;
struct timeval last_run = (struct timeval) {0,0};
enum thread_looper_action call_rate_stats_updater() {
static struct timeval last_run;
while (!rtpe_shutdown) {
struct timeval tv_start;
long long run_diff_us;
stats_rate_min_max(&rtpe_rate_graphite_min_max, &rtpe_stats_rate);
gettimeofday(&tv_start, NULL); /* current run */
run_diff_us = timeval_diff(&tv_start, &last_run); /* TODO: do we need `run_diff_us` at all? */
last_run = tv_start; /* for the next cycle */
stats_rate_min_max(&rtpe_rate_graphite_min_max, &rtpe_stats_rate);
if (!first_run) /* `stats_counters_calc_rate()` shouldn't be called on the very first cycle */
stats_counters_calc_rate(&rtpe_stats, run_diff_us, &rtpe_stats_intv, &rtpe_stats_rate);
if (!last_run.tv_sec) { /* `stats_counters_calc_rate()` shouldn't be called on the very first cycle */
long long run_diff_us = timeval_diff(&rtpe_now, &last_run);
stats_counters_calc_rate(&rtpe_stats, run_diff_us, &rtpe_stats_intv, &rtpe_stats_rate);
}
thread_cancel_enable();
usleep(1000000); /* sleep for 1 second in each iteration */
thread_cancel_disable();
last_run = rtpe_now;
first_run = false;
}
return TLA_CONTINUE;
}

@ -198,7 +198,7 @@ void statistics_update_foreignown_inc(struct call* c);
GQueue *statistics_gather_metrics(struct interface_sampled_rate_stats *);
void statistics_free_metrics(GQueue **);
const char *statistics_ng(bencode_item_t *input, bencode_item_t *output);
void call_rate_stats_updater(void * dummy);
enum thread_looper_action call_rate_stats_updater(void);
/**
* Calculation of the call rate counters.

Loading…
Cancel
Save