All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v3 0/4] trace-cmd list: Include ftrace in event listings
@ 2021-05-06 16:51 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
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: Steven Rostedt @ 2021-05-06 16:51 UTC (permalink / raw)
  To: linux-trace-devel; +Cc: Steven Rostedt (VMware)

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

I'm constantly needing to look at the event formats of ftrace events
(like the function event or print event), but trace-cmd list does not
include them, as they can not be enabled by trace-cmd record/start.

By default, trace-cmd list -e, wont show ftrace events, but if a regex
is added to the search: trace-cmd list -e print, then it will now list
those events in ftrace. This is useful for:

 # trace-cmd list -e ftrace:function -F
system: ftrace
name: function
ID: 1
format:
        field:unsigned short common_type;       offset:0;       size:2; signed:0;
        field:unsigned char common_flags;       offset:2;       size:1; signed:0;
        field:unsigned char common_preempt_count;       offset:3;       size:1; signed:0;
        field:int common_pid;   offset:4;       size:4; signed:1;

        field:unsigned long ip; offset:8;       size:8; signed:0;
        field:unsigned long parent_ip;  offset:16;      size:8; signed:0;

Changes since v2:

 - Fixed cover letter subject and body, as v2 referenced listing of options?
   https://lore.kernel.org/linux-trace-devel/20210422211803.862397-1-rostedt@goodmis.org/

 - Broke up patch: https://lore.kernel.org/linux-trace-devel/20210422211803.862397-4-rostedt@goodmis.org/
   To separate out the adding of the helper function "match_system_events()"
   from the functional change of listing ftrace events.

 - The diff of this patch set compared to v2 is the same (no functional changes).


Steven Rostedt (VMware) (4):
  trace-cmd list: Add --full to show print fmt of an event
  trace-cmd list: Use tracefs to help find events for -e
  trace-cmd list: Add match_system_events() helper function
  trace-cmd list: Add ftrace events to listing of events

 Documentation/trace-cmd/trace-cmd-list.1.txt |   5 +-
 tracecmd/trace-list.c                        | 179 +++++++++++++++++--
 tracecmd/trace-usage.c                       |   1 +
 3 files changed, 168 insertions(+), 17 deletions(-)

-- 
2.29.2


^ permalink raw reply	[flat|nested] 5+ messages in thread

* [PATCH v3 1/4] trace-cmd list: Add --full to show print fmt of an event
  2021-05-06 16:51 [PATCH v3 0/4] trace-cmd list: Include ftrace in event listings Steven Rostedt
@ 2021-05-06 16:52 ` Steven Rostedt
  2021-05-06 16:52 ` [PATCH v3 2/4] trace-cmd list: Use tracefs to help find events for -e Steven Rostedt
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 5+ messages in thread
From: Steven Rostedt @ 2021-05-06 16:52 UTC (permalink / raw)
  To: linux-trace-devel; +Cc: Steven Rostedt (VMware)

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

There's several times I want to see the print fmt from the event's format
file, and there's no way to do that with trace-cmd list -e. Add a --full
option to display the entire format file of an event, including the print
fmt, which can be useful as well.

Signed-off-by: Steven Rostedt (VMware) <rostedt@goodmis.org>
---
 Documentation/trace-cmd/trace-cmd-list.1.txt |  5 ++-
 tracecmd/trace-list.c                        | 37 ++++++++++++--------
 tracecmd/trace-usage.c                       |  1 +
 3 files changed, 27 insertions(+), 16 deletions(-)

diff --git a/Documentation/trace-cmd/trace-cmd-list.1.txt b/Documentation/trace-cmd/trace-cmd-list.1.txt
index 0ad62643..a5c6b16c 100644
--- a/Documentation/trace-cmd/trace-cmd-list.1.txt
+++ b/Documentation/trace-cmd/trace-cmd-list.1.txt
@@ -26,7 +26,10 @@ OPTIONS
     trace-cmd list -e '^sys.*'
 
 *-F*::
-    Used with *-e* 'regex' to show those events formats.
+    Used with *-e* 'regex' to show the fields of the event.
+
+*--full*::
+    Used with *-F* which will show the "print fmt" of the event along with the fields.
 
 *-l*::
     Used with *-e* 'regex' to show those events filters.
diff --git a/tracecmd/trace-list.c b/tracecmd/trace-list.c
index 63216b43..fb62b754 100644
--- a/tracecmd/trace-list.c
+++ b/tracecmd/trace-list.c
@@ -44,6 +44,7 @@ enum {
 	SHOW_EVENT_FORMAT		= 1 << 0,
 	SHOW_EVENT_FILTER		= 1 << 1,
 	SHOW_EVENT_TRIGGER		= 1 << 2,
+	SHOW_EVENT_FULL			= 1 << 3,
 };
 
 
@@ -56,10 +57,10 @@ void show_file(const char *name)
 	tracefs_put_tracing_file(path);
 }
 
-typedef int (*process_file_func)(char *buf, int len);
+typedef int (*process_file_func)(char *buf, int len, int flags);
 
 static void process_file_re(process_file_func func,
-			    const char *name, const char *re)
+			    const char *name, const char *re, int flags)
 {
 	regex_t reg;
 	char *path;
@@ -97,7 +98,7 @@ static void process_file_re(process_file_func func,
 	do {
 		n = getline(&buf, &l, fp);
 		if (n > 0 && regexec(&reg, buf, 0, NULL, 0) == 0)
-			func(buf, n);
+			func(buf, n, flags);
 	} while (n > 0);
 	free(buf);
 	fclose(fp);
@@ -105,14 +106,14 @@ static void process_file_re(process_file_func func,
 	regfree(&reg);
 }
 
-static int show_file_write(char *buf, int len)
+static int show_file_write(char *buf, int len, int flags)
 {
 	return fwrite(buf, 1, len, stdout);
 }
 
 static void show_file_re(const char *name, const char *re)
 {
-	process_file_re(show_file_write, name, re);
+	process_file_re(show_file_write, name, re, 0);
 }
 
 static char *get_event_file(const char *type, char *buf, int len)
@@ -144,7 +145,7 @@ static char *get_event_file(const char *type, char *buf, int len)
 	return file;
 }
 
-static int event_filter_write(char *buf, int len)
+static int event_filter_write(char *buf, int len, int flags)
 {
 	char *file;
 
@@ -161,7 +162,7 @@ static int event_filter_write(char *buf, int len)
 	return 0;
 }
 
-static int event_trigger_write(char *buf, int len)
+static int event_trigger_write(char *buf, int len, int flags)
 {
 	char *file;
 
@@ -178,14 +179,17 @@ static int event_trigger_write(char *buf, int len)
 	return 0;
 }
 
-static int event_format_write(char *fbuf, int len)
+static int event_format_write(char *fbuf, int len, int flags)
 {
 	char *file = get_event_file("format", fbuf, len);
 	char *buf = NULL;
 	size_t l;
 	FILE *fp;
+	bool full;
 	int n;
 
+	full = flags & SHOW_EVENT_FULL;
+
 	/* The get_event_file() crops system in fbuf */
 	printf("system: %s\n", fbuf);
 
@@ -198,7 +202,7 @@ static int event_format_write(char *fbuf, int len)
 	do {
 		n = getline(&buf, &l, fp);
 		if (n > 0) {
-			if (strncmp(buf, "print fmt", 9) == 0)
+			if (!full && strncmp(buf, "print fmt", 9) == 0)
 				break;
 			fwrite(buf, 1, n, stdout);
 		}
@@ -213,19 +217,19 @@ static int event_format_write(char *fbuf, int len)
 
 static void show_event_filter_re(const char *re)
 {
-	process_file_re(event_filter_write, "available_events", re);
+	process_file_re(event_filter_write, "available_events", re, 0);
 }
 
 
 static void show_event_trigger_re(const char *re)
 {
-	process_file_re(event_trigger_write, "available_events", re);
+	process_file_re(event_trigger_write, "available_events", re, 0);
 }
 
 
-static void show_event_format_re(const char *re)
+static void show_event_format_re(const char *re, int flags)
 {
-	process_file_re(event_format_write, "available_events", re);
+	process_file_re(event_format_write, "available_events", re, flags);
 }
 
 
@@ -236,7 +240,7 @@ static void show_events(const char *eventre, int flags)
 
 	if (eventre) {
 		if (flags & SHOW_EVENT_FORMAT)
-			show_event_format_re(eventre);
+			show_event_format_re(eventre, flags);
 
 		else if (flags & SHOW_EVENT_FILTER)
 			show_event_filter_re(eventre);
@@ -405,7 +409,6 @@ static void show_plugins(void)
 	tep_free(pevent);
 }
 
-
 void trace_list(int argc, char **argv)
 {
 	int events = 0;
@@ -488,6 +491,10 @@ void trace_list(int argc, char **argv)
 					tracecmd_set_debug(true);
 					break;
 				}
+				if (strcmp(argv[i], "--full") == 0) {
+					flags |= SHOW_EVENT_FULL;
+					break;
+				}
 				fprintf(stderr, "list: invalid option -- '%s'\n",
 					argv[i]);
 			default:
diff --git a/tracecmd/trace-usage.c b/tracecmd/trace-usage.c
index 98247074..7b0d01d8 100644
--- a/tracecmd/trace-usage.c
+++ b/tracecmd/trace-usage.c
@@ -319,6 +319,7 @@ static struct usage_help usage_help[] = {
 		" %s list [-e [regex]][-t][-o][-f [regex]]\n"
 		"          -e list available events\n"
 		"            -F show event format\n"
+		"            --full show the print fmt with -F\n"
 		"            -R show event triggers\n"
 		"            -l show event filters\n"
 		"          -t list available tracers\n"
-- 
2.29.2


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [PATCH v3 2/4] trace-cmd list: Use tracefs to help find events for -e
  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 ` Steven Rostedt
  2021-05-06 16:52 ` [PATCH v3 3/4] trace-cmd list: Add match_system_events() helper function Steven Rostedt
  2021-05-06 16:52 ` [PATCH v3 4/4] trace-cmd list: Add ftrace events to listing of events Steven Rostedt
  3 siblings, 0 replies; 5+ messages in thread
From: Steven Rostedt @ 2021-05-06 16:52 UTC (permalink / raw)
  To: linux-trace-devel; +Cc: Steven Rostedt (VMware)

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

When the user specifies -e and wants to search for events, use the tracefs
helper functions tracefs_event_systems() and tracefs_system_events() to
find the matching events.

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

diff --git a/tracecmd/trace-list.c b/tracecmd/trace-list.c
index fb62b754..a0d743fb 100644
--- a/tracecmd/trace-list.c
+++ b/tracecmd/trace-list.c
@@ -106,6 +106,123 @@ static void process_file_re(process_file_func func,
 	regfree(&reg);
 }
 
+static void show_event(process_file_func func, const char *system,
+		       const char *event, int flags)
+{
+	char *buf;
+	int ret;
+
+	ret = asprintf(&buf, "%s:%s", system, event);
+	if (ret < 0)
+		die("Can not allocate event");
+	func(buf, strlen(buf), flags);
+	free(buf);
+}
+
+static void show_system(process_file_func func, const char *system, int flags)
+{
+	char **events;
+	int e;
+
+	events = tracefs_system_events(NULL, system);
+	if (!events) /* die? */
+		return;
+
+	for (e = 0; events[e]; e++)
+		show_event(func, system, events[e], flags);
+}
+
+static void show_event_systems(process_file_func func, char **systems, int flags)
+{
+	int s;
+
+	for (s = 0; systems[s]; s++)
+		show_system(func, systems[s], flags);
+}
+
+
+static void process_events(process_file_func func, const char *re, int flags)
+{
+	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;
+
+	systems = tracefs_event_systems(NULL);
+	if (!systems)
+		return process_file_re(func, "available_events", re, flags);
+
+	if (!re || l == 0) {
+		show_event_systems(func, systems, flags);
+		return;
+	}
+
+	str = strdup(re);
+	if (!str)
+		die("Can not allocate momory for regex");
+
+	system = strtok(str, ":");
+	event = strtok(NULL, "");
+
+	if (regcomp(&system_reg, system, REG_ICASE|REG_NOSUB))
+		die("invalid regex '%s'", system);
+
+	if (event) {
+		if (regcomp(&event_reg, event, REG_ICASE|REG_NOSUB))
+			die("invalid regex '%s'", event);
+	} else {
+		/*
+		 * If the regex ends with ":", then event would be null,
+		 * but we do not want to match events.
+		 */
+		if (re[l-1] != ':')
+			just_systems = false;
+	}
+	free(str);
+
+	for (s = 0; systems[s]; s++) {
+
+		if (regexec(&system_reg, systems[s], 0, NULL, 0) == 0) {
+			if (!event) {
+				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);
+			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);
+	}
+	tracefs_list_free(systems);
+
+	regfree(&system_reg);
+	if (event)
+		regfree(&event_reg);
+}
+
 static int show_file_write(char *buf, int len, int flags)
 {
 	return fwrite(buf, 1, len, stdout);
@@ -214,24 +331,34 @@ static int event_format_write(char *fbuf, int len, int flags)
 	return 0;
 }
 
+static int event_name(char *buf, int len, int flags)
+{
+	printf("%s\n", buf);
+
+	return 0;
+}
 
 static void show_event_filter_re(const char *re)
 {
-	process_file_re(event_filter_write, "available_events", re, 0);
+	process_events(event_filter_write, re, 0);
 }
 
 
 static void show_event_trigger_re(const char *re)
 {
-	process_file_re(event_trigger_write, "available_events", re, 0);
+	process_events(event_trigger_write, re, 0);
 }
 
 
 static void show_event_format_re(const char *re, int flags)
 {
-	process_file_re(event_format_write, "available_events", re, flags);
+	process_events(event_format_write, re, flags);
 }
 
+static void show_event_names_re(const char *re)
+{
+	process_events(event_name, re, 0);
+}
 
 static void show_events(const char *eventre, int flags)
 {
@@ -248,7 +375,7 @@ static void show_events(const char *eventre, int flags)
 		else if (flags & SHOW_EVENT_TRIGGER)
 			show_event_trigger_re(eventre);
 		else
-			show_file_re("available_events", eventre);
+			show_event_names_re(eventre);
 	} else
 		show_file("available_events");
 }
-- 
2.29.2


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [PATCH v3 3/4] trace-cmd list: Add match_system_events() helper function
  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
  2021-05-06 16:52 ` [PATCH v3 4/4] trace-cmd list: Add ftrace events to listing of events Steven Rostedt
  3 siblings, 0 replies; 5+ messages in thread
From: Steven Rostedt @ 2021-05-06 16:52 UTC (permalink / raw)
  To: linux-trace-devel; +Cc: Steven Rostedt (VMware)

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


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [PATCH v3 4/4] trace-cmd list: Add ftrace events to listing of events
  2021-05-06 16:51 [PATCH v3 0/4] trace-cmd list: Include ftrace in event listings Steven Rostedt
                   ` (2 preceding siblings ...)
  2021-05-06 16:52 ` [PATCH v3 3/4] trace-cmd list: Add match_system_events() helper function Steven Rostedt
@ 2021-05-06 16:52 ` Steven Rostedt
  3 siblings, 0 replies; 5+ messages in thread
From: Steven Rostedt @ 2021-05-06 16:52 UTC (permalink / raw)
  To: linux-trace-devel; +Cc: Steven Rostedt (VMware)

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

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@goodmis.org>
---
 tracecmd/trace-list.c | 14 ++++++++++++++
 1 file changed, 14 insertions(+)

diff --git a/tracecmd/trace-list.c b/tracecmd/trace-list.c
index 1b32af17..d060c810 100644
--- a/tracecmd/trace-list.c
+++ b/tracecmd/trace-list.c
@@ -158,6 +158,7 @@ static void match_system_events(process_file_func func, const char *system,
 
 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;
@@ -200,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) {
-- 
2.29.2


^ permalink raw reply related	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2021-05-06 16:52 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
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 ` [PATCH v3 3/4] trace-cmd list: Add match_system_events() helper function Steven Rostedt
2021-05-06 16:52 ` [PATCH v3 4/4] trace-cmd list: Add ftrace events to listing of events Steven Rostedt

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.