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 <irogers@google.com>
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
This commit is contained in:
Ian Rogers 2026-09-17 23:32:46 -07:00 committed by Arnaldo Carvalho de Melo
parent e223a41c42
commit d9eba1d5b5

View File

@ -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);