]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
lscpu: support +list for -e, -p and -C
authorKarel Zak <kzak@redhat.com>
Tue, 9 Mar 2021 09:37:36 +0000 (10:37 +0100)
committerKarel Zak <kzak@redhat.com>
Tue, 9 Mar 2021 09:37:36 +0000 (10:37 +0100)
For example "lscpu -e=+MHZ" to list the default columns and MHZ. We
use the same in other tools.

Signed-off-by: Karel Zak <kzak@redhat.com>
sys-utils/lscpu.1
sys-utils/lscpu.c

index a4112539528b9d64d701e504f86483f5eb83f8ab..78b4b45575c77c2796a935d201df6e50a6538393 100644 (file)
@@ -130,6 +130,9 @@ are included in the command output.
 When specifying the \fIlist\fP argument, the string of option, equal sign (=), and
 \fIlist\fP must not contain any blanks or other whitespace.
 Examples: '\fB\-C=NAME,ONE-SIZE\fP' or '\fB\-\-caches=NAME,ONE-SIZE\fP'.
+
+The default list of columns may be extended if list is specified in the format +list
+(e.g., lscpu -C=+ALLOC-POLICY).
 .TP
 .BR \-c , " \-\-offline"
 Limit the output to offline CPUs.
@@ -144,6 +147,9 @@ are included in the command output.
 When specifying the \fIlist\fP argument, the string of option, equal sign (=), and
 \fIlist\fP must not contain any blanks or other whitespace.
 Examples: '\fB\-e=cpu,node\fP' or '\fB\-\-extended=cpu,node\fP'.
+
+The default list of columns may be extended if list is specified in the format +list
+(e.g., lscpu -e=+MHZ).
 .TP
 .BR \-h , " \-\-help"
 Display help text and exit.
@@ -163,6 +169,9 @@ If the \fIlist\fP argument is used, cache columns are separated with a colon (:)
 When specifying the \fIlist\fP argument, the string of option, equal sign (=), and
 \fIlist\fP must not contain any blanks or other whitespace.
 Examples: '\fB\-p=cpu,node\fP' or '\fB\-\-parse=cpu,node\fP'.
+
+The default list of columns may be extended if list is specified in the format +list
+(e.g., lscpu -p=+MHZ).
 .TP
 .BR \-s , " \-\-sysroot " \fIdirectory\fP
 Gather CPU data for a Linux instance other than the instance from which the
index b1d162c92b2a06fd050e3adb66c9ad73b0dff11e..fdf9c759bbfd3c67990517e0b9bfeac8e3a9f654 100644 (file)
@@ -1163,6 +1163,7 @@ int main(int argc, char *argv[])
        int c, all = 0;
        int columns[ARRAY_SIZE(coldescs_cpu)], ncolumns = 0;
        int cpu_modifier_specified = 0;
+       char *outarg = NULL;
        size_t i;
        enum {
                OPT_OUTPUT_ALL = CHAR_MAX + 1,
@@ -1223,11 +1224,7 @@ int main(int argc, char *argv[])
                        if (optarg) {
                                if (*optarg == '=')
                                        optarg++;
-                               ncolumns = string_to_idarray(optarg,
-                                               columns, ARRAY_SIZE(columns),
-                                               cache_column_name_to_id);
-                               if (ncolumns < 0)
-                                       return EXIT_FAILURE;
+                               outarg = optarg;
                        }
                        cxt->mode = LSCPU_OUTPUT_CACHES;
                        break;
@@ -1239,11 +1236,7 @@ int main(int argc, char *argv[])
                        if (optarg) {
                                if (*optarg == '=')
                                        optarg++;
-                               ncolumns = string_to_idarray(optarg,
-                                               columns, ARRAY_SIZE(columns),
-                                               cpu_column_name_to_id);
-                               if (ncolumns < 0)
-                                       return EXIT_FAILURE;
+                               outarg = optarg;
                        }
                        cxt->mode = c == 'p' ? LSCPU_OUTPUT_PARSABLE : LSCPU_OUTPUT_READABLE;
                        break;
@@ -1333,6 +1326,11 @@ int main(int argc, char *argv[])
                        columns[ncolumns++] = COL_CACHE_PHYLINE;
                        columns[ncolumns++] = COL_CACHE_COHERENCYSIZE;
                }
+               if (outarg && string_add_to_idarray(outarg, columns,
+                                       ARRAY_SIZE(columns),
+                                       &ncolumns, cache_column_name_to_id) < 0)
+                       return EXIT_FAILURE;
+
                print_caches_readable(cxt, columns, ncolumns);
                break;
        case LSCPU_OUTPUT_READABLE:
@@ -1370,6 +1368,10 @@ int main(int argc, char *argv[])
                                columns[ncolumns++] = COL_CPU_MINMHZ;
                        }
                }
+               if (outarg && string_add_to_idarray(outarg, columns,
+                                       ARRAY_SIZE(columns),
+                                       &ncolumns, cpu_column_name_to_id) < 0)
+                       return EXIT_FAILURE;
                print_cpus_readable(cxt, columns, ncolumns);
                break;
        case LSCPU_OUTPUT_PARSABLE:
@@ -1384,6 +1386,11 @@ int main(int argc, char *argv[])
                        columns[ncolumns++] = COL_CPU_CACHE;
                        cxt->show_compatible = 1;
                }
+               if (outarg && string_add_to_idarray(outarg, columns,
+                                       ARRAY_SIZE(columns),
+                                       &ncolumns, cpu_column_name_to_id) < 0)
+                       return EXIT_FAILURE;
+
                print_cpus_parsable(cxt, columns, ncolumns);
                break;
        }