~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

TOMOYO Linux Cross Reference
Linux/tools/perf/builtin-check.c

Version: ~ [ linux-6.12-rc7 ] ~ [ linux-6.11.7 ] ~ [ linux-6.10.14 ] ~ [ linux-6.9.12 ] ~ [ linux-6.8.12 ] ~ [ linux-6.7.12 ] ~ [ linux-6.6.60 ] ~ [ linux-6.5.13 ] ~ [ linux-6.4.16 ] ~ [ linux-6.3.13 ] ~ [ linux-6.2.16 ] ~ [ linux-6.1.116 ] ~ [ linux-6.0.19 ] ~ [ linux-5.19.17 ] ~ [ linux-5.18.19 ] ~ [ linux-5.17.15 ] ~ [ linux-5.16.20 ] ~ [ linux-5.15.171 ] ~ [ linux-5.14.21 ] ~ [ linux-5.13.19 ] ~ [ linux-5.12.19 ] ~ [ linux-5.11.22 ] ~ [ linux-5.10.229 ] ~ [ linux-5.9.16 ] ~ [ linux-5.8.18 ] ~ [ linux-5.7.19 ] ~ [ linux-5.6.19 ] ~ [ linux-5.5.19 ] ~ [ linux-5.4.285 ] ~ [ linux-5.3.18 ] ~ [ linux-5.2.21 ] ~ [ linux-5.1.21 ] ~ [ linux-5.0.21 ] ~ [ linux-4.20.17 ] ~ [ linux-4.19.323 ] ~ [ linux-4.18.20 ] ~ [ linux-4.17.19 ] ~ [ linux-4.16.18 ] ~ [ linux-4.15.18 ] ~ [ linux-4.14.336 ] ~ [ linux-4.13.16 ] ~ [ linux-4.12.14 ] ~ [ linux-4.11.12 ] ~ [ linux-4.10.17 ] ~ [ linux-4.9.337 ] ~ [ linux-4.4.302 ] ~ [ linux-3.10.108 ] ~ [ linux-2.6.32.71 ] ~ [ linux-2.6.0 ] ~ [ linux-2.4.37.11 ] ~ [ unix-v6-master ] ~ [ ccs-tools-1.8.12 ] ~ [ policy-sample ] ~
Architecture: ~ [ i386 ] ~ [ alpha ] ~ [ m68k ] ~ [ mips ] ~ [ ppc ] ~ [ sparc ] ~ [ sparc64 ] ~

Diff markup

Differences between /tools/perf/builtin-check.c (Architecture mips) and /tools/perf/builtin-check.c (Architecture sparc)


  1 // SPDX-License-Identifier: GPL-2.0                 1 // SPDX-License-Identifier: GPL-2.0
  2 #include "builtin.h"                                2 #include "builtin.h"
  3 #include "color.h"                                  3 #include "color.h"
  4 #include "util/debug.h"                             4 #include "util/debug.h"
  5 #include "util/header.h"                            5 #include "util/header.h"
  6 #include <tools/config.h>                           6 #include <tools/config.h>
  7 #include <stdbool.h>                                7 #include <stdbool.h>
  8 #include <stdio.h>                                  8 #include <stdio.h>
  9 #include <string.h>                                 9 #include <string.h>
 10 #include <subcmd/parse-options.h>                  10 #include <subcmd/parse-options.h>
 11                                                    11 
 12 static const char * const check_subcommands[]      12 static const char * const check_subcommands[] = { "feature", NULL };
 13 static struct option check_options[] = {           13 static struct option check_options[] = {
 14         OPT_BOOLEAN('q', "quiet", &quiet, "do      14         OPT_BOOLEAN('q', "quiet", &quiet, "do not show any warnings or messages"),
 15         OPT_END()                                  15         OPT_END()
 16 };                                                 16 };
 17 static struct option check_feature_options[] =     17 static struct option check_feature_options[] = { OPT_PARENT(check_options) };
 18                                                    18 
 19 static const char *check_usage[] = { NULL, NUL     19 static const char *check_usage[] = { NULL, NULL };
 20 static const char *check_feature_usage[] = {       20 static const char *check_feature_usage[] = {
 21         "perf check feature <feature_list>",       21         "perf check feature <feature_list>",
 22         NULL                                       22         NULL
 23 };                                                 23 };
 24                                                    24 
 25 struct feature_status supported_features[] = {     25 struct feature_status supported_features[] = {
 26         FEATURE_STATUS("aio", HAVE_AIO_SUPPORT     26         FEATURE_STATUS("aio", HAVE_AIO_SUPPORT),
 27         FEATURE_STATUS("bpf", HAVE_LIBBPF_SUPP     27         FEATURE_STATUS("bpf", HAVE_LIBBPF_SUPPORT),
 28         FEATURE_STATUS("bpf_skeletons", HAVE_B     28         FEATURE_STATUS("bpf_skeletons", HAVE_BPF_SKEL),
 29         FEATURE_STATUS("debuginfod", HAVE_DEBU     29         FEATURE_STATUS("debuginfod", HAVE_DEBUGINFOD_SUPPORT),
 30         FEATURE_STATUS("dwarf", HAVE_DWARF_SUP     30         FEATURE_STATUS("dwarf", HAVE_DWARF_SUPPORT),
 31         FEATURE_STATUS("dwarf_getlocations", H     31         FEATURE_STATUS("dwarf_getlocations", HAVE_DWARF_GETLOCATIONS_SUPPORT),
 32         FEATURE_STATUS("dwarf-unwind", HAVE_DW     32         FEATURE_STATUS("dwarf-unwind", HAVE_DWARF_UNWIND_SUPPORT),
 33         FEATURE_STATUS("auxtrace", HAVE_AUXTRA     33         FEATURE_STATUS("auxtrace", HAVE_AUXTRACE_SUPPORT),
 34         FEATURE_STATUS("libaudit", HAVE_LIBAUD     34         FEATURE_STATUS("libaudit", HAVE_LIBAUDIT_SUPPORT),
 35         FEATURE_STATUS("libbfd", HAVE_LIBBFD_S     35         FEATURE_STATUS("libbfd", HAVE_LIBBFD_SUPPORT),
 36         FEATURE_STATUS("libcapstone", HAVE_LIB     36         FEATURE_STATUS("libcapstone", HAVE_LIBCAPSTONE_SUPPORT),
 37         FEATURE_STATUS("libcrypto", HAVE_LIBCR     37         FEATURE_STATUS("libcrypto", HAVE_LIBCRYPTO_SUPPORT),
 38         FEATURE_STATUS("libdw-dwarf-unwind", H     38         FEATURE_STATUS("libdw-dwarf-unwind", HAVE_DWARF_SUPPORT),
 39         FEATURE_STATUS("libelf", HAVE_LIBELF_S     39         FEATURE_STATUS("libelf", HAVE_LIBELF_SUPPORT),
 40         FEATURE_STATUS("libnuma", HAVE_LIBNUMA     40         FEATURE_STATUS("libnuma", HAVE_LIBNUMA_SUPPORT),
 41         FEATURE_STATUS("libopencsd", HAVE_CSTR     41         FEATURE_STATUS("libopencsd", HAVE_CSTRACE_SUPPORT),
 42         FEATURE_STATUS("libperl", HAVE_LIBPERL     42         FEATURE_STATUS("libperl", HAVE_LIBPERL_SUPPORT),
 43         FEATURE_STATUS("libpfm4", HAVE_LIBPFM)     43         FEATURE_STATUS("libpfm4", HAVE_LIBPFM),
 44         FEATURE_STATUS("libpython", HAVE_LIBPY     44         FEATURE_STATUS("libpython", HAVE_LIBPYTHON_SUPPORT),
 45         FEATURE_STATUS("libslang", HAVE_SLANG_     45         FEATURE_STATUS("libslang", HAVE_SLANG_SUPPORT),
 46         FEATURE_STATUS("libtraceevent", HAVE_L     46         FEATURE_STATUS("libtraceevent", HAVE_LIBTRACEEVENT),
 47         FEATURE_STATUS("libunwind", HAVE_LIBUN     47         FEATURE_STATUS("libunwind", HAVE_LIBUNWIND_SUPPORT),
 48         FEATURE_STATUS("lzma", HAVE_LZMA_SUPPO     48         FEATURE_STATUS("lzma", HAVE_LZMA_SUPPORT),
 49         FEATURE_STATUS("numa_num_possible_cpus     49         FEATURE_STATUS("numa_num_possible_cpus", HAVE_LIBNUMA_SUPPORT),
 50         FEATURE_STATUS("syscall_table", HAVE_S     50         FEATURE_STATUS("syscall_table", HAVE_SYSCALL_TABLE_SUPPORT),
 51         FEATURE_STATUS("zlib", HAVE_ZLIB_SUPPO     51         FEATURE_STATUS("zlib", HAVE_ZLIB_SUPPORT),
 52         FEATURE_STATUS("zstd", HAVE_ZSTD_SUPPO     52         FEATURE_STATUS("zstd", HAVE_ZSTD_SUPPORT),
 53                                                    53 
 54         /* this should remain at end, to know      54         /* this should remain at end, to know the array end */
 55         FEATURE_STATUS(NULL, _)                    55         FEATURE_STATUS(NULL, _)
 56 };                                                 56 };
 57                                                    57 
 58 static void on_off_print(const char *status)       58 static void on_off_print(const char *status)
 59 {                                                  59 {
 60         printf("[ ");                              60         printf("[ ");
 61                                                    61 
 62         if (!strcmp(status, "OFF"))                62         if (!strcmp(status, "OFF"))
 63                 color_fprintf(stdout, PERF_COL     63                 color_fprintf(stdout, PERF_COLOR_RED, "%-3s", status);
 64         else                                       64         else
 65                 color_fprintf(stdout, PERF_COL     65                 color_fprintf(stdout, PERF_COLOR_GREEN, "%-3s", status);
 66                                                    66 
 67         printf(" ]");                              67         printf(" ]");
 68 }                                                  68 }
 69                                                    69 
 70 /* Helper function to print status of a featur     70 /* Helper function to print status of a feature along with name/macro */
 71 static void status_print(const char *name, con     71 static void status_print(const char *name, const char *macro,
 72                          const char *status)       72                          const char *status)
 73 {                                                  73 {
 74         printf("%22s: ", name);                    74         printf("%22s: ", name);
 75         on_off_print(status);                      75         on_off_print(status);
 76         printf("  # %s\n", macro);                 76         printf("  # %s\n", macro);
 77 }                                                  77 }
 78                                                    78 
 79 #define STATUS(feature)                            79 #define STATUS(feature)                                           \
 80 do {                                               80 do {                                                              \
 81         if (feature.is_builtin)                    81         if (feature.is_builtin)                                   \
 82                 status_print(feature.name, fea     82                 status_print(feature.name, feature.macro, "on");  \
 83         else                                       83         else                                                      \
 84                 status_print(feature.name, fea     84                 status_print(feature.name, feature.macro, "OFF"); \
 85 } while (0)                                        85 } while (0)
 86                                                    86 
 87 /**                                                87 /**
 88  * check whether "feature" is built-in with pe     88  * check whether "feature" is built-in with perf
 89  *                                                 89  *
 90  * returns:                                        90  * returns:
 91  *    0: NOT built-in or Feature not known         91  *    0: NOT built-in or Feature not known
 92  *    1: Built-in                                  92  *    1: Built-in
 93  */                                                93  */
 94 static int has_support(const char *feature)        94 static int has_support(const char *feature)
 95 {                                                  95 {
 96         for (int i = 0; supported_features[i].     96         for (int i = 0; supported_features[i].name; ++i) {
 97                 if ((strcasecmp(feature, suppo     97                 if ((strcasecmp(feature, supported_features[i].name) == 0) ||
 98                     (strcasecmp(feature, suppo     98                     (strcasecmp(feature, supported_features[i].macro) == 0)) {
 99                         if (!quiet)                99                         if (!quiet)
100                                 STATUS(support    100                                 STATUS(supported_features[i]);
101                         return supported_featu    101                         return supported_features[i].is_builtin;
102                 }                                 102                 }
103         }                                         103         }
104                                                   104 
105         if (!quiet)                               105         if (!quiet)
106                 pr_err("Unknown feature '%s',     106                 pr_err("Unknown feature '%s', please use 'perf version --build-options' to see which ones are available.\n", feature);
107                                                   107 
108         return 0;                                 108         return 0;
109 }                                                 109 }
110                                                   110 
111                                                   111 
112 /**                                               112 /**
113  * Usage: 'perf check feature <feature_list>'     113  * Usage: 'perf check feature <feature_list>'
114  *                                                114  *
115  * <feature_list> can be a single feature name    115  * <feature_list> can be a single feature name/macro, or a comma-separated list
116  * of feature names/macros                        116  * of feature names/macros
117  * eg. argument can be "libtraceevent" or "lib    117  * eg. argument can be "libtraceevent" or "libtraceevent,bpf" etc
118  *                                                118  *
119  * In case of a comma-separated list, feature_    119  * In case of a comma-separated list, feature_enabled will be 1, only if
120  * all features passed in the string are suppo    120  * all features passed in the string are supported
121  *                                                121  *
122  * Note that argv will get modified               122  * Note that argv will get modified
123  */                                               123  */
124 static int subcommand_feature(int argc, const     124 static int subcommand_feature(int argc, const char **argv)
125 {                                                 125 {
126         char *feature_list;                       126         char *feature_list;
127         char *feature_name;                       127         char *feature_name;
128         int feature_enabled;                      128         int feature_enabled;
129                                                   129 
130         argc = parse_options(argc, argv, check    130         argc = parse_options(argc, argv, check_feature_options,
131                         check_feature_usage, 0    131                         check_feature_usage, 0);
132                                                   132 
133         if (!argc)                                133         if (!argc)
134                 usage_with_options(check_featu    134                 usage_with_options(check_feature_usage, check_feature_options);
135                                                   135 
136         if (argc > 1) {                           136         if (argc > 1) {
137                 pr_err("Too many arguments pas    137                 pr_err("Too many arguments passed to 'perf check feature'\n");
138                 return -1;                        138                 return -1;
139         }                                         139         }
140                                                   140 
141         feature_enabled = 1;                      141         feature_enabled = 1;
142         /* feature_list is a non-const copy of    142         /* feature_list is a non-const copy of 'argv[0]' */
143         feature_list = strdup(argv[0]);           143         feature_list = strdup(argv[0]);
144         if (!feature_list) {                      144         if (!feature_list) {
145                 pr_err("ERROR: failed to alloc    145                 pr_err("ERROR: failed to allocate memory for feature list\n");
146                 return -1;                        146                 return -1;
147         }                                         147         }
148                                                   148 
149         feature_name = strtok(feature_list, ",    149         feature_name = strtok(feature_list, ",");
150                                                   150 
151         while (feature_name) {                    151         while (feature_name) {
152                 feature_enabled &= has_support    152                 feature_enabled &= has_support(feature_name);
153                 feature_name = strtok(NULL, ",    153                 feature_name = strtok(NULL, ",");
154         }                                         154         }
155                                                   155 
156         free(feature_list);                       156         free(feature_list);
157                                                   157 
158         return !feature_enabled;                  158         return !feature_enabled;
159 }                                                 159 }
160                                                   160 
161 int cmd_check(int argc, const char **argv)        161 int cmd_check(int argc, const char **argv)
162 {                                                 162 {
163         argc = parse_options_subcommand(argc,     163         argc = parse_options_subcommand(argc, argv, check_options,
164                         check_subcommands, che    164                         check_subcommands, check_usage, 0);
165                                                   165 
166         if (!argc)                                166         if (!argc)
167                 usage_with_options(check_usage    167                 usage_with_options(check_usage, check_options);
168                                                   168 
169         if (strcmp(argv[0], "feature") == 0)      169         if (strcmp(argv[0], "feature") == 0)
170                 return subcommand_feature(argc    170                 return subcommand_feature(argc, argv);
171                                                   171 
172         /* If no subcommand matched above, pri    172         /* If no subcommand matched above, print usage help */
173         pr_err("Unknown subcommand: %s\n", arg    173         pr_err("Unknown subcommand: %s\n", argv[0]);
174         usage_with_options(check_usage, check_    174         usage_with_options(check_usage, check_options);
175                                                   175 
176         /* free usage string allocated by pars    176         /* free usage string allocated by parse_options_subcommand */
177         free((void *)check_usage[0]);             177         free((void *)check_usage[0]);
178                                                   178 
179         return 0;                                 179         return 0;
180 }                                                 180 }
181                                                   181 

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

kernel.org | git.kernel.org | LWN.net | Project Home | SVN repository | Mail admin

Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.

sflogo.php