Skip to content

Commit 25be7e1

Browse files
committed
Merge branch 'jaunix-mpstat'
Signed-off-by: Sebastien GODARD <[email protected]>
2 parents b8369bf + a9def1b commit 25be7e1

File tree

1 file changed

+20
-2
lines changed

1 file changed

+20
-2
lines changed

mpstat.c

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -218,8 +218,9 @@ void write_irqcpu_stats(struct stats_irqcpu *st_ic[], int ic_nr, int dis,
218218
char *prev_string, char *curr_string)
219219
{
220220
struct stats_cpu *scc;
221-
int j = 0, offset, cpu;
221+
int j = 0, offset, cpu, colwidth[NR_IRQS];
222222
struct stats_irqcpu *p, *q, *p0, *q0;
223+
char fmtspec[MAX_IRQ_LEN];
223224

224225
/*
225226
* Check if number of interrupts has changed.
@@ -253,6 +254,22 @@ void write_irqcpu_stats(struct stats_irqcpu *st_ic[], int ic_nr, int dis,
253254
printf("\n");
254255
}
255256

257+
/* Calculate column widths */
258+
for (j = 0; j < ic_nr; j++) {
259+
p0 = st_ic[curr] + j;
260+
if (p0->irq_name[0] != '\0') {
261+
/* Width is IRQ name + 2 for the trailing "/s" */
262+
colwidth[j] = strlen(p0->irq_name) + 2;
263+
/*
264+
* Normal space for printing a number is 14 chars
265+
* (space + 10 digits + period + mantissa).
266+
*/
267+
if (colwidth[j] < 14) {
268+
colwidth[j] = 10;
269+
}
270+
}
271+
}
272+
256273
for (cpu = 1; cpu <= cpu_nr; cpu++) {
257274

258275
scc = st_cpu[curr] + cpu;
@@ -305,7 +322,8 @@ void write_irqcpu_stats(struct stats_irqcpu *st_ic[], int ic_nr, int dis,
305322
if (!strcmp(p0->irq_name, q0->irq_name) || !interval) {
306323
p = st_ic[curr] + (cpu - 1) * ic_nr + j;
307324
q = st_ic[prev] + (cpu - 1) * ic_nr + offset;
308-
printf(" %10.2f",
325+
snprintf(fmtspec, sizeof(fmtspec), " %%%d.2f", colwidth[j]);
326+
printf(fmtspec,
309327
S_VALUE(q->interrupt, p->interrupt, itv));
310328
}
311329
else

0 commit comments

Comments
 (0)