Skip to contentSkip to conversation

Add dialog for loading user-defined plugins

PATCH Superseded Yordan Karadzhov 3 participants 8 messages Mar 8, 2019 – Mar 11, 2019

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

cover Add dialog for loading user-defined plugins

So far loading user-defined plugins was possible only from the command line

./kernelshark -p /path/to/your/plugin-lib.so

This patch set adds the possibility to load a plugin from the GUI itself by using a dedicated dialog available in Tools

Yordan Karadzhov (4):
kernel-shark: Define addPlugin method for KsPluginManager
kernel-shark: Add dialog for user-defined plugin to the Tools menu
kernel-shark: Rename the manu action for managing registered plugins
kernel-shark: Add icons for "Add plugin" and "Manage plugins"

 kernel-shark/src/KsMainWindow.cpp | 32 ++++++++++++++++++++++++++-----
 kernel-shark/src/KsMainWindow.hpp |  6 +++++-
 kernel-shark/src/KsUtils.cpp      | 17 ++++++++++++++++
 kernel-shark/src/KsUtils.hpp      |  3 +++
 4 files changed, 52 insertions(+), 6 deletions(-)
Signature · 1 line
2.19.1
#1 lore raw

PATCH 1/4 kernel-shark: Define addPlugin method for KsPluginManager

The method can be used to register and load a user-defined plugin. All other previously loaded plugins will be reloaded.

---
 kernel-shark/src/KsUtils.cpp | 17 +++++++++++++++++
 kernel-shark/src/KsUtils.hpp |  3 +++
 2 files changed, 20 insertions(+)
kernel-shark/src/KsUtils.cpp +17 -0
index d7b1753..4d05bda 100644
@@ -596,6 +596,23 @@ void KsPluginManager::unregisterPlugin(const QString &plugin)
 	}
 }
 
+/** @brief Add to the list and load a user-provided plugin. All other
+ *	   previously loaded plugins will be reloaded.
+ *
+ * @param fileName: the library file (.so) of the plugin.
+*/
+void KsPluginManager::addPlugin(const QString &fileName)
+{
+	kshark_context *kshark_ctx(nullptr);
+
+	if (!kshark_instance(&kshark_ctx))
+		return;
+
+	kshark_handle_plugins(kshark_ctx, KSHARK_PLUGIN_CLOSE);
+	registerPlugin(fileName);
+	kshark_handle_plugins(kshark_ctx, KSHARK_PLUGIN_INIT);
+}
+
 /** Unload all plugins. */
 void KsPluginManager::unloadAll()
 {
kernel-shark/src/KsUtils.hpp +3 -0
index cb95b4f..ae7f6d1 100644
@@ -210,6 +210,9 @@ public:
 
 	void registerPlugin(const QString &plugin);
 	void unregisterPlugin(const QString &plugin);
+
+	void addPlugin(const QString &fileName);
+
 	void unloadAll();
 
 	void updatePlugins(QVector<int> pluginId);
Signature · 1 line
2.19.1
#2 lore raw

Re: [PATCH 1/4] kernel-shark: Define addPlugin method for KsPluginManager

Quoted 24 lines · Yordan Karadzhov

The method can be used to register and load a user-defined plugin. All other previously loaded plugins will be reloaded.

---
 kernel-shark/src/KsUtils.cpp | 17 +++++++++++++++++
 kernel-shark/src/KsUtils.hpp |  3 +++
 2 files changed, 20 insertions(+)
kernel-shark/src/KsUtils.cpp +6 -0
index d7b1753..4d05bda 100644
@@ -596,6 +596,23 @@ void KsPluginManager::unregisterPlugin(const QString &plugin)
        }
 }
 
+/** @brief Add to the list and load a user-provided plugin. All other
+ *        previously loaded plugins will be reloaded.
+ *
+ * @param fileName: the library file (.so) of the plugin.
+*/
+void KsPluginManager::addPlugin(const QString &fileName)

kernel-shark/src/KsUtils.cpp void KsPluginManager::unregisterPlugin(const QString &plugin) · line 614

Quoted 10 lines
kernel-shark/src/KsUtils.cpp +10 -0
+{
+       kshark_context *kshark_ctx(nullptr);
+
+       if (!kshark_instance(&kshark_ctx))
+               return;
+
+       kshark_handle_plugins(kshark_ctx, KSHARK_PLUGIN_CLOSE);
+       registerPlugin(fileName);
+       kshark_handle_plugins(kshark_ctx, KSHARK_PLUGIN_INIT);
+}

Calling addPlugin() several times in a row will reinitialize all already registered plugins several times and lead to quadratic complexity. This seems wrong to me.

Maybe we should split adding plugins from (re-)initializing them so that one can add several plugins and then have initialized once when they are actually needed to run. Wdyt?

--Slavi

Quoted 21 lines
kernel-shark/src/KsUtils.cpp +1 -0
+
 /** Unload all plugins. */
 void KsPluginManager::unloadAll()
 {
kernel-shark/src/KsUtils.hpp +3 -1
index cb95b4f..ae7f6d1 100644
@@ -210,6 +210,9 @@ public:
 
        void registerPlugin(const QString &plugin);
        void unregisterPlugin(const QString &plugin);
+
+       void addPlugin(const QString &fileName);
+
        void unloadAll();
 
        void updatePlugins(QVector<int> pluginId);
--

2.19.1

Signature · 1 line
Slavomir Kaslev
#3 lore raw

Re: [PATCH 1/4] kernel-shark: Define addPlugin method for KsPluginManager

Quoted 40 lines · Slavomir Kaslev
Quoted 24 lines · Yordan Karadzhov

The method can be used to register and load a user-defined plugin. All other previously loaded plugins will be reloaded.

---
  kernel-shark/src/KsUtils.cpp | 17 +++++++++++++++++
  kernel-shark/src/KsUtils.hpp |  3 +++
  2 files changed, 20 insertions(+)
kernel-shark/src/KsUtils.cpp +6 -0
index d7b1753..4d05bda 100644
@@ -596,6 +596,23 @@ void KsPluginManager::unregisterPlugin(const QString &plugin)
         }
  }
 
+/** @brief Add to the list and load a user-provided plugin. All other
+ *        previously loaded plugins will be reloaded.
+ *
+ * @param fileName: the library file (.so) of the plugin.
+*/
+void KsPluginManager::addPlugin(const QString &fileName)

kernel-shark/src/KsUtils.cpp void KsPluginManager::unregisterPlugin(const QString &plugin) · line 614

Quoted 10 lines
kernel-shark/src/KsUtils.cpp +10 -0
+{
+       kshark_context *kshark_ctx(nullptr);
+
+       if (!kshark_instance(&kshark_ctx))
+               return;
+
+       kshark_handle_plugins(kshark_ctx, KSHARK_PLUGIN_CLOSE);
+       registerPlugin(fileName);
+       kshark_handle_plugins(kshark_ctx, KSHARK_PLUGIN_INIT);
+}

Calling addPlugin() several times in a row will reinitialize all already registered plugins several times and lead to quadratic complexity. This seems wrong to me.

Quoted 4 lines

Maybe we should split adding plugins from (re-)initializing them so that one can add several plugins and then have initialized once when they are actually needed to run. Wdyt?

Hi Slavi,

KsPluginManager is a helper class for the GUI. It only does what the GUI is supposed to do. Currently the dialog that allows to load user plugins provides loading only one plugin at a time, so the KsPluginManager provides only this functionality.

So the questions is: do we want a dialog that loads multiple plugins with one click?

On the other hand we do encourage the users to use the KernelShark library for making custom applications. This is the motivation for having the C API, but KsPluginManager it is not part of this API. KsPluginManager operates on top of the API and is intended to be used only by the GUI code.

Indeed the C API itself separates adding plugins from there initializing.

Thanks a lot!
Y.

Quoted 25 lines

--Slavi

Quoted 21 lines
kernel-shark/src/KsUtils.cpp +1 -0
+
  /** Unload all plugins. */
  void KsPluginManager::unloadAll()
  {
kernel-shark/src/KsUtils.hpp +3 -1
index cb95b4f..ae7f6d1 100644
@@ -210,6 +210,9 @@ public:
 
         void registerPlugin(const QString &plugin);
         void unregisterPlugin(const QString &plugin);
+
+       void addPlugin(const QString &fileName);
+
         void unloadAll();
 
         void updatePlugins(QVector<int> pluginId);
--

2.19.1

#4 lore raw

Re: [PATCH 1/4] kernel-shark: Define addPlugin method for KsPluginManager

Quoted 11 lines · On Mon, 11 Mar 2019 17:39:11 +0000 Yordan Karadzhov <[email protected]>…
Quoted 8 lines

Calling addPlugin() several times in a row will reinitialize all already registered plugins several times and lead to quadratic complexity. This seems wrong to me.

Maybe we should split adding plugins from (re-)initializing them so that one can add several plugins and then have initialized once when they are actually needed to run. Wdyt?

Hi Slavi,

Quoted 7 lines

KsPluginManager is a helper class for the GUI. It only does what the GUI is supposed to do. Currently the dialog that allows to load user plugins provides loading only one plugin at a time, so the KsPluginManager provides only this functionality.

So the questions is: do we want a dialog that loads multiple plugins with one click?

What would be the issue with allowing that?

Quoted 8 lines

On the other hand we do encourage the users to use the KernelShark library for making custom applications. This is the motivation for having the C API, but KsPluginManager it is not part of this API. KsPluginManager operates on top of the API and is intended to be used only by the GUI code.

Indeed the C API itself separates adding plugins from there initializing.

Just like clicking the plugin dialog, where you select the plugins to add or remove and hit apply. Couldn't this be the same, or am I missing something?

-- Steve

#5 lore raw

PATCH 2/4 kernel-shark: Add dialog for user-defined plugin to the Tools menu

In reply to Yordan Karadzhov

The dialog allows the user to find and load the plugin's lobrary (.so file).

---
 kernel-shark/src/KsMainWindow.cpp | 20 ++++++++++++++++++++
 kernel-shark/src/KsMainWindow.hpp |  4 ++++
 2 files changed, 24 insertions(+)
kernel-shark/src/KsMainWindow.cpp +20 -0
index 362b955..004c9ac 100644
@@ -59,6 +59,7 @@ KsMainWindow::KsMainWindow(QWidget *parent)
   _cpuSelectAction("CPUs", this),
   _taskSelectAction("Tasks", this),
   _pluginsAction("Plugins", this),
+  _addPluginAction("Add plugin", this),
   _captureAction("Record", this),
   _colorAction(this),
   _colSlider(this),
@@ -233,6 +234,11 @@ void KsMainWindow::_createActions()
 	connect(&_pluginsAction,	&QAction::triggered,
 		this,			&KsMainWindow::_pluginSelect);
 
+	_addPluginAction.setStatusTip("Add plugin");
+
+	connect(&_addPluginAction,	&QAction::triggered,
+		this,			&KsMainWindow::_pluginAdd);
+
 	_captureAction.setIcon(QIcon::fromTheme("media-record"));
 	_captureAction.setShortcut(tr("Ctrl+R"));
 	_captureAction.setStatusTip("Capture trace data");
@@ -336,6 +342,7 @@ void KsMainWindow::_createMenus()
 	/* Tools menu */
 	tools = menuBar()->addMenu("Tools");
 	tools->addAction(&_pluginsAction);
+	tools->addAction(&_addPluginAction);
 	tools->addAction(&_captureAction);
 	tools->addSeparator();
 	tools->addAction(&_colorAction);
@@ -796,6 +803,19 @@ void KsMainWindow::_pluginSelect()
 	dialog->show();
 }
 
+void KsMainWindow::_pluginAdd()
+{
+	QString fileName;
+
+	fileName = QFileDialog::getOpenFileName(this, "Add KernelShark plugin", KS_DIR,
+						"KernelShark Plugins (*.so);;");
+
+	if (fileName.isEmpty())
+		return;
+
+	_plugins.addPlugin(fileName);
+}
+
 void KsMainWindow::_record()
 {
 #ifndef DO_AS_ROOT
kernel-shark/src/KsMainWindow.hpp +4 -0
index 969b603..a4eed19 100644
@@ -132,6 +132,8 @@ private:
 	// Tools menu.
 	QAction		_pluginsAction;
 
+	QAction		_addPluginAction;
+
 	QAction		_captureAction;
 
 	QWidgetAction	_colorAction;
@@ -185,6 +187,8 @@ private:
 
 	void _pluginSelect();
 
+	void _pluginAdd();
+
 	void _record();
 
 	void _setColorPhase(int);
Signature · 1 line
2.19.1
#6 lore raw

PATCH 3/4 kernel-shark: Rename the manu action for managing registered plugins

In reply to Yordan Karadzhov

The menu action in Tools that is used to manage all registered plugins is renamed in order to avoid confusion with the "Add plugin" menu action, implemented in the previous patch.

---
 kernel-shark/src/KsMainWindow.cpp | 10 +++++-----
 kernel-shark/src/KsMainWindow.hpp |  2 +-
 2 files changed, 6 insertions(+), 6 deletions(-)
kernel-shark/src/KsMainWindow.cpp +5 -5
index 004c9ac..f6889ca 100644
@@ -58,7 +58,7 @@ KsMainWindow::KsMainWindow(QWidget *parent)
   _clearAllFilters("Clear all filters", this),
   _cpuSelectAction("CPUs", this),
   _taskSelectAction("Tasks", this),
-  _pluginsAction("Plugins", this),
+  _managePluginsAction("Manage plugins", this),
   _addPluginAction("Add plugin", this),
   _captureAction("Record", this),
   _colorAction(this),
@@ -228,10 +228,10 @@ void KsMainWindow::_createActions()
 		this,			&KsMainWindow::_taskSelect);
 
 	/* Tools menu */
-	_pluginsAction.setShortcut(tr("Ctrl+P"));
-	_pluginsAction.setStatusTip("Manage plugins");
+	_managePluginsAction.setShortcut(tr("Ctrl+P"));
+	_managePluginsAction.setStatusTip("Manage plugins");
 
-	connect(&_pluginsAction,	&QAction::triggered,
+	connect(&_managePluginsAction,	&QAction::triggered,
 		this,			&KsMainWindow::_pluginSelect);
 
 	_addPluginAction.setStatusTip("Add plugin");
@@ -341,7 +341,7 @@ void KsMainWindow::_createMenus()
 
 	/* Tools menu */
 	tools = menuBar()->addMenu("Tools");
-	tools->addAction(&_pluginsAction);
+	tools->addAction(&_managePluginsAction);
 	tools->addAction(&_addPluginAction);
 	tools->addAction(&_captureAction);
 	tools->addSeparator();
kernel-shark/src/KsMainWindow.hpp +1 -1
index a4eed19..0727631 100644
@@ -130,7 +130,7 @@ private:
 	QAction		_taskSelectAction;
 
 	// Tools menu.
-	QAction		_pluginsAction;
+	QAction		_managePluginsAction;
 
 	QAction		_addPluginAction;
 
Signature · 1 line
2.19.1
#7 lore raw

PATCH 4/4 kernel-shark: Add icons for "Add plugin" and "Manage plugins"

In reply to Yordan Karadzhov

Just a small cosmetic improvement.

---
 kernel-shark/src/KsMainWindow.cpp | 2 ++
 1 file changed, 2 insertions(+)
kernel-shark/src/KsMainWindow.cpp +2 -0
index f6889ca..782b230 100644
@@ -229,11 +229,13 @@ void KsMainWindow::_createActions()
 
 	/* Tools menu */
 	_managePluginsAction.setShortcut(tr("Ctrl+P"));
+	_managePluginsAction.setIcon(QIcon::fromTheme("preferences-system"));
 	_managePluginsAction.setStatusTip("Manage plugins");
 
 	connect(&_managePluginsAction,	&QAction::triggered,
 		this,			&KsMainWindow::_pluginSelect);
 
+	_addPluginAction.setIcon(QIcon::fromTheme("applications-engineering"));
 	_addPluginAction.setStatusTip("Add plugin");
 
 	connect(&_addPluginAction,	&QAction::triggered,
Signature · 1 line
2.19.1