Skip to content

Commit 4d70cae

Browse files
tzstoyanovacmel
authored andcommitted
tools lib traceevent: Introduced new traceevent API, for adding new plugins directories.
Implement new traceevent plugin API, which can be used to add new plugins directories: enum tep_plugin_load_priority { TEP_PLUGIN_FIRST, TEP_PLUGIN_LAST, }; int tep_add_plugin_path(struct tep_handle *tep, char *path, enum tep_plugin_load_priority prio); It adds the "path" as new plugin directory, in the context of the handler "tep". The tep_load_plugins() API searches for plugins in this new location. Depending of the priority "prio", the plugins from this directory are loaded before (TEP_PLUGIN_FIRST) or after (TEP_PLUGIN_LAST) the ordinary libtraceevent plugin locations. Link: http://lore.kernel.org/linux-trace-devel/20191007114947.17104-2-tz.stoyanov@gmail.com Link: http://lore.kernel.org/linux-trace-devel/20200625100516.365338-6-tz.stoyanov@gmail.com Signed-off-by: Tzvetomir Stoyanov (VMware) <tz.stoyanov@gmail.com> Cc: Andrew Morton <akpm@linux-foundation.org> Cc: Jiri Olsa <jolsa@redhat.com> Cc: Namhyung Kim <namhyung@kernel.org> Cc: linux-trace-devel@vger.kernel.org Link: http://lore.kernel.org/lkml/20200702185704.248123446@goodmis.org Signed-off-by: Steven Rostedt (VMware) <rostedt@goodmis.org> Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
1 parent 7400628 commit 4d70cae

4 files changed

Lines changed: 82 additions & 1 deletion

File tree

‎tools/lib/traceevent/event-parse-local.h‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ struct func_map;
1313
struct func_list;
1414
struct event_handler;
1515
struct func_resolver;
16+
struct tep_plugins_dir;
1617

1718
struct tep_handle {
1819
int ref_count;
@@ -47,7 +48,6 @@ struct tep_handle {
4748
struct printk_list *printklist;
4849
unsigned int printk_count;
4950

50-
5151
struct tep_event **events;
5252
int nr_events;
5353
struct tep_event **sort_events;
@@ -81,10 +81,13 @@ struct tep_handle {
8181

8282
/* cache */
8383
struct tep_event *last_event;
84+
85+
struct tep_plugins_dir *plugins_dir;
8486
};
8587

8688
void tep_free_event(struct tep_event *event);
8789
void tep_free_format_field(struct tep_format_field *field);
90+
void tep_free_plugin_paths(struct tep_handle *tep);
8891

8992
unsigned short tep_data2host2(struct tep_handle *tep, unsigned short data);
9093
unsigned int tep_data2host4(struct tep_handle *tep, unsigned int data);

‎tools/lib/traceevent/event-parse.c‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7119,6 +7119,7 @@ void tep_free(struct tep_handle *tep)
71197119
free(tep->events);
71207120
free(tep->sort_events);
71217121
free(tep->func_resolver);
7122+
tep_free_plugin_paths(tep);
71227123

71237124
free(tep);
71247125
}

‎tools/lib/traceevent/event-parse.h‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -393,6 +393,13 @@ struct tep_plugin_list;
393393

394394
#define INVALID_PLUGIN_LIST_OPTION ((char **)((unsigned long)-1))
395395

396+
enum tep_plugin_load_priority {
397+
TEP_PLUGIN_FIRST,
398+
TEP_PLUGIN_LAST,
399+
};
400+
401+
int tep_add_plugin_path(struct tep_handle *tep, char *path,
402+
enum tep_plugin_load_priority prio);
396403
struct tep_plugin_list *tep_load_plugins(struct tep_handle *tep);
397404
void tep_unload_plugins(struct tep_plugin_list *plugin_list,
398405
struct tep_handle *tep);

‎tools/lib/traceevent/event-plugin.c‎

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,12 @@ struct tep_plugin_list {
3939
void *handle;
4040
};
4141

42+
struct tep_plugins_dir {
43+
struct tep_plugins_dir *next;
44+
char *path;
45+
enum tep_plugin_load_priority prio;
46+
};
47+
4248
static void lower_case(char *str)
4349
{
4450
if (!str)
@@ -544,6 +550,7 @@ void tep_load_plugins_hook(struct tep_handle *tep, const char *suffix,
544550
void *data),
545551
void *data)
546552
{
553+
struct tep_plugins_dir *dir = NULL;
547554
char *home;
548555
char *path;
549556
char *envdir;
@@ -552,6 +559,15 @@ void tep_load_plugins_hook(struct tep_handle *tep, const char *suffix,
552559
if (tep && tep->flags & TEP_DISABLE_PLUGINS)
553560
return;
554561

562+
if (tep)
563+
dir = tep->plugins_dir;
564+
while (dir) {
565+
if (dir->prio == TEP_PLUGIN_FIRST)
566+
load_plugins_dir(tep, suffix, dir->path,
567+
load_plugin, data);
568+
dir = dir->next;
569+
}
570+
555571
/*
556572
* If a system plugin directory was defined,
557573
* check that first.
@@ -586,6 +602,15 @@ void tep_load_plugins_hook(struct tep_handle *tep, const char *suffix,
586602

587603
load_plugins_dir(tep, suffix, path, load_plugin, data);
588604

605+
if (tep)
606+
dir = tep->plugins_dir;
607+
while (dir) {
608+
if (dir->prio == TEP_PLUGIN_LAST)
609+
load_plugins_dir(tep, suffix, dir->path,
610+
load_plugin, data);
611+
dir = dir->next;
612+
}
613+
589614
free(path);
590615
}
591616

@@ -598,6 +623,51 @@ tep_load_plugins(struct tep_handle *tep)
598623
return list;
599624
}
600625

626+
/**
627+
* tep_add_plugin_path - Add a new plugin directory.
628+
* @tep: Trace event handler.
629+
* @path: Path to a directory. All files with extension .so in that
630+
* directory will be loaded as plugins.
631+
*@prio: Load priority of the plugins in that directory.
632+
*
633+
* Returns -1 in case of an error, 0 otherwise.
634+
*/
635+
int tep_add_plugin_path(struct tep_handle *tep, char *path,
636+
enum tep_plugin_load_priority prio)
637+
{
638+
struct tep_plugins_dir *dir;
639+
640+
if (!tep || !path)
641+
return -1;
642+
643+
dir = calloc(1, sizeof(*dir));
644+
if (!dir)
645+
return -1;
646+
647+
dir->path = strdup(path);
648+
dir->prio = prio;
649+
dir->next = tep->plugins_dir;
650+
tep->plugins_dir = dir;
651+
652+
return 0;
653+
}
654+
655+
void tep_free_plugin_paths(struct tep_handle *tep)
656+
{
657+
struct tep_plugins_dir *dir;
658+
659+
if (!tep)
660+
return;
661+
662+
dir = tep->plugins_dir;
663+
while (dir) {
664+
tep->plugins_dir = tep->plugins_dir->next;
665+
free(dir->path);
666+
free(dir);
667+
dir = tep->plugins_dir;
668+
}
669+
}
670+
601671
void
602672
tep_unload_plugins(struct tep_plugin_list *plugin_list, struct tep_handle *tep)
603673
{

0 commit comments

Comments
 (0)