2 * mpstat: per-processor statistics
3 * (C) 2000-2010 by Sebastien GODARD (sysstat <at> orange.fr)
5 ***************************************************************************
6 * This program is free software; you can redistribute it and/or modify it *
7 * under the terms of the GNU General Public License as published by the *
8 * Free Software Foundation; either version 2 of the License, or (at your *
9 * option) any later version. *
11 * This program is distributed in the hope that it will be useful, but *
12 * WITHOUT ANY WARRANTY; without the implied warranty of MERCHANTABILITY *
13 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License *
16 * You should have received a copy of the GNU General Public License along *
17 * with this program; if not, write to the Free Software Foundation, Inc., *
18 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA *
19 ***************************************************************************
29 #include <sys/utsname.h>
39 #define _(string) gettext(string)
41 #define _(string) (string)
44 #define SCCSID "@(#)sysstat-" VERSION ": " __FILE__ " compiled " __DATE__ " " __TIME__
45 char *sccsid(void) { return (SCCSID); }
47 unsigned long long uptime[3] = {0, 0, 0};
48 unsigned long long uptime0[3] = {0, 0, 0};
50 /* NOTE: Use array of _char_ for bitmaps to avoid endianness problems...*/
51 unsigned char *cpu_bitmap; /* Bit 0: Global; Bit 1: 1st proc; etc. */
53 /* Structures used to store stats */
54 struct stats_cpu *st_cpu[3];
55 struct stats_irq *st_irq[3];
56 struct stats_irqcpu *st_irqcpu[3];
57 struct stats_irqcpu *st_softirqcpu[3];
59 struct tm mp_tstamp[3];
62 unsigned int actflags = 0;
64 unsigned int flags = 0;
66 /* Interval and count parameters */
67 long interval = -1, count = 0;
69 /* Nb of processors on the machine */
71 /* Nb of interrupts per processor */
73 /* Nb of soft interrupts per processor */
74 int softirqcpu_nr = 0;
77 ***************************************************************************
78 * Print usage and exit
81 * @progname Name of sysstat command
82 ***************************************************************************
84 void usage(char *progname)
86 fprintf(stderr, _("Usage: %s [ options ] [ <interval> [ <count> ] ]\n"),
89 fprintf(stderr, _("Options are:\n"
90 "[ -A ] [ -I { SUM | CPU | SCPU | ALL } ] [ -u ] [ -P { <cpu> [,...] | ALL } ] [ -V ]\n"));
95 ***************************************************************************
96 * SIGALRM signal handler
99 * @sig Signal number. Set to 0 for the first time, then to SIGALRM.
100 ***************************************************************************
102 void alarm_handler(int sig)
104 signal(SIGALRM, alarm_handler);
109 ***************************************************************************
110 * Allocate stats structures and cpu bitmap.
113 * @nr_cpus Number of CPUs. This is the real number of available CPUs + 1
114 * because we also have to allocate a structure for CPU 'all'.
115 ***************************************************************************
117 void salloc_mp_struct(int nr_cpus)
121 for (i = 0; i < 3; i++) {
123 if ((st_cpu[i] = (struct stats_cpu *) malloc(STATS_CPU_SIZE * nr_cpus))
128 memset(st_cpu[i], 0, STATS_CPU_SIZE * nr_cpus);
130 if ((st_irq[i] = (struct stats_irq *) malloc(STATS_IRQ_SIZE * nr_cpus))
135 memset(st_irq[i], 0, STATS_IRQ_SIZE * nr_cpus);
137 if ((st_irqcpu[i] = (struct stats_irqcpu *) malloc(STATS_IRQCPU_SIZE * nr_cpus * irqcpu_nr))
142 memset(st_irqcpu[i], 0, STATS_IRQCPU_SIZE * nr_cpus * irqcpu_nr);
144 if ((st_softirqcpu[i] = (struct stats_irqcpu *) malloc(STATS_IRQCPU_SIZE * nr_cpus * softirqcpu_nr))
149 memset(st_softirqcpu[i], 0, STATS_IRQCPU_SIZE * nr_cpus * softirqcpu_nr);
152 if ((cpu_bitmap = (unsigned char *) malloc((nr_cpus >> 3) + 1)) == NULL) {
156 memset(cpu_bitmap, 0, (nr_cpus >> 3) + 1);
160 ***************************************************************************
161 * Free structures and bitmap.
162 ***************************************************************************
164 void sfree_mp_struct(void)
168 for (i = 0; i < 3; i++) {
179 if (st_softirqcpu[i]) {
180 free(st_softirqcpu[i]);
190 ***************************************************************************
191 * Display per CPU statistics.
194 * @st_ic Array for per-CPU statistics.
195 * @ic_nr Number of interrupts (hard or soft) per CPU.
196 * @dis TRUE if a header line must be printed.
197 * @itv Interval value.
198 * @prev Position in array where statistics used as reference are.
199 * Stats used as reference may be the previous ones read, or
200 * the very first ones when calculating the average.
201 * @curr Position in array where current statistics will be saved.
202 * @prev_string String displayed at the beginning of a header line. This is
203 * the timestamp of the previous sample, or "Average" when
204 * displaying average stats.
205 * @curr_string String displayed at the beginning of current sample stats.
206 * This is the timestamp of the current sample, or "Average"
207 * when displaying average stats.
208 ***************************************************************************
210 void write_irqcpu_stats(struct stats_irqcpu *st_ic[], int ic_nr, int dis,
211 unsigned long long itv, int prev, int curr,
212 char *prev_string, char *curr_string)
214 int j = 0, offset, cpu;
215 struct stats_irqcpu *p, *q, *p0, *q0;
218 * Check if number of interrupts has changed.
219 * NB: A null interval value indicates that we are
220 * displaying statistics since system startup.
222 if (!dis && interval) {
224 p0 = st_ic[curr] + j;
225 if (p0->irq_name[0] != '\0') {
226 q0 = st_ic[prev] + j;
227 if (strcmp(p0->irq_name, q0->irq_name)) {
228 /* These are two different irq */
234 while ((j > 0) && (j <= ic_nr));
237 if (dis || (j < 0)) {
239 printf("\n%-11s CPU", prev_string);
240 for (j = 0; j < ic_nr; j++) {
241 p0 = st_ic[curr] + j;
242 if (p0->irq_name[0] != '\0') { /* Nb of irq per proc may have varied... */
243 printf(" %8s/s", p0->irq_name);
249 for (cpu = 1; cpu <= cpu_nr; cpu++) {
252 * Check if we want stats about this CPU.
253 * CPU must have been explicitly selected using option -P,
254 * else we display every CPU.
256 if (!(*(cpu_bitmap + (cpu >> 3)) & (1 << (cpu & 0x07))) && USE_P_OPTION(flags))
259 printf("%-11s %3d", curr_string, cpu - 1);
261 for (j = 0; j < ic_nr; j++) {
262 p0 = st_ic[curr] + j; /* irq field set only for proc #0 */
264 * An empty string for irq name means it is a remaining interrupt
265 * which is no longer used, for example because the
266 * number of interrupts has decreased in /proc/interrupts.
268 if (p0->irq_name[0] != '\0') {
269 q0 = st_ic[prev] + j;
273 * If we want stats for the time since system startup,
274 * we have p0->irq != q0->irq, since q0 structure is
275 * completely set to zero.
277 if (strcmp(p0->irq_name, q0->irq_name) && interval) {
280 q0 = st_ic[prev] + offset;
281 if (strcmp(p0->irq_name, q0->irq_name) && (j + 1 < ic_nr))
283 q0 = st_ic[prev] + offset;
286 if (!strcmp(p0->irq_name, q0->irq_name) || !interval) {
287 p = st_ic[curr] + (cpu - 1) * ic_nr + j;
288 q = st_ic[prev] + (cpu - 1) * ic_nr + offset;
290 S_VALUE(q->interrupt, p->interrupt, itv));
301 ***************************************************************************
302 * Core function used to display statistics
305 * @prev Position in array where statistics used as reference are.
306 * Stats used as reference may be the previous ones read, or
307 * the very first ones when calculating the average.
308 * @curr Position in array where statistics for current sample are.
309 * @dis TRUE if a header line must be printed.
310 * @prev_string String displayed at the beginning of a header line. This is
311 * the timestamp of the previous sample, or "Average" when
312 * displaying average stats.
313 * @curr_string String displayed at the beginning of current sample stats.
314 * This is the timestamp of the current sample, or "Average"
315 * when displaying average stats.
316 ***************************************************************************
318 void write_stats_core(int prev, int curr, int dis,
319 char *prev_string, char *curr_string)
321 struct stats_cpu *scc, *scp;
322 unsigned long long itv, pc_itv, g_itv;
326 TEST_STDOUT(STDOUT_FILENO);
328 /* Compute time interval */
329 g_itv = get_interval(uptime[prev], uptime[curr]);
331 /* Reduce interval value to one processor */
333 itv = get_interval(uptime0[prev], uptime0[curr]);
339 /* Print CPU stats */
340 if (DISPLAY_CPU(actflags)) {
342 printf("\n%-11s CPU %%usr %%nice %%sys %%iowait %%irq "
343 "%%soft %%steal %%guest %%idle\n",
347 /* Check if we want global stats among all proc */
348 if (*cpu_bitmap & 1) {
350 printf("%-11s all", curr_string);
352 printf(" %6.2f %6.2f %6.2f %6.2f %6.2f %6.2f %6.2f %6.2f %6.2f\n",
353 (st_cpu[curr]->cpu_user - st_cpu[curr]->cpu_guest) <
354 (st_cpu[prev]->cpu_user - st_cpu[prev]->cpu_guest) ?
356 ll_sp_value(st_cpu[prev]->cpu_user - st_cpu[prev]->cpu_guest,
357 st_cpu[curr]->cpu_user - st_cpu[curr]->cpu_guest,
359 ll_sp_value(st_cpu[prev]->cpu_nice,
360 st_cpu[curr]->cpu_nice,
362 ll_sp_value(st_cpu[prev]->cpu_sys,
363 st_cpu[curr]->cpu_sys,
365 ll_sp_value(st_cpu[prev]->cpu_iowait,
366 st_cpu[curr]->cpu_iowait,
368 ll_sp_value(st_cpu[prev]->cpu_hardirq,
369 st_cpu[curr]->cpu_hardirq,
371 ll_sp_value(st_cpu[prev]->cpu_softirq,
372 st_cpu[curr]->cpu_softirq,
374 ll_sp_value(st_cpu[prev]->cpu_steal,
375 st_cpu[curr]->cpu_steal,
377 ll_sp_value(st_cpu[prev]->cpu_guest,
378 st_cpu[curr]->cpu_guest,
380 (st_cpu[curr]->cpu_idle < st_cpu[prev]->cpu_idle) ?
382 ll_sp_value(st_cpu[prev]->cpu_idle,
383 st_cpu[curr]->cpu_idle,
387 for (cpu = 1; cpu <= cpu_nr; cpu++) {
389 scc = st_cpu[curr] + cpu;
390 scp = st_cpu[prev] + cpu;
392 /* Check if we want stats about this proc */
393 if (!(*(cpu_bitmap + (cpu >> 3)) & (1 << (cpu & 0x07))))
396 printf("%-11s %4d", curr_string, cpu - 1);
399 * If the CPU is offline then it is omited from /proc/stat
400 * and the sum of all values is zero.
401 * (Remember that guest time is already included in user mode.)
403 if ((scc->cpu_user + scc->cpu_nice + scc->cpu_sys +
404 scc->cpu_iowait + scc->cpu_idle + scc->cpu_steal +
405 scc->cpu_hardirq + scc->cpu_softirq) == 0) {
407 * Set current struct fields (which have been set to zero)
408 * to values from previous iteration. Hence their values won't
409 * jump from zero when the CPU comes back online.
413 printf(" %6.2f %6.2f %6.2f %6.2f %6.2f %6.2f"
414 " %6.2f %6.2f %6.2f\n",
415 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0);
419 /* Recalculate itv for current proc */
420 pc_itv = get_per_cpu_interval(scc, scp);
424 * If the CPU is tickless then there is no change in CPU values
425 * but the sum of values is not zero.
427 printf(" %6.2f %6.2f %6.2f %6.2f %6.2f %6.2f"
428 " %6.2f %6.2f %6.2f\n",
429 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 100.0);
433 printf(" %6.2f %6.2f %6.2f %6.2f %6.2f %6.2f"
434 " %6.2f %6.2f %6.2f\n",
435 (scc->cpu_user - scc->cpu_guest) < (scp->cpu_user - scp->cpu_guest) ?
437 ll_sp_value(scp->cpu_user - scp->cpu_guest,
438 scc->cpu_user - scc->cpu_guest,
440 ll_sp_value(scp->cpu_nice,
443 ll_sp_value(scp->cpu_sys,
446 ll_sp_value(scp->cpu_iowait,
449 ll_sp_value(scp->cpu_hardirq,
452 ll_sp_value(scp->cpu_softirq,
455 ll_sp_value(scp->cpu_steal,
458 ll_sp_value(scp->cpu_guest,
461 (scc->cpu_idle < scp->cpu_idle) ?
463 ll_sp_value(scp->cpu_idle,
470 /* Print total number of interrupts per processor */
471 if (DISPLAY_IRQ_SUM(actflags)) {
472 struct stats_irq *sic, *sip;
475 printf("\n%-11s CPU intr/s\n", prev_string);
478 if (*cpu_bitmap & 1) {
479 printf("%-11s all %9.2f\n", curr_string,
480 ll_s_value(st_irq[prev]->irq_nr, st_irq[curr]->irq_nr, itv));
483 for (cpu = 1; cpu <= cpu_nr; cpu++) {
485 sic = st_irq[curr] + cpu;
486 sip = st_irq[prev] + cpu;
488 scc = st_cpu[curr] + cpu;
489 scp = st_cpu[prev] + cpu;
491 /* Check if we want stats about this proc */
492 if (!(*(cpu_bitmap + (cpu >> 3)) & (1 << (cpu & 0x07))))
495 printf("%-11s %4d", curr_string, cpu - 1);
497 /* Recalculate itv for current proc */
498 pc_itv = get_per_cpu_interval(scc, scp);
501 /* Current CPU is offline */
502 printf(" %9.2f\n", 0.0);
506 ll_s_value(sip->irq_nr, sic->irq_nr, itv));
511 if (DISPLAY_IRQ_CPU(actflags)) {
512 write_irqcpu_stats(st_irqcpu, irqcpu_nr, dis, itv, prev, curr,
513 prev_string, curr_string);
516 if (DISPLAY_SOFTIRQS(actflags)) {
517 write_irqcpu_stats(st_softirqcpu, softirqcpu_nr, dis, itv, prev, curr,
518 prev_string, curr_string);
523 ***************************************************************************
524 * Print statistics average
527 * @curr Position in array where statistics for current sample are.
528 * @dis TRUE if a header line must be printed.
529 ***************************************************************************
531 void write_stats_avg(int curr, int dis)
535 strncpy(string, _("Average:"), 16);
537 write_stats_core(2, curr, dis, string, string);
541 ***************************************************************************
545 * @curr Position in array where statistics for current sample are.
546 * @dis TRUE if a header line must be printed.
547 ***************************************************************************
549 void write_stats(int curr, int dis)
551 char cur_time[2][16];
553 /* Get previous timestamp */
554 strftime(cur_time[!curr], 16, "%X", &(mp_tstamp[!curr]));
556 /* Get current timestamp */
557 strftime(cur_time[curr], 16, "%X", &(mp_tstamp[curr]));
559 write_stats_core(!curr, curr, dis, cur_time[!curr], cur_time[curr]);
563 ***************************************************************************
564 * Read stats from /proc/interrupts or /proc/softirqs.
567 * @file /proc file to read (interrupts or softirqs).
568 * @ic_nr Number of interrupts (hard or soft) per CPU.
569 * @curr Position in array where current statistics will be saved.
572 * @st_ic Array for per-CPU statistics.
573 ***************************************************************************
575 void read_interrupts_stat(char *file, struct stats_irqcpu *st_ic[], int ic_nr, int curr)
578 struct stats_irq *st_irq_i;
579 struct stats_irqcpu *p;
581 unsigned long irq = 0;
583 int cpu_index[cpu_nr], index = 0, dgt, len;
586 for (cpu = 0; cpu < cpu_nr; cpu++) {
587 st_irq_i = st_irq[curr] + cpu + 1;
588 st_irq_i->irq_nr = 0;
591 if ((fp = fopen(file, "r")) != NULL) {
593 SREALLOC(line, char, INTERRUPTS_LINE + 11 * cpu_nr);
596 * Parse header line to see which CPUs are online
598 while (fgets(line, INTERRUPTS_LINE + 11 * cpu_nr, fp) != NULL) {
600 while (((cp = strstr(next, "CPU")) != NULL) && (index < cpu_nr)) {
601 cpu = strtol(cp + 3, &next, 10);
602 cpu_index[index++] = cpu;
605 /* Header line found */
609 while ((fgets(line, INTERRUPTS_LINE + 11 * cpu_nr, fp) != NULL) &&
612 /* Skip over "<irq>:" */
613 if ((cp = strchr(line, ':')) == NULL)
617 p = st_ic[curr] + irq;
618 len = strcspn(line, ":");
619 if (len >= MAX_IRQ_LEN) {
620 len = MAX_IRQ_LEN - 1;
622 strncpy(p->irq_name, line, len);
623 p->irq_name[len] = '\0';
624 dgt = isdigit(line[len - 1]);
626 for (cpu = 0; cpu < index; cpu++) {
627 p = st_ic[curr] + cpu_index[cpu] * ic_nr + irq;
628 st_irq_i = st_irq[curr] + cpu_index[cpu] + 1;
630 * No need to set (st_irqcpu + cpu * irqcpu_nr)->irq:
631 * This is the same as st_irqcpu->irq.
633 p->interrupt = strtoul(cp, &next, 10);
635 /* Sum only numerical irq (and not NMI, LOC, etc.) */
636 st_irq_i->irq_nr += p->interrupt;
650 while (irq < ic_nr) {
651 /* Nb of interrupts per processor has changed */
652 p = st_ic[curr] + irq;
653 p->irq_name[0] = '\0'; /* This value means this is a dummy interrupt */
659 ***************************************************************************
660 * Main loop: Read stats from the relevant sources, and display them.
663 * @dis_hdr Set to TRUE if the header line must always be printed.
664 * @rows Number of rows of screen.
665 ***************************************************************************
667 void rw_mpstat_loop(int dis_hdr, int rows)
669 struct stats_cpu *scc;
671 int curr = 1, dis = 1;
672 unsigned long lines = rows;
674 /* Dont buffer data if redirected to a pipe */
675 setbuf(stdout, NULL);
680 * Init uptime0. So if /proc/uptime cannot fill it,
681 * this will be done by /proc/stat.
684 read_uptime(&(uptime0[0]));
686 read_stat_cpu(st_cpu[0], cpu_nr + 1, &(uptime[0]), &(uptime0[0]));
688 if (DISPLAY_IRQ_SUM(actflags)) {
689 read_stat_irq(st_irq[0], 1);
692 if (DISPLAY_IRQ_SUM(actflags) || DISPLAY_IRQ_CPU(actflags)) {
693 /* Read this file to display int per CPU or total nr of int per CPU */
694 read_interrupts_stat(INTERRUPTS, st_irqcpu, irqcpu_nr, 0);
697 if (DISPLAY_SOFTIRQS(actflags)) {
698 read_interrupts_stat(SOFTIRQS, st_softirqcpu, softirqcpu_nr, 0);
702 /* Display since boot time */
703 mp_tstamp[1] = mp_tstamp[0];
704 memset(st_cpu[1], 0, STATS_CPU_SIZE * (cpu_nr + 1));
705 memset(st_irq[1], 0, STATS_IRQ_SIZE * (cpu_nr + 1));
706 memset(st_irqcpu[1], 0, STATS_IRQCPU_SIZE * (cpu_nr + 1) * irqcpu_nr);
707 if (DISPLAY_SOFTIRQS(actflags)) {
708 memset(st_softirqcpu[1], 0, STATS_IRQCPU_SIZE * (cpu_nr + 1) * softirqcpu_nr);
710 write_stats(0, DISP_HDR);
714 /* Set a handler for SIGALRM */
717 /* Save the first stats collected. Will be used to compute the average */
718 mp_tstamp[2] = mp_tstamp[0];
719 uptime[2] = uptime[0];
720 uptime0[2] = uptime0[0];
721 memcpy(st_cpu[2], st_cpu[0], STATS_CPU_SIZE * (cpu_nr + 1));
722 memcpy(st_irq[2], st_irq[0], STATS_IRQ_SIZE * (cpu_nr + 1));
723 memcpy(st_irqcpu[2], st_irqcpu[0], STATS_IRQCPU_SIZE * (cpu_nr + 1) * irqcpu_nr);
724 if (DISPLAY_SOFTIRQS(actflags)) {
725 memcpy(st_softirqcpu[2], st_softirqcpu[0],
726 STATS_IRQCPU_SIZE * (cpu_nr + 1) * softirqcpu_nr);
733 * Resetting the structure not needed since every fields will be set.
734 * Exceptions are per-CPU structures: Some of them may not be filled
735 * if corresponding processor is disabled (offline). We set them to zero
736 * to be able to distinguish between offline and tickless CPUs.
738 for (cpu = 1; cpu <= cpu_nr; cpu++) {
739 scc = st_cpu[curr] + cpu;
740 memset(scc, 0, STATS_CPU_SIZE);
744 get_localtime(&(mp_tstamp[curr]));
749 read_uptime(&(uptime0[curr]));
751 read_stat_cpu(st_cpu[curr], cpu_nr + 1, &(uptime[curr]), &(uptime0[curr]));
753 if (DISPLAY_IRQ_SUM(actflags)) {
754 read_stat_irq(st_irq[curr], 1);
757 if (DISPLAY_IRQ_SUM(actflags) || DISPLAY_IRQ_CPU(actflags)) {
758 read_interrupts_stat(INTERRUPTS, st_irqcpu, irqcpu_nr, curr);
761 if (DISPLAY_SOFTIRQS(actflags)) {
762 read_interrupts_stat(SOFTIRQS, st_softirqcpu, softirqcpu_nr, curr);
773 write_stats(curr, dis);
785 /* Write stats average */
786 write_stats_avg(curr, dis_hdr);
790 ***************************************************************************
791 * Main entry to the program
792 ***************************************************************************
794 int main(int argc, char **argv)
796 int opt = 0, i, actset = FALSE;
797 struct utsname header;
803 /* Init National Language Support */
810 /* How many processors on this machine ? */
811 cpu_nr = get_cpu_nr(~0);
813 /* Calculate number of interrupts per processor */
814 irqcpu_nr = get_irqcpu_nr(INTERRUPTS, NR_IRQS, cpu_nr) +
816 /* Calculate number of soft interrupts per processor */
817 softirqcpu_nr = get_irqcpu_nr(SOFTIRQS, NR_IRQS, cpu_nr) +
821 * cpu_nr: a value of 2 means there are 2 processors (0 and 1).
822 * In this case, we have to allocate 3 structures: global, proc0 and proc1.
824 salloc_mp_struct(cpu_nr + 1);
826 while (++opt < argc) {
828 if (!strcmp(argv[opt], "-I")) {
831 if (!strcmp(argv[opt], K_SUM)) {
832 /* Display total number of interrupts per CPU */
833 actflags |= M_D_IRQ_SUM;
835 else if (!strcmp(argv[opt], K_CPU)) {
836 /* Display interrupts per CPU */
837 actflags |= M_D_IRQ_CPU;
839 else if (!strcmp(argv[opt], K_SCPU)) {
840 /* Display soft interrupts per CPU */
841 actflags |= M_D_SOFTIRQS;
843 else if (!strcmp(argv[opt], K_ALL)) {
844 actflags |= M_D_IRQ_SUM + M_D_IRQ_CPU + M_D_SOFTIRQS;
855 else if (!strcmp(argv[opt], "-P")) {
856 /* '-P ALL' can be used on UP machines */
861 for (t = strtok(argv[opt], ","); t; t = strtok(NULL, ",")) {
862 if (!strcmp(t, K_ALL)) {
867 * Set bit for every processor.
868 * Also indicate to display stats for CPU 'all'.
870 memset(cpu_bitmap, 0xff, ((cpu_nr + 1) >> 3) + 1);
873 if (strspn(t, DIGITS) != strlen(t)) {
876 i = atoi(t); /* Get cpu number */
878 fprintf(stderr, _("Not that many processors!\n"));
882 *(cpu_bitmap + (i >> 3)) |= 1 << (i & 0x07);
891 else if (!strncmp(argv[opt], "-", 1)) {
892 for (i = 1; *(argv[opt] + i); i++) {
894 switch (*(argv[opt] + i)) {
897 actflags |= M_D_CPU + M_D_IRQ_SUM + M_D_IRQ_CPU + M_D_SOFTIRQS;
899 /* Select all processors */
901 memset(cpu_bitmap, 0xff, ((cpu_nr + 1) >> 3) + 1);
910 /* Print version number */
920 else if (interval < 0) {
922 if (strspn(argv[opt], DIGITS) != strlen(argv[opt])) {
925 interval = atol(argv[opt]);
932 else if (count <= 0) {
933 /* Get count value */
934 if ((strspn(argv[opt], DIGITS) != strlen(argv[opt])) ||
938 count = atol(argv[opt]);
949 /* Default: Display CPU */
954 if (count_bits(&actflags, sizeof(unsigned int)) > 1) {
958 if (!USE_P_OPTION(flags)) {
959 /* Option -P not used: Set bit 0 (global stats among all proc) */
966 /* Get window size */
967 rows = get_win_height();
970 /* Interval not set => display stats since boot time */
975 get_localtime(&(mp_tstamp[0]));
977 /* Get system name, release number and hostname */
979 print_gal_header(&(mp_tstamp[0]), header.sysname, header.release,
980 header.nodename, header.machine, cpu_nr);
983 rw_mpstat_loop(dis_hdr, rows);
985 /* Free structures */