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 17/17] kernel-shark-qt: Add the user filter mask to the Json config I/O
Date: Wed, 28 Nov 2018 15:16:29 +0000	[thread overview]
Message-ID: <20181128151530.21965-18-ykaradzhov@vmware.com> (raw)
In-Reply-To: <20181128151530.21965-1-ykaradzhov@vmware.com>

This patch updates the Json config I/O, making possible to
import/export the value of the user filter mask. When the filters
are imported, the states of the "Apply filters to Graph" and
"Apply filters to List" check-boxes are updated accordingly.

Signed-off-by: Yordan Karadzhov <ykaradzhov@vmware.com>
---
 kernel-shark-qt/src/KsMainWindow.cpp     | 35 ++++++---
 kernel-shark-qt/src/KsMainWindow.hpp     |  6 ++
 kernel-shark-qt/src/libkshark-configio.c | 99 ++++++++++++++++++++++++
 kernel-shark-qt/src/libkshark.h          | 11 +++
 4 files changed, 142 insertions(+), 9 deletions(-)

diff --git a/kernel-shark-qt/src/KsMainWindow.cpp b/kernel-shark-qt/src/KsMainWindow.cpp
index 16ba8bb..7213c01 100644
--- a/kernel-shark-qt/src/KsMainWindow.cpp
+++ b/kernel-shark-qt/src/KsMainWindow.cpp
@@ -50,7 +50,9 @@ KsMainWindow::KsMainWindow(QWidget *parent)
   _importFilterAction("Import Filter", this),
   _exportFilterAction("Export Filter", this),
   _graphFilterSyncAction(this),
+  _graphFilterSyncCBox(nullptr),
   _listFilterSyncAction(this),
+  _listFilterSyncCBox(nullptr),
   _showEventsAction("Show events", this),
   _showTasksAction("Show tasks", this),
   _hideTasksAction("Hide tasks", this),
@@ -273,7 +275,6 @@ void KsMainWindow::_createMenus()
 {
 	QMenu *file, *sessions, *filter, *plots, *tools, *help;
 	kshark_context *kshark_ctx(nullptr);
-	QCheckBox *cbf2g, *cbf2l;
 
 	if (!kshark_instance(&kshark_ctx))
 		return;
@@ -316,17 +317,17 @@ void KsMainWindow::_createMenus()
 
 	kshark_ctx->filter_mask |= KS_EVENT_VIEW_FILTER_MASK;
 
-	cbf2g = lamMakeCBAction(&_graphFilterSyncAction,
-				"Apply filters to Graph");
+	_graphFilterSyncCBox = lamMakeCBAction(&_graphFilterSyncAction,
+					       "Apply filters to Graph");
 
-	connect(cbf2g,	&QCheckBox::stateChanged,
-		this,	&KsMainWindow::_graphFilterSync);
+	connect(_graphFilterSyncCBox,	&QCheckBox::stateChanged,
+		this,			&KsMainWindow::_graphFilterSync);
 
-	cbf2l = lamMakeCBAction(&_listFilterSyncAction,
-				"Apply filters to List");
+	_listFilterSyncCBox = lamMakeCBAction(&_listFilterSyncAction,
+					      "Apply filters to List");
 
-	connect(cbf2l,	&QCheckBox::stateChanged,
-		this,	&KsMainWindow::_listFilterSync);
+	connect(_listFilterSyncCBox,	&QCheckBox::stateChanged,
+		this,			&KsMainWindow::_listFilterSync);
 
 	filter->addAction(&_graphFilterSyncAction);
 	filter->addAction(&_listFilterSyncAction);
@@ -431,6 +432,20 @@ void KsMainWindow::_exportSession()
 	_session.exportToFile(fileName);
 }
 
+void KsMainWindow::_filterSyncCBoxUpdate(kshark_context *kshark_ctx)
+{
+	if (kshark_ctx->filter_mask & KS_TEXT_VIEW_FILTER_MASK)
+		_listFilterSyncCBox->setChecked(true);
+	else
+		_listFilterSyncCBox->setChecked(false);
+
+	if (kshark_ctx->filter_mask &
+	    (KS_GRAPH_VIEW_FILTER_MASK | KS_EVENT_VIEW_FILTER_MASK))
+		_graphFilterSyncCBox->setChecked(true);
+	else
+		_graphFilterSyncCBox->setChecked(false);
+}
+
 void KsMainWindow::_importFilter()
 {
 	kshark_context *kshark_ctx(nullptr);
@@ -455,6 +470,7 @@ void KsMainWindow::_importFilter()
 	kshark_free_config_doc(conf);
 
 	kshark_filter_entries(kshark_ctx, _data.rows(), _data.size());
+	_filterSyncCBoxUpdate(kshark_ctx);
 	emit _data.updateWidgets(&_data);
 }
 
@@ -960,6 +976,7 @@ void KsMainWindow::loadSession(const QString &fileName)
 	pb.setValue(20);
 
 	_session.loadFilters(kshark_ctx, &_data);
+	_filterSyncCBoxUpdate(kshark_ctx);
 	pb.setValue(130);
 
 	_session.loadSplitterSize(&_splitter);
diff --git a/kernel-shark-qt/src/KsMainWindow.hpp b/kernel-shark-qt/src/KsMainWindow.hpp
index b231b52..72f7059 100644
--- a/kernel-shark-qt/src/KsMainWindow.hpp
+++ b/kernel-shark-qt/src/KsMainWindow.hpp
@@ -112,8 +112,12 @@ private:
 
 	QWidgetAction	_graphFilterSyncAction;
 
+	QCheckBox	*_graphFilterSyncCBox;
+
 	QWidgetAction	_listFilterSyncAction;
 
+	QCheckBox	*_listFilterSyncCBox;
+
 	QAction		_showEventsAction;
 
 	QAction		_showTasksAction;
@@ -218,6 +222,8 @@ private:
 
 	void _deselect();
 
+	void _filterSyncCBoxUpdate(kshark_context *kshark_ctx);
+
 private slots:
 	void _captureFinished(int, QProcess::ExitStatus);
 };
diff --git a/kernel-shark-qt/src/libkshark-configio.c b/kernel-shark-qt/src/libkshark-configio.c
index a426e48..4fe7de3 100644
--- a/kernel-shark-qt/src/libkshark-configio.c
+++ b/kernel-shark-qt/src/libkshark-configio.c
@@ -1201,6 +1201,103 @@ bool kshark_import_adv_filters(struct kshark_context *kshark_ctx,
 	}
 }
 
+static bool kshark_user_mask_to_json(struct kshark_context *kshark_ctx,
+				     struct json_object *jobj)
+{
+	uint8_t mask = kshark_ctx->filter_mask;
+	json_object *jmask;
+
+	jmask = json_object_new_int((int) mask);
+	if (!jmask)
+		return false;
+
+	/* Add the mask to the filter config document. */
+	json_object_object_add(jobj, KS_USER_FILTER_MASK_NAME, jmask);
+	return true;
+}
+
+/**
+ * @brief Record the current value of the the user-specified filter mask 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 Adv. Filter
+ *		Configuration document will be created.
+ *
+ * @returns True on success, otherwise False.
+ */
+bool kshark_export_user_mask(struct kshark_context *kshark_ctx,
+			     struct kshark_config_doc **conf)
+{
+	if (!*conf)
+		*conf = kshark_filter_config_new(KS_CONFIG_JSON);
+
+	if (!*conf)
+		return false;
+
+	switch ((*conf)->format) {
+	case KS_CONFIG_JSON:
+		return kshark_user_mask_to_json(kshark_ctx,
+						(*conf)->conf_doc);
+
+	default:
+		fprintf(stderr, "Document format %d not supported\n",
+			(*conf)->format);
+		return false;
+	}
+}
+
+static bool kshark_user_mask_from_json(struct kshark_context *kshark_ctx,
+				       struct json_object *jobj)
+{
+	json_object *jmask;
+	uint8_t mask;
+
+	if (!kshark_json_type_check(jobj, "kshark.config.filter"))
+		return false;
+	/*
+	 * Use the name of the filter to find the value of the filter maks.
+	 * Notice that the filter config document may contain no data for
+	 * the mask.
+	 */
+	if (!json_object_object_get_ex(jobj, KS_USER_FILTER_MASK_NAME,
+				       &jmask))
+		return false;
+
+	mask = json_object_get_int(jmask);
+	kshark_ctx->filter_mask = mask;
+
+	return true;
+}
+
+/**
+ * @brief Load from Configuration document the value of the user-specified
+ *	  filter mask.
+ *
+ * @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 mask has been loaded. If the filter configuration
+ *	    document contains no data for the mask or in a case of an error,
+ *	    the function returns False.
+ */
+bool kshark_import_user_mask(struct kshark_context *kshark_ctx,
+			     struct kshark_config_doc *conf)
+{
+	switch (conf->format) {
+	case KS_CONFIG_JSON:
+		return kshark_user_mask_from_json(kshark_ctx,
+						  conf->conf_doc);
+
+	default:
+		fprintf(stderr, "Document format %d not supported\n",
+			conf->format);
+		return false;
+	}
+}
+
 static bool filter_is_set(struct tracecmd_filter_id *filter)
 {
 	return filter && filter->count;
@@ -1430,6 +1527,7 @@ kshark_export_all_filters(struct kshark_context *kshark_ctx,
 	    !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_user_mask(kshark_ctx, &conf) ||
 	    !kshark_export_adv_filters(kshark_ctx, &conf)) {
 		kshark_free_config_doc(conf);
 		return NULL;
@@ -1456,6 +1554,7 @@ bool kshark_import_all_filters(struct kshark_context *kshark_ctx,
 	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_user_mask(kshark_ctx, conf);
 	ret |= kshark_import_adv_filters(kshark_ctx, conf);
 
 	return ret;
diff --git a/kernel-shark-qt/src/libkshark.h b/kernel-shark-qt/src/libkshark.h
index 6a3eba6..b3bd646 100644
--- a/kernel-shark-qt/src/libkshark.h
+++ b/kernel-shark-qt/src/libkshark.h
@@ -504,6 +504,11 @@ enum kshark_config_formats {
  */
 #define KS_ADV_EVENT_FILTER_NAME	"adv event filter"
 
+/**
+ * Field name for the Configuration document describing user-specified filter
+ * mask.
+ */
+#define KS_USER_FILTER_MASK_NAME	"filter mask"
 /**
  * Field name for the Configuration document describing the state of the Vis.
  * model.
@@ -575,6 +580,12 @@ bool kshark_import_event_filter(struct tep_handle *pevent,
 				const char *filter_name,
 				struct kshark_config_doc *conf);
 
+bool kshark_export_user_mask(struct kshark_context *kshark_ctx,
+			     struct kshark_config_doc **conf);
+
+bool kshark_import_user_mask(struct kshark_context *kshark_ctx,
+			     struct kshark_config_doc *conf);
+
 bool kshark_export_filter_array(struct tracecmd_filter_id *filter,
 				const char *filter_name,
 				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 ` [PATCH 15/17] kernel-shark-qt: Add the CPU filters to the Json config I/O Yordan Karadzhov
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 ` Yordan Karadzhov [this message]

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-18-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.