]> git.ipfire.org Git - thirdparty/collectd.git/commitdiff
Tree wide: Remove `up_down_counter_t` and use `int64_t` instead.
authorFlorian Forster <octo@collectd.org>
Wed, 21 Feb 2024 08:53:37 +0000 (09:53 +0100)
committerFlorian Forster <octo@collectd.org>
Wed, 21 Feb 2024 20:36:32 +0000 (21:36 +0100)
src/daemon/metric.h
src/memory.c
src/utils/common/common.c

index d2d78c08f6acc64a07eb820a9f3abd3c1828f96b..3e1fcfc0a28d58d738b9d0490b5d06e20ececdfb 100644 (file)
@@ -72,14 +72,13 @@ typedef double gauge_t;
 typedef uint64_t counter_t;
 typedef double fpcounter_t;
 typedef int64_t derive_t;
-typedef int64_t up_down_counter_t;
 typedef double up_down_counter_fp_t;
 
 union value_u {
   gauge_t gauge;
   counter_t counter;
   fpcounter_t counter_fp;
-  up_down_counter_t up_down;
+  int64_t up_down;
   up_down_counter_fp_t up_down_fp;
   // For collectd 5 compatiblity. Treated the same as up_down.
   derive_t derive;
index 6f72ea087b48aae52f9e910d619ffde49315e467..d76a26f234366c801d630314bc06e6fc8bbb8102 100644 (file)
@@ -170,14 +170,14 @@ static int memory_config(oconfig_item_t *ci) /* {{{ */
   return 0;
 } /* }}} int memory_config */
 
-static int memory_dispatch(up_down_counter_t values[STATE_MAX]) {
+static int memory_dispatch(int64_t values[STATE_MAX]) {
   metric_family_t fam_usage = {
       .name = "system.memory.usage",
       .help = "Reports memory in use by state",
       .unit = "By",
       .type = METRIC_TYPE_UP_DOWN,
   };
-  up_down_counter_t total = 0;
+  int64_t total = 0;
 
   for (size_t i = 0; i < STATE_MAX; i++) {
     if (values[i] < 0) {
@@ -328,7 +328,7 @@ static int memory_init(void) {
   return 0;
 } /* int memory_init */
 
-static int memory_read_internal(up_down_counter_t values[STATE_MAX]) {
+static int memory_read_internal(int64_t values[STATE_MAX]) {
 #if HAVE_HOST_STATISTICS
   if (!port_host || !pagesize) {
     return EINVAL;
@@ -364,11 +364,10 @@ static int memory_read_internal(up_down_counter_t values[STATE_MAX]) {
    *   This memory is not being used.
    */
 
-  values[STATE_WIRED] = (up_down_counter_t)(vm_data.wire_count * pagesize);
-  values[STATE_ACTIVE] = (up_down_counter_t)(vm_data.active_count * pagesize);
-  values[STATE_INACTIVE] =
-      (up_down_counter_t)(vm_data.inactive_count * pagesize);
-  values[STATE_FREE] = (up_down_counter_t)(vm_data.free_count * pagesize);
+  values[STATE_WIRED] = (int64_t)(vm_data.wire_count * pagesize);
+  values[STATE_ACTIVE] = (int64_t)(vm_data.active_count * pagesize);
+  values[STATE_INACTIVE] = (int64_t)(vm_data.inactive_count * pagesize);
+  values[STATE_FREE] = (int64_t)(vm_data.free_count * pagesize);
   /* #endif HAVE_HOST_STATISTICS */
 
 #elif HAVE_SYSCTLBYNAME
@@ -386,16 +385,15 @@ static int memory_read_internal(up_down_counter_t values[STATE_MAX]) {
     return errno;
   }
 
-  values[STATE_WIRED] = (up_down_counter_t)(uvmexp.wired * pagesize);
-  values[STATE_ACTIVE] = (up_down_counter_t)(uvmexp.active * pagesize);
-  values[STATE_INACTIVE] = (up_down_counter_t)(uvmexp.inactive * pagesize);
-  values[STATE_FREE] = (up_down_counter_t)(uvmexp.free * pagesize);
+  values[STATE_WIRED] = (int64_t)(uvmexp.wired * pagesize);
+  values[STATE_ACTIVE] = (int64_t)(uvmexp.active * pagesize);
+  values[STATE_INACTIVE] = (int64_t)(uvmexp.inactive * pagesize);
+  values[STATE_FREE] = (int64_t)(uvmexp.free * pagesize);
 
   int64_t accounted =
       uvmexp.wired + uvmexp.active + uvmexp.inactive + uvmexp.free;
   if (uvmexp.npages > accounted) {
-    values[STATE_KERNEL] =
-        (up_down_counter_t)((uvmexp.npages - accounted) * pagesize);
+    values[STATE_KERNEL] = (int64_t)((uvmexp.npages - accounted) * pagesize);
   }
   /* #endif HAVE_SYSCTL && defined(KERNEL_NETBSD) */
 
@@ -425,7 +423,7 @@ static int memory_read_internal(up_down_counter_t values[STATE_MAX]) {
       {"vm.stats.vm.v_laundry_count", STATE_LAUNDRY},
   };
 
-  up_down_counter_t pagesize = 0;
+  int64_t pagesize = 0;
   for (size_t i = 0; i < STATIC_ARRAY_SIZE(metrics); i++) {
     long value = 0;
     size_t value_len = sizeof(value);
@@ -439,11 +437,11 @@ static int memory_read_internal(up_down_counter_t values[STATE_MAX]) {
     }
 
     if (i == 0) {
-      pagesize = (up_down_counter_t)value;
+      pagesize = (int64_t)value;
       continue;
     }
 
-    values[metrics[i].type] = ((up_down_counter_t)value) * pagesize;
+    values[metrics[i].type] = ((int64_t)value) * pagesize;
   } /* for (sysctl_keys) */
 #endif /* HAVE_SYSCTL && KERNEL_NETBSD */
   /* #endif HAVE_SYSCTLBYNAME */
@@ -456,8 +454,8 @@ static int memory_read_internal(up_down_counter_t values[STATE_MAX]) {
     return status;
   }
 
-  up_down_counter_t mem_total = -1;
-  up_down_counter_t mem_not_used = 0;
+  int64_t mem_total = -1;
+  int64_t mem_not_used = 0;
 
   char buffer[256];
   while (fgets(buffer, sizeof(buffer), fh) != NULL) {
@@ -467,7 +465,7 @@ static int memory_read_internal(up_down_counter_t values[STATE_MAX]) {
       continue;
     }
 
-    up_down_counter_t v = (up_down_counter_t)(1024 * atoll(fields[1]));
+    int64_t v = (int64_t)(1024 * atoll(fields[1]));
 
     if (strcmp(fields[0], "MemTotal:") == 0) {
       mem_total = v;
@@ -549,12 +547,12 @@ static int memory_read_internal(up_down_counter_t values[STATE_MAX]) {
     mem_lock = 0;
   }
 
-  values[STATE_USED] = (up_down_counter_t)(mem_used * pagesize);
-  values[STATE_FREE] = (up_down_counter_t)(mem_free * pagesize);
-  values[STATE_LOCKED] = (up_down_counter_t)(mem_lock * pagesize);
-  values[STATE_KERNEL] = (up_down_counter_t)((mem_kern * pagesize) - arcsize);
-  values[STATE_UNUSED] = (up_down_counter_t)(mem_unus * pagesize);
-  values[STATE_ARC] = (up_down_counter_t)arcsize;
+  values[STATE_USED] = (int64_t)(mem_used * pagesize);
+  values[STATE_FREE] = (int64_t)(mem_free * pagesize);
+  values[STATE_LOCKED] = (int64_t)(mem_lock * pagesize);
+  values[STATE_KERNEL] = (int64_t)((mem_kern * pagesize) - arcsize);
+  values[STATE_UNUSED] = (int64_t)(mem_unus * pagesize);
+  values[STATE_ARC] = (int64_t)arcsize;
   /* #endif HAVE_LIBKSTAT */
 
 #elif HAVE_SYSCTL && __OpenBSD__
@@ -571,10 +569,9 @@ static int memory_read_internal(up_down_counter_t values[STATE_MAX]) {
     return errno;
   }
 
-  values[STATE_ACTIVE] = (up_down_counter_t)(vmtotal.t_arm * pagesize);
-  values[STATE_INACTIVE] =
-      (up_down_counter_t)((vmtotal.t_rm - vmtotal.t_arm) * pagesize);
-  values[STATE_FREE] = (up_down_counter_t)(vmtotal.t_free * pagesize);
+  values[STATE_ACTIVE] = (int64_t)(vmtotal.t_arm * pagesize);
+  values[STATE_INACTIVE] = (int64_t)((vmtotal.t_rm - vmtotal.t_arm) * pagesize);
+  values[STATE_FREE] = (int64_t)(vmtotal.t_free * pagesize);
   /* #endif HAVE_SYSCTL && __OpenBSD__ */
 
 #elif HAVE_LIBSTATGRAB
@@ -583,9 +580,9 @@ static int memory_read_internal(up_down_counter_t values[STATE_MAX]) {
     return -1;
   }
 
-  values[STATE_USED] = (up_down_counter_t)ios->used;
-  values[STATE_CACHED] = (up_down_counter_t)ios->cache;
-  values[STATE_FREE] = (up_down_counter_t)ios->free;
+  values[STATE_USED] = (int64_t)ios->used;
+  values[STATE_CACHED] = (int64_t)ios->cache;
+  values[STATE_FREE] = (int64_t)ios->free;
   /* #endif HAVE_LIBSTATGRAB */
 
 #elif HAVE_PERFSTAT
@@ -605,10 +602,10 @@ static int memory_read_internal(up_down_counter_t values[STATE_MAX]) {
    *   real_total = real_free + real_inuse
    *   real_inuse = "active" + real_pinned + numperm
    */
-  values[STATE_FREE] = (up_down_counter_t)(pmemory.real_free * pagesize);
-  values[STATE_CACHED] = (up_down_counter_t)(pmemory.numperm * pagesize);
-  values[STATE_KERNEL] = (up_down_counter_t)(pmemory.real_system * pagesize);
-  values[STATE_USED] = (up_down_counter_t)(pmemory.real_process * pagesize);
+  values[STATE_FREE] = (int64_t)(pmemory.real_free * pagesize);
+  values[STATE_CACHED] = (int64_t)(pmemory.numperm * pagesize);
+  values[STATE_KERNEL] = (int64_t)(pmemory.real_system * pagesize);
+  values[STATE_USED] = (int64_t)(pmemory.real_process * pagesize);
 #endif /* HAVE_PERFSTAT */
 
   return 0;
@@ -616,7 +613,7 @@ static int memory_read_internal(up_down_counter_t values[STATE_MAX]) {
 
 static int memory_read(void) /* {{{ */
 {
-  up_down_counter_t values[STATE_MAX] = {0};
+  int64_t values[STATE_MAX] = {0};
   for (size_t i = 0; i < STATE_MAX; i++) {
     values[i] = -1;
   }
index 6010c9724aa77949d302d311fe36c96878193ba8..f261bc351c08883055dc54cf82d0f2a693b41c52 100644 (file)
@@ -969,7 +969,7 @@ int parse_value(char const *value, value_t *ret_value, metric_type_t type) {
     break;
 
   case METRIC_TYPE_UP_DOWN:
-    ret_value->up_down = (up_down_counter_t)strtoll(value, &endptr, 0);
+    ret_value->up_down = (int64_t)strtoll(value, &endptr, 0);
     break;
 
   case METRIC_TYPE_UP_DOWN_FP:
@@ -1239,7 +1239,7 @@ int rate_to_value(value_t *ret_value, gauge_t rate, /* {{{ */
       state->residual = 0;
       break;
     case METRIC_TYPE_UP_DOWN:
-      state->last_value.up_down = (up_down_counter_t)floor(rate);
+      state->last_value.up_down = (int64_t)floor(rate);
       state->residual = rate - ((gauge_t)state->last_value.up_down);
       break;
     case METRIC_TYPE_UP_DOWN_FP:
@@ -1272,7 +1272,7 @@ int rate_to_value(value_t *ret_value, gauge_t rate, /* {{{ */
     break;
   }
   case METRIC_TYPE_UP_DOWN: {
-    up_down_counter_t delta = (up_down_counter_t)floor(delta_gauge);
+    int64_t delta = (int64_t)floor(delta_gauge);
     state->last_value.up_down += delta;
     state->residual = delta_gauge - ((gauge_t)delta);
     break;
@@ -1314,7 +1314,7 @@ static int calculate_rate(gauge_t *ret_rate, value_t value, metric_type_t type,
     return 0;
   }
   case METRIC_TYPE_UP_DOWN: {
-    up_down_counter_t diff = value.up_down - state->last_value.up_down;
+    int64_t diff = value.up_down - state->last_value.up_down;
     *ret_rate = ((gauge_t)diff) / ((gauge_t)interval);
     return 0;
   }