Merge tag 'mm-nonmm-stable-2024-05-22-17-30' of git://git.kernel.org/pub/scm/linux...
[linux-2.6-block.git] / tools / perf / builtin-version.c
CommitLineData
b2441318 1// SPDX-License-Identifier: GPL-2.0
0a4bb5da 2#include "builtin.h"
9ff2a647 3#include "color.h"
2176f9e2 4#include "util/debug.h"
8641661c 5#include "util/header.h"
9ff2a647 6#include <tools/config.h>
d3300a3c 7#include <stdbool.h>
7a8ef4c4 8#include <stdio.h>
9ff2a647
JY
9#include <string.h>
10#include <subcmd/parse-options.h>
0a4bb5da 11
9ff2a647
JY
12struct version {
13 bool build_options;
14};
15
16static struct version version;
17
18static struct option version_options[] = {
19 OPT_BOOLEAN(0, "build-options", &version.build_options,
20 "display the build options"),
916c31ff 21 OPT_END(),
9ff2a647
JY
22};
23
24static const char * const version_usage[] = {
25 "perf version [<options>]",
26 NULL
27};
28
29static 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
41static void status_print(const char *name, const char *macro,
42 const char *status)
0a4bb5da 43{
9ff2a647
JY
44 printf("%22s: ", name);
45 on_off_print(status);
46 printf(" # %s\n", macro);
47}
48
49#define STATUS(__d, __m) \
50do { \
51 if (IS_BUILTIN(__d)) \
52 status_print(#__m, #__d, "on"); \
53 else \
54 status_print(#__m, #__d, "OFF"); \
55} while (0)
56
57static void library_status(void)
58{
59 STATUS(HAVE_DWARF_SUPPORT, dwarf);
60 STATUS(HAVE_DWARF_GETLOCATIONS_SUPPORT, dwarf_getlocations);
8a812bf5 61#ifndef HAVE_SYSCALL_TABLE_SUPPORT
9ff2a647 62 STATUS(HAVE_LIBAUDIT_SUPPORT, libaudit);
8a812bf5
JY
63#endif
64 STATUS(HAVE_SYSCALL_TABLE_SUPPORT, syscall_table);
9ff2a647 65 STATUS(HAVE_LIBBFD_SUPPORT, libbfd);
b8836c2a 66 STATUS(HAVE_DEBUGINFOD_SUPPORT, debuginfod);
9ff2a647
JY
67 STATUS(HAVE_LIBELF_SUPPORT, libelf);
68 STATUS(HAVE_LIBNUMA_SUPPORT, libnuma);
69 STATUS(HAVE_LIBNUMA_SUPPORT, numa_num_possible_cpus);
70 STATUS(HAVE_LIBPERL_SUPPORT, libperl);
71 STATUS(HAVE_LIBPYTHON_SUPPORT, libpython);
72 STATUS(HAVE_SLANG_SUPPORT, libslang);
73 STATUS(HAVE_LIBCRYPTO_SUPPORT, libcrypto);
74 STATUS(HAVE_LIBUNWIND_SUPPORT, libunwind);
75 STATUS(HAVE_DWARF_SUPPORT, libdw-dwarf-unwind);
8b767db3 76 STATUS(HAVE_LIBCAPSTONE_SUPPORT, libcapstone);
9ff2a647
JY
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);
3b1c5d96
AB
81 STATUS(HAVE_AIO_SUPPORT, aio);
82 STATUS(HAVE_ZSTD_SUPPORT, zstd);
a7c77c4f 83 STATUS(HAVE_LIBPFM, libpfm4);
378ef0f5 84 STATUS(HAVE_LIBTRACEEVENT, libtraceevent);
727e4314 85 STATUS(HAVE_BPF_SKEL, bpf_skeletons);
b58ab8ac 86 STATUS(HAVE_DWARF_UNWIND_SUPPORT, dwarf-unwind-support);
507ad2bd 87 STATUS(HAVE_CSTRACE_SUPPORT, libopencsd);
9ff2a647
JY
88}
89
90int cmd_version(int argc, const char **argv)
91{
92 argc = parse_options(argc, argv, version_options, version_usage,
93 PARSE_OPT_STOP_AT_NON_OPTION);
94
0a4bb5da 95 printf("perf version %s\n", perf_version_string);
9ff2a647 96
2176f9e2 97 if (version.build_options || verbose > 0)
9ff2a647
JY
98 library_status();
99
0a4bb5da
JP
100 return 0;
101}