diff options
author | Denys Vlasenko <vda.linux@googlemail.com> | 2010-07-21 11:54:33 +0200 |
---|---|---|
committer | Denys Vlasenko <vda.linux@googlemail.com> | 2010-07-21 11:54:33 +0200 |
commit | 217df6ea9fe3fa93e2cf3e6b44cbec14a526f422 (patch) | |
tree | e45db9a51709fdc4f3eb493208d688f6cfc8c5bd | |
parent | 23e8c08fa2e1faab335e7ff625272f57d1dde469 (diff) | |
download | busybox-w32-217df6ea9fe3fa93e2cf3e6b44cbec14a526f422.tar.gz busybox-w32-217df6ea9fe3fa93e2cf3e6b44cbec14a526f422.tar.bz2 busybox-w32-217df6ea9fe3fa93e2cf3e6b44cbec14a526f422.zip |
mpstat: small code shrink
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
-rw-r--r-- | procps/mpstat.c | 24 |
1 files changed, 10 insertions, 14 deletions
diff --git a/procps/mpstat.c b/procps/mpstat.c index 0f633c713..125bb3de7 100644 --- a/procps/mpstat.c +++ b/procps/mpstat.c | |||
@@ -57,7 +57,6 @@ struct stats_irqcpu { | |||
57 | char irq_name[MAX_IRQ_LEN]; | 57 | char irq_name[MAX_IRQ_LEN]; |
58 | }; | 58 | }; |
59 | 59 | ||
60 | /* Structure for CPU statistics */ | ||
61 | struct stats_cpu { | 60 | struct stats_cpu { |
62 | data_t cpu_user; | 61 | data_t cpu_user; |
63 | data_t cpu_nice; | 62 | data_t cpu_nice; |
@@ -70,13 +69,12 @@ struct stats_cpu { | |||
70 | data_t cpu_guest; | 69 | data_t cpu_guest; |
71 | }; | 70 | }; |
72 | 71 | ||
73 | /* Struct for interrupts statistics */ | ||
74 | struct stats_irq { | 72 | struct stats_irq { |
75 | data_t irq_nr; | 73 | data_t irq_nr; |
76 | }; | 74 | }; |
77 | 75 | ||
78 | 76 | ||
79 | /* Globals. Try to sort by size. */ | 77 | /* Globals. Sort by size and access frequency. */ |
80 | struct globals { | 78 | struct globals { |
81 | int interval; | 79 | int interval; |
82 | int count; | 80 | int count; |
@@ -451,11 +449,10 @@ static void get_cpu_statistics(struct stats_cpu *cpu, data_t *up, data_t *up0) | |||
451 | 449 | ||
452 | if (!starts_with_cpu(buf)) | 450 | if (!starts_with_cpu(buf)) |
453 | continue; /* not "cpu" */ | 451 | continue; /* not "cpu" */ |
454 | if (buf[3] == ' ') { | 452 | |
455 | /* "cpu " */ | 453 | cp = cpu; /* for "cpu " case */ |
456 | cp = cpu; | 454 | if (buf[3] != ' ') { |
457 | } else { | 455 | /* "cpuN " */ |
458 | /* "cpuN" */ | ||
459 | if (G.cpu_nr == 0 | 456 | if (G.cpu_nr == 0 |
460 | || sscanf(buf + 3, "%u ", &cpu_number) != 1 | 457 | || sscanf(buf + 3, "%u ", &cpu_number) != 1 |
461 | || cpu_number >= G.cpu_nr | 458 | || cpu_number >= G.cpu_nr |
@@ -465,17 +462,16 @@ static void get_cpu_statistics(struct stats_cpu *cpu, data_t *up, data_t *up0) | |||
465 | cp = &cpu[cpu_number + 1]; | 462 | cp = &cpu[cpu_number + 1]; |
466 | } | 463 | } |
467 | 464 | ||
468 | /* Read the jiffies, save them */ | 465 | /* Read the counters, save them */ |
469 | /* Not all fields have to be present */ | 466 | /* Not all fields have to be present */ |
470 | memset(cp, 0, sizeof(*cp)); | 467 | memset(cp, 0, sizeof(*cp)); |
471 | sscanf(skip_non_whitespace(buf + 3), | 468 | sscanf(buf, "%*s" |
472 | " %"FMT_DATA"u %"FMT_DATA"u %"FMT_DATA"u" | 469 | " %"FMT_DATA"u %"FMT_DATA"u %"FMT_DATA"u" |
473 | " %"FMT_DATA"u %"FMT_DATA"u %"FMT_DATA"u" | 470 | " %"FMT_DATA"u %"FMT_DATA"u %"FMT_DATA"u" |
474 | " %"FMT_DATA"u %"FMT_DATA"u %"FMT_DATA"u", | 471 | " %"FMT_DATA"u %"FMT_DATA"u %"FMT_DATA"u", |
475 | &cp->cpu_user, &cp->cpu_nice, &cp->cpu_system, | 472 | &cp->cpu_user, &cp->cpu_nice, &cp->cpu_system, |
476 | &cp->cpu_idle, &cp->cpu_iowait, &cp->cpu_irq, | 473 | &cp->cpu_idle, &cp->cpu_iowait, &cp->cpu_irq, |
477 | &cp->cpu_softirq, &cp->cpu_steal, | 474 | &cp->cpu_softirq, &cp->cpu_steal, &cp->cpu_guest |
478 | &cp->cpu_guest | ||
479 | ); | 475 | ); |
480 | /* | 476 | /* |
481 | * Compute uptime in jiffies (1/HZ), it'll be the sum of | 477 | * Compute uptime in jiffies (1/HZ), it'll be the sum of |
@@ -490,7 +486,7 @@ static void get_cpu_statistics(struct stats_cpu *cpu, data_t *up, data_t *up0) | |||
490 | /* "cpu " */ | 486 | /* "cpu " */ |
491 | *up = sum; | 487 | *up = sum; |
492 | } else { | 488 | } else { |
493 | /* "cpuN" */ | 489 | /* "cpuN " */ |
494 | if (cpu_number == 0 && *up0 != 0) { | 490 | if (cpu_number == 0 && *up0 != 0) { |
495 | /* Compute uptime of single CPU */ | 491 | /* Compute uptime of single CPU */ |
496 | *up0 = sum; | 492 | *up0 = sum; |
@@ -769,7 +765,7 @@ static void print_header(struct tm *t) | |||
769 | 765 | ||
770 | strftime(cur_date, sizeof(cur_date), "%x", t); | 766 | strftime(cur_date, sizeof(cur_date), "%x", t); |
771 | 767 | ||
772 | printf("%s %s (%s) \t%s \t_%s_\t(%d CPU)\n", | 768 | printf("%s %s (%s)\t%s\t_%s_\t(%u CPU)\n", |
773 | uts.sysname, uts.release, uts.nodename, cur_date, uts.machine, G.cpu_nr); | 769 | uts.sysname, uts.release, uts.nodename, cur_date, uts.machine, G.cpu_nr); |
774 | } | 770 | } |
775 | 771 | ||