diff mbox series

[2/8] tools/lib/traceevent: Add counter to track parsing failures

Message ID 20190326154328.28718-3-tstoyanov@vmware.com (mailing list archive)
State Rejected
Headers show
Series Cleanup traceevent API and make it more consistent | expand

Commit Message

Tzvetomir Stoyanov March 26, 2019, 3:43 p.m. UTC
This patch adds a parsing failures counter to struct tep_handle. The counter can
be used to track failures on parsing event format files. It is updated
automatically by tep_parse_event(), when failure is detected. The patch also
adds two new APIs for accessing the counter:
 tep_get_parsing_failures() - returns the current value of the counter.
 tep_clear_parsing_failures() - clears the counter.

Signed-off-by: Tzvetomir Stoyanov <tstoyanov@vmware.com>
---
 tools/lib/traceevent/event-parse-api.c   | 27 ++++++++++++++++++++++++
 tools/lib/traceevent/event-parse-local.h |  2 ++
 tools/lib/traceevent/event-parse.c       |  8 ++++++-
 tools/lib/traceevent/event-parse.h       |  2 ++
 4 files changed, 38 insertions(+), 1 deletion(-)

Comments

Steven Rostedt March 26, 2019, 7:48 p.m. UTC | #1
On Tue, 26 Mar 2019 17:43:22 +0200
Tzvetomir Stoyanov <tstoyanov@vmware.com> wrote:

> This patch adds a parsing failures counter to struct tep_handle. The counter can
> be used to track failures on parsing event format files. It is updated
> automatically by tep_parse_event(), when failure is detected. The patch also
> adds two new APIs for accessing the counter:
>  tep_get_parsing_failures() - returns the current value of the counter.
>  tep_clear_parsing_failures() - clears the counter.
> 

I think we can do the same thing here as we did test_filters.

I don't think we really need to put this into the tep interface. Let's
see if we can move this into trace-cmd itself and have it just keep
track of when parsing failed.

I mean, trace-cmd is just using the tep structure as place to store
this variable.

-- Steve
diff mbox series

Patch

diff --git a/tools/lib/traceevent/event-parse-api.c b/tools/lib/traceevent/event-parse-api.c
index 46670bb87051..1fe284b1fac8 100644
--- a/tools/lib/traceevent/event-parse-api.c
+++ b/tools/lib/traceevent/event-parse-api.c
@@ -371,3 +371,30 @@  void tep_set_test_filters(struct tep_handle *tep, int test_filters)
 	if (tep)
 		tep->test_filters = test_filters;
 }
+
+/**
+ * tep_get_parsing_failures - get the count of parsing failures
+ * @tep: a handle to a tep_handle
+ *
+ * Every time when tep_parse_event() fails to parse an event format file,
+ * a parsing failure is registered. This returns the parsing failures count.
+ */
+int tep_get_parsing_failures(struct tep_handle *tep)
+{
+	if (tep)
+		return tep->parsing_failures;
+	return 0;
+}
+
+/**
+ * tep_clear_parsing_failures - clear parsing failures count
+ * @tep: a handle to a tep_handle
+ *
+ * Every time when tep_parse_event() fails to parse an event format file,
+ * a parsing failure is registered. This clears the parsing failures counter.
+ */
+void tep_clear_parsing_failures(struct tep_handle *tep)
+{
+	if (tep)
+		tep->parsing_failures = 0;
+}
diff --git a/tools/lib/traceevent/event-parse-local.h b/tools/lib/traceevent/event-parse-local.h
index 35833ee32d6c..c5c8eb4c4ab7 100644
--- a/tools/lib/traceevent/event-parse-local.h
+++ b/tools/lib/traceevent/event-parse-local.h
@@ -83,6 +83,8 @@  struct tep_handle {
 	struct event_handler *handlers;
 	struct tep_function_handler *func_handlers;
 
+	int parsing_failures;
+
 	/* cache */
 	struct tep_event *last_event;
 
diff --git a/tools/lib/traceevent/event-parse.c b/tools/lib/traceevent/event-parse.c
index f309b6d7e08a..4144c4e20e4e 100644
--- a/tools/lib/traceevent/event-parse.c
+++ b/tools/lib/traceevent/event-parse.c
@@ -6230,7 +6230,13 @@  enum tep_errno tep_parse_event(struct tep_handle *pevent, const char *buf,
 			       unsigned long size, const char *sys)
 {
 	struct tep_event *event = NULL;
-	return __parse_event(pevent, &event, buf, size, sys);
+	enum tep_errno ret;
+
+	ret = __parse_event(pevent, &event, buf, size, sys);
+	if (ret != TEP_ERRNO__SUCCESS)
+		pevent->parsing_failures++;
+
+	return ret;
 }
 
 int get_field_val(struct trace_seq *s, struct tep_format_field *field,
diff --git a/tools/lib/traceevent/event-parse.h b/tools/lib/traceevent/event-parse.h
index f3b822736d87..dcf0385684b8 100644
--- a/tools/lib/traceevent/event-parse.h
+++ b/tools/lib/traceevent/event-parse.h
@@ -464,6 +464,8 @@  enum tep_errno tep_parse_format(struct tep_handle *pevent,
 				struct tep_event **eventp,
 				const char *buf,
 				unsigned long size, const char *sys);
+int tep_get_parsing_failures(struct tep_handle *tep);
+void tep_clear_parsing_failures(struct tep_handle *tep);
 
 void *tep_get_field_raw(struct trace_seq *s, struct tep_event *event,
 			const char *name, struct tep_record *record,