Skip to content

Commit 9dc7dc7

Browse files
tzstoyanovacmel
authored andcommitted
libtraceevent: Document tep_load_plugins_hook()
Add description of tep_load_plugins_hook() traceevent API. Updated library man pages with description of the tep_load_plugins_hook() API. Link: https://lore.kernel.org/r/CAM9d7cgLBWCrEHwz+Lhv5x5EXGcNWB0QQoeGh3OKh2JfR=dV9Q@mail.gmail.com Link: https://lore.kernel.org/linux-trace-devel/[email protected] Link: https://lore.kernel.org/linux-trace-devel/[email protected] Suggested-by: Namhyung Kim <[email protected]> Signed-off-by: Tzvetomir Stoyanov (VMware) <[email protected]> Acked-by: Namhyung Kim <[email protected]> Cc: Andrew Morton <[email protected]> Cc: Jiri Olsa <[email protected]> Cc: [email protected] Link: http://lore.kernel.org/lkml/[email protected] Signed-off-by: Steven Rostedt (VMware) <[email protected]> Signed-off-by: Arnaldo Carvalho de Melo <[email protected]>
1 parent 4b0297e commit 9dc7dc7

File tree

2 files changed

+40
-1
lines changed

2 files changed

+40
-1
lines changed

tools/lib/traceevent/Documentation/libtraceevent-plugins.txt

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ libtraceevent(3)
33

44
NAME
55
----
6-
tep_load_plugins, tep_unload_plugins - Load / unload traceevent plugins.
6+
tep_load_plugins, tep_unload_plugins, tep_load_plugins_hook - Load / unload traceevent plugins.
77

88
SYNOPSIS
99
--------
@@ -13,6 +13,12 @@ SYNOPSIS
1313

1414
struct tep_plugin_list pass:[*]*tep_load_plugins*(struct tep_handle pass:[*]_tep_);
1515
void *tep_unload_plugins*(struct tep_plugin_list pass:[*]_plugin_list_, struct tep_handle pass:[*]_tep_);
16+
void *tep_load_plugins_hook*(struct tep_handle pass:[*]_tep_, const char pass:[*]_suffix_,
17+
void (pass:[*]_load_plugin_)(struct tep_handle pass:[*]tep,
18+
const char pass:[*]path,
19+
const char pass:[*]name,
20+
void pass:[*]data),
21+
void pass:[*]_data_);
1622
--
1723

1824
DESCRIPTION
@@ -22,11 +28,13 @@ directories. The _tep_ argument is trace event parser context.
2228
The plugin directories are :
2329
[verse]
2430
--
31+
- Directories, specified in _tep_->plugins_dir with priority TEP_PLUGIN_FIRST
2532
- System's plugin directory, defined at the library compile time. It
2633
depends on the library installation prefix and usually is
2734
_(install_preffix)/lib/traceevent/plugins_
2835
- Directory, defined by the environment variable _TRACEEVENT_PLUGIN_DIR_
2936
- User's plugin directory, located at _~/.local/lib/traceevent/plugins_
37+
- Directories, specified in _tep_->plugins_dir with priority TEP_PLUGIN_LAST
3038
--
3139
Loading of plugins can be controlled by the _tep_flags_, using the
3240
_tep_set_flag()_ API:
@@ -44,6 +52,12 @@ _tep_load_plugins()_. The _tep_ argument is trace event parser context. The
4452
_plugin_list_ is the list of loaded plugins, returned by
4553
the _tep_load_plugins()_ function.
4654

55+
The _tep_load_plugins_hook_ function walks through all directories with plugins
56+
and calls user specified _load_plugin()_ hook for each plugin file. Only files
57+
with given _suffix_ are considered to be plugins. The _data_ is a user specified
58+
context, passed to _load_plugin()_. Directories and the walk order are the same
59+
as in _tep_load_plugins()_ API.
60+
4761
RETURN VALUE
4862
------------
4963
The _tep_load_plugins()_ function returns a list of successfully loaded plugins,
@@ -63,6 +77,15 @@ if (plugins == NULL) {
6377
}
6478
...
6579
tep_unload_plugins(plugins, tep);
80+
...
81+
void print_plugin(struct tep_handle *tep, const char *path,
82+
const char *name, void *data)
83+
{
84+
pritnf("Found libtraceevent plugin %s/%s\n", path, name);
85+
}
86+
...
87+
tep_load_plugins_hook(tep, ".so", print_plugin, NULL);
88+
...
6689
--
6790

6891
FILES

tools/lib/traceevent/event-plugin.c

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -543,6 +543,22 @@ load_plugins_dir(struct tep_handle *tep, const char *suffix,
543543
closedir(dir);
544544
}
545545

546+
/**
547+
* tep_load_plugins_hook - call a user specified callback to load a plugin
548+
* @tep: handler to traceevent context
549+
* @suffix: filter only plugin files with given suffix
550+
* @load_plugin: user specified callback, called for each plugin file
551+
* @data: custom context, passed to @load_plugin
552+
*
553+
* Searches for traceevent plugin files and calls @load_plugin for each
554+
* The order of plugins search is:
555+
* - Directories, specified in @tep->plugins_dir and priority TEP_PLUGIN_FIRST
556+
* - Directory, specified at compile time with PLUGIN_TRACEEVENT_DIR
557+
* - Directory, specified by environment variable TRACEEVENT_PLUGIN_DIR
558+
* - In user's home: ~/.local/lib/traceevent/plugins/
559+
* - Directories, specified in @tep->plugins_dir and priority TEP_PLUGIN_LAST
560+
*
561+
*/
546562
void tep_load_plugins_hook(struct tep_handle *tep, const char *suffix,
547563
void (*load_plugin)(struct tep_handle *tep,
548564
const char *path,

0 commit comments

Comments
 (0)