]> granicus.if.org Git - sysstat/commitdiff
mpstat: Rework option -P parsing
authorSebastien GODARD <sysstat@users.noreply.github.com>
Sun, 20 Nov 2016 09:28:35 +0000 (10:28 +0100)
committerSebastien GODARD <sysstat@users.noreply.github.com>
Sun, 20 Nov 2016 09:28:35 +0000 (10:28 +0100)
It is no longer possibe to specify individual CPUs and also to use
keyword ALL together (e.g. mpstat -P ALL,0,2) which is meaningless.
Also separate options "-P ALL" from "-P ON".

Signed-off-by: Sebastien GODARD <sysstat@users.noreply.github.com>
mpstat.c

index bd29bec612a2c95ac416e0e882ff0a57930fdf85..88eebd4d0dc93a648d53163ee82ca08e87ee40c2 100644 (file)
--- a/mpstat.c
+++ b/mpstat.c
@@ -1610,24 +1610,19 @@ int main(int argc, char **argv)
                        /* '-P ALL' can be used on UP machines */
                        if (argv[++opt]) {
                                flags |= F_P_OPTION;
-                               dis_hdr++;
+                               dis_hdr = 9;
 
-                               for (t = strtok(argv[opt], ","); t; t = strtok(NULL, ",")) {
-                                       if (!strcmp(t, K_ALL) || !strcmp(t, K_ON)) {
-                                               if (cpu_nr) {
-                                                       dis_hdr = 9;
-                                               }
-                                               /*
-                                                * Set bit for every processor.
-                                                * Also indicate to display stats for CPU 'all'.
-                                                */
-                                               memset(cpu_bitmap, 0xff, ((cpu_nr + 1) >> 3) + 1);
-                                               if (!strcmp(t, K_ON)) {
-                                                       /* Display stats only for online CPU */
-                                                       flags |= F_P_ON;
-                                               }
-                                       }
-                                       else {
+                               if (!strcmp(argv[opt], K_ON)) {
+                                       /* Display stats for all online CPU */
+                                       flags |= F_P_ON;
+                                       memset(cpu_bitmap, ~0, ((cpu_nr + 1) >> 3) + 1);
+                               }
+                               else if (!strcmp(argv[opt], K_ALL)) {
+                                       /* Set bit for every processor, including CPU "all" */
+                                       memset(cpu_bitmap, ~0, ((cpu_nr + 1) >> 3) + 1);
+                               }
+                               else {
+                                       for (t = strtok(argv[opt], ","); t; t = strtok(NULL, ",")) {
                                                if (strspn(t, DIGITS) != strlen(t)) {
                                                        usage(argv[0]);
                                                }