From patchwork Fri Jul 12 18:10:52 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ian Rogers X-Patchwork-Id: 13732145 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 536EDC3DA45 for ; Fri, 12 Jul 2024 18:15:34 +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=W3N+sXEIdDW4FZ9MEavkeCx7Ak5mBAvz0H4sFCDbHeI=; b=LaDAWdxlpIGuRUzgaSlexUqeG8 KPHtvEZlafUuTBdBoomlSkQq18XltsGaj7FQc2HVGQcwEvmt5qHJO2R/3yBQjyhHKMPajgNc9ulDh Hh1yKkBvNM/IT5kAdfYePrzZGPRONJQZ0ZUUfwgMMfTru+ficYvJdZuuG7uOhih+INnotaXVSDxcg 87rAVvGfKGbSzaJ4tfTcpGE6YPSSwaDKEL3mmHJ8i2uHLSYdgUiOKTYZG43M8hOwTd4KmEHIpmnh/ qdDfJruaq2pazbibhnFzeqLeXQgR9fxzlyQ0lzNFOrvnRiHepRhn6OLgY/mDQcp1tt3rncQJhAVN3 LDq+A9fg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1sSKnl-00000000wcW-1rGZ; Fri, 12 Jul 2024 18:15:25 +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 1sSKl2-00000000vLm-0U31 for linux-arm-kernel@lists.infradead.org; Fri, 12 Jul 2024 18:12:37 +0000 Received: by mail-yw1-x1149.google.com with SMTP id 00721157ae682-6502e4c5aafso27176657b3.1 for ; Fri, 12 Jul 2024 11:12:35 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1720807955; x=1721412755; 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=W3N+sXEIdDW4FZ9MEavkeCx7Ak5mBAvz0H4sFCDbHeI=; b=VBTqmwdTCtpV4mK+KEyZ70gG609aOHbX3bP02/c+3L7VERiVnEUnTsHimX7QY62D/7 ZzbwH0F23hosqN+SdXewunUYYjM+eWQCYqXzJ4EpWlfToce1i/kfQ9fFX4cSqGf7LR9k cMU+CBBfgJ99+Oo8W62ot9syrSa4NSUaHOd8gzSrufhYYcoreyWHG6wkU8Bjs04jFqQA lUEGNIvMYlP8664LLsDA1PyHlPV+dJwMrVgJN0e5KLN6U76GZE80v3jBZQFcC0rnoE1v P+2bMaJn6sT5FGeQa6WtywUOV5J2GQuLKXD239ylIXIkaeyCy8gD+1e/Ks7oAUdNsdrD fbmg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1720807955; x=1721412755; 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=W3N+sXEIdDW4FZ9MEavkeCx7Ak5mBAvz0H4sFCDbHeI=; b=Isu141KzcEHAXmZ8iZujDwpnWiQvlUk6uk99ICE5d6V8k03Smh+mYPAWrfjEcheCk0 tnY0DBERPXhgyV8O21Cu9dXJpp1iq2zsjZRw/Cva/AIMDgeJu8NcZDC2iNWV7G8z5aGy y+wwi5lV8W7hz8JLR5aoNdfKqmZ12nf3RWvk4PhEZN9gFP2u7I8msFYoi33jNcSQXLbU aLtifogU3k5+Sv8wvckKjkcsJyoDuZTh4Fwlas33/S2sURqa0WrnkSqn9QmocyF7lbH9 lKZjPWj+/XrNC7idLk1SeG3VcPX2afCBBuyO7pqZ4ltOjhV4BSsZzac5e6HTvWbV/CBK 9ejg== X-Forwarded-Encrypted: i=1; AJvYcCXyFvZSa27UstbmesV1KZ4p/deJdzno4oRuhSUKJOhq35rZLAubt9X2gS36qMYLDck96VyTWx+XKr08GbvNGTrcMUYESdBRFbAI3iRipQnFeWsUVUw= X-Gm-Message-State: AOJu0YwIuviJdwVfqNKnycoCCeRpE7PqJSAFZzRHf3YFQPXziRux26tH zNbMC5RoiipU3Nc9WSgdUktL+M3WIAiO0VPzt+P0fBDQ/1Np06qmI8vucS05+TMo1GdlR8vaIow vdtnDbQ== X-Google-Smtp-Source: AGHT+IExEZhqBBcIexchHpBnvFmTKUgMli03JoYZcn32JuoHYiPGuJJ58g8CD6QprTxwGaZs6P7o4XHXSCM9 X-Received: from irogers.svl.corp.google.com ([2620:15c:2a3:200:2e7d:d47a:a0c6:e3b1]) (user=irogers job=sendgmr) by 2002:a05:690c:dd3:b0:620:32ea:e1d4 with SMTP id 00721157ae682-65df661ceb7mr703737b3.0.1720807954828; Fri, 12 Jul 2024 11:12:34 -0700 (PDT) Date: Fri, 12 Jul 2024 11:10:52 -0700 In-Reply-To: <20240712181108.475336-1-irogers@google.com> Message-Id: <20240712181108.475336-12-irogers@google.com> Mime-Version: 1.0 References: <20240712181108.475336-1-irogers@google.com> X-Mailer: git-send-email 2.45.2.993.g49e7a77208-goog Subject: [PATCH v5 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-20240712_111236_189244_EBB81815 X-CRM114-Status: GOOD ( 16.23 ) 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 f27f725913d7..12a5170d9193 100644 --- a/tools/perf/builtin-record.c +++ b/tools/perf/builtin-record.c @@ -193,6 +193,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) { @@ -1458,7 +1467,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); } @@ -2386,6 +2395,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"); @@ -3326,18 +3345,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 897c6c44b6b2..fb7e32d98dda 100644 --- a/tools/perf/util/tool.h +++ b/tools/perf/util/tool.h @@ -93,4 +93,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 */