[PATCH 2/8] tools/lib/traceevent: Add counter to track parsing failures
From: Tzvetomir Stoyanov
Date: Tue Mar 26 2019 - 11:43:38 EST
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@xxxxxxxxxx>
---
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(-)
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,
--
2.20.1