4 * Babeltrace Python Module interface file
6 * Copyright 2012 EfficiOS Inc.
8 * Author: Danny Serres <danny.serres@efficios.com>
9 * Author: Jérémie Galarneau <jeremie.galarneau@efficios.com>
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:
18 * The above copyright notice and this permission notice shall be included in
19 * all copies or substantial portions of the Software.
24 "BABELTRACE_VERSION_STR
26 Babeltrace is a trace viewer and converter reading and writing the
27 Common Trace Format (CTF). Its main use is to pretty-print CTF
28 traces into a human-readable text output.
30 To use this module, the first step is to create a TraceCollection and add a
34 %module(docstring=DOCSTRING) babeltrace
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>
50 #include <babeltrace/types.h>
51 #include <babeltrace/ctf/iterator.h>
52 #include "python-complements.h"
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>
61 typedef int bt_intern_str;
62 typedef int64_t ssize_t;
64 /* =================================================================
66 ¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯
69 struct bt_definition **_bt_python_field_listcaller(
70 const struct bt_ctf_event *ctf_event,
71 const struct bt_definition *scope,
72 unsigned int *OUTPUT);
73 struct bt_definition *_bt_python_field_one_from_list(
74 struct bt_definition **list, int index);
75 struct bt_ctf_event_decl **_bt_python_event_decl_listcaller(
77 struct bt_context *ctx,
78 unsigned int *OUTPUT);
79 struct bt_ctf_event_decl *_bt_python_decl_one_from_list(
80 struct bt_ctf_event_decl **list, int index);
81 struct 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);
85 struct bt_ctf_field_decl *_bt_python_field_decl_one_from_list(
86 struct bt_ctf_field_decl **list, int index);
87 struct definition_array *_bt_python_get_array_from_def(
88 struct bt_definition *field);
89 struct definition_sequence *_bt_python_get_sequence_from_def(
90 struct bt_definition *field);
91 struct bt_declaration *_bt_python_get_array_element_declaration(
92 struct bt_declaration *field);
93 struct bt_declaration *_bt_python_get_sequence_element_declaration(
94 struct bt_declaration *field);
95 const char *_bt_python_get_array_string(struct bt_definition *field);
96 const char *_bt_python_get_sequence_string(struct bt_definition *field);
97 int _bt_python_field_integer_get_signedness(const struct bt_ctf_field *field);
98 enum ctf_type_id _bt_python_get_field_type(const struct bt_ctf_field *field);
99 const 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);
102 const 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);
105 const char *_bt_python_ctf_field_type_structure_get_field_name(
106 struct bt_ctf_field_type *structure, size_t index);
107 struct bt_ctf_field_type *_bt_python_ctf_field_type_structure_get_field_type(
108 struct bt_ctf_field_type *structure, size_t index);
109 const char *_bt_python_ctf_field_type_variant_get_field_name(
110 struct bt_ctf_field_type *variant, size_t index);
111 struct bt_ctf_field_type *_bt_python_ctf_field_type_variant_get_field_type(
112 struct bt_ctf_field_type *variant, size_t index);
113 const char *_bt_python_ctf_event_class_get_field_name(
114 struct bt_ctf_event_class *event_class, size_t index);
115 struct bt_ctf_field_type *_bt_python_ctf_event_class_get_field_type(
116 struct bt_ctf_event_class *event_class, size_t index);
117 int _bt_python_ctf_clock_get_uuid_index(struct bt_ctf_clock *clock,
118 size_t index, unsigned char *OUTPUT);
119 int _bt_python_ctf_clock_set_uuid_index(struct bt_ctf_clock *clock,
120 size_t index, unsigned char value);
122 /* =================================================================
123 CONTEXT.H, CONTEXT-INTERNAL.H
124 ¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯
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,
130 void (*packet_seek)(struct bt_stream_pos *pos, size_t index, int whence),
131 struct bt_mmap_stream_list *stream_list, FILE *metadata);
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);
139 struct bt_context *bt_context_create(void);
140 int bt_context_add_trace(struct bt_context *ctx, const char *path, const char *format,
141 void (*packet_seek)(struct bt_stream_pos *pos, size_t index, int whence),
142 struct bt_mmap_stream_list *stream_list, FILE *metadata);
143 void bt_context_remove_trace(struct bt_context *ctx, int trace_id);
144 void bt_context_get(struct bt_context *ctx);
145 void bt_context_put(struct bt_context *ctx);
146 struct bt_context *bt_ctf_event_get_context(const struct bt_ctf_event *event);
148 // class TraceCollection to prevent direct access to struct bt_context
151 class TraceCollection:
154 The TraceCollection is the object that contains all currently opened traces.
158 self._tc = _bt_context_create()
161 _bt_context_put(self._tc)
163 def add_trace(self, path, format_str):
165 Add a trace by path to the TraceCollection.
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.
173 format is a string containing the format name in which the trace was
176 Return: the corresponding TraceHandle on success or None on error.
178 ret = _bt_context_add_trace(
188 th = TraceHandle.__new__(TraceHandle)
190 th._trace_collection = self
193 def add_traces_recursive(self, path, format_str):
195 Open a trace recursively.
197 Find each trace present in the subdirectory starting from the given
198 path, and add them to the TraceCollection.
200 Return a dict of TraceHandle instances (the full path is the key).
201 Return None on error.
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:
218 trace_handles[fullpath] = trace_handle
221 if noTrace and error:
225 def remove_trace(self, trace_handle):
227 Remove a trace from the TraceCollection.
228 Effectively closing the trace.
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")
239 Generator function to iterate over the events of open in the current
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.
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.
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
258 for event in self._events(begin_pos_ptr, end_pos_ptr):
261 def events_timestamps(self, timestamp_begin, timestamp_end):
263 Generator function to iterate over the events of open in the current
264 TraceCollection from timestamp_begin to timestamp_end.
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
272 for event in self._events(begin_pos_ptr, end_pos_ptr):
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)
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)
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)
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.")
304 ev_ptr = _bt_ctf_iter_read_event(ctf_it_ptr)
308 ev = Event.__new__(Event)
312 except GeneratorExit:
315 ret = _bt_iter_next(_bt_ctf_get_iter(ctf_it_ptr))
319 _bt_ctf_iter_destroy(ctf_it_ptr)
324 /* =================================================================
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);
332 %rename("unregister_format") bt_unregister_format(struct bt_format *format);
334 extern struct format *bt_lookup_format(bt_intern_str qname);
335 extern void bt_fprintf_format_list(FILE *fp);
336 extern int bt_register_format(struct bt_format *format);
337 extern void bt_unregister_format(struct bt_format *format);
341 def print_format_list(babeltrace_file):
343 Print a list of available formats to file.
345 babeltrace_file must be a File instance opened in write mode.
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")
357 /* =================================================================
358 ITERATOR.H, ITERATOR-INTERNAL.H
359 ¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯
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,
373 struct bt_iter *bt_iter_create(struct bt_context *ctx,
374 const struct bt_iter_pos *begin_pos, const struct bt_iter_pos *end_pos);
375 void bt_iter_destroy(struct bt_iter *iter);
376 int bt_iter_next(struct bt_iter *iter);
377 struct bt_iter_pos *bt_iter_get_pos(struct bt_iter *iter);
378 void bt_iter_free_pos(struct bt_iter_pos *pos);
379 int bt_iter_set_pos(struct bt_iter *iter, const struct bt_iter_pos *pos);
380 struct bt_iter_pos *bt_iter_create_time_pos(struct bt_iter *iter, uint64_t timestamp);
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;
387 %rename("SEEK_LAST") BT_SEEK_LAST;
389 // This struct is taken from iterator.h
390 // All changes to the struct must also be made here
393 BT_SEEK_TIME, /* uses u.seek_time */
394 BT_SEEK_RESTORE, /* uses u.restore */
401 struct bt_saved_pos *restore;
405 /* =================================================================
406 TRACE-HANDLE.H, TRACE-HANDLE-INTERNAL.H
407 ¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯
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);
412 struct bt_trace_handle *bt_trace_handle_create(struct bt_context *ctx);
413 void bt_trace_handle_destroy(struct bt_trace_handle *bt);
415 %rename("_bt_trace_handle_get_path") bt_trace_handle_get_path(struct bt_context *ctx,
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);
421 const char *bt_trace_handle_get_path(struct bt_context *ctx, int handle_id);
422 uint64_t bt_trace_handle_get_timestamp_begin(struct bt_context *ctx, int handle_id,
423 enum bt_clock_type type);
424 uint64_t bt_trace_handle_get_timestamp_end(struct bt_context *ctx, int handle_id,
425 enum bt_clock_type type);
427 %rename("_bt_ctf_event_get_handle_id") bt_ctf_event_get_handle_id(
428 const struct bt_ctf_event *event);
429 int bt_ctf_event_get_handle_id(const struct bt_ctf_event *event);
434 # Based on enum bt_clock_type in clock-type.h
440 class TraceHandle(object):
443 The TraceHandle allows the user to manipulate a trace file directly.
444 It is a unique identifier representing a trace file.
449 raise NotImplementedError("TraceHandle cannot be instantiated")
452 return "Babeltrace TraceHandle: trace_id('{0}')".format(self._id)
456 """Return the TraceHandle id."""
461 """Return the path of a TraceHandle."""
462 return _bt_trace_handle_get_path(self._trace_collection._tc, self._id)
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)
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)
479 Generator returning all events (EventDeclaration) in a trace.
481 ret = _bt_python_event_decl_listcaller(
483 self._trace_collection._tc)
485 if not isinstance(ret, list):
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)
497 // =================================================================
499 // =================================================================
501 /* =================================================================
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);
514 struct 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);
517 struct bt_iter *bt_ctf_get_iter(struct bt_ctf_iter *iter);
518 void bt_ctf_iter_destroy(struct bt_ctf_iter *iter);
519 struct bt_ctf_event *bt_ctf_iter_read_event(struct bt_ctf_iter *iter);
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);
531 %rename("_bt_ctf_get_field") bt_ctf_get_field(const struct bt_ctf_event *ctf_event,
532 const struct bt_definition *scope, const char *field);
533 %rename("_bt_ctf_get_index") bt_ctf_get_index(const struct bt_ctf_event *ctf_event,
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);
537 %rename("_bt_ctf_get_int_signedness") bt_ctf_get_int_signedness(
538 const struct bt_declaration *field);
539 %rename("_bt_ctf_get_int_base") bt_ctf_get_int_base(const struct bt_declaration *field);
540 %rename("_bt_ctf_get_int_byte_order") bt_ctf_get_int_byte_order(
541 const struct bt_declaration *field);
542 %rename("_bt_ctf_get_int_len") bt_ctf_get_int_len(const struct bt_declaration *field);
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);
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);
551 %rename("_bt_ctf_get_float") bt_ctf_get_float(const struct bt_definition *field);
552 %rename("_bt_ctf_get_variant") bt_ctf_get_variant(const struct bt_definition *field);
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);
556 %rename("_bt_ctf_get_decl_event_id") bt_ctf_get_decl_event_id(const struct
557 bt_ctf_event_decl *event);
558 %rename("_bt_ctf_get_decl_field_name") bt_ctf_get_decl_field_name(
559 const struct bt_ctf_field_decl *field);
560 %rename("_bt_ctf_get_decl_from_def") bt_ctf_get_decl_from_def(
561 const struct bt_definition *field);
562 %rename("_bt_ctf_get_decl_from_field_decl") bt_ctf_get_decl_from_field_decl(
563 const struct bt_ctf_field_decl *field);
564 %rename("_bt_array_index") bt_array_index(struct definition_array *array, uint64_t i);
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);
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);
570 const struct bt_definition *bt_ctf_get_top_level_scope(const struct bt_ctf_event *ctf_event,
571 enum bt_ctf_scope scope);
572 const char *bt_ctf_event_name(const struct bt_ctf_event *ctf_event);
573 uint64_t bt_ctf_get_timestamp(const struct bt_ctf_event *ctf_event);
574 uint64_t bt_ctf_get_cycles(const struct bt_ctf_event *ctf_event);
575 const struct bt_definition *bt_ctf_get_field(const struct bt_ctf_event *ctf_event,
576 const struct bt_definition *scope,
578 const struct bt_definition *bt_ctf_get_index(const struct bt_ctf_event *ctf_event,
579 const struct bt_definition *field,
581 const char *bt_ctf_field_name(const struct bt_definition *field);
582 enum ctf_type_id bt_ctf_field_type(const struct bt_declaration *field);
583 int bt_ctf_get_int_signedness(const struct bt_declaration *field);
584 int bt_ctf_get_int_base(const struct bt_declaration *field);
585 int bt_ctf_get_int_byte_order(const struct bt_declaration *field);
586 ssize_t bt_ctf_get_int_len(const struct bt_declaration *field);
587 const struct bt_definition *bt_ctf_get_enum_int(const struct bt_definition *field);
588 const char *bt_ctf_get_enum_str(const struct bt_definition *field);
589 enum ctf_string_encoding bt_ctf_get_encoding(const struct bt_declaration *field);
590 int bt_ctf_get_array_len(const struct bt_declaration *field);
591 struct bt_definition *bt_array_index(struct definition_array *array, uint64_t i);
592 uint64_t bt_ctf_get_uint64(const struct bt_definition *field);
593 int64_t bt_ctf_get_int64(const struct bt_definition *field);
594 char *bt_ctf_get_char_array(const struct bt_definition *field);
595 char *bt_ctf_get_string(const struct bt_definition *field);
596 double bt_ctf_get_float(const struct bt_definition *field);
597 const struct bt_definition *bt_ctf_get_variant(const struct bt_definition *field);
598 int bt_ctf_field_get_error(void);
599 const char *bt_ctf_get_decl_event_name(const struct bt_ctf_event_decl *event);
600 uint64_t bt_ctf_get_decl_event_id(const struct bt_ctf_event_decl *event);
601 const char *bt_ctf_get_decl_field_name(const struct bt_ctf_field_decl *field);
602 const struct bt_declaration *bt_ctf_get_decl_from_def(const struct bt_definition *field);
603 const struct bt_declaration *bt_ctf_get_decl_from_field_decl(const struct bt_ctf_field_decl *field);
604 uint64_t bt_sequence_len(struct definition_sequence *sequence);
605 struct bt_definition *bt_sequence_index(struct definition_sequence *sequence, uint64_t i);
606 uint64_t bt_ctf_get_struct_field_count(const struct bt_definition *structure);
607 const struct bt_definition *bt_ctf_get_struct_field_index(const struct bt_definition *structure, uint64_t i);
611 class CTFStringEncoding:
617 # Based on the enum in ctf-writer/writer.h
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
625 # enum equivalent, accessible constants
626 # These are taken directly from ctf/events.h
627 # All changes to enums must also be made here
642 name = "UNKNOWN_TYPE"
644 attr for attr in dir(CTFTypeId) if not callable(
647 attr)) and not attr.startswith("__")]
648 for attr in constants:
649 if getattr(CTFTypeId, attr) == id:
656 TRACE_PACKET_HEADER = 0
657 STREAM_PACKET_CONTEXT = 1
658 STREAM_EVENT_HEADER = 2
659 STREAM_EVENT_CONTEXT = 3
663 def scope_name(scope):
664 name = "UNKNOWN_SCOPE"
666 attr for attr in dir(CTFScope) if not callable(
669 attr)) and not attr.startswith("__")]
670 for attr in constants:
671 if getattr(CTFScope, attr) == scope:
676 # Priority of the scopes when searching for event fields
677 _scopes = [CTFScope.EVENT_FIELDS, CTFScope.EVENT_CONTEXT, CTFScope.STREAM_EVENT_CONTEXT,
678 CTFScope.STREAM_EVENT_HEADER, CTFScope.STREAM_PACKET_CONTEXT, CTFScope.TRACE_PACKET_HEADER]
681 from datetime import datetime
684 class Event(collections.Mapping):
687 This class represents an event from the trace.
688 It is obtained using the TraceCollection generator functions.
693 raise NotImplementedError("Event cannot be instantiated")
697 """Return the name of the event or None on error."""
698 return _bt_ctf_event_name(self._e)
703 Return the timestamp of the event as written in
704 the packet (in cycles) or -1ULL on error.
706 return _bt_ctf_get_cycles(self._e)
711 Return the timestamp of the event offset with the
712 system clock source or -1ULL on error.
714 return _bt_ctf_get_timestamp(self._e)
719 Return a datetime object based on the event's
720 timestamp. Note that the datetime class' precision
721 is limited to microseconds.
723 return datetime.fromtimestamp(self.timestamp / 1E9)
725 def field_with_scope(self, field_name, scope):
727 Get field_name's value in scope.
728 None is returned if no field matches field_name.
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:
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")
742 for field in self._field_list_with_scope(scope):
743 field_names.append(field.name)
749 Get the TraceHandle associated with this event
752 ret = _bt_ctf_event_get_handle_id(self._e)
756 th = TraceHandle.__new__(TraceHandle)
758 th._trace_collection = self.get_trace_collection()
762 def trace_collection(self):
764 Get the TraceCollection associated with this event.
765 Return None on error.
767 trace_collection = TraceCollection()
768 trace_collection._tc = _bt_ctf_event_get_context(self._e)
769 if trace_collection._tc is None:
772 return trace_collection
774 def __getitem__(self, field_name):
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:
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.
787 Use field_with_scope() to explicitly access fields in a given
790 field = self._field(field_name)
791 if field is not None:
793 raise KeyError(field_name)
796 for key in self.keys():
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):
808 def __contains__(self, field_name):
809 return self._field(field_name) is not None
812 """Return a list of field names."""
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)
819 def get(self, field_name, default=None):
820 field = self._field(field_name)
826 for field in self.keys():
827 yield (field, self[field])
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:
834 definition_ptr = _bt_ctf_get_field(self._e, scope_ptr, field_name)
835 if definition_ptr is None:
838 field = _Definition(definition_ptr, scope)
841 def _field(self, field_name):
843 for scope in _scopes:
844 field = self._field_with_scope(field_name, scope)
845 if field is not None:
849 def _field_list_with_scope(self, scope):
851 scope_ptr = _bt_ctf_get_top_level_scope(self._e, scope)
853 # Returns a list [list_ptr, count]. If list_ptr is NULL, SWIG will only
854 # provide the "count" return value
857 ret = _bt_python_field_listcaller(self._e, scope_ptr)
858 if isinstance(ret, list):
859 list_ptr, count = ret
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)
869 class FieldError(Exception):
871 def __init__(self, value):
875 return repr(self.value)
878 class EventDeclaration(object):
880 """Event declaration class. Do not instantiate."""
881 MAX_UINT64 = 0xFFFFFFFFFFFFFFFF
884 raise NotImplementedError("EventDeclaration cannot be instantiated")
888 """Return the name of the event or None on error"""
889 return _bt_ctf_get_decl_event_name(self._ed)
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:
902 Generator returning all FieldDeclarations of an event, going through
903 each scope in the following order:
906 3) STREAM_EVENT_CONTEXT
907 4) STREAM_EVENT_HEADER
908 5) STREAM_PACKET_CONTEXT
909 6) TRACE_PACKET_HEADER
911 for scope in _scopes:
912 for declaration in self.fields_scope(scope):
915 def fields_scope(self, scope):
917 Generator returning FieldDeclarations of the current event in scope.
919 ret = _by_python_field_decl_listcaller(self._ed, scope)
921 if not isinstance(ret, list):
924 list_ptr, count = ret
925 for i in range(count):
926 field_declaration_ptr = _bt_python_field_decl_one_from_list(
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(
934 _bt_ctf_get_decl_field_name(field_declaration_ptr),
936 yield field_declaration
939 class FieldDeclaration(object):
941 """Field declaration class. Do not instantiate."""
944 raise NotImplementedError("FieldDeclaration cannot be instantiated")
947 return "({0}) {1} {2}".format(
948 CTFScope.scope_name(self.scope), CTFTypeId.type_name(self.type), self.name)
952 """Return the name of a FieldDeclaration or None on error."""
958 Return the FieldDeclaration's type. One of the entries in class
961 return _bt_ctf_field_type(self._fd)
966 Return the FieldDeclaration's scope.
971 class IntegerFieldDeclaration(FieldDeclaration):
973 """Do not instantiate."""
976 raise NotImplementedError(
977 "IntegerFieldDeclaration cannot be instantiated")
980 def signedness(self):
982 Return the signedness of an integer:
983 0 if unsigned; 1 if signed; -1 on error.
985 return _bt_ctf_get_int_signedness(self._fd)
989 """Return the base of an int or a negative value on error."""
990 return _bt_ctf_get_int_base(self._fd)
993 def byte_order(self):
995 Return the byte order. One of class ByteOrder's entries.
997 ret = _bt_ctf_get_int_byte_order(self._fd)
999 return ByteOrder.BYTE_ORDER_LITTLE_ENDIAN
1001 return ByteOrder.BYTE_ORDER_BIG_ENDIAN
1003 return ByteOrder.BYTE_ORDER_UNKNOWN
1008 Return the size, in bits, of an int or a negative
1011 return _bt_ctf_get_int_len(self._fd)
1016 Return the encoding. One of class CTFStringEncoding's entries.
1017 Return a negative value on error.
1019 return _bt_ctf_get_encoding(self._fd)
1022 class EnumerationFieldDeclaration(FieldDeclaration):
1024 """Do not instantiate."""
1027 raise NotImplementedError(
1028 "EnumerationFieldDeclaration cannot be instantiated")
1031 class ArrayFieldDeclaration(FieldDeclaration):
1033 """Do not instantiate."""
1036 raise NotImplementedError(
1037 "ArrayFieldDeclaration cannot be instantiated")
1042 Return the length of an array or a negative
1045 return _bt_ctf_get_array_len(self._fd)
1048 def element_declaration(self):
1050 Return element declaration.
1052 field_decl_ptr = _bt_python_get_array_element_declaration(self._fd)
1053 return _create_field_declaration(field_decl_ptr, "", self.scope)
1056 class SequenceFieldDeclaration(FieldDeclaration):
1058 """Do not instantiate."""
1061 raise NotImplementedError(
1062 "SequenceFieldDeclaration cannot be instantiated")
1065 def element_declaration(self):
1067 Return element declaration.
1069 field_decl_ptr = _bt_python_get_sequence_element_declaration(self._fd)
1070 return _create_field_declaration(field_decl_ptr, "", self.scope)
1073 class FloatFieldDeclaration(FieldDeclaration):
1075 """Do not instantiate."""
1078 raise NotImplementedError(
1079 "FloatFieldDeclaration cannot be instantiated")
1082 class StructureFieldDeclaration(FieldDeclaration):
1084 """Do not instantiate."""
1087 raise NotImplementedError(
1088 "StructureFieldDeclaration cannot be instantiated")
1091 class StringFieldDeclaration(FieldDeclaration):
1093 """Do not instantiate."""
1096 raise NotImplementedError(
1097 "StringFieldDeclaration cannot be instantiated")
1100 class VariantFieldDeclaration(FieldDeclaration):
1102 """Do not instantiate."""
1105 raise NotImplementedError(
1106 "VariantFieldDeclaration cannot be instantiated")
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.
1115 return _bt_ctf_field_get_error()
1118 def _create_field_declaration(declaration_ptr, name, scope):
1120 Private field declaration factory.
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")
1127 type = _bt_ctf_field_type(declaration_ptr)
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)
1151 declaration._fd = declaration_ptr
1152 declaration._s = scope
1153 declaration._name = name
1157 class _Definition(object):
1159 def __init__(self, definition_ptr, scope):
1160 self._d = definition_ptr
1162 if not scope in _scopes:
1163 ValueError("Invalid scope provided")
1167 """Return the name of a field or None on error."""
1168 return _bt_ctf_field_name(self._d)
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))
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)
1181 def _get_enum_str(self):
1183 Return the string matching the current enumeration.
1184 Return None on error.
1186 return _bt_ctf_get_enum_str(self._d)
1188 def _get_array_element_at(self, index):
1190 Return the array's element at position index.
1191 Return None on error
1193 array_ptr = _bt_python_get_array_from_def(self._d)
1194 if array_ptr is None:
1197 definition_ptr = _bt_array_index(array_ptr, index)
1198 if definition_ptr is None:
1200 return _Definition(definition_ptr, self.scope)
1202 def _get_sequence_len(self):
1204 Return the len of a sequence or a negative
1207 seq = _bt_python_get_sequence_from_def(self._d)
1208 return _bt_sequence_len(seq)
1210 def _get_sequence_element_at(self, index):
1212 Return the sequence's element at position index,
1213 otherwise return None
1215 seq = _bt_python_get_sequence_from_def(self._d)
1217 definition_ptr = _bt_sequence_index(seq, index)
1218 if definition_ptr is not None:
1219 return _Definition(definition_ptr, self.scope)
1222 def _get_uint64(self):
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.
1229 return _bt_ctf_get_uint64(self._d)
1231 def _get_int64(self):
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.
1238 return _bt_ctf_get_int64(self._d)
1240 def _get_char_array(self):
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.
1247 return _bt_ctf_get_char_array(self._d)
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.
1256 return _bt_ctf_get_string(self._d)
1258 def _get_float(self):
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.
1265 return _bt_ctf_get_float(self._d)
1267 def _get_variant(self):
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.
1274 return _bt_ctf_get_variant(self._d)
1276 def _get_struct_field_count(self):
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.
1282 return _bt_ctf_get_struct_field_count(self._d)
1284 def _get_struct_field_at(self, i):
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.
1291 return _bt_ctf_get_struct_field_index(self._d, i)
1296 Return the value associated with the field according to its type.
1297 Return None on error.
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)
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()
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)
1329 seq_len = self._get_sequence_len()
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:
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
1348 "Error occurred while accessing field {} of type {}".format(
1350 CTFTypeId.type_name(id)))
1355 """Return the scope of a field or None on error."""
1361 // =================================================================
1363 // =================================================================
1366 %rename("_bt_ctf_clock_create") bt_ctf_clock_create(const char *name);
1367 %rename("_bt_ctf_clock_get_name") bt_ctf_clock_get_name(struct bt_ctf_clock *clock);
1368 %rename("_bt_ctf_clock_get_description") bt_ctf_clock_get_description(struct bt_ctf_clock *clock);
1369 %rename("_bt_ctf_clock_set_description") bt_ctf_clock_set_description(struct bt_ctf_clock *clock, const char *desc);
1370 %rename("_bt_ctf_clock_get_frequency") bt_ctf_clock_get_frequency(struct bt_ctf_clock *clock);
1371 %rename("_bt_ctf_clock_set_frequency") bt_ctf_clock_set_frequency(struct bt_ctf_clock *clock, uint64_t freq);
1372 %rename("_bt_ctf_clock_get_precision") bt_ctf_clock_get_precision(struct bt_ctf_clock *clock);
1373 %rename("_bt_ctf_clock_set_precision") bt_ctf_clock_set_precision(struct bt_ctf_clock *clock, uint64_t precision);
1374 %rename("_bt_ctf_clock_get_offset_s") bt_ctf_clock_get_offset_s(struct bt_ctf_clock *clock);
1375 %rename("_bt_ctf_clock_set_offset_s") bt_ctf_clock_set_offset_s(struct bt_ctf_clock *clock, uint64_t offset_s);
1376 %rename("_bt_ctf_clock_get_offset") bt_ctf_clock_get_offset(struct bt_ctf_clock *clock);
1377 %rename("_bt_ctf_clock_set_offset") bt_ctf_clock_set_offset(struct bt_ctf_clock *clock, uint64_t offset);
1378 %rename("_bt_ctf_clock_get_is_absolute") bt_ctf_clock_get_is_absolute(struct bt_ctf_clock *clock);
1379 %rename("_bt_ctf_clock_set_is_absolute") bt_ctf_clock_set_is_absolute(struct bt_ctf_clock *clock, int is_absolute);
1380 %rename("_bt_ctf_clock_get_time") bt_ctf_clock_get_time(struct bt_ctf_clock *clock);
1381 %rename("_bt_ctf_clock_set_time") bt_ctf_clock_set_time(struct bt_ctf_clock *clock, uint64_t time);
1382 %rename("_bt_ctf_clock_get") bt_ctf_clock_get(struct bt_ctf_clock *clock);
1383 %rename("_bt_ctf_clock_put") bt_ctf_clock_put(struct bt_ctf_clock *clock);
1385 struct bt_ctf_clock *bt_ctf_clock_create(const char *name);
1386 const char *bt_ctf_clock_get_name(struct bt_ctf_clock *clock);
1387 const char *bt_ctf_clock_get_description(struct bt_ctf_clock *clock);
1388 int bt_ctf_clock_set_description(struct bt_ctf_clock *clock, const char *desc);
1389 uint64_t bt_ctf_clock_get_frequency(struct bt_ctf_clock *clock);
1390 int bt_ctf_clock_set_frequency(struct bt_ctf_clock *clock, uint64_t freq);
1391 uint64_t bt_ctf_clock_get_precision(struct bt_ctf_clock *clock);
1392 int bt_ctf_clock_set_precision(struct bt_ctf_clock *clock, uint64_t precision);
1393 uint64_t bt_ctf_clock_get_offset_s(struct bt_ctf_clock *clock);
1394 int bt_ctf_clock_set_offset_s(struct bt_ctf_clock *clock, uint64_t offset_s);
1395 uint64_t bt_ctf_clock_get_offset(struct bt_ctf_clock *clock);
1396 int bt_ctf_clock_set_offset(struct bt_ctf_clock *clock, uint64_t offset);
1397 int bt_ctf_clock_get_is_absolute(struct bt_ctf_clock *clock);
1398 int bt_ctf_clock_set_is_absolute(struct bt_ctf_clock *clock, int is_absolute);
1399 uint64_t bt_ctf_clock_get_time(struct bt_ctf_clock *clock);
1400 int bt_ctf_clock_set_time(struct bt_ctf_clock *clock, uint64_t time);
1401 void bt_ctf_clock_get(struct bt_ctf_clock *clock);
1402 void bt_ctf_clock_put(struct bt_ctf_clock *clock);
1405 %rename("_bt_ctf_field_type_integer_create") bt_ctf_field_type_integer_create(unsigned int size);
1406 %rename("_bt_ctf_field_type_integer_get_size") bt_ctf_field_type_integer_get_size(struct bt_ctf_field_type *integer);
1407 %rename("_bt_ctf_field_type_integer_get_signed") bt_ctf_field_type_integer_get_signed(struct bt_ctf_field_type *integer);
1408 %rename("_bt_ctf_field_type_integer_set_signed") bt_ctf_field_type_integer_set_signed(struct bt_ctf_field_type *integer, int is_signed);
1409 %rename("_bt_ctf_field_type_integer_get_base") bt_ctf_field_type_integer_get_base(struct bt_ctf_field_type *integer);
1410 %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);
1411 %rename("_bt_ctf_field_type_integer_get_encoding") bt_ctf_field_type_integer_get_encoding(struct bt_ctf_field_type *integer);
1412 %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);
1413 %rename("_bt_ctf_field_type_enumeration_create") bt_ctf_field_type_enumeration_create(struct bt_ctf_field_type *integer_container_type);
1414 %rename("_bt_ctf_field_type_enumeration_get_container_type") bt_ctf_field_type_enumeration_get_container_type(struct bt_ctf_field_type *enumeration);
1415 %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);
1416 %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);
1417 %rename("_bt_ctf_field_type_enumeration_get_mapping_count") bt_ctf_field_type_enumeration_get_mapping_count(struct bt_ctf_field_type *enumeration);
1418 %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);
1419 %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);
1420 %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);
1421 %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);
1422 %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);
1423 %rename("_bt_ctf_field_type_floating_point_create") bt_ctf_field_type_floating_point_create(void);
1424 %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);
1425 %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);
1426 %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);
1427 %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);
1428 %rename("_bt_ctf_field_type_structure_create") bt_ctf_field_type_structure_create(void);
1429 %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);
1430 %rename("_bt_ctf_field_type_structure_get_field_count") bt_ctf_field_type_structure_get_field_count(struct bt_ctf_field_type *structure);
1431 %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);
1432 %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);
1433 %rename("_bt_ctf_field_type_variant_create") bt_ctf_field_type_variant_create(struct bt_ctf_field_type *enum_tag, const char *tag_name);
1434 %rename("_bt_ctf_field_type_variant_get_tag_type") bt_ctf_field_type_variant_get_tag_type(struct bt_ctf_field_type *variant);
1435 %rename("_bt_ctf_field_type_variant_get_tag_name") bt_ctf_field_type_variant_get_tag_name(struct bt_ctf_field_type *variant);
1436 %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);
1437 %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);
1438 %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);
1439 %rename("_bt_ctf_field_type_variant_get_field_count") bt_ctf_field_type_variant_get_field_count(struct bt_ctf_field_type *variant);
1440 %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);
1441 %rename("_bt_ctf_field_type_array_create") bt_ctf_field_type_array_create(struct bt_ctf_field_type *element_type, unsigned int length);
1442 %rename("_bt_ctf_field_type_array_get_element_type") bt_ctf_field_type_array_get_element_type(struct bt_ctf_field_type *array);
1443 %rename("_bt_ctf_field_type_array_get_length") bt_ctf_field_type_array_get_length(struct bt_ctf_field_type *array);
1444 %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);
1445 %rename("_bt_ctf_field_type_sequence_get_element_type") bt_ctf_field_type_sequence_get_element_type(struct bt_ctf_field_type *sequence);
1446 %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);
1447 %rename("_bt_ctf_field_type_string_create") bt_ctf_field_type_string_create(void);
1448 %rename("_bt_ctf_field_type_string_get_encoding") bt_ctf_field_type_string_get_encoding(struct bt_ctf_field_type *string_type);
1449 %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);
1450 %rename("_bt_ctf_field_type_get_alignment") bt_ctf_field_type_get_alignment(struct bt_ctf_field_type *type);
1451 %rename("_bt_ctf_field_type_set_alignment") bt_ctf_field_type_set_alignment(struct bt_ctf_field_type *type, unsigned int alignment);
1452 %rename("_bt_ctf_field_type_get_byte_order") bt_ctf_field_type_get_byte_order(struct bt_ctf_field_type *type);
1453 %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);
1454 %rename("_bt_ctf_field_type_get_type_id") bt_ctf_field_type_get_type_id(struct bt_ctf_field_type *type);
1455 %rename("_bt_ctf_field_type_get") bt_ctf_field_type_get(struct bt_ctf_field_type *type);
1456 %rename("_bt_ctf_field_type_put") bt_ctf_field_type_put(struct bt_ctf_field_type *type);
1458 struct bt_ctf_field_type *bt_ctf_field_type_integer_create(unsigned int size);
1459 int bt_ctf_field_type_integer_get_size(struct bt_ctf_field_type *integer);
1460 int bt_ctf_field_type_integer_get_signed(struct bt_ctf_field_type *integer);
1461 int bt_ctf_field_type_integer_set_signed(struct bt_ctf_field_type *integer, int is_signed);
1462 enum bt_ctf_integer_base bt_ctf_field_type_integer_get_base(struct bt_ctf_field_type *integer);
1463 int bt_ctf_field_type_integer_set_base(struct bt_ctf_field_type *integer, enum bt_ctf_integer_base base);
1464 enum ctf_string_encoding bt_ctf_field_type_integer_get_encoding(struct bt_ctf_field_type *integer);
1465 int bt_ctf_field_type_integer_set_encoding(struct bt_ctf_field_type *integer, enum ctf_string_encoding encoding);
1466 struct bt_ctf_field_type *bt_ctf_field_type_enumeration_create(struct bt_ctf_field_type *integer_container_type);
1467 struct bt_ctf_field_type *bt_ctf_field_type_enumeration_get_container_type(struct bt_ctf_field_type *enumeration);
1468 int bt_ctf_field_type_enumeration_add_mapping(struct bt_ctf_field_type *enumeration, const char *name, int64_t range_start, int64_t range_end);
1469 int 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);
1470 int64_t bt_ctf_field_type_enumeration_get_mapping_count(struct bt_ctf_field_type *enumeration);
1471 int 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);
1472 int 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);
1473 int bt_ctf_field_type_enumeration_get_mapping_index_by_name(struct bt_ctf_field_type *enumeration, const char *name, size_t *OUTPUT);
1474 int bt_ctf_field_type_enumeration_get_mapping_index_by_value(struct bt_ctf_field_type *enumeration, int64_t value, size_t *OUTPUT);
1475 int bt_ctf_field_type_enumeration_get_mapping_index_by_unsigned_value(struct bt_ctf_field_type *enumeration, uint64_t value, size_t *OUTPUT);
1476 struct bt_ctf_field_type *bt_ctf_field_type_floating_point_create(void);
1477 int bt_ctf_field_type_floating_point_get_exponent_digits(struct bt_ctf_field_type *floating_point);
1478 int bt_ctf_field_type_floating_point_set_exponent_digits(struct bt_ctf_field_type *floating_point, unsigned int exponent_digits);
1479 int bt_ctf_field_type_floating_point_get_mantissa_digits(struct bt_ctf_field_type *floating_point);
1480 int bt_ctf_field_type_floating_point_set_mantissa_digits(struct bt_ctf_field_type *floating_point, unsigned int mantissa_digits);
1481 struct bt_ctf_field_type *bt_ctf_field_type_structure_create(void);
1482 int bt_ctf_field_type_structure_add_field(struct bt_ctf_field_type *structure, struct bt_ctf_field_type *field_type, const char *field_name);
1483 int64_t bt_ctf_field_type_structure_get_field_count(struct bt_ctf_field_type *structure);
1484 int 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);
1485 struct bt_ctf_field_type *bt_ctf_field_type_structure_get_field_type_by_name(struct bt_ctf_field_type *structure, const char *field_name);
1486 struct bt_ctf_field_type *bt_ctf_field_type_variant_create(struct bt_ctf_field_type *enum_tag, const char *tag_name);
1487 struct bt_ctf_field_type *bt_ctf_field_type_variant_get_tag_type(struct bt_ctf_field_type *variant);
1488 const char *bt_ctf_field_type_variant_get_tag_name(struct bt_ctf_field_type *variant);
1489 int bt_ctf_field_type_variant_add_field(struct bt_ctf_field_type *variant, struct bt_ctf_field_type *field_type, const char *field_name);
1490 struct bt_ctf_field_type *bt_ctf_field_type_variant_get_field_type_by_name(struct bt_ctf_field_type *variant, const char *field_name);
1491 struct 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);
1492 int64_t bt_ctf_field_type_variant_get_field_count(struct bt_ctf_field_type *variant);
1493 int 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);
1494 struct bt_ctf_field_type *bt_ctf_field_type_array_create(struct bt_ctf_field_type *element_type, unsigned int length);
1495 struct bt_ctf_field_type *bt_ctf_field_type_array_get_element_type(struct bt_ctf_field_type *array);
1496 int64_t bt_ctf_field_type_array_get_length(struct bt_ctf_field_type *array);
1497 struct bt_ctf_field_type *bt_ctf_field_type_sequence_create(struct bt_ctf_field_type *element_type, const char *length_field_name);
1498 struct bt_ctf_field_type *bt_ctf_field_type_sequence_get_element_type(struct bt_ctf_field_type *sequence);
1499 const char *bt_ctf_field_type_sequence_get_length_field_name(struct bt_ctf_field_type *sequence);
1500 struct bt_ctf_field_type *bt_ctf_field_type_string_create(void);
1501 enum ctf_string_encoding bt_ctf_field_type_string_get_encoding(struct bt_ctf_field_type *string_type);
1502 int bt_ctf_field_type_string_set_encoding(struct bt_ctf_field_type *string_type, enum ctf_string_encoding encoding);
1503 int bt_ctf_field_type_get_alignment(struct bt_ctf_field_type *type);
1504 int bt_ctf_field_type_set_alignment(struct bt_ctf_field_type *type, unsigned int alignment);
1505 enum bt_ctf_byte_order bt_ctf_field_type_get_byte_order(struct bt_ctf_field_type *type);
1506 int bt_ctf_field_type_set_byte_order(struct bt_ctf_field_type *type, enum bt_ctf_byte_order byte_order);
1507 enum ctf_type_id bt_ctf_field_type_get_type_id(struct bt_ctf_field_type *type);
1508 void bt_ctf_field_type_get(struct bt_ctf_field_type *type);
1509 void bt_ctf_field_type_put(struct bt_ctf_field_type *type);
1511 /* event-fields.h */
1512 %rename("_bt_ctf_field_create") bt_ctf_field_create(struct bt_ctf_field_type *type);
1513 %rename("_bt_ctf_field_structure_get_field") bt_ctf_field_structure_get_field(struct bt_ctf_field *structure, const char *name);
1514 %rename("_bt_ctf_field_array_get_field") bt_ctf_field_array_get_field(struct bt_ctf_field *array, uint64_t index);
1515 %rename("_bt_ctf_field_sequence_get_length") bt_ctf_field_sequence_get_length(struct bt_ctf_field *sequence);
1516 %rename("_bt_ctf_field_sequence_set_length") bt_ctf_field_sequence_set_length(struct bt_ctf_field *sequence, struct bt_ctf_field *length_field);
1517 %rename("_bt_ctf_field_sequence_get_field") bt_ctf_field_sequence_get_field(struct bt_ctf_field *sequence, uint64_t index);
1518 %rename("_bt_ctf_field_variant_get_field") bt_ctf_field_variant_get_field(struct bt_ctf_field *variant, struct bt_ctf_field *tag);
1519 %rename("_bt_ctf_field_enumeration_get_container") bt_ctf_field_enumeration_get_container(struct bt_ctf_field *enumeration);
1520 %rename("_bt_ctf_field_enumeration_get_mapping_name") bt_ctf_field_enumeration_get_mapping_name(struct bt_ctf_field *enumeration);
1521 %rename("_bt_ctf_field_signed_integer_get_value") bt_ctf_field_signed_integer_get_value(struct bt_ctf_field *integer, int64_t *value);
1522 %rename("_bt_ctf_field_signed_integer_set_value") bt_ctf_field_signed_integer_set_value(struct bt_ctf_field *integer, int64_t value);
1523 %rename("_bt_ctf_field_unsigned_integer_get_value") bt_ctf_field_unsigned_integer_get_value(struct bt_ctf_field *integer, uint64_t *value);
1524 %rename("_bt_ctf_field_unsigned_integer_set_value") bt_ctf_field_unsigned_integer_set_value(struct bt_ctf_field *integer, uint64_t value);
1525 %rename("_bt_ctf_field_floating_point_get_value") bt_ctf_field_floating_point_get_value(struct bt_ctf_field *floating_point, double *value);
1526 %rename("_bt_ctf_field_floating_point_set_value") bt_ctf_field_floating_point_set_value(struct bt_ctf_field *floating_point, double value);
1527 %rename("_bt_ctf_field_string_get_value") bt_ctf_field_string_get_value(struct bt_ctf_field *string_field);
1528 %rename("_bt_ctf_field_string_set_value") bt_ctf_field_string_set_value(struct bt_ctf_field *string_field, const char *value);
1529 %rename("_bt_ctf_field_get_type") bt_ctf_field_get_type(struct bt_ctf_field *field);
1530 %rename("_bt_ctf_field_get") bt_ctf_field_get(struct bt_ctf_field *field);
1531 %rename("_bt_ctf_field_put") bt_ctf_field_put(struct bt_ctf_field *field);
1533 struct bt_ctf_field *bt_ctf_field_create(struct bt_ctf_field_type *type);
1534 struct bt_ctf_field *bt_ctf_field_structure_get_field(struct bt_ctf_field *structure, const char *name);
1535 struct bt_ctf_field *bt_ctf_field_array_get_field(struct bt_ctf_field *array, uint64_t index);
1536 struct bt_ctf_field * bt_ctf_field_sequence_get_length(struct bt_ctf_field *sequence);
1537 int bt_ctf_field_sequence_set_length(struct bt_ctf_field *sequence, struct bt_ctf_field *length_field);
1538 struct bt_ctf_field *bt_ctf_field_sequence_get_field(struct bt_ctf_field *sequence, uint64_t index);
1539 struct bt_ctf_field *bt_ctf_field_variant_get_field(struct bt_ctf_field *variant, struct bt_ctf_field *tag);
1540 struct bt_ctf_field *bt_ctf_field_enumeration_get_container(struct bt_ctf_field *enumeration);
1541 const char *bt_ctf_field_enumeration_get_mapping_name(struct bt_ctf_field *enumeration);
1542 int bt_ctf_field_signed_integer_get_value(struct bt_ctf_field *integer, int64_t *OUTPUT);
1543 int bt_ctf_field_signed_integer_set_value(struct bt_ctf_field *integer, int64_t value);
1544 int bt_ctf_field_unsigned_integer_get_value(struct bt_ctf_field *integer, uint64_t *OUTPUT);
1545 int bt_ctf_field_unsigned_integer_set_value(struct bt_ctf_field *integer, uint64_t value);
1546 int bt_ctf_field_floating_point_get_value(struct bt_ctf_field *floating_point, double *OUTPUT);
1547 int bt_ctf_field_floating_point_set_value(struct bt_ctf_field *floating_point, double value);
1548 const char *bt_ctf_field_string_get_value(struct bt_ctf_field *string_field);
1549 int bt_ctf_field_string_set_value(struct bt_ctf_field *string_field, const char *value);
1550 struct bt_ctf_field_type *bt_ctf_field_get_type(struct bt_ctf_field *field);
1551 void bt_ctf_field_get(struct bt_ctf_field *field);
1552 void bt_ctf_field_put(struct bt_ctf_field *field);
1555 %rename("_bt_ctf_event_class_create") bt_ctf_event_class_create(const char *name);
1556 %rename("_bt_ctf_event_class_get_name") bt_ctf_event_class_get_name(struct bt_ctf_event_class *event_class);
1557 %rename("_bt_ctf_event_class_get_id") bt_ctf_event_class_get_id(struct bt_ctf_event_class *event_class);
1558 %rename("_bt_ctf_event_class_set_id") bt_ctf_event_class_set_id(struct bt_ctf_event_class *event_class, uint32_t id);
1559 %rename("_bt_ctf_event_class_get_stream_class") bt_ctf_event_class_get_stream_class(struct bt_ctf_event_class *event_class);
1560 %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);
1561 %rename("_bt_ctf_event_class_get_field_count") bt_ctf_event_class_get_field_count(struct bt_ctf_event_class *event_class);
1562 %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);
1563 %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);
1564 %rename("_bt_ctf_event_class_get") bt_ctf_event_class_get(struct bt_ctf_event_class *event_class);
1565 %rename("_bt_ctf_event_class_put") bt_ctf_event_class_put(struct bt_ctf_event_class *event_class);
1567 struct bt_ctf_event_class *bt_ctf_event_class_create(const char *name);
1568 const char *bt_ctf_event_class_get_name(struct bt_ctf_event_class *event_class);
1569 int64_t bt_ctf_event_class_get_id(struct bt_ctf_event_class *event_class);
1570 int bt_ctf_event_class_set_id(struct bt_ctf_event_class *event_class, uint32_t id);
1571 struct bt_ctf_stream_class *bt_ctf_event_class_get_stream_class(struct bt_ctf_event_class *event_class);
1572 int bt_ctf_event_class_add_field(struct bt_ctf_event_class *event_class, struct bt_ctf_field_type *type, const char *name);
1573 int64_t bt_ctf_event_class_get_field_count(struct bt_ctf_event_class *event_class);
1574 int 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 struct bt_ctf_field_type *bt_ctf_event_class_get_field_by_name(struct bt_ctf_event_class *event_class, const char *name);
1576 void bt_ctf_event_class_get(struct bt_ctf_event_class *event_class);
1577 void bt_ctf_event_class_put(struct bt_ctf_event_class *event_class);
1580 %rename("_bt_ctf_event_create") bt_ctf_event_create(struct bt_ctf_event_class *event_class);
1581 %rename("_bt_ctf_event_get_class") bt_ctf_event_get_class(struct bt_ctf_event *event);
1582 %rename("_bt_ctf_event_get_clock") bt_ctf_event_get_clock(struct bt_ctf_event *event);
1583 %rename("_bt_ctf_event_get_payload") bt_ctf_event_get_payload(struct bt_ctf_event *event, const char *name);
1584 %rename("_bt_ctf_event_set_payload") bt_ctf_event_set_payload(struct bt_ctf_event *event, const char *name, struct bt_ctf_field *value);
1585 %rename("_bt_ctf_event_get_payload_by_index") bt_ctf_event_get_payload_by_index(struct bt_ctf_event *event, size_t index);
1586 %rename("_bt_ctf_event_get") bt_ctf_event_get(struct bt_ctf_event *event);
1587 %rename("_bt_ctf_event_put") bt_ctf_event_put(struct bt_ctf_event *event);
1589 struct bt_ctf_event *bt_ctf_event_create(struct bt_ctf_event_class *event_class);
1590 struct bt_ctf_event_class *bt_ctf_event_get_class(struct bt_ctf_event *event);
1591 struct bt_ctf_clock *bt_ctf_event_get_clock(struct bt_ctf_event *event);
1592 struct bt_ctf_field *bt_ctf_event_get_payload(struct bt_ctf_event *event, const char *name);
1593 int bt_ctf_event_set_payload(struct bt_ctf_event *event, const char *name, struct bt_ctf_field *value);
1594 struct bt_ctf_field *bt_ctf_event_get_payload_by_index(struct bt_ctf_event *event, size_t index);
1595 void bt_ctf_event_get(struct bt_ctf_event *event);
1596 void bt_ctf_event_put(struct bt_ctf_event *event);
1598 /* stream-class.h */
1599 %rename("_bt_ctf_stream_class_create") bt_ctf_stream_class_create(const char *name);
1600 %rename("_bt_ctf_stream_class_get_name") bt_ctf_stream_class_get_name(struct bt_ctf_stream_class *stream_class);
1601 %rename("_bt_ctf_stream_class_get_clock") bt_ctf_stream_class_get_clock(struct bt_ctf_stream_class *stream_class);
1602 %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);
1603 %rename("_bt_ctf_stream_class_get_id") bt_ctf_stream_class_get_id(struct bt_ctf_stream_class *stream_class);
1604 %rename("_bt_ctf_stream_class_set_id") bt_ctf_stream_class_set_id(struct bt_ctf_stream_class *stream_class, uint32_t id);
1605 %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);
1606 %rename("_bt_ctf_stream_class_get_event_class_count") bt_ctf_stream_class_get_event_class_count(struct bt_ctf_stream_class *stream_class);
1607 %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);
1608 %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);
1609 %rename("_bt_ctf_stream_class_get_packet_context_type") bt_ctf_stream_class_get_packet_context_type(struct bt_ctf_stream_class *stream_class);
1610 %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);
1611 %rename("_bt_ctf_stream_class_get") bt_ctf_stream_class_get(struct bt_ctf_stream_class *stream_class);
1612 %rename("_bt_ctf_stream_class_put") bt_ctf_stream_class_put(struct bt_ctf_stream_class *stream_class);
1614 struct bt_ctf_stream_class *bt_ctf_stream_class_create(const char *name);
1615 const char *bt_ctf_stream_class_get_name(struct bt_ctf_stream_class *stream_class);
1616 struct bt_ctf_clock *bt_ctf_stream_class_get_clock(struct bt_ctf_stream_class *stream_class);
1617 int bt_ctf_stream_class_set_clock(struct bt_ctf_stream_class *stream_class, struct bt_ctf_clock *clock);
1618 int64_t bt_ctf_stream_class_get_id(struct bt_ctf_stream_class *stream_class);
1619 int bt_ctf_stream_class_set_id(struct bt_ctf_stream_class *stream_class, uint32_t id);
1620 int bt_ctf_stream_class_add_event_class(struct bt_ctf_stream_class *stream_class, struct bt_ctf_event_class *event_class);
1621 int64_t bt_ctf_stream_class_get_event_class_count(struct bt_ctf_stream_class *stream_class);
1622 struct bt_ctf_event_class *bt_ctf_stream_class_get_event_class(struct bt_ctf_stream_class *stream_class, size_t index);
1623 struct bt_ctf_event_class *bt_ctf_stream_class_get_event_class_by_name(struct bt_ctf_stream_class *stream_class, const char *name);
1624 struct bt_ctf_field_type *bt_ctf_stream_class_get_packet_context_type(struct bt_ctf_stream_class *stream_class);
1625 int bt_ctf_stream_class_set_packet_context_type(struct bt_ctf_stream_class *stream_class, struct bt_ctf_field_type *packet_context_type);
1626 void bt_ctf_stream_class_get(struct bt_ctf_stream_class *stream_class);
1627 void bt_ctf_stream_class_put(struct bt_ctf_stream_class *stream_class);
1630 %rename("_bt_ctf_stream_get_discarded_events_count") bt_ctf_stream_get_discarded_events_count(struct bt_ctf_stream *stream, uint64_t *count);
1631 %rename("_bt_ctf_stream_append_discarded_events") bt_ctf_stream_append_discarded_events(struct bt_ctf_stream *stream, uint64_t event_count);
1632 %rename("_bt_ctf_stream_append_event") bt_ctf_stream_append_event(struct bt_ctf_stream *stream, struct bt_ctf_event *event);
1633 %rename("_bt_ctf_stream_get_packet_context") bt_ctf_stream_get_packet_context(struct bt_ctf_stream *stream);
1634 %rename("_bt_ctf_stream_set_packet_context") bt_ctf_stream_set_packet_context(struct bt_ctf_stream *stream, struct bt_ctf_field *packet_context);
1635 %rename("_bt_ctf_stream_flush") bt_ctf_stream_flush(struct bt_ctf_stream *stream);
1636 %rename("_bt_ctf_stream_get") bt_ctf_stream_get(struct bt_ctf_stream *stream);
1637 %rename("_bt_ctf_stream_put") bt_ctf_stream_put(struct bt_ctf_stream *stream);
1639 int bt_ctf_stream_get_discarded_events_count(struct bt_ctf_stream *stream, uint64_t *OUTPUT);
1640 void bt_ctf_stream_append_discarded_events(struct bt_ctf_stream *stream, uint64_t event_count);
1641 int bt_ctf_stream_append_event(struct bt_ctf_stream *stream, struct bt_ctf_event *event);
1642 struct bt_ctf_field *bt_ctf_stream_get_packet_context(struct bt_ctf_stream *stream);
1643 int bt_ctf_stream_set_packet_context(struct bt_ctf_stream *stream, struct bt_ctf_field *packet_context);
1644 int bt_ctf_stream_flush(struct bt_ctf_stream *stream);
1645 void bt_ctf_stream_get(struct bt_ctf_stream *stream);
1646 void bt_ctf_stream_put(struct bt_ctf_stream *stream);
1649 %rename("_bt_ctf_writer_create") bt_ctf_writer_create(const char *path);
1650 %rename("_bt_ctf_writer_create_stream") bt_ctf_writer_create_stream(struct bt_ctf_writer *writer, struct bt_ctf_stream_class *stream_class);
1651 %rename("_bt_ctf_writer_add_environment_field") bt_ctf_writer_add_environment_field(struct bt_ctf_writer *writer, const char *name, const char *value);
1652 %rename("_bt_ctf_writer_add_clock") bt_ctf_writer_add_clock(struct bt_ctf_writer *writer, struct bt_ctf_clock *clock);
1653 %newobject bt_ctf_writer_get_metadata_string;
1654 %rename("_bt_ctf_writer_get_metadata_string") bt_ctf_writer_get_metadata_string(struct bt_ctf_writer *writer);
1655 %rename("_bt_ctf_writer_flush_metadata") bt_ctf_writer_flush_metadata(struct bt_ctf_writer *writer);
1656 %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);
1657 %rename("_bt_ctf_writer_get") bt_ctf_writer_get(struct bt_ctf_writer *writer);
1658 %rename("_bt_ctf_writer_put") bt_ctf_writer_put(struct bt_ctf_writer *writer);
1660 struct bt_ctf_writer *bt_ctf_writer_create(const char *path);
1661 struct bt_ctf_stream *bt_ctf_writer_create_stream(struct bt_ctf_writer *writer, struct bt_ctf_stream_class *stream_class);
1662 int bt_ctf_writer_add_environment_field(struct bt_ctf_writer *writer, const char *name, const char *value);
1663 int bt_ctf_writer_add_clock(struct bt_ctf_writer *writer, struct bt_ctf_clock *clock);
1664 char *bt_ctf_writer_get_metadata_string(struct bt_ctf_writer *writer);
1665 void bt_ctf_writer_flush_metadata(struct bt_ctf_writer *writer);
1666 int bt_ctf_writer_set_byte_order(struct bt_ctf_writer *writer, enum bt_ctf_byte_order byte_order);
1667 void bt_ctf_writer_get(struct bt_ctf_writer *writer);
1668 void bt_ctf_writer_put(struct bt_ctf_writer *writer);
1672 from uuid import UUID
1676 # Used to compare to -1ULL in error checks
1677 _MAX_UINT64 = 0xFFFFFFFFFFFFFFFF
1680 Enumeration mapping class. start and end values are inclusive.
1682 class EnumerationMapping:
1684 def __init__(self, name, start, end):
1691 def __init__(self, name):
1692 self._c = _bt_ctf_clock_create(name)
1694 raise ValueError("Invalid clock name.")
1697 _bt_ctf_clock_put(self._c)
1700 Get the clock's name.
1704 name = _bt_ctf_clock_get_name(self._c)
1706 raise ValueError("Invalid clock instance.")
1710 Get the clock's description. None if unset.
1713 def description(self):
1714 return _bt_ctf_clock_get_description(self._c)
1717 Set the clock's description. The description appears in the clock's TSDL
1721 def description(self, desc):
1722 ret = _bt_ctf_clock_set_description(self._c, str(desc))
1724 raise ValueError("Invalid clock description.")
1727 Get the clock's frequency (Hz).
1730 def frequency(self):
1731 freq = _bt_ctf_clock_get_frequency(self._c)
1732 if freq == CTFWriter._MAX_UINT64:
1733 raise ValueError("Invalid clock instance")
1737 Set the clock's frequency (Hz).
1740 def frequency(self, freq):
1741 ret = _bt_ctf_clock_set_frequency(self._c, freq)
1743 raise ValueError("Invalid frequency value.")
1746 Get the clock's precision (in clock ticks).
1749 def precision(self):
1750 precision = _bt_ctf_clock_get_precision(self._c)
1751 if precision == CTFWriter._MAX_UINT64:
1752 raise ValueError("Invalid clock instance")
1756 Set the clock's precision (in clock ticks).
1759 def precision(self, precision):
1760 ret = _bt_ctf_clock_set_precision(self._c, precision)
1763 Get the clock's offset in seconds from POSIX.1 Epoch.
1766 def offset_seconds(self):
1767 offset_s = _bt_ctf_clock_get_offset_s(self._c)
1768 if offset_s == CTFWriter._MAX_UINT64:
1769 raise ValueError("Invalid clock instance")
1773 Set the clock's offset in seconds from POSIX.1 Epoch.
1775 @offset_seconds.setter
1776 def offset_seconds(self, offset_s):
1777 ret = _bt_ctf_clock_set_offset_s(self._c, offset_s)
1779 raise ValueError("Invalid offset value.")
1782 Get the clock's offset in ticks from POSIX.1 Epoch + offset in seconds.
1786 offset = _bt_ctf_clock_get_offset(self._c)
1787 if offset == CTFWriter._MAX_UINT64:
1788 raise ValueError("Invalid clock instance")
1792 Set the clock's offset in ticks from POSIX.1 Epoch + offset in seconds.
1795 def offset(self, offset):
1796 ret = _bt_ctf_clock_set_offset(self._c, offset)
1798 raise ValueError("Invalid offset value.")
1801 Get a clock's absolute attribute. A clock is absolute if the clock
1802 is a global reference across the trace's other clocks.
1806 is_absolute = _bt_ctf_clock_get_is_absolute(self._c)
1807 if is_absolute == -1:
1808 raise ValueError("Invalid clock instance")
1809 return False if is_absolute == 0 else True
1812 Set a clock's absolute attribute. A clock is absolute if the clock
1813 is a global reference across the trace's other clocks.
1816 def absolute(self, is_absolute):
1817 ret = _bt_ctf_clock_set_is_absolute(self._c, int(is_absolute))
1820 "Could not set the clock's absolute attribute.")
1823 Get a clock's UUID (an object of type UUID).
1829 ret, value = _bt_python_ctf_clock_get_uuid_index(self._c, i)
1831 raise ValueError("Invalid clock instance")
1832 uuid_list.append(value)
1833 return UUID(bytes=bytes(uuid_list))
1836 Set a clock's UUID (an object of type UUID).
1839 def uuid(self, uuid):
1840 uuid_bytes = uuid.bytes
1841 if len(uuid_bytes) != 16:
1843 "Invalid UUID provided. UUID length must be 16 bytes")
1844 for i in range(len(uuid_bytes)):
1845 ret = _bt_python_ctf_clock_set_uuid_index(
1850 raise ValueError("Invalid clock instance")
1853 Get the current time in nanoseconds since the clock's origin (offset and
1854 offset_s attributes).
1858 time = _bt_ctf_clock_get_time(self._c)
1859 if time == CTFWriter._MAX_UINT64:
1860 raise ValueError("Invalid clock instance")
1864 Set the current time in nanoseconds since the clock's origin (offset and
1865 offset_s attributes). The clock's value will be sampled as events are
1866 appended to a stream.
1869 def time(self, time):
1870 ret = _bt_ctf_clock_set_time(self._c, time)
1872 raise ValueError("Invalid time value.")
1874 class FieldDeclaration:
1877 FieldDeclaration should not be instantiated directly. Instantiate
1878 one of the concrete FieldDeclaration classes.
1881 # These values are based on the bt_ctf_integer_base enum
1882 # declared in event-types.h.
1883 INTEGER_BASE_UNKNOWN = -1
1884 INTEGER_BASE_BINARY = 2
1885 INTEGER_BASE_OCTAL = 8
1886 INTEGER_BASE_DECIMAL = 10
1887 INTEGER_BASE_HEXADECIMAL = 16
1890 if self._ft is None:
1891 raise ValueError("FieldDeclaration creation failed.")
1894 _bt_ctf_field_type_put(self._ft)
1897 def _create_field_declaration_from_native_instance(
1898 native_field_declaration):
1900 CTFTypeId.INTEGER: CTFWriter.IntegerFieldDeclaration,
1901 CTFTypeId.FLOAT: CTFWriter.FloatFieldDeclaration,
1902 CTFTypeId.ENUM: CTFWriter.EnumerationFieldDeclaration,
1903 CTFTypeId.STRING: CTFWriter.StringFieldDeclaration,
1904 CTFTypeId.STRUCT: CTFWriter.StructureFieldDeclaration,
1905 CTFTypeId.VARIANT: CTFWriter.VariantFieldDeclaration,
1906 CTFTypeId.ARRAY: CTFWriter.ArrayFieldDeclaration,
1907 CTFTypeId.SEQUENCE: CTFWriter.SequenceFieldDeclaration
1910 field_type_id = _bt_ctf_field_type_get_type_id(
1911 native_field_declaration)
1912 if field_type_id == CTFTypeId.UNKNOWN:
1913 raise TypeError("Invalid field instance")
1915 declaration = CTFWriter.Field.__new__(CTFWriter.Field)
1916 declaration._ft = native_field_declaration
1917 declaration.__class__ = type_dict[field_type_id]
1921 Get the field declaration's alignment. Returns -1 on error.
1924 def alignment(self):
1925 return _bt_ctf_field_type_get_alignment(self._ft)
1928 Set the field declaration's alignment. Defaults to 1 (bit-aligned). However,
1929 some types, such as structures and string, may impose other alignment
1933 def alignment(self, alignment):
1934 ret = _bt_ctf_field_type_set_alignment(self._ft, alignment)
1936 raise ValueError("Invalid alignment value.")
1939 Get the field declaration's byte order. One of the ByteOrder's constant.
1942 def byte_order(self):
1943 return _bt_ctf_field_type_get_byte_order(self._ft)
1946 Set the field declaration's byte order. Use constants defined in the ByteOrder
1950 def byte_order(self, byte_order):
1951 ret = _bt_ctf_field_type_set_byte_order(self._ft, byte_order)
1953 raise ValueError("Could not set byte order value.")
1955 class IntegerFieldDeclaration(FieldDeclaration):
1958 Create a new integer field declaration of the given size.
1961 def __init__(self, size):
1962 self._ft = _bt_ctf_field_type_integer_create(size)
1966 Get an integer's size.
1970 ret = _bt_ctf_field_type_integer_get_size(self._ft)
1972 raise ValueError("Could not get Integer's size attribute.")
1977 Get an integer's signedness attribute.
1981 ret = _bt_ctf_field_type_integer_get_signed(self._ft)
1983 raise ValueError("Could not get Integer's signed attribute.")
1990 Set an integer's signedness attribute.
1993 def signed(self, signed):
1994 ret = _bt_ctf_field_type_integer_set_signed(self._ft, signed)
1996 raise ValueError("Could not set Integer's signed attribute.")
1999 Get the integer's base used to pretty-print the resulting trace.
2000 Returns a constant from the FieldDeclaration.IntegerBase class.
2004 return _bt_ctf_field_type_integer_get_base(self._ft)
2007 Set the integer's base used to pretty-print the resulting trace.
2008 The base must be a constant of the FieldDeclarationIntegerBase class.
2011 def base(self, base):
2012 ret = _bt_ctf_field_type_integer_set_base(self._ft, base)
2014 raise ValueError("Could not set Integer's base.")
2017 Get the integer's encoding (one of the constants of the
2018 CTFStringEncoding class).
2019 Returns a constant from the CTFStringEncoding class.
2023 return _bt_ctf_field_type_integer_get_encoding(self._ft)
2026 An integer encoding may be set to signal that the integer must be printed
2027 as a text character. Must be a constant from the CTFStringEncoding class.
2030 def encoding(self, encoding):
2031 ret = _bt_ctf_field_type_integer_set_encoding(self._ft, encoding)
2033 raise ValueError("Could not set Integer's encoding.")
2035 class EnumerationFieldDeclaration(FieldDeclaration):
2038 Create a new enumeration field declaration with the given underlying container type.
2041 def __init__(self, integer_type):
2042 if integer_type is None or not isinstance(
2043 integer_type, CTFWriter.IntegerFieldDeclaration):
2044 raise TypeError("Invalid integer container.")
2046 self._ft = _bt_ctf_field_type_enumeration_create(integer_type._ft)
2050 Get the enumeration's underlying container type.
2053 def container(self):
2054 ret = _bt_ctf_field_type_enumeration_get_container_type(self._ft)
2056 raise TypeError("Invalid enumeration declaration")
2057 return CTFWriter.FieldDeclaration._create_field_declaration_from_native_instance(
2061 Add a mapping to the enumeration. The range's values are inclusive.
2064 def add_mapping(self, name, range_start, range_end):
2065 if range_start < 0 or range_end < 0:
2066 ret = _bt_ctf_field_type_enumeration_add_mapping(
2072 ret = _bt_ctf_field_type_enumeration_add_mapping_unsigned(
2080 "Could not add mapping to enumeration declaration.")
2083 Generator returning instances of EnumerationMapping.
2087 signed = self.container.signed
2089 count = _bt_ctf_field_type_enumeration_get_mapping_count(self._ft)
2090 for i in range(count):
2092 ret = _bt_python_ctf_field_type_enumeration_get_mapping(
2096 ret = _bt_python_ctf_field_type_enumeration_get_mapping_unsigned(
2102 "Could not get Enumeration mapping at index {}".format(i))
2103 name, range_start, range_end = ret
2104 yield CTFWriter.EnumerationMapping(name, range_start, range_end)
2107 Get a mapping by name (EnumerationMapping).
2110 def get_mapping_by_name(self, name):
2111 ret, index = _bt_ctf_field_type_enumeration_get_mapping_index_by_name(
2116 if self.container.signed:
2117 ret = _bt_python_ctf_field_type_enumeration_get_mapping(
2121 ret = _bt_python_ctf_field_type_enumeration_get_mapping_unsigned(
2127 "Could not get Enumeration mapping at index {}".format(i))
2128 name, range_start, range_end = ret
2129 return CTFWriter.EnumerationMapping(name, range_start, range_end)
2132 Get a mapping by value (EnumerationMapping).
2135 def get_mapping_by_value(self, value):
2137 ret, index = _bt_ctf_field_type_enumeration_get_mapping_index_by_value(
2140 ret, index = _bt_ctf_field_type_enumeration_get_mapping_index_by_unsigned_value(
2146 if self.container.signed:
2147 ret = _bt_python_ctf_field_type_enumeration_get_mapping(
2151 ret = _bt_python_ctf_field_type_enumeration_get_mapping_unsigned(
2157 "Could not get Enumeration mapping at index {}".format(i))
2158 name, range_start, range_end = ret
2159 return CTFWriter.EnumerationMapping(name, range_start, range_end)
2161 class FloatFieldDeclaration(FieldDeclaration):
2168 Create a new floating point field declaration.
2172 self._ft = _bt_ctf_field_type_floating_point_create()
2176 Get the number of exponent digits used to store the floating point field.
2179 def exponent_digits(self):
2180 ret = _bt_ctf_field_type_floating_point_get_exponent_digits(
2184 "Could not get Floating point exponent digit count")
2188 Set the number of exponent digits to use to store the floating point field.
2189 The only values currently supported are FLT_EXP_DIG and DBL_EXP_DIG which
2190 are defined as constants of this class.
2192 @exponent_digits.setter
2193 def exponent_digits(self, exponent_digits):
2194 ret = _bt_ctf_field_type_floating_point_set_exponent_digits(
2198 raise ValueError("Could not set exponent digit count.")
2201 Get the number of mantissa digits used to store the floating point field.
2204 def mantissa_digits(self):
2205 ret = _bt_ctf_field_type_floating_point_get_mantissa_digits(
2209 "Could not get Floating point mantissa digit count")
2213 Set the number of mantissa digits to use to store the floating point field.
2214 The only values currently supported are FLT_MANT_DIG and DBL_MANT_DIG which
2215 are defined as constants of this class.
2217 @mantissa_digits.setter
2218 def mantissa_digits(self, mantissa_digits):
2219 ret = _bt_ctf_field_type_floating_point_set_mantissa_digits(
2223 raise ValueError("Could not set mantissa digit count.")
2225 class StructureFieldDeclaration(FieldDeclaration):
2228 Create a new structure field declaration.
2232 self._ft = _bt_ctf_field_type_structure_create()
2236 Add a field of type "field_type" to the structure.
2239 def add_field(self, field_type, field_name):
2240 ret = _bt_ctf_field_type_structure_add_field(
2245 raise ValueError("Could not add field to structure.")
2248 Generator returning the structure's field as tuples of (field name, field declaration).
2252 count = _bt_ctf_field_type_structure_get_field_count(self._ft)
2254 raise TypeError("Could not get Structure field count")
2256 for i in range(count):
2257 field_name = _bt_python_ctf_field_type_structure_get_field_name(
2260 if field_name is None:
2262 "Could not get Structure field name at index {}".format(i))
2264 field_type_native = _bt_python_ctf_field_type_structure_get_field_type(
2267 if field_type_native is None:
2269 "Could not get Structure field type at index {}".format(i))
2271 field_type = CTFWriter.FieldDeclaration._create_field_declaration_from_native_instance(
2273 yield (field_name, field_type)
2276 Get a field declaration by name (FieldDeclaration).
2279 def get_field_by_name(self, name):
2280 field_type_native = _bt_ctf_field_type_structure_get_field_type_by_name(
2283 if field_type_native is None:
2285 "Could not find Structure field with name {}".format(name))
2287 return CTFWriter.FieldDeclaration._create_field_declaration_from_native_instance(
2290 class VariantFieldDeclaration(FieldDeclaration):
2293 Create a new variant field declaration.
2296 def __init__(self, enum_tag, tag_name):
2297 if enum_tag is None or not isinstance(
2298 enum_tag, CTFWriter.EnumerationFieldDeclaration):
2300 "Invalid tag type; must be of type EnumerationFieldDeclaration.")
2302 self._ft = _bt_ctf_field_type_variant_create(
2308 Get the variant's tag name.
2312 ret = _bt_ctf_field_type_variant_get_tag_name(self._ft)
2314 raise TypeError("Could not get Variant tag name")
2318 Get the variant's tag type.
2322 ret = _bt_ctf_field_type_variant_get_tag_type(self._ft)
2324 raise TypeError("Could not get Variant tag type")
2325 return CTFWriter.FieldDeclaration._create_field_declaration_from_native_instance(
2329 Add a field of type "field_type" to the variant.
2332 def add_field(self, field_type, field_name):
2333 ret = _bt_ctf_field_type_variant_add_field(
2338 raise ValueError("Could not add field to variant.")
2341 Generator returning the variant's field as tuples of (field name, field declaration).
2345 count = _bt_ctf_field_type_variant_get_field_count(self._ft)
2347 raise TypeError("Could not get Variant field count")
2349 for i in range(count):
2350 field_name = _bt_python_ctf_field_type_variant_get_field_name(
2353 if field_name is None:
2355 "Could not get Variant field name at index {}".format(i))
2357 field_type_native = _bt_python_ctf_field_type_variant_get_field_type(
2360 if field_type_native is None:
2362 "Could not get Variant field type at index {}".format(i))
2364 field_type = CTFWriter.FieldDeclaration._create_field_declaration_from_native_instance(
2366 yield (field_name, field_type)
2369 Get a field declaration by name (FieldDeclaration).
2372 def get_field_by_name(self, name):
2373 field_type_native = _bt_ctf_field_type_variant_get_field_type_by_name(
2376 if field_type_native is None:
2378 "Could not find Variant field with name {}".format(name))
2380 return CTFWriter.FieldDeclaration._create_field_declaration_from_native_instance(
2384 Get a field declaration from tag (EnumerationField).
2387 def get_field_from_tag(self, tag):
2388 field_type_native = _bt_ctf_field_type_variant_get_field_type_from_tag(
2391 if field_type_native is None:
2393 "Could not find Variant field with tag value {}".format(
2396 return CTFWriter.FieldDeclaration._create_field_declaration_from_native_instance(
2399 class ArrayFieldDeclaration(FieldDeclaration):
2402 Create a new array field declaration.
2405 def __init__(self, element_type, length):
2406 self._ft = _bt_ctf_field_type_array_create(
2412 Get the array's element type.
2415 def element_type(self):
2416 ret = _bt_ctf_field_type_array_get_element_type(self._ft)
2418 raise TypeError("Could not get Array element type")
2419 return CTFWriter.FieldDeclaration._create_field_declaration_from_native_instance(
2423 Get the array's length.
2427 ret = _bt_ctf_field_type_array_get_length(self._ft)
2429 raise TypeError("Could not get Array length")
2432 class SequenceFieldDeclaration(FieldDeclaration):
2435 Create a new sequence field declaration.
2438 def __init__(self, element_type, length_field_name):
2439 self._ft = _bt_ctf_field_type_sequence_create(
2441 str(length_field_name))
2445 Get the sequence's element type.
2448 def element_type(self):
2449 ret = _bt_ctf_field_type_sequence_get_element_type(self._ft)
2451 raise TypeError("Could not get Sequence element type")
2452 return CTFWriter.FieldDeclaration._create_field_declaration_from_native_instance(
2456 Get the sequence's length field name.
2459 def length_field_name(self):
2460 ret = _bt_ctf_field_type_sequence_get_length_field_name(self._ft)
2462 raise TypeError("Could not get Sequence length field name")
2465 class StringFieldDeclaration(FieldDeclaration):
2468 Create a new string field declaration.
2472 self._ft = _bt_ctf_field_type_string_create()
2476 Get a string declaration's encoding (a constant from the CTFStringEncoding class).
2480 return _bt_ctf_field_type_string_get_encoding(self._ft)
2483 Set a string declaration's encoding. Must be a constant from the CTFStringEncoding class.
2486 def encoding(self, encoding):
2487 ret = _bt_ctf_field_type_string_set_encoding(self._ft, encoding)
2489 raise ValueError("Could not set string encoding.")
2492 Create an instance of a field.
2495 def create_field(field_type):
2496 if field_type is None or not isinstance(
2497 field_type, CTFWriter.FieldDeclaration):
2499 "Invalid field_type. Type must be a FieldDeclaration-derived class.")
2501 if isinstance(field_type, CTFWriter.IntegerFieldDeclaration):
2502 return CTFWriter.IntegerField(field_type)
2503 elif isinstance(field_type, CTFWriter.EnumerationFieldDeclaration):
2504 return CTFWriter.EnumerationField(field_type)
2505 elif isinstance(field_type, CTFWriter.FloatFieldDeclaration):
2506 return CTFWriter.FloatFieldingPoint(field_type)
2507 elif isinstance(field_type, CTFWriter.StructureFieldDeclaration):
2508 return CTFWriter.StructureField(field_type)
2509 elif isinstance(field_type, CTFWriter.VariantFieldDeclaration):
2510 return CTFWriter.VariantField(field_type)
2511 elif isinstance(field_type, CTFWriter.ArrayFieldDeclaration):
2512 return CTFWriter.ArrayField(field_type)
2513 elif isinstance(field_type, CTFWriter.SequenceFieldDeclaration):
2514 return CTFWriter.SequenceField(field_type)
2515 elif isinstance(field_type, CTFWriter.StringFieldDeclaration):
2516 return CTFWriter.StringField(field_type)
2521 Base class, do not instantiate.
2524 def __init__(self, field_type):
2525 if not isinstance(field_type, CTFWriter.FieldDeclaration):
2526 raise TypeError("Invalid field_type argument.")
2528 self._f = _bt_ctf_field_create(field_type._ft)
2530 raise ValueError("Field creation failed.")
2533 _bt_ctf_field_put(self._f)
2536 def _create_field_from_native_instance(native_field_instance):
2538 CTFTypeId.INTEGER: CTFWriter.IntegerField,
2539 CTFTypeId.FLOAT: CTFWriter.FloatFieldingPoint,
2540 CTFTypeId.ENUM: CTFWriter.EnumerationField,
2541 CTFTypeId.STRING: CTFWriter.StringField,
2542 CTFTypeId.STRUCT: CTFWriter.StructureField,
2543 CTFTypeId.VARIANT: CTFWriter.VariantField,
2544 CTFTypeId.ARRAY: CTFWriter.ArrayField,
2545 CTFTypeId.SEQUENCE: CTFWriter.SequenceField
2548 field_type = _bt_python_get_field_type(native_field_instance)
2549 if field_type == CTFTypeId.UNKNOWN:
2550 raise TypeError("Invalid field instance")
2552 field = CTFWriter.Field.__new__(CTFWriter.Field)
2553 field._f = native_field_instance
2554 field.__class__ = type_dict[field_type]
2558 def declaration(self):
2559 native_field_type = _bt_ctf_field_get_type(self._f)
2560 if native_field_type is None:
2561 raise TypeError("Invalid field instance")
2562 return CTFWriter.FieldDeclaration._create_field_declaration_from_native_instance(
2565 class IntegerField(Field):
2568 Get an integer field's value.
2572 signedness = _bt_python_field_integer_get_signedness(self._f)
2574 raise TypeError("Invalid integer instance.")
2577 ret, value = _bt_ctf_field_unsigned_integer_get_value(self._f)
2579 ret, value = _bt_ctf_field_signed_integer_get_value(self._f)
2582 raise ValueError("Could not get integer field value.")
2586 Set an integer field's value.
2589 def value(self, value):
2590 if not isinstance(value, int):
2591 raise TypeError("IntegerField's value must be an int")
2593 signedness = _bt_python_field_integer_get_signedness(self._f)
2595 raise TypeError("Invalid integer instance.")
2598 ret = _bt_ctf_field_unsigned_integer_set_value(self._f, value)
2600 ret = _bt_ctf_field_signed_integer_set_value(self._f, value)
2603 raise ValueError("Could not set integer field value.")
2605 class EnumerationField(Field):
2608 Return the enumeration's underlying container field (an integer field).
2611 def container(self):
2612 container = CTFWriter.IntegerField.__new__(CTFWriter.IntegerField)
2613 container._f = _bt_ctf_field_enumeration_get_container(self._f)
2614 if container._f is None:
2615 raise TypeError("Invalid enumeration field type.")
2619 Get the enumeration field's mapping name.
2623 value = _bt_ctf_field_enumeration_get_mapping_name(self._f)
2625 raise ValueError("Could not get enumeration's mapping name.")
2629 Set the enumeration field's value. Must be an integer as mapping names
2633 def value(self, value):
2634 if not isinstance(value, int):
2635 raise TypeError("EnumerationField value must be an int")
2636 self.container.value = value
2638 class FloatFieldingPoint(Field):
2641 Get a floating point field's value.
2645 ret, value = _bt_ctf_field_floating_point_get_value(self._f)
2647 raise ValueError("Could not get floating point field value.")
2651 Set a floating point field's value.
2654 def value(self, value):
2655 if not isinstance(value, int) and not isinstance(value, float):
2656 raise TypeError("Value must be either a float or an int")
2658 ret = _bt_ctf_field_floating_point_set_value(self._f, float(value))
2660 raise ValueError("Could not set floating point field value.")
2662 class StructureField(Field):
2665 Get the structure's field corresponding to the provided field name.
2668 def field(self, field_name):
2669 native_instance = _bt_ctf_field_structure_get_field(
2672 if native_instance is None:
2673 raise ValueError("Invalid field_name provided.")
2674 return CTFWriter.Field._create_field_from_native_instance(
2677 class VariantField(Field):
2680 Return the variant's selected field. The "tag" field is the selector enum field.
2683 def field(self, tag):
2684 native_instance = _bt_ctf_field_variant_get_field(self._f, tag._f)
2685 if native_instance is None:
2686 raise ValueError("Invalid tag provided.")
2687 return CTFWriter.Field._create_field_from_native_instance(
2690 class ArrayField(Field):
2693 Return the array's field at position "index".
2696 def field(self, index):
2697 native_instance = _bt_ctf_field_array_get_field(self._f, index)
2698 if native_instance is None:
2699 raise IndexError("Invalid index provided.")
2700 return CTFWriter.Field._create_field_from_native_instance(
2703 class SequenceField(Field):
2706 Get the sequence's length field (IntegerField).
2710 native_instance = _bt_ctf_field_sequence_get_length(self._f)
2711 if native_instance is None:
2713 return CTFWriter.Field._create_field_from_native_instance(
2717 Set the sequence's length field (IntegerField).
2720 def length(self, length_field):
2721 if not isinstance(length_field, CTFWriter.IntegerField):
2722 raise TypeError("Invalid length field.")
2723 if length_field.declaration.signed:
2724 raise TypeError("Sequence field length must be unsigned")
2725 ret = _bt_ctf_field_sequence_set_length(self._f, length_field._f)
2727 raise ValueError("Could not set sequence length.")
2730 Return the sequence's field at position "index".
2733 def field(self, index):
2734 native_instance = _bt_ctf_field_sequence_get_field(self._f, index)
2735 if native_instance is None:
2736 raise ValueError("Could not get sequence element at index.")
2737 return CTFWriter.Field._create_field_from_native_instance(
2740 class StringField(Field):
2743 Get a string field's value.
2747 return _bt_ctf_field_string_get_value(self._f)
2750 Set a string field's value.
2753 def value(self, value):
2754 ret = _bt_ctf_field_string_set_value(self._f, str(value))
2756 raise ValueError("Could not set string field value.")
2761 Create a new event class of the given name.
2764 def __init__(self, name):
2765 self._ec = _bt_ctf_event_class_create(name)
2766 if self._ec is None:
2767 raise ValueError("Event class creation failed.")
2770 _bt_ctf_event_class_put(self._ec)
2773 Add a field of type "field_type" to the event class.
2776 def add_field(self, field_type, field_name):
2777 ret = _bt_ctf_event_class_add_field(
2782 raise ValueError("Could not add field to event class.")
2785 Get the event class' name.
2789 name = _bt_ctf_event_class_get_name(self._ec)
2791 raise TypeError("Could not get EventClass name")
2795 Get the event class' id. Returns a negative value if unset.
2799 id = _bt_ctf_event_class_get_id(self._ec)
2801 raise TypeError("Could not get EventClass id")
2805 Set the event class' id. Throws a TypeError if the event class
2806 is already registered to a stream class.
2810 ret = _bt_ctf_event_class_set_id(self._ec, id)
2813 "Can't change an Event Class's id after it has been assigned to a stream class")
2816 Get the event class' stream class. Returns None if unset.
2819 def stream_class(self):
2820 stream_class_native = _bt_ctf_event_class_get_stream_class(
2822 if stream_class_native is None:
2824 stream_class = CTFWriter.StreamClass.__new__(CTFWriter.StreamClass)
2825 stream_class._sc = stream_class_native
2829 Generator returning the event class' fields as tuples of (field name, field declaration).
2833 count = _bt_ctf_event_class_get_field_count(self._ec)
2835 raise TypeError("Could not get EventClass' field count")
2837 for i in range(count):
2838 field_name = _bt_python_ctf_event_class_get_field_name(
2841 if field_name is None:
2843 "Could not get EventClass' field name at index {}".format(i))
2845 field_type_native = _bt_python_ctf_event_class_get_field_type(
2848 if field_type_native is None:
2850 "Could not get EventClass' field type at index {}".format(i))
2852 field_type = CTFWriter.FieldDeclaration._create_field_declaration_from_native_instance(
2854 yield (field_name, field_type)
2857 Get a field declaration by name (FieldDeclaration).
2860 def get_field_by_name(self, name):
2861 field_type_native = _bt_ctf_event_class_get_field_by_name(
2864 if field_type_native is None:
2866 "Could not find EventClass field with name {}".format(name))
2867 return CTFWriter.FieldDeclaration._create_field_declaration_from_native_instance(
2873 Create a new event of the given event class.
2876 def __init__(self, event_class):
2877 if not isinstance(event_class, CTFWriter.EventClass):
2878 raise TypeError("Invalid event_class argument.")
2880 self._e = _bt_ctf_event_create(event_class._ec)
2882 raise ValueError("Event creation failed.")
2885 _bt_ctf_event_put(self._e)
2888 Get the event's class.
2891 def event_class(self):
2892 event_class_native = _bt_ctf_event_get_class(self._e)
2893 if event_class_native is None:
2895 event_class = CTFWriter.EventClass.__new__(CTFWriter.EventClass)
2896 event_class._ec = event_class_native
2900 Get a clock from event. Returns None if the event's class
2901 is not registered to a stream class.
2905 clock_instance = _bt_ctf_event_get_clock(self._e)
2906 if clock_instance is None:
2908 clock = CTFWriter.Clock.__new__(CTFWriter.Clock)
2909 clock._c = clock_instance
2913 Get a field from event.
2916 def payload(self, field_name):
2917 native_instance = _bt_ctf_event_get_payload(
2920 if native_instance is None:
2921 raise ValueError("Could not get event payload.")
2922 return CTFWriter.Field._create_field_from_native_instance(
2926 Set a manually created field as an event's payload.
2929 def set_payload(self, field_name, value_field):
2930 if not isinstance(value, CTFWriter.Field):
2931 raise TypeError("Invalid value type.")
2932 ret = _bt_ctf_event_set_payload(
2937 raise ValueError("Could not set event field payload.")
2942 Create a new stream class of the given name.
2945 def __init__(self, name):
2946 self._sc = _bt_ctf_stream_class_create(name)
2947 if self._sc is None:
2948 raise ValueError("Stream class creation failed.")
2951 _bt_ctf_stream_class_put(self._sc)
2954 Get a stream class' name.
2958 name = _bt_ctf_stream_class_get_name(self._sc)
2960 raise TypeError("Could not get StreamClass name")
2964 Get a stream class' clock.
2968 clock_instance = _bt_ctf_stream_class_get_clock(self._sc)
2969 if clock_instance is None:
2971 clock = CTFWriter.Clock.__new__(CTFWriter.Clock)
2972 clock._c = clock_instance
2976 Assign a clock to a stream class.
2979 def clock(self, clock):
2980 if not isinstance(clock, CTFWriter.Clock):
2981 raise TypeError("Invalid clock type.")
2983 ret = _bt_ctf_stream_class_set_clock(self._sc, clock._c)
2985 raise ValueError("Could not set stream class clock.")
2988 Get a stream class' id.
2992 ret = _bt_ctf_stream_class_get_id(self._sc)
2994 raise TypeError("Could not get StreamClass id")
2998 Assign an id to a stream class.
3002 ret = _bt_ctf_stream_class_set_id(self._sc, id)
3004 raise TypeError("Could not set stream class id.")
3007 Generator returning the stream class' event classes.
3010 def event_classes(self):
3011 count = _bt_ctf_stream_class_get_event_class_count(self._sc)
3013 raise TypeError("Could not get StreamClass' event class count")
3015 for i in range(count):
3016 event_class_native = _bt_ctf_stream_class_get_event_class(
3019 if event_class_native is None:
3021 "Could not get StreamClass' event class at index {}".format(i))
3023 event_class = CTFWriter.EventClass.__new__(
3024 CTFWriter.EventClass)
3025 event_class._ec = event_class_native
3029 Add an event class to a stream class. New events can be added even after a
3030 stream has been instantiated and events have been appended. However, a stream
3031 will not accept events of a class that has not been added to the stream
3035 def add_event_class(self, event_class):
3036 if not isinstance(event_class, CTFWriter.EventClass):
3037 raise TypeError("Invalid event_class type.")
3039 ret = _bt_ctf_stream_class_add_event_class(
3043 raise ValueError("Could not add event class.")
3046 Get the StreamClass' packet context type (StructureFieldDeclaration)
3049 def packet_context_type(self):
3050 field_type_native = _bt_ctf_stream_class_get_packet_context_type(
3052 if field_type_native is None:
3053 raise ValueError("Invalid StreamClass")
3054 field_type = CTFWriter.FieldDeclaration._create_field_declaration_from_native_instance(
3059 Set a StreamClass' packet context type. Must be of type
3060 StructureFieldDeclaration.
3062 @packet_context_type.setter
3063 def packet_context_type(self, field_type):
3064 if not isinstance(field_type, CTFWriter.StructureFieldDeclaration):
3066 "field_type argument must be of type StructureFieldDeclaration.")
3067 ret = _bt_ctf_stream_class_set_packet_context_type(
3071 raise ValueError("Failed to set packet context type.")
3076 Create a stream of the given class.
3079 def __init__(self, stream_class):
3080 if not isinstance(stream_class, CTFWriter.StreamClass):
3082 "Invalid stream_class argument must be of type StreamClass.")
3084 self._s = _bt_ctf_stream_create(stream_class._sc)
3086 raise ValueError("Stream creation failed.")
3089 _bt_ctf_stream_put(self._s)
3092 Get a stream's discarded event count.
3095 def discarded_events(self):
3096 ret, count = _bt_ctf_stream_get_discarded_events_count(self._s)
3099 "Could not get the stream's discarded events count")
3103 Increase the current packet's discarded event count.
3106 def append_discarded_events(self, event_count):
3107 _bt_ctf_stream_append_discarded_events(self._s, event_count)
3110 Append "event" to the stream's current packet. The stream's associated clock
3111 will be sampled during this call. The event shall not be modified after
3112 being appended to a stream.
3115 def append_event(self, event):
3116 ret = _bt_ctf_stream_append_event(self._s, event._e)
3118 raise ValueError("Could not append event to stream.")
3121 Get a Stream's packet context field (a StructureField).
3124 def packet_context(self):
3125 native_field = _bt_ctf_stream_get_packet_context(self._s)
3126 if native_field is None:
3127 raise ValueError("Invalid Stream.")
3128 return CTFWriter.Field._create_field_from_native_instance(
3132 Set a Stream's packet context field (must be a StructureField).
3134 @packet_context.setter
3135 def packet_context(self, field):
3136 if not isinstance(field, CTFWriter.StructureField):
3138 "Argument field must be of type StructureField")
3139 ret = _bt_ctf_stream_set_packet_context(self._s, field._f)
3141 raise ValueError("Invalid packet context field.")
3144 The stream's current packet's events will be flushed to disk. Events
3145 subsequently appended to the stream will be added to a new packet.
3149 ret = _bt_ctf_stream_flush(self._s)
3151 raise ValueError("Could not flush stream.")
3156 Create a new writer that will produce a trace in the given path.
3159 def __init__(self, path):
3160 self._w = _bt_ctf_writer_create(path)
3162 raise ValueError("Writer creation failed.")
3165 _bt_ctf_writer_put(self._w)
3168 Create a new stream instance and register it to the writer.
3171 def create_stream(self, stream_class):
3172 if not isinstance(stream_class, CTFWriter.StreamClass):
3173 raise TypeError("Invalid stream_class type.")
3175 stream = CTFWriter.Stream.__new__(CTFWriter.Stream)
3176 stream._s = _bt_ctf_writer_create_stream(self._w, stream_class._sc)
3180 Add an environment field to the trace.
3183 def add_environment_field(self, name, value):
3184 ret = _bt_ctf_writer_add_environment_field(
3189 raise ValueError("Could not add environment field to trace.")
3192 Add a clock to the trace. Clocks assigned to stream classes must be
3193 registered to the writer.
3196 def add_clock(self, clock):
3197 ret = _bt_ctf_writer_add_clock(self._w, clock._c)
3199 raise ValueError("Could not add clock to Writer.")
3202 Get the trace's TSDL meta-data.
3206 return _bt_ctf_writer_get_metadata_string(self._w)
3209 Flush the trace's metadata to the metadata file.
3212 def flush_metadata(self):
3213 _bt_ctf_writer_flush_metadata(self._w)
3216 Get the trace's byte order. Must be a constant from the ByteOrder
3220 def byte_order(self):
3221 raise NotImplementedError("Getter not implemented.")
3224 Set the trace's byte order. Must be a constant from the ByteOrder
3225 class. Defaults to BYTE_ORDER_NATIVE, the host machine's endianness.
3228 def byte_order(self, byte_order):
3229 ret = _bt_ctf_writer_set_byte_order(self._w, byte_order)
3231 raise ValueError("Could not set trace's byte order.")