linux-trace-devel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Steven Rostedt <rostedt@goodmis.org>
To: <linux-trace-devel@vger.kernel.org>
Cc: "Steven Rostedt (VMware)" <rostedt@goodmis.org>
Subject: [PATCH v3 3/4] trace-cmd list: Add match_system_events() helper function
Date: Thu, 6 May 2021 12:52:02 -0400	[thread overview]
Message-ID: <20210506165203.3889058-4-rostedt@goodmis.org> (raw)
In-Reply-To: <20210506165203.3889058-1-rostedt@goodmis.org>

From: "Steven Rostedt (VMware)" <rostedt@goodmis.org>

Remove the duplicate code that matches all events for a given system and
replace it with a helper function called match_system_events().

Signed-off-by: Steven Rostedt (VMware) <rostedt@goodmis.org>
---
 tracecmd/trace-list.c | 37 ++++++++++++++++++-------------------
 1 file changed, 18 insertions(+), 19 deletions(-)

diff --git a/tracecmd/trace-list.c b/tracecmd/trace-list.c
index a0d743fb..1b32af17 100644
--- a/tracecmd/trace-list.c
+++ b/tracecmd/trace-list.c
@@ -140,6 +140,21 @@ 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)
 {
@@ -149,10 +164,9 @@ static void process_events(process_file_func func, const char *re, int flags)
 	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)
@@ -193,28 +207,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


  parent reply	other threads:[~2021-05-06 16:52 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-05-06 16:51 [PATCH v3 0/4] trace-cmd list: Include ftrace in event listings Steven Rostedt
2021-05-06 16:52 ` [PATCH v3 1/4] trace-cmd list: Add --full to show print fmt of an event Steven Rostedt
2021-05-06 16:52 ` [PATCH v3 2/4] trace-cmd list: Use tracefs to help find events for -e Steven Rostedt
2021-05-06 16:52 ` Steven Rostedt [this message]
2021-05-06 16:52 ` [PATCH v3 4/4] trace-cmd list: Add ftrace events to listing of events Steven Rostedt

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20210506165203.3889058-4-rostedt@goodmis.org \
    --to=rostedt@goodmis.org \
    --cc=linux-trace-devel@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).