<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<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>Hihi, Kienan,</p>
<p>I finally find a workaround. I could success with the following code:<br>
<table class="x_code x_js-syntax-highlight x_blameDetail">
<tbody>
<tr class="x_line_holder" id="x_L27">
<td class="x_line_content"><span class="x_n">file_name</span> <span class="x_o">=</span>
<span class="x_sh">"</span><span class="x_s">bt_plugin_latency_filter.py</span><span class="x_sh">"</span>
</td>
</tr>
<tr class="x_line_holder" id="x_L28">
<td class="x_blame-container"><span class="x_n">current_directory</span><span class="x_o">=</span><span class="x_n">os</span><span class="x_p">.</span><span class="x_nf">getcwd</span><span class="x_p">()</span><br>
</td>
</tr>
</tbody>
</table>
<table class="x_code x_js-syntax-highlight x_blameDetail">
<tbody>
<tr class="x_line_holder" id="x_L28">
<td class="x_line_content"><span class="x_n">file_path</span> <span class="x_o">=</span>
<span class="x_n">os</span><span class="x_p">.</span><span class="x_n">path</span><span class="x_p">.</span><span class="x_nf">join</span><span class="x_p">(</span><span class="x_n">current_directory</span><span class="x_p">,</span>
<span class="x_n">file_name</span><span class="x_p">)</span> </td>
</tr>
<tr class="x_line_holder" id="x_L29">
<td class="x_blame-container"><span class="x_n">pset</span><span class="x_o">=</span><span class="x_n">bt2</span><span class="x_p">.</span><span class="x_nf">find_plugins_in_path</span><span class="x_p">(</span><span class="x_n">file_path</span><span class="x_p">)</span><br>
</td>
</tr>
</tbody>
</table>
<table class="x_code x_js-syntax-highlight x_blameDetail">
<tbody>
<tr class="x_line_holder" id="x_L29">
<td class="x_line_content"><span class="x_p"></span><span class="x_k">for</span><span class="x_n">plugin</span><span class="x_ow">in</span><span class="x_n">pset</span><span class="x_p">:</span><br>
</td>
</tr>
<tr class="x_line_holder" id="x_L30">
<td class="x_blame-container"><span class="x_k">if </span><span class="x_n">plugin</span><span class="x_p">.</span><span class="x_n">name</span><span class="x_o">==</span><span class="x_sh">"</span><span class="x_s">latency_filter</span><span class="x_sh">"</span><span class="x_ow">and</span><span class="x_nf">
 hasattr</span><span class="x_p">(</span><span class="x_n">plugin</span><span class="x_p">,</span><span class="x_sh">"</span><span class="x_s">filter_component_classes</span><span class="x_sh">"</span><span class="x_p">):</span><br>
</td>
</tr>
</tbody>
</table>
<table class="x_code x_js-syntax-highlight x_blameDetail">
<tbody>
<tr class="x_line_holder" id="x_L30">
<td class="x_line_content">  <span class="x_p"></span>  <span class="x_n">latency_filter_comp_cls</span><span class="x_o">=</span><span class="x_n">plugin</span><span class="x_p">.</span><span class="x_n">filter_component_classes</span><span class="x_p">[</span><span class="x_sh">'</span><span class="x_s">LatencyFilter</span><span class="x_sh">'</span><span class="x_p">]</span><br>
</td>
</tr>
<tr class="x_line_holder" id="x_L31">
<td class="x_blame-container"><br>
</td>
</tr>
</tbody>
</table>
<table class="x_code x_js-syntax-highlight x_blameDetail">
<tbody>
<tr class="x_line_holder" id="x_L31">
<td class="x_line_content">
<table class="x_code x_js-syntax-highlight x_blameDetail">
<tbody>
<tr class="x_line_holder" id="x_L27">
<td class="x_blame-container" rowspan="1">But loading the whole directory, it just doesnt work from command line.<br>
</td>
</tr>
<tr class="x_line_holder" id="x_L27">
<td class="x_blame-container" rowspan="1">Amanda<br>
</td>
</tr>
</tbody>
</table>
<br>
</td>
</tr>
<tr class="x_line_holder" id="x_L32">
<td class="x_blame-container"><br>
</td>
</tr>
</tbody>
</table>
<table class="x_code x_js-syntax-highlight x_blameDetail">
<tbody>
<tr class="x_line_holder" id="x_L26">
<td class="x_line_content"><br>
</td>
</tr>
<tr class="x_line_holder" id="x_L27">
<td class="x_blame-container"><br>
</td>
</tr>
<tr class="x_line_holder" id="x_L27">
<td class="x_blame-container" rowspan="1"><br>
</td>
</tr>
<tr class="x_line_holder" id="x_L27">
<td class="x_blame-container" rowspan="1"><br>
</td>
</tr>
</tbody>
</table>
<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> Kienan Stewart <kstewart@efficios.com><br>
<b>Sent:</b> Thursday, April 25, 2024 11:43:05 PM<br>
<b>To:</b> Wu, Yannan; 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>
My apologies,<br>
<br>
there is a typo in my previous e-mail, the library directory should be:<br>
<br>
`<libdir>/babeltrace2/plugin-providers/'<br>
<br>
thanks,<br>
kienan<br>
<br>
On 4/25/24 11:41 AM, Kienan Stewart via lttng-dev wrote:<br>
> Hi Amanda,<br>
><br>
> could you double-check to ensure that babeltrace2 was built with<br>
> `--enable-python-plugins`, and that `import bt2` works?<br>
><br>
> There should be a babeltrace2-python-plugin-provider.so in<br>
> `<libdir>/babeltrace2/plugin-provides`<br>
><br>
> thanks,<br>
> kienan<br>
><br>
><br>
> On 4/24/24 11:28 PM, Wu, Yannan via lttng-dev wrote:<br>
>> Hi, There,<br>
>><br>
>> I am trying to construct a customized filter and sink based on<br>
>> babeltrace2 python binding. However, nether mine plugin nor the<br>
>> plugins sample I could find on the internet all dont work.<br>
>><br>
>> For example,<br>
>> <a href="https://github.com/simark/babeltrace-fun-plugins/tree/master/my-first-components">
https://github.com/simark/babeltrace-fun-plugins/tree/master/my-first-components</a> <<a href="https://github.com/simark/babeltrace-fun-plugins/tree/master/my-first-components">https://github.com/simark/babeltrace-fun-plugins/tree/master/my-first-components</a>><br>
>><br>
>> I just downloaded the py file and run the exact command, it failed.<br>
>> The log is as following:<br>
>><br>
>><br>
>> babeltrace2 --plugin-path . -c source.demo.MyFirstSource -c<br>
>> sink.demo.MyFirstSink<br>
>> 04-24 16:52:04.349 919805 919805 E CLI<br>
>> add_descriptor_to_component_descriptor_set@babeltrace2.c:1720 Cannot<br>
>> find component class: plugin-name="demo",<br>
>> comp-cls-name="MyFirstSource", comp-cls-type=1<br>
>> 04-24 16:52:04.349 919805 919805 E CLI<br>
>> cmd_run_ctx_init@babeltrace2.c:1882 Cannot find an operative message<br>
>> interchange protocol version to use to create the `run` command's<br>
>> graph: status=ERROR<br>
>> 04-24 16:52:04.349 919805 919805 E CLI cmd_run@babeltrace2.c:2465<br>
>> Cannot initialize the command's context.<br>
>><br>
>> ERROR:    [Babeltrace CLI] (babeltrace2.c:2465)<br>
>>    Cannot initialize the command's context.<br>
>> CAUSED BY [Babeltrace CLI] (babeltrace2.c:1882)<br>
>>    Cannot find an operative message interchange protocol version to<br>
>> use to create the `run` command's graph: status=ERROR<br>
>> CAUSED BY [Babeltrace CLI] (babeltrace2.c:1720)<br>
>>    Cannot find component class: plugin-name="demo",<br>
>> comp-cls-name="MyFirstSource", comp-cls-type=1<br>
>><br>
>> babeltrace2 --version<br>
>> Babeltrace 2.0.7 "Amqui" [v2.0.6-1-g825a0ed6d]<br>
>><br>
>> Amqui (/ɒmkwiː/) is a town in eastern Québec, Canada, at the base of<br>
>> the Gaspé peninsula in Bas-Saint-Laurent. Located at the<br>
>> confluence of the Humqui and Matapédia Rivers, its proximity to<br>
>> woodlands makes it a great destination for outdoor activities such as<br>
>> camping, hiking, and mountain biking.<br>
>> yannanwu@ue91e96f2951b5c:~/trees/lttng_test_run$<br>
>><br>
>> Is the cli changed or something? How can I make it right?<br>
>><br>
>> Besides, is it possible we create a pipeline in python and make use<br>
>> the the python drafted plugin? Can you advise me how?<br>
>><br>
>> Amanda<br>
>><br>
>><br>
>><br>
>> _______________________________________________<br>
>> lttng-dev mailing list<br>
>> lttng-dev@lists.lttng.org<br>
>> <a href="https://lists.lttng.org/cgi-bin/mailman/listinfo/lttng-dev">https://lists.lttng.org/cgi-bin/mailman/listinfo/lttng-dev</a><br>
> _______________________________________________<br>
> lttng-dev mailing list<br>
> lttng-dev@lists.lttng.org<br>
> <a href="https://lists.lttng.org/cgi-bin/mailman/listinfo/lttng-dev">https://lists.lttng.org/cgi-bin/mailman/listinfo/lttng-dev</a><br>
</div>
</span></font>
</body>
</html>