All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 1/4] trace-cmd: Add parse error checking target
@ 2011-07-16  3:00 Vaibhav Nagarnaik
  2011-07-16  3:00 ` [PATCH 2/4] trace-cmd: Handle invalid opcode parsing gracefully Vaibhav Nagarnaik
                   ` (4 more replies)
  0 siblings, 5 replies; 20+ messages in thread
From: Vaibhav Nagarnaik @ 2011-07-16  3:00 UTC (permalink / raw)
  To: Steven Rostedt
  Cc: Michael Rubin, David Sharp, linux-kernel, Vaibhav Nagarnaik

Add another target 'check-events' which parses all the event formats and
returns whether there are any issues with the print format strings.

With an error in the format, the return value is 22 (EINVAL) and for
success, it is 0.

Signed-off-by: Vaibhav Nagarnaik <vnagarnaik@google.com>
---
 trace-capture.c |    2 +-
 trace-cmd.c     |   22 ++++++++++++++++++++++
 trace-cmd.h     |    2 +-
 trace-usage.c   |    5 +++++
 trace-util.c    |   48 ++++++++++++++++++++++++++++++++----------------
 5 files changed, 61 insertions(+), 18 deletions(-)

diff --git a/trace-capture.c b/trace-capture.c
index 61ff165..5708945 100644
--- a/trace-capture.c
+++ b/trace-capture.c
@@ -1295,7 +1295,7 @@ static void tracing_dialog(struct shark_info *info, const char *tracing)
 	/* Send parse warnings to status display */
 	trace_dialog_register_alt_warning(vpr_stat);
 
-	pevent = tracecmd_local_events(tracing);
+	tracecmd_local_events(tracing, &pevent);
 	trace_dialog_register_alt_warning(NULL);
 
 	cap.pevent = pevent;
diff --git a/trace-cmd.c b/trace-cmd.c
index bff5bbf..a2b6b91 100644
--- a/trace-cmd.c
+++ b/trace-cmd.c
@@ -158,6 +158,28 @@ int main (int argc, char **argv)
 	} else if (strcmp(argv[1], "stack") == 0) {
 		trace_stack(argc, argv);
 		exit(0);
+	} else if (strcmp(argv[1], "check-events") == 0) {
+		char *tracing;
+		int ret;
+		struct pevent *pevent = NULL;
+
+		tracing = tracecmd_find_tracing_dir();
+
+		if (!tracing) {
+			printf("Can not find or mount tracing directory!\n"
+				"Either tracing is not configured for this "
+				"kernel\n"
+				"or you do not have the proper permissions to "
+				"mount the directory");
+			exit(EINVAL);
+		}
+
+		ret = tracecmd_local_events(tracing, &pevent);
+		if (pevent)
+			pevent_free(pevent);
+
+		ret ? exit(0) : exit(EINVAL);
+
 	} else if (strcmp(argv[1], "record") == 0 ||
 		   strcmp(argv[1], "start") == 0 ||
 		   strcmp(argv[1], "extract") == 0 ||
diff --git a/trace-cmd.h b/trace-cmd.h
index f436845..6aa4744 100644
--- a/trace-cmd.h
+++ b/trace-cmd.h
@@ -37,7 +37,7 @@ void tracecmd_unload_plugins(struct plugin_list *list);
 
 char **tracecmd_event_systems(const char *tracing_dir);
 char **tracecmd_system_events(const char *tracing_dir, const char *system);
-struct pevent *tracecmd_local_events(const char *tracing_dir);
+int tracecmd_local_events(const char *tracing_dir, struct pevent **event);
 char **tracecmd_local_plugins(const char *tracing_dir);
 
 char **tracecmd_add_list(char **list, const char *name, int len);
diff --git a/trace-usage.c b/trace-usage.c
index 39c8fc1..58ef167 100644
--- a/trace-usage.c
+++ b/trace-usage.c
@@ -150,6 +150,11 @@ static struct usage_help usage_help[] = {
 		"          --reset  reset the maximum stack found\n"
 	},
 	{
+		"check-events",
+		"parse trace event formats",
+		" %s check-format\n"
+	},
+	{
 		NULL, NULL, NULL
 	}
 };
diff --git a/trace-util.c b/trace-util.c
index 674f37e..91ec5a7 100644
--- a/trace-util.c
+++ b/trace-util.c
@@ -621,22 +621,22 @@ static int read_file(const char *file, char **buffer)
 	return len;
 }
 
-static void load_events(struct pevent *pevent, const char *system,
+static int load_events(struct pevent *pevent, const char *system,
 			const char *sys_dir)
 {
 	struct dirent *dent;
 	struct stat st;
 	DIR *dir;
 	int len = 0;
-	int ret;
+	int ret = 0, failure = 0;
 
 	ret = stat(sys_dir, &st);
 	if (ret < 0 || !S_ISDIR(st.st_mode))
-		return;
+		return EINVAL;
 
 	dir = opendir(sys_dir);
 	if (!dir)
-		return;
+		return errno;
 
 	while ((dent = readdir(dir))) {
 		const char *name = dent->d_name;
@@ -662,15 +662,18 @@ static void load_events(struct pevent *pevent, const char *system,
 		if (len < 0)
 			goto free_format;
 
-		pevent_parse_event(pevent, buf, len, system);
+		ret = pevent_parse_event(pevent, buf, len, system);
 		free(buf);
  free_format:
 		free(format);
  free_event:
 		free(event);
+		if (ret)
+			failure = ret;
 	}
 
 	closedir(dir);
+	return failure;
 }
 
 static int read_header(struct pevent *pevent, const char *events_dir)
@@ -704,42 +707,50 @@ static int read_header(struct pevent *pevent, const char *events_dir)
 /**
  * tracecmd_local_events - create a pevent from the events on system
  * @tracing_dir: The directory that contains the events.
+ * @event: The pointer where the list of parsed events will be returned
  *
- * Returns a pevent structure that contains the pevents local to
- * the system.
+ * Returns an int indicating if the parsing was without any errors. Success is
+ * 1.
  */
-struct pevent *tracecmd_local_events(const char *tracing_dir)
+int tracecmd_local_events(const char *tracing_dir, struct pevent **event)
 {
 	struct pevent *pevent = NULL;
 	struct dirent *dent;
 	char *events_dir;
 	struct stat st;
 	DIR *dir;
-	int ret;
+	int ret, failure = 0;
 
 	if (!tracing_dir)
-		return NULL;
+		return 0;
 
 	events_dir = append_file(tracing_dir, "events");
 	if (!events_dir)
-		return NULL;
+		return 0;
 
 	ret = stat(events_dir, &st);
-	if (ret < 0 || !S_ISDIR(st.st_mode))
+	if (ret < 0 || !S_ISDIR(st.st_mode)) {
+		failure = 1;
 		goto out_free;
+	}
 
 	dir = opendir(events_dir);
-	if (!dir)
+	if (!dir) {
+		failure = 1;
 		goto out_free;
+	}
 
 	pevent = pevent_alloc();
-	if (!pevent)
+	if (!pevent) {
+		failure = 1;
 		goto out_free;
+	}
 
 	ret = read_header(pevent, events_dir);
 	if (ret < 0) {
 		pevent_free(pevent);
 		pevent = NULL;
+		failure = 1;
 		goto out_free;
 	}
 
@@ -758,9 +769,12 @@ struct pevent *tracecmd_local_events(const char *tracing_dir)
 			continue;
 		}
 
-		load_events(pevent, name, sys);
+		ret = load_events(pevent, name, sys);
 
 		free(sys);
+
+		if (ret)
+			failure = 1;
 	}
 
 	closedir(dir);
@@ -768,7 +782,9 @@ struct pevent *tracecmd_local_events(const char *tracing_dir)
  out_free:
 	free(events_dir);
 
-	return pevent;
+	*event = pevent;
+
+	return !failure;
 }
 
 /**
-- 
1.7.3.1


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

end of thread, other threads:[~2012-05-21  9:42 UTC | newest]

Thread overview: 20+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-07-16  3:00 [PATCH 1/4] trace-cmd: Add parse error checking target Vaibhav Nagarnaik
2011-07-16  3:00 ` [PATCH 2/4] trace-cmd: Handle invalid opcode parsing gracefully Vaibhav Nagarnaik
2011-07-25 14:03   ` Steven Rostedt
2012-05-21  9:39   ` [tip:perf/core] parse-events: " tip-bot for Vaibhav Nagarnaik
2011-07-16  3:00 ` [PATCH 3/4] trace-cmd: Handle opcode parsing error Vaibhav Nagarnaik
2011-07-25 14:01   ` Steven Rostedt
2011-07-25 18:06     ` Vaibhav Nagarnaik
2011-07-25 18:40   ` Vaibhav Nagarnaik
2012-05-21  9:39     ` [tip:perf/core] parse-events: " tip-bot for Vaibhav Nagarnaik
2011-07-16  3:00 ` [PATCH 4/4] trace-cmd: Support '+' opcode in print format Vaibhav Nagarnaik
2011-07-25 14:02   ` Steven Rostedt
2012-05-21  9:41   ` [tip:perf/core] parse-events: " tip-bot for Vaibhav Nagarnaik
2011-07-25 13:32 ` [PATCH 1/4] trace-cmd: Add parse error checking target Steven Rostedt
2011-07-25 18:06   ` Vaibhav Nagarnaik
2011-07-25 18:39 ` [PATCH v2 " Vaibhav Nagarnaik
2011-07-29 14:19   ` Steven Rostedt
2011-07-29 17:41     ` Vaibhav Nagarnaik
2011-07-29 17:53       ` Steven Rostedt
2011-07-29 19:07         ` Vaibhav Nagarnaik
2011-07-30  1:33           ` 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.