<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=us-ascii">
<meta name="Generator" content="Microsoft Exchange Server">
<!-- converted from text --><style><!-- .EmailQuote { margin-left: 1pt; padding-left: 4pt; border-left: #800000 2px solid; } --></style>
</head>
<body>
<meta content="text/html; charset=UTF-8">
<style type="text/css" style="">
<!--
p
{margin-top:0;
margin-bottom:0}
-->
</style>
<div dir="ltr">
<div id="x_divtagdefaultwrapper" dir="ltr" style="font-size:12pt; color:#000000; font-family:Calibri,Helvetica,sans-serif">
<p>ok thanks for the help. I will try it later <br>
</p>
<p>Amanda<br>
</p>
</div>
<hr tabindex="-1" style="display:inline-block; width:98%">
<div id="x_divRplyFwdMsg" dir="ltr"><font face="Calibri, sans-serif" color="#000000" style="font-size:11pt"><b>From:</b> Simon Marchi <simark@simark.ca><br>
<b>Sent:</b> Friday, April 26, 2024 10:57:59 PM<br>
<b>To:</b> Wu, Yannan; Kienan Stewart; lttng-dev@lists.lttng.org<br>
<b>Subject:</b> RE: [EXTERNAL] [lttng-dev] [babeltrace2]about python self-defined plugin loading</font>
<div> </div>
</div>
</div>
<font size="2"><span style="font-size:10pt;">
<div class="PlainText">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.<br>
<br>
<br>
<br>
On 2024-04-26 09:56, Wu, Yannan via lttng-dev wrote:<br>
> Hihi, Kienan,<br>
><br>
> I finally find a workaround. I could success with the following code:<br>
> file_name = "bt_plugin_latency_filter.py"<br>
> current_directory=os.getcwd()<br>
><br>
> file_path = os.path.join(current_directory, file_name)<br>
> pset=bt2.find_plugins_in_path(file_path)<br>
><br>
> forplugininpset:<br>
> if plugin.name=="latency_filter"andhasattr(plugin,"filter_component_classes"):<br>
><br>
> latency_filter_comp_cls=plugin.filter_component_classes['LatencyFilter']<br>
><br>
> But loading the whole directory, it just doesnt work from command line.<br>
> Amanda<br>
<br>
So, since this works, it confirms that your babeltrace build has support<br>
for Python plugins. Then there's no reason for your original example<br>
using babeltrace-fun-plugins/my-first-components not to work.<br>
<br>
When running the command:<br>
<br>
babeltrace2 --plugin-path . -c source.demo.MyFirstSource -c sink.demo.MyFirstSink<br>
<br>
is your working directory babeltrace-fun-plugins/my-first-component?<br>
`--plugin-path .` refers to the current working directory, so it must be<br>
the directory that directly contains the `bt_plugin_*.py` file.<br>
<br>
I made an example with docker to show it working, hopefully this can<br>
help you figure out what's wrong on your side. Put this inside a<br>
`Dockerfile` file:<br>
<br>
```<br>
FROM debian:12<br>
<br>
RUN apt-get -y update<br>
RUN apt-get -y full-upgrade<br>
RUN apt-get -y install babeltrace2 git<br>
RUN git clone <a href="https://github.com/simark/babeltrace-fun-plugins.git">https://github.com/simark/babeltrace-fun-plugins.git</a><br>
WORKDIR /babeltrace-fun-plugins/my-first-components<br>
ENTRYPOINT babeltrace2 --plugin-path . -c source.demo.MyFirstSource -c sink.demo.MyFirstSink<br>
```<br>
<br>
Then, do either (whatever works for you):<br>
<br>
$ docker buildx build -t bt2-example .<br>
$ docker build -t bt2-example .<br>
<br>
And finally:<br>
<br>
$ docker run -it bt2-example<br>
Stream beginning<br>
event my-event, timestamp 123<br>
Stream end<br>
<br>
This last command runs babeltrace2, loading the Python plugin from<br>
babeltrace-fun-plugins/my-first-components.<br>
<br>
Finally, to investigate more in depth, you can increase the log level of<br>
babeltrace2, like so:<br>
<br>
$ babeltrace2 --log-level DEBUG --plugin-path . -c source.demo.MyFirstSource -c sink.demo.MyFirstSink<br>
<br>
This will output all sorts of things about babeltrace looking for<br>
plugins and trying to load them.<br>
<br>
Simon<br>
</div>
</span></font>
</body>
</html>