1 // SPDX-License-Identifier: GPL-2.0 1 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[] 13 static struct option check_options[] = { 14 OPT_BOOLEAN('q', "quiet", &quiet, "do 15 OPT_END() 16 }; 17 static struct option check_feature_options[] = 18 19 static const char *check_usage[] = { NULL, NUL 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_SUPP 28 FEATURE_STATUS("bpf_skeletons", HAVE_B 29 FEATURE_STATUS("debuginfod", HAVE_DEBU 30 FEATURE_STATUS("dwarf", HAVE_DWARF_SUP 31 FEATURE_STATUS("dwarf_getlocations", H 32 FEATURE_STATUS("dwarf-unwind", HAVE_DW 33 FEATURE_STATUS("auxtrace", HAVE_AUXTRA 34 FEATURE_STATUS("libaudit", HAVE_LIBAUD 35 FEATURE_STATUS("libbfd", HAVE_LIBBFD_S 36 FEATURE_STATUS("libcapstone", HAVE_LIB 37 FEATURE_STATUS("libcrypto", HAVE_LIBCR 38 FEATURE_STATUS("libdw-dwarf-unwind", H 39 FEATURE_STATUS("libelf", HAVE_LIBELF_S 40 FEATURE_STATUS("libnuma", HAVE_LIBNUMA 41 FEATURE_STATUS("libopencsd", HAVE_CSTR 42 FEATURE_STATUS("libperl", HAVE_LIBPERL 43 FEATURE_STATUS("libpfm4", HAVE_LIBPFM) 44 FEATURE_STATUS("libpython", HAVE_LIBPY 45 FEATURE_STATUS("libslang", HAVE_SLANG_ 46 FEATURE_STATUS("libtraceevent", HAVE_L 47 FEATURE_STATUS("libunwind", HAVE_LIBUN 48 FEATURE_STATUS("lzma", HAVE_LZMA_SUPPO 49 FEATURE_STATUS("numa_num_possible_cpus 50 FEATURE_STATUS("syscall_table", HAVE_S 51 FEATURE_STATUS("zlib", HAVE_ZLIB_SUPPO 52 FEATURE_STATUS("zstd", HAVE_ZSTD_SUPPO 53 54 /* this should remain at end, to know 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_COL 64 else 65 color_fprintf(stdout, PERF_COL 66 67 printf(" ]"); 68 } 69 70 /* Helper function to print status of a featur 71 static void status_print(const char *name, con 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, fea 83 else 84 status_print(feature.name, fea 85 } while (0) 86 87 /** 88 * check whether "feature" is built-in with pe 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]. 97 if ((strcasecmp(feature, suppo 98 (strcasecmp(feature, suppo 99 if (!quiet) 100 STATUS(support 101 return supported_featu 102 } 103 } 104 105 if (!quiet) 106 pr_err("Unknown feature '%s', 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 116 * of feature names/macros 117 * eg. argument can be "libtraceevent" or "lib 118 * 119 * In case of a comma-separated list, feature_ 120 * all features passed in the string are suppo 121 * 122 * Note that argv will get modified 123 */ 124 static int subcommand_feature(int argc, const 125 { 126 char *feature_list; 127 char *feature_name; 128 int feature_enabled; 129 130 argc = parse_options(argc, argv, check 131 check_feature_usage, 0 132 133 if (!argc) 134 usage_with_options(check_featu 135 136 if (argc > 1) { 137 pr_err("Too many arguments pas 138 return -1; 139 } 140 141 feature_enabled = 1; 142 /* feature_list is a non-const copy of 143 feature_list = strdup(argv[0]); 144 if (!feature_list) { 145 pr_err("ERROR: failed to alloc 146 return -1; 147 } 148 149 feature_name = strtok(feature_list, ", 150 151 while (feature_name) { 152 feature_enabled &= has_support 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, 164 check_subcommands, che 165 166 if (!argc) 167 usage_with_options(check_usage 168 169 if (strcmp(argv[0], "feature") == 0) 170 return subcommand_feature(argc 171 172 /* If no subcommand matched above, pri 173 pr_err("Unknown subcommand: %s\n", arg 174 usage_with_options(check_usage, check_ 175 176 /* free usage string allocated by pars 177 free((void *)check_usage[0]); 178 179 return 0; 180 } 181
Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.