]> git.ipfire.org Git - thirdparty/kernel/stable.git/commitdiff
perf record: Use perf_tool__init()
authorIan Rogers <irogers@google.com>
Mon, 12 Aug 2024 20:47:03 +0000 (13:47 -0700)
committerArnaldo Carvalho de Melo <acme@redhat.com>
Mon, 12 Aug 2024 21:09:05 +0000 (18:09 -0300)
Use perf_tool__init() so that more uses of 'struct perf_tool' can be const
and not relying on perf_tool__fill_defaults().

Signed-off-by: Ian Rogers <irogers@google.com>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Anshuman Khandual <anshuman.khandual@arm.com>
Cc: Athira Rajeev <atrajeev@linux.vnet.ibm.com>
Cc: Huacai Chen <chenhuacai@kernel.org>
Cc: Ilkka Koskinen <ilkka@os.amperecomputing.com>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: James Clark <james.clark@arm.com>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: John Garry <john.g.garry@oracle.com>
Cc: Jonathan Cameron <jonathan.cameron@huawei.com>
Cc: Kan Liang <kan.liang@linux.intel.com>
Cc: Leo Yan <leo.yan@linux.dev>
Cc: Mark Rutland <mark.rutland@arm.com>
Cc: Mike Leach <mike.leach@linaro.org>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Nick Desaulniers <ndesaulniers@google.com>
Cc: Nick Terrell <terrelln@fb.com>
Cc: Oliver Upton <oliver.upton@linux.dev>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Song Liu <song@kernel.org>
Cc: Sun Haiyong <sunhaiyong@loongson.cn>
Cc: Suzuki Poulouse <suzuki.poulose@arm.com>
Cc: Will Deacon <will@kernel.org>
Cc: Yanteng Si <siyanteng@loongson.cn>
Cc: Yicong Yang <yangyicong@hisilicon.com>
Cc: linux-arm-kernel@lists.infradead.org
Link: https://lore.kernel.org/r/20240812204720.631678-12-irogers@google.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
tools/perf/builtin-record.c
tools/perf/util/tool.c
tools/perf/util/tool.h

index 46410eb3a76bb8b41ab4ee693acc564d2ef525eb..39367709fd99161937e471ca7fa3ff40086d81dc 100644 (file)
@@ -194,6 +194,15 @@ static const char *affinity_tags[PERF_AFFINITY_MAX] = {
        "SYS", "NODE", "CPU"
 };
 
+static int build_id__process_mmap(const struct perf_tool *tool, union perf_event *event,
+                                 struct perf_sample *sample, struct machine *machine);
+static int build_id__process_mmap2(const struct perf_tool *tool, union perf_event *event,
+                                  struct perf_sample *sample, struct machine *machine);
+static int process_timestamp_boundary(const struct perf_tool *tool,
+                                     union perf_event *event,
+                                     struct perf_sample *sample,
+                                     struct machine *machine);
+
 #ifndef HAVE_GETTID
 static inline pid_t gettid(void)
 {
@@ -1459,7 +1468,7 @@ static int process_buildids(struct record *rec)
         * first/last samples.
         */
        if (rec->buildid_all && !rec->timestamp_boundary)
-               rec->tool.sample = NULL;
+               rec->tool.sample = process_event_sample_stub;
 
        return perf_session__process_events(session);
 }
@@ -2387,6 +2396,16 @@ static int __cmd_record(struct record *rec, int argc, const char **argv)
                signal(SIGUSR2, SIG_IGN);
        }
 
+       perf_tool__init(tool, /*ordered_events=*/true);
+       tool->sample            = process_sample_event;
+       tool->fork              = perf_event__process_fork;
+       tool->exit              = perf_event__process_exit;
+       tool->comm              = perf_event__process_comm;
+       tool->namespaces        = perf_event__process_namespaces;
+       tool->mmap              = build_id__process_mmap;
+       tool->mmap2             = build_id__process_mmap2;
+       tool->itrace_start      = process_timestamp_boundary;
+       tool->aux               = process_timestamp_boundary;
        session = perf_session__new(data, tool);
        if (IS_ERR(session)) {
                pr_err("Perf session creation failed.\n");
@@ -3327,18 +3346,6 @@ static struct record record = {
                .ctl_fd_ack          = -1,
                .synth               = PERF_SYNTH_ALL,
        },
-       .tool = {
-               .sample         = process_sample_event,
-               .fork           = perf_event__process_fork,
-               .exit           = perf_event__process_exit,
-               .comm           = perf_event__process_comm,
-               .namespaces     = perf_event__process_namespaces,
-               .mmap           = build_id__process_mmap,
-               .mmap2          = build_id__process_mmap2,
-               .itrace_start   = process_timestamp_boundary,
-               .aux            = process_timestamp_boundary,
-               .ordered_events = true,
-       },
 };
 
 const char record_callchain_help[] = CALLCHAIN_RECORD_HELP
index cbd9b888bd731d3ed013ed8ae39d294eb91dbef3..a4ca16e5eefeea0fa574d409a58f54d3a881e8ef 100644 (file)
@@ -99,11 +99,11 @@ static int process_event_synth_event_update_stub(const struct perf_tool *tool __
        return 0;
 }
 
-static int process_event_sample_stub(const struct perf_tool *tool __maybe_unused,
-                                    union perf_event *event __maybe_unused,
-                                    struct perf_sample *sample __maybe_unused,
-                                    struct evsel *evsel __maybe_unused,
-                                    struct machine *machine __maybe_unused)
+int process_event_sample_stub(const struct perf_tool *tool __maybe_unused,
+                             union perf_event *event __maybe_unused,
+                             struct perf_sample *sample __maybe_unused,
+                             struct evsel *evsel __maybe_unused,
+                             struct machine *machine __maybe_unused)
 {
        dump_printf(": unhandled!\n");
        return 0;
index 7c7ce395e573591d3c9b7a6cea7990a9be7f345d..c7fea58729a5dbed7e58d5d499b9af2b8e89c42e 100644 (file)
@@ -94,4 +94,10 @@ void perf_tool__fill_defaults(struct perf_tool *tool);
 
 bool perf_tool__compressed_is_stub(const struct perf_tool *tool);
 
+int process_event_sample_stub(const struct perf_tool *tool,
+                             union perf_event *event,
+                             struct perf_sample *sample,
+                             struct evsel *evsel,
+                             struct machine *machine);
+
 #endif /* __PERF_TOOL_H */