All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Tzvetomir Stoyanov (VMware)" <tz.stoyanov@gmail.com>
To: rostedt@goodmis.org
Cc: linux-trace-devel@vger.kernel.org
Subject: [PATCH v2 5/6] trace-cmd: Load libtraceevent plugins from build folder, if exists.
Date: Fri,  2 Aug 2019 14:01:00 +0300	[thread overview]
Message-ID: <20190802110101.14759-6-tz.stoyanov@gmail.com> (raw)
In-Reply-To: <20190802110101.14759-1-tz.stoyanov@gmail.com>

When a development version of trace-cmd is built and run on the machine,
by default it loads only installed plugins, from system drierctories.
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 (VMware) <tz.stoyanov@gmail.com>
---
 lib/traceevent/event-plugin.c | 28 ++++++++++++++++++++++++++++
 1 file changed, 28 insertions(+)

diff --git a/lib/traceevent/event-plugin.c b/lib/traceevent/event-plugin.c
index bc10205..fdaadba 100644
--- a/lib/traceevent/event-plugin.c
+++ b/lib/traceevent/event-plugin.c
@@ -14,6 +14,7 @@
 #include <unistd.h>
 #include <dirent.h>
 #include <errno.h>
+#include <libgen.h>
 #include "event-parse.h"
 #include "event-parse-local.h"
 #include "event-utils.h"
@@ -538,6 +539,27 @@ load_plugins_dir(struct tep_handle *tep, const char *suffix,
 	closedir(dir);
 }
 
+static char *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/traceevent");
+	return strdup(path);
+}
+
 void tep_load_plugins_hook(struct tep_handle *tep, const char *suffix,
 			   void (*load_plugin)(struct tep_handle *tep,
 					       const char *path,
@@ -588,6 +610,12 @@ void tep_load_plugins_hook(struct tep_handle *tep, const char *suffix,
 	load_plugins_dir(tep, suffix, path, load_plugin, data);
 
 	free(path);
+
+	path = get_source_plugins_dir();
+	if (path) {
+		load_plugins_dir(tep, suffix, path, load_plugin, data);
+		free(path);
+	}
 }
 
 struct tep_plugin_list*
-- 
2.21.0


  parent reply	other threads:[~2019-08-02 11:01 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-08-02 11:00 [PATCH v2 0/6] Remove redundant trace-cmd plugin handling logic Tzvetomir Stoyanov (VMware)
2019-08-02 11:00 ` [PATCH v2 1/6] trace-cmd: Move kernel_stack event handler to "function" plugin Tzvetomir Stoyanov (VMware)
2019-08-02 11:00 ` [PATCH v2 2/6] trace-cmd: Move plugin options from trace-cmd to libtraceevent Tzvetomir Stoyanov (VMware)
2019-08-02 11:00 ` [PATCH v2 3/6] trace-cmd: Remove trace-cmd plugin handling routines Tzvetomir Stoyanov (VMware)
2019-08-02 11:00 ` [PATCH v2 4/6] trace-cmd: Move libtraceevent plugins in its own directory Tzvetomir Stoyanov (VMware)
2019-08-30 15:23   ` Steven Rostedt
2019-08-02 11:01 ` Tzvetomir Stoyanov (VMware) [this message]
2019-08-02 11:01 ` [PATCH v2 6/6] trace-cmd: Change plugin install directories Tzvetomir Stoyanov (VMware)

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=20190802110101.14759-6-tz.stoyanov@gmail.com \
    --to=tz.stoyanov@gmail.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.