Python bindings: Make bindings PEP8 compliant
[babeltrace.git] / bindings / python / babeltrace.i.in
CommitLineData
24a3136a
DS
1/*
2 * babeltrace.i.in
3 *
4 * Babeltrace Python Module interface file
5 *
6 * Copyright 2012 EfficiOS Inc.
7 *
8 * Author: Danny Serres <danny.serres@efficios.com>
74ea15ad 9 * Author: Jérémie Galarneau <jeremie.galarneau@efficios.com>
24a3136a
DS
10 *
11 * Permission is hereby granted, free of charge, to any person obtaining a copy
12 * of this software and associated documentation files (the "Software"), to deal
13 * in the Software without restriction, including without limitation the rights
14 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
15 * copies of the Software, and to permit persons to whom the Software is
16 * furnished to do so, subject to the following conditions:
17 *
18 * The above copyright notice and this permission notice shall be included in
19 * all copies or substantial portions of the Software.
20 */
21
22
23%define DOCSTRING
24"BABELTRACE_VERSION_STR
25
26Babeltrace is a trace viewer and converter reading and writing the
27Common Trace Format (CTF). Its main use is to pretty-print CTF
28traces into a human-readable text output.
29
74ea15ad 30To use this module, the first step is to create a TraceCollection and add a
24a3136a
DS
31trace to it."
32%enddef
33
34%module(docstring=DOCSTRING) babeltrace
35
38f28df6 36%include "stdint.i"
24a3136a
DS
37%include "typemaps.i"
38%{
39#define SWIG_FILE_WITH_INIT
40#include <babeltrace/babeltrace.h>
41#include <babeltrace/babeltrace-internal.h>
42#include <babeltrace/trace-handle.h>
43#include <babeltrace/trace-handle-internal.h>
44#include <babeltrace/context.h>
45#include <babeltrace/context-internal.h>
46#include <babeltrace/iterator.h>
47#include <babeltrace/iterator-internal.h>
48#include <babeltrace/format.h>
49#include <babeltrace/list.h>
24a3136a
DS
50#include <babeltrace/types.h>
51#include <babeltrace/ctf/iterator.h>
52#include "python-complements.h"
ec8c88d7
JG
53#include <babeltrace/ctf-writer/clock.h>
54#include <babeltrace/ctf-writer/event-fields.h>
55#include <babeltrace/ctf-writer/event-types.h>
56#include <babeltrace/ctf-writer/event.h>
57#include <babeltrace/ctf-writer/stream.h>
58#include <babeltrace/ctf-writer/writer.h>
24a3136a
DS
59%}
60
24a3136a 61typedef int bt_intern_str;
5792eb34 62typedef int64_t ssize_t;
24a3136a 63
cebae8c3
JG
64/* =================================================================
65 PYTHON-COMPLEMENTS.H
66 ¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯
67*/
68
cebae8c3
JG
69struct bt_definition **_bt_python_field_listcaller(
70 const struct bt_ctf_event *ctf_event,
71 const struct bt_definition *scope,
72 unsigned int *OUTPUT);
73struct bt_definition *_bt_python_field_one_from_list(
74 struct bt_definition **list, int index);
75struct bt_ctf_event_decl **_bt_python_event_decl_listcaller(
76 int handle_id,
77 struct bt_context *ctx,
78 unsigned int *OUTPUT);
79struct bt_ctf_event_decl *_bt_python_decl_one_from_list(
80 struct bt_ctf_event_decl **list, int index);
81struct bt_ctf_field_decl **_by_python_field_decl_listcaller(
82 struct bt_ctf_event_decl *event_decl,
83 enum bt_ctf_scope scope,
84 unsigned int *OUTPUT);
85struct bt_ctf_field_decl *_bt_python_field_decl_one_from_list(
86 struct bt_ctf_field_decl **list, int index);
87struct definition_array *_bt_python_get_array_from_def(
88 struct bt_definition *field);
89struct definition_sequence *_bt_python_get_sequence_from_def(
90 struct bt_definition *field);
5792eb34
JG
91struct bt_declaration *_bt_python_get_array_element_declaration(
92 struct bt_declaration *field);
3866c850
JG
93struct bt_declaration *_bt_python_get_sequence_element_declaration(
94 struct bt_declaration *field);
5792eb34 95const char *_bt_python_get_array_string(struct bt_definition *field);
3866c850 96const char *_bt_python_get_sequence_string(struct bt_definition *field);
ec8c88d7
JG
97int _bt_python_field_integer_get_signedness(const struct bt_ctf_field *field);
98enum ctf_type_id _bt_python_get_field_type(const struct bt_ctf_field *field);
b4b5e4b5
JG
99const char *_bt_python_ctf_field_type_enumeration_get_mapping(
100 struct bt_ctf_field_type *enumeration, size_t index,
101 int64_t *OUTPUT, int64_t *OUTPUT);
102const char *_bt_python_ctf_field_type_enumeration_get_mapping_unsigned(
103 struct bt_ctf_field_type *enumeration, size_t index,
104 uint64_t *OUTPUT, uint64_t *OUTPUT);
105const char *_bt_python_ctf_field_type_structure_get_field_name(
106 struct bt_ctf_field_type *structure, size_t index);
107struct bt_ctf_field_type *_bt_python_ctf_field_type_structure_get_field_type(
108 struct bt_ctf_field_type *structure, size_t index);
109const char *_bt_python_ctf_field_type_variant_get_field_name(
110 struct bt_ctf_field_type *variant, size_t index);
111struct bt_ctf_field_type *_bt_python_ctf_field_type_variant_get_field_type(
112 struct bt_ctf_field_type *variant, size_t index);
38f28df6
JG
113const char *_bt_python_ctf_event_class_get_field_name(
114 struct bt_ctf_event_class *event_class, size_t index);
115struct bt_ctf_field_type *_bt_python_ctf_event_class_get_field_type(
116 struct bt_ctf_event_class *event_class, size_t index);
da64442f
JG
117int _bt_python_ctf_clock_get_uuid_index(struct bt_ctf_clock *clock,
118 size_t index, unsigned char *OUTPUT);
119int _bt_python_ctf_clock_set_uuid_index(struct bt_ctf_clock *clock,
120 size_t index, unsigned char value);
cebae8c3 121
24a3136a
DS
122/* =================================================================
123 CONTEXT.H, CONTEXT-INTERNAL.H
124 ¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯
125*/
126
127%rename("_bt_context_create") bt_context_create(void);
128%rename("_bt_context_add_trace") bt_context_add_trace(
129 struct bt_context *ctx, const char *path, const char *format,
2c0df204
XH
130 void (*packet_seek)(struct bt_stream_pos *pos, size_t index, int whence),
131 struct bt_mmap_stream_list *stream_list, FILE *metadata);
24a3136a
DS
132%rename("_bt_context_remove_trace") bt_context_remove_trace(
133 struct bt_context *ctx, int trace_id);
134%rename("_bt_context_get") bt_context_get(struct bt_context *ctx);
135%rename("_bt_context_put") bt_context_put(struct bt_context *ctx);
136%rename("_bt_ctf_event_get_context") bt_ctf_event_get_context(
137 const struct bt_ctf_event *event);
138
139struct bt_context *bt_context_create(void);
140int bt_context_add_trace(struct bt_context *ctx, const char *path, const char *format,
2c0df204
XH
141 void (*packet_seek)(struct bt_stream_pos *pos, size_t index, int whence),
142 struct bt_mmap_stream_list *stream_list, FILE *metadata);
24a3136a
DS
143void bt_context_remove_trace(struct bt_context *ctx, int trace_id);
144void bt_context_get(struct bt_context *ctx);
145void bt_context_put(struct bt_context *ctx);
146struct bt_context *bt_ctf_event_get_context(const struct bt_ctf_event *event);
147
74ea15ad 148// class TraceCollection to prevent direct access to struct bt_context
24a3136a 149%pythoncode%{
24a3136a 150
be02a6e6 151class TraceCollection:
74ea15ad 152
be02a6e6
JG
153 """
154 The TraceCollection is the object that contains all currently opened traces.
155 """
156
157 def __init__(self):
158 self._tc = _bt_context_create()
159
160 def __del__(self):
161 _bt_context_put(self._tc)
162
163 def add_trace(self, path, format_str):
164 """
165 Add a trace by path to the TraceCollection.
166
167 Open a trace.
168
169 path is the path to the trace, it is not recursive.
170 If "path" is None, stream_list is used instead as a list
171 of mmap streams to open for the trace.
172
173 format is a string containing the format name in which the trace was
174 produced.
175
176 Return: the corresponding TraceHandle on success or None on error.
177 """
178 ret = _bt_context_add_trace(
179 self._tc,
180 path,
181 format_str,
182 None,
183 None,
184 None)
185 if ret < 0:
186 return None
187
188 th = TraceHandle.__new__(TraceHandle)
189 th._id = ret
190 th._trace_collection = self
191 return th
192
193 def add_traces_recursive(self, path, format_str):
194 """
195 Open a trace recursively.
196
197 Find each trace present in the subdirectory starting from the given
198 path, and add them to the TraceCollection.
199
200 Return a dict of TraceHandle instances (the full path is the key).
201 Return None on error.
202 """
203
204 import os
205
206 trace_handles = {}
207
208 noTrace = True
209 error = False
210
211 for fullpath, dirs, files in os.walk(path):
212 if "metadata" in files:
213 trace_handle = self.add_trace(fullpath, format_str)
214 if trace_handle is None:
215 error = True
216 continue
217
218 trace_handles[fullpath] = trace_handle
219 noTrace = False
220
221 if noTrace and error:
222 return None
223 return trace_handles
224
225 def remove_trace(self, trace_handle):
226 """
227 Remove a trace from the TraceCollection.
228 Effectively closing the trace.
229 """
230 try:
231 _bt_context_remove_trace(self._tc, trace_handle._id)
232 except AttributeError:
233 raise TypeError("in remove_trace, "
234 "argument 2 must be a TraceHandle instance")
235
236 @property
237 def events(self):
238 """
239 Generator function to iterate over the events of open in the current
240 TraceCollection.
241
242 Due to limitations of the native Babeltrace API, only one event
243 may be "alive" at a time (i.e. a user should never store a copy
244 of the events returned by this function for ulterior use). Users
245 shall make sure to copy the information they need from an event
246 before accessing the next one.
247
248 Furthermore, event objects become invalid when the generator goes
249 out of scope as the underlying iterator will be reclaimed. Using an
250 event after the the generator has gone out of scope may result in a
251 crash or data corruption.
252 """
253 begin_pos_ptr = _bt_iter_pos()
254 end_pos_ptr = _bt_iter_pos()
255 begin_pos_ptr.type = SEEK_BEGIN
256 end_pos_ptr.type = SEEK_LAST
257
258 for event in self._events(begin_pos_ptr, end_pos_ptr):
259 yield event
260
261 def events_timestamps(self, timestamp_begin, timestamp_end):
262 """
263 Generator function to iterate over the events of open in the current
264 TraceCollection from timestamp_begin to timestamp_end.
265 """
266 begin_pos_ptr = _bt_iter_pos()
267 end_pos_ptr = _bt_iter_pos()
268 begin_pos_ptr.type = end_pos_ptr.type = SEEK_TIME
269 begin_pos_ptr.u.seek_time = timestamp_begin
270 end_pos_ptr.u.seek_time = timestamp_end
271
272 for event in self._events(begin_pos_ptr, end_pos_ptr):
273 yield event
274
275 @property
276 def timestamp_begin(self):
277 pos_ptr = _bt_iter_pos()
278 pos_ptr.type = SEEK_BEGIN
279 return self._timestamp_at_pos(pos_ptr)
280
281 @property
282 def timestamp_end(self):
283 pos_ptr = _bt_iter_pos()
284 pos_ptr.type = SEEK_LAST
285 return self._timestamp_at_pos(pos_ptr)
286
287 def _timestamp_at_pos(self, pos_ptr):
288 ctf_it_ptr = _bt_ctf_iter_create(self._tc, pos_ptr, pos_ptr)
289 if ctf_it_ptr is None:
290 raise NotImplementedError(
291 "Creation of multiple iterators is unsupported.")
292 ev_ptr = _bt_ctf_iter_read_event(ctf_it_ptr)
293 _bt_ctf_iter_destroy(ctf_it_ptr)
294 if ev_ptr is None:
295 return None
296
297 def _events(self, begin_pos_ptr, end_pos_ptr):
298 ctf_it_ptr = _bt_ctf_iter_create(self._tc, begin_pos_ptr, end_pos_ptr)
299 if ctf_it_ptr is None:
300 raise NotImplementedError(
301 "Creation of multiple iterators is unsupported.")
302
303 while True:
304 ev_ptr = _bt_ctf_iter_read_event(ctf_it_ptr)
305 if ev_ptr is None:
306 break
307
308 ev = Event.__new__(Event)
309 ev._e = ev_ptr
310 try:
311 yield ev
312 except GeneratorExit:
313 break
314
315 ret = _bt_iter_next(_bt_ctf_get_iter(ctf_it_ptr))
316 if ret != 0:
317 break
318
319 _bt_ctf_iter_destroy(ctf_it_ptr)
24a3136a
DS
320%}
321
322
323
324/* =================================================================
325 FORMAT.H, REGISTRY
326 ¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯
327*/
328
329%rename("lookup_format") bt_lookup_format(bt_intern_str qname);
330%rename("_bt_print_format_list") bt_fprintf_format_list(FILE *fp);
331%rename("register_format") bt_register_format(struct format *format);
cc26a15a 332%rename("unregister_format") bt_unregister_format(struct bt_format *format);
24a3136a
DS
333
334extern struct format *bt_lookup_format(bt_intern_str qname);
335extern void bt_fprintf_format_list(FILE *fp);
2c0df204 336extern int bt_register_format(struct bt_format *format);
cc26a15a 337extern void bt_unregister_format(struct bt_format *format);
24a3136a 338
24a3136a
DS
339%pythoncode %{
340
341def print_format_list(babeltrace_file):
be02a6e6
JG
342 """
343 Print a list of available formats to file.
344
345 babeltrace_file must be a File instance opened in write mode.
346 """
347 try:
348 if babeltrace_file._file is not None:
349 _bt_print_format_list(babeltrace_file._file)
350 except AttributeError:
351 raise TypeError("in print_format_list, "
352 "argument 1 must be a File instance")
24a3136a
DS
353
354%}
355
356
357/* =================================================================
358 ITERATOR.H, ITERATOR-INTERNAL.H
359 ¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯
360*/
361
362%rename("_bt_iter_create") bt_iter_create(struct bt_context *ctx,
363 const struct bt_iter_pos *begin_pos, const struct bt_iter_pos *end_pos);
364%rename("_bt_iter_destroy") bt_iter_destroy(struct bt_iter *iter);
365%rename("_bt_iter_next") bt_iter_next(struct bt_iter *iter);
366%rename("_bt_iter_get_pos") bt_iter_get_pos(struct bt_iter *iter);
367%rename("_bt_iter_free_pos") bt_iter_free_pos(struct bt_iter_pos *pos);
368%rename("_bt_iter_set_pos") bt_iter_set_pos(struct bt_iter *iter,
369 const struct bt_iter_pos *pos);
370%rename("_bt_iter_create_time_pos") bt_iter_create_time_pos(struct bt_iter *iter,
371 uint64_t timestamp);
372
373struct bt_iter *bt_iter_create(struct bt_context *ctx,
374 const struct bt_iter_pos *begin_pos, const struct bt_iter_pos *end_pos);
375void bt_iter_destroy(struct bt_iter *iter);
376int bt_iter_next(struct bt_iter *iter);
377struct bt_iter_pos *bt_iter_get_pos(struct bt_iter *iter);
378void bt_iter_free_pos(struct bt_iter_pos *pos);
379int bt_iter_set_pos(struct bt_iter *iter, const struct bt_iter_pos *pos);
380struct bt_iter_pos *bt_iter_create_time_pos(struct bt_iter *iter, uint64_t timestamp);
381
382%rename("_bt_iter_pos") bt_iter_pos;
383%rename("SEEK_TIME") BT_SEEK_TIME;
384%rename("SEEK_RESTORE") BT_SEEK_RESTORE;
385%rename("SEEK_CUR") BT_SEEK_CUR;
386%rename("SEEK_BEGIN") BT_SEEK_BEGIN;
ef42f9eb 387%rename("SEEK_LAST") BT_SEEK_LAST;
24a3136a
DS
388
389// This struct is taken from iterator.h
390// All changes to the struct must also be made here
391struct bt_iter_pos {
392 enum {
393 BT_SEEK_TIME, /* uses u.seek_time */
394 BT_SEEK_RESTORE, /* uses u.restore */
395 BT_SEEK_CUR,
396 BT_SEEK_BEGIN,
ef42f9eb 397 BT_SEEK_LAST
24a3136a
DS
398 } type;
399 union {
400 uint64_t seek_time;
401 struct bt_saved_pos *restore;
402 } u;
403};
404
24a3136a
DS
405/* =================================================================
406 TRACE-HANDLE.H, TRACE-HANDLE-INTERNAL.H
407 ¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯
408*/
409
410%rename("_bt_trace_handle_create") bt_trace_handle_create(struct bt_context *ctx);
411%rename("_bt_trace_handle_destroy") bt_trace_handle_destroy(struct bt_trace_handle *bt);
412struct bt_trace_handle *bt_trace_handle_create(struct bt_context *ctx);
413void bt_trace_handle_destroy(struct bt_trace_handle *bt);
414
415%rename("_bt_trace_handle_get_path") bt_trace_handle_get_path(struct bt_context *ctx,
416 int handle_id);
417%rename("_bt_trace_handle_get_timestamp_begin") bt_trace_handle_get_timestamp_begin(
418 struct bt_context *ctx, int handle_id, enum bt_clock_type type);
419%rename("_bt_trace_handle_get_timestamp_end") bt_trace_handle_get_timestamp_end(
420 struct bt_context *ctx, int handle_id, enum bt_clock_type type);
24a3136a
DS
421const char *bt_trace_handle_get_path(struct bt_context *ctx, int handle_id);
422uint64_t bt_trace_handle_get_timestamp_begin(struct bt_context *ctx, int handle_id,
423 enum bt_clock_type type);
424uint64_t bt_trace_handle_get_timestamp_end(struct bt_context *ctx, int handle_id,
425 enum bt_clock_type type);
426
427%rename("_bt_ctf_event_get_handle_id") bt_ctf_event_get_handle_id(
428 const struct bt_ctf_event *event);
429int bt_ctf_event_get_handle_id(const struct bt_ctf_event *event);
430
431
432%pythoncode%{
433
8a2cd19a 434# Based on enum bt_clock_type in clock-type.h
464425e1 435class ClockType:
be02a6e6
JG
436 CLOCK_CYCLES = 0
437 CLOCK_REAL = 1
464425e1 438
8bb27181 439
be02a6e6 440class TraceHandle(object):
8bb27181 441
be02a6e6
JG
442 """
443 The TraceHandle allows the user to manipulate a trace file directly.
444 It is a unique identifier representing a trace file.
445 Do not instantiate.
446 """
447
448 def __init__(self):
449 raise NotImplementedError("TraceHandle cannot be instantiated")
450
451 def __repr__(self):
452 return "Babeltrace TraceHandle: trace_id('{0}')".format(self._id)
453
454 @property
455 def id(self):
456 """Return the TraceHandle id."""
457 return self._id
458
459 @property
460 def path(self):
461 """Return the path of a TraceHandle."""
462 return _bt_trace_handle_get_path(self._trace_collection._tc, self._id)
463
464 @property
465 def timestamp_begin(self):
466 """Return the creation time of the buffers of a trace."""
467 return _bt_trace_handle_get_timestamp_begin(
468 self._trace_collection._tc, self._id, ClockType.CLOCK_REAL)
469
470 @property
471 def timestamp_end(self):
472 """Return the destruction timestamp of the buffers of a trace."""
473 return _bt_trace_handle_get_timestamp_end(
474 self._trace_collection._tc, self._id, ClockType.CLOCK_REAL)
475
476 @property
477 def events(self):
478 """
479 Generator returning all events (EventDeclaration) in a trace.
480 """
481 ret = _bt_python_event_decl_listcaller(
482 self.id,
483 self._trace_collection._tc)
484
485 if not isinstance(ret, list):
486 return
487
488 ptr_list, count = ret
489 for i in range(count):
490 tmp = EventDeclaration.__new__(EventDeclaration)
491 tmp._ed = _bt_python_decl_one_from_list(ptr_list, i)
492 yield tmp
8bb27181 493
24a3136a
DS
494%}
495
496
24a3136a
DS
497// =================================================================
498// CTF
499// =================================================================
500
501/* =================================================================
502 ITERATOR.H, EVENTS.H
503 ¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯
504*/
505
506//Iterator
507%rename("_bt_ctf_iter_create") bt_ctf_iter_create(struct bt_context *ctx,
508 const struct bt_iter_pos *begin_pos,
509 const struct bt_iter_pos *end_pos);
510%rename("_bt_ctf_get_iter") bt_ctf_get_iter(struct bt_ctf_iter *iter);
511%rename("_bt_ctf_iter_destroy") bt_ctf_iter_destroy(struct bt_ctf_iter *iter);
512%rename("_bt_ctf_iter_read_event") bt_ctf_iter_read_event(struct bt_ctf_iter *iter);
513
514struct bt_ctf_iter *bt_ctf_iter_create(struct bt_context *ctx,
515 const struct bt_iter_pos *begin_pos,
516 const struct bt_iter_pos *end_pos);
517struct bt_iter *bt_ctf_get_iter(struct bt_ctf_iter *iter);
518void bt_ctf_iter_destroy(struct bt_ctf_iter *iter);
519struct bt_ctf_event *bt_ctf_iter_read_event(struct bt_ctf_iter *iter);
520
521
522//Events
24a3136a
DS
523%rename("_bt_ctf_get_top_level_scope") bt_ctf_get_top_level_scope(const struct
524 bt_ctf_event *event, enum bt_ctf_scope scope);
525%rename("_bt_ctf_event_name") bt_ctf_event_name(const struct bt_ctf_event *ctf_event);
526%rename("_bt_ctf_get_timestamp") bt_ctf_get_timestamp(
527 const struct bt_ctf_event *ctf_event);
528%rename("_bt_ctf_get_cycles") bt_ctf_get_cycles(
529 const struct bt_ctf_event *ctf_event);
530
531%rename("_bt_ctf_get_field") bt_ctf_get_field(const struct bt_ctf_event *ctf_event,
2c0df204 532 const struct bt_definition *scope, const char *field);
24a3136a 533%rename("_bt_ctf_get_index") bt_ctf_get_index(const struct bt_ctf_event *ctf_event,
2c0df204
XH
534 const struct bt_definition *field, unsigned int index);
535%rename("_bt_ctf_field_name") bt_ctf_field_name(const struct bt_definition *field);
536%rename("_bt_ctf_field_type") bt_ctf_field_type(const struct bt_declaration *field);
24a3136a 537%rename("_bt_ctf_get_int_signedness") bt_ctf_get_int_signedness(
2c0df204
XH
538 const struct bt_declaration *field);
539%rename("_bt_ctf_get_int_base") bt_ctf_get_int_base(const struct bt_declaration *field);
24a3136a 540%rename("_bt_ctf_get_int_byte_order") bt_ctf_get_int_byte_order(
2c0df204
XH
541 const struct bt_declaration *field);
542%rename("_bt_ctf_get_int_len") bt_ctf_get_int_len(const struct bt_declaration *field);
4191bcd2
XH
543%rename("_bt_ctf_get_enum_int") bt_ctf_get_enum_int(const struct bt_definition *field);
544%rename("_bt_ctf_get_enum_str") bt_ctf_get_enum_str(const struct bt_definition *field);
2c0df204
XH
545%rename("_bt_ctf_get_encoding") bt_ctf_get_encoding(const struct bt_declaration *field);
546%rename("_bt_ctf_get_array_len") bt_ctf_get_array_len(const struct bt_declaration *field);
547%rename("_bt_ctf_get_uint64") bt_ctf_get_uint64(const struct bt_definition *field);
548%rename("_bt_ctf_get_int64") bt_ctf_get_int64(const struct bt_definition *field);
549%rename("_bt_ctf_get_char_array") bt_ctf_get_char_array(const struct bt_definition *field);
550%rename("_bt_ctf_get_string") bt_ctf_get_string(const struct bt_definition *field);
e5a73b90 551%rename("_bt_ctf_get_float") bt_ctf_get_float(const struct bt_definition *field);
812e6682 552%rename("_bt_ctf_get_variant") bt_ctf_get_variant(const struct bt_definition *field);
24a3136a
DS
553%rename("_bt_ctf_field_get_error") bt_ctf_field_get_error(void);
554%rename("_bt_ctf_get_decl_event_name") bt_ctf_get_decl_event_name(const struct
555 bt_ctf_event_decl *event);
78564612
AM
556%rename("_bt_ctf_get_decl_event_id") bt_ctf_get_decl_event_id(const struct
557 bt_ctf_event_decl *event);
24a3136a
DS
558%rename("_bt_ctf_get_decl_field_name") bt_ctf_get_decl_field_name(
559 const struct bt_ctf_field_decl *field);
f01efa78 560%rename("_bt_ctf_get_decl_from_def") bt_ctf_get_decl_from_def(
2c0df204 561 const struct bt_definition *field);
8bb27181
JG
562%rename("_bt_ctf_get_decl_from_field_decl") bt_ctf_get_decl_from_field_decl(
563 const struct bt_ctf_field_decl *field);
3c2ce778 564%rename("_bt_array_index") bt_array_index(struct definition_array *array, uint64_t i);
786207e0
XH
565%rename("_bt_sequence_len") bt_sequence_len(struct definition_sequence *sequence);
566%rename("_bt_sequence_index") bt_sequence_index(struct definition_sequence *sequence, uint64_t i);
3a068915
JG
567%rename("_bt_ctf_get_struct_field_count") bt_ctf_get_struct_field_count(const struct bt_definition *structure);
568%rename("_bt_ctf_get_struct_field_index") bt_ctf_get_struct_field_index(const struct bt_definition *structure, uint64_t i);
24a3136a 569
2c0df204 570const struct bt_definition *bt_ctf_get_top_level_scope(const struct bt_ctf_event *ctf_event,
24a3136a
DS
571 enum bt_ctf_scope scope);
572const char *bt_ctf_event_name(const struct bt_ctf_event *ctf_event);
573uint64_t bt_ctf_get_timestamp(const struct bt_ctf_event *ctf_event);
574uint64_t bt_ctf_get_cycles(const struct bt_ctf_event *ctf_event);
2c0df204
XH
575const struct bt_definition *bt_ctf_get_field(const struct bt_ctf_event *ctf_event,
576 const struct bt_definition *scope,
24a3136a 577 const char *field);
2c0df204
XH
578const struct bt_definition *bt_ctf_get_index(const struct bt_ctf_event *ctf_event,
579 const struct bt_definition *field,
24a3136a 580 unsigned int index);
2c0df204
XH
581const char *bt_ctf_field_name(const struct bt_definition *field);
582enum ctf_type_id bt_ctf_field_type(const struct bt_declaration *field);
583int bt_ctf_get_int_signedness(const struct bt_declaration *field);
584int bt_ctf_get_int_base(const struct bt_declaration *field);
585int bt_ctf_get_int_byte_order(const struct bt_declaration *field);
586ssize_t bt_ctf_get_int_len(const struct bt_declaration *field);
4191bcd2
XH
587const struct bt_definition *bt_ctf_get_enum_int(const struct bt_definition *field);
588const char *bt_ctf_get_enum_str(const struct bt_definition *field);
2c0df204
XH
589enum ctf_string_encoding bt_ctf_get_encoding(const struct bt_declaration *field);
590int bt_ctf_get_array_len(const struct bt_declaration *field);
3c2ce778 591struct bt_definition *bt_array_index(struct definition_array *array, uint64_t i);
2c0df204
XH
592uint64_t bt_ctf_get_uint64(const struct bt_definition *field);
593int64_t bt_ctf_get_int64(const struct bt_definition *field);
594char *bt_ctf_get_char_array(const struct bt_definition *field);
595char *bt_ctf_get_string(const struct bt_definition *field);
e5a73b90 596double bt_ctf_get_float(const struct bt_definition *field);
812e6682 597const struct bt_definition *bt_ctf_get_variant(const struct bt_definition *field);
24a3136a
DS
598int bt_ctf_field_get_error(void);
599const char *bt_ctf_get_decl_event_name(const struct bt_ctf_event_decl *event);
78564612 600uint64_t bt_ctf_get_decl_event_id(const struct bt_ctf_event_decl *event);
24a3136a 601const char *bt_ctf_get_decl_field_name(const struct bt_ctf_field_decl *field);
2c0df204 602const struct bt_declaration *bt_ctf_get_decl_from_def(const struct bt_definition *field);
8bb27181 603const struct bt_declaration *bt_ctf_get_decl_from_field_decl(const struct bt_ctf_field_decl *field);
786207e0
XH
604uint64_t bt_sequence_len(struct definition_sequence *sequence);
605struct bt_definition *bt_sequence_index(struct definition_sequence *sequence, uint64_t i);
3a068915
JG
606uint64_t bt_ctf_get_struct_field_count(const struct bt_definition *structure);
607const struct bt_definition *bt_ctf_get_struct_field_index(const struct bt_definition *structure, uint64_t i);
24a3136a
DS
608
609%pythoncode%{
610
24d5c942 611class CTFStringEncoding:
be02a6e6
JG
612 NONE = 0
613 UTF8 = 1
614 ASCII = 2
615 UNKNOWN = 3
24d5c942 616
8bb27181
JG
617# Based on the enum in ctf-writer/writer.h
618class ByteOrder:
be02a6e6
JG
619 BYTE_ORDER_NATIVE = 0
620 BYTE_ORDER_LITTLE_ENDIAN = 1
621 BYTE_ORDER_BIG_ENDIAN = 2
622 BYTE_ORDER_NETWORK = 3
623 BYTE_ORDER_UNKNOWN = 4 # Python-specific entry
624
625# enum equivalent, accessible constants
626# These are taken directly from ctf/events.h
627# All changes to enums must also be made here
24d5c942 628class CTFTypeId:
be02a6e6
JG
629 UNKNOWN = 0
630 INTEGER = 1
631 FLOAT = 2
632 ENUM = 3
633 STRING = 4
634 STRUCT = 5
635 UNTAGGED_VARIANT = 6
636 VARIANT = 7
637 ARRAY = 8
638 SEQUENCE = 9
639 NR_CTF_TYPES = 10
640
641 def type_name(id):
642 name = "UNKNOWN_TYPE"
643 constants = [
644 attr for attr in dir(CTFTypeId) if not callable(
645 getattr(
646 CTFTypeId,
647 attr)) and not attr.startswith("__")]
648 for attr in constants:
649 if getattr(CTFTypeId, attr) == id:
650 name = attr
651 break
652 return name
653
24d5c942 654
8bb27181 655class CTFScope:
be02a6e6
JG
656 TRACE_PACKET_HEADER = 0
657 STREAM_PACKET_CONTEXT = 1
658 STREAM_EVENT_HEADER = 2
659 STREAM_EVENT_CONTEXT = 3
660 EVENT_CONTEXT = 4
661 EVENT_FIELDS = 5
662
663 def scope_name(scope):
664 name = "UNKNOWN_SCOPE"
665 constants = [
666 attr for attr in dir(CTFScope) if not callable(
667 getattr(
668 CTFScope,
669 attr)) and not attr.startswith("__")]
670 for attr in constants:
671 if getattr(CTFScope, attr) == scope:
672 name = attr
673 break
674 return name
8bb27181 675
e404272a 676# Priority of the scopes when searching for event fields
8bb27181 677_scopes = [CTFScope.EVENT_FIELDS, CTFScope.EVENT_CONTEXT, CTFScope.STREAM_EVENT_CONTEXT,
be02a6e6 678 CTFScope.STREAM_EVENT_HEADER, CTFScope.STREAM_PACKET_CONTEXT, CTFScope.TRACE_PACKET_HEADER]
e404272a 679
78d714e8 680import collections
49a04569 681from datetime import datetime
be02a6e6
JG
682
683
78d714e8 684class Event(collections.Mapping):
78d714e8 685
be02a6e6
JG
686 """
687 This class represents an event from the trace.
688 It is obtained using the TraceCollection generator functions.
689 Do not instantiate.
690 """
691
692 def __init__(self):
693 raise NotImplementedError("Event cannot be instantiated")
694
695 @property
696 def name(self):
697 """Return the name of the event or None on error."""
698 return _bt_ctf_event_name(self._e)
699
700 @property
701 def cycles(self):
702 """
703 Return the timestamp of the event as written in
704 the packet (in cycles) or -1ULL on error.
705 """
706 return _bt_ctf_get_cycles(self._e)
707
708 @property
709 def timestamp(self):
710 """
711 Return the timestamp of the event offset with the
712 system clock source or -1ULL on error.
713 """
714 return _bt_ctf_get_timestamp(self._e)
715
716 @property
717 def datetime(self):
718 """
719 Return a datetime object based on the event's
720 timestamp. Note that the datetime class' precision
721 is limited to microseconds.
722 """
723 return datetime.fromtimestamp(self.timestamp / 1E9)
724
725 def field_with_scope(self, field_name, scope):
726 """
727 Get field_name's value in scope.
728 None is returned if no field matches field_name.
729 """
730 if not scope in _scopes:
731 raise ValueError("Invalid scope provided")
732 field = self._field_with_scope(field_name, scope)
733 if field is not None:
734 return field.value
735 return None
736
737 def field_list_with_scope(self, scope):
738 """Return a list of field names in scope."""
739 if not scope in _scopes:
740 raise ValueError("Invalid scope provided")
741 field_names = []
742 for field in self._field_list_with_scope(scope):
743 field_names.append(field.name)
744 return field_names
745
746 @property
747 def handle(self):
748 """
749 Get the TraceHandle associated with this event
750 Return None on error
751 """
752 ret = _bt_ctf_event_get_handle_id(self._e)
753 if ret < 0:
754 return None
755
756 th = TraceHandle.__new__(TraceHandle)
757 th._id = ret
758 th._trace_collection = self.get_trace_collection()
759 return th
760
761 @property
762 def trace_collection(self):
763 """
764 Get the TraceCollection associated with this event.
765 Return None on error.
766 """
767 trace_collection = TraceCollection()
768 trace_collection._tc = _bt_ctf_event_get_context(self._e)
769 if trace_collection._tc is None:
770 return None
771 else:
772 return trace_collection
773
774 def __getitem__(self, field_name):
775 """
776 Get field_name's value. If the field_name exists in multiple
777 scopes, the first field found is returned. The scopes are searched
778 in the following order:
779 1) EVENT_FIELDS
780 2) EVENT_CONTEXT
781 3) STREAM_EVENT_CONTEXT
782 4) STREAM_EVENT_HEADER
783 5) STREAM_PACKET_CONTEXT
784 6) TRACE_PACKET_HEADER
785 None is returned if no field matches field_name.
786
787 Use field_with_scope() to explicitly access fields in a given
788 scope.
789 """
790 field = self._field(field_name)
791 if field is not None:
792 return field.value
793 raise KeyError(field_name)
794
795 def __iter__(self):
796 for key in self.keys():
797 yield key
798
799 def __len__(self):
800 count = 0
801 for scope in _scopes:
802 scope_ptr = _bt_ctf_get_top_level_scope(self._e, scope)
803 ret = _bt_python_field_listcaller(self._e, scope_ptr)
804 if isinstance(ret, list):
805 count += ret[1]
806 return count
807
808 def __contains__(self, field_name):
809 return self._field(field_name) is not None
810
811 def keys(self):
812 """Return a list of field names."""
813 field_names = set()
814 for scope in _scopes:
815 for name in self.field_list_with_scope(scope):
816 field_names.add(name)
817 return list(field_names)
818
819 def get(self, field_name, default=None):
820 field = self._field(field_name)
821 if field is None:
822 return default
823 return field.value
824
825 def items(self):
826 for field in self.keys():
827 yield (field, self[field])
828
829 def _field_with_scope(self, field_name, scope):
830 scope_ptr = _bt_ctf_get_top_level_scope(self._e, scope)
831 if scope_ptr is None:
832 return None
833
834 definition_ptr = _bt_ctf_get_field(self._e, scope_ptr, field_name)
835 if definition_ptr is None:
836 return None
837
838 field = _Definition(definition_ptr, scope)
839 return field
840
841 def _field(self, field_name):
842 field = None
843 for scope in _scopes:
844 field = self._field_with_scope(field_name, scope)
845 if field is not None:
846 break
847 return field
848
849 def _field_list_with_scope(self, scope):
850 fields = []
851 scope_ptr = _bt_ctf_get_top_level_scope(self._e, scope)
852
853 # Returns a list [list_ptr, count]. If list_ptr is NULL, SWIG will only
854 # provide the "count" return value
855 count = 0
856 list_ptr = None
857 ret = _bt_python_field_listcaller(self._e, scope_ptr)
858 if isinstance(ret, list):
859 list_ptr, count = ret
860
861 for i in range(count):
862 definition_ptr = _bt_python_field_one_from_list(list_ptr, i)
863 if definition_ptr is not None:
864 definition = _Definition(definition_ptr, scope)
865 fields.append(definition)
866 return fields
78d714e8 867
78d714e8
JG
868
869class FieldError(Exception):
78d714e8 870
be02a6e6
JG
871 def __init__(self, value):
872 self.value = value
873
874 def __str__(self):
875 return repr(self.value)
876
78d714e8 877
cb1fcc68 878class EventDeclaration(object):
be02a6e6
JG
879
880 """Event declaration class. Do not instantiate."""
881 MAX_UINT64 = 0xFFFFFFFFFFFFFFFF
882
883 def __init__(self):
884 raise NotImplementedError("EventDeclaration cannot be instantiated")
885
886 @property
887 def name(self):
888 """Return the name of the event or None on error"""
889 return _bt_ctf_get_decl_event_name(self._ed)
890
891 @property
892 def id(self):
893 """Return the event-ID of the event or -1 on error"""
894 id = _bt_ctf_get_decl_event_id(self._ed)
895 if id == self.MAX_UINT64:
896 id = -1
897 return id
898
899 @property
900 def fields(self):
901 """
902 Generator returning all FieldDeclarations of an event, going through
903 each scope in the following order:
904 1) EVENT_FIELDS
905 2) EVENT_CONTEXT
906 3) STREAM_EVENT_CONTEXT
907 4) STREAM_EVENT_HEADER
908 5) STREAM_PACKET_CONTEXT
909 6) TRACE_PACKET_HEADER
910 """
911 for scope in _scopes:
912 for declaration in self.fields_scope(scope):
913 yield declaration
914
915 def fields_scope(self, scope):
916 """
917 Generator returning FieldDeclarations of the current event in scope.
918 """
919 ret = _by_python_field_decl_listcaller(self._ed, scope)
920
921 if not isinstance(ret, list):
922 return
923
924 list_ptr, count = ret
925 for i in range(count):
926 field_declaration_ptr = _bt_python_field_decl_one_from_list(
927 list_ptr,
928 i)
929 if field_declaration_ptr is not None:
930 declaration_ptr = _bt_ctf_get_decl_from_field_decl(
931 field_declaration_ptr)
932 field_declaration = _create_field_declaration(
933 declaration_ptr,
934 _bt_ctf_get_decl_field_name(field_declaration_ptr),
935 scope)
936 yield field_declaration
937
cb1fcc68
JG
938
939class FieldDeclaration(object):
78d714e8 940
be02a6e6 941 """Field declaration class. Do not instantiate."""
8bb27181 942
be02a6e6
JG
943 def __init__(self):
944 raise NotImplementedError("FieldDeclaration cannot be instantiated")
8bb27181 945
be02a6e6
JG
946 def __repr__(self):
947 return "({0}) {1} {2}".format(
948 CTFScope.scope_name(self.scope), CTFTypeId.type_name(self.type), self.name)
8bb27181 949
be02a6e6
JG
950 @property
951 def name(self):
952 """Return the name of a FieldDeclaration or None on error."""
953 return self._name
8bb27181 954
be02a6e6
JG
955 @property
956 def type(self):
957 """
958 Return the FieldDeclaration's type. One of the entries in class
959 CTFTypeId.
960 """
961 return _bt_ctf_field_type(self._fd)
8bb27181 962
be02a6e6
JG
963 @property
964 def scope(self):
965 """
966 Return the FieldDeclaration's scope.
967 """
968 return self._s
8bb27181 969
8bb27181 970
be02a6e6 971class IntegerFieldDeclaration(FieldDeclaration):
8bb27181 972
be02a6e6
JG
973 """Do not instantiate."""
974
975 def __init__(self):
976 raise NotImplementedError(
977 "IntegerFieldDeclaration cannot be instantiated")
978
979 @property
980 def signedness(self):
981 """
982 Return the signedness of an integer:
983 0 if unsigned; 1 if signed; -1 on error.
984 """
985 return _bt_ctf_get_int_signedness(self._fd)
986
987 @property
988 def base(self):
989 """Return the base of an int or a negative value on error."""
990 return _bt_ctf_get_int_base(self._fd)
991
992 @property
993 def byte_order(self):
994 """
995 Return the byte order. One of class ByteOrder's entries.
996 """
997 ret = _bt_ctf_get_int_byte_order(self._fd)
998 if ret == 1234:
999 return ByteOrder.BYTE_ORDER_LITTLE_ENDIAN
1000 elif ret == 4321:
1001 return ByteOrder.BYTE_ORDER_BIG_ENDIAN
1002 else:
1003 return ByteOrder.BYTE_ORDER_UNKNOWN
1004
1005 @property
1006 def length(self):
1007 """
1008 Return the size, in bits, of an int or a negative
1009 value on error.
1010 """
1011 return _bt_ctf_get_int_len(self._fd)
1012
1013 @property
1014 def encoding(self):
1015 """
1016 Return the encoding. One of class CTFStringEncoding's entries.
1017 Return a negative value on error.
1018 """
1019 return _bt_ctf_get_encoding(self._fd)
8bb27181 1020
8bb27181
JG
1021
1022class EnumerationFieldDeclaration(FieldDeclaration):
be02a6e6
JG
1023
1024 """Do not instantiate."""
1025
1026 def __init__(self):
1027 raise NotImplementedError(
1028 "EnumerationFieldDeclaration cannot be instantiated")
1029
8bb27181
JG
1030
1031class ArrayFieldDeclaration(FieldDeclaration):
8bb27181 1032
be02a6e6
JG
1033 """Do not instantiate."""
1034
1035 def __init__(self):
1036 raise NotImplementedError(
1037 "ArrayFieldDeclaration cannot be instantiated")
1038
1039 @property
1040 def length(self):
1041 """
1042 Return the length of an array or a negative
1043 value on error.
1044 """
1045 return _bt_ctf_get_array_len(self._fd)
1046
1047 @property
1048 def element_declaration(self):
1049 """
1050 Return element declaration.
1051 """
1052 field_decl_ptr = _bt_python_get_array_element_declaration(self._fd)
1053 return _create_field_declaration(field_decl_ptr, "", self.scope)
8bb27181 1054
5792eb34 1055
8bb27181 1056class SequenceFieldDeclaration(FieldDeclaration):
8bb27181 1057
be02a6e6
JG
1058 """Do not instantiate."""
1059
1060 def __init__(self):
1061 raise NotImplementedError(
1062 "SequenceFieldDeclaration cannot be instantiated")
1063
1064 @property
1065 def element_declaration(self):
1066 """
1067 Return element declaration.
1068 """
1069 field_decl_ptr = _bt_python_get_sequence_element_declaration(self._fd)
1070 return _create_field_declaration(field_decl_ptr, "", self.scope)
1071
3866c850 1072
8bb27181 1073class FloatFieldDeclaration(FieldDeclaration):
be02a6e6
JG
1074
1075 """Do not instantiate."""
1076
1077 def __init__(self):
1078 raise NotImplementedError(
1079 "FloatFieldDeclaration cannot be instantiated")
1080
8bb27181
JG
1081
1082class StructureFieldDeclaration(FieldDeclaration):
8bb27181 1083
be02a6e6 1084 """Do not instantiate."""
8bb27181 1085
be02a6e6
JG
1086 def __init__(self):
1087 raise NotImplementedError(
1088 "StructureFieldDeclaration cannot be instantiated")
78d714e8 1089
78d714e8 1090
be02a6e6 1091class StringFieldDeclaration(FieldDeclaration):
78d714e8 1092
be02a6e6 1093 """Do not instantiate."""
78d714e8 1094
be02a6e6
JG
1095 def __init__(self):
1096 raise NotImplementedError(
1097 "StringFieldDeclaration cannot be instantiated")
78d714e8 1098
78d714e8 1099
be02a6e6 1100class VariantFieldDeclaration(FieldDeclaration):
78d714e8 1101
be02a6e6 1102 """Do not instantiate."""
78d714e8 1103
be02a6e6
JG
1104 def __init__(self):
1105 raise NotImplementedError(
1106 "VariantFieldDeclaration cannot be instantiated")
78d714e8 1107
78d714e8 1108
be02a6e6
JG
1109def field_error():
1110 """
1111 Return the last error code encountered while
1112 accessing a field and reset the error flag.
1113 Return 0 if no error, a negative value otherwise.
1114 """
1115 return _bt_ctf_field_get_error()
78d714e8 1116
78d714e8 1117
be02a6e6
JG
1118def _create_field_declaration(declaration_ptr, name, scope):
1119 """
1120 Private field declaration factory.
1121 """
1122 if declaration_ptr is None:
1123 raise ValueError("declaration_ptr must be valid")
1124 if not scope in _scopes:
1125 raise ValueError("Invalid scope provided")
1126
1127 type = _bt_ctf_field_type(declaration_ptr)
1128 declaration = None
1129 if type == CTFTypeId.INTEGER:
1130 declaration = IntegerFieldDeclaration.__new__(IntegerFieldDeclaration)
1131 elif type == CTFTypeId.ENUM:
1132 declaration = EnumerationFieldDeclaration.__new__(
1133 EnumerationFieldDeclaration)
1134 elif type == CTFTypeId.ARRAY:
1135 declaration = ArrayFieldDeclaration.__new__(ArrayFieldDeclaration)
1136 elif type == CTFTypeId.SEQUENCE:
1137 declaration = SequenceFieldDeclaration.__new__(
1138 SequenceFieldDeclaration)
1139 elif type == CTFTypeId.FLOAT:
1140 declaration = FloatFieldDeclaration.__new__(FloatFieldDeclaration)
1141 elif type == CTFTypeId.STRUCT:
1142 declaration = StructureFieldDeclaration.__new__(
1143 StructureFieldDeclaration)
1144 elif type == CTFTypeId.STRING:
1145 declaration = StringFieldDeclaration.__new__(StringFieldDeclaration)
1146 elif type == CTFTypeId.VARIANT:
1147 declaration = VariantFieldDeclaration.__new__(VariantFieldDeclaration)
1148 else:
1149 return declaration
1150
1151 declaration._fd = declaration_ptr
1152 declaration._s = scope
1153 declaration._name = name
1154 return declaration
78d714e8 1155
78d714e8 1156
be02a6e6
JG
1157class _Definition(object):
1158
1159 def __init__(self, definition_ptr, scope):
1160 self._d = definition_ptr
1161 self._s = scope
1162 if not scope in _scopes:
1163 ValueError("Invalid scope provided")
1164
1165 @property
1166 def name(self):
1167 """Return the name of a field or None on error."""
1168 return _bt_ctf_field_name(self._d)
1169
1170 @property
1171 def type(self):
1172 """Return the type of a field or -1 if unknown."""
1173 return _bt_ctf_field_type(_bt_ctf_get_decl_from_def(self._d))
1174
1175 @property
1176 def declaration(self):
1177 """Return the associated Definition object."""
1178 return _create_field_declaration(
1179 _bt_ctf_get_decl_from_def(self._d), self.name, self.scope)
1180
1181 def _get_enum_str(self):
1182 """
1183 Return the string matching the current enumeration.
1184 Return None on error.
1185 """
1186 return _bt_ctf_get_enum_str(self._d)
1187
1188 def _get_array_element_at(self, index):
1189 """
1190 Return the array's element at position index.
1191 Return None on error
1192 """
1193 array_ptr = _bt_python_get_array_from_def(self._d)
1194 if array_ptr is None:
1195 return None
1196
1197 definition_ptr = _bt_array_index(array_ptr, index)
1198 if definition_ptr is None:
1199 return None
1200 return _Definition(definition_ptr, self.scope)
1201
1202 def _get_sequence_len(self):
1203 """
1204 Return the len of a sequence or a negative
1205 value on error.
1206 """
1207 seq = _bt_python_get_sequence_from_def(self._d)
1208 return _bt_sequence_len(seq)
1209
1210 def _get_sequence_element_at(self, index):
1211 """
1212 Return the sequence's element at position index,
1213 otherwise return None
1214 """
1215 seq = _bt_python_get_sequence_from_def(self._d)
1216 if seq is not None:
1217 definition_ptr = _bt_sequence_index(seq, index)
1218 if definition_ptr is not None:
1219 return _Definition(definition_ptr, self.scope)
1220 return None
1221
1222 def _get_uint64(self):
1223 """
1224 Return the value associated with the field.
1225 If the field does not exist or is not of the type requested,
1226 the value returned is undefined. To check if an error occured,
1227 use the field_error() function after accessing a field.
1228 """
1229 return _bt_ctf_get_uint64(self._d)
1230
1231 def _get_int64(self):
1232 """
1233 Return the value associated with the field.
1234 If the field does not exist or is not of the type requested,
1235 the value returned is undefined. To check if an error occured,
1236 use the field_error() function after accessing a field.
1237 """
1238 return _bt_ctf_get_int64(self._d)
1239
1240 def _get_char_array(self):
1241 """
1242 Return the value associated with the field.
1243 If the field does not exist or is not of the type requested,
1244 the value returned is undefined. To check if an error occurred,
1245 use the field_error() function after accessing a field.
1246 """
1247 return _bt_ctf_get_char_array(self._d)
1248
1249 def _get_str(self):
1250 """
1251 Return the value associated with the field.
1252 If the field does not exist or is not of the type requested,
1253 the value returned is undefined. To check if an error occurred,
1254 use the field_error() function after accessing a field.
1255 """
1256 return _bt_ctf_get_string(self._d)
1257
1258 def _get_float(self):
1259 """
1260 Return the value associated with the field.
1261 If the field does not exist or is not of the type requested,
1262 the value returned is undefined. To check if an error occurred,
1263 use the field_error() function after accessing a field.
1264 """
1265 return _bt_ctf_get_float(self._d)
1266
1267 def _get_variant(self):
1268 """
1269 Return the variant's selected field.
1270 If the field does not exist or is not of the type requested,
1271 the value returned is undefined. To check if an error occurred,
1272 use the field_error() function after accessing a field.
1273 """
1274 return _bt_ctf_get_variant(self._d)
1275
1276 def _get_struct_field_count(self):
1277 """
1278 Return the number of fields contained in the structure.
1279 If the field does not exist or is not of the type requested,
1280 the value returned is undefined.
1281 """
1282 return _bt_ctf_get_struct_field_count(self._d)
1283
1284 def _get_struct_field_at(self, i):
1285 """
1286 Return the structure's field at position i.
1287 If the field does not exist or is not of the type requested,
1288 the value returned is undefined. To check if an error occurred,
1289 use the field_error() function after accessing a field.
1290 """
1291 return _bt_ctf_get_struct_field_index(self._d, i)
1292
1293 @property
1294 def value(self):
1295 """
1296 Return the value associated with the field according to its type.
1297 Return None on error.
1298 """
1299 id = self.type
1300 value = None
1301
1302 if id == CTFTypeId.STRING:
1303 value = self._get_str()
1304 elif id == CTFTypeId.ARRAY:
1305 element_decl = self.declaration.element_declaration
1306 if ((element_decl.type == CTFTypeId.INTEGER
1307 and element_decl.length == 8)
1308 and (element_decl.encoding == CTFStringEncoding.ASCII or element_decl.encoding == CTFStringEncoding.UTF8)):
1309 value = _bt_python_get_array_string(self._d)
1310 else:
1311 value = []
1312 for i in range(self.declaration.length):
1313 element = self._get_array_element_at(i)
1314 value.append(element.value)
1315 elif id == CTFTypeId.INTEGER:
1316 if self.declaration.signedness == 0:
1317 value = self._get_uint64()
1318 else:
1319 value = self._get_int64()
1320 elif id == CTFTypeId.ENUM:
1321 value = self._get_enum_str()
1322 elif id == CTFTypeId.SEQUENCE:
1323 element_decl = self.declaration.element_declaration
1324 if ((element_decl.type == CTFTypeId.INTEGER
1325 and element_decl.length == 8)
1326 and (element_decl.encoding == CTFStringEncoding.ASCII or element_decl.encoding == CTFStringEncoding.UTF8)):
1327 value = _bt_python_get_sequence_string(self._d)
1328 else:
1329 seq_len = self._get_sequence_len()
1330 value = []
1331 for i in range(seq_len):
1332 evDef = self._get_sequence_element_at(i)
1333 value.append(evDef.value)
1334 elif id == CTFTypeId.FLOAT:
1335 value = self._get_float()
1336 elif id == CTFTypeId.VARIANT:
1337 variant = _Definition.__new__(_Definition)
1338 variant._d = self._get_variant()
1339 value = variant.value
1340 elif id == CTFTypeId.STRUCT:
1341 value = {}
1342 for i in range(self._get_struct_field_count()):
1343 member = _Definition(self._get_struct_field_at(i), self.scope)
1344 value[member.name] = member.value
1345
1346 if field_error():
1347 raise FieldError(
1348 "Error occurred while accessing field {} of type {}".format(
1349 self.name,
1350 CTFTypeId.type_name(id)))
1351 return value
1352
1353 @property
1354 def scope(self):
1355 """Return the scope of a field or None on error."""
1356 return self._s
78d714e8 1357
24a3136a
DS
1358%}
1359
1360
ec8c88d7
JG
1361// =================================================================
1362// CTF Writer
1363// =================================================================
1364
1365/* =================================================================
1366 CLOCK.H
1367 ¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯
1368*/
1369%rename("_bt_ctf_clock_create") bt_ctf_clock_create(const char *name);
b0bb560c
JG
1370%rename("_bt_ctf_clock_get_name") bt_ctf_clock_get_name(struct bt_ctf_clock *clock);
1371%rename("_bt_ctf_clock_get_description") bt_ctf_clock_get_description(struct bt_ctf_clock *clock);
ec8c88d7 1372%rename("_bt_ctf_clock_set_description") bt_ctf_clock_set_description(struct bt_ctf_clock *clock, const char *desc);
b0bb560c 1373%rename("_bt_ctf_clock_get_frequency") bt_ctf_clock_get_frequency(struct bt_ctf_clock *clock);
ec8c88d7 1374%rename("_bt_ctf_clock_set_frequency") bt_ctf_clock_set_frequency(struct bt_ctf_clock *clock, uint64_t freq);
b0bb560c 1375%rename("_bt_ctf_clock_get_precision") bt_ctf_clock_get_precision(struct bt_ctf_clock *clock);
ec8c88d7 1376%rename("_bt_ctf_clock_set_precision") bt_ctf_clock_set_precision(struct bt_ctf_clock *clock, uint64_t precision);
b0bb560c 1377%rename("_bt_ctf_clock_get_offset_s") bt_ctf_clock_get_offset_s(struct bt_ctf_clock *clock);
ec8c88d7 1378%rename("_bt_ctf_clock_set_offset_s") bt_ctf_clock_set_offset_s(struct bt_ctf_clock *clock, uint64_t offset_s);
b0bb560c 1379%rename("_bt_ctf_clock_get_offset") bt_ctf_clock_get_offset(struct bt_ctf_clock *clock);
ec8c88d7 1380%rename("_bt_ctf_clock_set_offset") bt_ctf_clock_set_offset(struct bt_ctf_clock *clock, uint64_t offset);
b0bb560c 1381%rename("_bt_ctf_clock_get_is_absolute") bt_ctf_clock_get_is_absolute(struct bt_ctf_clock *clock);
ec8c88d7 1382%rename("_bt_ctf_clock_set_is_absolute") bt_ctf_clock_set_is_absolute(struct bt_ctf_clock *clock, int is_absolute);
b0bb560c 1383%rename("_bt_ctf_clock_get_time") bt_ctf_clock_get_time(struct bt_ctf_clock *clock);
ec8c88d7
JG
1384%rename("_bt_ctf_clock_set_time") bt_ctf_clock_set_time(struct bt_ctf_clock *clock, uint64_t time);
1385%rename("_bt_ctf_clock_get") bt_ctf_clock_get(struct bt_ctf_clock *clock);
1386%rename("_bt_ctf_clock_put") bt_ctf_clock_put(struct bt_ctf_clock *clock);
1387
1388struct bt_ctf_clock *bt_ctf_clock_create(const char *name);
b0bb560c
JG
1389const char *bt_ctf_clock_get_name(struct bt_ctf_clock *clock);
1390const char *bt_ctf_clock_get_description(struct bt_ctf_clock *clock);
ec8c88d7 1391int bt_ctf_clock_set_description(struct bt_ctf_clock *clock, const char *desc);
b0bb560c 1392uint64_t bt_ctf_clock_get_frequency(struct bt_ctf_clock *clock);
ec8c88d7 1393int bt_ctf_clock_set_frequency(struct bt_ctf_clock *clock, uint64_t freq);
b0bb560c 1394uint64_t bt_ctf_clock_get_precision(struct bt_ctf_clock *clock);
ec8c88d7 1395int bt_ctf_clock_set_precision(struct bt_ctf_clock *clock, uint64_t precision);
b0bb560c 1396uint64_t bt_ctf_clock_get_offset_s(struct bt_ctf_clock *clock);
ec8c88d7 1397int bt_ctf_clock_set_offset_s(struct bt_ctf_clock *clock, uint64_t offset_s);
b0bb560c 1398uint64_t bt_ctf_clock_get_offset(struct bt_ctf_clock *clock);
ec8c88d7 1399int bt_ctf_clock_set_offset(struct bt_ctf_clock *clock, uint64_t offset);
b0bb560c 1400int bt_ctf_clock_get_is_absolute(struct bt_ctf_clock *clock);
ec8c88d7 1401int bt_ctf_clock_set_is_absolute(struct bt_ctf_clock *clock, int is_absolute);
b0bb560c 1402uint64_t bt_ctf_clock_get_time(struct bt_ctf_clock *clock);
ec8c88d7
JG
1403int bt_ctf_clock_set_time(struct bt_ctf_clock *clock, uint64_t time);
1404void bt_ctf_clock_get(struct bt_ctf_clock *clock);
1405void bt_ctf_clock_put(struct bt_ctf_clock *clock);
1406
1407/* =================================================================
1408 EVENT-TYPES.H
1409 ¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯
1410*/
1411%rename("_bt_ctf_field_type_integer_create") bt_ctf_field_type_integer_create(unsigned int size);
b4b5e4b5
JG
1412%rename("_bt_ctf_field_type_integer_get_size") bt_ctf_field_type_integer_get_size(struct bt_ctf_field_type *integer);
1413%rename("_bt_ctf_field_type_integer_get_signed") bt_ctf_field_type_integer_get_signed(struct bt_ctf_field_type *integer);
ec8c88d7 1414%rename("_bt_ctf_field_type_integer_set_signed") bt_ctf_field_type_integer_set_signed(struct bt_ctf_field_type *integer, int is_signed);
b4b5e4b5 1415%rename("_bt_ctf_field_type_integer_get_base") bt_ctf_field_type_integer_get_base(struct bt_ctf_field_type *integer);
ec8c88d7 1416%rename("_bt_ctf_field_type_integer_set_base") bt_ctf_field_type_integer_set_base(struct bt_ctf_field_type *integer, enum bt_ctf_integer_base base);
b4b5e4b5 1417%rename("_bt_ctf_field_type_integer_get_encoding") bt_ctf_field_type_integer_get_encoding(struct bt_ctf_field_type *integer);
ec8c88d7
JG
1418%rename("_bt_ctf_field_type_integer_set_encoding") bt_ctf_field_type_integer_set_encoding(struct bt_ctf_field_type *integer, enum ctf_string_encoding encoding);
1419%rename("_bt_ctf_field_type_enumeration_create") bt_ctf_field_type_enumeration_create(struct bt_ctf_field_type *integer_container_type);
b4b5e4b5
JG
1420%rename("_bt_ctf_field_type_enumeration_get_container_type") bt_ctf_field_type_enumeration_get_container_type(struct bt_ctf_field_type *enumeration);
1421%rename("_bt_ctf_field_type_enumeration_add_mapping") bt_ctf_field_type_enumeration_add_mapping(struct bt_ctf_field_type *enumeration, const char *name, int64_t range_start, int64_t range_end);
1422%rename("_bt_ctf_field_type_enumeration_add_mapping_unsigned") bt_ctf_field_type_enumeration_add_mapping_unsigned(struct bt_ctf_field_type *enumeration, const char *name, uint64_t range_start, uint64_t range_end);
1423%rename("_bt_ctf_field_type_enumeration_get_mapping_count") bt_ctf_field_type_enumeration_get_mapping_count(struct bt_ctf_field_type *enumeration);
1424%rename("_bt_ctf_field_type_enumeration_get_mapping") bt_ctf_field_type_enumeration_get_mapping(struct bt_ctf_field_type *enumeration, size_t index, const char **name, int64_t *range_start, int64_t *range_end);
1425%rename("_bt_ctf_field_type_enumeration_get_mapping_unsigned") bt_ctf_field_type_enumeration_get_mapping_unsigned(struct bt_ctf_field_type *enumeration, size_t index, const char **name, uint64_t *range_start, uint64_t *range_end);
1426%rename("_bt_ctf_field_type_enumeration_get_mapping_index_by_name") bt_ctf_field_type_enumeration_get_mapping_index_by_name(struct bt_ctf_field_type *enumeration, const char *name, size_t *index);
1427%rename("_bt_ctf_field_type_enumeration_get_mapping_index_by_value") bt_ctf_field_type_enumeration_get_mapping_index_by_value(struct bt_ctf_field_type *enumeration, int64_t value, size_t *index);
1428%rename("_bt_ctf_field_type_enumeration_get_mapping_index_by_unsigned_value") bt_ctf_field_type_enumeration_get_mapping_index_by_unsigned_value(struct bt_ctf_field_type *enumeration, uint64_t value, size_t *index);
ec8c88d7 1429%rename("_bt_ctf_field_type_floating_point_create") bt_ctf_field_type_floating_point_create(void);
b4b5e4b5 1430%rename("_bt_ctf_field_type_floating_point_get_exponent_digits") bt_ctf_field_type_floating_point_get_exponent_digits(struct bt_ctf_field_type *floating_point);
ec8c88d7 1431%rename("_bt_ctf_field_type_floating_point_set_exponent_digits") bt_ctf_field_type_floating_point_set_exponent_digits(struct bt_ctf_field_type *floating_point, unsigned int exponent_digits);
b4b5e4b5 1432%rename("_bt_ctf_field_type_floating_point_get_mantissa_digits") bt_ctf_field_type_floating_point_get_mantissa_digits(struct bt_ctf_field_type *floating_point);
ec8c88d7
JG
1433%rename("_bt_ctf_field_type_floating_point_set_mantissa_digits") bt_ctf_field_type_floating_point_set_mantissa_digits(struct bt_ctf_field_type *floating_point, unsigned int mantissa_digits);
1434%rename("_bt_ctf_field_type_structure_create") bt_ctf_field_type_structure_create(void);
1435%rename("_bt_ctf_field_type_structure_add_field") bt_ctf_field_type_structure_add_field(struct bt_ctf_field_type *structure, struct bt_ctf_field_type *field_type, const char *field_name);
b4b5e4b5
JG
1436%rename("_bt_ctf_field_type_structure_get_field_count") bt_ctf_field_type_structure_get_field_count(struct bt_ctf_field_type *structure);
1437%rename("_bt_ctf_field_type_structure_get_field") bt_ctf_field_type_structure_get_field(struct bt_ctf_field_type *structure, const char **field_name, struct bt_ctf_field_type **field_type, size_t index);
1438%rename("_bt_ctf_field_type_structure_get_field_type_by_name") bt_ctf_field_type_structure_get_field_type_by_name(struct bt_ctf_field_type *structure, const char *field_name);
ec8c88d7 1439%rename("_bt_ctf_field_type_variant_create") bt_ctf_field_type_variant_create(struct bt_ctf_field_type *enum_tag, const char *tag_name);
b4b5e4b5
JG
1440%rename("_bt_ctf_field_type_variant_get_tag_type") bt_ctf_field_type_variant_get_tag_type(struct bt_ctf_field_type *variant);
1441%rename("_bt_ctf_field_type_variant_get_tag_name") bt_ctf_field_type_variant_get_tag_name(struct bt_ctf_field_type *variant);
ec8c88d7 1442%rename("_bt_ctf_field_type_variant_add_field") bt_ctf_field_type_variant_add_field(struct bt_ctf_field_type *variant, struct bt_ctf_field_type *field_type, const char *field_name);
b4b5e4b5
JG
1443%rename("_bt_ctf_field_type_variant_get_field_type_by_name") bt_ctf_field_type_variant_get_field_type_by_name(struct bt_ctf_field_type *variant, const char *field_name);
1444%rename("_bt_ctf_field_type_variant_get_field_type_from_tag") bt_ctf_field_type_variant_get_field_type_from_tag(struct bt_ctf_field_type *variant, struct bt_ctf_field *tag);
1445%rename("_bt_ctf_field_type_variant_get_field_count") bt_ctf_field_type_variant_get_field_count(struct bt_ctf_field_type *variant);
1446%rename("_bt_ctf_field_type_variant_get_field") bt_ctf_field_type_variant_get_field(struct bt_ctf_field_type *variant, const char **field_name, struct bt_ctf_field_type **field_type, size_t index);
ec8c88d7 1447%rename("_bt_ctf_field_type_array_create") bt_ctf_field_type_array_create(struct bt_ctf_field_type *element_type, unsigned int length);
b4b5e4b5
JG
1448%rename("_bt_ctf_field_type_array_get_element_type") bt_ctf_field_type_array_get_element_type(struct bt_ctf_field_type *array);
1449%rename("_bt_ctf_field_type_array_get_length") bt_ctf_field_type_array_get_length(struct bt_ctf_field_type *array);
ec8c88d7 1450%rename("_bt_ctf_field_type_sequence_create") bt_ctf_field_type_sequence_create(struct bt_ctf_field_type *element_type, const char *length_field_name);
b4b5e4b5
JG
1451%rename("_bt_ctf_field_type_sequence_get_element_type") bt_ctf_field_type_sequence_get_element_type(struct bt_ctf_field_type *sequence);
1452%rename("_bt_ctf_field_type_sequence_get_length_field_name") bt_ctf_field_type_sequence_get_length_field_name(struct bt_ctf_field_type *sequence);
ec8c88d7 1453%rename("_bt_ctf_field_type_string_create") bt_ctf_field_type_string_create(void);
b4b5e4b5
JG
1454%rename("_bt_ctf_field_type_string_get_encoding") bt_ctf_field_type_string_get_encoding(struct bt_ctf_field_type *string_type);
1455%rename("_bt_ctf_field_type_string_set_encoding") bt_ctf_field_type_string_set_encoding(struct bt_ctf_field_type *string_type, enum ctf_string_encoding encoding);
1456%rename("_bt_ctf_field_type_get_alignment") bt_ctf_field_type_get_alignment(struct bt_ctf_field_type *type);
ec8c88d7 1457%rename("_bt_ctf_field_type_set_alignment") bt_ctf_field_type_set_alignment(struct bt_ctf_field_type *type, unsigned int alignment);
b4b5e4b5 1458%rename("_bt_ctf_field_type_get_byte_order") bt_ctf_field_type_get_byte_order(struct bt_ctf_field_type *type);
ec8c88d7 1459%rename("_bt_ctf_field_type_set_byte_order") bt_ctf_field_type_set_byte_order(struct bt_ctf_field_type *type, enum bt_ctf_byte_order byte_order);
b4b5e4b5 1460%rename("_bt_ctf_field_type_get_type_id") bt_ctf_field_type_get_type_id(struct bt_ctf_field_type *type);
ec8c88d7
JG
1461%rename("_bt_ctf_field_type_get") bt_ctf_field_type_get(struct bt_ctf_field_type *type);
1462%rename("_bt_ctf_field_type_put") bt_ctf_field_type_put(struct bt_ctf_field_type *type);
1463
1464struct bt_ctf_field_type *bt_ctf_field_type_integer_create(unsigned int size);
b4b5e4b5
JG
1465int bt_ctf_field_type_integer_get_size(struct bt_ctf_field_type *integer);
1466int bt_ctf_field_type_integer_get_signed(struct bt_ctf_field_type *integer);
ec8c88d7 1467int bt_ctf_field_type_integer_set_signed(struct bt_ctf_field_type *integer, int is_signed);
b4b5e4b5 1468enum bt_ctf_integer_base bt_ctf_field_type_integer_get_base(struct bt_ctf_field_type *integer);
ec8c88d7 1469int bt_ctf_field_type_integer_set_base(struct bt_ctf_field_type *integer, enum bt_ctf_integer_base base);
b4b5e4b5 1470enum ctf_string_encoding bt_ctf_field_type_integer_get_encoding(struct bt_ctf_field_type *integer);
ec8c88d7
JG
1471int bt_ctf_field_type_integer_set_encoding(struct bt_ctf_field_type *integer, enum ctf_string_encoding encoding);
1472struct bt_ctf_field_type *bt_ctf_field_type_enumeration_create(struct bt_ctf_field_type *integer_container_type);
b4b5e4b5
JG
1473struct bt_ctf_field_type *bt_ctf_field_type_enumeration_get_container_type(struct bt_ctf_field_type *enumeration);
1474int bt_ctf_field_type_enumeration_add_mapping(struct bt_ctf_field_type *enumeration, const char *name, int64_t range_start, int64_t range_end);
1475int bt_ctf_field_type_enumeration_add_mapping_unsigned(struct bt_ctf_field_type *enumeration, const char *name, uint64_t range_start, uint64_t range_end);
1476int64_t bt_ctf_field_type_enumeration_get_mapping_count(struct bt_ctf_field_type *enumeration);
1477int bt_ctf_field_type_enumeration_get_mapping(struct bt_ctf_field_type *enumeration, size_t index, const char **OUTPUT, int64_t *OUTPUT, int64_t *OUTPUT);
1478int bt_ctf_field_type_enumeration_get_mapping_unsigned(struct bt_ctf_field_type *enumeration, size_t index, const char **OUTPUT, uint64_t *OUTPUT, uint64_t *OUTPUT);
1479int bt_ctf_field_type_enumeration_get_mapping_index_by_name(struct bt_ctf_field_type *enumeration, const char *name, size_t *OUTPUT);
1480int bt_ctf_field_type_enumeration_get_mapping_index_by_value(struct bt_ctf_field_type *enumeration, int64_t value, size_t *OUTPUT);
1481int bt_ctf_field_type_enumeration_get_mapping_index_by_unsigned_value(struct bt_ctf_field_type *enumeration, uint64_t value, size_t *OUTPUT);
ec8c88d7 1482struct bt_ctf_field_type *bt_ctf_field_type_floating_point_create(void);
b4b5e4b5 1483int bt_ctf_field_type_floating_point_get_exponent_digits(struct bt_ctf_field_type *floating_point);
ec8c88d7 1484int bt_ctf_field_type_floating_point_set_exponent_digits(struct bt_ctf_field_type *floating_point, unsigned int exponent_digits);
b4b5e4b5 1485int bt_ctf_field_type_floating_point_get_mantissa_digits(struct bt_ctf_field_type *floating_point);
ec8c88d7
JG
1486int bt_ctf_field_type_floating_point_set_mantissa_digits(struct bt_ctf_field_type *floating_point, unsigned int mantissa_digits);
1487struct bt_ctf_field_type *bt_ctf_field_type_structure_create(void);
1488int bt_ctf_field_type_structure_add_field(struct bt_ctf_field_type *structure, struct bt_ctf_field_type *field_type, const char *field_name);
b4b5e4b5
JG
1489int64_t bt_ctf_field_type_structure_get_field_count(struct bt_ctf_field_type *structure);
1490int bt_ctf_field_type_structure_get_field(struct bt_ctf_field_type *structure, const char **OUTPUT, struct bt_ctf_field_type **OUTPUT, size_t index);
1491struct bt_ctf_field_type *bt_ctf_field_type_structure_get_field_type_by_name(struct bt_ctf_field_type *structure, const char *field_name);
ec8c88d7 1492struct bt_ctf_field_type *bt_ctf_field_type_variant_create(struct bt_ctf_field_type *enum_tag, const char *tag_name);
b4b5e4b5
JG
1493struct bt_ctf_field_type *bt_ctf_field_type_variant_get_tag_type(struct bt_ctf_field_type *variant);
1494const char *bt_ctf_field_type_variant_get_tag_name(struct bt_ctf_field_type *variant);
ec8c88d7 1495int bt_ctf_field_type_variant_add_field(struct bt_ctf_field_type *variant, struct bt_ctf_field_type *field_type, const char *field_name);
b4b5e4b5
JG
1496struct bt_ctf_field_type *bt_ctf_field_type_variant_get_field_type_by_name(struct bt_ctf_field_type *variant, const char *field_name);
1497struct bt_ctf_field_type *bt_ctf_field_type_variant_get_field_type_from_tag(struct bt_ctf_field_type *variant, struct bt_ctf_field *tag);
1498int64_t bt_ctf_field_type_variant_get_field_count(struct bt_ctf_field_type *variant);
1499int bt_ctf_field_type_variant_get_field(struct bt_ctf_field_type *variant, const char **OUTPUT, struct bt_ctf_field_type **OUTPUT, size_t index);
ec8c88d7 1500struct bt_ctf_field_type *bt_ctf_field_type_array_create(struct bt_ctf_field_type *element_type, unsigned int length);
b4b5e4b5
JG
1501struct bt_ctf_field_type *bt_ctf_field_type_array_get_element_type(struct bt_ctf_field_type *array);
1502int64_t bt_ctf_field_type_array_get_length(struct bt_ctf_field_type *array);
ec8c88d7 1503struct bt_ctf_field_type *bt_ctf_field_type_sequence_create(struct bt_ctf_field_type *element_type, const char *length_field_name);
b4b5e4b5
JG
1504struct bt_ctf_field_type *bt_ctf_field_type_sequence_get_element_type(struct bt_ctf_field_type *sequence);
1505const char *bt_ctf_field_type_sequence_get_length_field_name(struct bt_ctf_field_type *sequence);
ec8c88d7 1506struct bt_ctf_field_type *bt_ctf_field_type_string_create(void);
b4b5e4b5
JG
1507enum ctf_string_encoding bt_ctf_field_type_string_get_encoding(struct bt_ctf_field_type *string_type);
1508int bt_ctf_field_type_string_set_encoding(struct bt_ctf_field_type *string_type, enum ctf_string_encoding encoding);
1509int bt_ctf_field_type_get_alignment(struct bt_ctf_field_type *type);
ec8c88d7 1510int bt_ctf_field_type_set_alignment(struct bt_ctf_field_type *type, unsigned int alignment);
b4b5e4b5 1511enum bt_ctf_byte_order bt_ctf_field_type_get_byte_order(struct bt_ctf_field_type *type);
ec8c88d7 1512int bt_ctf_field_type_set_byte_order(struct bt_ctf_field_type *type, enum bt_ctf_byte_order byte_order);
b4b5e4b5 1513enum ctf_type_id bt_ctf_field_type_get_type_id(struct bt_ctf_field_type *type);
ec8c88d7
JG
1514void bt_ctf_field_type_get(struct bt_ctf_field_type *type);
1515void bt_ctf_field_type_put(struct bt_ctf_field_type *type);
1516
1517/* =================================================================
1518 EVENT-FIELDS.H
1519 ¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯
1520*/
1521%rename("_bt_ctf_field_create") bt_ctf_field_create(struct bt_ctf_field_type *type);
1522%rename("_bt_ctf_field_structure_get_field") bt_ctf_field_structure_get_field(struct bt_ctf_field *structure, const char *name);
1523%rename("_bt_ctf_field_array_get_field") bt_ctf_field_array_get_field(struct bt_ctf_field *array, uint64_t index);
821ca76c 1524%rename("_bt_ctf_field_sequence_get_length") bt_ctf_field_sequence_get_length(struct bt_ctf_field *sequence);
ec8c88d7
JG
1525%rename("_bt_ctf_field_sequence_set_length") bt_ctf_field_sequence_set_length(struct bt_ctf_field *sequence, struct bt_ctf_field *length_field);
1526%rename("_bt_ctf_field_sequence_get_field") bt_ctf_field_sequence_get_field(struct bt_ctf_field *sequence, uint64_t index);
1527%rename("_bt_ctf_field_variant_get_field") bt_ctf_field_variant_get_field(struct bt_ctf_field *variant, struct bt_ctf_field *tag);
1528%rename("_bt_ctf_field_enumeration_get_container") bt_ctf_field_enumeration_get_container(struct bt_ctf_field *enumeration);
821ca76c
JG
1529%rename("_bt_ctf_field_enumeration_get_mapping_name") bt_ctf_field_enumeration_get_mapping_name(struct bt_ctf_field *enumeration);
1530%rename("_bt_ctf_field_signed_integer_get_value") bt_ctf_field_signed_integer_get_value(struct bt_ctf_field *integer, int64_t *value);
ec8c88d7 1531%rename("_bt_ctf_field_signed_integer_set_value") bt_ctf_field_signed_integer_set_value(struct bt_ctf_field *integer, int64_t value);
821ca76c 1532%rename("_bt_ctf_field_unsigned_integer_get_value") bt_ctf_field_unsigned_integer_get_value(struct bt_ctf_field *integer, uint64_t *value);
ec8c88d7 1533%rename("_bt_ctf_field_unsigned_integer_set_value") bt_ctf_field_unsigned_integer_set_value(struct bt_ctf_field *integer, uint64_t value);
821ca76c 1534%rename("_bt_ctf_field_floating_point_get_value") bt_ctf_field_floating_point_get_value(struct bt_ctf_field *floating_point, double *value);
ec8c88d7 1535%rename("_bt_ctf_field_floating_point_set_value") bt_ctf_field_floating_point_set_value(struct bt_ctf_field *floating_point, double value);
b4b5e4b5
JG
1536%rename("_bt_ctf_field_string_get_value") bt_ctf_field_string_get_value(struct bt_ctf_field *string_field);
1537%rename("_bt_ctf_field_string_set_value") bt_ctf_field_string_set_value(struct bt_ctf_field *string_field, const char *value);
821ca76c 1538%rename("_bt_ctf_field_get_type") bt_ctf_field_get_type(struct bt_ctf_field *field);
ec8c88d7
JG
1539%rename("_bt_ctf_field_get") bt_ctf_field_get(struct bt_ctf_field *field);
1540%rename("_bt_ctf_field_put") bt_ctf_field_put(struct bt_ctf_field *field);
1541
1542struct bt_ctf_field *bt_ctf_field_create(struct bt_ctf_field_type *type);
1543struct bt_ctf_field *bt_ctf_field_structure_get_field(struct bt_ctf_field *structure, const char *name);
1544struct bt_ctf_field *bt_ctf_field_array_get_field(struct bt_ctf_field *array, uint64_t index);
821ca76c 1545struct bt_ctf_field * bt_ctf_field_sequence_get_length(struct bt_ctf_field *sequence);
ec8c88d7
JG
1546int bt_ctf_field_sequence_set_length(struct bt_ctf_field *sequence, struct bt_ctf_field *length_field);
1547struct bt_ctf_field *bt_ctf_field_sequence_get_field(struct bt_ctf_field *sequence, uint64_t index);
1548struct bt_ctf_field *bt_ctf_field_variant_get_field(struct bt_ctf_field *variant, struct bt_ctf_field *tag);
1549struct bt_ctf_field *bt_ctf_field_enumeration_get_container(struct bt_ctf_field *enumeration);
821ca76c
JG
1550const char *bt_ctf_field_enumeration_get_mapping_name(struct bt_ctf_field *enumeration);
1551int bt_ctf_field_signed_integer_get_value(struct bt_ctf_field *integer, int64_t *OUTPUT);
ec8c88d7 1552int bt_ctf_field_signed_integer_set_value(struct bt_ctf_field *integer, int64_t value);
821ca76c 1553int bt_ctf_field_unsigned_integer_get_value(struct bt_ctf_field *integer, uint64_t *OUTPUT);
ec8c88d7 1554int bt_ctf_field_unsigned_integer_set_value(struct bt_ctf_field *integer, uint64_t value);
821ca76c 1555int bt_ctf_field_floating_point_get_value(struct bt_ctf_field *floating_point, double *OUTPUT);
ec8c88d7 1556int bt_ctf_field_floating_point_set_value(struct bt_ctf_field *floating_point, double value);
b4b5e4b5
JG
1557const char *bt_ctf_field_string_get_value(struct bt_ctf_field *string_field);
1558int bt_ctf_field_string_set_value(struct bt_ctf_field *string_field, const char *value);
821ca76c 1559struct bt_ctf_field_type *bt_ctf_field_get_type(struct bt_ctf_field *field);
ec8c88d7
JG
1560void bt_ctf_field_get(struct bt_ctf_field *field);
1561void bt_ctf_field_put(struct bt_ctf_field *field);
1562
1563/* =================================================================
1564 EVENT.H
1565 ¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯
1566*/
1567%rename("_bt_ctf_event_class_create") bt_ctf_event_class_create(const char *name);
38f28df6
JG
1568%rename("_bt_ctf_event_class_get_name") bt_ctf_event_class_get_name(struct bt_ctf_event_class *event_class);
1569%rename("_bt_ctf_event_class_get_id") bt_ctf_event_class_get_id(struct bt_ctf_event_class *event_class);
1570%rename("_bt_ctf_event_class_set_id") bt_ctf_event_class_set_id(struct bt_ctf_event_class *event_class, uint32_t id);
1571%rename("_bt_ctf_event_class_get_stream_class") bt_ctf_event_class_get_stream_class(struct bt_ctf_event_class *event_class);
ec8c88d7 1572%rename("_bt_ctf_event_class_add_field") bt_ctf_event_class_add_field(struct bt_ctf_event_class *event_class, struct bt_ctf_field_type *type, const char *name);
38f28df6
JG
1573%rename("_bt_ctf_event_class_get_field_count") bt_ctf_event_class_get_field_count(struct bt_ctf_event_class *event_class);
1574%rename("_bt_ctf_event_class_get_field") bt_ctf_event_class_get_field(struct bt_ctf_event_class *event_class, const char **field_name, struct bt_ctf_field_type **field_type, size_t index);
1575%rename("_bt_ctf_event_class_get_field_by_name") bt_ctf_event_class_get_field_by_name(struct bt_ctf_event_class *event_class, const char *name);
ec8c88d7
JG
1576%rename("_bt_ctf_event_class_get") bt_ctf_event_class_get(struct bt_ctf_event_class *event_class);
1577%rename("_bt_ctf_event_class_put") bt_ctf_event_class_put(struct bt_ctf_event_class *event_class);
1578%rename("_bt_ctf_event_create") bt_ctf_event_create(struct bt_ctf_event_class *event_class);
38f28df6
JG
1579%rename("_bt_ctf_event_get_class") bt_ctf_event_get_class(struct bt_ctf_event *event);
1580%rename("_bt_ctf_event_get_clock") bt_ctf_event_get_clock(struct bt_ctf_event *event);
ec8c88d7 1581%rename("_bt_ctf_event_get_payload") bt_ctf_event_get_payload(struct bt_ctf_event *event, const char *name);
38f28df6
JG
1582%rename("_bt_ctf_event_set_payload") bt_ctf_event_set_payload(struct bt_ctf_event *event, const char *name, struct bt_ctf_field *value);
1583%rename("_bt_ctf_event_get_payload_by_index") bt_ctf_event_get_payload_by_index(struct bt_ctf_event *event, size_t index);
ec8c88d7
JG
1584%rename("_bt_ctf_event_get") bt_ctf_event_get(struct bt_ctf_event *event);
1585%rename("_bt_ctf_event_put") bt_ctf_event_put(struct bt_ctf_event *event);
1586
1587struct bt_ctf_event_class *bt_ctf_event_class_create(const char *name);
38f28df6
JG
1588const char *bt_ctf_event_class_get_name(struct bt_ctf_event_class *event_class);
1589int64_t bt_ctf_event_class_get_id(struct bt_ctf_event_class *event_class);
1590int bt_ctf_event_class_set_id(struct bt_ctf_event_class *event_class, uint32_t id);
1591struct bt_ctf_stream_class *bt_ctf_event_class_get_stream_class(struct bt_ctf_event_class *event_class);
ec8c88d7 1592int bt_ctf_event_class_add_field(struct bt_ctf_event_class *event_class, struct bt_ctf_field_type *type, const char *name);
38f28df6
JG
1593int64_t bt_ctf_event_class_get_field_count(struct bt_ctf_event_class *event_class);
1594int bt_ctf_event_class_get_field(struct bt_ctf_event_class *event_class, const char **field_name, struct bt_ctf_field_type **field_type, size_t index);
1595struct bt_ctf_field_type *bt_ctf_event_class_get_field_by_name(struct bt_ctf_event_class *event_class, const char *name);
ec8c88d7
JG
1596void bt_ctf_event_class_get(struct bt_ctf_event_class *event_class);
1597void bt_ctf_event_class_put(struct bt_ctf_event_class *event_class);
1598struct bt_ctf_event *bt_ctf_event_create(struct bt_ctf_event_class *event_class);
38f28df6
JG
1599struct bt_ctf_event_class *bt_ctf_event_get_class(struct bt_ctf_event *event);
1600struct bt_ctf_clock *bt_ctf_event_get_clock(struct bt_ctf_event *event);
ec8c88d7 1601struct bt_ctf_field *bt_ctf_event_get_payload(struct bt_ctf_event *event, const char *name);
38f28df6
JG
1602int bt_ctf_event_set_payload(struct bt_ctf_event *event, const char *name, struct bt_ctf_field *value);
1603struct bt_ctf_field *bt_ctf_event_get_payload_by_index(struct bt_ctf_event *event, size_t index);
ec8c88d7
JG
1604void bt_ctf_event_get(struct bt_ctf_event *event);
1605void bt_ctf_event_put(struct bt_ctf_event *event);
1606
1607/* =================================================================
1608 STREAM.H
1609 ¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯
1610*/
1611%rename("_bt_ctf_stream_class_create") bt_ctf_stream_class_create(const char *name);
f6c2aa83
JG
1612%rename("_bt_ctf_stream_class_get_name") bt_ctf_stream_class_get_name(struct bt_ctf_stream_class *stream_class);
1613%rename("_bt_ctf_stream_class_get_clock") bt_ctf_stream_class_get_clock(struct bt_ctf_stream_class *stream_class);
ec8c88d7 1614%rename("_bt_ctf_stream_class_set_clock") bt_ctf_stream_class_set_clock(struct bt_ctf_stream_class *stream_class, struct bt_ctf_clock *clock);
f6c2aa83
JG
1615%rename("_bt_ctf_stream_class_get_id") bt_ctf_stream_class_get_id(struct bt_ctf_stream_class *stream_class);
1616%rename("_bt_ctf_stream_class_set_id") bt_ctf_stream_class_set_id(struct bt_ctf_stream_class *stream_class, uint32_t id);
ec8c88d7 1617%rename("_bt_ctf_stream_class_add_event_class") bt_ctf_stream_class_add_event_class(struct bt_ctf_stream_class *stream_class, struct bt_ctf_event_class *event_class);
f6c2aa83
JG
1618%rename("_bt_ctf_stream_class_get_event_class_count") bt_ctf_stream_class_get_event_class_count(struct bt_ctf_stream_class *stream_class);
1619%rename("_bt_ctf_stream_class_get_event_class") bt_ctf_stream_class_get_event_class(struct bt_ctf_stream_class *stream_class, size_t index);
1620%rename("_bt_ctf_stream_class_get_event_class_by_name") bt_ctf_stream_class_get_event_class_by_name(struct bt_ctf_stream_class *stream_class, const char *name);
7df927c7
JG
1621%rename("_bt_ctf_stream_class_get_packet_context_type") bt_ctf_stream_class_get_packet_context_type(struct bt_ctf_stream_class *stream_class);
1622%rename("_bt_ctf_stream_class_set_packet_context_type") bt_ctf_stream_class_set_packet_context_type(struct bt_ctf_stream_class *stream_class, struct bt_ctf_field_type *packet_context_type);
ec8c88d7
JG
1623%rename("_bt_ctf_stream_class_get") bt_ctf_stream_class_get(struct bt_ctf_stream_class *stream_class);
1624%rename("_bt_ctf_stream_class_put") bt_ctf_stream_class_put(struct bt_ctf_stream_class *stream_class);
708e628a 1625%rename("_bt_ctf_stream_get_discarded_events_count") bt_ctf_stream_get_discarded_events_count(struct bt_ctf_stream *stream, uint64_t *count);
ec8c88d7
JG
1626%rename("_bt_ctf_stream_append_discarded_events") bt_ctf_stream_append_discarded_events(struct bt_ctf_stream *stream, uint64_t event_count);
1627%rename("_bt_ctf_stream_append_event") bt_ctf_stream_append_event(struct bt_ctf_stream *stream, struct bt_ctf_event *event);
7df927c7
JG
1628%rename("_bt_ctf_stream_get_packet_context") bt_ctf_stream_get_packet_context(struct bt_ctf_stream *stream);
1629%rename("_bt_ctf_stream_set_packet_context") bt_ctf_stream_set_packet_context(struct bt_ctf_stream *stream, struct bt_ctf_field *packet_context);
ec8c88d7
JG
1630%rename("_bt_ctf_stream_flush") bt_ctf_stream_flush(struct bt_ctf_stream *stream);
1631%rename("_bt_ctf_stream_get") bt_ctf_stream_get(struct bt_ctf_stream *stream);
1632%rename("_bt_ctf_stream_put") bt_ctf_stream_put(struct bt_ctf_stream *stream);
1633
1634struct bt_ctf_stream_class *bt_ctf_stream_class_create(const char *name);
f6c2aa83
JG
1635const char *bt_ctf_stream_class_get_name(struct bt_ctf_stream_class *stream_class);
1636struct bt_ctf_clock *bt_ctf_stream_class_get_clock(struct bt_ctf_stream_class *stream_class);
ec8c88d7 1637int bt_ctf_stream_class_set_clock(struct bt_ctf_stream_class *stream_class, struct bt_ctf_clock *clock);
f6c2aa83
JG
1638int64_t bt_ctf_stream_class_get_id(struct bt_ctf_stream_class *stream_class);
1639int bt_ctf_stream_class_set_id(struct bt_ctf_stream_class *stream_class, uint32_t id);
ec8c88d7 1640int bt_ctf_stream_class_add_event_class(struct bt_ctf_stream_class *stream_class, struct bt_ctf_event_class *event_class);
f6c2aa83
JG
1641int64_t bt_ctf_stream_class_get_event_class_count(struct bt_ctf_stream_class *stream_class);
1642struct bt_ctf_event_class *bt_ctf_stream_class_get_event_class(struct bt_ctf_stream_class *stream_class, size_t index);
1643struct bt_ctf_event_class *bt_ctf_stream_class_get_event_class_by_name(struct bt_ctf_stream_class *stream_class, const char *name);
7df927c7
JG
1644struct bt_ctf_field_type *bt_ctf_stream_class_get_packet_context_type(struct bt_ctf_stream_class *stream_class);
1645int bt_ctf_stream_class_set_packet_context_type(struct bt_ctf_stream_class *stream_class, struct bt_ctf_field_type *packet_context_type);
ec8c88d7
JG
1646void bt_ctf_stream_class_get(struct bt_ctf_stream_class *stream_class);
1647void bt_ctf_stream_class_put(struct bt_ctf_stream_class *stream_class);
708e628a 1648int bt_ctf_stream_get_discarded_events_count(struct bt_ctf_stream *stream, uint64_t *OUTPUT);
ec8c88d7
JG
1649void bt_ctf_stream_append_discarded_events(struct bt_ctf_stream *stream, uint64_t event_count);
1650int bt_ctf_stream_append_event(struct bt_ctf_stream *stream, struct bt_ctf_event *event);
7df927c7
JG
1651struct bt_ctf_field *bt_ctf_stream_get_packet_context(struct bt_ctf_stream *stream);
1652int bt_ctf_stream_set_packet_context(struct bt_ctf_stream *stream, struct bt_ctf_field *packet_context);
ec8c88d7
JG
1653int bt_ctf_stream_flush(struct bt_ctf_stream *stream);
1654void bt_ctf_stream_get(struct bt_ctf_stream *stream);
1655void bt_ctf_stream_put(struct bt_ctf_stream *stream);
1656
1657/* =================================================================
1658 WRITER.H
1659 ¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯
1660*/
1661%rename("_bt_ctf_writer_create") bt_ctf_writer_create(const char *path);
1662%rename("_bt_ctf_writer_create_stream") bt_ctf_writer_create_stream(struct bt_ctf_writer *writer, struct bt_ctf_stream_class *stream_class);
1663%rename("_bt_ctf_writer_add_environment_field") bt_ctf_writer_add_environment_field(struct bt_ctf_writer *writer, const char *name, const char *value);
1664%rename("_bt_ctf_writer_add_clock") bt_ctf_writer_add_clock(struct bt_ctf_writer *writer, struct bt_ctf_clock *clock);
1665%newobject bt_ctf_writer_get_metadata_string;
1666%rename("_bt_ctf_writer_get_metadata_string") bt_ctf_writer_get_metadata_string(struct bt_ctf_writer *writer);
1667%rename("_bt_ctf_writer_flush_metadata") bt_ctf_writer_flush_metadata(struct bt_ctf_writer *writer);
1668%rename("_bt_ctf_writer_set_byte_order") bt_ctf_writer_set_byte_order(struct bt_ctf_writer *writer, enum bt_ctf_byte_order byte_order);
1669%rename("_bt_ctf_writer_get") bt_ctf_writer_get(struct bt_ctf_writer *writer);
1670%rename("_bt_ctf_writer_put") bt_ctf_writer_put(struct bt_ctf_writer *writer);
1671
1672struct bt_ctf_writer *bt_ctf_writer_create(const char *path);
1673struct bt_ctf_stream *bt_ctf_writer_create_stream(struct bt_ctf_writer *writer, struct bt_ctf_stream_class *stream_class);
1674int bt_ctf_writer_add_environment_field(struct bt_ctf_writer *writer, const char *name, const char *value);
1675int bt_ctf_writer_add_clock(struct bt_ctf_writer *writer, struct bt_ctf_clock *clock);
1676char *bt_ctf_writer_get_metadata_string(struct bt_ctf_writer *writer);
1677void bt_ctf_writer_flush_metadata(struct bt_ctf_writer *writer);
1678int bt_ctf_writer_set_byte_order(struct bt_ctf_writer *writer, enum bt_ctf_byte_order byte_order);
1679void bt_ctf_writer_get(struct bt_ctf_writer *writer);
1680void bt_ctf_writer_put(struct bt_ctf_writer *writer);
1681
1682%pythoncode %{
be02a6e6
JG
1683
1684from uuid import UUID
1685
ec8c88d7
JG
1686
1687class CTFWriter:
be02a6e6
JG
1688 # Used to compare to -1ULL in error checks
1689 _MAX_UINT64 = 0xFFFFFFFFFFFFFFFF
ec8c88d7 1690
be02a6e6 1691 """
b4b5e4b5
JG
1692 Enumeration mapping class. start and end values are inclusive.
1693 """
be02a6e6 1694 class EnumerationMapping:
b4b5e4b5 1695
be02a6e6
JG
1696 def __init__(self, name, start, end):
1697 self.name = name
1698 self.start = start
1699 self.end = end
ec8c88d7 1700
be02a6e6 1701 class Clock:
ec8c88d7 1702
be02a6e6
JG
1703 def __init__(self, name):
1704 self._c = _bt_ctf_clock_create(name)
1705 if self._c is None:
1706 raise ValueError("Invalid clock name.")
1707
1708 def __del__(self):
1709 _bt_ctf_clock_put(self._c)
1710
1711 """
b0bb560c
JG
1712 Get the clock's name.
1713 """
be02a6e6
JG
1714 @property
1715 def name(self):
1716 name = _bt_ctf_clock_get_name(self._c)
1717 if name is None:
1718 raise ValueError("Invalid clock instance.")
1719 return name
b0bb560c 1720
be02a6e6 1721 """
b0bb560c 1722 Get the clock's description. None if unset.
14001277 1723 """
be02a6e6
JG
1724 @property
1725 def description(self):
1726 return _bt_ctf_clock_get_description(self._c)
14001277 1727
be02a6e6 1728 """
ec8c88d7
JG
1729 Set the clock's description. The description appears in the clock's TSDL
1730 meta-data.
1731 """
be02a6e6
JG
1732 @description.setter
1733 def description(self, desc):
1734 ret = _bt_ctf_clock_set_description(self._c, str(desc))
1735 if ret < 0:
1736 raise ValueError("Invalid clock description.")
ec8c88d7 1737
be02a6e6 1738 """
14001277
JG
1739 Get the clock's frequency (Hz).
1740 """
be02a6e6
JG
1741 @property
1742 def frequency(self):
1743 freq = _bt_ctf_clock_get_frequency(self._c)
1744 if freq == CTFWriter._MAX_UINT64:
1745 raise ValueError("Invalid clock instance")
1746 return freq
14001277 1747
be02a6e6 1748 """
ec8c88d7
JG
1749 Set the clock's frequency (Hz).
1750 """
be02a6e6
JG
1751 @frequency.setter
1752 def frequency(self, freq):
1753 ret = _bt_ctf_clock_set_frequency(self._c, freq)
1754 if ret < 0:
1755 raise ValueError("Invalid frequency value.")
ec8c88d7 1756
be02a6e6 1757 """
14001277
JG
1758 Get the clock's precision (in clock ticks).
1759 """
be02a6e6
JG
1760 @property
1761 def precision(self):
1762 precision = _bt_ctf_clock_get_precision(self._c)
1763 if precision == CTFWriter._MAX_UINT64:
1764 raise ValueError("Invalid clock instance")
1765 return precision
14001277 1766
be02a6e6 1767 """
ec8c88d7
JG
1768 Set the clock's precision (in clock ticks).
1769 """
be02a6e6
JG
1770 @precision.setter
1771 def precision(self, precision):
1772 ret = _bt_ctf_clock_set_precision(self._c, precision)
ec8c88d7 1773
be02a6e6 1774 """
14001277
JG
1775 Get the clock's offset in seconds from POSIX.1 Epoch.
1776 """
be02a6e6
JG
1777 @property
1778 def offset_seconds(self):
1779 offset_s = _bt_ctf_clock_get_offset_s(self._c)
1780 if offset_s == CTFWriter._MAX_UINT64:
1781 raise ValueError("Invalid clock instance")
1782 return offset_s
14001277 1783
be02a6e6 1784 """
ec8c88d7
JG
1785 Set the clock's offset in seconds from POSIX.1 Epoch.
1786 """
be02a6e6
JG
1787 @offset_seconds.setter
1788 def offset_seconds(self, offset_s):
1789 ret = _bt_ctf_clock_set_offset_s(self._c, offset_s)
1790 if ret < 0:
1791 raise ValueError("Invalid offset value.")
ec8c88d7 1792
be02a6e6 1793 """
14001277
JG
1794 Get the clock's offset in ticks from POSIX.1 Epoch + offset in seconds.
1795 """
be02a6e6
JG
1796 @property
1797 def offset(self):
1798 offset = _bt_ctf_clock_get_offset(self._c)
1799 if offset == CTFWriter._MAX_UINT64:
1800 raise ValueError("Invalid clock instance")
1801 return offset
14001277 1802
be02a6e6 1803 """
ec8c88d7
JG
1804 Set the clock's offset in ticks from POSIX.1 Epoch + offset in seconds.
1805 """
be02a6e6
JG
1806 @offset.setter
1807 def offset(self, offset):
1808 ret = _bt_ctf_clock_set_offset(self._c, offset)
1809 if ret < 0:
1810 raise ValueError("Invalid offset value.")
ec8c88d7 1811
be02a6e6 1812 """
14001277
JG
1813 Get a clock's absolute attribute. A clock is absolute if the clock
1814 is a global reference across the trace's other clocks.
1815 """
be02a6e6
JG
1816 @property
1817 def absolute(self):
1818 is_absolute = _bt_ctf_clock_get_is_absolute(self._c)
1819 if is_absolute == -1:
1820 raise ValueError("Invalid clock instance")
1821 return False if is_absolute == 0 else True
14001277 1822
be02a6e6 1823 """
ec8c88d7
JG
1824 Set a clock's absolute attribute. A clock is absolute if the clock
1825 is a global reference across the trace's other clocks.
1826 """
be02a6e6
JG
1827 @absolute.setter
1828 def absolute(self, is_absolute):
1829 ret = _bt_ctf_clock_set_is_absolute(self._c, int(is_absolute))
1830 if ret < 0:
1831 raise ValueError(
1832 "Could not set the clock's absolute attribute.")
ec8c88d7 1833
be02a6e6 1834 """
da64442f
JG
1835 Get a clock's UUID (an object of type UUID).
1836 """
be02a6e6
JG
1837 @property
1838 def uuid(self):
1839 uuid_list = []
1840 for i in range(16):
1841 ret, value = _bt_python_ctf_clock_get_uuid_index(self._c, i)
1842 if ret < 0:
1843 raise ValueError("Invalid clock instance")
1844 uuid_list.append(value)
1845 return UUID(bytes=bytes(uuid_list))
1846
1847 """
da64442f
JG
1848 Set a clock's UUID (an object of type UUID).
1849 """
be02a6e6
JG
1850 @uuid.setter
1851 def uuid(self, uuid):
1852 uuid_bytes = uuid.bytes
1853 if len(uuid_bytes) != 16:
1854 raise ValueError(
1855 "Invalid UUID provided. UUID length must be 16 bytes")
1856 for i in range(len(uuid_bytes)):
1857 ret = _bt_python_ctf_clock_set_uuid_index(
1858 self._c,
1859 i,
1860 uuid_bytes[i])
1861 if ret < 0:
1862 raise ValueError("Invalid clock instance")
1863
1864 """
14001277
JG
1865 Get the current time in nanoseconds since the clock's origin (offset and
1866 offset_s attributes).
1867 """
be02a6e6
JG
1868 @property
1869 def time(self):
1870 time = _bt_ctf_clock_get_time(self._c)
1871 if time == CTFWriter._MAX_UINT64:
1872 raise ValueError("Invalid clock instance")
1873 return time
14001277 1874
be02a6e6 1875 """
ec8c88d7
JG
1876 Set the current time in nanoseconds since the clock's origin (offset and
1877 offset_s attributes). The clock's value will be sampled as events are
1878 appended to a stream.
1879 """
be02a6e6
JG
1880 @time.setter
1881 def time(self, time):
1882 ret = _bt_ctf_clock_set_time(self._c, time)
1883 if ret < 0:
1884 raise ValueError("Invalid time value.")
1885
1886 class FieldDeclaration:
1887
1888 """
1889 FieldDeclaration should not be instantiated directly. Instantiate
1890 one of the concrete FieldDeclaration classes.
1891 """
1892 class IntegerBase:
1893 # These values are based on the bt_ctf_integer_base enum
1894 # declared in event-types.h.
1895 INTEGER_BASE_UNKNOWN = -1
1896 INTEGER_BASE_BINARY = 2
1897 INTEGER_BASE_OCTAL = 8
1898 INTEGER_BASE_DECIMAL = 10
1899 INTEGER_BASE_HEXADECIMAL = 16
1900
1901 def __init__(self):
1902 if self._ft is None:
1903 raise ValueError("FieldDeclaration creation failed.")
1904
1905 def __del__(self):
1906 _bt_ctf_field_type_put(self._ft)
1907
1908 @staticmethod
1909 def _create_field_declaration_from_native_instance(
1910 native_field_declaration):
1911 type_dict = {
1912 CTFTypeId.INTEGER: CTFWriter.IntegerFieldDeclaration,
1913 CTFTypeId.FLOAT: CTFWriter.FloatFieldDeclaration,
1914 CTFTypeId.ENUM: CTFWriter.EnumerationFieldDeclaration,
1915 CTFTypeId.STRING: CTFWriter.StringFieldDeclaration,
1916 CTFTypeId.STRUCT: CTFWriter.StructureFieldDeclaration,
1917 CTFTypeId.VARIANT: CTFWriter.VariantFieldDeclaration,
1918 CTFTypeId.ARRAY: CTFWriter.ArrayFieldDeclaration,
1919 CTFTypeId.SEQUENCE: CTFWriter.SequenceFieldDeclaration
1920 }
1921
1922 field_type_id = _bt_ctf_field_type_get_type_id(
1923 native_field_declaration)
1924 if field_type_id == CTFTypeId.UNKNOWN:
1925 raise TypeError("Invalid field instance")
1926
1927 declaration = CTFWriter.Field.__new__(CTFWriter.Field)
1928 declaration._ft = native_field_declaration
1929 declaration.__class__ = type_dict[field_type_id]
1930 return declaration
1931
1932 """
b4b5e4b5 1933 Get the field declaration's alignment. Returns -1 on error.
14001277 1934 """
be02a6e6
JG
1935 @property
1936 def alignment(self):
1937 return _bt_ctf_field_type_get_alignment(self._ft)
14001277 1938
be02a6e6 1939 """
b4b5e4b5 1940 Set the field declaration's alignment. Defaults to 1 (bit-aligned). However,
ec8c88d7
JG
1941 some types, such as structures and string, may impose other alignment
1942 constraints.
1943 """
be02a6e6
JG
1944 @alignment.setter
1945 def alignment(self, alignment):
1946 ret = _bt_ctf_field_type_set_alignment(self._ft, alignment)
1947 if ret < 0:
1948 raise ValueError("Invalid alignment value.")
ec8c88d7 1949
be02a6e6 1950 """
b4b5e4b5 1951 Get the field declaration's byte order. One of the ByteOrder's constant.
14001277 1952 """
be02a6e6
JG
1953 @property
1954 def byte_order(self):
1955 return _bt_ctf_field_type_get_byte_order(self._ft)
14001277 1956
be02a6e6 1957 """
b4b5e4b5 1958 Set the field declaration's byte order. Use constants defined in the ByteOrder
ec8c88d7
JG
1959 class.
1960 """
be02a6e6
JG
1961 @byte_order.setter
1962 def byte_order(self, byte_order):
1963 ret = _bt_ctf_field_type_set_byte_order(self._ft, byte_order)
1964 if ret < 0:
1965 raise ValueError("Could not set byte order value.")
ec8c88d7 1966
be02a6e6 1967 class IntegerFieldDeclaration(FieldDeclaration):
ec8c88d7 1968
be02a6e6
JG
1969 """
1970 Create a new integer field declaration of the given size.
1971 """
1972
1973 def __init__(self, size):
1974 self._ft = _bt_ctf_field_type_integer_create(size)
1975 super().__init__()
1976
1977 """
b4b5e4b5
JG
1978 Get an integer's size.
1979 """
be02a6e6
JG
1980 @property
1981 def size(self):
1982 ret = _bt_ctf_field_type_integer_get_size(self._ft)
1983 if ret < 0:
1984 raise ValueError("Could not get Integer's size attribute.")
1985 else:
1986 return ret
b4b5e4b5 1987
be02a6e6 1988 """
14001277
JG
1989 Get an integer's signedness attribute.
1990 """
be02a6e6
JG
1991 @property
1992 def signed(self):
1993 ret = _bt_ctf_field_type_integer_get_signed(self._ft)
1994 if ret < 0:
1995 raise ValueError("Could not get Integer's signed attribute.")
1996 elif ret > 0:
1997 return True
1998 else:
1999 return False
2000
2001 """
14001277 2002 Set an integer's signedness attribute.
ec8c88d7 2003 """
be02a6e6
JG
2004 @signed.setter
2005 def signed(self, signed):
2006 ret = _bt_ctf_field_type_integer_set_signed(self._ft, signed)
2007 if ret < 0:
2008 raise ValueError("Could not set Integer's signed attribute.")
ec8c88d7 2009
be02a6e6 2010 """
14001277 2011 Get the integer's base used to pretty-print the resulting trace.
b4b5e4b5 2012 Returns a constant from the FieldDeclaration.IntegerBase class.
14001277 2013 """
be02a6e6
JG
2014 @property
2015 def base(self):
2016 return _bt_ctf_field_type_integer_get_base(self._ft)
14001277 2017
be02a6e6 2018 """
14001277 2019 Set the integer's base used to pretty-print the resulting trace.
b4b5e4b5 2020 The base must be a constant of the FieldDeclarationIntegerBase class.
ec8c88d7 2021 """
be02a6e6
JG
2022 @base.setter
2023 def base(self, base):
2024 ret = _bt_ctf_field_type_integer_set_base(self._ft, base)
2025 if ret < 0:
2026 raise ValueError("Could not set Integer's base.")
ec8c88d7 2027
be02a6e6 2028 """
14001277
JG
2029 Get the integer's encoding (one of the constants of the
2030 CTFStringEncoding class).
b4b5e4b5 2031 Returns a constant from the CTFStringEncoding class.
14001277 2032 """
be02a6e6
JG
2033 @property
2034 def encoding(self):
2035 return _bt_ctf_field_type_integer_get_encoding(self._ft)
14001277 2036
be02a6e6 2037 """
ec8c88d7
JG
2038 An integer encoding may be set to signal that the integer must be printed
2039 as a text character. Must be a constant from the CTFStringEncoding class.
2040 """
be02a6e6
JG
2041 @encoding.setter
2042 def encoding(self, encoding):
2043 ret = _bt_ctf_field_type_integer_set_encoding(self._ft, encoding)
2044 if ret < 0:
2045 raise ValueError("Could not set Integer's encoding.")
ec8c88d7 2046
be02a6e6 2047 class EnumerationFieldDeclaration(FieldDeclaration):
ec8c88d7 2048
be02a6e6
JG
2049 """
2050 Create a new enumeration field declaration with the given underlying container type.
2051 """
ec8c88d7 2052
be02a6e6
JG
2053 def __init__(self, integer_type):
2054 if integer_type is None or not isinstance(
2055 integer_type, CTFWriter.IntegerFieldDeclaration):
2056 raise TypeError("Invalid integer container.")
2057
2058 self._ft = _bt_ctf_field_type_enumeration_create(integer_type._ft)
2059 super().__init__()
2060
2061 """
b4b5e4b5
JG
2062 Get the enumeration's underlying container type.
2063 """
be02a6e6
JG
2064 @property
2065 def container(self):
2066 ret = _bt_ctf_field_type_enumeration_get_container_type(self._ft)
2067 if ret is None:
2068 raise TypeError("Invalid enumeration declaration")
2069 return CTFWriter.FieldDeclaration._create_field_declaration_from_native_instance(
2070 ret)
b4b5e4b5 2071
be02a6e6 2072 """
ec8c88d7
JG
2073 Add a mapping to the enumeration. The range's values are inclusive.
2074 """
b4b5e4b5 2075
be02a6e6
JG
2076 def add_mapping(self, name, range_start, range_end):
2077 if range_start < 0 or range_end < 0:
2078 ret = _bt_ctf_field_type_enumeration_add_mapping(
2079 self._ft,
2080 str(name),
2081 range_start,
2082 range_end)
2083 else:
2084 ret = _bt_ctf_field_type_enumeration_add_mapping_unsigned(
2085 self._ft,
2086 str(name),
2087 range_start,
2088 range_end)
2089
2090 if ret < 0:
2091 raise ValueError(
2092 "Could not add mapping to enumeration declaration.")
2093
2094 """
b4b5e4b5
JG
2095 Generator returning instances of EnumerationMapping.
2096 """
be02a6e6
JG
2097 @property
2098 def mappings(self):
2099 signed = self.container.signed
2100
2101 count = _bt_ctf_field_type_enumeration_get_mapping_count(self._ft)
2102 for i in range(count):
2103 if signed:
2104 ret = _bt_python_ctf_field_type_enumeration_get_mapping(
2105 self._ft,
2106 i)
2107 else:
2108 ret = _bt_python_ctf_field_type_enumeration_get_mapping_unsigned(
2109 self._ft,
2110 i)
2111
2112 if len(ret) != 3:
2113 raise TypeError(
2114 "Could not get Enumeration mapping at index {}".format(i))
2115 name, range_start, range_end = ret
2116 yield CTFWriter.EnumerationMapping(name, range_start, range_end)
2117
2118 """
b4b5e4b5
JG
2119 Get a mapping by name (EnumerationMapping).
2120 """
b4b5e4b5 2121
be02a6e6
JG
2122 def get_mapping_by_name(self, name):
2123 ret, index = _bt_ctf_field_type_enumeration_get_mapping_index_by_name(
2124 self._ft, name)
2125 if ret < 0:
2126 return None
2127
2128 if self.container.signed:
2129 ret = _bt_python_ctf_field_type_enumeration_get_mapping(
2130 self._ft,
2131 index)
2132 else:
2133 ret = _bt_python_ctf_field_type_enumeration_get_mapping_unsigned(
2134 self._ft,
2135 index)
2136
2137 if len(ret) != 3:
2138 raise TypeError(
2139 "Could not get Enumeration mapping at index {}".format(i))
2140 name, range_start, range_end = ret
2141 return CTFWriter.EnumerationMapping(name, range_start, range_end)
2142
2143 """
b4b5e4b5
JG
2144 Get a mapping by value (EnumerationMapping).
2145 """
b4b5e4b5 2146
be02a6e6
JG
2147 def get_mapping_by_value(self, value):
2148 if value < 0:
2149 ret, index = _bt_ctf_field_type_enumeration_get_mapping_index_by_value(
2150 self._ft, value)
2151 else:
2152 ret, index = _bt_ctf_field_type_enumeration_get_mapping_index_by_unsigned_value(
2153 self._ft, value)
2154
2155 if ret < 0:
2156 return None
2157
2158 if self.container.signed:
2159 ret = _bt_python_ctf_field_type_enumeration_get_mapping(
2160 self._ft,
2161 index)
2162 else:
2163 ret = _bt_python_ctf_field_type_enumeration_get_mapping_unsigned(
2164 self._ft,
2165 index)
2166
2167 if len(ret) != 3:
2168 raise TypeError(
2169 "Could not get Enumeration mapping at index {}".format(i))
2170 name, range_start, range_end = ret
2171 return CTFWriter.EnumerationMapping(name, range_start, range_end)
2172
2173 class FloatFieldDeclaration(FieldDeclaration):
2174 FLT_EXP_DIG = 8
2175 DBL_EXP_DIG = 11
2176 FLT_MANT_DIG = 24
2177 DBL_MANT_DIG = 53
2178
2179 """
b4b5e4b5 2180 Create a new floating point field declaration.
ec8c88d7 2181 """
ec8c88d7 2182
be02a6e6
JG
2183 def __init__(self):
2184 self._ft = _bt_ctf_field_type_floating_point_create()
2185 super().__init__()
2186
2187 """
b4b5e4b5 2188 Get the number of exponent digits used to store the floating point field.
14001277 2189 """
be02a6e6
JG
2190 @property
2191 def exponent_digits(self):
2192 ret = _bt_ctf_field_type_floating_point_get_exponent_digits(
2193 self._ft)
2194 if ret < 0:
2195 raise TypeError(
2196 "Could not get Floating point exponent digit count")
2197 return ret
14001277 2198
be02a6e6 2199 """
14001277 2200 Set the number of exponent digits to use to store the floating point field.
ec8c88d7
JG
2201 The only values currently supported are FLT_EXP_DIG and DBL_EXP_DIG which
2202 are defined as constants of this class.
2203 """
be02a6e6
JG
2204 @exponent_digits.setter
2205 def exponent_digits(self, exponent_digits):
2206 ret = _bt_ctf_field_type_floating_point_set_exponent_digits(
2207 self._ft,
2208 exponent_digits)
2209 if ret < 0:
2210 raise ValueError("Could not set exponent digit count.")
ec8c88d7 2211
be02a6e6 2212 """
b4b5e4b5 2213 Get the number of mantissa digits used to store the floating point field.
14001277 2214 """
be02a6e6
JG
2215 @property
2216 def mantissa_digits(self):
2217 ret = _bt_ctf_field_type_floating_point_get_mantissa_digits(
2218 self._ft)
2219 if ret < 0:
2220 raise TypeError(
2221 "Could not get Floating point mantissa digit count")
2222 return ret
14001277 2223
be02a6e6 2224 """
14001277 2225 Set the number of mantissa digits to use to store the floating point field.
ec8c88d7
JG
2226 The only values currently supported are FLT_MANT_DIG and DBL_MANT_DIG which
2227 are defined as constants of this class.
2228 """
be02a6e6
JG
2229 @mantissa_digits.setter
2230 def mantissa_digits(self, mantissa_digits):
2231 ret = _bt_ctf_field_type_floating_point_set_mantissa_digits(
2232 self._ft,
2233 mantissa_digits)
2234 if ret < 0:
2235 raise ValueError("Could not set mantissa digit count.")
ec8c88d7 2236
be02a6e6 2237 class StructureFieldDeclaration(FieldDeclaration):
ec8c88d7 2238
be02a6e6
JG
2239 """
2240 Create a new structure field declaration.
2241 """
2242
2243 def __init__(self):
2244 self._ft = _bt_ctf_field_type_structure_create()
2245 super().__init__()
2246
2247 """
ec8c88d7
JG
2248 Add a field of type "field_type" to the structure.
2249 """
ec8c88d7 2250
be02a6e6
JG
2251 def add_field(self, field_type, field_name):
2252 ret = _bt_ctf_field_type_structure_add_field(
2253 self._ft,
2254 field_type._ft,
2255 str(field_name))
2256 if ret < 0:
2257 raise ValueError("Could not add field to structure.")
2258
2259 """
b4b5e4b5
JG
2260 Generator returning the structure's field as tuples of (field name, field declaration).
2261 """
be02a6e6
JG
2262 @property
2263 def fields(self):
2264 count = _bt_ctf_field_type_structure_get_field_count(self._ft)
2265 if count < 0:
2266 raise TypeError("Could not get Structure field count")
2267
2268 for i in range(count):
2269 field_name = _bt_python_ctf_field_type_structure_get_field_name(
2270 self._ft,
2271 i)
2272 if field_name is None:
2273 raise TypeError(
2274 "Could not get Structure field name at index {}".format(i))
2275
2276 field_type_native = _bt_python_ctf_field_type_structure_get_field_type(
2277 self._ft,
2278 i)
2279 if field_type_native is None:
2280 raise TypeError(
2281 "Could not get Structure field type at index {}".format(i))
2282
2283 field_type = CTFWriter.FieldDeclaration._create_field_declaration_from_native_instance(
2284 field_type_native)
2285 yield (field_name, field_type)
2286
2287 """
2288 Get a field declaration by name (FieldDeclaration).
2289 """
b4b5e4b5 2290
be02a6e6
JG
2291 def get_field_by_name(self, name):
2292 field_type_native = _bt_ctf_field_type_structure_get_field_type_by_name(
2293 self._ft,
2294 name)
2295 if field_type_native is None:
2296 raise TypeError(
2297 "Could not find Structure field with name {}".format(name))
b4b5e4b5 2298
be02a6e6
JG
2299 return CTFWriter.FieldDeclaration._create_field_declaration_from_native_instance(
2300 field_type_native)
b4b5e4b5 2301
be02a6e6 2302 class VariantFieldDeclaration(FieldDeclaration):
b4b5e4b5 2303
be02a6e6
JG
2304 """
2305 Create a new variant field declaration.
2306 """
b4b5e4b5 2307
be02a6e6
JG
2308 def __init__(self, enum_tag, tag_name):
2309 if enum_tag is None or not isinstance(
2310 enum_tag, CTFWriter.EnumerationFieldDeclaration):
2311 raise TypeError(
2312 "Invalid tag type; must be of type EnumerationFieldDeclaration.")
ec8c88d7 2313
be02a6e6
JG
2314 self._ft = _bt_ctf_field_type_variant_create(
2315 enum_tag._ft,
2316 str(tag_name))
2317 super().__init__()
ec8c88d7 2318
be02a6e6 2319 """
b4b5e4b5
JG
2320 Get the variant's tag name.
2321 """
be02a6e6
JG
2322 @property
2323 def tag_name(self):
2324 ret = _bt_ctf_field_type_variant_get_tag_name(self._ft)
2325 if ret is None:
2326 raise TypeError("Could not get Variant tag name")
2327 return ret
b4b5e4b5 2328
be02a6e6 2329 """
b4b5e4b5
JG
2330 Get the variant's tag type.
2331 """
be02a6e6
JG
2332 @property
2333 def tag_type(self):
2334 ret = _bt_ctf_field_type_variant_get_tag_type(self._ft)
2335 if ret is None:
2336 raise TypeError("Could not get Variant tag type")
2337 return CTFWriter.FieldDeclaration._create_field_declaration_from_native_instance(
2338 ret)
b4b5e4b5 2339
be02a6e6 2340 """
ec8c88d7
JG
2341 Add a field of type "field_type" to the variant.
2342 """
b4b5e4b5 2343
be02a6e6
JG
2344 def add_field(self, field_type, field_name):
2345 ret = _bt_ctf_field_type_variant_add_field(
2346 self._ft,
2347 field_type._ft,
2348 str(field_name))
2349 if ret < 0:
2350 raise ValueError("Could not add field to variant.")
b4b5e4b5 2351
be02a6e6
JG
2352 """
2353 Generator returning the variant's field as tuples of (field name, field declaration).
b4b5e4b5 2354 """
be02a6e6
JG
2355 @property
2356 def fields(self):
2357 count = _bt_ctf_field_type_variant_get_field_count(self._ft)
2358 if count < 0:
2359 raise TypeError("Could not get Variant field count")
2360
2361 for i in range(count):
2362 field_name = _bt_python_ctf_field_type_variant_get_field_name(
2363 self._ft,
2364 i)
2365 if field_name is None:
2366 raise TypeError(
2367 "Could not get Variant field name at index {}".format(i))
2368
2369 field_type_native = _bt_python_ctf_field_type_variant_get_field_type(
2370 self._ft,
2371 i)
2372 if field_type_native is None:
2373 raise TypeError(
2374 "Could not get Variant field type at index {}".format(i))
2375
2376 field_type = CTFWriter.FieldDeclaration._create_field_declaration_from_native_instance(
2377 field_type_native)
2378 yield (field_name, field_type)
2379
2380 """
b4b5e4b5
JG
2381 Get a field declaration by name (FieldDeclaration).
2382 """
b4b5e4b5 2383
be02a6e6
JG
2384 def get_field_by_name(self, name):
2385 field_type_native = _bt_ctf_field_type_variant_get_field_type_by_name(
2386 self._ft,
2387 name)
2388 if field_type_native is None:
2389 raise TypeError(
2390 "Could not find Variant field with name {}".format(name))
b4b5e4b5 2391
be02a6e6
JG
2392 return CTFWriter.FieldDeclaration._create_field_declaration_from_native_instance(
2393 field_type_native)
2394
2395 """
b4b5e4b5
JG
2396 Get a field declaration from tag (EnumerationField).
2397 """
b4b5e4b5 2398
be02a6e6
JG
2399 def get_field_from_tag(self, tag):
2400 field_type_native = _bt_ctf_field_type_variant_get_field_type_from_tag(
2401 self._ft,
2402 tag._f)
2403 if field_type_native is None:
2404 raise TypeError(
2405 "Could not find Variant field with tag value {}".format(
2406 tag.value))
b4b5e4b5 2407
be02a6e6
JG
2408 return CTFWriter.FieldDeclaration._create_field_declaration_from_native_instance(
2409 field_type_native)
ec8c88d7 2410
be02a6e6
JG
2411 class ArrayFieldDeclaration(FieldDeclaration):
2412
2413 """
2414 Create a new array field declaration.
2415 """
2416
2417 def __init__(self, element_type, length):
2418 self._ft = _bt_ctf_field_type_array_create(
2419 element_type._ft,
2420 length)
2421 super().__init__()
2422
2423 """
b4b5e4b5
JG
2424 Get the array's element type.
2425 """
be02a6e6
JG
2426 @property
2427 def element_type(self):
2428 ret = _bt_ctf_field_type_array_get_element_type(self._ft)
2429 if ret is None:
2430 raise TypeError("Could not get Array element type")
2431 return CTFWriter.FieldDeclaration._create_field_declaration_from_native_instance(
2432 ret)
b4b5e4b5 2433
be02a6e6 2434 """
b4b5e4b5
JG
2435 Get the array's length.
2436 """
be02a6e6
JG
2437 @property
2438 def length(self):
2439 ret = _bt_ctf_field_type_array_get_length(self._ft)
2440 if ret < 0:
2441 raise TypeError("Could not get Array length")
2442 return ret
b4b5e4b5 2443
be02a6e6 2444 class SequenceFieldDeclaration(FieldDeclaration):
ec8c88d7 2445
be02a6e6
JG
2446 """
2447 Create a new sequence field declaration.
2448 """
2449
2450 def __init__(self, element_type, length_field_name):
2451 self._ft = _bt_ctf_field_type_sequence_create(
2452 element_type._ft,
2453 str(length_field_name))
2454 super().__init__()
2455
2456 """
b4b5e4b5
JG
2457 Get the sequence's element type.
2458 """
be02a6e6
JG
2459 @property
2460 def element_type(self):
2461 ret = _bt_ctf_field_type_sequence_get_element_type(self._ft)
2462 if ret is None:
2463 raise TypeError("Could not get Sequence element type")
2464 return CTFWriter.FieldDeclaration._create_field_declaration_from_native_instance(
2465 ret)
b4b5e4b5 2466
be02a6e6 2467 """
b4b5e4b5
JG
2468 Get the sequence's length field name.
2469 """
be02a6e6
JG
2470 @property
2471 def length_field_name(self):
2472 ret = _bt_ctf_field_type_sequence_get_length_field_name(self._ft)
2473 if ret is None:
2474 raise TypeError("Could not get Sequence length field name")
2475 return ret
b4b5e4b5 2476
be02a6e6 2477 class StringFieldDeclaration(FieldDeclaration):
ec8c88d7 2478
be02a6e6
JG
2479 """
2480 Create a new string field declaration.
2481 """
2482
2483 def __init__(self):
2484 self._ft = _bt_ctf_field_type_string_create()
2485 super().__init__()
2486
2487 """
b4b5e4b5 2488 Get a string declaration's encoding (a constant from the CTFStringEncoding class).
14001277 2489 """
be02a6e6
JG
2490 @property
2491 def encoding(self):
2492 return _bt_ctf_field_type_string_get_encoding(self._ft)
14001277 2493
be02a6e6 2494 """
b4b5e4b5 2495 Set a string declaration's encoding. Must be a constant from the CTFStringEncoding class.
ec8c88d7 2496 """
be02a6e6
JG
2497 @encoding.setter
2498 def encoding(self, encoding):
2499 ret = _bt_ctf_field_type_string_set_encoding(self._ft, encoding)
2500 if ret < 0:
2501 raise ValueError("Could not set string encoding.")
ec8c88d7 2502
be02a6e6 2503 """
ec8c88d7
JG
2504 Create an instance of a field.
2505 """
be02a6e6
JG
2506 @staticmethod
2507 def create_field(field_type):
2508 if field_type is None or not isinstance(
2509 field_type, CTFWriter.FieldDeclaration):
2510 raise TypeError(
2511 "Invalid field_type. Type must be a FieldDeclaration-derived class.")
2512
2513 if isinstance(field_type, CTFWriter.IntegerFieldDeclaration):
2514 return CTFWriter.IntegerField(field_type)
2515 elif isinstance(field_type, CTFWriter.EnumerationFieldDeclaration):
2516 return CTFWriter.EnumerationField(field_type)
2517 elif isinstance(field_type, CTFWriter.FloatFieldDeclaration):
2518 return CTFWriter.FloatFieldingPoint(field_type)
2519 elif isinstance(field_type, CTFWriter.StructureFieldDeclaration):
2520 return CTFWriter.StructureField(field_type)
2521 elif isinstance(field_type, CTFWriter.VariantFieldDeclaration):
2522 return CTFWriter.VariantField(field_type)
2523 elif isinstance(field_type, CTFWriter.ArrayFieldDeclaration):
2524 return CTFWriter.ArrayField(field_type)
2525 elif isinstance(field_type, CTFWriter.SequenceFieldDeclaration):
2526 return CTFWriter.SequenceField(field_type)
2527 elif isinstance(field_type, CTFWriter.StringFieldDeclaration):
2528 return CTFWriter.StringField(field_type)
2529
2530 class Field:
2531
2532 """
2533 Base class, do not instantiate.
2534 """
2535
2536 def __init__(self, field_type):
2537 if not isinstance(field_type, CTFWriter.FieldDeclaration):
2538 raise TypeError("Invalid field_type argument.")
2539
2540 self._f = _bt_ctf_field_create(field_type._ft)
2541 if self._f is None:
2542 raise ValueError("Field creation failed.")
2543
2544 def __del__(self):
2545 _bt_ctf_field_put(self._f)
2546
2547 @staticmethod
2548 def _create_field_from_native_instance(native_field_instance):
2549 type_dict = {
2550 CTFTypeId.INTEGER: CTFWriter.IntegerField,
2551 CTFTypeId.FLOAT: CTFWriter.FloatFieldingPoint,
2552 CTFTypeId.ENUM: CTFWriter.EnumerationField,
2553 CTFTypeId.STRING: CTFWriter.StringField,
2554 CTFTypeId.STRUCT: CTFWriter.StructureField,
2555 CTFTypeId.VARIANT: CTFWriter.VariantField,
2556 CTFTypeId.ARRAY: CTFWriter.ArrayField,
2557 CTFTypeId.SEQUENCE: CTFWriter.SequenceField
2558 }
2559
2560 field_type = _bt_python_get_field_type(native_field_instance)
2561 if field_type == CTFTypeId.UNKNOWN:
2562 raise TypeError("Invalid field instance")
2563
2564 field = CTFWriter.Field.__new__(CTFWriter.Field)
2565 field._f = native_field_instance
2566 field.__class__ = type_dict[field_type]
2567 return field
2568
2569 @property
2570 def declaration(self):
2571 native_field_type = _bt_ctf_field_get_type(self._f)
2572 if native_field_type is None:
2573 raise TypeError("Invalid field instance")
2574 return CTFWriter.FieldDeclaration._create_field_declaration_from_native_instance(
2575 native_field_type)
2576
2577 class IntegerField(Field):
2578
2579 """
2580 Get an integer field's value.
2581 """
2582 @property
2583 def value(self):
2584 signedness = _bt_python_field_integer_get_signedness(self._f)
2585 if signedness < 0:
2586 raise TypeError("Invalid integer instance.")
2587
2588 if signedness == 0:
2589 ret, value = _bt_ctf_field_unsigned_integer_get_value(self._f)
2590 else:
2591 ret, value = _bt_ctf_field_signed_integer_get_value(self._f)
2592
2593 if ret < 0:
2594 raise ValueError("Could not get integer field value.")
2595 return value
2596
2597 """
ec8c88d7
JG
2598 Set an integer field's value.
2599 """
be02a6e6
JG
2600 @value.setter
2601 def value(self, value):
2602 if not isinstance(value, int):
2603 raise TypeError("IntegerField's value must be an int")
2604
2605 signedness = _bt_python_field_integer_get_signedness(self._f)
2606 if signedness < 0:
2607 raise TypeError("Invalid integer instance.")
2608
2609 if signedness == 0:
2610 ret = _bt_ctf_field_unsigned_integer_set_value(self._f, value)
2611 else:
2612 ret = _bt_ctf_field_signed_integer_set_value(self._f, value)
2613
2614 if ret < 0:
2615 raise ValueError("Could not set integer field value.")
2616
2617 class EnumerationField(Field):
2618
2619 """
2620 Return the enumeration's underlying container field (an integer field).
2621 """
2622 @property
2623 def container(self):
2624 container = CTFWriter.IntegerField.__new__(CTFWriter.IntegerField)
2625 container._f = _bt_ctf_field_enumeration_get_container(self._f)
2626 if container._f is None:
2627 raise TypeError("Invalid enumeration field type.")
2628 return container
2629
2630 """
821ca76c
JG
2631 Get the enumeration field's mapping name.
2632 """
be02a6e6
JG
2633 @property
2634 def value(self):
2635 value = _bt_ctf_field_enumeration_get_mapping_name(self._f)
2636 if value is None:
2637 raise ValueError("Could not get enumeration's mapping name.")
2638 return value
821ca76c 2639
be02a6e6 2640 """
821ca76c
JG
2641 Set the enumeration field's value. Must be an integer as mapping names
2642 may be ambiguous.
2643 """
be02a6e6
JG
2644 @value.setter
2645 def value(self, value):
2646 if not isinstance(value, int):
2647 raise TypeError("EnumerationField value must be an int")
2648 self.container.value = value
2649
2650 class FloatFieldingPoint(Field):
2651
2652 """
2653 Get a floating point field's value.
2654 """
2655 @property
2656 def value(self):
2657 ret, value = _bt_ctf_field_floating_point_get_value(self._f)
2658 if ret < 0:
2659 raise ValueError("Could not get floating point field value.")
2660 return value
2661
2662 """
ec8c88d7
JG
2663 Set a floating point field's value.
2664 """
be02a6e6
JG
2665 @value.setter
2666 def value(self, value):
2667 if not isinstance(value, int) and not isinstance(value, float):
2668 raise TypeError("Value must be either a float or an int")
2669
2670 ret = _bt_ctf_field_floating_point_set_value(self._f, float(value))
2671 if ret < 0:
2672 raise ValueError("Could not set floating point field value.")
2673
2674 class StructureField(Field):
2675
2676 """
2677 Get the structure's field corresponding to the provided field name.
2678 """
2679
2680 def field(self, field_name):
2681 native_instance = _bt_ctf_field_structure_get_field(
2682 self._f,
2683 str(field_name))
2684 if native_instance is None:
2685 raise ValueError("Invalid field_name provided.")
2686 return CTFWriter.Field._create_field_from_native_instance(
2687 native_instance)
2688
2689 class VariantField(Field):
2690
2691 """
2692 Return the variant's selected field. The "tag" field is the selector enum field.
2693 """
2694
2695 def field(self, tag):
2696 native_instance = _bt_ctf_field_variant_get_field(self._f, tag._f)
2697 if native_instance is None:
2698 raise ValueError("Invalid tag provided.")
2699 return CTFWriter.Field._create_field_from_native_instance(
2700 native_instance)
2701
2702 class ArrayField(Field):
2703
2704 """
2705 Return the array's field at position "index".
2706 """
2707
2708 def field(self, index):
2709 native_instance = _bt_ctf_field_array_get_field(self._f, index)
2710 if native_instance is None:
2711 raise IndexError("Invalid index provided.")
2712 return CTFWriter.Field._create_field_from_native_instance(
2713 native_instance)
2714
2715 class SequenceField(Field):
2716
2717 """
2718 Get the sequence's length field (IntegerField).
2719 """
2720 @property
2721 def length(self):
2722 native_instance = _bt_ctf_field_sequence_get_length(self._f)
2723 if native_instance is None:
2724 length = -1
2725 return CTFWriter.Field._create_field_from_native_instance(
2726 native_instance)
2727
2728 """
2729 Set the sequence's length field (IntegerField).
ec8c88d7 2730 """
be02a6e6
JG
2731 @length.setter
2732 def length(self, length_field):
2733 if not isinstance(length_field, CTFWriter.IntegerField):
2734 raise TypeError("Invalid length field.")
2735 if length_field.declaration.signed:
2736 raise TypeError("Sequence field length must be unsigned")
2737 ret = _bt_ctf_field_sequence_set_length(self._f, length_field._f)
2738 if ret < 0:
2739 raise ValueError("Could not set sequence length.")
2740
2741 """
2742 Return the sequence's field at position "index".
ec8c88d7 2743 """
ec8c88d7 2744
be02a6e6
JG
2745 def field(self, index):
2746 native_instance = _bt_ctf_field_sequence_get_field(self._f, index)
2747 if native_instance is None:
2748 raise ValueError("Could not get sequence element at index.")
2749 return CTFWriter.Field._create_field_from_native_instance(
2750 native_instance)
ec8c88d7 2751
be02a6e6 2752 class StringField(Field):
14001277 2753
be02a6e6
JG
2754 """
2755 Get a string field's value.
2756 """
2757 @property
2758 def value(self):
2759 return _bt_ctf_field_string_get_value(self._f)
ec8c88d7 2760
be02a6e6
JG
2761 """
2762 Set a string field's value.
ec8c88d7 2763 """
be02a6e6
JG
2764 @value.setter
2765 def value(self, value):
2766 ret = _bt_ctf_field_string_set_value(self._f, str(value))
2767 if ret < 0:
2768 raise ValueError("Could not set string field value.")
ec8c88d7 2769
be02a6e6 2770 class EventClass:
14001277 2771
be02a6e6
JG
2772 """
2773 Create a new event class of the given name.
2774 """
ec8c88d7 2775
be02a6e6
JG
2776 def __init__(self, name):
2777 self._ec = _bt_ctf_event_class_create(name)
2778 if self._ec is None:
2779 raise ValueError("Event class creation failed.")
ec8c88d7 2780
be02a6e6
JG
2781 def __del__(self):
2782 _bt_ctf_event_class_put(self._ec)
ec8c88d7 2783
be02a6e6 2784 """
ec8c88d7
JG
2785 Add a field of type "field_type" to the event class.
2786 """
ec8c88d7 2787
be02a6e6
JG
2788 def add_field(self, field_type, field_name):
2789 ret = _bt_ctf_event_class_add_field(
2790 self._ec,
2791 field_type._ft,
2792 str(field_name))
2793 if ret < 0:
2794 raise ValueError("Could not add field to event class.")
2795
2796 """
38f28df6
JG
2797 Get the event class' name.
2798 """
be02a6e6
JG
2799 @property
2800 def name(self):
2801 name = _bt_ctf_event_class_get_name(self._ec)
2802 if name is None:
2803 raise TypeError("Could not get EventClass name")
2804 return name
38f28df6 2805
be02a6e6 2806 """
38f28df6
JG
2807 Get the event class' id. Returns a negative value if unset.
2808 """
be02a6e6
JG
2809 @property
2810 def id(self):
2811 id = _bt_ctf_event_class_get_id(self._ec)
2812 if id < 0:
2813 raise TypeError("Could not get EventClass id")
2814 return id
38f28df6 2815
be02a6e6 2816 """
38f28df6
JG
2817 Set the event class' id. Throws a TypeError if the event class
2818 is already registered to a stream class.
2819 """
be02a6e6
JG
2820 @id.setter
2821 def id(self, id):
2822 ret = _bt_ctf_event_class_set_id(self._ec, id)
2823 if ret < 0:
2824 raise TypeError(
2825 "Can't change an Event Class's id after it has been assigned to a stream class")
38f28df6 2826
be02a6e6 2827 """
38f28df6
JG
2828 Get the event class' stream class. Returns None if unset.
2829 """
be02a6e6
JG
2830 @property
2831 def stream_class(self):
2832 stream_class_native = _bt_ctf_event_class_get_stream_class(
2833 self._ec)
2834 if stream_class_native is None:
2835 return None
2836 stream_class = CTFWriter.StreamClass.__new__(CTFWriter.StreamClass)
2837 stream_class._sc = stream_class_native
2838 return stream_class
2839
2840 """
38f28df6
JG
2841 Generator returning the event class' fields as tuples of (field name, field declaration).
2842 """
be02a6e6
JG
2843 @property
2844 def fields(self):
2845 count = _bt_ctf_event_class_get_field_count(self._ec)
2846 if count < 0:
2847 raise TypeError("Could not get EventClass' field count")
2848
2849 for i in range(count):
2850 field_name = _bt_python_ctf_event_class_get_field_name(
2851 self._ec,
2852 i)
2853 if field_name is None:
2854 raise TypeError(
2855 "Could not get EventClass' field name at index {}".format(i))
2856
2857 field_type_native = _bt_python_ctf_event_class_get_field_type(
2858 self._ec,
2859 i)
2860 if field_type_native is None:
2861 raise TypeError(
2862 "Could not get EventClass' field type at index {}".format(i))
2863
2864 field_type = CTFWriter.FieldDeclaration._create_field_declaration_from_native_instance(
2865 field_type_native)
2866 yield (field_name, field_type)
2867
2868 """
2869 Get a field declaration by name (FieldDeclaration).
2870 """
38f28df6 2871
be02a6e6
JG
2872 def get_field_by_name(self, name):
2873 field_type_native = _bt_ctf_event_class_get_field_by_name(
2874 self._ec,
2875 name)
2876 if field_type_native is None:
2877 raise TypeError(
2878 "Could not find EventClass field with name {}".format(name))
2879 return CTFWriter.FieldDeclaration._create_field_declaration_from_native_instance(
2880 field_type_native)
38f28df6 2881
be02a6e6 2882 class Event:
38f28df6 2883
be02a6e6
JG
2884 """
2885 Create a new event of the given event class.
2886 """
38f28df6 2887
be02a6e6
JG
2888 def __init__(self, event_class):
2889 if not isinstance(event_class, CTFWriter.EventClass):
2890 raise TypeError("Invalid event_class argument.")
ec8c88d7 2891
be02a6e6
JG
2892 self._e = _bt_ctf_event_create(event_class._ec)
2893 if self._e is None:
2894 raise ValueError("Event creation failed.")
ec8c88d7 2895
be02a6e6
JG
2896 def __del__(self):
2897 _bt_ctf_event_put(self._e)
ec8c88d7 2898
be02a6e6 2899 """
38f28df6 2900 Get the event's class.
ec8c88d7 2901 """
be02a6e6
JG
2902 @property
2903 def event_class(self):
2904 event_class_native = _bt_ctf_event_get_class(self._e)
2905 if event_class_native is None:
2906 return None
2907 event_class = CTFWriter.EventClass.__new__(CTFWriter.EventClass)
2908 event_class._ec = event_class_native
2909 return event_class
38f28df6 2910
be02a6e6 2911 """
38f28df6
JG
2912 Get a clock from event. Returns None if the event's class
2913 is not registered to a stream class.
2914 """
ec8c88d7 2915
be02a6e6
JG
2916 def clock(self):
2917 clock_instance = _bt_ctf_event_get_clock(self._e)
2918 if clock_instance is None:
2919 return None
2920 clock = CTFWriter.Clock.__new__(CTFWriter.Clock)
2921 clock._c = clock_instance
2922 return clock
2923
2924 """
14001277 2925 Get a field from event.
ec8c88d7 2926 """
ec8c88d7 2927
be02a6e6
JG
2928 def payload(self, field_name):
2929 native_instance = _bt_ctf_event_get_payload(
2930 self._e,
2931 str(field_name))
2932 if native_instance is None:
2933 raise ValueError("Could not get event payload.")
2934 return CTFWriter.Field._create_field_from_native_instance(
2935 native_instance)
2936
2937 """
38f28df6
JG
2938 Set a manually created field as an event's payload.
2939 """
38f28df6 2940
be02a6e6
JG
2941 def set_payload(self, field_name, value_field):
2942 if not isinstance(value, CTFWriter.Field):
2943 raise TypeError("Invalid value type.")
2944 ret = _bt_ctf_event_set_payload(
2945 self._e,
2946 str(field_name),
2947 value_field._f)
2948 if ret < 0:
2949 raise ValueError("Could not set event field payload.")
ec8c88d7 2950
be02a6e6 2951 class StreamClass:
ec8c88d7 2952
be02a6e6
JG
2953 """
2954 Create a new stream class of the given name.
2955 """
2956
2957 def __init__(self, name):
2958 self._sc = _bt_ctf_stream_class_create(name)
2959 if self._sc is None:
2960 raise ValueError("Stream class creation failed.")
2961
2962 def __del__(self):
2963 _bt_ctf_stream_class_put(self._sc)
2964
2965 """
f6c2aa83
JG
2966 Get a stream class' name.
2967 """
be02a6e6
JG
2968 @property
2969 def name(self):
2970 name = _bt_ctf_stream_class_get_name(self._sc)
2971 if name is None:
2972 raise TypeError("Could not get StreamClass name")
2973 return name
f6c2aa83 2974
be02a6e6 2975 """
14001277
JG
2976 Get a stream class' clock.
2977 """
be02a6e6
JG
2978 @property
2979 def clock(self):
2980 clock_instance = _bt_ctf_stream_class_get_clock(self._sc)
2981 if clock_instance is None:
2982 return None
2983 clock = CTFWriter.Clock.__new__(CTFWriter.Clock)
2984 clock._c = clock_instance
2985 return clock
14001277 2986
be02a6e6 2987 """
ec8c88d7
JG
2988 Assign a clock to a stream class.
2989 """
be02a6e6
JG
2990 @clock.setter
2991 def clock(self, clock):
2992 if not isinstance(clock, CTFWriter.Clock):
2993 raise TypeError("Invalid clock type.")
ec8c88d7 2994
be02a6e6
JG
2995 ret = _bt_ctf_stream_class_set_clock(self._sc, clock._c)
2996 if ret < 0:
2997 raise ValueError("Could not set stream class clock.")
ec8c88d7 2998
be02a6e6 2999 """
f6c2aa83
JG
3000 Get a stream class' id.
3001 """
be02a6e6
JG
3002 @property
3003 def id(self):
3004 ret = _bt_ctf_stream_class_get_id(self._sc)
3005 if ret < 0:
3006 raise TypeError("Could not get StreamClass id")
3007 return ret
f6c2aa83 3008
be02a6e6 3009 """
f6c2aa83
JG
3010 Assign an id to a stream class.
3011 """
be02a6e6
JG
3012 @id.setter
3013 def id(self, id):
3014 ret = _bt_ctf_stream_class_set_id(self._sc, id)
3015 if ret < 0:
3016 raise TypeError("Could not set stream class id.")
f6c2aa83 3017
be02a6e6 3018 """
f6c2aa83
JG
3019 Generator returning the stream class' event classes.
3020 """
be02a6e6
JG
3021 @property
3022 def event_classes(self):
3023 count = _bt_ctf_stream_class_get_event_class_count(self._sc)
3024 if count < 0:
3025 raise TypeError("Could not get StreamClass' event class count")
3026
3027 for i in range(count):
3028 event_class_native = _bt_ctf_stream_class_get_event_class(
3029 self._sc,
3030 i)
3031 if event_class_native is None:
3032 raise TypeError(
3033 "Could not get StreamClass' event class at index {}".format(i))
3034
3035 event_class = CTFWriter.EventClass.__new__(
3036 CTFWriter.EventClass)
3037 event_class._ec = event_class_native
3038 yield event_class
3039
3040 """
ec8c88d7 3041 Add an event class to a stream class. New events can be added even after a
14001277 3042 stream has been instantiated and events have been appended. However, a stream
a5e4f94c
JG
3043 will not accept events of a class that has not been added to the stream
3044 class beforehand.
ec8c88d7 3045 """
ec8c88d7 3046
be02a6e6
JG
3047 def add_event_class(self, event_class):
3048 if not isinstance(event_class, CTFWriter.EventClass):
3049 raise TypeError("Invalid event_class type.")
ec8c88d7 3050
be02a6e6
JG
3051 ret = _bt_ctf_stream_class_add_event_class(
3052 self._sc,
3053 event_class._ec)
3054 if ret < 0:
3055 raise ValueError("Could not add event class.")
7df927c7 3056
be02a6e6
JG
3057 """
3058 Get the StreamClass' packet context type (StructureFieldDeclaration)
7df927c7 3059 """
be02a6e6
JG
3060 @property
3061 def packet_context_type(self):
3062 field_type_native = _bt_ctf_stream_class_get_packet_context_type(
3063 self._sc)
3064 if field_type_native is None:
3065 raise ValueError("Invalid StreamClass")
3066 field_type = CTFWriter.FieldDeclaration._create_field_declaration_from_native_instance(
3067 field_type_native)
3068 return field_type
3069
3070 """
7df927c7
JG
3071 Set a StreamClass' packet context type. Must be of type
3072 StructureFieldDeclaration.
3073 """
be02a6e6
JG
3074 @packet_context_type.setter
3075 def packet_context_type(self, field_type):
3076 if not isinstance(field_type, CTFWriter.StructureFieldDeclaration):
3077 raise TypeError(
3078 "field_type argument must be of type StructureFieldDeclaration.")
3079 ret = _bt_ctf_stream_class_set_packet_context_type(
3080 self._sc,
3081 field_type._ft)
3082 if ret < 0:
3083 raise ValueError("Failed to set packet context type.")
7df927c7 3084
be02a6e6 3085 class Stream:
ec8c88d7 3086
be02a6e6
JG
3087 """
3088 Create a stream of the given class.
3089 """
ec8c88d7 3090
be02a6e6
JG
3091 def __init__(self, stream_class):
3092 if not isinstance(stream_class, CTFWriter.StreamClass):
3093 raise TypeError(
3094 "Invalid stream_class argument must be of type StreamClass.")
ec8c88d7 3095
be02a6e6
JG
3096 self._s = _bt_ctf_stream_create(stream_class._sc)
3097 if self._s is None:
3098 raise ValueError("Stream creation failed.")
3099
3100 def __del__(self):
3101 _bt_ctf_stream_put(self._s)
3102
3103 """
708e628a
JG
3104 Get a stream's discarded event count.
3105 """
be02a6e6
JG
3106 @property
3107 def discarded_events(self):
3108 ret, count = _bt_ctf_stream_get_discarded_events_count(self._s)
3109 if ret < 0:
3110 raise ValueError(
3111 "Could not get the stream's discarded events count")
3112 return count
708e628a 3113
be02a6e6 3114 """
ec8c88d7
JG
3115 Increase the current packet's discarded event count.
3116 """
ec8c88d7 3117
be02a6e6
JG
3118 def append_discarded_events(self, event_count):
3119 _bt_ctf_stream_append_discarded_events(self._s, event_count)
3120
3121 """
ec8c88d7
JG
3122 Append "event" to the stream's current packet. The stream's associated clock
3123 will be sampled during this call. The event shall not be modified after
3124 being appended to a stream.
3125 """
ec8c88d7 3126
be02a6e6
JG
3127 def append_event(self, event):
3128 ret = _bt_ctf_stream_append_event(self._s, event._e)
3129 if ret < 0:
3130 raise ValueError("Could not append event to stream.")
3131
3132 """
7df927c7
JG
3133 Get a Stream's packet context field (a StructureField).
3134 """
be02a6e6
JG
3135 @property
3136 def packet_context(self):
3137 native_field = _bt_ctf_stream_get_packet_context(self._s)
3138 if native_field is None:
3139 raise ValueError("Invalid Stream.")
3140 return CTFWriter.Field._create_field_from_native_instance(
3141 native_field)
7df927c7 3142
be02a6e6 3143 """
7df927c7
JG
3144 Set a Stream's packet context field (must be a StructureField).
3145 """
be02a6e6
JG
3146 @packet_context.setter
3147 def packet_context(self, field):
3148 if not isinstance(field, CTFWriter.StructureField):
3149 raise TypeError(
3150 "Argument field must be of type StructureField")
3151 ret = _bt_ctf_stream_set_packet_context(self._s, field._f)
3152 if ret < 0:
3153 raise ValueError("Invalid packet context field.")
7df927c7 3154
be02a6e6 3155 """
ec8c88d7
JG
3156 The stream's current packet's events will be flushed to disk. Events
3157 subsequently appended to the stream will be added to a new packet.
3158 """
ec8c88d7 3159
be02a6e6
JG
3160 def flush(self):
3161 ret = _bt_ctf_stream_flush(self._s)
3162 if ret < 0:
3163 raise ValueError("Could not flush stream.")
ec8c88d7 3164
be02a6e6 3165 class Writer:
ec8c88d7 3166
be02a6e6
JG
3167 """
3168 Create a new writer that will produce a trace in the given path.
3169 """
3170
3171 def __init__(self, path):
3172 self._w = _bt_ctf_writer_create(path)
3173 if self._w is None:
3174 raise ValueError("Writer creation failed.")
3175
3176 def __del__(self):
3177 _bt_ctf_writer_put(self._w)
3178
3179 """
ec8c88d7
JG
3180 Create a new stream instance and register it to the writer.
3181 """
ec8c88d7 3182
be02a6e6
JG
3183 def create_stream(self, stream_class):
3184 if not isinstance(stream_class, CTFWriter.StreamClass):
3185 raise TypeError("Invalid stream_class type.")
ec8c88d7 3186
be02a6e6
JG
3187 stream = CTFWriter.Stream.__new__(CTFWriter.Stream)
3188 stream._s = _bt_ctf_writer_create_stream(self._w, stream_class._sc)
3189 return stream
3190
3191 """
ec8c88d7
JG
3192 Add an environment field to the trace.
3193 """
ec8c88d7 3194
be02a6e6
JG
3195 def add_environment_field(self, name, value):
3196 ret = _bt_ctf_writer_add_environment_field(
3197 self._w,
3198 str(name),
3199 str(value))
3200 if ret < 0:
3201 raise ValueError("Could not add environment field to trace.")
3202
3203 """
ec8c88d7
JG
3204 Add a clock to the trace. Clocks assigned to stream classes must be
3205 registered to the writer.
3206 """
ec8c88d7 3207
be02a6e6
JG
3208 def add_clock(self, clock):
3209 ret = _bt_ctf_writer_add_clock(self._w, clock._c)
3210 if ret < 0:
3211 raise ValueError("Could not add clock to Writer.")
3212
3213 """
ec8c88d7
JG
3214 Get the trace's TSDL meta-data.
3215 """
be02a6e6
JG
3216 @property
3217 def metadata(self):
3218 return _bt_ctf_writer_get_metadata_string(self._w)
ec8c88d7 3219
be02a6e6 3220 """
ec8c88d7
JG
3221 Flush the trace's metadata to the metadata file.
3222 """
ec8c88d7 3223
be02a6e6
JG
3224 def flush_metadata(self):
3225 _bt_ctf_writer_flush_metadata(self._w)
3226
3227 """
14001277
JG
3228 Get the trace's byte order. Must be a constant from the ByteOrder
3229 class.
3230 """
be02a6e6
JG
3231 @property
3232 def byte_order(self):
3233 raise NotImplementedError("Getter not implemented.")
14001277 3234
be02a6e6 3235 """
ec8c88d7
JG
3236 Set the trace's byte order. Must be a constant from the ByteOrder
3237 class. Defaults to BYTE_ORDER_NATIVE, the host machine's endianness.
3238 """
be02a6e6
JG
3239 @byte_order.setter
3240 def byte_order(self, byte_order):
3241 ret = _bt_ctf_writer_set_byte_order(self._w, byte_order)
3242 if ret < 0:
3243 raise ValueError("Could not set trace's byte order.")
ec8c88d7
JG
3244
3245%}
This page took 0.171604 seconds and 4 git commands to generate.