[lttng-dev] Python Babeltrace - Write multiple streams

Rocky Dunlap rsdunlapiv at gmail.com
Fri Nov 6 21:40:41 EST 2015


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
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.lttng.org/pipermail/lttng-dev/attachments/20151106/75a25cda/attachment.html>


More information about the lttng-dev mailing list