]> git.ipfire.org Git - thirdparty/collectd.git/commitdiff
cpu plugin: Fold the `usage_global_count` function into `usage_count`.
authorFlorian Forster <octo@collectd.org>
Wed, 10 Jan 2024 17:17:02 +0000 (18:17 +0100)
committerFlorian Forster <octo@collectd.org>
Mon, 22 Jan 2024 15:07:57 +0000 (16:07 +0100)
src/cpu.c

index a1508287a539fab7fcce8710dc3eceee04c0e91a..eed5eacb409044595949cb7a2833e5bc3af0f2a5 100644 (file)
--- 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 */