From nobody Fri Nov 22 01:08:57 2024 Received: from mail-yw1-f201.google.com (mail-yw1-f201.google.com [209.85.128.201]) (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 322CB1EE001 for ; Mon, 18 Nov 2024 22:54:40 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731970482; cv=none; b=n5fv7q28/6+m+Y919xIFUKks+tiVnRjw5nuxdZab9TN22Js3JZsHr4TkcrP7PFA2AxYMoamVuJlp7mHIEUz9JxGr3Rj49cSdRn7WkBJlUBp1YnYU+zFlncSEBky/Jyrsg8VTJXfRs5pCZk4jz1bS7cqHwW0nICUDNLuL6zeZv0Q= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731970482; c=relaxed/simple; bh=mGhk140QZdt4j9l9JIQDlAq6kmxP1h7Khw8epzrTtQw=; h=Date:In-Reply-To:Message-Id:Mime-Version:References:Subject:From: To:Content-Type; b=WsDL6XtdsPfX15o/9DhbYJw6C/86nHP/8NXvCN6gmobPFwMmqzDL6QchOPkrIe84qbra+Y/CC57psGvPi0TacAxFH24nnWrPfRBUz/IL0J/kVntHZa4m+vRzeEsryc0j48+IYez+tY84hOqbuDDG1jvfZ9FiXHlNr6nZPP8hneU= 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=vOPGoslK; arc=none smtp.client-ip=209.85.128.201 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="vOPGoslK" Received: by mail-yw1-f201.google.com with SMTP id 00721157ae682-6ea863ecfe9so7296717b3.3 for ; Mon, 18 Nov 2024 14:54:40 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1731970479; x=1732575279; darn=vger.kernel.org; h=to:from:subject:references:mime-version:message-id:in-reply-to:date :from:to:cc:subject:date:message-id:reply-to; bh=TDhvCMX7JOKls9vxeiCGPEnafFSjBkepNjN/DQ23IUs=; b=vOPGoslKVhq3QVW83F8Esyxq8hjv/QPZddolFf7LaQEMPLGaTn+1lrDw0qjXXtg+XP 2SEoLp6+daGwvwYmd8+7T5VDy7SFB/ju2ajEKux1TjYBgW7Hws/nZ2i5tDsf2p/XrfSV aHMCBfySwgtIiXkrYMKRGC3XJ5xkOTQEhTKvVy5WALbuAGzzyjPLY8SPbCT7Yasw0HOb l9udUzKgScx9ZYFANWx2zxwsGy0OWUxel1vfw0UMsfLtUVumDg8s9C/um754YvfcVQYc FWoiVvMIf3KW1F9j9WLI/cLz1vtzO/floZlqgbBvqQTKblXcHYWy7a16JiPbHPHmM3w1 e6sg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1731970479; x=1732575279; 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=TDhvCMX7JOKls9vxeiCGPEnafFSjBkepNjN/DQ23IUs=; b=dphL63ga/dPad3Enp//b370pBpTtAVPR+Arx20Qhq74eVNSlgT9KeZQPZSQLAT+2Xg lLkpckv/It8n+Ag2o+7H0RNLTS+0/zqodbZF/a9Hcs1vS4HvmVgOqWth5d1XqH6bCjSz oNxtM6aZk/xiWqjiTwNvbMgfzIF447WVq39+0s/BqTm1rf6eboM+MXWvs+jVqi6Boe3s RWxilBl4Qs4OreGiFZGmkTOJl7eO+sy77edJUWuiuGRP8jJUjxt3YHO+JSDh2XMt2Pef /eoqumEbeKllj2t+Mn0MgCVWIL4KAJ5fCY4TQD9uLZ15TE6Nezec8zsULbsiH3YbQNPl vAhQ== X-Forwarded-Encrypted: i=1; AJvYcCWvhxVqtbvVO3OeQg4ZctJQCmUQhPpa2QoaHhvIoQDIxHbIF+l/XuThzXcKbquNzNvRXr4v322vaPjx1tU=@vger.kernel.org X-Gm-Message-State: AOJu0Yz0mooLMWsGRSwZej5DScilNNVpymPvnY8HRsuSwRUfu1HkXGlO D58rduk1AOHfx6UgEiqWak8X6t9Bcl4yuym/FxZO82JbmtMz9Zu1pjjlOYI1tn+FZOIZTE7vOOv 5P/yrOg== X-Google-Smtp-Source: AGHT+IHdKY4PrQ3sjQRomCGzWEZYw36OZj62aQVWdr+T9sfmCulxuAmnlhvC+HMtegX2oDG2yXdzlBscn8PN X-Received: from irogers.svl.corp.google.com ([2620:15c:2c5:11:22a4:ded5:5c37:fcc7]) (user=irogers job=sendgmr) by 2002:a05:690c:528f:b0:6e2:1b8c:39bf with SMTP id 00721157ae682-6ee55a3e3afmr472107b3.2.1731970479221; Mon, 18 Nov 2024 14:54:39 -0800 (PST) Date: Mon, 18 Nov 2024 14:53:43 -0800 In-Reply-To: <20241118225345.889810-1-irogers@google.com> Message-Id: <20241118225345.889810-6-irogers@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20241118225345.889810-1-irogers@google.com> X-Mailer: git-send-email 2.47.0.338.g60cca15819-goog Subject: [PATCH v5 5/7] perf evsel: Add/use accessor for tp_format 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 , Athira Jajeev , James Clark , Dominique Martinet , Yang Li , Colin Ian King , Yang Jihong , "Steinar H. Gunderson" , Oliver Upton , Ilkka Koskinen , Ze Gao , Weilin Wang , Ben Gainey , zhaimingbing , Zixian Cai , Andi Kleen , Paran Lee , Thomas Falcon , linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org, "Steven Rostedt (Google)" Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Add an accessor function for tp_format. Rather than search+replace uses try to use a variable and reuse it. Add additional NULL checks when accessing/using the value. Make sure the PTR_ERR is nulled out on error path in evsel__newtp_idx. Signed-off-by: Ian Rogers --- tools/perf/builtin-kmem.c | 12 +-- tools/perf/builtin-kwork.c | 3 +- tools/perf/builtin-script.c | 9 ++- tools/perf/builtin-trace.c | 79 +++++++++++++------ tools/perf/util/data-convert-bt.c | 10 ++- tools/perf/util/data-convert-json.c | 8 +- tools/perf/util/evsel.c | 9 ++- tools/perf/util/evsel.h | 5 ++ tools/perf/util/evsel_fprintf.c | 4 +- .../util/scripting-engines/trace-event-perl.c | 3 +- .../scripting-engines/trace-event-python.c | 3 +- tools/perf/util/sort.c | 33 +++++--- tools/perf/util/trace-event-scripting.c | 10 ++- 13 files changed, 128 insertions(+), 60 deletions(-) diff --git a/tools/perf/builtin-kmem.c b/tools/perf/builtin-kmem.c index 4d8d94146f8d..67fb1946ef13 100644 --- a/tools/perf/builtin-kmem.c +++ b/tools/perf/builtin-kmem.c @@ -761,6 +761,7 @@ static int parse_gfp_flags(struct evsel *evsel, struct = perf_sample *sample, }; struct trace_seq seq; char *str, *pos =3D NULL; + const struct tep_event *tp_format; =20 if (nr_gfps) { struct gfp_flag key =3D { @@ -772,8 +773,9 @@ static int parse_gfp_flags(struct evsel *evsel, struct = perf_sample *sample, } =20 trace_seq_init(&seq); - tep_print_event(evsel->tp_format->tep, - &seq, &record, "%s", TEP_PRINT_INFO); + tp_format =3D evsel__tp_format(evsel); + if (tp_format) + tep_print_event(tp_format->tep, &seq, &record, "%s", TEP_PRINT_INFO); =20 str =3D strtok_r(seq.buffer, " ", &pos); while (str) { @@ -2012,13 +2014,13 @@ int cmd_kmem(int argc, const char **argv) =20 if (kmem_page) { struct evsel *evsel =3D evlist__find_tracepoint_by_name(session->evlist,= "kmem:mm_page_alloc"); + const struct tep_event *tp_format =3D evsel ? evsel__tp_format(evsel) : = NULL; =20 - if (evsel =3D=3D NULL) { + if (tp_format =3D=3D NULL) { pr_err(errmsg, "page", "page"); goto out_delete; } - - kmem_page_size =3D tep_get_page_size(evsel->tp_format->tep); + kmem_page_size =3D tep_get_page_size(tp_format->tep); symbol_conf.use_callchain =3D true; } =20 diff --git a/tools/perf/builtin-kwork.c b/tools/perf/builtin-kwork.c index 8234410cba4c..4eaa6cf5a775 100644 --- a/tools/perf/builtin-kwork.c +++ b/tools/perf/builtin-kwork.c @@ -1103,7 +1103,8 @@ static char *evsel__softirq_name(struct evsel *evsel,= u64 num) char *name =3D NULL; bool found =3D false; struct tep_print_flag_sym *sym =3D NULL; - struct tep_print_arg *args =3D evsel->tp_format->print_fmt.args; + const struct tep_event *tp_format =3D evsel__tp_format(evsel); + struct tep_print_arg *args =3D tp_format ? tp_format->print_fmt.args : NU= LL; =20 if ((args =3D=3D NULL) || (args->next =3D=3D NULL)) return NULL; diff --git a/tools/perf/builtin-script.c b/tools/perf/builtin-script.c index 9e47905f75a6..aad607b8918f 100644 --- a/tools/perf/builtin-script.c +++ b/tools/perf/builtin-script.c @@ -2289,8 +2289,13 @@ static void process_event(struct perf_script *script, } #ifdef HAVE_LIBTRACEEVENT if (PRINT_FIELD(TRACE) && sample->raw_data) { - event_format__fprintf(evsel->tp_format, sample->cpu, - sample->raw_data, sample->raw_size, fp); + const struct tep_event *tp_format =3D evsel__tp_format(evsel); + + if (tp_format) { + event_format__fprintf(tp_format, sample->cpu, + sample->raw_data, sample->raw_size, + fp); + } } #endif if (attr->type =3D=3D PERF_TYPE_SYNTH && PRINT_FIELD(SYNTH)) diff --git a/tools/perf/builtin-trace.c b/tools/perf/builtin-trace.c index 6a1a128fe645..3c46de1a8d79 100644 --- a/tools/perf/builtin-trace.c +++ b/tools/perf/builtin-trace.c @@ -389,7 +389,12 @@ static struct syscall_arg_fmt *evsel__syscall_arg_fmt(= struct evsel *evsel) } =20 if (et->fmt =3D=3D NULL) { - et->fmt =3D calloc(evsel->tp_format->format.nr_fields, sizeof(struct sys= call_arg_fmt)); + const struct tep_event *tp_format =3D evsel__tp_format(evsel); + + if (tp_format =3D=3D NULL) + goto out_delete; + + et->fmt =3D calloc(tp_format->format.nr_fields, sizeof(struct syscall_ar= g_fmt)); if (et->fmt =3D=3D NULL) goto out_delete; } @@ -2154,8 +2159,12 @@ static int evsel__init_tp_arg_scnprintf(struct evsel= *evsel, bool *use_btf) struct syscall_arg_fmt *fmt =3D evsel__syscall_arg_fmt(evsel); =20 if (fmt !=3D NULL) { - syscall_arg_fmt__init_array(fmt, evsel->tp_format->format.fields, use_bt= f); - return 0; + const struct tep_event *tp_format =3D evsel__tp_format(evsel); + + if (tp_format) { + syscall_arg_fmt__init_array(fmt, tp_format->format.fields, use_btf); + return 0; + } } =20 return -ENOMEM; @@ -3027,7 +3036,8 @@ static size_t trace__fprintf_tp_fields(struct trace *= trace, struct evsel *evsel, { char bf[2048]; size_t size =3D sizeof(bf); - struct tep_format_field *field =3D evsel->tp_format->format.fields; + const struct tep_event *tp_format =3D evsel__tp_format(evsel); + struct tep_format_field *field =3D tp_format ? tp_format->format.fields := NULL; struct syscall_arg_fmt *arg =3D __evsel__syscall_arg_fmt(evsel); size_t printed =3D 0, btf_printed; unsigned long val; @@ -3145,11 +3155,13 @@ static int trace__event_handler(struct trace *trace= , struct evsel *evsel, =20 if (evsel__is_bpf_output(evsel)) { bpf_output__fprintf(trace, sample); - } else if (evsel->tp_format) { - if (strncmp(evsel->tp_format->name, "sys_enter_", 10) || - trace__fprintf_sys_enter(trace, evsel, sample)) { + } else { + const struct tep_event *tp_format =3D evsel__tp_format(evsel); + + if (tp_format && (strncmp(tp_format->name, "sys_enter_", 10) || + trace__fprintf_sys_enter(trace, evsel, sample))) { if (trace->libtraceevent_print) { - event_format__fprintf(evsel->tp_format, sample->cpu, + event_format__fprintf(tp_format, sample->cpu, sample->raw_data, sample->raw_size, trace->output); } else { @@ -4077,17 +4089,23 @@ static int ordered_events__deliver_event(struct ord= ered_events *oe, static struct syscall_arg_fmt *evsel__find_syscall_arg_fmt_by_name(struct = evsel *evsel, char *arg, char **type) { - struct tep_format_field *field; struct syscall_arg_fmt *fmt =3D __evsel__syscall_arg_fmt(evsel); + const struct tep_event *tp_format; + + if (!fmt) + return NULL; =20 - if (evsel->tp_format =3D=3D NULL || fmt =3D=3D NULL) + tp_format =3D evsel__tp_format(evsel); + if (!tp_format) return NULL; =20 - for (field =3D evsel->tp_format->format.fields; field; field =3D field->n= ext, ++fmt) + for (const struct tep_format_field *field =3D tp_format->format.fields; f= ield; + field =3D field->next, ++fmt) { if (strcmp(field->name, arg) =3D=3D 0) { *type =3D field->type; return fmt; } + } =20 return NULL; } @@ -4843,13 +4861,18 @@ static void evsel__set_syscall_arg_fmt(struct evsel= *evsel, const char *name) const struct syscall_fmt *scfmt =3D syscall_fmt__find(name); =20 if (scfmt) { - int skip =3D 0; + const struct tep_event *tp_format =3D evsel__tp_format(evsel); + + if (tp_format) { + int skip =3D 0; =20 - if (strcmp(evsel->tp_format->format.fields->name, "__syscall_nr") =3D= =3D 0 || - strcmp(evsel->tp_format->format.fields->name, "nr") =3D=3D 0) - ++skip; + if (strcmp(tp_format->format.fields->name, "__syscall_nr") =3D=3D 0 || + strcmp(tp_format->format.fields->name, "nr") =3D=3D 0) + ++skip; =20 - memcpy(fmt + skip, scfmt->arg, (evsel->tp_format->format.nr_fields - sk= ip) * sizeof(*fmt)); + memcpy(fmt + skip, scfmt->arg, + (tp_format->format.nr_fields - skip) * sizeof(*fmt)); + } } } } @@ -4859,10 +4882,16 @@ static int evlist__set_syscall_tp_fields(struct evl= ist *evlist, bool *use_btf) struct evsel *evsel; =20 evlist__for_each_entry(evlist, evsel) { - if (evsel->priv || !evsel->tp_format) + const struct tep_event *tp_format; + + if (evsel->priv) + continue; + + tp_format =3D evsel__tp_format(evsel); + if (!tp_format) continue; =20 - if (strcmp(evsel->tp_format->system, "syscalls")) { + if (strcmp(tp_format->system, "syscalls")) { evsel__init_tp_arg_scnprintf(evsel, use_btf); continue; } @@ -4870,20 +4899,24 @@ static int evlist__set_syscall_tp_fields(struct evl= ist *evlist, bool *use_btf) if (evsel__init_syscall_tp(evsel)) return -1; =20 - if (!strncmp(evsel->tp_format->name, "sys_enter_", 10)) { + if (!strncmp(tp_format->name, "sys_enter_", 10)) { struct syscall_tp *sc =3D __evsel__syscall_tp(evsel); =20 if (__tp_field__init_ptr(&sc->args, sc->id.offset + sizeof(u64))) return -1; =20 - evsel__set_syscall_arg_fmt(evsel, evsel->tp_format->name + sizeof("sys_= enter_") - 1); - } else if (!strncmp(evsel->tp_format->name, "sys_exit_", 9)) { + evsel__set_syscall_arg_fmt(evsel, + tp_format->name + sizeof("sys_enter_") - 1); + } else if (!strncmp(tp_format->name, "sys_exit_", 9)) { struct syscall_tp *sc =3D __evsel__syscall_tp(evsel); =20 - if (__tp_field__init_uint(&sc->ret, sizeof(u64), sc->id.offset + sizeof= (u64), evsel->needs_swap)) + if (__tp_field__init_uint(&sc->ret, sizeof(u64), + sc->id.offset + sizeof(u64), + evsel->needs_swap)) return -1; =20 - evsel__set_syscall_arg_fmt(evsel, evsel->tp_format->name + sizeof("sys_= exit_") - 1); + evsel__set_syscall_arg_fmt(evsel, + tp_format->name + sizeof("sys_exit_") - 1); } } =20 diff --git a/tools/perf/util/data-convert-bt.c b/tools/perf/util/data-conve= rt-bt.c index f0599c61fab4..5e7ff09fbc95 100644 --- a/tools/perf/util/data-convert-bt.c +++ b/tools/perf/util/data-convert-bt.c @@ -426,8 +426,9 @@ static int add_tracepoint_values(struct ctf_writer *cw, struct evsel *evsel, struct perf_sample *sample) { - struct tep_format_field *common_fields =3D evsel->tp_format->format.commo= n_fields; - struct tep_format_field *fields =3D evsel->tp_format->format.field= s; + const struct tep_event *tp_format =3D evsel__tp_format(evsel); + struct tep_format_field *common_fields =3D tp_format->format.common_field= s; + struct tep_format_field *fields =3D tp_format->format.fields; int ret; =20 ret =3D add_tracepoint_fields_values(cw, event_class, event, @@ -1064,8 +1065,9 @@ static int add_tracepoint_types(struct ctf_writer *cw, struct evsel *evsel, struct bt_ctf_event_class *class) { - struct tep_format_field *common_fields =3D evsel->tp_format->format.commo= n_fields; - struct tep_format_field *fields =3D evsel->tp_format->format.field= s; + const struct tep_event *tp_format =3D evsel__tp_format(evsel); + struct tep_format_field *common_fields =3D tp_format ? tp_format->format.= common_fields : NULL; + struct tep_format_field *fields =3D tp_format ? tp_format->format.= fields : NULL; int ret; =20 ret =3D add_tracepoint_fields_types(cw, common_fields, class); diff --git a/tools/perf/util/data-convert-json.c b/tools/perf/util/data-con= vert-json.c index 8304cd2d4a9c..d9f805bf6fb0 100644 --- a/tools/perf/util/data-convert-json.c +++ b/tools/perf/util/data-convert-json.c @@ -230,12 +230,12 @@ static int process_sample_event(const struct perf_too= l *tool, =20 #ifdef HAVE_LIBTRACEEVENT if (sample->raw_data) { - int i; - struct tep_format_field **fields; + struct tep_event *tp_format =3D evsel__tp_format(evsel); + struct tep_format_field **fields =3D tp_format ? tep_event_fields(tp_for= mat) : NULL; =20 - fields =3D tep_event_fields(evsel->tp_format); if (fields) { - i =3D 0; + int i =3D 0; + while (fields[i]) { struct trace_seq s; =20 diff --git a/tools/perf/util/evsel.c b/tools/perf/util/evsel.c index f745723d486b..4759d644a5aa 100644 --- a/tools/perf/util/evsel.c +++ b/tools/perf/util/evsel.c @@ -571,6 +571,7 @@ struct evsel *evsel__newtp_idx(const char *sys, const c= har *name, int idx, bool evsel->tp_format =3D trace_event__tp_format(sys, name); if (IS_ERR(evsel->tp_format)) { err =3D PTR_ERR(evsel->tp_format); + evsel->tp_format =3D NULL; goto out_free; } attr.config =3D evsel->tp_format->id; @@ -3218,12 +3219,16 @@ u16 evsel__id_hdr_size(const struct evsel *evsel) #ifdef HAVE_LIBTRACEEVENT struct tep_format_field *evsel__field(struct evsel *evsel, const char *nam= e) { - return tep_find_field(evsel->tp_format, name); + struct tep_event *tp_format =3D evsel__tp_format(evsel); + + return tp_format ? tep_find_field(tp_format, name) : NULL; } =20 struct tep_format_field *evsel__common_field(struct evsel *evsel, const ch= ar *name) { - return tep_find_common_field(evsel->tp_format, name); + struct tep_event *tp_format =3D evsel__tp_format(evsel); + + return tp_format ? tep_find_common_field(tp_format, name) : NULL; } =20 void *evsel__rawptr(struct evsel *evsel, struct perf_sample *sample, const= char *name) diff --git a/tools/perf/util/evsel.h b/tools/perf/util/evsel.h index 04934a7af174..c3e53d320bf5 100644 --- a/tools/perf/util/evsel.h +++ b/tools/perf/util/evsel.h @@ -257,6 +257,11 @@ static inline struct evsel *evsel__newtp(const char *s= ys, const char *name) { return evsel__newtp_idx(sys, name, 0, true); } + +static inline struct tep_event *evsel__tp_format(struct evsel *evsel) +{ + return evsel->tp_format; +} #endif =20 #ifdef HAVE_LIBTRACEEVENT diff --git a/tools/perf/util/evsel_fprintf.c b/tools/perf/util/evsel_fprint= f.c index 86b7f46f9e2a..103984b29b1e 100644 --- a/tools/perf/util/evsel_fprintf.c +++ b/tools/perf/util/evsel_fprintf.c @@ -81,13 +81,15 @@ int evsel__fprintf(struct evsel *evsel, struct perf_att= r_details *details, FILE #ifdef HAVE_LIBTRACEEVENT if (details->trace_fields) { struct tep_format_field *field; + const struct tep_event *tp_format; =20 if (evsel->core.attr.type !=3D PERF_TYPE_TRACEPOINT) { printed +=3D comma_fprintf(fp, &first, " (not a tracepoint)"); goto out; } =20 - field =3D evsel->tp_format->format.fields; + tp_format =3D evsel__tp_format(evsel); + field =3D tp_format ? tp_format->format.fields : NULL; if (field =3D=3D NULL) { printed +=3D comma_fprintf(fp, &first, " (no trace field)"); goto out; diff --git a/tools/perf/util/scripting-engines/trace-event-perl.c b/tools/p= erf/util/scripting-engines/trace-event-perl.c index 85b7f188f729..e261a57b87d4 100644 --- a/tools/perf/util/scripting-engines/trace-event-perl.c +++ b/tools/perf/util/scripting-engines/trace-event-perl.c @@ -344,7 +344,7 @@ static void perl_process_tracepoint(struct perf_sample = *sample, struct addr_location *al) { struct thread *thread =3D al->thread; - struct tep_event *event =3D evsel->tp_format; + struct tep_event *event; struct tep_format_field *field; static char handler[256]; unsigned long long val; @@ -362,6 +362,7 @@ static void perl_process_tracepoint(struct perf_sample = *sample, if (evsel->core.attr.type !=3D PERF_TYPE_TRACEPOINT) return; =20 + event =3D evsel__tp_format(evsel); if (!event) { pr_debug("ug! no event found for type %" PRIu64, (u64)evsel->core.attr.c= onfig); return; diff --git a/tools/perf/util/scripting-engines/trace-event-python.c b/tools= /perf/util/scripting-engines/trace-event-python.c index 8bdae066e839..231233639b5d 100644 --- a/tools/perf/util/scripting-engines/trace-event-python.c +++ b/tools/perf/util/scripting-engines/trace-event-python.c @@ -949,7 +949,7 @@ static void python_process_tracepoint(struct perf_sampl= e *sample, struct addr_location *al, struct addr_location *addr_al) { - struct tep_event *event =3D evsel->tp_format; + struct tep_event *event; PyObject *handler, *context, *t, *obj =3D NULL, *callchain; PyObject *dict =3D NULL, *all_entries_dict =3D NULL; static char handler_name[256]; @@ -966,6 +966,7 @@ static void python_process_tracepoint(struct perf_sampl= e *sample, =20 bitmap_zero(events_defined, TRACE_EVENT_TYPE_MAX); =20 + event =3D evsel__tp_format(evsel); if (!event) { snprintf(handler_name, sizeof(handler_name), "ug! no event found for type %" PRIu64, (u64)evsel->core.attr.config); diff --git a/tools/perf/util/sort.c b/tools/perf/util/sort.c index 9dd60c7869a2..3dd33721823f 100644 --- a/tools/perf/util/sort.c +++ b/tools/perf/util/sort.c @@ -1038,17 +1038,19 @@ static char *get_trace_output(struct hist_entry *he) .data =3D he->raw_data, .size =3D he->raw_size, }; + struct tep_event *tp_format; =20 evsel =3D hists_to_evsel(he->hists); =20 trace_seq_init(&seq); - if (symbol_conf.raw_trace) { - tep_print_fields(&seq, he->raw_data, he->raw_size, - evsel->tp_format); - } else { - tep_print_event(evsel->tp_format->tep, - &seq, &rec, "%s", TEP_PRINT_INFO); + tp_format =3D evsel__tp_format(evsel); + if (tp_format) { + if (symbol_conf.raw_trace) + tep_print_fields(&seq, he->raw_data, he->raw_size, tp_format); + else + tep_print_event(tp_format->tep, &seq, &rec, "%s", TEP_PRINT_INFO); } + /* * Trim the buffer, it starts at 4KB and we're not going to * add anything more to this buffer. @@ -3293,9 +3295,8 @@ static int __dynamic_dimension__add(struct evsel *evs= el, static int add_evsel_fields(struct evsel *evsel, bool raw_trace, int level) { int ret; - struct tep_format_field *field; - - field =3D evsel->tp_format->format.fields; + struct tep_event *tp_format =3D evsel__tp_format(evsel); + struct tep_format_field *field =3D tp_format ? tp_format->format.fields := NULL; while (field) { ret =3D __dynamic_dimension__add(evsel, field, raw_trace, level); if (ret < 0) @@ -3328,13 +3329,19 @@ static int add_all_matching_fields(struct evlist *e= vlist, { int ret =3D -ESRCH; struct evsel *evsel; - struct tep_format_field *field; =20 evlist__for_each_entry(evlist, evsel) { + struct tep_event *tp_format; + struct tep_format_field *field; + if (evsel->core.attr.type !=3D PERF_TYPE_TRACEPOINT) continue; =20 - field =3D tep_find_any_field(evsel->tp_format, field_name); + tp_format =3D evsel__tp_format(evsel); + if (tp_format =3D=3D NULL) + continue; + + field =3D tep_find_any_field(tp_format, field_name); if (field =3D=3D NULL) continue; =20 @@ -3416,7 +3423,9 @@ static int add_dynamic_entry(struct evlist *evlist, c= onst char *tok, if (!strcmp(field_name, "*")) { ret =3D add_evsel_fields(evsel, raw_trace, level); } else { - struct tep_format_field *field =3D tep_find_any_field(evsel->tp_format, = field_name); + struct tep_event *tp_format =3D evsel__tp_format(evsel); + struct tep_format_field *field =3D + tp_format ? tep_find_any_field(tp_format, field_name) : NULL; =20 if (field =3D=3D NULL) { pr_debug("Cannot find event field for %s.%s\n", diff --git a/tools/perf/util/trace-event-scripting.c b/tools/perf/util/trac= e-event-scripting.c index 5596fcda2c10..edfde7056c99 100644 --- a/tools/perf/util/trace-event-scripting.c +++ b/tools/perf/util/trace-event-scripting.c @@ -28,12 +28,14 @@ void scripting_context__update(struct scripting_context= *c, struct addr_location *al, struct addr_location *addr_al) { - c->event_data =3D sample->raw_data; - c->pevent =3D NULL; #ifdef HAVE_LIBTRACEEVENT - if (evsel->tp_format) - c->pevent =3D evsel->tp_format->tep; + const struct tep_event *tp_format =3D evsel__tp_format(evsel); + + c->pevent =3D tp_format ? tp_format->tep : NULL; +#else + c->pevent =3D NULL; #endif + c->event_data =3D sample->raw_data; c->event =3D event; c->sample =3D sample; c->evsel =3D evsel; --=20 2.47.0.338.g60cca15819-goog