trace-cmd: Load trace-cmd plugins from build folder, if exists
PATCH v3 1/1 trace-cmd: Load trace-cmd plugins from build folder, if exists
[
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.
--- lib/trace-cmd/trace-util.c | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+)
lib/trace-cmd/trace-util.c +29 -0
@@ -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 ; }
Signature · 1 line
2.20.1
Quoted 9 lines · On Tue, 23 Apr 2019 17:33:44 +0300 Tzvetomir Stoyanov <[email protected]>…
[
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.
]
Hi Tzvetomir,
FYI, change versions should go below the three dashes "---" under the Signed-off-by, as that will keep them from being added to the git logs. Patch change versions are only for reviewers information not for git history.
Other than that, the patch looks fine.
Thanks!
-- Steve
Quoted 72 lines
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 inTRACEEVENT_PLUGIN_DIRenvironment 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 <[email protected]>--- lib/trace-cmd/trace-util.c | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+)lib/trace-cmd/trace-util.c +29
-0@@ -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 ; }
Quoted 10 lines · On Tue, 23 Apr 2019 17:33:44 +0300 Tzvetomir Stoyanov <[email protected]>…
[
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.
]
Quoted 12 lines
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 inTRACEEVENT_PLUGIN_DIRenvironment 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.
Slavomir,
Can you review this patch, and if it looks good to you, add your "Reviewed-by"?
Thanks!
-- Steve
Quoted 59 lines
Signed-off-by Tzvetomir Stoyanov <[email protected]>--- lib/trace-cmd/trace-util.c | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+)lib/trace-cmd/trace-util.c +29
-0@@ -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 ; }
Slavomir Kaslev
Reviewed-byQuoted 4 lines · Steven Rostedt
Slavomir,
Can you review this patch, and if it looks good to you, add your "Reviewed-by"?
Sure, tried it locally and seems to be working correctly
Cheers,
-- Slavi