0001
0002 #include "builtin.h"
0003 #include "perf.h"
0004 #include "color.h"
0005 #include <tools/config.h>
0006 #include <stdbool.h>
0007 #include <stdio.h>
0008 #include <string.h>
0009 #include <subcmd/parse-options.h>
0010
0011 int version_verbose;
0012
0013 struct version {
0014 bool build_options;
0015 };
0016
0017 static struct version version;
0018
0019 static struct option version_options[] = {
0020 OPT_BOOLEAN(0, "build-options", &version.build_options,
0021 "display the build options"),
0022 OPT_END(),
0023 };
0024
0025 static const char * const version_usage[] = {
0026 "perf version [<options>]",
0027 NULL
0028 };
0029
0030 static void on_off_print(const char *status)
0031 {
0032 printf("[ ");
0033
0034 if (!strcmp(status, "OFF"))
0035 color_fprintf(stdout, PERF_COLOR_RED, "%-3s", status);
0036 else
0037 color_fprintf(stdout, PERF_COLOR_GREEN, "%-3s", status);
0038
0039 printf(" ]");
0040 }
0041
0042 static void status_print(const char *name, const char *macro,
0043 const char *status)
0044 {
0045 printf("%22s: ", name);
0046 on_off_print(status);
0047 printf(" # %s\n", macro);
0048 }
0049
0050 #define STATUS(__d, __m) \
0051 do { \
0052 if (IS_BUILTIN(__d)) \
0053 status_print(#__m, #__d, "on"); \
0054 else \
0055 status_print(#__m, #__d, "OFF"); \
0056 } while (0)
0057
0058 static void library_status(void)
0059 {
0060 STATUS(HAVE_DWARF_SUPPORT, dwarf);
0061 STATUS(HAVE_DWARF_GETLOCATIONS_SUPPORT, dwarf_getlocations);
0062 STATUS(HAVE_GLIBC_SUPPORT, glibc);
0063 #ifndef HAVE_SYSCALL_TABLE_SUPPORT
0064 STATUS(HAVE_LIBAUDIT_SUPPORT, libaudit);
0065 #endif
0066 STATUS(HAVE_SYSCALL_TABLE_SUPPORT, syscall_table);
0067 STATUS(HAVE_LIBBFD_SUPPORT, libbfd);
0068 STATUS(HAVE_DEBUGINFOD_SUPPORT, debuginfod);
0069 STATUS(HAVE_LIBELF_SUPPORT, libelf);
0070 STATUS(HAVE_LIBNUMA_SUPPORT, libnuma);
0071 STATUS(HAVE_LIBNUMA_SUPPORT, numa_num_possible_cpus);
0072 STATUS(HAVE_LIBPERL_SUPPORT, libperl);
0073 STATUS(HAVE_LIBPYTHON_SUPPORT, libpython);
0074 STATUS(HAVE_SLANG_SUPPORT, libslang);
0075 STATUS(HAVE_LIBCRYPTO_SUPPORT, libcrypto);
0076 STATUS(HAVE_LIBUNWIND_SUPPORT, libunwind);
0077 STATUS(HAVE_DWARF_SUPPORT, libdw-dwarf-unwind);
0078 STATUS(HAVE_ZLIB_SUPPORT, zlib);
0079 STATUS(HAVE_LZMA_SUPPORT, lzma);
0080 STATUS(HAVE_AUXTRACE_SUPPORT, get_cpuid);
0081 STATUS(HAVE_LIBBPF_SUPPORT, bpf);
0082 STATUS(HAVE_AIO_SUPPORT, aio);
0083 STATUS(HAVE_ZSTD_SUPPORT, zstd);
0084 STATUS(HAVE_LIBPFM, libpfm4);
0085 }
0086
0087 int cmd_version(int argc, const char **argv)
0088 {
0089 argc = parse_options(argc, argv, version_options, version_usage,
0090 PARSE_OPT_STOP_AT_NON_OPTION);
0091
0092 printf("perf version %s\n", perf_version_string);
0093
0094 if (version.build_options || version_verbose == 1)
0095 library_status();
0096
0097 return 0;
0098 }