18c2ecf20Sopenharmony_ci// SPDX-License-Identifier: GPL-2.0
28c2ecf20Sopenharmony_ci#include "builtin.h"
38c2ecf20Sopenharmony_ci#include "perf.h"
48c2ecf20Sopenharmony_ci#include "color.h"
58c2ecf20Sopenharmony_ci#include <tools/config.h>
68c2ecf20Sopenharmony_ci#include <stdbool.h>
78c2ecf20Sopenharmony_ci#include <stdio.h>
88c2ecf20Sopenharmony_ci#include <string.h>
98c2ecf20Sopenharmony_ci#include <subcmd/parse-options.h>
108c2ecf20Sopenharmony_ci
118c2ecf20Sopenharmony_ciint version_verbose;
128c2ecf20Sopenharmony_ci
138c2ecf20Sopenharmony_cistruct version {
148c2ecf20Sopenharmony_ci	bool	build_options;
158c2ecf20Sopenharmony_ci};
168c2ecf20Sopenharmony_ci
178c2ecf20Sopenharmony_cistatic struct version version;
188c2ecf20Sopenharmony_ci
198c2ecf20Sopenharmony_cistatic struct option version_options[] = {
208c2ecf20Sopenharmony_ci	OPT_BOOLEAN(0, "build-options", &version.build_options,
218c2ecf20Sopenharmony_ci		    "display the build options"),
228c2ecf20Sopenharmony_ci	OPT_END(),
238c2ecf20Sopenharmony_ci};
248c2ecf20Sopenharmony_ci
258c2ecf20Sopenharmony_cistatic const char * const version_usage[] = {
268c2ecf20Sopenharmony_ci	"perf version [<options>]",
278c2ecf20Sopenharmony_ci	NULL
288c2ecf20Sopenharmony_ci};
298c2ecf20Sopenharmony_ci
308c2ecf20Sopenharmony_cistatic void on_off_print(const char *status)
318c2ecf20Sopenharmony_ci{
328c2ecf20Sopenharmony_ci	printf("[ ");
338c2ecf20Sopenharmony_ci
348c2ecf20Sopenharmony_ci	if (!strcmp(status, "OFF"))
358c2ecf20Sopenharmony_ci		color_fprintf(stdout, PERF_COLOR_RED, "%-3s", status);
368c2ecf20Sopenharmony_ci	else
378c2ecf20Sopenharmony_ci		color_fprintf(stdout, PERF_COLOR_GREEN, "%-3s", status);
388c2ecf20Sopenharmony_ci
398c2ecf20Sopenharmony_ci	printf(" ]");
408c2ecf20Sopenharmony_ci}
418c2ecf20Sopenharmony_ci
428c2ecf20Sopenharmony_cistatic void status_print(const char *name, const char *macro,
438c2ecf20Sopenharmony_ci			 const char *status)
448c2ecf20Sopenharmony_ci{
458c2ecf20Sopenharmony_ci	printf("%22s: ", name);
468c2ecf20Sopenharmony_ci	on_off_print(status);
478c2ecf20Sopenharmony_ci	printf("  # %s\n", macro);
488c2ecf20Sopenharmony_ci}
498c2ecf20Sopenharmony_ci
508c2ecf20Sopenharmony_ci#define STATUS(__d, __m)				\
518c2ecf20Sopenharmony_cido {							\
528c2ecf20Sopenharmony_ci	if (IS_BUILTIN(__d))				\
538c2ecf20Sopenharmony_ci		status_print(#__m, #__d, "on");		\
548c2ecf20Sopenharmony_ci	else						\
558c2ecf20Sopenharmony_ci		status_print(#__m, #__d, "OFF");	\
568c2ecf20Sopenharmony_ci} while (0)
578c2ecf20Sopenharmony_ci
588c2ecf20Sopenharmony_cistatic void library_status(void)
598c2ecf20Sopenharmony_ci{
608c2ecf20Sopenharmony_ci	STATUS(HAVE_DWARF_SUPPORT, dwarf);
618c2ecf20Sopenharmony_ci	STATUS(HAVE_DWARF_GETLOCATIONS_SUPPORT, dwarf_getlocations);
628c2ecf20Sopenharmony_ci	STATUS(HAVE_GLIBC_SUPPORT, glibc);
638c2ecf20Sopenharmony_ci#ifndef HAVE_SYSCALL_TABLE_SUPPORT
648c2ecf20Sopenharmony_ci	STATUS(HAVE_LIBAUDIT_SUPPORT, libaudit);
658c2ecf20Sopenharmony_ci#endif
668c2ecf20Sopenharmony_ci	STATUS(HAVE_SYSCALL_TABLE_SUPPORT, syscall_table);
678c2ecf20Sopenharmony_ci	STATUS(HAVE_LIBBFD_SUPPORT, libbfd);
688c2ecf20Sopenharmony_ci	STATUS(HAVE_LIBELF_SUPPORT, libelf);
698c2ecf20Sopenharmony_ci	STATUS(HAVE_LIBNUMA_SUPPORT, libnuma);
708c2ecf20Sopenharmony_ci	STATUS(HAVE_LIBNUMA_SUPPORT, numa_num_possible_cpus);
718c2ecf20Sopenharmony_ci	STATUS(HAVE_LIBPERL_SUPPORT, libperl);
728c2ecf20Sopenharmony_ci	STATUS(HAVE_LIBPYTHON_SUPPORT, libpython);
738c2ecf20Sopenharmony_ci	STATUS(HAVE_SLANG_SUPPORT, libslang);
748c2ecf20Sopenharmony_ci	STATUS(HAVE_LIBCRYPTO_SUPPORT, libcrypto);
758c2ecf20Sopenharmony_ci	STATUS(HAVE_LIBUNWIND_SUPPORT, libunwind);
768c2ecf20Sopenharmony_ci	STATUS(HAVE_DWARF_SUPPORT, libdw-dwarf-unwind);
778c2ecf20Sopenharmony_ci	STATUS(HAVE_ZLIB_SUPPORT, zlib);
788c2ecf20Sopenharmony_ci	STATUS(HAVE_LZMA_SUPPORT, lzma);
798c2ecf20Sopenharmony_ci	STATUS(HAVE_AUXTRACE_SUPPORT, get_cpuid);
808c2ecf20Sopenharmony_ci	STATUS(HAVE_LIBBPF_SUPPORT, bpf);
818c2ecf20Sopenharmony_ci	STATUS(HAVE_AIO_SUPPORT, aio);
828c2ecf20Sopenharmony_ci	STATUS(HAVE_ZSTD_SUPPORT, zstd);
838c2ecf20Sopenharmony_ci}
848c2ecf20Sopenharmony_ci
858c2ecf20Sopenharmony_ciint cmd_version(int argc, const char **argv)
868c2ecf20Sopenharmony_ci{
878c2ecf20Sopenharmony_ci	argc = parse_options(argc, argv, version_options, version_usage,
888c2ecf20Sopenharmony_ci			     PARSE_OPT_STOP_AT_NON_OPTION);
898c2ecf20Sopenharmony_ci
908c2ecf20Sopenharmony_ci	printf("perf version %s\n", perf_version_string);
918c2ecf20Sopenharmony_ci
928c2ecf20Sopenharmony_ci	if (version.build_options || version_verbose == 1)
938c2ecf20Sopenharmony_ci		library_status();
948c2ecf20Sopenharmony_ci
958c2ecf20Sopenharmony_ci	return 0;
968c2ecf20Sopenharmony_ci}
97