Greg Kroah-Hartman | b244131 | 2017-11-01 15:07:57 +0100 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0 |
Josh Poimboeuf | 0a4bb5d | 2015-12-07 22:21:48 -0600 | [diff] [blame] | 2 | #include "builtin.h" |
| 3 | #include "perf.h" |
Jin Yao | 9ff2a647 | 2018-03-30 17:27:14 +0800 | [diff] [blame] | 4 | #include "color.h" |
Jin Yao | 9ff2a647 | 2018-03-30 17:27:14 +0800 | [diff] [blame] | 5 | #include <tools/config.h> |
Arnaldo Carvalho de Melo | d3300a3 | 2019-08-30 15:09:54 -0300 | [diff] [blame] | 6 | #include <stdbool.h> |
Arnaldo Carvalho de Melo | 7a8ef4c | 2017-04-19 20:57:47 -0300 | [diff] [blame] | 7 | #include <stdio.h> |
Jin Yao | 9ff2a647 | 2018-03-30 17:27:14 +0800 | [diff] [blame] | 8 | #include <string.h> |
| 9 | #include <subcmd/parse-options.h> |
Josh Poimboeuf | 0a4bb5d | 2015-12-07 22:21:48 -0600 | [diff] [blame] | 10 | |
Jin Yao | 9ff2a647 | 2018-03-30 17:27:14 +0800 | [diff] [blame] | 11 | int version_verbose; |
| 12 | |
| 13 | struct version { |
| 14 | bool build_options; |
| 15 | }; |
| 16 | |
| 17 | static struct version version; |
| 18 | |
| 19 | static struct option version_options[] = { |
| 20 | OPT_BOOLEAN(0, "build-options", &version.build_options, |
| 21 | "display the build options"), |
Ravi Bangoria | 916c31f | 2019-06-11 08:31:09 +0530 | [diff] [blame] | 22 | OPT_END(), |
Jin Yao | 9ff2a647 | 2018-03-30 17:27:14 +0800 | [diff] [blame] | 23 | }; |
| 24 | |
| 25 | static const char * const version_usage[] = { |
| 26 | "perf version [<options>]", |
| 27 | NULL |
| 28 | }; |
| 29 | |
| 30 | static void on_off_print(const char *status) |
Josh Poimboeuf | 0a4bb5d | 2015-12-07 22:21:48 -0600 | [diff] [blame] | 31 | { |
Jin Yao | 9ff2a647 | 2018-03-30 17:27:14 +0800 | [diff] [blame] | 32 | printf("[ "); |
| 33 | |
| 34 | if (!strcmp(status, "OFF")) |
| 35 | color_fprintf(stdout, PERF_COLOR_RED, "%-3s", status); |
| 36 | else |
| 37 | color_fprintf(stdout, PERF_COLOR_GREEN, "%-3s", status); |
| 38 | |
| 39 | printf(" ]"); |
| 40 | } |
| 41 | |
| 42 | static void status_print(const char *name, const char *macro, |
| 43 | const char *status) |
| 44 | { |
| 45 | printf("%22s: ", name); |
| 46 | on_off_print(status); |
| 47 | printf(" # %s\n", macro); |
| 48 | } |
| 49 | |
| 50 | #define STATUS(__d, __m) \ |
| 51 | do { \ |
| 52 | if (IS_BUILTIN(__d)) \ |
| 53 | status_print(#__m, #__d, "on"); \ |
| 54 | else \ |
| 55 | status_print(#__m, #__d, "OFF"); \ |
| 56 | } while (0) |
| 57 | |
| 58 | static void library_status(void) |
| 59 | { |
| 60 | STATUS(HAVE_DWARF_SUPPORT, dwarf); |
| 61 | STATUS(HAVE_DWARF_GETLOCATIONS_SUPPORT, dwarf_getlocations); |
| 62 | STATUS(HAVE_GLIBC_SUPPORT, glibc); |
Jin Yao | 8a812bf | 2018-04-09 18:26:49 +0800 | [diff] [blame] | 63 | #ifndef HAVE_SYSCALL_TABLE_SUPPORT |
Jin Yao | 9ff2a647 | 2018-03-30 17:27:14 +0800 | [diff] [blame] | 64 | STATUS(HAVE_LIBAUDIT_SUPPORT, libaudit); |
Jin Yao | 8a812bf | 2018-04-09 18:26:49 +0800 | [diff] [blame] | 65 | #endif |
| 66 | STATUS(HAVE_SYSCALL_TABLE_SUPPORT, syscall_table); |
Jin Yao | 9ff2a647 | 2018-03-30 17:27:14 +0800 | [diff] [blame] | 67 | STATUS(HAVE_LIBBFD_SUPPORT, libbfd); |
| 68 | STATUS(HAVE_LIBELF_SUPPORT, libelf); |
| 69 | STATUS(HAVE_LIBNUMA_SUPPORT, libnuma); |
| 70 | STATUS(HAVE_LIBNUMA_SUPPORT, numa_num_possible_cpus); |
| 71 | STATUS(HAVE_LIBPERL_SUPPORT, libperl); |
| 72 | STATUS(HAVE_LIBPYTHON_SUPPORT, libpython); |
| 73 | STATUS(HAVE_SLANG_SUPPORT, libslang); |
| 74 | STATUS(HAVE_LIBCRYPTO_SUPPORT, libcrypto); |
| 75 | STATUS(HAVE_LIBUNWIND_SUPPORT, libunwind); |
| 76 | STATUS(HAVE_DWARF_SUPPORT, libdw-dwarf-unwind); |
| 77 | STATUS(HAVE_ZLIB_SUPPORT, zlib); |
| 78 | STATUS(HAVE_LZMA_SUPPORT, lzma); |
| 79 | STATUS(HAVE_AUXTRACE_SUPPORT, get_cpuid); |
| 80 | STATUS(HAVE_LIBBPF_SUPPORT, bpf); |
Alexey Budankov | 3b1c5d9 | 2019-03-18 20:39:49 +0300 | [diff] [blame] | 81 | STATUS(HAVE_AIO_SUPPORT, aio); |
| 82 | STATUS(HAVE_ZSTD_SUPPORT, zstd); |
Ian Rogers | a7c77c4 | 2020-10-19 16:25:45 -0700 | [diff] [blame] | 83 | STATUS(HAVE_LIBPFM, libpfm4); |
Jin Yao | 9ff2a647 | 2018-03-30 17:27:14 +0800 | [diff] [blame] | 84 | } |
| 85 | |
| 86 | int cmd_version(int argc, const char **argv) |
| 87 | { |
| 88 | argc = parse_options(argc, argv, version_options, version_usage, |
| 89 | PARSE_OPT_STOP_AT_NON_OPTION); |
| 90 | |
Josh Poimboeuf | 0a4bb5d | 2015-12-07 22:21:48 -0600 | [diff] [blame] | 91 | printf("perf version %s\n", perf_version_string); |
Jin Yao | 9ff2a647 | 2018-03-30 17:27:14 +0800 | [diff] [blame] | 92 | |
| 93 | if (version.build_options || version_verbose == 1) |
| 94 | library_status(); |
| 95 | |
Josh Poimboeuf | 0a4bb5d | 2015-12-07 22:21:48 -0600 | [diff] [blame] | 96 | return 0; |
| 97 | } |