* Re: Python CTF writer example
[not found] <CAC6yHM7iNtK7nt30mq2xeX5Z_K9nhEND6XP6jHS-s7dAJGkgZA@mail.gmail.com>
@ 2019-09-17 19:17 ` Jonathan Rajotte-Julien
0 siblings, 0 replies; 2+ messages in thread
From: Jonathan Rajotte-Julien @ 2019-09-17 19:17 UTC (permalink / raw)
To: Francis Giraldeau; +Cc: lttng-dev
Hi,
On Fri, Sep 13, 2019 at 07:03:59PM -0400, Francis Giraldeau wrote:
> Hello!
>
> It looks like there are some issues with the Python CTF writer example with
> babeltrace stable-1.5.
I will infer that you are looking at this doc:
https://diamon.org/babeltrace/docs/python/examples/#ctf-writer-api-examples
This doc is currently outdated(invalid). We are in the process of
revamping it/removing it.
If you need an example for bt 1.5 use:
https://github.com/efficios/babeltrace/blob/stable-1.5/bindings/python/babeltrace/examples/ctf_writer.py
This example works as expected.
>
> * Import error, should replace "import babeltrace.writer as btw" by "from
> babeltrace import CTFWriter as btw"
> * The FloatingPointDeclaration does not exists and should be replaced
> by FloatFieldDeclaration
> * babeltrace.common.CTFStringEncoding.UTF8 is
> instead babeltrace.CTFStringEncoding.UTF8
> * The variant still had issue that I cannot fix (ValueError("Invalid tag
> provided.") babeltrace.py:2221)
If you still wish to follow the documentation, please make sure to read the
green notice here:
https://diamon.org/babeltrace/docs/python/examples/#examples
>
> Events with simple fields are working okay with these changes. I thought
> that the clock would be updated automatically when appending the event, but
> that would be nice also to add it to the example.
>
> I tried babeltrace 2.0.0-pre6, but the writer API seems to have
> disappeared. I was looking at how to create a ctf.fs.sink, but I was not
> successful. Is writing CTF traces with the Python bindings still possible?
The ctf-writer capability are not part of the bindings anymore.
https://review.lttng.org/c/babeltrace/+/1392
What can be done is writing a source plugin using the bindings and use a ctf
sink on the cli to generate a ctf trace.
A quick source plugin: http://paste.ubuntu.com/p/8CBqTt8cSj/
Note that babeltrace 1.5 and babeltrace 2 can coexist on the same system.
Allowing you to still use the bindings from bt1.5 to generate traces.
I recommend that you stick with the babeltrace 1.5 bindings (import babeltrace).
Cheers
--
Jonathan Rajotte-Julien
EfficiOS
^ permalink raw reply [flat|nested] 2+ messages in thread
* Python CTF writer example
@ 2019-09-13 23:03 Francis Giraldeau
0 siblings, 0 replies; 2+ messages in thread
From: Francis Giraldeau @ 2019-09-13 23:03 UTC (permalink / raw)
To: lttng-dev
[-- Attachment #1.1: Type: text/plain, Size: 942 bytes --]
Hello!
It looks like there are some issues with the Python CTF writer example with
babeltrace stable-1.5.
* Import error, should replace "import babeltrace.writer as btw" by "from
babeltrace import CTFWriter as btw"
* The FloatingPointDeclaration does not exists and should be replaced
by FloatFieldDeclaration
* babeltrace.common.CTFStringEncoding.UTF8 is
instead babeltrace.CTFStringEncoding.UTF8
* The variant still had issue that I cannot fix (ValueError("Invalid tag
provided.") babeltrace.py:2221)
Events with simple fields are working okay with these changes. I thought
that the clock would be updated automatically when appending the event, but
that would be nice also to add it to the example.
I tried babeltrace 2.0.0-pre6, but the writer API seems to have
disappeared. I was looking at how to create a ctf.fs.sink, but I was not
successful. Is writing CTF traces with the Python bindings still possible?
Regards,
--
Francis
[-- Attachment #1.2: Type: text/html, Size: 1286 bytes --]
[-- Attachment #2: ctf-writer-example --]
[-- Type: application/octet-stream, Size: 1522 bytes --]
#!/usr/bin/env python3
#import babeltrace.writer as btw
#import babeltrace.common
import babeltrace
from babeltrace import CTFWriter as btw
import tempfile
import time
trace_path = tempfile.mkdtemp()
print('trace path: {}'.format(trace_path))
writer = btw.Writer(trace_path)
clock = btw.Clock('my_clock')
clock.description = 'this is my clock'
writer.add_clock(clock)
stream_class = btw.StreamClass('my_stream')
stream_class.clock = clock
event_class = btw.EventClass('my_event')
# 32-bit signed integer field declaration
int32_field_decl = btw.IntegerFieldDeclaration(32)
int32_field_decl.signed = True
# string field declaration
string_field_decl = btw.StringFieldDeclaration()
string_field_decl.encoding = babeltrace.CTFStringEncoding.UTF8
# IEEE 754 single precision floating point number field declaration
float_field_decl = btw.FloatFieldDeclaration()
float_field_decl.exponent_digits = btw.FloatFieldDeclaration.FLT_EXP_DIG
float_field_decl.mantissa_digits = btw.FloatFieldDeclaration.FLT_MANT_DIG
event_class.add_field(int32_field_decl, 'val1')
event_class.add_field(string_field_decl, 'val2')
event_class.add_field(float_field_decl, 'val3')
stream_class.add_event_class(event_class)
stream = writer.create_stream(stream_class)
for i in range(10):
event = btw.Event(event_class)
event.payload('val1').value = 42 + i
event.payload('val2').value = "foo {}".format(i)
event.payload('val3').value = i * 0.1
clock.time = time.time_ns()
stream.append_event(event)
stream.flush()
[-- Attachment #3: 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
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2019-09-17 19:18 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
[not found] <CAC6yHM7iNtK7nt30mq2xeX5Z_K9nhEND6XP6jHS-s7dAJGkgZA@mail.gmail.com>
2019-09-17 19:17 ` Python CTF writer example Jonathan Rajotte-Julien
2019-09-13 23:03 Francis Giraldeau
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 NNTP newsgroup(s).