~ [ 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 ] ~

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