From: "Steven Rostedt (VMware)" <rostedt@xxxxxxxxxxx> If a search of events is done with trace-cmd list -e, check if any matches the ftrace events. This is useful to get the fields and print fmt of the events under the ftrace system. Note, just "trace-cmd list -e" will still not list ftrace events by default. Signed-off-by: Steven Rostedt (VMware) <rostedt@xxxxxxxxxxx> --- tracecmd/trace-list.c | 51 +++++++++++++++++++++++++++---------------- 1 file changed, 32 insertions(+), 19 deletions(-) diff --git a/tracecmd/trace-list.c b/tracecmd/trace-list.c index 3e9e2713..048a7e5d 100644 --- a/tracecmd/trace-list.c +++ b/tracecmd/trace-list.c @@ -140,19 +140,34 @@ static void show_event_systems(process_file_func func, char **systems, int flags show_system(func, systems[s], flags); } +static void match_system_events(process_file_func func, const char *system, + regex_t *reg, int flags) +{ + char **events; + int e; + + events = tracefs_system_events(NULL, system); + if (!events) /* die? */ + return; + for (e = 0; events[e]; e++) { + if (regexec(reg, events[e], 0, NULL, 0) == 0) + show_event(func, system, events[e], flags); + } + tracefs_list_free(events); +} static void process_events(process_file_func func, const char *re, int flags) { + const char *ftrace = "ftrace"; regex_t system_reg; regex_t event_reg; char *str; size_t l = strlen(re); bool just_systems = true; char **systems; - char **events; char *system; char *event; - int s, e; + int s; systems = tracefs_event_systems(NULL); if (!systems) @@ -186,6 +201,19 @@ static void process_events(process_file_func func, const char *re, int flags) } free(str); + /* + * See if this matches the special ftrace system, as ftrace is not included + * in the systems list, but can get events from tracefs_system_events(). + */ + if (regexec(&system_reg, ftrace, 0, NULL, 0) == 0) { + if (!event) + show_system(func, ftrace, flags); + else + match_system_events(func, ftrace, &event_reg, flags); + } else if (!just_systems) { + match_system_events(func, ftrace, &system_reg, flags); + } + for (s = 0; systems[s]; s++) { if (regexec(&system_reg, systems[s], 0, NULL, 0) == 0) { @@ -193,28 +221,13 @@ static void process_events(process_file_func func, const char *re, int flags) show_system(func, systems[s], flags); continue; } - events = tracefs_system_events(NULL, systems[s]); - if (!events) /* die? */ - continue; - for (e = 0; events[e]; e++) { - if (regexec(&event_reg, events[e], 0, NULL, 0) == 0) - show_event(func, systems[s], events[e], flags); - } - tracefs_list_free(events); + match_system_events(func, systems[s], &event_reg, flags); continue; } if (just_systems) continue; - events = tracefs_system_events(NULL, systems[s]); - if (!events) /* die? */ - continue; - - for (e = 0; events[e]; e++) { - if (regexec(&system_reg, events[e], 0, NULL, 0) == 0) - show_event(func, systems[s], events[e], flags); - } - tracefs_list_free(events); + match_system_events(func, systems[s], &system_reg, flags); } tracefs_list_free(systems); -- 2.29.2