linux-trace-devel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v3] trace-cmd: Load trace-cmd plugins from build folder, if exists
@ 2019-04-23 14:33 Tzvetomir Stoyanov
  2019-04-23 14:58 ` Steven Rostedt
  2019-04-23 15:02 ` Steven Rostedt
  0 siblings, 2 replies; 4+ messages in thread
From: Tzvetomir Stoyanov @ 2019-04-23 14:33 UTC (permalink / raw)
  To: rostedt; +Cc: linux-trace-devel

[
 v3 changes:
  - Simplified the logic, using standard library functions.
  - Added check to ensure the binary is inside the source tree.
 v2 changes:
  - Removed the logic looking for plugins in the build path.
  - Added logic which gets the full path of the running trace-cmd
    binary and loads plugins from "plugins" directory around it, if exist.
]

When a development version of trace-cmd is built and run on the machine,
by default it loads all plugins from predefined drierctories :
  (install_preffix)/lib/traceevent/plugins
  ~/.traceevent/plugins
  the path specified in TRACEEVENT_PLUGIN_DIR environment variable.
Thus, the development plugins will not be loaded. To simplify the development
process, a new logic is added:
  At plugins load time, check the location of trace-cmd application and look
  for "plugins" directory around it. If found, load plugins from it. Those
  pluigins will be loaded last, so in case of duplication the "development"
  plugins win.

Signed-off-by: Tzvetomir Stoyanov <tstoyanov@vmware.com>
---
 lib/trace-cmd/trace-util.c | 29 +++++++++++++++++++++++++++++
 1 file changed, 29 insertions(+)

diff --git a/lib/trace-cmd/trace-util.c b/lib/trace-cmd/trace-util.c
index 8d21fb2..190cf74 100644
--- a/lib/trace-cmd/trace-util.c
+++ b/lib/trace-cmd/trace-util.c
@@ -14,6 +14,7 @@
 #include <unistd.h>
 #include <ctype.h>
 #include <limits.h>
+#include <libgen.h>
 #include <sys/mount.h>
 #include <sys/types.h>
 #include <sys/stat.h>
@@ -1364,6 +1365,28 @@ static int add_plugin_file(struct tep_handle *pevent, const char *path,
 	return -ENOMEM;
 }
 
+static char *trace_util_get_source_plugins_dir(void)
+{
+	char *p, path[PATH_MAX+1];
+	int ret;
+
+	ret = readlink("/proc/self/exe", path, PATH_MAX);
+	if (ret > PATH_MAX || ret < 0)
+		return NULL;
+
+	dirname(path);
+	p = strrchr(path, '/');
+	if (!p)
+		return NULL;
+	/* Check if we are in the the source tree */
+	if (strcmp(p, "/tracecmd") != 0)
+		return NULL;
+
+	strcpy(p, "/plugins");
+	return strdup(path);
+}
+
+
 int trace_util_load_plugins(struct tep_handle *pevent, const char *suffix,
 			    int (*load_plugin)(struct tep_handle *pevent,
 					       const char *path,
@@ -1404,6 +1427,12 @@ int trace_util_load_plugins(struct tep_handle *pevent, const char *suffix,
 	trace_util_load_plugins_dir(pevent, suffix, path, load_plugin, data);
 
 	free(path);
+
+	path = trace_util_get_source_plugins_dir();
+	if (path) {
+		trace_util_load_plugins_dir(pevent, suffix, path, load_plugin, data);
+		free(path);
+	}
 	return 0;
 }
 
-- 
2.20.1


^ permalink raw reply related	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2019-04-23 15:08 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2019-04-23 14:33 [PATCH v3] trace-cmd: Load trace-cmd plugins from build folder, if exists Tzvetomir Stoyanov
2019-04-23 14:58 ` Steven Rostedt
2019-04-23 15:02 ` Steven Rostedt
2019-04-23 15:08   ` Slavomir Kaslev

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).