Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

perf check: Share the feature status printing routine with 'perf version'

Both had the same open coded functions, share them so that we can add
tips for opt-in features such as libunwind, coresight, etc.

Examples of use:

$ perf check feature libcapstone
libcapstone: [ on ] # HAVE_LIBCAPSTONE_SUPPORT
$ perf check feature libunwind
libunwind: [ OFF ] # HAVE_LIBUNWIND_SUPPORT
$ perf version --build-options
perf version 6.15.rc1.g113e3df8ccc5
aio: [ on ] # HAVE_AIO_SUPPORT
bpf: [ on ] # HAVE_LIBBPF_SUPPORT
bpf_skeletons: [ on ] # HAVE_BPF_SKEL
debuginfod: [ OFF ] # HAVE_DEBUGINFOD_SUPPORT
dwarf: [ on ] # HAVE_LIBDW_SUPPORT
dwarf_getlocations: [ on ] # HAVE_LIBDW_SUPPORT
dwarf-unwind: [ on ] # HAVE_DWARF_UNWIND_SUPPORT
auxtrace: [ on ] # HAVE_AUXTRACE_SUPPORT
libbfd: [ OFF ] # HAVE_LIBBFD_SUPPORT
libcapstone: [ on ] # HAVE_LIBCAPSTONE_SUPPORT
libcrypto: [ on ] # HAVE_LIBCRYPTO_SUPPORT
libdw-dwarf-unwind: [ on ] # HAVE_LIBDW_SUPPORT
libelf: [ on ] # HAVE_LIBELF_SUPPORT
libnuma: [ on ] # HAVE_LIBNUMA_SUPPORT
libopencsd: [ on ] # HAVE_CSTRACE_SUPPORT
libperl: [ on ] # HAVE_LIBPERL_SUPPORT
libpfm4: [ on ] # HAVE_LIBPFM
libpython: [ on ] # HAVE_LIBPYTHON_SUPPORT
libslang: [ on ] # HAVE_SLANG_SUPPORT
libtraceevent: [ on ] # HAVE_LIBTRACEEVENT
libunwind: [ OFF ] # HAVE_LIBUNWIND_SUPPORT
lzma: [ on ] # HAVE_LZMA_SUPPORT
numa_num_possible_cpus: [ on ] # HAVE_LIBNUMA_SUPPORT
zlib: [ on ] # HAVE_ZLIB_SUPPORT
zstd: [ on ] # HAVE_ZSTD_SUPPORT
$

Tested-by: Ingo Molnar <mingo@kernel.org>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Dmitriy Vyukov <dvyukov@google.com>
Cc: Howard Chu <howardchu95@gmail.com>
Cc: Ian Rogers <irogers@google.com>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Kan Liang <kan.liang@linux.intel.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Link: https://lore.kernel.org/r/Z_Rz10stoLzBocIO@x1
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>

+9 -40
+5 -11
tools/perf/builtin-check.c
··· 66 66 } 67 67 68 68 /* Helper function to print status of a feature along with name/macro */ 69 - static void status_print(const char *name, const char *macro, 70 - const char *status) 69 + void feature_status__printf(const struct feature_status *feature) 71 70 { 71 + const char *name = feature->name, *macro = feature->macro, 72 + *status = feature->is_builtin ? "on" : "OFF"; 73 + 72 74 printf("%22s: ", name); 73 75 on_off_print(status); 74 76 printf(" # %s\n", macro); 75 77 } 76 - 77 - #define STATUS(feature) \ 78 - do { \ 79 - if (feature.is_builtin) \ 80 - status_print(feature.name, feature.macro, "on"); \ 81 - else \ 82 - status_print(feature.name, feature.macro, "OFF"); \ 83 - } while (0) 84 78 85 79 /** 86 80 * check whether "feature" is built-in with perf ··· 89 95 if ((strcasecmp(feature, supported_features[i].name) == 0) || 90 96 (strcasecmp(feature, supported_features[i].macro) == 0)) { 91 97 if (!quiet) 92 - STATUS(supported_features[i]); 98 + feature_status__printf(&supported_features[i]); 93 99 return supported_features[i].is_builtin; 94 100 } 95 101 }
+1 -29
tools/perf/builtin-version.c
··· 26 26 NULL 27 27 }; 28 28 29 - static void on_off_print(const char *status) 30 - { 31 - printf("[ "); 32 - 33 - if (!strcmp(status, "OFF")) 34 - color_fprintf(stdout, PERF_COLOR_RED, "%-3s", status); 35 - else 36 - color_fprintf(stdout, PERF_COLOR_GREEN, "%-3s", status); 37 - 38 - printf(" ]"); 39 - } 40 - 41 - static void status_print(const char *name, const char *macro, 42 - const char *status) 43 - { 44 - printf("%22s: ", name); 45 - on_off_print(status); 46 - printf(" # %s\n", macro); 47 - } 48 - 49 - #define STATUS(feature) \ 50 - do { \ 51 - if (feature.is_builtin) \ 52 - status_print(feature.name, feature.macro, "on"); \ 53 - else \ 54 - status_print(feature.name, feature.macro, "OFF"); \ 55 - } while (0) 56 - 57 29 static void library_status(void) 58 30 { 59 31 for (int i = 0; supported_features[i].name; ++i) 60 - STATUS(supported_features[i]); 32 + feature_status__printf(&supported_features[i]); 61 33 } 62 34 63 35 int cmd_version(int argc, const char **argv)
+3
tools/perf/builtin.h
··· 14 14 .is_builtin = IS_BUILTIN(macro_) } 15 15 16 16 extern struct feature_status supported_features[]; 17 + 18 + void feature_status__printf(const struct feature_status *feature); 19 + 17 20 struct cmdnames; 18 21 19 22 void list_common_cmds_help(void);