From patchwork Mon Aug 12 20:47:03 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ian Rogers X-Patchwork-Id: 13761028 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 16972C3DA7F for ; Mon, 12 Aug 2024 20:54:23 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Content-Type:To:From:Subject :References:Mime-Version:Message-Id:In-Reply-To:Date:Reply-To:Cc: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=J3jqi17epiT5W5NpHtjXH0dEG9gj5/vhoZ4ouw58D8Y=; b=uLrVhDgxLWIivYjLwtUaRhaF8v IkN5vd24mY6BHm63tWb3HhBxD9/0SeA8+0hhe0tqosRQRsCY5rfitDuEwtvUca/L4VAA1rNojgG36 Ms7FfRr1lcNrZXC4j+KvoObB3TSezlzgBphx6pXzbzE3edatrb5PQautKeQapqnjzEuv1n8TfH005 hmlF+0xVh2+bYCOgYGvPo0CWRYRxLnnnZz8A+UY7GYjRq5FmOHt9zW8WGSm4zUfyZEJhHI8KERrLM bYN54mb1+lxwwmamb3Lnk9plla+vVxILzhyC17TYGuZQZfl4kiQdv1/FO7vJYkLXyU256WeQPegoV KB32rZ5w==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1sdc3L-00000001Wbs-07Ey; Mon, 12 Aug 2024 20:54:07 +0000 Received: from mail-yw1-x1149.google.com ([2607:f8b0:4864:20::1149]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1sdbxH-00000001UZx-1xNM for linux-arm-kernel@lists.infradead.org; Mon, 12 Aug 2024 20:47:53 +0000 Received: by mail-yw1-x1149.google.com with SMTP id 00721157ae682-664916e5b40so68394547b3.1 for ; Mon, 12 Aug 2024 13:47:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1723495670; x=1724100470; darn=lists.infradead.org; h=to:from:subject:references:mime-version:message-id:in-reply-to:date :from:to:cc:subject:date:message-id:reply-to; bh=J3jqi17epiT5W5NpHtjXH0dEG9gj5/vhoZ4ouw58D8Y=; b=hvx+UFgmmmAEVbocvL4Z54qCICV2VKyJdoj0ySdemKCa3wnt03f4+50KmHuosKb+vW bG4Pv2FSaJJfkfXe2iQrDnhxevE03s4m3pHGNLwyzy1s7ZNIEB6BsooqZrz7WU6uq3sZ D8zwkbfU4O9bbxR+jI3E/d6HLnppwC0X4JFXv9LvTSV3kkCJX/dMS1HMrLaMhsgE/abC tqUsRBeV3OaoXxsn00KQRiG9sLLNAEM8lRqbBwLh5mC8r/fLJYJJffUvszWu4fbc60CN 3NXx0LNDfSQRVvAt0bbAQWn7MePBzC32+COQIylmmRKEWOdyDw0vh7FiT+KVzBzrGuXT sDuQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1723495670; x=1724100470; h=to:from:subject:references:mime-version:message-id:in-reply-to:date :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=J3jqi17epiT5W5NpHtjXH0dEG9gj5/vhoZ4ouw58D8Y=; b=njvk5DbbHPtTOTIXL3VfaZm0bocWoo3M2cKIRAhxHo6Li2NMWklBF/yuDJdBmhmkC+ V6bWGl7PCZwMoHH1ioe2m50uKzLQNhiTjsZeU/uq4BvmwxdIDKkXokZaqqjDy40aY9Oj 6XD++Slcxw7OWrDxdxG5VamJj0Be2VaqwMGJ2UhqnpoxmGO/eovfN9o35LzXWuA1hSwp wUDlGrJ50/w9RI6o5s7ojjRzs6PzLFhlmXSqewvi/POEKOCQzoyWsFLMQ86xrfK7dPbY ZE5Ha7/+oTfghOtbK9XxVEcFIbvjiuyvkBPKS9BenykS7zKXgsFYuhls60swxW0mquZL J+ow== X-Forwarded-Encrypted: i=1; AJvYcCU71tRniSgr3sHXVwWEh699VznE9u6oWmArXRFvESJ46QPa2BcxGuBRrSABTbd0IfhUmbIHxi458dyRqFcrXoVI3ugadVEBrvp0sn25uUIBe4wQjGg= X-Gm-Message-State: AOJu0Yw28TPT2JD0FcW/5JW/stT8CfF0xWyZcxzINq4goIKc4TTBSFeq sS0J/kixRZR0LzQ0usfUCj7Eo1e9brXA9OPg4pUMGM8gL45ijGLhB4F0ieTO4P+G2aP6nKnAAmt uVOK4fA== X-Google-Smtp-Source: AGHT+IEUTe+31u4c0XlLwpy08DjQKT6rgdB8gr9GGhJp2e2MdzhZe2ydsJffGE/8HlJ8ES1MJe7plUf+7SS6 X-Received: from irogers.svl.corp.google.com ([2620:15c:2a3:200:e7f1:b90:720c:35bf]) (user=irogers job=sendgmr) by 2002:a0d:c6c3:0:b0:644:c4d6:add0 with SMTP id 00721157ae682-6a9e4c87a4amr142227b3.1.1723495670221; Mon, 12 Aug 2024 13:47:50 -0700 (PDT) Date: Mon, 12 Aug 2024 13:47:03 -0700 In-Reply-To: <20240812204720.631678-1-irogers@google.com> Message-Id: <20240812204720.631678-12-irogers@google.com> Mime-Version: 1.0 References: <20240812204720.631678-1-irogers@google.com> X-Mailer: git-send-email 2.46.0.76.ge559c4bf1a-goog Subject: [PATCH v7 11/27] perf record: Use perf_tool__init From: Ian Rogers To: Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Namhyung Kim , Mark Rutland , Alexander Shishkin , Jiri Olsa , Ian Rogers , Adrian Hunter , Kan Liang , John Garry , Will Deacon , James Clark , Mike Leach , Leo Yan , Suzuki K Poulose , Yicong Yang , Jonathan Cameron , Nick Terrell , Nick Desaulniers , Oliver Upton , Anshuman Khandual , Song Liu , Ilkka Koskinen , Athira Rajeev , Huacai Chen , Yanteng Si , Sun Haiyong , linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org, linux-arm-kernel@lists.infradead.org X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240812_134751_569254_BD973CC7 X-CRM114-Status: GOOD ( 16.74 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org 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 --- tools/perf/builtin-record.c | 33 ++++++++++++++++++++------------- tools/perf/util/tool.c | 10 +++++----- tools/perf/util/tool.h | 6 ++++++ 3 files changed, 31 insertions(+), 18 deletions(-) diff --git a/tools/perf/builtin-record.c b/tools/perf/builtin-record.c index 46410eb3a76b..39367709fd99 100644 --- a/tools/perf/builtin-record.c +++ b/tools/perf/builtin-record.c @@ -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 diff --git a/tools/perf/util/tool.c b/tools/perf/util/tool.c index cbd9b888bd73..a4ca16e5eefe 100644 --- a/tools/perf/util/tool.c +++ b/tools/perf/util/tool.c @@ -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; diff --git a/tools/perf/util/tool.h b/tools/perf/util/tool.h index 7c7ce395e573..c7fea58729a5 100644 --- a/tools/perf/util/tool.h +++ b/tools/perf/util/tool.h @@ -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 */