From nobody Tue Feb 10 20:06:14 2026 Received: from mail-dl1-f73.google.com (mail-dl1-f73.google.com [74.125.82.73]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 6F8EF3A1D1C for ; Mon, 9 Feb 2026 17:41:33 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=74.125.82.73 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1770658893; cv=none; b=pY9FdG0cmyUTwciN5/bL0qw2DIridFXeomhu2Mt4JCTCsGQSO09Q56D2iAtxIYzHI7hX02aiUFe2q8fMwf/cmwerdunKIE2x4SZToBwLsWOqcJitmfwzs8493RzN4oL5Y9b3lQky1aYk9ZXoAcPsdYzk+Uau4ungeP40/RRC4SE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1770658893; c=relaxed/simple; bh=CXh+eFU5YtRUOBXtV2IECoJ2dCMUwGTcMJgRGhjVckY=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Content-Type; b=bJnEK/VDCmIaRDhEeLKuSO/dJAfwvoArYgWdHfMWwQTgskVCwNVnPJpxJEZI597AIJJyUYIVy0WUb2SXWwh7S9Wsk8z/J9/qjBDU/G4UTc7Q48YIkygTfrzsZa0TcfcvkN2kLMe+6Ma0Pnj7YJPgIWnMASv1WaPPu1veMtG4yo8= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--irogers.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=tpMkobR+; arc=none smtp.client-ip=74.125.82.73 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--irogers.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="tpMkobR+" Received: by mail-dl1-f73.google.com with SMTP id a92af1059eb24-124a38e8980so3816872c88.0 for ; Mon, 09 Feb 2026 09:41:33 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1770658893; x=1771263693; darn=vger.kernel.org; h=to:from:subject:message-id:references:mime-version:in-reply-to:date :from:to:cc:subject:date:message-id:reply-to; bh=/QcBbxvHOyiN8NjYfndkJsVEnF1q6+c6eApGTKX1f8c=; b=tpMkobR+EHS9lP4F64pj00SyPXwswZT7idEj9Tj1wqn7pJfmRN8X2fcfXPzwW3jNPW qq5VMy8hkiiDqe3wNuOSD7AJKF6bUHWj+EzJPjbfjvPuUg2v5NdqYyZJBbTapgWX8Gym wMuehLod8sq9dxVJmgpNMq2qSvX5M4187z0gI6A790zVuvZ2ayRKEff9t9NGwi4BZXDu T3fWkx/NEh9MHVQIVEqiKjMPPEOVLEv5FvIGnId0FqyoP00zhnWGMdciughwrPvIr0Yd iiHYy6GqEl+VL4fzYjNAH/z/S+QX6QlBhGT61k9TWtDA1Or2SESbhnrc6e72Yes1oQMd fTtg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1770658893; x=1771263693; h=to:from:subject:message-id:references:mime-version:in-reply-to:date :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=/QcBbxvHOyiN8NjYfndkJsVEnF1q6+c6eApGTKX1f8c=; b=CM+/x40O7iYi97g4D57hqgvmO/CvcWuclWWNiQvLyV5o24tlO5NiDQdj6blGRI5FDB rP83pjzcM2sucnOE1Jj4g6EFkU9cqBAC4pvLAC8iRvINDa0FftR8P32TOXJs6OwBSpPL ughaWioCm/x50ZTl0kVRNJxuGHka7eOfNnJtd1/Hr56p/42PGDLDR6879dKdPRScYf09 TXubBV4tdbfJFE7LyCi8uGhxu++5am0P5HYAJZtiVK9sd9PMMdTKkZGetv3miWZgfjY/ i2N01bRNLYVi0hjXdM8SWpa89j8fZMlUHw6eQd+17BgRbBkoOlCGg/TLaqYZN/HZDkJe HgDA== X-Forwarded-Encrypted: i=1; AJvYcCUf2pomLkOmOozu9bB6fH2mnkG33psYUZcyKuIYHPjVZR9E9edtvo0Ctae18IzCggp64xt9/z8v1VDclM0=@vger.kernel.org X-Gm-Message-State: AOJu0YwB8QmdcxuiKLuP06ySXOMDZq5p7x6sBAPGgqi3o5tu+jZPyWp3 0bG5VpQ95HAYbr8DcNPKRthcvQFVJJ4kHF4qcFYIxi6s8XjCMmUHJVe2rc4MiA24EUZwDQznLmS ocUEyOnsodw== X-Received: from dlbrp11.prod.google.com ([2002:a05:7022:160b:b0:123:2800:6acb]) (user=irogers job=prod-delivery.src-stubby-dispatcher) by 2002:a05:7022:3f88:b0:127:dd7:2062 with SMTP id a92af1059eb24-1270dd720e6mr3532717c88.43.1770658892614; Mon, 09 Feb 2026 09:41:32 -0800 (PST) Date: Mon, 9 Feb 2026 09:40:30 -0800 In-Reply-To: <20260209174032.4142096-1-irogers@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20260209174032.4142096-1-irogers@google.com> X-Mailer: git-send-email 2.53.0.239.g8d8fc8a987-goog Message-ID: <20260209174032.4142096-24-irogers@google.com> Subject: [PATCH v1 23/25] perf script: Don't pass evsel with sample From: Ian Rogers To: Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Namhyung Kim , Alexander Shishkin , Jiri Olsa , Ian Rogers , Adrian Hunter , James Clark , Paul Walmsley , Palmer Dabbelt , Albert Ou , Alexandre Ghiti , Leo Yan , Tianyou Li , Athira Rajeev , Derek Foreman , Thomas Falcon , Howard Chu , Dmitry Vyukov , Andi Kleen , tanze , Hrishikesh Suresh , Quan Zhou , Andrew Jones , Anup Patel , Dapeng Mi , "Dr. David Alan Gilbert" , "=?UTF-8?q?Krzysztof=20=C5=81opatowski?=" , Chun-Tse Shao , Ravi Bangoria , Swapnil Sapkal , Chen Ni , Blake Jones , Yujie Liu , linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" The sample contains the evsel and so it is unnecessary to pass the evsel as well. Remove the evsel from the struct scripting_context so that the sample version is always accessed. Signed-off-by: Ian Rogers --- tools/perf/builtin-script.c | 12 ++++-- .../util/scripting-engines/trace-event-perl.c | 21 +++++------ .../scripting-engines/trace-event-python.c | 37 ++++++++----------- tools/perf/util/trace-event-scripting.c | 5 +-- tools/perf/util/trace-event.h | 3 -- 5 files changed, 33 insertions(+), 45 deletions(-) diff --git a/tools/perf/builtin-script.c b/tools/perf/builtin-script.c index 7788a6934a8d..9f7d261b1291 100644 --- a/tools/perf/builtin-script.c +++ b/tools/perf/builtin-script.c @@ -2414,12 +2414,13 @@ static bool show_event(struct perf_sample *sample, } =20 static void process_event(struct perf_script *script, - struct perf_sample *sample, struct evsel *evsel, + struct perf_sample *sample, struct addr_location *al, struct addr_location *addr_al, struct machine *machine) { struct thread *thread =3D al->thread; + struct evsel *evsel =3D sample->evsel; struct perf_event_attr *attr =3D &evsel->core.attr; unsigned int type =3D evsel__output_type(evsel); struct evsel_script *es =3D evsel->priv; @@ -2710,9 +2711,9 @@ static int process_sample_event(const struct perf_too= l *tool, thread__resolve(al.thread, &addr_al, sample); addr_al_ptr =3D &addr_al; } - scripting_ops->process_event(event, sample, evsel, &al, addr_al_ptr); + scripting_ops->process_event(event, sample, &al, addr_al_ptr); } else { - process_event(scr, sample, evsel, &al, &addr_al, machine); + process_event(scr, sample, &al, &addr_al, machine); } =20 out_put: @@ -2888,9 +2889,12 @@ static int print_event_with_time(const struct perf_t= ool *tool, { struct perf_script *script =3D container_of(tool, struct perf_script, too= l); struct perf_session *session =3D script->session; - struct evsel *evsel =3D evlist__id2evsel(session->evlist, sample->id); + struct evsel *evsel =3D sample->evsel; struct thread *thread =3D NULL; =20 + if (!evsel) + evsel =3D evlist__id2evsel(session->evlist, sample->id); + if (evsel && !evsel->core.attr.sample_id_all) { sample->cpu =3D 0; sample->time =3D timestamp; diff --git a/tools/perf/util/scripting-engines/trace-event-perl.c b/tools/p= erf/util/scripting-engines/trace-event-perl.c index 850a0048df82..7a18ea4b7d50 100644 --- a/tools/perf/util/scripting-engines/trace-event-perl.c +++ b/tools/perf/util/scripting-engines/trace-event-perl.c @@ -257,7 +257,6 @@ static void define_event_symbols(struct tep_event *even= t, } =20 static SV *perl_process_callchain(struct perf_sample *sample, - struct evsel *evsel, struct addr_location *al) { struct callchain_cursor *cursor; @@ -340,7 +339,6 @@ static SV *perl_process_callchain(struct perf_sample *s= ample, } =20 static void perl_process_tracepoint(struct perf_sample *sample, - struct evsel *evsel, struct addr_location *al) { struct thread *thread =3D al->thread; @@ -355,6 +353,7 @@ static void perl_process_tracepoint(struct perf_sample = *sample, unsigned long long nsecs =3D sample->time; const char *comm =3D thread__comm_str(thread); DECLARE_BITMAP(events_defined, TRACE_EVENT_TYPE_MAX); + struct evsel *evsel =3D sample->evsel; =20 bitmap_zero(events_defined, TRACE_EVENT_TYPE_MAX); dSP; @@ -389,7 +388,7 @@ static void perl_process_tracepoint(struct perf_sample = *sample, XPUSHs(sv_2mortal(newSVuv(ns))); XPUSHs(sv_2mortal(newSViv(pid))); XPUSHs(sv_2mortal(newSVpv(comm, 0))); - XPUSHs(sv_2mortal(perl_process_callchain(sample, evsel, al))); + XPUSHs(sv_2mortal(perl_process_callchain(sample, al))); =20 /* common fields other than pid can be accessed via xsub fns */ =20 @@ -426,7 +425,7 @@ static void perl_process_tracepoint(struct perf_sample = *sample, XPUSHs(sv_2mortal(newSVuv(nsecs))); XPUSHs(sv_2mortal(newSViv(pid))); XPUSHs(sv_2mortal(newSVpv(comm, 0))); - XPUSHs(sv_2mortal(perl_process_callchain(sample, evsel, al))); + XPUSHs(sv_2mortal(perl_process_callchain(sample, al))); call_pv("main::trace_unhandled", G_SCALAR); } SPAGAIN; @@ -435,9 +434,7 @@ static void perl_process_tracepoint(struct perf_sample = *sample, LEAVE; } =20 -static void perl_process_event_generic(union perf_event *event, - struct perf_sample *sample, - struct evsel *evsel) +static void perl_process_event_generic(union perf_event *event, struct per= f_sample *sample) { dSP; =20 @@ -448,7 +445,8 @@ static void perl_process_event_generic(union perf_event= *event, SAVETMPS; PUSHMARK(SP); XPUSHs(sv_2mortal(newSVpvn((const char *)event, event->header.size))); - XPUSHs(sv_2mortal(newSVpvn((const char *)&evsel->core.attr, sizeof(evsel-= >core.attr)))); + XPUSHs(sv_2mortal(newSVpvn((const char *)&sample->evsel->core.attr, + sizeof(sample->evsel->core.attr)))); XPUSHs(sv_2mortal(newSVpvn((const char *)sample, sizeof(*sample)))); XPUSHs(sv_2mortal(newSVpvn((const char *)sample->raw_data, sample->raw_si= ze))); PUTBACK; @@ -461,13 +459,12 @@ static void perl_process_event_generic(union perf_eve= nt *event, =20 static void perl_process_event(union perf_event *event, struct perf_sample *sample, - struct evsel *evsel, struct addr_location *al, struct addr_location *addr_al) { - scripting_context__update(scripting_context, event, sample, evsel, al, ad= dr_al); - perl_process_tracepoint(sample, evsel, al); - perl_process_event_generic(event, sample, evsel); + scripting_context__update(scripting_context, event, sample, al, addr_al); + perl_process_tracepoint(sample, al); + perl_process_event_generic(event, sample); } =20 static void run_start_sub(void) diff --git a/tools/perf/util/scripting-engines/trace-event-python.c b/tools= /perf/util/scripting-engines/trace-event-python.c index 9f5c6e5e6ebe..63d04b051846 100644 --- a/tools/perf/util/scripting-engines/trace-event-python.c +++ b/tools/perf/util/scripting-engines/trace-event-python.c @@ -390,7 +390,6 @@ static unsigned long get_offset(struct symbol *sym, str= uct addr_location *al) } =20 static PyObject *python_process_callchain(struct perf_sample *sample, - struct evsel *evsel, struct addr_location *al) { PyObject *pylist; @@ -651,11 +650,9 @@ static PyObject *get_sample_value_as_tuple(struct samp= le_read_value *value, return t; } =20 -static void set_sample_read_in_dict(PyObject *dict_sample, - struct perf_sample *sample, - struct evsel *evsel) +static void set_sample_read_in_dict(PyObject *dict_sample, struct perf_sam= ple *sample) { - u64 read_format =3D evsel->core.attr.read_format; + u64 read_format =3D sample->evsel->core.attr.read_format; PyObject *values; unsigned int i; =20 @@ -741,11 +738,10 @@ static void regs_map(struct regs_dump *regs, uint64_t= mask, uint16_t e_machine, =20 static int set_regs_in_dict(PyObject *dict, struct perf_sample *sample, - struct evsel *evsel, uint16_t e_machine, uint32_t e_flags) { - struct perf_event_attr *attr =3D &evsel->core.attr; + struct perf_event_attr *attr =3D &sample->evsel->core.attr; =20 int size =3D (__sw_hweight64(attr->sample_regs_intr) * MAX_REG_SIZE) + 1; char *bf =3D NULL; @@ -831,7 +827,6 @@ static void python_process_sample_flags(struct perf_sam= ple *sample, PyObject *di } =20 static PyObject *get_perf_sample_dict(struct perf_sample *sample, - struct evsel *evsel, struct addr_location *al, struct addr_location *addr_al, PyObject *callchain) @@ -839,6 +834,7 @@ static PyObject *get_perf_sample_dict(struct perf_sampl= e *sample, PyObject *dict, *dict_sample, *brstack, *brstacksym; uint16_t e_machine =3D EM_HOST; uint32_t e_flags =3D EF_HOST; + struct evsel *evsel =3D sample->evsel; =20 dict =3D PyDict_New(); if (!dict) @@ -871,7 +867,7 @@ static PyObject *get_perf_sample_dict(struct perf_sampl= e *sample, PyLong_FromUnsignedLongLong(sample->phys_addr)); pydict_set_item_string_decref(dict_sample, "addr", PyLong_FromUnsignedLongLong(sample->addr)); - set_sample_read_in_dict(dict_sample, sample, evsel); + set_sample_read_in_dict(dict_sample, sample); pydict_set_item_string_decref(dict_sample, "weight", PyLong_FromUnsignedLongLong(sample->weight)); pydict_set_item_string_decref(dict_sample, "ins_lat", @@ -928,7 +924,7 @@ static PyObject *get_perf_sample_dict(struct perf_sampl= e *sample, if (al->thread) e_machine =3D thread__e_machine(al->thread, /*machine=3D*/NULL, &e_flags= ); =20 - if (set_regs_in_dict(dict, sample, evsel, e_machine, e_flags)) + if (set_regs_in_dict(dict, sample, e_machine, e_flags)) Py_FatalError("Failed to setting regs in dict"); =20 return dict; @@ -936,7 +932,6 @@ static PyObject *get_perf_sample_dict(struct perf_sampl= e *sample, =20 #ifdef HAVE_LIBTRACEEVENT static void python_process_tracepoint(struct perf_sample *sample, - struct evsel *evsel, struct addr_location *al, struct addr_location *addr_al) { @@ -954,6 +949,7 @@ static void python_process_tracepoint(struct perf_sampl= e *sample, const char *comm =3D thread__comm_str(al->thread); const char *default_handler_name =3D "trace_unhandled"; DECLARE_BITMAP(events_defined, TRACE_EVENT_TYPE_MAX); + struct evsel *evsel =3D sample->evsel; =20 bitmap_zero(events_defined, TRACE_EVENT_TYPE_MAX); =20 @@ -995,7 +991,7 @@ static void python_process_tracepoint(struct perf_sampl= e *sample, PyTuple_SetItem(t, n++, context); =20 /* ip unwinding */ - callchain =3D python_process_callchain(sample, evsel, al); + callchain =3D python_process_callchain(sample, al); /* Need an additional reference for the perf_sample dict */ Py_INCREF(callchain); =20 @@ -1051,7 +1047,7 @@ static void python_process_tracepoint(struct perf_sam= ple *sample, PyTuple_SetItem(t, n++, dict); =20 if (get_argument_count(handler) =3D=3D (int) n + 1) { - all_entries_dict =3D get_perf_sample_dict(sample, evsel, al, addr_al, + all_entries_dict =3D get_perf_sample_dict(sample, al, addr_al, callchain); PyTuple_SetItem(t, n++, all_entries_dict); } else { @@ -1070,7 +1066,6 @@ static void python_process_tracepoint(struct perf_sam= ple *sample, } #else static void python_process_tracepoint(struct perf_sample *sample __maybe_u= nused, - struct evsel *evsel __maybe_unused, struct addr_location *al __maybe_unused, struct addr_location *addr_al __maybe_unused) { @@ -1465,7 +1460,6 @@ static int python_process_call_return(struct call_ret= urn *cr, u64 *parent_db_id, } =20 static void python_process_general_event(struct perf_sample *sample, - struct evsel *evsel, struct addr_location *al, struct addr_location *addr_al) { @@ -1488,8 +1482,8 @@ static void python_process_general_event(struct perf_= sample *sample, Py_FatalError("couldn't create Python tuple"); =20 /* ip unwinding */ - callchain =3D python_process_callchain(sample, evsel, al); - dict =3D get_perf_sample_dict(sample, evsel, al, addr_al, callchain); + callchain =3D python_process_callchain(sample, al); + dict =3D get_perf_sample_dict(sample, al, addr_al, callchain); =20 PyTuple_SetItem(t, n++, dict); if (_PyTuple_Resize(&t, n) =3D=3D -1) @@ -1502,24 +1496,23 @@ static void python_process_general_event(struct per= f_sample *sample, =20 static void python_process_event(union perf_event *event, struct perf_sample *sample, - struct evsel *evsel, struct addr_location *al, struct addr_location *addr_al) { struct tables *tables =3D &tables_global; =20 - scripting_context__update(scripting_context, event, sample, evsel, al, ad= dr_al); + scripting_context__update(scripting_context, event, sample, al, addr_al); =20 - switch (evsel->core.attr.type) { + switch (sample->evsel->core.attr.type) { case PERF_TYPE_TRACEPOINT: - python_process_tracepoint(sample, evsel, al, addr_al); + python_process_tracepoint(sample, al, addr_al); break; /* Reserve for future process_hw/sw/raw APIs */ default: if (tables->db_export_mode) db_export__sample(&tables->dbe, event, sample, al, addr_al); else - python_process_general_event(sample, evsel, al, addr_al); + python_process_general_event(sample, al, addr_al); } } =20 diff --git a/tools/perf/util/trace-event-scripting.c b/tools/perf/util/trac= e-event-scripting.c index fa850e44cb46..dc584ac316a3 100644 --- a/tools/perf/util/trace-event-scripting.c +++ b/tools/perf/util/trace-event-scripting.c @@ -103,12 +103,11 @@ int script_spec__for_each(int (*cb)(struct scripting_= ops *ops, const char *spec) void scripting_context__update(struct scripting_context *c, union perf_event *event, struct perf_sample *sample, - struct evsel *evsel, struct addr_location *al, struct addr_location *addr_al) { #ifdef HAVE_LIBTRACEEVENT - const struct tep_event *tp_format =3D evsel__tp_format(evsel); + const struct tep_event *tp_format =3D evsel__tp_format(sample->evsel); =20 c->pevent =3D tp_format ? tp_format->tep : NULL; #else @@ -117,7 +116,6 @@ void scripting_context__update(struct scripting_context= *c, c->event_data =3D sample->raw_data; c->event =3D event; c->sample =3D sample; - c->evsel =3D evsel; c->al =3D al; c->addr_al =3D addr_al; } @@ -134,7 +132,6 @@ static int stop_script_unsupported(void) =20 static void process_event_unsupported(union perf_event *event __maybe_unus= ed, struct perf_sample *sample __maybe_unused, - struct evsel *evsel __maybe_unused, struct addr_location *al __maybe_unused, struct addr_location *addr_al __maybe_unused) { diff --git a/tools/perf/util/trace-event.h b/tools/perf/util/trace-event.h index 914d9b69ed62..720121c74f1d 100644 --- a/tools/perf/util/trace-event.h +++ b/tools/perf/util/trace-event.h @@ -94,7 +94,6 @@ struct scripting_ops { int (*stop_script) (void); void (*process_event) (union perf_event *event, struct perf_sample *sample, - struct evsel *evsel, struct addr_location *al, struct addr_location *addr_al); void (*process_switch)(union perf_event *event, @@ -124,7 +123,6 @@ struct scripting_context { void *event_data; union perf_event *event; struct perf_sample *sample; - struct evsel *evsel; struct addr_location *al; struct addr_location *addr_al; struct perf_session *session; @@ -133,7 +131,6 @@ struct scripting_context { void scripting_context__update(struct scripting_context *scripting_context, union perf_event *event, struct perf_sample *sample, - struct evsel *evsel, struct addr_location *al, struct addr_location *addr_al); =20 --=20 2.53.0.239.g8d8fc8a987-goog