[lttng-dev] Python Babeltrace - Write multiple streams

Jérémie Galarneau jeremie.galarneau at efficios.com
Tue Nov 10 10:12:24 EST 2015


Hi Rocky,

The code looks good at first glance. Can you try with master and see
if that might be problem that has been fixed since then?

Thanks,
Jérémie

On Fri, Nov 6, 2015 at 9:40 PM, Rocky Dunlap <rsdunlapiv at gmail.com> wrote:
> Using the Babletrace Python binding version 1.3, I adapted a simple example
> to try to write a trace with two streams.  It appears to write okay (no
> errors), but when I attempt to read it back (again using Babeltrace) I get
> an error:
>
> [error] Stream 1 is not declared in metadata.
> [error] Stream index creation error.
> [error] Open file stream error.
> [warning] [Context] Cannot open_trace of format ctf at path ./trace.
>
> Here is my code to write the streams:
>
> ################################
>
> from babeltrace import *
>
> trace_path = "./trace"
>
> print('trace path: {}'.format(trace_path))
>
> writer = CTFWriter.Writer(trace_path)
>
> clock = CTFWriter.Clock('my_clock')
> clock.description = 'this is my clock'
> writer.add_clock(clock)
>
> stream_class = CTFWriter.StreamClass('my_stream')
> stream_class.clock = clock
>
> event_class = CTFWriter.EventClass('my_event')
>
> int32_field_decl = CTFWriter.IntegerFieldDeclaration(32)
> int32_field_decl.signed = True
>
> event_class.add_field(int32_field_decl, 'my_field')
>
> stream_class.add_event_class(event_class)
>
> stream = writer.create_stream(stream_class)
> stream2 = writer.create_stream(stream_class)
>
> event = CTFWriter.Event(event_class)
> event.payload('my_field').value = -23
> stream.append_event(event)
>
> event = CTFWriter.Event(event_class)
> event.payload('my_field').value = -89
> stream.append_event(event)
>
> event = CTFWriter.Event(event_class)
> event.payload('my_field').value = -849
> stream2.append_event(event)
>
> event = CTFWriter.Event(event_class)
> event.payload('my_field').value = 42
> stream2.append_event(event)
>
> stream.flush()
> stream2.flush()
>
> ######################
>
> I am sure I am just not quite using the API correctly.  If you can spot the
> error, please let me know.  Also, if anyone can point me to an example of
> using the python bindings to write out multiple streams, I would appreciate
> it.
>
> Thanks!
> Rocky
>
> _______________________________________________
> lttng-dev mailing list
> lttng-dev at lists.lttng.org
> http://lists.lttng.org/cgi-bin/mailman/listinfo/lttng-dev
>



-- 
Jérémie Galarneau
EfficiOS Inc.
http://www.efficios.com



More information about the lttng-dev mailing list