From d9eba1d5b56e8a62158aa797d45e4e988aa60844 Mon Sep 17 00:00:00 2001 From: Ian Rogers Date: Thu, 17 Sep 2026 23:32:46 -0700 Subject: [PATCH] perf trace-event: Reuse an already parsed tracepoint format tp_format() read and parsed the format file on every call. Each parse registers another tep_event with the global tep handle, and libtraceevent has no way to free an individual event, only the whole handle, so a repeated lookup of the same tracepoint both redoes the work of reading and parsing the file and leaves a duplicate behind for the rest of the session. Ask the handle for the event first with tep_find_event_by_name() and only fall back to reading the format file when it has not been parsed yet. The handle holds formats for the running kernel alone, so a name that is found is the same format that would have been read. Assisted-by: Antigravity:gemini-3.1-pro Signed-off-by: Ian Rogers Signed-off-by: Arnaldo Carvalho de Melo --- tools/perf/util/trace-event.c | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/tools/perf/util/trace-event.c b/tools/perf/util/trace-event.c index 10a7652f0305..826f75464171 100644 --- a/tools/perf/util/trace-event.c +++ b/tools/perf/util/trace-event.c @@ -81,14 +81,25 @@ void trace_event__cleanup(struct trace_event *t) static struct tep_event* tp_format(const char *sys, const char *name) { - char *tp_dir = get_events_file(sys); struct tep_handle *pevent = tevent.pevent; - struct tep_event *event = NULL; + struct tep_event *event; + char *tp_dir; char path[PATH_MAX]; size_t size; char *data; int err; + /* + * Each parse adds an event to the tep handle that can only be freed + * by freeing the whole handle, so re-reading a format file both + * repeats the work and grows the handle with a duplicate. Reuse the + * event if it was already parsed. + */ + event = tep_find_event_by_name(pevent, sys, name); + if (event) + return event; + + tp_dir = get_events_file(sys); if (!tp_dir) { errno = ENOMEM; return NULL; @@ -103,6 +114,7 @@ tp_format(const char *sys, const char *name) return NULL; } + event = NULL; err = tep_parse_format(pevent, &event, data, size, sys); free(data);