7 .. currentmodule:: babeltrace.writer
9 The **CTF writer API** allows to write native
10 `CTF <http://www.efficios.com/ctf>`_ traces from a Python environment.
12 A CTF trace is made of one or more CTF streams. Streams contain
13 packets, which in turn contain serialized events. CTF readers, such as
14 Babeltrace, are able to merge streams and iterate on events in order
15 when reading a CTF trace.
17 The CTF writer API is exposed as a set of classes available in the
18 :mod:`babeltrace.writer` module.
22 :ref:`ctf-writer-api-examples`
24 There is a clear distinction to be made between field declaration
25 and field objects. A field declaration describes the properties, or
26 metadata, of a field. It does not contain a value. For example,
27 an integer *field declaration* contains a size in bits, a byte order,
28 a display base, whether it's signed or not, and so on. On the other
29 hand, an integer *field* is linked with a specific integer field
30 declaration, but contains an actual integer value. Thus, the layout and
31 properties of fields are described once in field declarations, and then
32 all concrete fields carry a value and a field declaration reference.
33 The same applies to event classes vs. events, as well as to stream
36 The main interface to write a CTF trace is the :class:`Writer` class:
41 Writing object in which clocks and streams may be registered, and
42 other common trace properties may be set.
44 A concrete :class:`Stream` object may be created from a
45 :class:`StreamClass` using :meth:`Writer.create_stream` method. A
46 stream class is also associated with a clock (:class:`Clock`), which
47 must also be registered to the writer object.
49 .. class:: StreamClass
57 Stream, based on a stream class.
62 Reference clock of one to many streams.
64 Events, before being created, must be described in an event class
65 (:class:`EventClass`). An event class must be added to a stream class
66 using :meth:`StreamClass.add_event_class` before appending an event
67 to an actual stream linked with this stream class.
77 Event, based on an event class.
79 An event class is created by instantiating an :class:`EventClass`
80 object and using its :meth:`~EventClass.add_field` method to add an
81 instance of one of the following field declarations:
83 .. class:: IntegerFieldDeclaration
86 Integer field declaration.
88 .. class:: FloatingPointFieldDeclaration
91 Floating point number field declaration.
93 .. class:: EnumerationFieldDeclaration
96 Enumeration field declaration (mapping from labels to ranges of
99 .. class:: StringFieldDeclaration
102 String (NULL-terminated array of bytes) field declaration.
104 .. class:: ArrayFieldDeclaration
107 Static array field declaration.
109 .. class:: SequenceFieldDeclaration
112 Sequence (dynamic array) field declaration.
114 .. class:: StructureFieldDeclaration
117 Structure (ordered map of field names to field declarations) field
120 .. class:: VariantFieldDeclaration
123 Variant (dynamic selection between different field declarations)
126 Once an event class is created, a concrete event may be created by
127 instantiating an :class:`Event` object. Its :meth:`~Event.payload`
128 method may be used to access the actual event's fields and set their
129 values. Those fields are instances of the following types:
131 .. class:: IntegerField
136 .. class:: FloatingPointField
139 Floating point number field.
141 .. class:: EnumerationField
144 Enumeration field (mapping from labels to ranges of integers).
146 .. class:: StringField
149 String (NULL-terminated array of bytes) field.
151 .. class:: ArrayField
156 .. class:: SequenceField
159 Sequence (dynamic array) field.
161 .. class:: StructureField
164 Structure (ordered map of field names to field declarations) field.
166 .. class:: VariantField
169 Variant (dynamic selection between different field declarations)
172 The subclass relationship for the CTF writer API is the following::
176 IntegerFieldDeclaration
177 FloatingPointFieldDeclaration
178 EnumerationFieldDeclaration
179 StringFieldDeclaration
180 ArrayFieldDeclaration
181 SequenceFieldDeclaration
182 StructureFieldDeclaration
183 VariantFieldDeclaration
201 Most of these classes' methods and properties raise :exc:`ValueError`
208 .. autoclass:: Writer
211 .. automethod:: __init__
217 .. autoclass:: StreamClass
220 .. automethod:: __init__
226 .. autoclass:: Stream
236 .. automethod:: __init__
242 .. autoclass:: EventClass
245 .. automethod:: __init__
254 .. automethod:: __init__
257 :class:`FieldDeclaration`
258 =========================
260 .. autoclass:: FieldDeclaration
267 .. autoclass:: IntegerBase
271 :class:`IntegerFieldDeclaration`
272 ================================
274 .. autoclass:: IntegerFieldDeclaration
278 .. automethod:: __init__
281 :class:`FloatingPointFieldDeclaration`
282 ======================================
284 .. autoclass:: FloatingPointFieldDeclaration
288 .. automethod:: __init__
291 :class:`EnumerationMapping`
292 ===========================
294 .. autoclass:: EnumerationMapping
297 .. automethod:: __init__
300 :class:`EnumerationFieldDeclaration`
301 ====================================
303 .. autoclass:: EnumerationFieldDeclaration
307 .. automethod:: __init__
310 :class:`StringFieldDeclaration`
311 ===============================
313 .. autoclass:: StringFieldDeclaration
317 .. automethod:: __init__
320 :class:`ArrayFieldDeclaration`
321 ==============================
323 .. autoclass:: ArrayFieldDeclaration
327 .. automethod:: __init__
330 :class:`SequenceFieldDeclaration`
331 =================================
333 .. autoclass:: SequenceFieldDeclaration
337 .. automethod:: __init__
340 :class:`StructureFieldDeclaration`
341 ==================================
343 .. autoclass:: StructureFieldDeclaration
347 .. automethod:: __init__
350 :class:`VariantFieldDeclaration`
351 ================================
353 .. autoclass:: VariantFieldDeclaration
357 .. automethod:: __init__
367 :class:`IntegerField`
368 =====================
370 .. autoclass:: IntegerField
375 :class:`FloatingPointField`
376 ===========================
378 .. autoclass:: FloatingPointField
383 :class:`EnumerationField`
384 =========================
386 .. autoclass:: EnumerationField
394 .. autoclass:: StringField
402 .. autoclass:: ArrayField
407 :class:`SequenceField`
408 ======================
410 .. autoclass:: SequenceField
415 :class:`StructureField`
416 =======================
418 .. autoclass:: StructureField
423 :class:`VariantField`
424 =====================
426 .. autoclass:: VariantField