]> granicus.if.org Git - sysstat/commitdiff
A_IRQ: sadf: Update PCP interface for per-CPU interrupts statistics
authorNathan Scott <nathans@redhat.com>
Wed, 9 Feb 2022 00:36:32 +0000 (11:36 +1100)
committerNathan Scott <nathans@redhat.com>
Wed, 9 Feb 2022 00:36:32 +0000 (11:36 +1100)
Use the PCP instance domain convention with kernel.percpu.interrupts
where the interrupt line and cpu ID are combined.  This provides the
same metric as PCP and also a single stable metric identifier (pmID).

Signed-off-by: Nathan Scott <nathans@redhat.com>
pcp_def_metrics.c
pcp_stats.c
sa.h
sadf_misc.c

index caabd97b54f77a3e109adc4bf3d6eabfa850ad2b..30118306b9d589a5cb2df3992eb61cfc64526277 100644 (file)
  * @indom      PCP domain for interrupts metrics.
  ***************************************************************************
  */
-void pcp_def_percpu_int_metrics(struct activity *a, pmInDom indom)
+void pcp_def_percpu_int_metrics(struct activity *a, int cpu)
 {
-       int inst = 1;
-       char name[64];
+#ifdef HAVE_PCP
+       char buf[64];
        struct sa_item *list = a->item_list;
+       static pmInDom indom = PM_INDOM_NULL;
+       static int inst;
 
-       /* Create per-CPU metrics for A_IRQ */
-       while (list != NULL) {
-               snprintf(name, sizeof(name), "kernel.percpu.interrupts.%s", list->item_name);
-               name[sizeof(name) - 1] = '\0';
-
-               /* Metric name cannot contain digits :-( Translate them to characters instead */
-               replace_digits(name);
+       if (indom == PM_INDOM_NULL) {
+               /* Create domain */
+               indom = pmInDom_build(60, 40);
 
-               pmiAddMetric(name,
-                            pmiID(60, 4, inst++), PM_TYPE_U64, indom, PM_SEM_COUNTER,
+               /* Create metric */
+               pmiAddMetric("kernel.percpu.interrupts",
+                            pmiID(60, 4, 1), PM_TYPE_U32, indom, PM_SEM_COUNTER,
                             pmiUnits(0, 0, 1, 0, 0, PM_COUNT_ONE));
+       }
+
+       /* Create instance for each interrupt for the current CPU */
+       while (list != NULL) {
+               snprintf(buf, sizeof(buf), "%s::cpu%d", list->item_name, cpu);
+               buf[sizeof(buf) - 1] = '\0';
+
+               pmiAddInstance(indom, buf, inst++);
                list = list->next;
        }
+#endif /* HAVE_PCP */
 }
 
 /*
@@ -247,7 +255,7 @@ void pcp_def_cpu_metrics(struct activity *a)
 
                                else if (a->id == A_IRQ) {
                                        /* Create per-CPU interrupts metrics */
-                                       pcp_def_percpu_int_metrics(a, indom);
+                                       pcp_def_percpu_int_metrics(a, i - 1);
                                }
                                first = FALSE;
                        }
index 41acb24831eaef677f60077dfe1b431ae40b6b11..1c99f78a3d0d10591069bbbeeb0fa5cec2df3024 100644 (file)
@@ -202,7 +202,7 @@ __print_funct_t pcp_print_irq_stats(struct activity *a, int curr)
 {
 #ifdef HAVE_PCP
        int i, c;
-       char buf[64], cpuno[64], name[64];
+       char buf[64], name[64];
        struct stats_irq *stc_cpu_irq, *stc_cpuall_irq;
        unsigned char masked_cpu_bitmap[BITMAP_SIZE(NR_CPUS)] = {0};
 
@@ -250,16 +250,11 @@ __print_funct_t pcp_print_irq_stats(struct activity *a, int curr)
                        }
                        else {
                                /* This is a particular CPU */
-                               sprintf(cpuno, "cpu%d", c - 1);
-
-                               snprintf(name, sizeof(name), "kernel.percpu.interrupts.%s",
-                                        stc_cpuall_irq->irq_name);
+                               snprintf(name, sizeof(name), "%s::cpu%d",
+                                        stc_cpuall_irq->irq_name, c - 1);
                                name[sizeof(name) - 1] = '\0';
 
-                               /* Metric name cannot contain digits */
-                               replace_digits(name);
-
-                               pmiPutValue(name, cpuno, buf);
+                               pmiPutValue("kernel.percpu.interrupts", name, buf);
                        }
                }
        }
diff --git a/sa.h b/sa.h
index 49736a78ef4db7d42f051ca0b7f5599310900095..91c0a2ab1454c7636fa5a30bb8cdd58706149248 100644 (file)
--- a/sa.h
+++ b/sa.h
@@ -1576,8 +1576,6 @@ int read_record_hdr
         int, size_t, uint64_t, struct report_format *);
 void reallocate_all_buffers
        (struct activity *, __nr_t);
-void replace_digits
-       (char []);
 void replace_nonprintable_char
        (int, char *);
 int sa_fread
index 4574921cefa60a396183210bda45764a55f424db..cff0fe2d86cb715c99568b0a85ab81d16d67a5e4 100644 (file)
@@ -1728,19 +1728,3 @@ void init_custom_color_palette()
                }
        }
 }
-
-/*
- ***************************************************************************
- * Replace digits in a string with letters ('0' -> 'a', etc.
- ***************************************************************************
- */
-void replace_digits(char name[])
-{
-       int i;
-
-       for (i = 0; i < strlen(name); i++) {
-               if ((name[i] >= '0') && (name[i] <= '9')) {
-                       name[i] += 'a' - '0';
-               }
-       }
-}