Add dialog for loading user-defined plugins
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
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
@@ -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
@@ -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
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.
Signed-off-by Yordan Karadzhov <[email protected]>--- kernel-shark/src/KsUtils.cpp | 17 +++++++++++++++++ kernel-shark/src/KsUtils.hpp | 3 +++ 2 files changed, 20 insertions(+)kernel-shark/src/KsUtils.cpp +6
-0@@ -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@@ -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
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.
Signed-off-by Yordan Karadzhov <[email protected]>--- kernel-shark/src/KsUtils.cpp | 17 +++++++++++++++++ kernel-shark/src/KsUtils.hpp | 3 +++ 2 files changed, 20 insertions(+)kernel-shark/src/KsUtils.cpp +6
-0@@ -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@@ -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
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
PATCH 2/4 kernel-shark: Add dialog for user-defined plugin to the Tools menu
In reply to Yordan KaradzhovThe 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
@@ -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
@@ -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
PATCH 3/4 kernel-shark: Rename the manu action for managing registered plugins
In reply to Yordan KaradzhovThe 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
@@ -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
@@ -130,7 +130,7 @@ private: QAction _taskSelectAction; // Tools menu. - QAction _pluginsAction; + QAction _managePluginsAction; QAction _addPluginAction;
Signature · 1 line
2.19.1
PATCH 4/4 kernel-shark: Add icons for "Add plugin" and "Manage plugins"
In reply to Yordan KaradzhovJust a small cosmetic improvement.
--- kernel-shark/src/KsMainWindow.cpp | 2 ++ 1 file changed, 2 insertions(+)
kernel-shark/src/KsMainWindow.cpp +2 -0
@@ -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