[lttng-dev] [babeltrace2]about python self-defined plugin loading
Wu, Yannan
yannanwu at amazon.com
Fri Apr 26 11:33:03 EDT 2024
ok thanks for the help. I will try it later
Amanda
________________________________
From: Simon Marchi <simark at simark.ca>
Sent: Friday, April 26, 2024 10:57:59 PM
To: Wu, Yannan; Kienan Stewart; lttng-dev at lists.lttng.org
Subject: RE: [EXTERNAL] [lttng-dev] [babeltrace2]about python self-defined plugin loading
CAUTION: This email originated from outside of the organization. Do not click links or open attachments unless you can confirm the sender and know the content is safe.
On 2024-04-26 09:56, Wu, Yannan via lttng-dev wrote:
> Hihi, Kienan,
>
> I finally find a workaround. I could success with the following code:
> file_name = "bt_plugin_latency_filter.py"
> current_directory=os.getcwd()
>
> file_path = os.path.join(current_directory, file_name)
> pset=bt2.find_plugins_in_path(file_path)
>
> forplugininpset:
> if plugin.name=="latency_filter"andhasattr(plugin,"filter_component_classes"):
>
> latency_filter_comp_cls=plugin.filter_component_classes['LatencyFilter']
>
> But loading the whole directory, it just doesnt work from command line.
> Amanda
So, since this works, it confirms that your babeltrace build has support
for Python plugins. Then there's no reason for your original example
using babeltrace-fun-plugins/my-first-components not to work.
When running the command:
babeltrace2 --plugin-path . -c source.demo.MyFirstSource -c sink.demo.MyFirstSink
is your working directory babeltrace-fun-plugins/my-first-component?
`--plugin-path .` refers to the current working directory, so it must be
the directory that directly contains the `bt_plugin_*.py` file.
I made an example with docker to show it working, hopefully this can
help you figure out what's wrong on your side. Put this inside a
`Dockerfile` file:
```
FROM debian:12
RUN apt-get -y update
RUN apt-get -y full-upgrade
RUN apt-get -y install babeltrace2 git
RUN git clone https://github.com/simark/babeltrace-fun-plugins.git
WORKDIR /babeltrace-fun-plugins/my-first-components
ENTRYPOINT babeltrace2 --plugin-path . -c source.demo.MyFirstSource -c sink.demo.MyFirstSink
```
Then, do either (whatever works for you):
$ docker buildx build -t bt2-example .
$ docker build -t bt2-example .
And finally:
$ docker run -it bt2-example
Stream beginning
event my-event, timestamp 123
Stream end
This last command runs babeltrace2, loading the Python plugin from
babeltrace-fun-plugins/my-first-components.
Finally, to investigate more in depth, you can increase the log level of
babeltrace2, like so:
$ babeltrace2 --log-level DEBUG --plugin-path . -c source.demo.MyFirstSource -c sink.demo.MyFirstSink
This will output all sorts of things about babeltrace looking for
plugins and trying to load them.
Simon
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.lttng.org/pipermail/lttng-dev/attachments/20240426/51e31559/attachment.htm>
More information about the lttng-dev
mailing list