All of lore.kernel.org
 help / color / mirror / Atom feed
From: Yordan Karadzhov <ykaradzhov@vmware.com>
To: rostedt@goodmis.org
Cc: linux-trace-devel@vger.kernel.org, y.karadz@gmail.com,
	Yordan Karadzhov <ykaradzhov@vmware.com>
Subject: [PATCH v3 4/8] kernel-shark: Add logic for the plugins search path
Date: Fri, 19 Apr 2019 16:50:32 +0300	[thread overview]
Message-ID: <20190419135036.19340-5-ykaradzhov@vmware.com> (raw)
In-Reply-To: <20190419135036.19340-1-ykaradzhov@vmware.com>

If the application has been started from the source code directory, all
build-in plugins will be loaded from kernel-shark/lib/
If the application has been started from its installation location, all
build-in plugins will be loaded from INSTALL_PREFIX/lib/kshark/plugins/

Signed-off-by: Yordan Karadzhov <ykaradzhov@vmware.com>
---
 kernel-shark/build/deff.h.cmake         |  3 +++
 kernel-shark/src/KsUtils.cpp            | 35 +++++++++++++++++--------
 kernel-shark/src/KsUtils.hpp            |  1 +
 kernel-shark/src/plugins/CMakeLists.txt |  2 +-
 4 files changed, 29 insertions(+), 12 deletions(-)

diff --git a/kernel-shark/build/deff.h.cmake b/kernel-shark/build/deff.h.cmake
index 8041cfc..ba211f4 100644
--- a/kernel-shark/build/deff.h.cmake
+++ b/kernel-shark/build/deff.h.cmake
@@ -14,6 +14,9 @@
 /** KernelShark source code path. */
 #cmakedefine KS_DIR "@KS_DIR@"
 
+/** KernelShark installation prefix path. */
+#cmakedefine _INSTALL_PREFIX "@_INSTALL_PREFIX@"
+
 /** Location of the trace-cmd executable. */
 #cmakedefine TRACECMD_BIN_DIR "@TRACECMD_BIN_DIR@"
 
diff --git a/kernel-shark/src/KsUtils.cpp b/kernel-shark/src/KsUtils.cpp
index 6af0c66..b05c0dc 100644
--- a/kernel-shark/src/KsUtils.cpp
+++ b/kernel-shark/src/KsUtils.cpp
@@ -423,13 +423,12 @@ void KsPluginManager::_parsePluginList()
  */
 void KsPluginManager::registerFromList(kshark_context *kshark_ctx)
 {
-	auto lamRegBuiltIn = [&kshark_ctx](const QString &plugin)
+	auto lamRegBuiltIn = [&kshark_ctx, this](const QString &plugin)
 	{
 		char *lib;
 		int n;
 
-		n = asprintf(&lib, "%s/lib/plugin-%s.so",
-			     KS_DIR, plugin.toStdString().c_str());
+		lib = _pluginLibFromName(plugin, n);
 		if (n <= 0)
 			return;
 
@@ -458,13 +457,12 @@ void KsPluginManager::registerFromList(kshark_context *kshark_ctx)
  */
 void KsPluginManager::unregisterFromList(kshark_context *kshark_ctx)
 {
-	auto lamUregBuiltIn = [&kshark_ctx](const QString &plugin)
+	auto lamUregBuiltIn = [&kshark_ctx, this](const QString &plugin)
 	{
 		char *lib;
 		int n;
 
-		n = asprintf(&lib, "%s/lib/plugin-%s.so",
-			     KS_DIR, plugin.toStdString().c_str());
+		lib = _pluginLibFromName(plugin, n);
 		if (n <= 0)
 			return;
 
@@ -487,6 +485,23 @@ void KsPluginManager::unregisterFromList(kshark_context *kshark_ctx)
 			lamUregUser);
 }
 
+char *KsPluginManager::_pluginLibFromName(const QString &plugin, int &n)
+{
+	QString path = QCoreApplication::applicationFilePath();
+	std::string pluginStr = plugin.toStdString();
+	char *lib;
+
+	if (path.contains(KS_DIR)) {
+		n = asprintf(&lib, "%s/lib/plugin-%s.so",
+			     KS_DIR, pluginStr.c_str());
+	} else {
+		n = asprintf(&lib, "%s/lib/kshark/plugins/plugin-%s.so",
+			     _INSTALL_PREFIX, pluginStr.c_str());
+	}
+
+	return lib;
+}
+
 /**
  * @brief Register a Plugin.
  *
@@ -508,8 +523,7 @@ void KsPluginManager::registerPlugin(const QString &plugin)
 			 * The argument is the name of the plugin. From the
 			 * name get the library .so file.
 			 */
-			n = asprintf(&lib, "%s/lib/plugin-%s.so",
-					KS_DIR, plugin.toStdString().c_str());
+			lib = _pluginLibFromName(plugin, n);
 			if (n > 0) {
 				kshark_register_plugin(kshark_ctx, lib);
 				_registeredKsPlugins[i] = true;
@@ -570,8 +584,7 @@ void KsPluginManager::unregisterPlugin(const QString &plugin)
 			 * The argument is the name of the plugin. From the
 			 * name get the library .so file.
 			 */
-			n = asprintf(&lib, "%s/lib/plugin-%s.so", KS_DIR,
-				     plugin.toStdString().c_str());
+			lib = _pluginLibFromName(plugin, n);
 			if (n > 0) {
 				kshark_unregister_plugin(kshark_ctx, lib);
 				_registeredKsPlugins[i] = false;
@@ -579,7 +592,7 @@ void KsPluginManager::unregisterPlugin(const QString &plugin)
 			}
 
 			return;
-		} else if  (plugin.contains("/lib/plugin-" +
+		} else if (plugin.contains("/lib/plugin-" +
 			                   _ksPluginList[i], Qt::CaseInsensitive)) {
 			/*
 			 * The argument is the name of the library .so file.
diff --git a/kernel-shark/src/KsUtils.hpp b/kernel-shark/src/KsUtils.hpp
index 77048ab..019bde8 100644
--- a/kernel-shark/src/KsUtils.hpp
+++ b/kernel-shark/src/KsUtils.hpp
@@ -238,6 +238,7 @@ signals:
 
 private:
 	void _parsePluginList();
+	char *_pluginLibFromName(const QString &plugin, int &n);
 
 	template <class T>
 	void _forEachInList(const QStringList &pl,
diff --git a/kernel-shark/src/plugins/CMakeLists.txt b/kernel-shark/src/plugins/CMakeLists.txt
index 6098275..64cf98d 100644
--- a/kernel-shark/src/plugins/CMakeLists.txt
+++ b/kernel-shark/src/plugins/CMakeLists.txt
@@ -29,6 +29,6 @@ BUILD_PLUGIN(NAME missed_events
 list(APPEND PLUGIN_LIST "missed_events default") # This plugin will be loaded by default
 
 install(TARGETS sched_events missed_events
-        LIBRARY DESTINATION ${_INSTALL_PREFIX}/lib/kshark/)
+        LIBRARY DESTINATION ${_INSTALL_PREFIX}/lib/kshark/plugins/)
 
 set(PLUGINS ${PLUGIN_LIST} PARENT_SCOPE)
-- 
2.20.1


  parent reply	other threads:[~2019-04-19 19:19 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-04-19 13:50 [PATCH v3 0/8] Various modifications and fixes toward KS 1.0 Yordan Karadzhov
2019-04-19 13:50 ` [PATCH v3 1/8] kernel-shark: Configuration information in ${HOME}/.cache/kernelshark Yordan Karadzhov
2019-04-19 13:50 ` [PATCH v3 2/8] kernel-shark: Remove the definition of KS_CONF_DIR Yordan Karadzhov
2019-04-19 13:50 ` [PATCH v3 3/8] kernel-shark: Add logic for the initial path of Open-File dialogs Yordan Karadzhov
2019-04-19 16:23   ` Steven Rostedt
2019-04-19 13:50 ` Yordan Karadzhov [this message]
2019-04-19 17:28   ` [PATCH v3 4/8] kernel-shark: Add logic for the plugins search path Steven Rostedt
2019-04-22 11:29     ` Yordan Karadzhov (VMware)
2019-04-22 11:50       ` Steven Rostedt
2019-04-22 12:21         ` Yordan Karadzhov (VMware)
2019-04-19 13:50 ` [PATCH v3 5/8] kernel-shark: Rename KS_DIR to KS_SOURCE_DIR Yordan Karadzhov
2019-04-19 13:50 ` [PATCH v3 6/8] kernel-shark: Load Last Session from command line Yordan Karadzhov
2019-04-19 18:16   ` Steven Rostedt
2019-04-19 13:50 ` [PATCH v3 7/8] kernel-shark: Use proper searching condition when the dataset is small Yordan Karadzhov
2019-04-19 13:50 ` [PATCH v3 8/8] kernel-shark: Handle the case when the marker points to a filtered entry Yordan Karadzhov
2019-04-19 18:13 ` [PATCH v3 0/8] Various modifications and fixes toward KS 1.0 Steven Rostedt

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=20190419135036.19340-5-ykaradzhov@vmware.com \
    --to=ykaradzhov@vmware.com \
    --cc=linux-trace-devel@vger.kernel.org \
    --cc=rostedt@goodmis.org \
    --cc=y.karadz@gmail.com \
    /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.