aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTzvetomir Stoyanov <tstoyanov@vmware.com>2019-04-23 17:33:44 +0300
committerSteven Rostedt (VMware) <rostedt@goodmis.org>2019-04-24 08:48:21 -0400
commita8faf36eae170f02f3ec2445538c74a90bba61bf (patch)
treecf58e6430818b0d5699b74df595ec868b92dd395
parent93ee67da48016b9f645748eb5961ff890ee33937 (diff)
downloadtrace-cmd-a8faf36eae170f02f3ec2445538c74a90bba61bf.tar.gz
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. 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. Link: http://lore.kernel.org/linux-trace-devel/20190423143344.30645-1-tstoyanov@vmware.com Reviewed-by: Slavomir Kaslev <kaslevs@vmware.com> Signed-off-by: Tzvetomir Stoyanov <tstoyanov@vmware.com> Signed-off-by: Steven Rostedt (VMware) <rostedt@goodmis.org>
-rw-r--r--lib/trace-cmd/trace-util.c29
1 files changed, 29 insertions, 0 deletions
diff --git a/lib/trace-cmd/trace-util.c b/lib/trace-cmd/trace-util.c
index 8d21fb22..190cf746 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;
}