linux-trace-devel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: "Yordan Karadzhov (VMware)" <y.karadz@gmail.com>
To: rostedt@goodmis.org
Cc: linux-trace-devel@vger.kernel.org,
	"Yordan Karadzhov (VMware)" <y.karadz@gmail.com>
Subject: [PATCH 1/4] kernel-shark: kshark_import_event_filter() tolerates non-existing events
Date: Wed, 24 Jul 2019 18:40:36 +0300	[thread overview]
Message-ID: <20190724154039.23705-2-y.karadz@gmail.com> (raw)
In-Reply-To: <20190724154039.23705-1-y.karadz@gmail.com>

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 --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);
-- 
2.20.1


  reply	other threads:[~2019-07-24 15:41 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-07-24 15:40 [PATCH 0/3] Fixes for Capture needed befor KS 1.0 Yordan Karadzhov (VMware)
2019-07-24 15:40 ` Yordan Karadzhov (VMware) [this message]
2019-07-24 15:40 ` [PATCH 2/4] kernel-shark: Allow KsCaptureControl widget to print text to the console Yordan Karadzhov (VMware)
2019-07-24 15:40 ` [PATCH 3/4] kernel-shark: Handle errors when loading Capture configurations Yordan Karadzhov (VMware)
2019-07-24 15:40 ` [PATCH 4/4] kernel-shark: Handle corrupted configuration file for the Capture dialog Yordan Karadzhov (VMware)

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20190724154039.23705-2-y.karadz@gmail.com \
    --to=y.karadz@gmail.com \
    --cc=linux-trace-devel@vger.kernel.org \
    --cc=rostedt@goodmis.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).