From: Florian Forster Date: Tue, 9 Jan 2024 10:03:25 +0000 (+0100) Subject: cpu plugin: Move type definitions close together. X-Git-Tag: 6.0.0-rc0~5^2~20 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=fa641402fcce1fd1a2cb60337c17157461bcd7ae;p=thirdparty%2Fcollectd.git cpu plugin: Move type definitions close together. --- diff --git a/src/cpu.c b/src/cpu.c index b893b3260..a2e58422f 100644 --- a/src/cpu.c +++ b/src/cpu.c @@ -90,6 +90,21 @@ #define CAN_USE_SYSCTL 0 #endif /* HAVE_SYSCTL_H && HAVE_SYSCTLBYNAME || __OpenBSD__ */ +#if HAVE_STATGRAB_H +#include +#endif + +#ifdef HAVE_PERFSTAT +#include +#include +#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 -#endif - -#ifdef HAVE_PERFSTAT -#include -#include -#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;