Message ID | 20191002114152.30048-4-tz.stoyanov@gmail.com (mailing list archive) |
---|---|
State | Superseded |
Headers | show |
Series | Remove redundant trace-cmd plugin handling logic | expand |
On Wed, 2 Oct 2019 14:41:50 +0300 "Tzvetomir Stoyanov (VMware)" <tz.stoyanov@gmail.com> wrote: > 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..4fc4ee3 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) Hmm, this is in the lib/libtraceevent directory. We shouldn't be referencing trace-cmd code here. We should have a way to override the plugins from the trace-cmd side, perhaps after tep_load_plugins_hook() gets called? -- Steve > + return NULL; > + > + strcpy(p, "/lib/traceevent/plugins"); > + 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*
On Wed, 2 Oct 2019 14:41:50 +0300 "Tzvetomir Stoyanov (VMware)" <tz.stoyanov@gmail.com> wrote: Also there's a few typos (which I originally fixed before seeing the issue of trace-cmd code in libtraceevent). > When a development version of trace-cmd is built and run on the machine, > by default it loads only installed plugins, from system drierctories. "directories" > 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" > plugins win. > > Signed-off-by: Tzvetomir Stoyanov (VMware) <tz.stoyanov@gmail.com> > -- Steve
On Thu, Oct 3, 2019 at 2:49 AM Steven Rostedt <rostedt@goodmis.org> wrote: > > On Wed, 2 Oct 2019 14:41:50 +0300 > "Tzvetomir Stoyanov (VMware)" <tz.stoyanov@gmail.com> wrote: > > > 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..4fc4ee3 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) > > Hmm, this is in the lib/libtraceevent directory. We shouldn't be > referencing trace-cmd code here. We should have a way to override the > plugins from the trace-cmd side, perhaps after tep_load_plugins_hook() > gets called? > I agree, we should move this check outside of the library. I'll expose the functionality of load_plugins_dir() as a library API. Thanks ! > -- Steve > > > > + return NULL; > > + > > + strcpy(p, "/lib/traceevent/plugins"); > > + 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* >
diff --git a/lib/traceevent/event-plugin.c b/lib/traceevent/event-plugin.c index bc10205..4fc4ee3 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, "/lib/traceevent/plugins"); + 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*
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(+)