From patchwork Thu Jul 11 17:59: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: 13730976 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 7A8ECC3DA4B for ; Thu, 11 Jul 2024 18:04:06 +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=5Ff/gAGDG2aAEbUu/hDCKYzzmvI/uHVZRadY3JBl8Rs=; b=s0Ca9NTFsZDJ3JQ5wA+TmqyG6Q bHZ96qlVK6i3ON0c20K+NCuHXFbpaHx5mSF3VLqgIfcXktg2Lc6p7Awq+hTa0pOcqmiFwoaNG5Wp7 sO9h0owAALf2LfS5GEK5Q6ZguXPJRx111LlVEO4MU4mY8yFroVDlrUoMFmFiE1fbXKiKQclWYlA81 oSAdQPtLg1rSnpAhdfUGT8RMMJQpGRArmiC21aoNCooi8xRf1s/jmbVipGLW3wHnYz12WKB2iwxoV Mi/4VBKiAQOoW3az+HHfgr2SdlOWO6uYxxyLPe3+dYaxGca/Egw3KvrGr//2TTyIpPj8/9/LQZqn+ YFoyR7/A==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1sRy97-0000000ExmG-0ICk; Thu, 11 Jul 2024 18:03:57 +0000 Received: from mail-yw1-x114a.google.com ([2607:f8b0:4864:20::114a]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1sRy5x-0000000EwFc-0KxR for linux-arm-kernel@lists.infradead.org; Thu, 11 Jul 2024 18:00:43 +0000 Received: by mail-yw1-x114a.google.com with SMTP id 00721157ae682-6502e4c5aafso13248377b3.1 for ; Thu, 11 Jul 2024 11:00:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1720720839; x=1721325639; 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=5Ff/gAGDG2aAEbUu/hDCKYzzmvI/uHVZRadY3JBl8Rs=; b=fsABz7hG9J90sJyWIrgJeCzifGHFDRi54xWCXB84J2IhN/C8elJuqZJtZEv2iGbBXn 5B7MsQzQMl8NACxNuicz5+nC9dm3q8T9pIrXYYwbnUZ8Lw1036UzYCmbzxq/T2853fhb d+yiZUxgTW/UBP68XO/BA2o2L5ekSoxm6ln5tTjJgVb/6hLBjmzb5lYLYcFCVc7GGLQT AnviihMkZHpF+cuxj+8ZZ0AtHW+5oUF+be35ecvyJOORKYwEdbBov+iPoegawUMik9iF v5EY4AuGibhEdgjyaRRhnYxGELC4lbr8cWFHsYI44FTqVzvmvjzoLy+dMIllWHQRezyr qYaA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1720720839; x=1721325639; 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=5Ff/gAGDG2aAEbUu/hDCKYzzmvI/uHVZRadY3JBl8Rs=; b=hEuqoNY6QY/mtpnXQeimS+y1/FC5WLluu/kkvvJB996seif0GOyTTTBU2YvMlfRjgU i11/ky60ckvICBXqhFhIoqn15rv11QmRKeLqsj3Ebnic1R8HQ1OGasJhytzNab7aM0c0 R6GjzO0DfFj1YnKFhhZ60ckh1Glab3ZceygZB+UP7PAV2yt1i/fq0rqawLAVRUsjPuAY 5OSlyxIs457Fb1H2FhHVmSBQP3q1gSXZlNkVvHB0Qby2w5i8VpDncCNPmqfECWKAnQOA xqe9cDUoqrhza5h0L1/rGkWW4DkAQP1oMa3979nX9N04c6VfjnIEXV8olJl1kxzbNWRu fDfA== X-Forwarded-Encrypted: i=1; AJvYcCW7UysnqCw08ZzGUBZLhunU86JaVu/XiQny71j0X+fuD3Ynrj6pAWfZ5avtf6PyPIRds5n0L7JynjKDnCn9Zk6+gazSPoUzOf7mOE1ORkxzTSAyinw= X-Gm-Message-State: AOJu0YzasVijaIlKblELECwl4gNYlj6IHzyq/vg1v+FVnEtEfpceKiEX 8GBEIZLJn04Gml7R0ggN4a+/ZYsbJOhc3ZMBZuXbjeoiB/KNdoRWTJ+F0npcBCUhCpJPE2BQgxF pzwBfsA== X-Google-Smtp-Source: AGHT+IFj9eydv65A7J7SzzeWQzPfBnQ3Mr87UOA0hqpnZkLQstHLPEsb9+ha7vzF8KoEQHxSj3FAFxPIHkwL X-Received: from irogers.svl.corp.google.com ([2620:15c:2a3:200:bd08:a1e0:c497:32db]) (user=irogers job=sendgmr) by 2002:a0d:ea49:0:b0:64b:a38:31d0 with SMTP id 00721157ae682-65df50b328amr15277b3.4.1720720839402; Thu, 11 Jul 2024 11:00:39 -0700 (PDT) Date: Thu, 11 Jul 2024 10:59:52 -0700 In-Reply-To: <20240711180008.188906-1-irogers@google.com> Message-Id: <20240711180008.188906-13-irogers@google.com> Mime-Version: 1.0 References: <20240711180008.188906-1-irogers@google.com> X-Mailer: git-send-email 2.45.2.993.g49e7a77208-goog Subject: [PATCH v4 12/28] 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-20240711_110041_195978_61CD5E0E X-CRM114-Status: GOOD ( 15.85 ) 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 e8677f9e1ccb..4b9309b4c07e 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 */