blob: f470144d1a7043ecf9fbcc3467d15c6df148b3d1 [file] [log] [blame]
Greg Kroah-Hartmanb2441312017-11-01 15:07:57 +01001// SPDX-License-Identifier: GPL-2.0
Josh Poimboeuf0a4bb5d2015-12-07 22:21:48 -06002#include "builtin.h"
3#include "perf.h"
Jin Yao9ff2a6472018-03-30 17:27:14 +08004#include "color.h"
Arnaldo Carvalho de Melo7a8ef4c2017-04-19 20:57:47 -03005#include <linux/compiler.h>
Jin Yao9ff2a6472018-03-30 17:27:14 +08006#include <tools/config.h>
Arnaldo Carvalho de Melo7a8ef4c2017-04-19 20:57:47 -03007#include <stdio.h>
Jin Yao9ff2a6472018-03-30 17:27:14 +08008#include <string.h>
9#include <subcmd/parse-options.h>
Josh Poimboeuf0a4bb5d2015-12-07 22:21:48 -060010
Jin Yao9ff2a6472018-03-30 17:27:14 +080011int version_verbose;
12
13struct version {
14 bool build_options;
15};
16
17static struct version version;
18
19static struct option version_options[] = {
20 OPT_BOOLEAN(0, "build-options", &version.build_options,
21 "display the build options"),
22};
23
24static const char * const version_usage[] = {
25 "perf version [<options>]",
26 NULL
27};
28
29static void on_off_print(const char *status)
Josh Poimboeuf0a4bb5d2015-12-07 22:21:48 -060030{
Jin Yao9ff2a6472018-03-30 17:27:14 +080031 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)
43{
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);
61 STATUS(HAVE_GLIBC_SUPPORT, glibc);
62 STATUS(HAVE_GTK2_SUPPORT, gtk2);
Jin Yao8a812bf2018-04-09 18:26:49 +080063#ifndef HAVE_SYSCALL_TABLE_SUPPORT
Jin Yao9ff2a6472018-03-30 17:27:14 +080064 STATUS(HAVE_LIBAUDIT_SUPPORT, libaudit);
Jin Yao8a812bf2018-04-09 18:26:49 +080065#endif
66 STATUS(HAVE_SYSCALL_TABLE_SUPPORT, syscall_table);
Jin Yao9ff2a6472018-03-30 17:27:14 +080067 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 Budankov3b1c5d92019-03-18 20:39:49 +030081 STATUS(HAVE_AIO_SUPPORT, aio);
82 STATUS(HAVE_ZSTD_SUPPORT, zstd);
Jin Yao9ff2a6472018-03-30 17:27:14 +080083}
84
85int cmd_version(int argc, const char **argv)
86{
87 argc = parse_options(argc, argv, version_options, version_usage,
88 PARSE_OPT_STOP_AT_NON_OPTION);
89
Josh Poimboeuf0a4bb5d2015-12-07 22:21:48 -060090 printf("perf version %s\n", perf_version_string);
Jin Yao9ff2a6472018-03-30 17:27:14 +080091
92 if (version.build_options || version_verbose == 1)
93 library_status();
94
Josh Poimboeuf0a4bb5d2015-12-07 22:21:48 -060095 return 0;
96}