From: Florian Forster Date: Wed, 10 Jan 2024 17:17:02 +0000 (+0100) Subject: cpu plugin: Fold the `usage_global_count` function into `usage_count`. X-Git-Tag: 6.0.0-rc0~5^2~10 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=e4efd4c12c4a0da21234f4f54072b27728b1a3bd;p=thirdparty%2Fcollectd.git cpu plugin: Fold the `usage_global_count` function into `usage_count`. --- diff --git a/src/cpu.c b/src/cpu.c index a1508287a..eed5eacb4 100644 --- a/src/cpu.c +++ b/src/cpu.c @@ -563,26 +563,21 @@ static gauge_t usage_ratio(usage_t *u, size_t cpu, state_t state) { return usage_rate(u, cpu, state) / global_rate; } -static derive_t usage_global_count(usage_t *u, state_t state) { - usage_finalize(u); - - return u->global[state].count; -} - static derive_t usage_count(usage_t *u, size_t cpu, state_t state) { usage_finalize(u); + usage_state_t us; if (cpu == CPU_ALL) { - return usage_global_count(u, state); - } - - size_t index = (cpu * STATE_MAX) + state; - if (index >= u->states_num) { - return -1; + us = u->global[state]; + } else { + size_t index = (cpu * STATE_MAX) + state; + if (index >= u->states_num) { + return -1; + } + us = u->states[index]; } - usage_state_t *us = u->states + index; - return us->count; + return us.has_count ? us.count : -1; } /* Commits the number of cores */