]> granicus.if.org Git - sysstat/commitdiff
Column widths : revise style to match existing code, use snprintf, calculate widths...
authorSteve Kay <stevekay@gmail.com>
Fri, 13 Mar 2015 08:57:28 +0000 (01:57 -0700)
committerSteve Kay <stevekay@gmail.com>
Fri, 13 Mar 2015 08:57:28 +0000 (01:57 -0700)
mpstat.c

index 662d18473ba65c884812fc31b448ef5f520814b2..1b41b254fdb97ac850b44465dc9fd80613ac4429 100644 (file)
--- a/mpstat.c
+++ b/mpstat.c
@@ -218,7 +218,7 @@ void write_irqcpu_stats(struct stats_irqcpu *st_ic[], int ic_nr, int dis,
                        char *prev_string, char *curr_string)
 {
        struct stats_cpu *scc;
-       int j = 0, offset, cpu, colwidth;
+       int j = 0, offset, cpu, colwidth[NR_IRQS];
        struct stats_irqcpu *p, *q, *p0, *q0;
        char fmtspec[MAX_IRQ_LEN];
 
@@ -254,6 +254,19 @@ void write_irqcpu_stats(struct stats_irqcpu *st_ic[], int ic_nr, int dis,
                printf("\n");
        }
 
+       /* Calculate column widths */
+       for (j = 0; j < ic_nr; j++) {
+               p0 = st_ic[curr] + j;
+               if (p0->irq_name[0] != '\0') { /* Nb of irq per proc may have varied... */
+                       /* Width is IRQ name + 2 for the trailing "/s" */
+                       colwidth[j] = strlen(p0->irq_name) + 2;
+                       /* normal space for printing a number is 14 chars 
+                        * (space + 10 digits + period + mantissa) */
+                       if (colwidth[j] < 14)
+                               colwidth[j] = 10;
+               }
+       }
+
        for (cpu = 1; cpu <= cpu_nr; cpu++) {
 
                scc = st_cpu[curr] + cpu;
@@ -306,13 +319,7 @@ void write_irqcpu_stats(struct stats_irqcpu *st_ic[], int ic_nr, int dis,
                                if (!strcmp(p0->irq_name, q0->irq_name) || !interval) {
                                        p = st_ic[curr] + (cpu - 1) * ic_nr + j;
                                        q = st_ic[prev] + (cpu - 1) * ic_nr + offset;
-                                       /* Width is IRQ name + 2 for the /s */
-                                       colwidth=strlen(p0->irq_name)+2;
-                                       /* normal space for printing a number is 14 chars 
-                                        * (space + 10 digits + period + mantissa) */
-                                       if(colwidth<14)
-                                               colwidth=10;
-                                       sprintf(fmtspec," %%%d.2f",colwidth);
+                                       snprintf(fmtspec, sizeof(fmtspec), " %%%d.2f", colwidth[j]);
                                        printf(fmtspec,
                                               S_VALUE(q->interrupt, p->interrupt, itv));
                                }