[lttng-dev] babeltrace2 python api related question

2022-08-15 Thread zenan via lttng-dev
In command line, I use “babeltrace2 net://somehost/some-session” to read live 
lttng session trace, and I want to use python bindings to do the same, is it 
possible?

here is my code:

import bt2
import sys


# Create an empty graph.
graph = bt2.Graph()


# Add a `source.text.dmesg` component.
#
# graph.add_component() returns the created and added component.
#
# Such a component reads Linux kernel ring buffer messages (see
# `dmesg(1)`) from the standard input and creates corresponding event
# messages. See `babeltrace2-source.text.dmesg(7)`.
#
# `my source` is the unique name of this component within `graph`.


# the original source code here in the example is:
# comp_cls = bt2.find_plugin('text').source_component_classes['dmesg']
# src_comp = graph.add_component(comp_cls,'my source')
comp_cls = bt2.find_plugin('ctf').source_component_classes['lttng-live']
src_comp = graph.add_component(comp_cls, 'my source', params = {
'inputs': [sys.argv[1]],
})


# Add a `sink.text.pretty` component.
#
# Such a component pretty-prints event messages on the standard output
# (one message per line). See `babeltrace2-sink.text.pretty(7)`.
#
# The `babeltrace2 convert` CLI command uses a `sink.text.pretty`
# sink component by default.
comp_cls = bt2.find_plugin('text').sink_component_classes['pretty']
sink_comp = graph.add_component(comp_cls, 'my sink')


# Connect the `out` output port of the `source.text.dmesg` component
# to the `in` input port of the `sink.text.pretty` component.
graph.connect_ports(src_comp.output_ports['out'], sink_comp.input_ports['in'])


# Run the trace processing graph.
graph.run()





 

发件人: Philippe Proulx
发送时间: 2022年8月10日 22:08
收件人: zenan
抄送: lttng-dev@lists.lttng.org
主题: Re: [lttng-dev] babeltrace2 python api related question

 

On Wed, Aug 10, 2022 at 9:54 AM zenan via lttng-dev

 wrote:

> 

> 

> 

> Hi there,

> 

> I’m trying to use babeltrace2 python bindings to track live lttng trace, as 
> shown in some examples in the documents, I tried to use ctf.lttng-live( 
> ctf.fs in the documents) plugin as source, and use text.pretty as sink, but 
> it didn’t work out as I expected.  So does the api support tracking live 
> lttng trace and print them out yet?

> 

> 

 

What did you try exactly?

 

I need command lines and/or some code (keep it minimal) to help you.

 

Philippe

 

> 

> 

> 

> Yours sincerely

> 

> ___

> lttng-dev mailing list

> lttng-dev@lists.lttng.org

> https://lists.lttng.org/cgi-bin/mailman/listinfo/lttng-dev

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


Re: [lttng-dev] Change to CPU number detection breaks QNX compilation

2022-08-15 Thread Michael Jeanson via lttng-dev

On 2022-08-13 19 h 10, Elad Lahav via lttng-dev wrote:

Hello,

I have just downloaded and built the library for QNX/aarch64 and
noticed that the code in compat-smp.h breaks the build. This file
appears to be a (very) recent addition, from this commit:

---
commit 5cfe81b7ddff9543d451746de9965cac58c67182
Author: Michael Jeanson 
Date:   Wed Jul 27 10:44:00 2022 -0400

 fix: sysconf(_SC_NPROCESSORS_CONF) can be less than max cpu id

---

I started working around it, but it got a bit ugly. Is the change not
a Linuxism? Does it make sense on other systems? If QNX is the
exception then I can try to come up with a patch, but if not perhaps
the entire code should be wrapped by #ifdef __linux__?

--Elad


Hi,

We'll need more details on the build failure you are seeing, there is 
already an '#ifdef __linux__' in 'src/compat-smp.h'.


Can you send the relevant build errors?

Michael

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


Re: [lttng-dev] Change to CPU number detection breaks QNX compilation

2022-08-15 Thread Michael Jeanson via lttng-dev

On 2022-08-15 10 h 04, Elad Lahav wrote:

The problem is the use of d_type as a member of the dirent structure.
POSIX does not define such a member.
I can provide the necessary code for getting the file type in a
readdir() loop on QNX, but it seems unnecessary given that there is no
/sys file system with CPU information. The method for getting
information on processors is different, and I suspect that is true for
*BSDs and other non-Linux OSs.

--Elad


Can you try this patch [1] to see if it fixes the build on QNX? Can you 
also run 'make check' in 'tests/unit', the linux specific tests should 
be skipped.


Michael

[1] https://review.lttng.org/c/userspace-rcu/+/8664
___
lttng-dev mailing list
lttng-dev@lists.lttng.org
https://lists.lttng.org/cgi-bin/mailman/listinfo/lttng-dev


Re: [lttng-dev] Change to CPU number detection breaks QNX compilation

2022-08-15 Thread Elad Lahav via lttng-dev
That fixes the build, thanks.

I see some errors coming out of "make check", though:

ERROR: test_get_cpu_mask_from_sysfs - missing test plan
ERROR: test_get_cpu_mask_from_sysfs - exited with status 1

--Elad

On Mon, 15 Aug 2022 at 11:55, Michael Jeanson  wrote:
>
> On 2022-08-15 10 h 04, Elad Lahav wrote:
> > The problem is the use of d_type as a member of the dirent structure.
> > POSIX does not define such a member.
> > I can provide the necessary code for getting the file type in a
> > readdir() loop on QNX, but it seems unnecessary given that there is no
> > /sys file system with CPU information. The method for getting
> > information on processors is different, and I suspect that is true for
> > *BSDs and other non-Linux OSs.
> >
> > --Elad
>
> Can you try this patch [1] to see if it fixes the build on QNX? Can you
> also run 'make check' in 'tests/unit', the linux specific tests should
> be skipped.
>
> Michael
>
> [1] https://review.lttng.org/c/userspace-rcu/+/8664
___
lttng-dev mailing list
lttng-dev@lists.lttng.org
https://lists.lttng.org/cgi-bin/mailman/listinfo/lttng-dev


Re: [lttng-dev] Change to CPU number detection breaks QNX compilation

2022-08-15 Thread Michael Jeanson via lttng-dev

On 2022-08-15 12 h 56, Elad Lahav wrote:

That fixes the build, thanks.

I see some errors coming out of "make check", though:

ERROR: test_get_cpu_mask_from_sysfs - missing test plan
ERROR: test_get_cpu_mask_from_sysfs - exited with status 1

--Elad


I tested on Freebsd (as a non-linux target) and I get the expected :

SKIP: test_get_cpu_mask_from_sysfs - Skip Linux specific tests.

I wonder what might differ here, it might have to do with the version of 
bash on QNX, I'm not familiar with this platform.


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


Re: [lttng-dev] Change to CPU number detection breaks QNX compilation

2022-08-15 Thread Elad Lahav via lttng-dev
/bin/sh on QNX is (by default) ksh, not bash, so perhaps that's the issue.

Shouldn't block you from submitting that change. +1 from me, if that matters ;-)

--Elad

On Mon, 15 Aug 2022 at 13:39, Michael Jeanson  wrote:
>
> On 2022-08-15 12 h 56, Elad Lahav wrote:
> > That fixes the build, thanks.
> >
> > I see some errors coming out of "make check", though:
> >
> > ERROR: test_get_cpu_mask_from_sysfs - missing test plan
> > ERROR: test_get_cpu_mask_from_sysfs - exited with status 1
> >
> > --Elad
>
> I tested on Freebsd (as a non-linux target) and I get the expected :
>
> SKIP: test_get_cpu_mask_from_sysfs - Skip Linux specific tests.
>
> I wonder what might differ here, it might have to do with the version of
> bash on QNX, I'm not familiar with this platform.
>
> Michael
___
lttng-dev mailing list
lttng-dev@lists.lttng.org
https://lists.lttng.org/cgi-bin/mailman/listinfo/lttng-dev


Re: [lttng-dev] babeltrace2 python api related question

2022-08-15 Thread Philippe Proulx via lttng-dev
On Sun, Aug 14, 2022 at 4:48 AM zenan  wrote:
>
> In command line, I use “babeltrace2 net://somehost/some-session” to read live 
> lttng session trace, and I want to use python bindings to do the same, is it 
> possible?
>
> here is my code:

Almost there.

Some `src.ctf.lttng-live` component and message iterator methods may
return a "try again" status code (I don't remember exactly under which
circumstances). This propagates to bt_graph_run() [1] (in C) eventually
which itself returns `BT_GRAPH_RUN_STATUS_AGAIN`. The Python
bt2.Graph.run() method translates this status code to throwing
`bt2.TryAgain`.

Just catch those `bt2.TryAgain`, wait a bit, and call `graph.run()`
again:

# Run the trace processing graph.
while True:
try:
graph.run()
except bt2.TryAgain:
time.sleep(.1)

Works for me.

If you ever need to access the messages themselves instead of forwarding
them to a `sink.text.pretty` component, then use a
`bt2.TraceCollectionMessageIterator` instance [2].

Hope it helps,

Phil

[1]: 
https://babeltrace.org/docs/v2.0/libbabeltrace2/group__api-graph.html#gad2e1c1ab20d1400af1b552e70b3d567c
[2]: 
https://babeltrace.org/docs/v2.0/python/bt2/examples.html#iterate-trace-events

>
> import bt2
> import sys
>
> # Create an empty graph.
> graph = bt2.Graph()
>
> # Add a `source.text.dmesg` component.
> #
> # graph.add_component() returns the created and added component.
> #
> # Such a component reads Linux kernel ring buffer messages (see
> # `dmesg(1)`) from the standard input and creates corresponding event
> # messages. See `babeltrace2-source.text.dmesg(7)`.
> #
> # `my source` is the unique name of this component within `graph`.
>
> # the original source code here in the example is:
> # comp_cls = bt2.find_plugin('text').source_component_classes['dmesg']
> # src_comp = graph.add_component(comp_cls,'my source')
> comp_cls = bt2.find_plugin('ctf').source_component_classes['lttng-live']
> src_comp = graph.add_component(comp_cls, 'my source', params = {
> 'inputs': [sys.argv[1]],
> })
>
> # Add a `sink.text.pretty` component.
> #
> # Such a component pretty-prints event messages on the standard output
> # (one message per line). See `babeltrace2-sink.text.pretty(7)`.
> #
> # The `babeltrace2 convert` CLI command uses a `sink.text.pretty`
> # sink component by default.
> comp_cls = bt2.find_plugin('text').sink_component_classes['pretty']
> sink_comp = graph.add_component(comp_cls, 'my sink')
>
> # Connect the `out` output port of the `source.text.dmesg` component
> # to the `in` input port of the `sink.text.pretty` component.
> graph.connect_ports(src_comp.output_ports['out'], sink_comp.input_ports['in'])
>
> # Run the trace processing graph.
> graph.run()
>
>
>
>
>
> 发件人: Philippe Proulx
> 发送时间: 2022年8月10日 22:08
> 收件人: zenan
> 抄送: lttng-dev@lists.lttng.org
> 主题: Re: [lttng-dev] babeltrace2 python api related question
>
>
>
> On Wed, Aug 10, 2022 at 9:54 AM zenan via lttng-dev
>
>  wrote:
>
> >
>
> >
>
> >
>
> > Hi there,
>
> >
>
> > I’m trying to use babeltrace2 python bindings to track live lttng trace, as 
> > shown in some examples in the documents, I tried to use ctf.lttng-live( 
> > ctf.fs in the documents) plugin as source, and use text.pretty as sink, but 
> > it didn’t work out as I expected.  So does the api support tracking live 
> > lttng trace and print them out yet?
>
> >
>
> >
>
>
>
> What did you try exactly?
>
>
>
> I need command lines and/or some code (keep it minimal) to help you.
>
>
>
> Philippe
>
>
>
> >
>
> >
>
> >
>
> > Yours sincerely
>
> >
>
> > ___
>
> > lttng-dev mailing list
>
> > lttng-dev@lists.lttng.org
>
> > https://lists.lttng.org/cgi-bin/mailman/listinfo/lttng-dev
>
>
___
lttng-dev mailing list
lttng-dev@lists.lttng.org
https://lists.lttng.org/cgi-bin/mailman/listinfo/lttng-dev