All of lore.kernel.org
 help / color / mirror / Atom feed
From: Yordan Karadzhov <ykaradzhov@vmware.com>
To: "rostedt@goodmis.org" <rostedt@goodmis.org>
Cc: "linux-trace-devel@vger.kernel.org" <linux-trace-devel@vger.kernel.org>
Subject: [PATCH 15/17] kernel-shark-qt: Add the CPU filters to the Json config I/O
Date: Wed, 28 Nov 2018 15:16:26 +0000	[thread overview]
Message-ID: <20181128151530.21965-16-ykaradzhov@vmware.com> (raw)
In-Reply-To: <20181128151530.21965-1-ykaradzhov@vmware.com>

This patch adds "Show CPU" and "Hide CPU" filters to the Json
config I/O, making possible to import/export those filters.
Saving/loading the CPU filters reuses some of the code used
so far by the Task filters. Because of this some functions
have been renamed.

Signed-off-by: Yordan Karadzhov <ykaradzhov@vmware.com>
---
 kernel-shark-qt/src/libkshark-configio.c | 133 +++++++++++++++++------
 kernel-shark-qt/src/libkshark.h          |  28 ++++-
 2 files changed, 123 insertions(+), 38 deletions(-)

diff --git a/kernel-shark-qt/src/libkshark-configio.c b/kernel-shark-qt/src/libkshark-configio.c
index bf2a08b..a426e48 100644
--- a/kernel-shark-qt/src/libkshark-configio.c
+++ b/kernel-shark-qt/src/libkshark-configio.c
@@ -870,20 +870,20 @@ bool kshark_import_event_filter(struct tep_handle *pevent,
 	}
 }
 
-static bool kshark_task_filter_to_json(struct tracecmd_filter_id *filter,
-				       const char *filter_name,
-				       struct json_object *jobj)
+static bool kshark_filter_array_to_json(struct tracecmd_filter_id *filter,
+					const char *filter_name,
+					struct json_object *jobj)
 {
 	json_object *jfilter_data, *jpid = NULL;
 	int i, *ids;
 
 	/*
-	 * If this Json document already contains a description of the model,
+	 * If this Json document already contains a description of the filter,
 	 * delete this description.
 	 */
 	json_del_if_exist(jobj, filter_name);
 
-	/* Get the array of Ids to be fitered. */
+	/* Get the array of Ids to be filtered. */
 	ids = tracecmd_filter_ids(filter);
 	if (!ids)
 		return true;
@@ -918,7 +918,7 @@ static bool kshark_task_filter_to_json(struct tracecmd_filter_id *filter,
 }
 
 /**
- * @brief Record the current configuration of a Task Id filter into a
+ * @brief Record the current configuration of a simple Id filter into a
  *	  Configuration document.
  *
  * @param filter: Input location for an Id filter.
@@ -928,14 +928,14 @@ static bool kshark_task_filter_to_json(struct tracecmd_filter_id *filter,
  *
  * @returns True on success, otherwise False.
  */
-bool kshark_export_task_filter(struct tracecmd_filter_id *filter,
-			       const char *filter_name,
-			       struct kshark_config_doc *conf)
+bool kshark_export_filter_array(struct tracecmd_filter_id *filter,
+				const char *filter_name,
+				struct kshark_config_doc *conf)
 {
 	switch (conf->format) {
 	case KS_CONFIG_JSON:
-		return kshark_task_filter_to_json(filter, filter_name,
-						  conf->conf_doc);
+		return kshark_filter_array_to_json(filter, filter_name,
+						   conf->conf_doc);
 
 	default:
 		fprintf(stderr, "Document format %d not supported\n",
@@ -944,9 +944,9 @@ bool kshark_export_task_filter(struct tracecmd_filter_id *filter,
 	}
 }
 
-static bool kshark_task_filter_from_json(struct tracecmd_filter_id *filter,
-					 const char *filter_name,
-					 struct json_object *jobj)
+static bool kshark_filter_array_from_json(struct tracecmd_filter_id *filter,
+					  const char *filter_name,
+					  struct json_object *jobj)
 {
 	json_object *jfilter, *jpid;
 	int i, length;
@@ -981,7 +981,8 @@ static bool kshark_task_filter_from_json(struct tracecmd_filter_id *filter,
 }
 
 /**
- * @brief Load from Configuration document the configuration of a Task Id filter.
+ * @brief Load from Configuration document the configuration of a simple
+ *	  Id filter.
  *
  * @param filter: Input location for an Id filter.
  * @param filter_name: The name of the filter as showing up in the Config.
@@ -993,14 +994,14 @@ static bool kshark_task_filter_from_json(struct tracecmd_filter_id *filter,
  *	    document contains no data for this particular filter or in a case
  *	    of an error, the function returns False.
  */
-bool kshark_import_task_filter(struct tracecmd_filter_id *filter,
-			       const char *filter_name,
-			       struct kshark_config_doc *conf)
+bool kshark_import_filter_array(struct tracecmd_filter_id *filter,
+				const char *filter_name,
+				struct kshark_config_doc *conf)
 {
 	switch (conf->format) {
 	case KS_CONFIG_JSON:
-		return kshark_task_filter_from_json(filter, filter_name,
-						    conf->conf_doc);
+		return kshark_filter_array_from_json(filter, filter_name,
+						     conf->conf_doc);
 
 	default:
 		fprintf(stderr, "Document format %d not supported\n",
@@ -1269,14 +1270,52 @@ bool kshark_export_all_task_filters(struct kshark_context *kshark_ctx,
 
 	/* Save a filter only if it contains Id values. */
 	if (filter_is_set(kshark_ctx->show_task_filter))
-		ret &= kshark_export_task_filter(kshark_ctx->show_task_filter,
-						 KS_SHOW_TASK_FILTER_NAME,
-						 *conf);
+		ret &= kshark_export_filter_array(kshark_ctx->show_task_filter,
+						  KS_SHOW_TASK_FILTER_NAME,
+						  *conf);
 
 	if (filter_is_set(kshark_ctx->hide_task_filter))
-		ret &= kshark_export_task_filter(kshark_ctx->hide_task_filter,
-						 KS_HIDE_TASK_FILTER_NAME,
-						 *conf);
+		ret &= kshark_export_filter_array(kshark_ctx->hide_task_filter,
+						  KS_HIDE_TASK_FILTER_NAME,
+						  *conf);
+
+	return ret;
+}
+
+
+/**
+ * @brief Record the current configuration of "show cpu" and "hide cpu"
+ *	  filters into a Configuration document.
+ *
+ * @param kshark_ctx: Input location for session context pointer.
+ * @param conf: Input location for the kshark_config_doc instance. Currently
+ *		only Json format is supported. If NULL, a new Filter
+ *		Configuration document will be created.
+ *
+ * @returns True, if a filter has been recorded. If both filters contain
+ *	    no Id values or in a case of an error, the function returns False.
+ */
+bool kshark_export_all_cpu_filters(struct kshark_context *kshark_ctx,
+				   struct kshark_config_doc **conf)
+{
+	bool ret = true;
+
+	if (!*conf)
+		*conf = kshark_filter_config_new(KS_CONFIG_JSON);
+
+	if (!*conf)
+		return false;
+
+	/* Save a filter only if it contains Id values. */
+	if (filter_is_set(kshark_ctx->show_task_filter))
+		ret &= kshark_export_filter_array(kshark_ctx->show_cpu_filter,
+						  KS_SHOW_CPU_FILTER_NAME,
+						  *conf);
+
+	if (filter_is_set(kshark_ctx->hide_task_filter))
+		ret &= kshark_export_filter_array(kshark_ctx->hide_cpu_filter,
+						  KS_HIDE_CPU_FILTER_NAME,
+						  *conf);
 
 	return ret;
 }
@@ -1328,13 +1367,41 @@ bool kshark_import_all_task_filters(struct kshark_context *kshark_ctx,
 {
 	bool ret = false;
 
-	ret |= kshark_import_task_filter(kshark_ctx->hide_task_filter,
-					 KS_HIDE_TASK_FILTER_NAME,
-					 conf);
+	ret |= kshark_import_filter_array(kshark_ctx->hide_task_filter,
+					  KS_HIDE_TASK_FILTER_NAME,
+					  conf);
+
+	ret |= kshark_import_filter_array(kshark_ctx->show_task_filter,
+					  KS_SHOW_TASK_FILTER_NAME,
+					  conf);
+
+	return ret;
+}
+
+/**
+ * @brief Load from Configuration document the configuration of "show cpu"
+ *	  and "hide cpu" filters.
+ *
+ * @param kshark_ctx: Input location for session context pointer.
+ * @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 any cpu filter or in a case of an
+ *	    error, the function returns False.
+ */
+bool kshark_import_all_cpu_filters(struct kshark_context *kshark_ctx,
+				    struct kshark_config_doc *conf)
+{
+	bool ret = false;
+
+	ret |= kshark_import_filter_array(kshark_ctx->hide_cpu_filter,
+					  KS_HIDE_CPU_FILTER_NAME,
+					  conf);
 
-	ret |= kshark_import_task_filter(kshark_ctx->show_task_filter,
-					 KS_SHOW_TASK_FILTER_NAME,
-					 conf);
+	ret |= kshark_import_filter_array(kshark_ctx->show_cpu_filter,
+					  KS_SHOW_CPU_FILTER_NAME,
+					  conf);
 
 	return ret;
 }
@@ -1362,6 +1429,7 @@ kshark_export_all_filters(struct kshark_context *kshark_ctx,
 	if (!conf ||
 	    !kshark_export_all_event_filters(kshark_ctx, &conf) ||
 	    !kshark_export_all_task_filters(kshark_ctx, &conf) ||
+	    !kshark_export_all_cpu_filters(kshark_ctx, &conf) ||
 	    !kshark_export_adv_filters(kshark_ctx, &conf)) {
 		kshark_free_config_doc(conf);
 		return NULL;
@@ -1386,6 +1454,7 @@ bool kshark_import_all_filters(struct kshark_context *kshark_ctx,
 {
 	bool ret;
 	ret = kshark_import_all_task_filters(kshark_ctx, conf);
+	ret |= kshark_import_all_cpu_filters(kshark_ctx, conf);
 	ret |= kshark_import_all_event_filters(kshark_ctx, conf);
 	ret |= kshark_import_adv_filters(kshark_ctx, conf);
 
diff --git a/kernel-shark-qt/src/libkshark.h b/kernel-shark-qt/src/libkshark.h
index eb8c261..6a3eba6 100644
--- a/kernel-shark-qt/src/libkshark.h
+++ b/kernel-shark-qt/src/libkshark.h
@@ -488,6 +488,16 @@ enum kshark_config_formats {
  */
 #define KS_SHOW_TASK_FILTER_NAME	"show task filter"
 
+/**
+ * Field name for the Configuration document describing the Hide Task filter.
+ */
+#define KS_HIDE_CPU_FILTER_NAME		"hide cpu filter"
+
+/**
+ * Field name for the Configuration document describing the Show Task filter.
+ */
+#define KS_SHOW_CPU_FILTER_NAME		"show cpu filter"
+
 /**
  * Field name for the Configuration document describing the Advanced event
  * filter.
@@ -565,13 +575,13 @@ bool kshark_import_event_filter(struct tep_handle *pevent,
 				const char *filter_name,
 				struct kshark_config_doc *conf);
 
-bool kshark_export_task_filter(struct tracecmd_filter_id *filter,
-			       const char *filter_name,
-			       struct kshark_config_doc *conf);
+bool kshark_export_filter_array(struct tracecmd_filter_id *filter,
+				const char *filter_name,
+				struct kshark_config_doc *conf);
 
-bool kshark_import_task_filter(struct tracecmd_filter_id *filter,
-			       const char *filter_name,
-			       struct kshark_config_doc *conf);
+bool kshark_import_filter_array(struct tracecmd_filter_id *filter,
+				const char *filter_name,
+				struct kshark_config_doc *conf);
 
 bool kshark_export_all_event_filters(struct kshark_context *kshark_ctx,
 				     struct kshark_config_doc **conf);
@@ -579,6 +589,9 @@ bool kshark_export_all_event_filters(struct kshark_context *kshark_ctx,
 bool kshark_export_all_task_filters(struct kshark_context *kshark_ctx,
 				    struct kshark_config_doc **conf);
 
+bool kshark_export_all_cpu_filters(struct kshark_context *kshark_ctx,
+				   struct kshark_config_doc **conf);
+
 struct kshark_config_doc *
 kshark_export_all_filters(struct kshark_context *kshark_ctx,
 			  enum kshark_config_formats format);
@@ -589,6 +602,9 @@ bool kshark_import_all_event_filters(struct kshark_context *kshark_ctx,
 bool kshark_import_all_task_filters(struct kshark_context *kshark_ctx,
 				    struct kshark_config_doc *conf);
 
+bool kshark_import_all_cpu_filters(struct kshark_context *kshark_ctx,
+				   struct kshark_config_doc *conf);
+
 bool kshark_import_all_filters(struct kshark_context *kshark_ctx,
 			       struct kshark_config_doc *conf);
 
-- 
2.17.1

  parent reply	other threads:[~2018-11-29  2:18 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-11-28 15:16 [PATCH 00/17] More modifications and bug fixes toward KS 1.0 Yordan Karadzhov
2018-11-28 15:16 ` [PATCH 01/17] kernel-shark-qt: Updata Event filter mask when applaing filters to Graph Yordan Karadzhov
2018-11-28 15:16 ` [PATCH 02/17] kernel-shark-qt: Reprocess all CPU collections when the filtering changes Yordan Karadzhov
2018-11-28 15:16 ` [PATCH 03/17] kernel-shark-qt: Fix a byg in unset_event_filter_flag() Yordan Karadzhov
2018-11-28 15:16 ` [PATCH 04/17] kernel-shark qt: No error when Record authentication dialog is closed Yordan Karadzhov
2018-11-28 15:16 ` [PATCH 05/17] kernel-shark-qt: Protect all calls of tep_read_number_field() Yordan Karadzhov
2018-11-28 15:16 ` [PATCH 06/17] kernel-shark-qt: Ignore sched_wakeup events if the task is running Yordan Karadzhov
2018-11-28 15:16 ` [PATCH 07/17] kernel-shark-qt: Fix the documentation of libkshark-model Yordan Karadzhov
2018-11-28 15:16 ` [PATCH 08/17] kernel-shark-qt: Add a method for easy retrieve of all Ids of a filter Yordan Karadzhov
2018-11-28 15:16 ` [PATCH 09/17] kernel-shark-qt: Add centralized context menu for View and Graph widgets Yordan Karadzhov
2018-11-28 15:16 ` [PATCH 10/17] kernel-shark-qt: Add keyboard shortcuts for deselecting the marker Yordan Karadzhov
2018-11-28 15:16 ` [PATCH 11/17] kernel-shark-qt: Sort all graphs before plotting Yordan Karadzhov
2018-11-28 17:12   ` Steven Rostedt
2018-11-29 11:29     ` Yordan Karadzhov
2018-11-28 15:16 ` [PATCH 12/17] kernel-shark-qt: Add CPU-based filtering to the C API Yordan Karadzhov
2018-11-28 15:16 ` [PATCH 13/17] kernel-shark-qt: Add CPU-based filtering to KsDataStore Yordan Karadzhov
2018-11-28 15:16 ` [PATCH 14/17] kernel-shark-qt: Add Hide CPU action to the Quick Context Menu Yordan Karadzhov
2018-11-28 15:16 ` Yordan Karadzhov [this message]
2018-11-28 15:16 ` [PATCH 16/17] kernel-shark-qt: Add "Hide CPU" checkbox dialog to the Main window menu Yordan Karadzhov
2018-11-28 17:16   ` Steven Rostedt
2018-11-28 15:16 ` [PATCH 17/17] kernel-shark-qt: Add the user filter mask to the Json config I/O Yordan Karadzhov

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=20181128151530.21965-16-ykaradzhov@vmware.com \
    --to=ykaradzhov@vmware.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 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.