Linux Perf Users
 help / color / mirror / Atom feed
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 4/6] perf tool: Move usage strings and functions to perf.c
Date: Wed,  2 Sep 2026 08:48:56 -0700	[thread overview]
Message-ID: <20260902154858.2078885-5-irogers@google.com> (raw)
In-Reply-To: <20260902154858.2078885-1-irogers@google.com>

The code is mostly used by perf.c with additional unused functionality
such as function pointers derived from early git code. Moving it into
perf.c directly reduces the code footprint, drops the util/util.h
dependence from perf.c, and allows us to remove util/usage.c entirely.

The string constants are exposed in builtin.h, as they are used
in builtin-help.c.

Signed-off-by: Ian Rogers <irogers@google.com>
Assisted-by: Antigravity:gemini-3.1-pro
---
 tools/perf/builtin.h    |  3 +++
 tools/perf/perf.c       | 13 ++++++++++++-
 tools/perf/util/Build   |  1 -
 tools/perf/util/usage.c | 34 ----------------------------------
 tools/perf/util/util.h  |  4 ----
 5 files changed, 15 insertions(+), 40 deletions(-)
 delete mode 100644 tools/perf/util/usage.c

diff --git a/tools/perf/builtin.h b/tools/perf/builtin.h
index 40c4078c295f..e0b430821abc 100644
--- a/tools/perf/builtin.h
+++ b/tools/perf/builtin.h
@@ -2,6 +2,9 @@
 #ifndef BUILTIN_H
 #define BUILTIN_H
 
+extern const char perf_usage_string[];
+extern const char perf_more_info_string[];
+
 struct feature_status {
 	const char *name;
 	const char *macro;
diff --git a/tools/perf/perf.c b/tools/perf/perf.c
index 7e2e667b011f..65bdfd71f626 100644
--- a/tools/perf/perf.c
+++ b/tools/perf/perf.c
@@ -31,7 +31,18 @@
 #include "util/build-id.h"
 #include "util/config.h"
 #include "util/debug.h"
-#include "util/util.h" // usage()
+
+const char perf_usage_string[] =
+	"perf [--version] [--help] [OPTIONS] COMMAND [ARGS]";
+
+const char perf_more_info_string[] =
+	"See 'perf help COMMAND' for more information on a specific command.";
+
+static void __noreturn usage(const char *err)
+{
+	fprintf(stderr, "\n Usage: %s\n", err);
+	exit(129);
+}
 
 #define CMD_EXEC_PATH "--exec-path"
 #define CMD_DEBUGFS_DIR "--debugfs-dir="
diff --git a/tools/perf/util/Build b/tools/perf/util/Build
index b26a0b1ddfa3..d08f2af7d970 100644
--- a/tools/perf/util/Build
+++ b/tools/perf/util/Build
@@ -54,7 +54,6 @@ perf-util-y += string.o
 perf-util-y += strlist.o
 perf-util-y += strfilter.o
 perf-util-y += top.o
-perf-util-y += usage.o
 perf-util-y += dso.o
 perf-util-y += dsos.o
 perf-util-y += symbol.o
diff --git a/tools/perf/util/usage.c b/tools/perf/util/usage.c
deleted file mode 100644
index 4c8ffbad2323..000000000000
--- a/tools/perf/util/usage.c
+++ /dev/null
@@ -1,34 +0,0 @@
-// SPDX-License-Identifier: GPL-2.0
-/*
- * usage.c
- *
- * Various reporting routines.
- * Originally copied from GIT source.
- *
- * Copyright (C) Linus Torvalds, 2005
- */
-#include "util.h"
-#include <stdio.h>
-#include <stdlib.h>
-#include <linux/compiler.h>
-
-const char perf_usage_string[] =
-	"perf [--version] [--help] [OPTIONS] COMMAND [ARGS]";
-
-const char perf_more_info_string[] =
-	"See 'perf help COMMAND' for more information on a specific command.";
-
-static __noreturn void usage_builtin(const char *err)
-{
-	fprintf(stderr, "\n Usage: %s\n", err);
-	exit(129);
-}
-
-/* If we are in a dlopen()ed .so write to a global variable would segfault
- * (ugh), so keep things static. */
-static void (*usage_routine)(const char *err) __noreturn = usage_builtin;
-
-void usage(const char *err)
-{
-	usage_routine(err);
-}
diff --git a/tools/perf/util/util.h b/tools/perf/util/util.h
index 87a0818a8c76..f8f1ff603c72 100644
--- a/tools/perf/util/util.h
+++ b/tools/perf/util/util.h
@@ -17,9 +17,6 @@
 #include <internal/cpumap.h>
 #endif
 
-extern const char perf_usage_string[];
-extern const char perf_more_info_string[];
-
 extern const char *input_name;
 
 /* This will control if perf_{host,guest} will set attr.exclude_{host,guest}. */
@@ -29,7 +26,6 @@ extern bool perf_host;
 extern bool perf_guest;
 
 /* General helper functions */
-void usage(const char *err) __noreturn;
 
 struct dirent;
 struct strlist;
-- 
2.55.0.966.g6673acef38-goog


  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 ` Ian Rogers [this message]
2026-09-02 15:56   ` [PATCH v3 4/6] perf tool: Move usage strings and functions to perf.c sashiko-bot
2026-09-02 15:48 ` [PATCH v3 5/6] perf tool: Add fallback stubs for missing dependencies Ian Rogers
2026-09-02 15:58   ` 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-5-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