diff mbox series

[v2,3/8] kernel-shark: Add logic for the plugins search path

Message ID 20190502124009.32208-4-ykaradzhov@vmware.com (mailing list archive)
State Superseded
Headers show
Series Modifications needed for KS 1.0 | expand

Commit Message

Yordan Karadzhov May 2, 2019, 12:40 p.m. UTC
If the application has not been started from its installation location
and the the directory

 app_file_path + "../../kernel-shark/lib"

exists, all build-in plugins will be loaded from this directory. In any
other case all build-in plugins will be loaded from

_INSTALL_PREFIX/lib/kshark/plugins/

Suggested-by: Steven Rostedt (VMware) <rostedt@goodmis.org>
Reviewed-by: Slavomir Kaslev <kaslevs@vmware.com>
Signed-off-by: Yordan Karadzhov <ykaradzhov@vmware.com>
---
 kernel-shark/src/KsUtils.cpp            | 40 ++++++++++++++++++-------
 kernel-shark/src/KsUtils.hpp            |  2 ++
 kernel-shark/src/plugins/CMakeLists.txt |  2 +-
 3 files changed, 32 insertions(+), 12 deletions(-)

Comments

Steven Rostedt May 3, 2019, 11:05 p.m. UTC | #1
On Thu,  2 May 2019 15:40:04 +0300
Yordan Karadzhov <ykaradzhov@vmware.com> wrote:

> If the application has not been started from its installation location
> and the the directory
> 
>  app_file_path + "../../kernel-shark/lib"
> 
> exists, all build-in plugins will be loaded from this directory. In any
> other case all build-in plugins will be loaded from
> 
> _INSTALL_PREFIX/lib/kshark/plugins/
> 
> Suggested-by: Steven Rostedt (VMware) <rostedt@goodmis.org>
> Reviewed-by: Slavomir Kaslev <kaslevs@vmware.com>
> Signed-off-by: Yordan Karadzhov <ykaradzhov@vmware.com>
> ---
>  kernel-shark/src/KsUtils.cpp            | 40 ++++++++++++++++++-------
>  kernel-shark/src/KsUtils.hpp            |  2 ++
>  kernel-shark/src/plugins/CMakeLists.txt |  2 +-
>  3 files changed, 32 insertions(+), 12 deletions(-)
> 

Hi Yordan,

After applying this patch, kernelshark's behavior for loading trace.dat
changed. It no longer looks for the file in the current directory. If I
run:

 # trace-cmd record -e sched_switch sleep 1
 # kernelshark

It loads without loading the produced trace.dat.

If I run:

 # kernelshark trace.dat

I get an error message stating:

 "Unable to find file trace.dat"

-- Steve
Yordan Karadzhov May 4, 2019, 8:27 a.m. UTC | #2
On 4.05.19 г. 2:05 ч., Steven Rostedt wrote:
> On Thu,  2 May 2019 15:40:04 +0300
> Yordan Karadzhov <ykaradzhov@vmware.com> wrote:
> 
>> If the application has not been started from its installation location
>> and the the directory
>>
>>   app_file_path + "../../kernel-shark/lib"
>>
>> exists, all build-in plugins will be loaded from this directory. In any
>> other case all build-in plugins will be loaded from
>>
>> _INSTALL_PREFIX/lib/kshark/plugins/
>>
>> Suggested-by: Steven Rostedt (VMware) <rostedt@goodmis.org>
>> Reviewed-by: Slavomir Kaslev <kaslevs@vmware.com>
>> Signed-off-by: Yordan Karadzhov <ykaradzhov@vmware.com>
>> ---
>>   kernel-shark/src/KsUtils.cpp            | 40 ++++++++++++++++++-------
>>   kernel-shark/src/KsUtils.hpp            |  2 ++
>>   kernel-shark/src/plugins/CMakeLists.txt |  2 +-
>>   3 files changed, 32 insertions(+), 12 deletions(-)
>>
> 
> Hi Yordan,
> 
> After applying this patch, kernelshark's behavior for loading trace.dat
> changed. It no longer looks for the file in the current directory. If I
> run:
> 
>   # trace-cmd record -e sched_switch sleep 1
>   # kernelshark
> 
> It loads without loading the produced trace.dat.
> 
> If I run:
> 
>   # kernelshark trace.dat
> 
> I get an error message stating:
> 
>   "Unable to find file trace.dat"

I see the problem. Have you pushed this patch already? I can send you a 
corrected version of the patch or a separate patch with the fix.

Thanks!
Yordan

> 
> -- Steve
>
Yordan Karadzhov May 4, 2019, 8:28 a.m. UTC | #3
On 4.05.19 г. 2:05 ч., Steven Rostedt wrote:
> On Thu,  2 May 2019 15:40:04 +0300
> Yordan Karadzhov <ykaradzhov@vmware.com> wrote:
> 
>> If the application has not been started from its installation location
>> and the the directory
>>
>>   app_file_path + "../../kernel-shark/lib"
>>
>> exists, all build-in plugins will be loaded from this directory. In any
>> other case all build-in plugins will be loaded from
>>
>> _INSTALL_PREFIX/lib/kshark/plugins/
>>
>> Suggested-by: Steven Rostedt (VMware) <rostedt@goodmis.org>
>> Reviewed-by: Slavomir Kaslev <kaslevs@vmware.com>
>> Signed-off-by: Yordan Karadzhov <ykaradzhov@vmware.com>
>> ---
>>   kernel-shark/src/KsUtils.cpp            | 40 ++++++++++++++++++-------
>>   kernel-shark/src/KsUtils.hpp            |  2 ++
>>   kernel-shark/src/plugins/CMakeLists.txt |  2 +-
>>   3 files changed, 32 insertions(+), 12 deletions(-)
>>
> 
> Hi Yordan,
> 
> After applying this patch, kernelshark's behavior for loading trace.dat
> changed. It no longer looks for the file in the current directory. If I
> run:
> 
>   # trace-cmd record -e sched_switch sleep 1
>   # kernelshark
> 
> It loads without loading the produced trace.dat.
> 
> If I run:
> 
>   # kernelshark trace.dat
> 
> I get an error message stating:
> 
>   "Unable to find file trace.dat"

I see the problem. Have you pushed this patch already? I can send you a 
corrected version of the patch or a separate patch with the fix.

Thanks!
Yordan

> 
> -- Steve
>
Steven Rostedt May 4, 2019, 11:31 a.m. UTC | #4
On May 4, 2019 4:27:47 AM EDT, "Yordan Karadzhov (VMware)" <y.karadz@gmail.com> wrote:
>
>I see the problem. Have you pushed this patch already? I can send you a
>
>corrected version of the patch or a separate patch with the fix.
>


I have not pushed yet. Please send a new version of this patch.

Thanks,

-- Steve
diff mbox series

Patch

diff --git a/kernel-shark/src/KsUtils.cpp b/kernel-shark/src/KsUtils.cpp
index 8c42206..f62e53a 100644
--- a/kernel-shark/src/KsUtils.cpp
+++ b/kernel-shark/src/KsUtils.cpp
@@ -544,13 +544,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;
 
@@ -579,13 +578,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;
 
@@ -608,6 +606,28 @@  void KsPluginManager::unregisterFromList(kshark_context *kshark_ctx)
 			lamUregUser);
 }
 
+char *KsPluginManager::_pluginLibFromName(const QString &plugin, int &n)
+{
+	QString execPath = QCoreApplication::applicationFilePath();
+	QString path = QFileInfo(execPath).path();
+	std::string pluginStr = plugin.toStdString();
+	char *lib;
+	QDir dir;
+
+	dir.setCurrent(path);
+	if (!KsUtils::isInstalled() && dir.cd("../../kernel-shark/lib")) {
+		std::string pathStr = dir.path().toStdString();
+
+		n = asprintf(&lib, "%s/plugin-%s.so",
+			     pathStr.c_str(), 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.
  *
@@ -629,8 +649,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;
@@ -691,8 +710,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;
@@ -700,7 +718,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 7b80b21..1c87271 100644
--- a/kernel-shark/src/KsUtils.hpp
+++ b/kernel-shark/src/KsUtils.hpp
@@ -241,6 +241,8 @@  signals:
 private:
 	void _parsePluginList();
 
+	char *_pluginLibFromName(const QString &plugin, int &n);
+
 	template <class T>
 	void _forEachInList(const QStringList &pl,
 			    const QVector<bool> &reg,
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)