diff mbox series

[1/4] kernel-shark: kshark_import_event_filter() tolerates non-existing events

Message ID 20190724154039.23705-2-y.karadz@gmail.com (mailing list archive)
State Accepted
Commit 1e40b00ebc3eb013d6259c261792054792779b31
Headers show
Series Fixes for Capture needed befor KS 1.0 | expand

Commit Message

Yordan Karadzhov July 24, 2019, 3:40 p.m. UTC
Instead of aborting, the function will ignore (skip) the non-existing
event and will continue loading the other events in the configuration
file. The return type is changed to int in order to provide information
about the number of events successfully added to the filter.

Signed-off-by: Yordan Karadzhov (VMware) <y.karadz@gmail.com>
---
 kernel-shark/src/libkshark-configio.c | 33 +++++++++++++++------------
 kernel-shark/src/libkshark.h          |  8 +++----
 2 files changed, 23 insertions(+), 18 deletions(-)
diff mbox series

Patch

diff --git a/kernel-shark/src/libkshark-configio.c b/kernel-shark/src/libkshark-configio.c
index cac27a7..5d7323f 100644
--- a/kernel-shark/src/libkshark-configio.c
+++ b/kernel-shark/src/libkshark-configio.c
@@ -793,7 +793,7 @@  bool kshark_export_event_filter(struct tep_handle *pevent,
 	}
 }
 
-static bool kshark_event_filter_from_json(struct tep_handle *pevent,
+static int kshark_event_filter_from_json(struct tep_handle *pevent,
 					  struct tracecmd_filter_id *filter,
 					  const char *filter_name,
 					  struct json_object *jobj)
@@ -801,7 +801,7 @@  static bool kshark_event_filter_from_json(struct tep_handle *pevent,
 	json_object *jfilter, *jevent, *jsystem, *jname;
 	const char *system_str, *name_str;
 	struct tep_event *event;
-	int i, length;
+	int i, length, count = 0;
 
 	/*
 	 * Use the name of the filter to find the array of events associated
@@ -809,7 +809,7 @@  static bool kshark_event_filter_from_json(struct tep_handle *pevent,
 	 * contain no data for this particular filter.
 	 */
 	if (!json_object_object_get_ex(jobj, filter_name, &jfilter))
-		return false;
+		return 0;
 
 	if (!kshark_json_type_check(jobj, "kshark.config.filter") ||
 	    json_object_get_type(jfilter) != json_type_array)
@@ -829,16 +829,21 @@  static bool kshark_event_filter_from_json(struct tep_handle *pevent,
 
 		event = tep_find_event_by_name(pevent, system_str, name_str);
 		if (!event)
-			goto fail;
+			continue;
 
 		tracecmd_filter_id_add(filter, event->id);
+		++count;
 	}
 
-	return true;
+	if (count != length)
+		count = -count;
+
+	return count;
 
  fail:
 	fprintf(stderr, "Failed to load event filter from json_object.\n");
-	return false;
+	tracecmd_filter_id_clear(filter);
+	return 0;
 }
 
 /**
@@ -851,14 +856,14 @@  static bool kshark_event_filter_from_json(struct tep_handle *pevent,
  * @param conf: Input location for the kshark_config_doc instance. Currently
  *		only Json format is supported.
  *
- * @returns True, if a filter has been loaded. If the filter configuration
- *	    document contains no data for this particular filter or in a case
- *	    of an error, the function returns False.
+ * @returns The total number of events added to the filter. If not all events
+ *	    listed in the input configuration have been added successfully,
+ *	    the returned number is negative.
  */
-bool kshark_import_event_filter(struct tep_handle *pevent,
-				struct tracecmd_filter_id *filter,
-				const char *filter_name,
-				struct kshark_config_doc *conf)
+int kshark_import_event_filter(struct tep_handle *pevent,
+			       struct tracecmd_filter_id *filter,
+			       const char *filter_name,
+			       struct kshark_config_doc *conf)
 {
 	switch (conf->format) {
 	case KS_CONFIG_JSON:
@@ -869,7 +874,7 @@  bool kshark_import_event_filter(struct tep_handle *pevent,
 	default:
 		fprintf(stderr, "Document format %d not supported\n",
 			conf->format);
-		return false;
+		return 0;
 	}
 }
 
diff --git a/kernel-shark/src/libkshark.h b/kernel-shark/src/libkshark.h
index fe35333..04e9cbf 100644
--- a/kernel-shark/src/libkshark.h
+++ b/kernel-shark/src/libkshark.h
@@ -587,10 +587,10 @@  bool kshark_export_event_filter(struct tep_handle *pevent,
 				const char *filter_name,
 				struct kshark_config_doc *conf);
 
-bool kshark_import_event_filter(struct tep_handle *pevent,
-				struct tracecmd_filter_id *filter,
-				const char *filter_name,
-				struct kshark_config_doc *conf);
+int kshark_import_event_filter(struct tep_handle *pevent,
+			       struct tracecmd_filter_id *filter,
+			       const char *filter_name,
+			       struct kshark_config_doc *conf);
 
 bool kshark_export_user_mask(struct kshark_context *kshark_ctx,
 			     struct kshark_config_doc **conf);