]> git.ipfire.org Git - thirdparty/collectd.git/commitdiff
cpu plugin: Move type definitions close together.
authorFlorian Forster <octo@collectd.org>
Tue, 9 Jan 2024 10:03:25 +0000 (11:03 +0100)
committerFlorian Forster <octo@collectd.org>
Mon, 22 Jan 2024 15:07:57 +0000 (16:07 +0100)
src/cpu.c

index b893b32609f12956baebe70d5059632b9f212ddc..a2e58422f3f070756e71364a670a17c44652a939 100644 (file)
--- a/src/cpu.c
+++ b/src/cpu.c
 #define CAN_USE_SYSCTL 0
 #endif /* HAVE_SYSCTL_H && HAVE_SYSCTLBYNAME || __OpenBSD__ */
 
+#if HAVE_STATGRAB_H
+#include <statgrab.h>
+#endif
+
+#ifdef HAVE_PERFSTAT
+#include <libperfstat.h>
+#include <sys/protosw.h>
+#endif /* HAVE_PERFSTAT */
+
+#if !PROCESSOR_CPU_LOAD_INFO && !KERNEL_LINUX && !HAVE_LIBKSTAT &&             \
+    !CAN_USE_SYSCTL && !HAVE_SYSCTLBYNAME && !HAVE_LIBSTATGRAB &&              \
+    !HAVE_PERFSTAT
+#error "No applicable input method."
+#endif
+
 typedef enum {
   STATE_USER,
   STATE_SYSTEM,
@@ -106,25 +121,33 @@ typedef enum {
   STATE_MAX,    /* #states */
 } state_t;
 
-#if HAVE_STATGRAB_H
-#include <statgrab.h>
-#endif
-
-#ifdef HAVE_PERFSTAT
-#include <libperfstat.h>
-#include <sys/protosw.h>
-#endif /* HAVE_PERFSTAT */
-
-#if !PROCESSOR_CPU_LOAD_INFO && !KERNEL_LINUX && !HAVE_LIBKSTAT &&             \
-    !CAN_USE_SYSCTL && !HAVE_SYSCTLBYNAME && !HAVE_LIBSTATGRAB &&              \
-    !HAVE_PERFSTAT
-#error "No applicable input method."
-#endif
-
 static const char *cpu_state_names[STATE_MAX] = {
     "user",    "system", "wait",  "nice",       "swap", "interrupt",
     "softirq", "steal",  "guest", "guest_nice", "idle", "active"};
 
+typedef struct {
+  gauge_t rate;
+  bool has_value;
+  value_to_rate_state_t conv;
+
+  /* count is a scaled counter, so that all states in sum increase by 1000000
+   * per second. */
+  derive_t count;
+  bool has_count;
+  rate_to_value_state_t to_count;
+} usage_state_t;
+
+typedef struct {
+  cdtime_t time;
+  cdtime_t interval;
+  bool finalized;
+
+  usage_state_t *states;
+  size_t states_num;
+
+  usage_state_t global[STATE_MAX];
+} usage_t;
+
 static char const *const label_state = "system.cpu.state";
 static char const *const label_number = "system.cpu.logical_number";
 
@@ -335,29 +358,6 @@ static int init(void) {
   return 0;
 } /* int init */
 
-typedef struct {
-  gauge_t rate;
-  bool has_value;
-  value_to_rate_state_t conv;
-
-  /* count is a scaled counter, so that all states in sum increase by 1000000
-   * per second. */
-  derive_t count;
-  bool has_count;
-  rate_to_value_state_t to_count;
-} usage_state_t;
-
-typedef struct {
-  cdtime_t time;
-  cdtime_t interval;
-  bool finalized;
-
-  usage_state_t *states;
-  size_t states_num;
-
-  usage_state_t global[STATE_MAX];
-} usage_t;
-
 __attribute__((unused)) static int usage_init(usage_t *u, cdtime_t now) {
   if (u == NULL || now == 0) {
     return EINVAL;