linux/tools/perf/builtin-version.c
Arnaldo Carvalho de Melo 6994c6374a perf check: Share the feature status printing routine with 'perf version'
Both had the same open coded functions, share them so that we can add
tips for opt-in features such as libunwind, coresight, etc.

Examples of use:

  $ perf check feature libcapstone
             libcapstone: [ on  ]  # HAVE_LIBCAPSTONE_SUPPORT
  $ perf check feature libunwind
               libunwind: [ OFF ]  # HAVE_LIBUNWIND_SUPPORT
  $ perf version --build-options
  perf version 6.15.rc1.g113e3df8ccc5
                     aio: [ on  ]  # HAVE_AIO_SUPPORT
                     bpf: [ on  ]  # HAVE_LIBBPF_SUPPORT
           bpf_skeletons: [ on  ]  # HAVE_BPF_SKEL
              debuginfod: [ OFF ]  # HAVE_DEBUGINFOD_SUPPORT
                   dwarf: [ on  ]  # HAVE_LIBDW_SUPPORT
      dwarf_getlocations: [ on  ]  # HAVE_LIBDW_SUPPORT
            dwarf-unwind: [ on  ]  # HAVE_DWARF_UNWIND_SUPPORT
                auxtrace: [ on  ]  # HAVE_AUXTRACE_SUPPORT
                  libbfd: [ OFF ]  # HAVE_LIBBFD_SUPPORT
             libcapstone: [ on  ]  # HAVE_LIBCAPSTONE_SUPPORT
               libcrypto: [ on  ]  # HAVE_LIBCRYPTO_SUPPORT
      libdw-dwarf-unwind: [ on  ]  # HAVE_LIBDW_SUPPORT
                  libelf: [ on  ]  # HAVE_LIBELF_SUPPORT
                 libnuma: [ on  ]  # HAVE_LIBNUMA_SUPPORT
              libopencsd: [ on  ]  # HAVE_CSTRACE_SUPPORT
                 libperl: [ on  ]  # HAVE_LIBPERL_SUPPORT
                 libpfm4: [ on  ]  # HAVE_LIBPFM
               libpython: [ on  ]  # HAVE_LIBPYTHON_SUPPORT
                libslang: [ on  ]  # HAVE_SLANG_SUPPORT
           libtraceevent: [ on  ]  # HAVE_LIBTRACEEVENT
               libunwind: [ OFF ]  # HAVE_LIBUNWIND_SUPPORT
                    lzma: [ on  ]  # HAVE_LZMA_SUPPORT
  numa_num_possible_cpus: [ on  ]  # HAVE_LIBNUMA_SUPPORT
                    zlib: [ on  ]  # HAVE_ZLIB_SUPPORT
                    zstd: [ on  ]  # HAVE_ZSTD_SUPPORT
  $

Tested-by: Ingo Molnar <mingo@kernel.org>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Dmitriy Vyukov <dvyukov@google.com>
Cc: Howard Chu <howardchu95@gmail.com>
Cc: Ian Rogers <irogers@google.com>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Kan Liang <kan.liang@linux.intel.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Link: https://lore.kernel.org/r/Z_Rz10stoLzBocIO@x1
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2025-04-10 10:44:04 -03:00

46 lines
977 B
C

// SPDX-License-Identifier: GPL-2.0
#include "builtin.h"
#include "color.h"
#include "util/debug.h"
#include "util/header.h"
#include <tools/config.h>
#include <stdbool.h>
#include <stdio.h>
#include <string.h>
#include <subcmd/parse-options.h>
struct version {
bool build_options;
};
static struct version version;
static struct option version_options[] = {
OPT_BOOLEAN(0, "build-options", &version.build_options,
"display the build options"),
OPT_END(),
};
static const char * const version_usage[] = {
"perf version [<options>]",
NULL
};
static void library_status(void)
{
for (int i = 0; supported_features[i].name; ++i)
feature_status__printf(&supported_features[i]);
}
int cmd_version(int argc, const char **argv)
{
argc = parse_options(argc, argv, version_options, version_usage,
PARSE_OPT_STOP_AT_NON_OPTION);
printf("perf version %s\n", perf_version_string);
if (version.build_options || verbose > 0)
library_status();
return 0;
}