]> git.ipfire.org Git - thirdparty/collectd.git/commitdiff
gpu_sysman: support logging all (new) metric types
authorEero Tamminen <eero.t.tamminen@intel.com>
Fri, 23 Feb 2024 13:49:06 +0000 (15:49 +0200)
committerEero Tamminen <eero.t.tamminen@intel.com>
Wed, 28 Feb 2024 15:21:09 +0000 (17:21 +0200)
New types are not yet used by the plugin, but soon are.

Signed-off-by: Eero Tamminen <eero.t.tamminen@intel.com>
src/gpu_sysman.c
src/gpu_sysman_test.c

index babf0221ca93a301009a46cee3939c797b4922ef..3609eed225d407590edb8593da261431bee63ff4 100644 (file)
@@ -770,6 +770,24 @@ static int gpu_init(void) {
   return gpu_config_init(count);
 }
 
+static double metric2double(metric_type_t type, value_t value) {
+  switch (type) {
+  case METRIC_TYPE_GAUGE:
+    return value.gauge;
+  case METRIC_TYPE_COUNTER:
+    return value.counter;
+  case METRIC_TYPE_COUNTER_FP:
+    return value.counter_fp;
+  case METRIC_TYPE_UP_DOWN:
+    return value.up_down;
+  case METRIC_TYPE_UP_DOWN_FP:
+    return value.up_down_fp;
+  case METRIC_TYPE_UNTYPED:
+    break;
+  }
+  assert(0);
+}
+
 /* Add device labels to all metrics in given metric family and submit family to
  * collectd, and log the metric if metric logging is enabled.
  * Resets metric family after dispatch */
@@ -806,8 +824,7 @@ static void gpu_submit(gpu_device_t *gpu, metric_family_t *fam) {
       }
       INFO("[%7ld.%03ld] %s: %s / %s [%ld]: %.3f", ts.tv_sec,
            ts.tv_nsec / 1000000, pci_bdf, name, type, i,
-           fam->type == METRIC_TYPE_COUNTER ? m->value.counter
-                                            : m->value.gauge);
+           metric2double(fam->type, m->value));
     }
 
     /* add extra per-metric labels */
index bb0665a9aa0c7c062ebdf6ee4c3464a54eac8436..0d215f9c2b0d52cec26341b1f4d9763b74dd4975 100644 (file)
@@ -809,19 +809,6 @@ static void compose_name(char *buf, size_t bufsize, const char *name,
   assert(len < bufsize);
 }
 
-static double get_value(metric_type_t type, value_t value) {
-  switch (type) {
-  case METRIC_TYPE_COUNTER:
-    return value.counter;
-    break;
-  case METRIC_TYPE_GAUGE:
-    return value.gauge;
-    break;
-  default:
-    assert(0);
-  }
-}
-
 /* matches constructed metric names against validation array ones and
  * updates the values accordingly
  */
@@ -833,7 +820,7 @@ int plugin_dispatch_metric_family(metric_family_t const *fam) {
   metric_t *metric = fam->metric.ptr;
 
   for (size_t m = 0; m < fam->metric.num; m++) {
-    double value = get_value(fam->type, metric[m].value);
+    double value = metric2double(fam->type, metric[m].value);
     compose_name(name, sizeof(name), fam->name, &metric[m]);
     if (globs.verbose & VERBOSE_METRICS) {
       fprintf(stderr, "METRIC: %s: %g\n", name, value);