From: Tzvetomir Stoyanov <tstoyanov@vmware.com>
To: rostedt@goodmis.org
Cc: linux-trace-devel@vger.kernel.org
Subject: [PATCH v3] trace-cmd: Load trace-cmd plugins from build folder, if exists
Date: Tue, 23 Apr 2019 17:33:44 +0300 [thread overview]
Message-ID: <20190423143344.30645-1-tstoyanov@vmware.com> (raw)
[
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
next reply other threads:[~2019-04-23 14:33 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-04-23 14:33 Tzvetomir Stoyanov [this message]
2019-04-23 14:58 ` [PATCH v3] trace-cmd: Load trace-cmd plugins from build folder, if exists Steven Rostedt
2019-04-23 15:02 ` Steven Rostedt
2019-04-23 15:08 ` Slavomir Kaslev
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20190423143344.30645-1-tstoyanov@vmware.com \
--to=tstoyanov@vmware.com \
--cc=linux-trace-devel@vger.kernel.org \
--cc=rostedt@goodmis.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).