From: Ian Rogers <irogers@google.com>
To: Peter Zijlstra <peterz@infradead.org>,
Ingo Molnar <mingo@redhat.com>,
Arnaldo Carvalho de Melo <acme@kernel.org>,
Namhyung Kim <namhyung@kernel.org>, Jiri Olsa <jolsa@kernel.org>,
Ian Rogers <irogers@google.com>,
Adrian Hunter <adrian.hunter@intel.com>,
James Clark <james.clark@linaro.org>,
Tianyou Li <tianyou.li@intel.com>,
Jiebin Sun <jiebin.sun@intel.com>,
Dapeng Mi <dapeng1.mi@linux.intel.com>,
Eric Biggers <ebiggers@kernel.org>,
Thomas Richter <tmricht@linux.ibm.com>,
Stephen Brennan <stephen.s.brennan@oracle.com>,
Swapnil Sapkal <swapnil.sapkal@amd.com>,
linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org
Subject: [PATCH v3 5/6] perf tool: Add fallback stubs for missing dependencies
Date: Wed, 2 Sep 2026 08:48:57 -0700 [thread overview]
Message-ID: <20260902154858.2078885-6-irogers@google.com> (raw)
In-Reply-To: <20260902154858.2078885-1-irogers@google.com>
Declare stubs directly inside perf.c for commands that have library
dependencies sometimes omitted at build time, such as libtraceevent
(timechart, sched, kmem, lock, trace, kwork) and libelf (probe).
By unconditionally including these commands in the commands[] array,
users will receive a clear, unified warning indicating the missing
dependency instead of the command silently being absent.
Running `perf trace` with libtraceevent missing. Before:
```
perf: 'trace' is not a perf-command. See 'perf --help'.
Did you mean this?
ftrace
```
After:
```
'trace' command not available: missing libtraceevent devel package at build time.
```
Signed-off-by: Ian Rogers <irogers@google.com>
Assisted-by: Antigravity:gemini-3.1-pro
---
tools/perf/perf.c | 51 ++++++++++++++++++++++++++++++-----------------
1 file changed, 33 insertions(+), 18 deletions(-)
diff --git a/tools/perf/perf.c b/tools/perf/perf.c
index 65bdfd71f626..6c5baa285b13 100644
--- a/tools/perf/perf.c
+++ b/tools/perf/perf.c
@@ -7,6 +7,7 @@
* perf top, perf record, perf report, etc.) are started.
*/
+#include <linux/compiler.h>
#include <errno.h>
#include <stdbool.h>
#include <stdio.h>
@@ -53,6 +54,38 @@ static void __noreturn usage(const char *err)
static int use_pager = -1;
static FILE *debug_fp = NULL;
+
+#ifndef HAVE_LIBTRACEEVENT
+#define DECLARE_LIBTRACEEVENT_STUB(_cmd) \
+ int cmd_##_cmd(int argc __always_unused, const char **argv __always_unused) \
+ { \
+ fprintf(stderr, \
+ "'" #_cmd "' command not available: missing libtraceevent " \
+ "devel package at build time.\n"); \
+ return -1; \
+ }
+
+DECLARE_LIBTRACEEVENT_STUB(timechart)
+DECLARE_LIBTRACEEVENT_STUB(sched)
+DECLARE_LIBTRACEEVENT_STUB(kmem)
+DECLARE_LIBTRACEEVENT_STUB(lock)
+DECLARE_LIBTRACEEVENT_STUB(trace)
+DECLARE_LIBTRACEEVENT_STUB(kwork)
+#endif
+
+#ifndef HAVE_LIBELF_SUPPORT
+#define DECLARE_LIBELF_SUPPORT_STUB(_cmd) \
+ int cmd_##_cmd(int argc __always_unused, const char **argv __always_unused) \
+ { \
+ fprintf(stderr, \
+ "'" #_cmd "' command not available: missing libelf " \
+ "devel package at build time.\n"); \
+ return -1; \
+ }
+
+DECLARE_LIBELF_SUPPORT_STUB(probe)
+#endif
+
struct cmd_struct {
const char *cmd;
int (*fn)(int, const char **);
@@ -76,36 +109,24 @@ static const struct cmd_struct commands[] = {
{ "report", cmd_report, 0 },
{ "bench", cmd_bench, 0 },
{ "stat", cmd_stat, 0 },
-#ifdef HAVE_LIBTRACEEVENT
{ "timechart", cmd_timechart, 0 },
-#endif
{ "top", cmd_top, 0 },
{ "annotate", cmd_annotate, 0 },
{ "version", cmd_version, 0 },
{ "script", cmd_script, 0 },
-#ifdef HAVE_LIBTRACEEVENT
{ "sched", cmd_sched, 0 },
-#endif
-#ifdef HAVE_LIBELF_SUPPORT
{ "probe", cmd_probe, 0 },
-#endif
-#ifdef HAVE_LIBTRACEEVENT
{ "kmem", cmd_kmem, 0 },
{ "lock", cmd_lock, 0 },
-#endif
{ "kvm", cmd_kvm, 0 },
{ "test", cmd_test, 0 },
-#if defined(HAVE_LIBTRACEEVENT)
{ "trace", cmd_trace, 0 },
-#endif
{ "inject", cmd_inject, 0 },
{ "mem", cmd_mem, 0 },
{ "data", cmd_data, 0 },
{ "ftrace", cmd_ftrace, 0 },
{ "daemon", cmd_daemon, 0 },
-#ifdef HAVE_LIBTRACEEVENT
{ "kwork", cmd_kwork, 0 },
-#endif
};
struct pager_config {
@@ -514,15 +535,9 @@ int main(int argc, const char **argv)
argv[0] = cmd;
}
if (strstarts(cmd, "trace")) {
-#ifndef HAVE_LIBTRACEEVENT
- fprintf(stderr,
- "trace command not available: missing libtraceevent devel package at build time.\n");
- goto out;
-#else
setup_path();
argv[0] = "trace";
return cmd_trace(argc, argv);
-#endif
}
/* Look for flags.. */
argv++;
--
2.55.0.966.g6673acef38-goog
next prev parent reply other threads:[~2026-09-02 15:49 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-09-02 15:48 [PATCH v3 0/6] perf tool: Build dependency tidy up Ian Rogers
2026-09-02 15:48 ` [PATCH v3 1/6] perf tool: Remove util/cache.h Ian Rogers
2026-09-02 15:57 ` sashiko-bot
2026-09-02 15:48 ` [PATCH v3 2/6] perf tool: Tidy up util/cache.h header file users Ian Rogers
2026-09-02 16:01 ` sashiko-bot
2026-09-02 15:48 ` [PATCH v3 3/6] perf tool: Remove unused includes in perf.c Ian Rogers
2026-09-02 15:57 ` sashiko-bot
2026-09-02 15:48 ` [PATCH v3 4/6] perf tool: Move usage strings and functions to perf.c Ian Rogers
2026-09-02 15:56 ` sashiko-bot
2026-09-02 15:48 ` Ian Rogers [this message]
2026-09-02 15:58 ` [PATCH v3 5/6] perf tool: Add fallback stubs for missing dependencies sashiko-bot
2026-09-02 16:03 ` Ian Rogers
2026-09-02 15:48 ` [PATCH v3 6/6] perf hist: Remove keysym.h include from hist.h Ian Rogers
2026-09-02 16:07 ` sashiko-bot
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260902154858.2078885-6-irogers@google.com \
--to=irogers@google.com \
--cc=acme@kernel.org \
--cc=adrian.hunter@intel.com \
--cc=dapeng1.mi@linux.intel.com \
--cc=ebiggers@kernel.org \
--cc=james.clark@linaro.org \
--cc=jiebin.sun@intel.com \
--cc=jolsa@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-perf-users@vger.kernel.org \
--cc=mingo@redhat.com \
--cc=namhyung@kernel.org \
--cc=peterz@infradead.org \
--cc=stephen.s.brennan@oracle.com \
--cc=swapnil.sapkal@amd.com \
--cc=tianyou.li@intel.com \
--cc=tmricht@linux.ibm.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox