From a8faf36eae170f02f3ec2445538c74a90bba61bf Mon Sep 17 00:00:00 2001 From: Tzvetomir Stoyanov Date: Tue, 23 Apr 2019 17:33:44 +0300 Subject: 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 Signed-off-by: Tzvetomir Stoyanov Signed-off-by: Steven Rostedt (VMware) --- 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 8d21fb22..190cf746 100644 --- a/lib/trace-cmd/trace-util.c +++ b/lib/trace-cmd/trace-util.c @@ -14,6 +14,7 @@ #include #include #include +#include #include #include #include @@ -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; } -- cgit 1.2.3-korg