[PATCH v1 5/6] perf util: Move input_name to util

From: Ian Rogers
Date: Mon Mar 27 2023 - 21:42:15 EST


input_name is the name of the input perf.data file, but having it in
perf.c makes it difficult to link without perf.c. Move it to util.

Signed-off-by: Ian Rogers <irogers@xxxxxxxxxx>
---
tools/perf/builtin-annotate.c | 2 +-
tools/perf/builtin-buildid-list.c | 2 +-
tools/perf/builtin-c2c.c | 2 +-
tools/perf/builtin-data.c | 2 +-
tools/perf/builtin-evlist.c | 2 +-
tools/perf/builtin-kmem.c | 2 +-
tools/perf/builtin-kwork.c | 2 +-
tools/perf/builtin-mem.c | 2 +-
tools/perf/builtin-sched.c | 2 +-
tools/perf/builtin-stat.c | 2 +-
tools/perf/builtin-timechart.c | 2 +-
tools/perf/perf.c | 1 -
tools/perf/perf.h | 1 -
tools/perf/ui/browsers/hists.c | 2 +-
tools/perf/util/util.c | 2 ++
tools/perf/util/util.h | 2 ++
16 files changed, 16 insertions(+), 14 deletions(-)

diff --git a/tools/perf/builtin-annotate.c b/tools/perf/builtin-annotate.c
index 4750fac7bf93..5a93a37318cc 100644
--- a/tools/perf/builtin-annotate.c
+++ b/tools/perf/builtin-annotate.c
@@ -15,7 +15,6 @@
#include <linux/zalloc.h>
#include "util/symbol.h"

-#include "perf.h"
#include "util/debug.h"

#include "util/evlist.h"
@@ -36,6 +35,7 @@
#include "util/block-range.h"
#include "util/map_symbol.h"
#include "util/branch.h"
+#include "util/util.h"

#include <dlfcn.h>
#include <errno.h>
diff --git a/tools/perf/builtin-buildid-list.c b/tools/perf/builtin-buildid-list.c
index 00bfe89f0b5d..b6816c4dd889 100644
--- a/tools/perf/builtin-buildid-list.c
+++ b/tools/perf/builtin-buildid-list.c
@@ -8,7 +8,6 @@
* Copyright (C) 2009, Arnaldo Carvalho de Melo <acme@xxxxxxxxxx>
*/
#include "builtin.h"
-#include "perf.h"
#include "util/build-id.h"
#include "util/debug.h"
#include "util/dso.h"
@@ -18,6 +17,7 @@
#include "util/session.h"
#include "util/symbol.h"
#include "util/data.h"
+#include "util/util.h"
#include <errno.h>
#include <inttypes.h>
#include <linux/err.h>
diff --git a/tools/perf/builtin-c2c.c b/tools/perf/builtin-c2c.c
index d3181fee4d3d..6c12f0865860 100644
--- a/tools/perf/builtin-c2c.c
+++ b/tools/perf/builtin-c2c.c
@@ -41,10 +41,10 @@
#include "symbol.h"
#include "ui/ui.h"
#include "ui/progress.h"
-#include "../perf.h"
#include "pmu.h"
#include "pmu-hybrid.h"
#include "string2.h"
+#include "util/util.h"

struct c2c_hists {
struct hists hists;
diff --git a/tools/perf/builtin-data.c b/tools/perf/builtin-data.c
index b2a9a3b7f68d..ce51cbf6dc97 100644
--- a/tools/perf/builtin-data.c
+++ b/tools/perf/builtin-data.c
@@ -3,10 +3,10 @@
#include <stdio.h>
#include <string.h>
#include "builtin.h"
-#include "perf.h"
#include "debug.h"
#include <subcmd/parse-options.h>
#include "data-convert.h"
+#include "util/util.h"

typedef int (*data_cmd_fn_t)(int argc, const char **argv);

diff --git a/tools/perf/builtin-evlist.c b/tools/perf/builtin-evlist.c
index b1076177c37f..7117656939e7 100644
--- a/tools/perf/builtin-evlist.c
+++ b/tools/perf/builtin-evlist.c
@@ -7,7 +7,6 @@

#include <linux/list.h>

-#include "perf.h"
#include "util/evlist.h"
#include "util/evsel.h"
#include "util/evsel_fprintf.h"
@@ -18,6 +17,7 @@
#include "util/debug.h"
#include <linux/err.h>
#include "util/tool.h"
+#include "util/util.h"

static int process_header_feature(struct perf_session *session __maybe_unused,
union perf_event *event __maybe_unused)
diff --git a/tools/perf/builtin-kmem.c b/tools/perf/builtin-kmem.c
index f3029742b800..8bc2d1775ed8 100644
--- a/tools/perf/builtin-kmem.c
+++ b/tools/perf/builtin-kmem.c
@@ -1,6 +1,5 @@
// SPDX-License-Identifier: GPL-2.0
#include "builtin.h"
-#include "perf.h"

#include "util/dso.h"
#include "util/evlist.h"
@@ -24,6 +23,7 @@

#include "util/debug.h"
#include "util/string2.h"
+#include "util/util.h"

#include <linux/kernel.h>
#include <linux/numa.h>
diff --git a/tools/perf/builtin-kwork.c b/tools/perf/builtin-kwork.c
index dc59d75180d1..a9395c52b23b 100644
--- a/tools/perf/builtin-kwork.c
+++ b/tools/perf/builtin-kwork.c
@@ -6,7 +6,6 @@
*/

#include "builtin.h"
-#include "perf.h"

#include "util/data.h"
#include "util/evlist.h"
@@ -20,6 +19,7 @@
#include "util/string2.h"
#include "util/callchain.h"
#include "util/evsel_fprintf.h"
+#include "util/util.h"

#include <subcmd/pager.h>
#include <subcmd/parse-options.h>
diff --git a/tools/perf/builtin-mem.c b/tools/perf/builtin-mem.c
index dedd612eae5e..93caf50df895 100644
--- a/tools/perf/builtin-mem.c
+++ b/tools/perf/builtin-mem.c
@@ -4,7 +4,6 @@
#include <sys/stat.h>
#include <unistd.h>
#include "builtin.h"
-#include "perf.h"

#include <subcmd/parse-options.h>
#include "util/auxtrace.h"
@@ -22,6 +21,7 @@
#include "util/pmu-hybrid.h"
#include "util/sample.h"
#include "util/string2.h"
+#include "util/util.h"
#include <linux/err.h>

#define MEM_OPERATION_LOAD 0x1
diff --git a/tools/perf/builtin-sched.c b/tools/perf/builtin-sched.c
index 86e18575c9be..96a0dceadeff 100644
--- a/tools/perf/builtin-sched.c
+++ b/tools/perf/builtin-sched.c
@@ -1,6 +1,5 @@
// SPDX-License-Identifier: GPL-2.0
#include "builtin.h"
-#include "perf.h"
#include "perf-sys.h"

#include "util/cpumap.h"
@@ -27,6 +26,7 @@

#include "util/debug.h"
#include "util/event.h"
+#include "util/util.h"

#include <linux/kernel.h>
#include <linux/log2.h>
diff --git a/tools/perf/builtin-stat.c b/tools/perf/builtin-stat.c
index 7ef565ae7265..31ac7a68a36c 100644
--- a/tools/perf/builtin-stat.c
+++ b/tools/perf/builtin-stat.c
@@ -41,7 +41,6 @@
*/

#include "builtin.h"
-#include "perf.h"
#include "util/cgroup.h"
#include <subcmd/parse-options.h>
#include "util/parse-events.h"
@@ -71,6 +70,7 @@
#include "util/bpf_counter.h"
#include "util/iostat.h"
#include "util/pmu-hybrid.h"
+#include "util/util.h"
#include "asm/bug.h"

#include <linux/time64.h>
diff --git a/tools/perf/builtin-timechart.c b/tools/perf/builtin-timechart.c
index 6c629e7d370a..bce1cf896f9c 100644
--- a/tools/perf/builtin-timechart.c
+++ b/tools/perf/builtin-timechart.c
@@ -24,7 +24,6 @@
#include "util/thread.h"
#include "util/callchain.h"

-#include "perf.h"
#include "util/header.h"
#include <subcmd/pager.h>
#include <subcmd/parse-options.h>
@@ -37,6 +36,7 @@
#include "util/debug.h"
#include "util/string2.h"
#include "util/tracepoint.h"
+#include "util/util.h"
#include <linux/err.h>
#include <traceevent/event-parse.h>

diff --git a/tools/perf/perf.c b/tools/perf/perf.c
index 441c354b8304..38cae4721583 100644
--- a/tools/perf/perf.c
+++ b/tools/perf/perf.c
@@ -40,7 +40,6 @@
#include <linux/zalloc.h>

static int use_pager = -1;
-const char *input_name;

struct cmd_struct {
const char *cmd;
diff --git a/tools/perf/perf.h b/tools/perf/perf.h
index 989eb17ec474..49e15e2be49e 100644
--- a/tools/perf/perf.h
+++ b/tools/perf/perf.h
@@ -8,7 +8,6 @@
#define MAX_NR_CPUS 2048
#endif

-extern const char *input_name;
extern bool perf_host, perf_guest;

enum perf_affinity {
diff --git a/tools/perf/ui/browsers/hists.c b/tools/perf/ui/browsers/hists.c
index b72ee6822222..23d1b592ebc0 100644
--- a/tools/perf/ui/browsers/hists.c
+++ b/tools/perf/ui/browsers/hists.c
@@ -29,8 +29,8 @@
#include "../../util/top.h"
#include "../../util/thread.h"
#include "../../util/block-info.h"
+#include "../../util/util.h"
#include "../../arch/common.h"
-#include "../../perf.h"

#include "../browsers/hists.h"
#include "../helpline.h"
diff --git a/tools/perf/util/util.c b/tools/perf/util/util.c
index b356c9f7f0c3..0cdd459a319d 100644
--- a/tools/perf/util/util.c
+++ b/tools/perf/util/util.c
@@ -28,6 +28,8 @@
* XXX We need to find a better place for these things...
*/

+const char *input_name;
+
bool perf_singlethreaded = true;

void perf_set_singlethreaded(void)
diff --git a/tools/perf/util/util.h b/tools/perf/util/util.h
index 5010abf9e01e..8bd515b67739 100644
--- a/tools/perf/util/util.h
+++ b/tools/perf/util/util.h
@@ -18,6 +18,8 @@
extern const char perf_usage_string[];
extern const char perf_more_info_string[];

+extern const char *input_name;
+
/* General helper functions */
void usage(const char *err) __noreturn;
void die(const char *err, ...) __noreturn __printf(1, 2);
--
2.40.0.348.gf938b09366-goog