]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
perf check: Share the feature status printing routine with 'perf version'
authorArnaldo Carvalho de Melo <acme@redhat.com>
Tue, 8 Apr 2025 13:37:01 +0000 (10:37 -0300)
committerArnaldo Carvalho de Melo <acme@redhat.com>
Thu, 10 Apr 2025 13:44:04 +0000 (10:44 -0300)
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>
tools/perf/builtin-check.c
tools/perf/builtin-version.c
tools/perf/builtin.h

index 61a11a9b4e7594bfc019e9e496b6cc919d584300..bed9df0d7912ec82ded07f01f4353737a9253d42 100644 (file)
@@ -66,22 +66,16 @@ static void on_off_print(const char *status)
 }
 
 /* Helper function to print status of a feature along with name/macro */
-static void status_print(const char *name, const char *macro,
-                        const char *status)
+void feature_status__printf(const struct feature_status *feature)
 {
+       const char *name = feature->name, *macro = feature->macro,
+                  *status = feature->is_builtin ? "on" : "OFF";
+
        printf("%22s: ", name);
        on_off_print(status);
        printf("  # %s\n", macro);
 }
 
-#define STATUS(feature)                                           \
-do {                                                              \
-       if (feature.is_builtin)                                   \
-               status_print(feature.name, feature.macro, "on");  \
-       else                                                      \
-               status_print(feature.name, feature.macro, "OFF"); \
-} while (0)
-
 /**
  * check whether "feature" is built-in with perf
  *
@@ -95,7 +89,7 @@ static int has_support(const char *feature)
                if ((strcasecmp(feature, supported_features[i].name) == 0) ||
                    (strcasecmp(feature, supported_features[i].macro) == 0)) {
                        if (!quiet)
-                               STATUS(supported_features[i]);
+                               feature_status__printf(&supported_features[i]);
                        return supported_features[i].is_builtin;
                }
        }
index e149d96c6dc57c2226a4aed8571a5a810c46e51c..10f25c6705b117a20c8a4b13bce5b0fbd2eef4aa 100644 (file)
@@ -26,38 +26,10 @@ static const char * const version_usage[] = {
        NULL
 };
 
-static void on_off_print(const char *status)
-{
-       printf("[ ");
-
-       if (!strcmp(status, "OFF"))
-               color_fprintf(stdout, PERF_COLOR_RED, "%-3s", status);
-       else
-               color_fprintf(stdout, PERF_COLOR_GREEN, "%-3s", status);
-
-       printf(" ]");
-}
-
-static void status_print(const char *name, const char *macro,
-                        const char *status)
-{
-       printf("%22s: ", name);
-       on_off_print(status);
-       printf("  # %s\n", macro);
-}
-
-#define STATUS(feature)                                   \
-do {                                                      \
-       if (feature.is_builtin)                               \
-               status_print(feature.name, feature.macro, "on");  \
-       else                                                  \
-               status_print(feature.name, feature.macro, "OFF"); \
-} while (0)
-
 static void library_status(void)
 {
        for (int i = 0; supported_features[i].name; ++i)
-               STATUS(supported_features[i]);
+               feature_status__printf(&supported_features[i]);
 }
 
 int cmd_version(int argc, const char **argv)
index a07e93c5384878d3d524d92c11eeb83ea7fcb7e4..b7e60d19fad9542717f7000eae79230191785242 100644 (file)
@@ -14,6 +14,9 @@ struct feature_status {
        .is_builtin = IS_BUILTIN(macro_) }
 
 extern struct feature_status supported_features[];
+
+void feature_status__printf(const struct feature_status *feature);
+
 struct cmdnames;
 
 void list_common_cmds_help(void);