Skip to contentSkip to conversation

trace-cmd: Load trace-cmd plugins from build folder, if exists

PATCH Superseded Tzvetomir Stoyanov 1 participant 1 message Apr 19, 2019 Kbuild

v1 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 trace-cmd: Load trace-cmd plugins from build folder, if exists

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.
In case there is a legacy trace-cmd version already installed, there will be a collision with the development version. Wrong, incompatible plugins will be loaded. To simplify the development process, a new logic is added:
On trace-cmd build stage, the full build path is stored in the trace-cmd binary. When the application is started, it checks if this build directory exists and loads only plugins from it.

---
 Makefile                   |  2 ++
 lib/trace-cmd/trace-util.c | 10 ++++++++++
 2 files changed, 12 insertions(+)
Makefile +2 -0
index cde45f8..534d882 100644
@@ -207,6 +207,8 @@ LDFLAGS ?=
 export CFLAGS
 export INCLUDES
 
+override CFLAGS += -DBUILD_PLUGIN_PATH="\"$(shell $(shell which pwd))/plugins"\"
+
 # Required CFLAGS
 override CFLAGS += -D_GNU_SOURCE
 
lib/trace-cmd/trace-util.c +10 -0
index 8d21fb2..ea4f430 100644
@@ -1374,11 +1374,21 @@ int trace_util_load_plugins(struct tep_handle *pevent, const char *suffix,
 	char *home;
 	char *path;
 	char *envdir;
+	struct stat sb;
 	int ret;
 
 	if (tracecmd_disable_plugins)
 		return -EBUSY;
 
+#ifdef BUILD_PLUGIN_PATH
+	if (stat(BUILD_PLUGIN_PATH, &sb) == 0 && S_ISDIR(sb.st_mode)) {
+		trace_util_load_plugins_dir(pevent, suffix, BUILD_PLUGIN_PATH,
+					    load_plugin, data);
+		return 0;
+	}
+#endif
+
+
 /* If a system plugin directory was defined, check that first */
 #ifdef PLUGIN_DIR
 	if (!tracecmd_disable_sys_plugins)
Signature · 1 line
2.20.1