lttng-dev Archive mirror
 help / color / mirror / Atom feed
From: "Wu, Yannan via lttng-dev" <lttng-dev@lists.lttng.org>
To: Simon Marchi <simark@simark.ca>,
	Kienan Stewart <kstewart@efficios.com>,
	"lttng-dev@lists.lttng.org" <lttng-dev@lists.lttng.org>
Subject: Re: [lttng-dev] [babeltrace2]about python self-defined plugin loading
Date: Fri, 26 Apr 2024 15:33:03 +0000	[thread overview]
Message-ID: <4e5fe0af4bdf4c8dbbfcf63af9e55bfa@amazon.com> (raw)
In-Reply-To: <52708661-b095-4f23-bfc7-9eb8c89f0cbe@simark.ca>


[-- Attachment #1.1: Type: text/plain, Size: 2812 bytes --]

ok thanks for the help. I will try it later

Amanda

________________________________
From: Simon Marchi <simark@simark.ca>
Sent: Friday, April 26, 2024 10:57:59 PM
To: Wu, Yannan; Kienan Stewart; lttng-dev@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

[-- Attachment #1.2: Type: text/html, Size: 4265 bytes --]

[-- Attachment #2: Type: text/plain, Size: 156 bytes --]

_______________________________________________
lttng-dev mailing list
lttng-dev@lists.lttng.org
https://lists.lttng.org/cgi-bin/mailman/listinfo/lttng-dev

      reply	other threads:[~2024-04-26 15:33 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-04-25  3:28 [lttng-dev] [babeltrace2]about python self-defined plugin loading Wu, Yannan via lttng-dev
2024-04-25 15:41 ` Kienan Stewart via lttng-dev
2024-04-25 15:43   ` Kienan Stewart via lttng-dev
2024-04-26 13:56     ` Wu, Yannan via lttng-dev
2024-04-26 14:57       ` Simon Marchi via lttng-dev
2024-04-26 15:33         ` Wu, Yannan via lttng-dev [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=4e5fe0af4bdf4c8dbbfcf63af9e55bfa@amazon.com \
    --to=lttng-dev@lists.lttng.org \
    --cc=kstewart@efficios.com \
    --cc=simark@simark.ca \
    --cc=yannanwu@amazon.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).