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.
21 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
22 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
23 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
24 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
25 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
26 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
32 "BABELTRACE_VERSION_STR
34 Babeltrace is a trace viewer and converter reading and writing the
35 Common Trace Format (CTF). Its main use is to pretty-print CTF
36 traces into a human-readable text output.
38 To use this module, the first step is to create a TraceCollection and add a
42 %module(docstring=DOCSTRING) babeltrace
47 #define SWIG_FILE_WITH_INIT
48 #include <babeltrace/babeltrace.h>
49 #include <babeltrace/babeltrace-internal.h>
50 #include <babeltrace/trace-handle.h>
51 #include <babeltrace/trace-handle-internal.h>
52 #include <babeltrace/context.h>
53 #include <babeltrace/context-internal.h>
54 #include <babeltrace/iterator.h>
55 #include <babeltrace/iterator-internal.h>
56 #include <babeltrace/format.h>
57 #include <babeltrace/list.h>
58 #include <babeltrace/types.h>
59 #include <babeltrace/ctf/iterator.h>
60 #include "python-complements.h"
61 #include <babeltrace/ctf-writer/clock.h>
62 #include <babeltrace/ctf-writer/event-fields.h>
63 #include <babeltrace/ctf-writer/event-types.h>
64 #include <babeltrace/ctf-writer/event.h>
65 #include <babeltrace/ctf-writer/stream.h>
66 #include <babeltrace/ctf-writer/writer.h>
69 typedef int bt_intern_str;
70 typedef int64_t ssize_t;
72 /* python-complements.h */
73 struct bt_definition **_bt_python_field_listcaller(
74 const struct bt_ctf_event *ctf_event,
75 const struct bt_definition *scope,
76 unsigned int *OUTPUT);
77 struct bt_definition *_bt_python_field_one_from_list(
78 struct bt_definition **list, int index);
79 struct bt_ctf_event_decl **_bt_python_event_decl_listcaller(
81 struct bt_context *ctx,
82 unsigned int *OUTPUT);
83 struct bt_ctf_event_decl *_bt_python_decl_one_from_list(
84 struct bt_ctf_event_decl **list, int index);
85 struct bt_ctf_field_decl **_by_python_field_decl_listcaller(
86 struct bt_ctf_event_decl *event_decl,
87 enum bt_ctf_scope scope,
88 unsigned int *OUTPUT);
89 struct bt_ctf_field_decl *_bt_python_field_decl_one_from_list(
90 struct bt_ctf_field_decl **list, int index);
91 struct definition_array *_bt_python_get_array_from_def(
92 struct bt_definition *field);
93 struct definition_sequence *_bt_python_get_sequence_from_def(
94 struct bt_definition *field);
95 struct bt_declaration *_bt_python_get_array_element_declaration(
96 struct bt_declaration *field);
97 struct bt_declaration *_bt_python_get_sequence_element_declaration(
98 struct bt_declaration *field);
99 const char *_bt_python_get_array_string(struct bt_definition *field);
100 const char *_bt_python_get_sequence_string(struct bt_definition *field);
101 int _bt_python_field_integer_get_signedness(const struct bt_ctf_field *field);
102 enum ctf_type_id _bt_python_get_field_type(const struct bt_ctf_field *field);
103 const char *_bt_python_ctf_field_type_enumeration_get_mapping(
104 struct bt_ctf_field_type *enumeration, size_t index,
105 int64_t *OUTPUT, int64_t *OUTPUT);
106 const char *_bt_python_ctf_field_type_enumeration_get_mapping_unsigned(
107 struct bt_ctf_field_type *enumeration, size_t index,
108 uint64_t *OUTPUT, uint64_t *OUTPUT);
109 const char *_bt_python_ctf_field_type_structure_get_field_name(
110 struct bt_ctf_field_type *structure, size_t index);
111 struct bt_ctf_field_type *_bt_python_ctf_field_type_structure_get_field_type(
112 struct bt_ctf_field_type *structure, size_t index);
113 const char *_bt_python_ctf_field_type_variant_get_field_name(
114 struct bt_ctf_field_type *variant, size_t index);
115 struct bt_ctf_field_type *_bt_python_ctf_field_type_variant_get_field_type(
116 struct bt_ctf_field_type *variant, size_t index);
117 const char *_bt_python_ctf_event_class_get_field_name(
118 struct bt_ctf_event_class *event_class, size_t index);
119 struct bt_ctf_field_type *_bt_python_ctf_event_class_get_field_type(
120 struct bt_ctf_event_class *event_class, size_t index);
121 int _bt_python_ctf_clock_get_uuid_index(struct bt_ctf_clock *clock,
122 size_t index, unsigned char *OUTPUT);
123 int _bt_python_ctf_clock_set_uuid_index(struct bt_ctf_clock *clock,
124 size_t index, unsigned char value);
126 /* context.h, context-internal.h */
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)
325 %rename("lookup_format") bt_lookup_format(bt_intern_str qname);
326 %rename("_bt_print_format_list") bt_fprintf_format_list(FILE *fp);
327 %rename("register_format") bt_register_format(struct format *format);
328 %rename("unregister_format") bt_unregister_format(struct bt_format *format);
330 extern struct format *bt_lookup_format(bt_intern_str qname);
331 extern void bt_fprintf_format_list(FILE *fp);
332 extern int bt_register_format(struct bt_format *format);
333 extern void bt_unregister_format(struct bt_format *format);
337 def print_format_list(babeltrace_file):
339 Print a list of available formats to file.
341 babeltrace_file must be a File instance opened in write mode.
344 if babeltrace_file._file is not None:
345 _bt_print_format_list(babeltrace_file._file)
346 except AttributeError:
347 raise TypeError("in print_format_list, "
348 "argument 1 must be a File instance")
352 /* iterator.h, iterator-internal.h */
353 %rename("_bt_iter_create") bt_iter_create(struct bt_context *ctx,
354 const struct bt_iter_pos *begin_pos, const struct bt_iter_pos *end_pos);
355 %rename("_bt_iter_destroy") bt_iter_destroy(struct bt_iter *iter);
356 %rename("_bt_iter_next") bt_iter_next(struct bt_iter *iter);
357 %rename("_bt_iter_get_pos") bt_iter_get_pos(struct bt_iter *iter);
358 %rename("_bt_iter_free_pos") bt_iter_free_pos(struct bt_iter_pos *pos);
359 %rename("_bt_iter_set_pos") bt_iter_set_pos(struct bt_iter *iter,
360 const struct bt_iter_pos *pos);
361 %rename("_bt_iter_create_time_pos") bt_iter_create_time_pos(struct bt_iter *iter,
364 struct bt_iter *bt_iter_create(struct bt_context *ctx,
365 const struct bt_iter_pos *begin_pos, const struct bt_iter_pos *end_pos);
366 void bt_iter_destroy(struct bt_iter *iter);
367 int bt_iter_next(struct bt_iter *iter);
368 struct bt_iter_pos *bt_iter_get_pos(struct bt_iter *iter);
369 void bt_iter_free_pos(struct bt_iter_pos *pos);
370 int bt_iter_set_pos(struct bt_iter *iter, const struct bt_iter_pos *pos);
371 struct bt_iter_pos *bt_iter_create_time_pos(struct bt_iter *iter, uint64_t timestamp);
373 %rename("_bt_iter_pos") bt_iter_pos;
374 %rename("SEEK_TIME") BT_SEEK_TIME;
375 %rename("SEEK_RESTORE") BT_SEEK_RESTORE;
376 %rename("SEEK_CUR") BT_SEEK_CUR;
377 %rename("SEEK_BEGIN") BT_SEEK_BEGIN;
378 %rename("SEEK_LAST") BT_SEEK_LAST;
381 * This struct is taken from iterator.h
382 * All changes to the struct must also be made here.
386 BT_SEEK_TIME, /* uses u.seek_time */
387 BT_SEEK_RESTORE, /* uses u.restore */
394 struct bt_saved_pos *restore;
398 /* trace-handle.h, trace-handle-internal.h */
399 %rename("_bt_trace_handle_create") bt_trace_handle_create(struct bt_context *ctx);
400 %rename("_bt_trace_handle_destroy") bt_trace_handle_destroy(struct bt_trace_handle *bt);
401 struct bt_trace_handle *bt_trace_handle_create(struct bt_context *ctx);
402 void bt_trace_handle_destroy(struct bt_trace_handle *bt);
404 %rename("_bt_trace_handle_get_path") bt_trace_handle_get_path(struct bt_context *ctx,
406 %rename("_bt_trace_handle_get_timestamp_begin") bt_trace_handle_get_timestamp_begin(
407 struct bt_context *ctx, int handle_id, enum bt_clock_type type);
408 %rename("_bt_trace_handle_get_timestamp_end") bt_trace_handle_get_timestamp_end(
409 struct bt_context *ctx, int handle_id, enum bt_clock_type type);
410 const char *bt_trace_handle_get_path(struct bt_context *ctx, int handle_id);
411 uint64_t bt_trace_handle_get_timestamp_begin(struct bt_context *ctx, int handle_id,
412 enum bt_clock_type type);
413 uint64_t bt_trace_handle_get_timestamp_end(struct bt_context *ctx, int handle_id,
414 enum bt_clock_type type);
416 %rename("_bt_ctf_event_get_handle_id") bt_ctf_event_get_handle_id(
417 const struct bt_ctf_event *event);
418 int bt_ctf_event_get_handle_id(const struct bt_ctf_event *event);
423 # Based on enum bt_clock_type in clock-type.h
429 class TraceHandle(object):
432 The TraceHandle allows the user to manipulate a trace file directly.
433 It is a unique identifier representing a trace file.
438 raise NotImplementedError("TraceHandle cannot be instantiated")
441 return "Babeltrace TraceHandle: trace_id('{0}')".format(self._id)
445 """Return the TraceHandle id."""
450 """Return the path of a TraceHandle."""
451 return _bt_trace_handle_get_path(self._trace_collection._tc, self._id)
454 def timestamp_begin(self):
455 """Return the creation time of the buffers of a trace."""
456 return _bt_trace_handle_get_timestamp_begin(
457 self._trace_collection._tc, self._id, ClockType.CLOCK_REAL)
460 def timestamp_end(self):
461 """Return the destruction timestamp of the buffers of a trace."""
462 return _bt_trace_handle_get_timestamp_end(
463 self._trace_collection._tc, self._id, ClockType.CLOCK_REAL)
468 Generator returning all events (EventDeclaration) in a trace.
470 ret = _bt_python_event_decl_listcaller(
472 self._trace_collection._tc)
474 if not isinstance(ret, list):
477 ptr_list, count = ret
478 for i in range(count):
479 tmp = EventDeclaration.__new__(EventDeclaration)
480 tmp._ed = _bt_python_decl_one_from_list(ptr_list, i)
485 /* iterator.h, events.h */
486 %rename("_bt_ctf_iter_create") bt_ctf_iter_create(struct bt_context *ctx,
487 const struct bt_iter_pos *begin_pos,
488 const struct bt_iter_pos *end_pos);
489 %rename("_bt_ctf_get_iter") bt_ctf_get_iter(struct bt_ctf_iter *iter);
490 %rename("_bt_ctf_iter_destroy") bt_ctf_iter_destroy(struct bt_ctf_iter *iter);
491 %rename("_bt_ctf_iter_read_event") bt_ctf_iter_read_event(struct bt_ctf_iter *iter);
493 struct bt_ctf_iter *bt_ctf_iter_create(struct bt_context *ctx,
494 const struct bt_iter_pos *begin_pos,
495 const struct bt_iter_pos *end_pos);
496 struct bt_iter *bt_ctf_get_iter(struct bt_ctf_iter *iter);
497 void bt_ctf_iter_destroy(struct bt_ctf_iter *iter);
498 struct bt_ctf_event *bt_ctf_iter_read_event(struct bt_ctf_iter *iter);
502 %rename("_bt_ctf_get_top_level_scope") bt_ctf_get_top_level_scope(const struct
503 bt_ctf_event *event, enum bt_ctf_scope scope);
504 %rename("_bt_ctf_event_name") bt_ctf_event_name(const struct bt_ctf_event *ctf_event);
505 %rename("_bt_ctf_get_timestamp") bt_ctf_get_timestamp(
506 const struct bt_ctf_event *ctf_event);
507 %rename("_bt_ctf_get_cycles") bt_ctf_get_cycles(
508 const struct bt_ctf_event *ctf_event);
510 %rename("_bt_ctf_get_field") bt_ctf_get_field(const struct bt_ctf_event *ctf_event,
511 const struct bt_definition *scope, const char *field);
512 %rename("_bt_ctf_get_index") bt_ctf_get_index(const struct bt_ctf_event *ctf_event,
513 const struct bt_definition *field, unsigned int index);
514 %rename("_bt_ctf_field_name") bt_ctf_field_name(const struct bt_definition *field);
515 %rename("_bt_ctf_field_type") bt_ctf_field_type(const struct bt_declaration *field);
516 %rename("_bt_ctf_get_int_signedness") bt_ctf_get_int_signedness(
517 const struct bt_declaration *field);
518 %rename("_bt_ctf_get_int_base") bt_ctf_get_int_base(const struct bt_declaration *field);
519 %rename("_bt_ctf_get_int_byte_order") bt_ctf_get_int_byte_order(
520 const struct bt_declaration *field);
521 %rename("_bt_ctf_get_int_len") bt_ctf_get_int_len(const struct bt_declaration *field);
522 %rename("_bt_ctf_get_enum_int") bt_ctf_get_enum_int(const struct bt_definition *field);
523 %rename("_bt_ctf_get_enum_str") bt_ctf_get_enum_str(const struct bt_definition *field);
524 %rename("_bt_ctf_get_encoding") bt_ctf_get_encoding(const struct bt_declaration *field);
525 %rename("_bt_ctf_get_array_len") bt_ctf_get_array_len(const struct bt_declaration *field);
526 %rename("_bt_ctf_get_uint64") bt_ctf_get_uint64(const struct bt_definition *field);
527 %rename("_bt_ctf_get_int64") bt_ctf_get_int64(const struct bt_definition *field);
528 %rename("_bt_ctf_get_char_array") bt_ctf_get_char_array(const struct bt_definition *field);
529 %rename("_bt_ctf_get_string") bt_ctf_get_string(const struct bt_definition *field);
530 %rename("_bt_ctf_get_float") bt_ctf_get_float(const struct bt_definition *field);
531 %rename("_bt_ctf_get_variant") bt_ctf_get_variant(const struct bt_definition *field);
532 %rename("_bt_ctf_field_get_error") bt_ctf_field_get_error(void);
533 %rename("_bt_ctf_get_decl_event_name") bt_ctf_get_decl_event_name(const struct
534 bt_ctf_event_decl *event);
535 %rename("_bt_ctf_get_decl_event_id") bt_ctf_get_decl_event_id(const struct
536 bt_ctf_event_decl *event);
537 %rename("_bt_ctf_get_decl_field_name") bt_ctf_get_decl_field_name(
538 const struct bt_ctf_field_decl *field);
539 %rename("_bt_ctf_get_decl_from_def") bt_ctf_get_decl_from_def(
540 const struct bt_definition *field);
541 %rename("_bt_ctf_get_decl_from_field_decl") bt_ctf_get_decl_from_field_decl(
542 const struct bt_ctf_field_decl *field);
543 %rename("_bt_array_index") bt_array_index(struct definition_array *array, uint64_t i);
544 %rename("_bt_sequence_len") bt_sequence_len(struct definition_sequence *sequence);
545 %rename("_bt_sequence_index") bt_sequence_index(struct definition_sequence *sequence, uint64_t i);
546 %rename("_bt_ctf_get_struct_field_count") bt_ctf_get_struct_field_count(const struct bt_definition *structure);
547 %rename("_bt_ctf_get_struct_field_index") bt_ctf_get_struct_field_index(const struct bt_definition *structure, uint64_t i);
549 const struct bt_definition *bt_ctf_get_top_level_scope(const struct bt_ctf_event *ctf_event,
550 enum bt_ctf_scope scope);
551 const char *bt_ctf_event_name(const struct bt_ctf_event *ctf_event);
552 uint64_t bt_ctf_get_timestamp(const struct bt_ctf_event *ctf_event);
553 uint64_t bt_ctf_get_cycles(const struct bt_ctf_event *ctf_event);
554 const struct bt_definition *bt_ctf_get_field(const struct bt_ctf_event *ctf_event,
555 const struct bt_definition *scope,
557 const struct bt_definition *bt_ctf_get_index(const struct bt_ctf_event *ctf_event,
558 const struct bt_definition *field,
560 const char *bt_ctf_field_name(const struct bt_definition *field);
561 enum ctf_type_id bt_ctf_field_type(const struct bt_declaration *field);
562 int bt_ctf_get_int_signedness(const struct bt_declaration *field);
563 int bt_ctf_get_int_base(const struct bt_declaration *field);
564 int bt_ctf_get_int_byte_order(const struct bt_declaration *field);
565 ssize_t bt_ctf_get_int_len(const struct bt_declaration *field);
566 const struct bt_definition *bt_ctf_get_enum_int(const struct bt_definition *field);
567 const char *bt_ctf_get_enum_str(const struct bt_definition *field);
568 enum ctf_string_encoding bt_ctf_get_encoding(const struct bt_declaration *field);
569 int bt_ctf_get_array_len(const struct bt_declaration *field);
570 struct bt_definition *bt_array_index(struct definition_array *array, uint64_t i);
571 uint64_t bt_ctf_get_uint64(const struct bt_definition *field);
572 int64_t bt_ctf_get_int64(const struct bt_definition *field);
573 char *bt_ctf_get_char_array(const struct bt_definition *field);
574 char *bt_ctf_get_string(const struct bt_definition *field);
575 double bt_ctf_get_float(const struct bt_definition *field);
576 const struct bt_definition *bt_ctf_get_variant(const struct bt_definition *field);
577 int bt_ctf_field_get_error(void);
578 const char *bt_ctf_get_decl_event_name(const struct bt_ctf_event_decl *event);
579 uint64_t bt_ctf_get_decl_event_id(const struct bt_ctf_event_decl *event);
580 const char *bt_ctf_get_decl_field_name(const struct bt_ctf_field_decl *field);
581 const struct bt_declaration *bt_ctf_get_decl_from_def(const struct bt_definition *field);
582 const struct bt_declaration *bt_ctf_get_decl_from_field_decl(const struct bt_ctf_field_decl *field);
583 uint64_t bt_sequence_len(struct definition_sequence *sequence);
584 struct bt_definition *bt_sequence_index(struct definition_sequence *sequence, uint64_t i);
585 uint64_t bt_ctf_get_struct_field_count(const struct bt_definition *structure);
586 const struct bt_definition *bt_ctf_get_struct_field_index(const struct bt_definition *structure, uint64_t i);
590 class CTFStringEncoding:
596 # Based on the enum in ctf-writer/writer.h
598 BYTE_ORDER_NATIVE = 0
599 BYTE_ORDER_LITTLE_ENDIAN = 1
600 BYTE_ORDER_BIG_ENDIAN = 2
601 BYTE_ORDER_NETWORK = 3
602 BYTE_ORDER_UNKNOWN = 4 # Python-specific entry
604 # enum equivalent, accessible constants
605 # These are taken directly from ctf/events.h
606 # All changes to enums must also be made here
621 name = "UNKNOWN_TYPE"
623 attr for attr in dir(CTFTypeId) if not callable(
626 attr)) and not attr.startswith("__")]
627 for attr in constants:
628 if getattr(CTFTypeId, attr) == id:
635 TRACE_PACKET_HEADER = 0
636 STREAM_PACKET_CONTEXT = 1
637 STREAM_EVENT_HEADER = 2
638 STREAM_EVENT_CONTEXT = 3
642 def scope_name(scope):
643 name = "UNKNOWN_SCOPE"
645 attr for attr in dir(CTFScope) if not callable(
648 attr)) and not attr.startswith("__")]
649 for attr in constants:
650 if getattr(CTFScope, attr) == scope:
655 # Priority of the scopes when searching for event fields
656 _scopes = [CTFScope.EVENT_FIELDS, CTFScope.EVENT_CONTEXT, CTFScope.STREAM_EVENT_CONTEXT,
657 CTFScope.STREAM_EVENT_HEADER, CTFScope.STREAM_PACKET_CONTEXT, CTFScope.TRACE_PACKET_HEADER]
660 from datetime import datetime
663 class Event(collections.Mapping):
666 This class represents an event from the trace.
667 It is obtained using the TraceCollection generator functions.
672 raise NotImplementedError("Event cannot be instantiated")
676 """Return the name of the event or None on error."""
677 return _bt_ctf_event_name(self._e)
682 Return the timestamp of the event as written in
683 the packet (in cycles) or -1ULL on error.
685 return _bt_ctf_get_cycles(self._e)
690 Return the timestamp of the event offset with the
691 system clock source or -1ULL on error.
693 return _bt_ctf_get_timestamp(self._e)
698 Return a datetime object based on the event's
699 timestamp. Note that the datetime class' precision
700 is limited to microseconds.
702 return datetime.fromtimestamp(self.timestamp / 1E9)
704 def field_with_scope(self, field_name, scope):
706 Get field_name's value in scope.
707 None is returned if no field matches field_name.
709 if not scope in _scopes:
710 raise ValueError("Invalid scope provided")
711 field = self._field_with_scope(field_name, scope)
712 if field is not None:
716 def field_list_with_scope(self, scope):
717 """Return a list of field names in scope."""
718 if not scope in _scopes:
719 raise ValueError("Invalid scope provided")
721 for field in self._field_list_with_scope(scope):
722 field_names.append(field.name)
728 Get the TraceHandle associated with this event
731 ret = _bt_ctf_event_get_handle_id(self._e)
735 th = TraceHandle.__new__(TraceHandle)
737 th._trace_collection = self.get_trace_collection()
741 def trace_collection(self):
743 Get the TraceCollection associated with this event.
744 Return None on error.
746 trace_collection = TraceCollection()
747 trace_collection._tc = _bt_ctf_event_get_context(self._e)
748 if trace_collection._tc is None:
751 return trace_collection
753 def __getitem__(self, field_name):
755 Get field_name's value. If the field_name exists in multiple
756 scopes, the first field found is returned. The scopes are searched
757 in the following order:
760 3) STREAM_EVENT_CONTEXT
761 4) STREAM_EVENT_HEADER
762 5) STREAM_PACKET_CONTEXT
763 6) TRACE_PACKET_HEADER
764 None is returned if no field matches field_name.
766 Use field_with_scope() to explicitly access fields in a given
769 field = self._field(field_name)
770 if field is not None:
772 raise KeyError(field_name)
775 for key in self.keys():
780 for scope in _scopes:
781 scope_ptr = _bt_ctf_get_top_level_scope(self._e, scope)
782 ret = _bt_python_field_listcaller(self._e, scope_ptr)
783 if isinstance(ret, list):
787 def __contains__(self, field_name):
788 return self._field(field_name) is not None
791 """Return a list of field names."""
793 for scope in _scopes:
794 for name in self.field_list_with_scope(scope):
795 field_names.add(name)
796 return list(field_names)
798 def get(self, field_name, default=None):
799 field = self._field(field_name)
805 for field in self.keys():
806 yield (field, self[field])
808 def _field_with_scope(self, field_name, scope):
809 scope_ptr = _bt_ctf_get_top_level_scope(self._e, scope)
810 if scope_ptr is None:
813 definition_ptr = _bt_ctf_get_field(self._e, scope_ptr, field_name)
814 if definition_ptr is None:
817 field = _Definition(definition_ptr, scope)
820 def _field(self, field_name):
822 for scope in _scopes:
823 field = self._field_with_scope(field_name, scope)
824 if field is not None:
828 def _field_list_with_scope(self, scope):
830 scope_ptr = _bt_ctf_get_top_level_scope(self._e, scope)
832 # Returns a list [list_ptr, count]. If list_ptr is NULL, SWIG will only
833 # provide the "count" return value
836 ret = _bt_python_field_listcaller(self._e, scope_ptr)
837 if isinstance(ret, list):
838 list_ptr, count = ret
840 for i in range(count):
841 definition_ptr = _bt_python_field_one_from_list(list_ptr, i)
842 if definition_ptr is not None:
843 definition = _Definition(definition_ptr, scope)
844 fields.append(definition)
848 class FieldError(Exception):
850 def __init__(self, value):
854 return repr(self.value)
857 class EventDeclaration(object):
859 """Event declaration class. Do not instantiate."""
860 MAX_UINT64 = 0xFFFFFFFFFFFFFFFF
863 raise NotImplementedError("EventDeclaration cannot be instantiated")
867 """Return the name of the event or None on error"""
868 return _bt_ctf_get_decl_event_name(self._ed)
872 """Return the event-ID of the event or -1 on error"""
873 id = _bt_ctf_get_decl_event_id(self._ed)
874 if id == self.MAX_UINT64:
881 Generator returning all FieldDeclarations of an event, going through
882 each scope in the following order:
885 3) STREAM_EVENT_CONTEXT
886 4) STREAM_EVENT_HEADER
887 5) STREAM_PACKET_CONTEXT
888 6) TRACE_PACKET_HEADER
890 for scope in _scopes:
891 for declaration in self.fields_scope(scope):
894 def fields_scope(self, scope):
896 Generator returning FieldDeclarations of the current event in scope.
898 ret = _by_python_field_decl_listcaller(self._ed, scope)
900 if not isinstance(ret, list):
903 list_ptr, count = ret
904 for i in range(count):
905 field_declaration_ptr = _bt_python_field_decl_one_from_list(
908 if field_declaration_ptr is not None:
909 declaration_ptr = _bt_ctf_get_decl_from_field_decl(
910 field_declaration_ptr)
911 field_declaration = _create_field_declaration(
913 _bt_ctf_get_decl_field_name(field_declaration_ptr),
915 yield field_declaration
918 class FieldDeclaration(object):
920 """Field declaration class. Do not instantiate."""
923 raise NotImplementedError("FieldDeclaration cannot be instantiated")
926 return "({0}) {1} {2}".format(
927 CTFScope.scope_name(self.scope), CTFTypeId.type_name(self.type), self.name)
931 """Return the name of a FieldDeclaration or None on error."""
937 Return the FieldDeclaration's type. One of the entries in class
940 return _bt_ctf_field_type(self._fd)
945 Return the FieldDeclaration's scope.
950 class IntegerFieldDeclaration(FieldDeclaration):
952 """Do not instantiate."""
955 raise NotImplementedError(
956 "IntegerFieldDeclaration cannot be instantiated")
959 def signedness(self):
961 Return the signedness of an integer:
962 0 if unsigned; 1 if signed; -1 on error.
964 return _bt_ctf_get_int_signedness(self._fd)
968 """Return the base of an int or a negative value on error."""
969 return _bt_ctf_get_int_base(self._fd)
972 def byte_order(self):
974 Return the byte order. One of class ByteOrder's entries.
976 ret = _bt_ctf_get_int_byte_order(self._fd)
978 return ByteOrder.BYTE_ORDER_LITTLE_ENDIAN
980 return ByteOrder.BYTE_ORDER_BIG_ENDIAN
982 return ByteOrder.BYTE_ORDER_UNKNOWN
987 Return the size, in bits, of an int or a negative
990 return _bt_ctf_get_int_len(self._fd)
995 Return the encoding. One of class CTFStringEncoding's entries.
996 Return a negative value on error.
998 return _bt_ctf_get_encoding(self._fd)
1001 class EnumerationFieldDeclaration(FieldDeclaration):
1003 """Do not instantiate."""
1006 raise NotImplementedError(
1007 "EnumerationFieldDeclaration cannot be instantiated")
1010 class ArrayFieldDeclaration(FieldDeclaration):
1012 """Do not instantiate."""
1015 raise NotImplementedError(
1016 "ArrayFieldDeclaration cannot be instantiated")
1021 Return the length of an array or a negative
1024 return _bt_ctf_get_array_len(self._fd)
1027 def element_declaration(self):
1029 Return element declaration.
1031 field_decl_ptr = _bt_python_get_array_element_declaration(self._fd)
1032 return _create_field_declaration(field_decl_ptr, "", self.scope)
1035 class SequenceFieldDeclaration(FieldDeclaration):
1037 """Do not instantiate."""
1040 raise NotImplementedError(
1041 "SequenceFieldDeclaration cannot be instantiated")
1044 def element_declaration(self):
1046 Return element declaration.
1048 field_decl_ptr = _bt_python_get_sequence_element_declaration(self._fd)
1049 return _create_field_declaration(field_decl_ptr, "", self.scope)
1052 class FloatFieldDeclaration(FieldDeclaration):
1054 """Do not instantiate."""
1057 raise NotImplementedError(
1058 "FloatFieldDeclaration cannot be instantiated")
1061 class StructureFieldDeclaration(FieldDeclaration):
1063 """Do not instantiate."""
1066 raise NotImplementedError(
1067 "StructureFieldDeclaration cannot be instantiated")
1070 class StringFieldDeclaration(FieldDeclaration):
1072 """Do not instantiate."""
1075 raise NotImplementedError(
1076 "StringFieldDeclaration cannot be instantiated")
1079 class VariantFieldDeclaration(FieldDeclaration):
1081 """Do not instantiate."""
1084 raise NotImplementedError(
1085 "VariantFieldDeclaration cannot be instantiated")
1090 Return the last error code encountered while
1091 accessing a field and reset the error flag.
1092 Return 0 if no error, a negative value otherwise.
1094 return _bt_ctf_field_get_error()
1097 def _create_field_declaration(declaration_ptr, name, scope):
1099 Private field declaration factory.
1101 if declaration_ptr is None:
1102 raise ValueError("declaration_ptr must be valid")
1103 if not scope in _scopes:
1104 raise ValueError("Invalid scope provided")
1106 type = _bt_ctf_field_type(declaration_ptr)
1108 if type == CTFTypeId.INTEGER:
1109 declaration = IntegerFieldDeclaration.__new__(IntegerFieldDeclaration)
1110 elif type == CTFTypeId.ENUM:
1111 declaration = EnumerationFieldDeclaration.__new__(
1112 EnumerationFieldDeclaration)
1113 elif type == CTFTypeId.ARRAY:
1114 declaration = ArrayFieldDeclaration.__new__(ArrayFieldDeclaration)
1115 elif type == CTFTypeId.SEQUENCE:
1116 declaration = SequenceFieldDeclaration.__new__(
1117 SequenceFieldDeclaration)
1118 elif type == CTFTypeId.FLOAT:
1119 declaration = FloatFieldDeclaration.__new__(FloatFieldDeclaration)
1120 elif type == CTFTypeId.STRUCT:
1121 declaration = StructureFieldDeclaration.__new__(
1122 StructureFieldDeclaration)
1123 elif type == CTFTypeId.STRING:
1124 declaration = StringFieldDeclaration.__new__(StringFieldDeclaration)
1125 elif type == CTFTypeId.VARIANT:
1126 declaration = VariantFieldDeclaration.__new__(VariantFieldDeclaration)
1130 declaration._fd = declaration_ptr
1131 declaration._s = scope
1132 declaration._name = name
1136 class _Definition(object):
1138 def __init__(self, definition_ptr, scope):
1139 self._d = definition_ptr
1141 if not scope in _scopes:
1142 ValueError("Invalid scope provided")
1146 """Return the name of a field or None on error."""
1147 return _bt_ctf_field_name(self._d)
1151 """Return the type of a field or -1 if unknown."""
1152 return _bt_ctf_field_type(_bt_ctf_get_decl_from_def(self._d))
1155 def declaration(self):
1156 """Return the associated Definition object."""
1157 return _create_field_declaration(
1158 _bt_ctf_get_decl_from_def(self._d), self.name, self.scope)
1160 def _get_enum_str(self):
1162 Return the string matching the current enumeration.
1163 Return None on error.
1165 return _bt_ctf_get_enum_str(self._d)
1167 def _get_array_element_at(self, index):
1169 Return the array's element at position index.
1170 Return None on error
1172 array_ptr = _bt_python_get_array_from_def(self._d)
1173 if array_ptr is None:
1176 definition_ptr = _bt_array_index(array_ptr, index)
1177 if definition_ptr is None:
1179 return _Definition(definition_ptr, self.scope)
1181 def _get_sequence_len(self):
1183 Return the len of a sequence or a negative
1186 seq = _bt_python_get_sequence_from_def(self._d)
1187 return _bt_sequence_len(seq)
1189 def _get_sequence_element_at(self, index):
1191 Return the sequence's element at position index,
1192 otherwise return None
1194 seq = _bt_python_get_sequence_from_def(self._d)
1196 definition_ptr = _bt_sequence_index(seq, index)
1197 if definition_ptr is not None:
1198 return _Definition(definition_ptr, self.scope)
1201 def _get_uint64(self):
1203 Return the value associated with the field.
1204 If the field does not exist or is not of the type requested,
1205 the value returned is undefined. To check if an error occured,
1206 use the field_error() function after accessing a field.
1208 return _bt_ctf_get_uint64(self._d)
1210 def _get_int64(self):
1212 Return the value associated with the field.
1213 If the field does not exist or is not of the type requested,
1214 the value returned is undefined. To check if an error occured,
1215 use the field_error() function after accessing a field.
1217 return _bt_ctf_get_int64(self._d)
1219 def _get_char_array(self):
1221 Return the value associated with the field.
1222 If the field does not exist or is not of the type requested,
1223 the value returned is undefined. To check if an error occurred,
1224 use the field_error() function after accessing a field.
1226 return _bt_ctf_get_char_array(self._d)
1230 Return the value associated with the field.
1231 If the field does not exist or is not of the type requested,
1232 the value returned is undefined. To check if an error occurred,
1233 use the field_error() function after accessing a field.
1235 return _bt_ctf_get_string(self._d)
1237 def _get_float(self):
1239 Return the value associated with the field.
1240 If the field does not exist or is not of the type requested,
1241 the value returned is undefined. To check if an error occurred,
1242 use the field_error() function after accessing a field.
1244 return _bt_ctf_get_float(self._d)
1246 def _get_variant(self):
1248 Return the variant's selected field.
1249 If the field does not exist or is not of the type requested,
1250 the value returned is undefined. To check if an error occurred,
1251 use the field_error() function after accessing a field.
1253 return _bt_ctf_get_variant(self._d)
1255 def _get_struct_field_count(self):
1257 Return the number of fields contained in the structure.
1258 If the field does not exist or is not of the type requested,
1259 the value returned is undefined.
1261 return _bt_ctf_get_struct_field_count(self._d)
1263 def _get_struct_field_at(self, i):
1265 Return the structure's field at position i.
1266 If the field does not exist or is not of the type requested,
1267 the value returned is undefined. To check if an error occurred,
1268 use the field_error() function after accessing a field.
1270 return _bt_ctf_get_struct_field_index(self._d, i)
1275 Return the value associated with the field according to its type.
1276 Return None on error.
1281 if id == CTFTypeId.STRING:
1282 value = self._get_str()
1283 elif id == CTFTypeId.ARRAY:
1284 element_decl = self.declaration.element_declaration
1285 if ((element_decl.type == CTFTypeId.INTEGER
1286 and element_decl.length == 8)
1287 and (element_decl.encoding == CTFStringEncoding.ASCII or element_decl.encoding == CTFStringEncoding.UTF8)):
1288 value = _bt_python_get_array_string(self._d)
1291 for i in range(self.declaration.length):
1292 element = self._get_array_element_at(i)
1293 value.append(element.value)
1294 elif id == CTFTypeId.INTEGER:
1295 if self.declaration.signedness == 0:
1296 value = self._get_uint64()
1298 value = self._get_int64()
1299 elif id == CTFTypeId.ENUM:
1300 value = self._get_enum_str()
1301 elif id == CTFTypeId.SEQUENCE:
1302 element_decl = self.declaration.element_declaration
1303 if ((element_decl.type == CTFTypeId.INTEGER
1304 and element_decl.length == 8)
1305 and (element_decl.encoding == CTFStringEncoding.ASCII or element_decl.encoding == CTFStringEncoding.UTF8)):
1306 value = _bt_python_get_sequence_string(self._d)
1308 seq_len = self._get_sequence_len()
1310 for i in range(seq_len):
1311 evDef = self._get_sequence_element_at(i)
1312 value.append(evDef.value)
1313 elif id == CTFTypeId.FLOAT:
1314 value = self._get_float()
1315 elif id == CTFTypeId.VARIANT:
1316 variant = _Definition.__new__(_Definition)
1317 variant._d = self._get_variant()
1318 value = variant.value
1319 elif id == CTFTypeId.STRUCT:
1321 for i in range(self._get_struct_field_count()):
1322 member = _Definition(self._get_struct_field_at(i), self.scope)
1323 value[member.name] = member.value
1327 "Error occurred while accessing field {} of type {}".format(
1329 CTFTypeId.type_name(id)))
1334 """Return the scope of a field or None on error."""
1342 %rename("_bt_ctf_clock_create") bt_ctf_clock_create(const char *name);
1343 %rename("_bt_ctf_clock_get_name") bt_ctf_clock_get_name(struct bt_ctf_clock *clock);
1344 %rename("_bt_ctf_clock_get_description") bt_ctf_clock_get_description(struct bt_ctf_clock *clock);
1345 %rename("_bt_ctf_clock_set_description") bt_ctf_clock_set_description(struct bt_ctf_clock *clock, const char *desc);
1346 %rename("_bt_ctf_clock_get_frequency") bt_ctf_clock_get_frequency(struct bt_ctf_clock *clock);
1347 %rename("_bt_ctf_clock_set_frequency") bt_ctf_clock_set_frequency(struct bt_ctf_clock *clock, uint64_t freq);
1348 %rename("_bt_ctf_clock_get_precision") bt_ctf_clock_get_precision(struct bt_ctf_clock *clock);
1349 %rename("_bt_ctf_clock_set_precision") bt_ctf_clock_set_precision(struct bt_ctf_clock *clock, uint64_t precision);
1350 %rename("_bt_ctf_clock_get_offset_s") bt_ctf_clock_get_offset_s(struct bt_ctf_clock *clock);
1351 %rename("_bt_ctf_clock_set_offset_s") bt_ctf_clock_set_offset_s(struct bt_ctf_clock *clock, uint64_t offset_s);
1352 %rename("_bt_ctf_clock_get_offset") bt_ctf_clock_get_offset(struct bt_ctf_clock *clock);
1353 %rename("_bt_ctf_clock_set_offset") bt_ctf_clock_set_offset(struct bt_ctf_clock *clock, uint64_t offset);
1354 %rename("_bt_ctf_clock_get_is_absolute") bt_ctf_clock_get_is_absolute(struct bt_ctf_clock *clock);
1355 %rename("_bt_ctf_clock_set_is_absolute") bt_ctf_clock_set_is_absolute(struct bt_ctf_clock *clock, int is_absolute);
1356 %rename("_bt_ctf_clock_get_time") bt_ctf_clock_get_time(struct bt_ctf_clock *clock);
1357 %rename("_bt_ctf_clock_set_time") bt_ctf_clock_set_time(struct bt_ctf_clock *clock, uint64_t time);
1358 %rename("_bt_ctf_clock_get") bt_ctf_clock_get(struct bt_ctf_clock *clock);
1359 %rename("_bt_ctf_clock_put") bt_ctf_clock_put(struct bt_ctf_clock *clock);
1361 struct bt_ctf_clock *bt_ctf_clock_create(const char *name);
1362 const char *bt_ctf_clock_get_name(struct bt_ctf_clock *clock);
1363 const char *bt_ctf_clock_get_description(struct bt_ctf_clock *clock);
1364 int bt_ctf_clock_set_description(struct bt_ctf_clock *clock, const char *desc);
1365 uint64_t bt_ctf_clock_get_frequency(struct bt_ctf_clock *clock);
1366 int bt_ctf_clock_set_frequency(struct bt_ctf_clock *clock, uint64_t freq);
1367 uint64_t bt_ctf_clock_get_precision(struct bt_ctf_clock *clock);
1368 int bt_ctf_clock_set_precision(struct bt_ctf_clock *clock, uint64_t precision);
1369 uint64_t bt_ctf_clock_get_offset_s(struct bt_ctf_clock *clock);
1370 int bt_ctf_clock_set_offset_s(struct bt_ctf_clock *clock, uint64_t offset_s);
1371 uint64_t bt_ctf_clock_get_offset(struct bt_ctf_clock *clock);
1372 int bt_ctf_clock_set_offset(struct bt_ctf_clock *clock, uint64_t offset);
1373 int bt_ctf_clock_get_is_absolute(struct bt_ctf_clock *clock);
1374 int bt_ctf_clock_set_is_absolute(struct bt_ctf_clock *clock, int is_absolute);
1375 uint64_t bt_ctf_clock_get_time(struct bt_ctf_clock *clock);
1376 int bt_ctf_clock_set_time(struct bt_ctf_clock *clock, uint64_t time);
1377 void bt_ctf_clock_get(struct bt_ctf_clock *clock);
1378 void bt_ctf_clock_put(struct bt_ctf_clock *clock);
1381 %rename("_bt_ctf_field_type_integer_create") bt_ctf_field_type_integer_create(unsigned int size);
1382 %rename("_bt_ctf_field_type_integer_get_size") bt_ctf_field_type_integer_get_size(struct bt_ctf_field_type *integer);
1383 %rename("_bt_ctf_field_type_integer_get_signed") bt_ctf_field_type_integer_get_signed(struct bt_ctf_field_type *integer);
1384 %rename("_bt_ctf_field_type_integer_set_signed") bt_ctf_field_type_integer_set_signed(struct bt_ctf_field_type *integer, int is_signed);
1385 %rename("_bt_ctf_field_type_integer_get_base") bt_ctf_field_type_integer_get_base(struct bt_ctf_field_type *integer);
1386 %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);
1387 %rename("_bt_ctf_field_type_integer_get_encoding") bt_ctf_field_type_integer_get_encoding(struct bt_ctf_field_type *integer);
1388 %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);
1389 %rename("_bt_ctf_field_type_enumeration_create") bt_ctf_field_type_enumeration_create(struct bt_ctf_field_type *integer_container_type);
1390 %rename("_bt_ctf_field_type_enumeration_get_container_type") bt_ctf_field_type_enumeration_get_container_type(struct bt_ctf_field_type *enumeration);
1391 %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);
1392 %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);
1393 %rename("_bt_ctf_field_type_enumeration_get_mapping_count") bt_ctf_field_type_enumeration_get_mapping_count(struct bt_ctf_field_type *enumeration);
1394 %rename("_bt_ctf_field_type_enumeration_get_mapping") bt_ctf_field_type_enumeration_get_mapping(struct bt_ctf_field_type *enumeration, int index, const char **name, int64_t *range_start, int64_t *range_end);
1395 %rename("_bt_ctf_field_type_enumeration_get_mapping_unsigned") bt_ctf_field_type_enumeration_get_mapping_unsigned(struct bt_ctf_field_type *enumeration, int index, const char **name, uint64_t *range_start, uint64_t *range_end);
1396 %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);
1397 %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);
1398 %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);
1399 %rename("_bt_ctf_field_type_floating_point_create") bt_ctf_field_type_floating_point_create(void);
1400 %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);
1401 %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);
1402 %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);
1403 %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);
1404 %rename("_bt_ctf_field_type_structure_create") bt_ctf_field_type_structure_create(void);
1405 %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);
1406 %rename("_bt_ctf_field_type_structure_get_field_count") bt_ctf_field_type_structure_get_field_count(struct bt_ctf_field_type *structure);
1407 %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, int index);
1408 %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);
1409 %rename("_bt_ctf_field_type_variant_create") bt_ctf_field_type_variant_create(struct bt_ctf_field_type *enum_tag, const char *tag_name);
1410 %rename("_bt_ctf_field_type_variant_get_tag_type") bt_ctf_field_type_variant_get_tag_type(struct bt_ctf_field_type *variant);
1411 %rename("_bt_ctf_field_type_variant_get_tag_name") bt_ctf_field_type_variant_get_tag_name(struct bt_ctf_field_type *variant);
1412 %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);
1413 %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);
1414 %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);
1415 %rename("_bt_ctf_field_type_variant_get_field_count") bt_ctf_field_type_variant_get_field_count(struct bt_ctf_field_type *variant);
1416 %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, int index);
1417 %rename("_bt_ctf_field_type_array_create") bt_ctf_field_type_array_create(struct bt_ctf_field_type *element_type, unsigned int length);
1418 %rename("_bt_ctf_field_type_array_get_element_type") bt_ctf_field_type_array_get_element_type(struct bt_ctf_field_type *array);
1419 %rename("_bt_ctf_field_type_array_get_length") bt_ctf_field_type_array_get_length(struct bt_ctf_field_type *array);
1420 %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);
1421 %rename("_bt_ctf_field_type_sequence_get_element_type") bt_ctf_field_type_sequence_get_element_type(struct bt_ctf_field_type *sequence);
1422 %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);
1423 %rename("_bt_ctf_field_type_string_create") bt_ctf_field_type_string_create(void);
1424 %rename("_bt_ctf_field_type_string_get_encoding") bt_ctf_field_type_string_get_encoding(struct bt_ctf_field_type *string_type);
1425 %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);
1426 %rename("_bt_ctf_field_type_get_alignment") bt_ctf_field_type_get_alignment(struct bt_ctf_field_type *type);
1427 %rename("_bt_ctf_field_type_set_alignment") bt_ctf_field_type_set_alignment(struct bt_ctf_field_type *type, unsigned int alignment);
1428 %rename("_bt_ctf_field_type_get_byte_order") bt_ctf_field_type_get_byte_order(struct bt_ctf_field_type *type);
1429 %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);
1430 %rename("_bt_ctf_field_type_get_type_id") bt_ctf_field_type_get_type_id(struct bt_ctf_field_type *type);
1431 %rename("_bt_ctf_field_type_get") bt_ctf_field_type_get(struct bt_ctf_field_type *type);
1432 %rename("_bt_ctf_field_type_put") bt_ctf_field_type_put(struct bt_ctf_field_type *type);
1434 struct bt_ctf_field_type *bt_ctf_field_type_integer_create(unsigned int size);
1435 int bt_ctf_field_type_integer_get_size(struct bt_ctf_field_type *integer);
1436 int bt_ctf_field_type_integer_get_signed(struct bt_ctf_field_type *integer);
1437 int bt_ctf_field_type_integer_set_signed(struct bt_ctf_field_type *integer, int is_signed);
1438 enum bt_ctf_integer_base bt_ctf_field_type_integer_get_base(struct bt_ctf_field_type *integer);
1439 int bt_ctf_field_type_integer_set_base(struct bt_ctf_field_type *integer, enum bt_ctf_integer_base base);
1440 enum ctf_string_encoding bt_ctf_field_type_integer_get_encoding(struct bt_ctf_field_type *integer);
1441 int bt_ctf_field_type_integer_set_encoding(struct bt_ctf_field_type *integer, enum ctf_string_encoding encoding);
1442 struct bt_ctf_field_type *bt_ctf_field_type_enumeration_create(struct bt_ctf_field_type *integer_container_type);
1443 struct bt_ctf_field_type *bt_ctf_field_type_enumeration_get_container_type(struct bt_ctf_field_type *enumeration);
1444 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);
1445 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);
1446 int bt_ctf_field_type_enumeration_get_mapping_count(struct bt_ctf_field_type *enumeration);
1447 int bt_ctf_field_type_enumeration_get_mapping(struct bt_ctf_field_type *enumeration, int index, const char **OUTPUT, int64_t *OUTPUT, int64_t *OUTPUT);
1448 int bt_ctf_field_type_enumeration_get_mapping_unsigned(struct bt_ctf_field_type *enumeration, int index, const char **OUTPUT, uint64_t *OUTPUT, uint64_t *OUTPUT);
1449 int bt_ctf_field_type_enumeration_get_mapping_index_by_name(struct bt_ctf_field_type *enumeration, const char *name);
1450 int bt_ctf_field_type_enumeration_get_mapping_index_by_value(struct bt_ctf_field_type *enumeration, int64_t value);
1451 int bt_ctf_field_type_enumeration_get_mapping_index_by_unsigned_value(struct bt_ctf_field_type *enumeration, uint64_t value);
1452 struct bt_ctf_field_type *bt_ctf_field_type_floating_point_create(void);
1453 int bt_ctf_field_type_floating_point_get_exponent_digits(struct bt_ctf_field_type *floating_point);
1454 int bt_ctf_field_type_floating_point_set_exponent_digits(struct bt_ctf_field_type *floating_point, unsigned int exponent_digits);
1455 int bt_ctf_field_type_floating_point_get_mantissa_digits(struct bt_ctf_field_type *floating_point);
1456 int bt_ctf_field_type_floating_point_set_mantissa_digits(struct bt_ctf_field_type *floating_point, unsigned int mantissa_digits);
1457 struct bt_ctf_field_type *bt_ctf_field_type_structure_create(void);
1458 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);
1459 int bt_ctf_field_type_structure_get_field_count(struct bt_ctf_field_type *structure);
1460 int bt_ctf_field_type_structure_get_field(struct bt_ctf_field_type *structure, const char **OUTPUT, struct bt_ctf_field_type **OUTPUT, int index);
1461 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);
1462 struct bt_ctf_field_type *bt_ctf_field_type_variant_create(struct bt_ctf_field_type *enum_tag, const char *tag_name);
1463 struct bt_ctf_field_type *bt_ctf_field_type_variant_get_tag_type(struct bt_ctf_field_type *variant);
1464 const char *bt_ctf_field_type_variant_get_tag_name(struct bt_ctf_field_type *variant);
1465 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);
1466 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);
1467 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);
1468 int bt_ctf_field_type_variant_get_field_count(struct bt_ctf_field_type *variant);
1469 int bt_ctf_field_type_variant_get_field(struct bt_ctf_field_type *variant, const char **OUTPUT, struct bt_ctf_field_type **OUTPUT, int index);
1470 struct bt_ctf_field_type *bt_ctf_field_type_array_create(struct bt_ctf_field_type *element_type, unsigned int length);
1471 struct bt_ctf_field_type *bt_ctf_field_type_array_get_element_type(struct bt_ctf_field_type *array);
1472 int64_t bt_ctf_field_type_array_get_length(struct bt_ctf_field_type *array);
1473 struct bt_ctf_field_type *bt_ctf_field_type_sequence_create(struct bt_ctf_field_type *element_type, const char *length_field_name);
1474 struct bt_ctf_field_type *bt_ctf_field_type_sequence_get_element_type(struct bt_ctf_field_type *sequence);
1475 const char *bt_ctf_field_type_sequence_get_length_field_name(struct bt_ctf_field_type *sequence);
1476 struct bt_ctf_field_type *bt_ctf_field_type_string_create(void);
1477 enum ctf_string_encoding bt_ctf_field_type_string_get_encoding(struct bt_ctf_field_type *string_type);
1478 int bt_ctf_field_type_string_set_encoding(struct bt_ctf_field_type *string_type, enum ctf_string_encoding encoding);
1479 int bt_ctf_field_type_get_alignment(struct bt_ctf_field_type *type);
1480 int bt_ctf_field_type_set_alignment(struct bt_ctf_field_type *type, unsigned int alignment);
1481 enum bt_ctf_byte_order bt_ctf_field_type_get_byte_order(struct bt_ctf_field_type *type);
1482 int bt_ctf_field_type_set_byte_order(struct bt_ctf_field_type *type, enum bt_ctf_byte_order byte_order);
1483 enum ctf_type_id bt_ctf_field_type_get_type_id(struct bt_ctf_field_type *type);
1484 void bt_ctf_field_type_get(struct bt_ctf_field_type *type);
1485 void bt_ctf_field_type_put(struct bt_ctf_field_type *type);
1487 /* event-fields.h */
1488 %rename("_bt_ctf_field_create") bt_ctf_field_create(struct bt_ctf_field_type *type);
1489 %rename("_bt_ctf_field_structure_get_field") bt_ctf_field_structure_get_field(struct bt_ctf_field *structure, const char *name);
1490 %rename("_bt_ctf_field_array_get_field") bt_ctf_field_array_get_field(struct bt_ctf_field *array, uint64_t index);
1491 %rename("_bt_ctf_field_sequence_get_length") bt_ctf_field_sequence_get_length(struct bt_ctf_field *sequence);
1492 %rename("_bt_ctf_field_sequence_set_length") bt_ctf_field_sequence_set_length(struct bt_ctf_field *sequence, struct bt_ctf_field *length_field);
1493 %rename("_bt_ctf_field_sequence_get_field") bt_ctf_field_sequence_get_field(struct bt_ctf_field *sequence, uint64_t index);
1494 %rename("_bt_ctf_field_variant_get_field") bt_ctf_field_variant_get_field(struct bt_ctf_field *variant, struct bt_ctf_field *tag);
1495 %rename("_bt_ctf_field_enumeration_get_container") bt_ctf_field_enumeration_get_container(struct bt_ctf_field *enumeration);
1496 %rename("_bt_ctf_field_enumeration_get_mapping_name") bt_ctf_field_enumeration_get_mapping_name(struct bt_ctf_field *enumeration);
1497 %rename("_bt_ctf_field_signed_integer_get_value") bt_ctf_field_signed_integer_get_value(struct bt_ctf_field *integer, int64_t *value);
1498 %rename("_bt_ctf_field_signed_integer_set_value") bt_ctf_field_signed_integer_set_value(struct bt_ctf_field *integer, int64_t value);
1499 %rename("_bt_ctf_field_unsigned_integer_get_value") bt_ctf_field_unsigned_integer_get_value(struct bt_ctf_field *integer, uint64_t *value);
1500 %rename("_bt_ctf_field_unsigned_integer_set_value") bt_ctf_field_unsigned_integer_set_value(struct bt_ctf_field *integer, uint64_t value);
1501 %rename("_bt_ctf_field_floating_point_get_value") bt_ctf_field_floating_point_get_value(struct bt_ctf_field *floating_point, double *value);
1502 %rename("_bt_ctf_field_floating_point_set_value") bt_ctf_field_floating_point_set_value(struct bt_ctf_field *floating_point, double value);
1503 %rename("_bt_ctf_field_string_get_value") bt_ctf_field_string_get_value(struct bt_ctf_field *string_field);
1504 %rename("_bt_ctf_field_string_set_value") bt_ctf_field_string_set_value(struct bt_ctf_field *string_field, const char *value);
1505 %rename("_bt_ctf_field_get_type") bt_ctf_field_get_type(struct bt_ctf_field *field);
1506 %rename("_bt_ctf_field_get") bt_ctf_field_get(struct bt_ctf_field *field);
1507 %rename("_bt_ctf_field_put") bt_ctf_field_put(struct bt_ctf_field *field);
1509 struct bt_ctf_field *bt_ctf_field_create(struct bt_ctf_field_type *type);
1510 struct bt_ctf_field *bt_ctf_field_structure_get_field(struct bt_ctf_field *structure, const char *name);
1511 struct bt_ctf_field *bt_ctf_field_array_get_field(struct bt_ctf_field *array, uint64_t index);
1512 struct bt_ctf_field * bt_ctf_field_sequence_get_length(struct bt_ctf_field *sequence);
1513 int bt_ctf_field_sequence_set_length(struct bt_ctf_field *sequence, struct bt_ctf_field *length_field);
1514 struct bt_ctf_field *bt_ctf_field_sequence_get_field(struct bt_ctf_field *sequence, uint64_t index);
1515 struct bt_ctf_field *bt_ctf_field_variant_get_field(struct bt_ctf_field *variant, struct bt_ctf_field *tag);
1516 struct bt_ctf_field *bt_ctf_field_enumeration_get_container(struct bt_ctf_field *enumeration);
1517 const char *bt_ctf_field_enumeration_get_mapping_name(struct bt_ctf_field *enumeration);
1518 int bt_ctf_field_signed_integer_get_value(struct bt_ctf_field *integer, int64_t *OUTPUT);
1519 int bt_ctf_field_signed_integer_set_value(struct bt_ctf_field *integer, int64_t value);
1520 int bt_ctf_field_unsigned_integer_get_value(struct bt_ctf_field *integer, uint64_t *OUTPUT);
1521 int bt_ctf_field_unsigned_integer_set_value(struct bt_ctf_field *integer, uint64_t value);
1522 int bt_ctf_field_floating_point_get_value(struct bt_ctf_field *floating_point, double *OUTPUT);
1523 int bt_ctf_field_floating_point_set_value(struct bt_ctf_field *floating_point, double value);
1524 const char *bt_ctf_field_string_get_value(struct bt_ctf_field *string_field);
1525 int bt_ctf_field_string_set_value(struct bt_ctf_field *string_field, const char *value);
1526 struct bt_ctf_field_type *bt_ctf_field_get_type(struct bt_ctf_field *field);
1527 void bt_ctf_field_get(struct bt_ctf_field *field);
1528 void bt_ctf_field_put(struct bt_ctf_field *field);
1531 %rename("_bt_ctf_event_class_create") bt_ctf_event_class_create(const char *name);
1532 %rename("_bt_ctf_event_class_get_name") bt_ctf_event_class_get_name(struct bt_ctf_event_class *event_class);
1533 %rename("_bt_ctf_event_class_get_id") bt_ctf_event_class_get_id(struct bt_ctf_event_class *event_class);
1534 %rename("_bt_ctf_event_class_set_id") bt_ctf_event_class_set_id(struct bt_ctf_event_class *event_class, uint32_t id);
1535 %rename("_bt_ctf_event_class_get_stream_class") bt_ctf_event_class_get_stream_class(struct bt_ctf_event_class *event_class);
1536 %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);
1537 %rename("_bt_ctf_event_class_get_field_count") bt_ctf_event_class_get_field_count(struct bt_ctf_event_class *event_class);
1538 %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, int index);
1539 %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);
1540 %rename("_bt_ctf_event_class_get") bt_ctf_event_class_get(struct bt_ctf_event_class *event_class);
1541 %rename("_bt_ctf_event_class_put") bt_ctf_event_class_put(struct bt_ctf_event_class *event_class);
1543 struct bt_ctf_event_class *bt_ctf_event_class_create(const char *name);
1544 const char *bt_ctf_event_class_get_name(struct bt_ctf_event_class *event_class);
1545 int64_t bt_ctf_event_class_get_id(struct bt_ctf_event_class *event_class);
1546 int bt_ctf_event_class_set_id(struct bt_ctf_event_class *event_class, uint32_t id);
1547 struct bt_ctf_stream_class *bt_ctf_event_class_get_stream_class(struct bt_ctf_event_class *event_class);
1548 int bt_ctf_event_class_add_field(struct bt_ctf_event_class *event_class, struct bt_ctf_field_type *type, const char *name);
1549 int bt_ctf_event_class_get_field_count(struct bt_ctf_event_class *event_class);
1550 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, int index);
1551 struct bt_ctf_field_type *bt_ctf_event_class_get_field_by_name(struct bt_ctf_event_class *event_class, const char *name);
1552 void bt_ctf_event_class_get(struct bt_ctf_event_class *event_class);
1553 void bt_ctf_event_class_put(struct bt_ctf_event_class *event_class);
1556 %rename("_bt_ctf_event_create") bt_ctf_event_create(struct bt_ctf_event_class *event_class);
1557 %rename("_bt_ctf_event_get_class") bt_ctf_event_get_class(struct bt_ctf_event *event);
1558 %rename("_bt_ctf_event_get_clock") bt_ctf_event_get_clock(struct bt_ctf_event *event);
1559 %rename("_bt_ctf_event_get_payload") bt_ctf_event_get_payload(struct bt_ctf_event *event, const char *name);
1560 %rename("_bt_ctf_event_set_payload") bt_ctf_event_set_payload(struct bt_ctf_event *event, const char *name, struct bt_ctf_field *value);
1561 %rename("_bt_ctf_event_get_payload_by_index") bt_ctf_event_get_payload_by_index(struct bt_ctf_event *event, int index);
1562 %rename("_bt_ctf_event_get") bt_ctf_event_get(struct bt_ctf_event *event);
1563 %rename("_bt_ctf_event_put") bt_ctf_event_put(struct bt_ctf_event *event);
1565 struct bt_ctf_event *bt_ctf_event_create(struct bt_ctf_event_class *event_class);
1566 struct bt_ctf_event_class *bt_ctf_event_get_class(struct bt_ctf_event *event);
1567 struct bt_ctf_clock *bt_ctf_event_get_clock(struct bt_ctf_event *event);
1568 struct bt_ctf_field *bt_ctf_event_get_payload(struct bt_ctf_event *event, const char *name);
1569 int bt_ctf_event_set_payload(struct bt_ctf_event *event, const char *name, struct bt_ctf_field *value);
1570 struct bt_ctf_field *bt_ctf_event_get_payload_by_index(struct bt_ctf_event *event, int index);
1571 void bt_ctf_event_get(struct bt_ctf_event *event);
1572 void bt_ctf_event_put(struct bt_ctf_event *event);
1574 /* stream-class.h */
1575 %rename("_bt_ctf_stream_class_create") bt_ctf_stream_class_create(const char *name);
1576 %rename("_bt_ctf_stream_class_get_name") bt_ctf_stream_class_get_name(struct bt_ctf_stream_class *stream_class);
1577 %rename("_bt_ctf_stream_class_get_clock") bt_ctf_stream_class_get_clock(struct bt_ctf_stream_class *stream_class);
1578 %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);
1579 %rename("_bt_ctf_stream_class_get_id") bt_ctf_stream_class_get_id(struct bt_ctf_stream_class *stream_class);
1580 %rename("_bt_ctf_stream_class_set_id") bt_ctf_stream_class_set_id(struct bt_ctf_stream_class *stream_class, uint32_t id);
1581 %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);
1582 %rename("_bt_ctf_stream_class_get_event_class_count") bt_ctf_stream_class_get_event_class_count(struct bt_ctf_stream_class *stream_class);
1583 %rename("_bt_ctf_stream_class_get_event_class") bt_ctf_stream_class_get_event_class(struct bt_ctf_stream_class *stream_class, int index);
1584 %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);
1585 %rename("_bt_ctf_stream_class_get_packet_context_type") bt_ctf_stream_class_get_packet_context_type(struct bt_ctf_stream_class *stream_class);
1586 %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);
1587 %rename("_bt_ctf_stream_class_get") bt_ctf_stream_class_get(struct bt_ctf_stream_class *stream_class);
1588 %rename("_bt_ctf_stream_class_put") bt_ctf_stream_class_put(struct bt_ctf_stream_class *stream_class);
1590 struct bt_ctf_stream_class *bt_ctf_stream_class_create(const char *name);
1591 const char *bt_ctf_stream_class_get_name(struct bt_ctf_stream_class *stream_class);
1592 struct bt_ctf_clock *bt_ctf_stream_class_get_clock(struct bt_ctf_stream_class *stream_class);
1593 int bt_ctf_stream_class_set_clock(struct bt_ctf_stream_class *stream_class, struct bt_ctf_clock *clock);
1594 int64_t bt_ctf_stream_class_get_id(struct bt_ctf_stream_class *stream_class);
1595 int bt_ctf_stream_class_set_id(struct bt_ctf_stream_class *stream_class, uint32_t id);
1596 int bt_ctf_stream_class_add_event_class(struct bt_ctf_stream_class *stream_class, struct bt_ctf_event_class *event_class);
1597 int bt_ctf_stream_class_get_event_class_count(struct bt_ctf_stream_class *stream_class);
1598 struct bt_ctf_event_class *bt_ctf_stream_class_get_event_class(struct bt_ctf_stream_class *stream_class, int index);
1599 struct bt_ctf_event_class *bt_ctf_stream_class_get_event_class_by_name(struct bt_ctf_stream_class *stream_class, const char *name);
1600 struct bt_ctf_field_type *bt_ctf_stream_class_get_packet_context_type(struct bt_ctf_stream_class *stream_class);
1601 int bt_ctf_stream_class_set_packet_context_type(struct bt_ctf_stream_class *stream_class, struct bt_ctf_field_type *packet_context_type);
1602 void bt_ctf_stream_class_get(struct bt_ctf_stream_class *stream_class);
1603 void bt_ctf_stream_class_put(struct bt_ctf_stream_class *stream_class);
1606 %rename("_bt_ctf_stream_get_discarded_events_count") bt_ctf_stream_get_discarded_events_count(struct bt_ctf_stream *stream, uint64_t *count);
1607 %rename("_bt_ctf_stream_append_discarded_events") bt_ctf_stream_append_discarded_events(struct bt_ctf_stream *stream, uint64_t event_count);
1608 %rename("_bt_ctf_stream_append_event") bt_ctf_stream_append_event(struct bt_ctf_stream *stream, struct bt_ctf_event *event);
1609 %rename("_bt_ctf_stream_get_packet_context") bt_ctf_stream_get_packet_context(struct bt_ctf_stream *stream);
1610 %rename("_bt_ctf_stream_set_packet_context") bt_ctf_stream_set_packet_context(struct bt_ctf_stream *stream, struct bt_ctf_field *packet_context);
1611 %rename("_bt_ctf_stream_flush") bt_ctf_stream_flush(struct bt_ctf_stream *stream);
1612 %rename("_bt_ctf_stream_get") bt_ctf_stream_get(struct bt_ctf_stream *stream);
1613 %rename("_bt_ctf_stream_put") bt_ctf_stream_put(struct bt_ctf_stream *stream);
1615 int bt_ctf_stream_get_discarded_events_count(struct bt_ctf_stream *stream, uint64_t *OUTPUT);
1616 void bt_ctf_stream_append_discarded_events(struct bt_ctf_stream *stream, uint64_t event_count);
1617 int bt_ctf_stream_append_event(struct bt_ctf_stream *stream, struct bt_ctf_event *event);
1618 struct bt_ctf_field *bt_ctf_stream_get_packet_context(struct bt_ctf_stream *stream);
1619 int bt_ctf_stream_set_packet_context(struct bt_ctf_stream *stream, struct bt_ctf_field *packet_context);
1620 int bt_ctf_stream_flush(struct bt_ctf_stream *stream);
1621 void bt_ctf_stream_get(struct bt_ctf_stream *stream);
1622 void bt_ctf_stream_put(struct bt_ctf_stream *stream);
1625 %rename("_bt_ctf_writer_create") bt_ctf_writer_create(const char *path);
1626 %rename("_bt_ctf_writer_create_stream") bt_ctf_writer_create_stream(struct bt_ctf_writer *writer, struct bt_ctf_stream_class *stream_class);
1627 %rename("_bt_ctf_writer_add_environment_field") bt_ctf_writer_add_environment_field(struct bt_ctf_writer *writer, const char *name, const char *value);
1628 %rename("_bt_ctf_writer_add_clock") bt_ctf_writer_add_clock(struct bt_ctf_writer *writer, struct bt_ctf_clock *clock);
1629 %newobject bt_ctf_writer_get_metadata_string;
1630 %rename("_bt_ctf_writer_get_metadata_string") bt_ctf_writer_get_metadata_string(struct bt_ctf_writer *writer);
1631 %rename("_bt_ctf_writer_flush_metadata") bt_ctf_writer_flush_metadata(struct bt_ctf_writer *writer);
1632 %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);
1633 %rename("_bt_ctf_writer_get") bt_ctf_writer_get(struct bt_ctf_writer *writer);
1634 %rename("_bt_ctf_writer_put") bt_ctf_writer_put(struct bt_ctf_writer *writer);
1636 struct bt_ctf_writer *bt_ctf_writer_create(const char *path);
1637 struct bt_ctf_stream *bt_ctf_writer_create_stream(struct bt_ctf_writer *writer, struct bt_ctf_stream_class *stream_class);
1638 int bt_ctf_writer_add_environment_field(struct bt_ctf_writer *writer, const char *name, const char *value);
1639 int bt_ctf_writer_add_clock(struct bt_ctf_writer *writer, struct bt_ctf_clock *clock);
1640 char *bt_ctf_writer_get_metadata_string(struct bt_ctf_writer *writer);
1641 void bt_ctf_writer_flush_metadata(struct bt_ctf_writer *writer);
1642 int bt_ctf_writer_set_byte_order(struct bt_ctf_writer *writer, enum bt_ctf_byte_order byte_order);
1643 void bt_ctf_writer_get(struct bt_ctf_writer *writer);
1644 void bt_ctf_writer_put(struct bt_ctf_writer *writer);
1648 from uuid import UUID
1652 # Used to compare to -1ULL in error checks
1653 _MAX_UINT64 = 0xFFFFFFFFFFFFFFFF
1656 Enumeration mapping class. start and end values are inclusive.
1658 class EnumerationMapping:
1660 def __init__(self, name, start, end):
1667 def __init__(self, name):
1668 self._c = _bt_ctf_clock_create(name)
1670 raise ValueError("Invalid clock name.")
1673 _bt_ctf_clock_put(self._c)
1676 Get the clock's name.
1680 name = _bt_ctf_clock_get_name(self._c)
1682 raise ValueError("Invalid clock instance.")
1686 Get the clock's description. None if unset.
1689 def description(self):
1690 return _bt_ctf_clock_get_description(self._c)
1693 Set the clock's description. The description appears in the clock's TSDL
1697 def description(self, desc):
1698 ret = _bt_ctf_clock_set_description(self._c, str(desc))
1700 raise ValueError("Invalid clock description.")
1703 Get the clock's frequency (Hz).
1706 def frequency(self):
1707 freq = _bt_ctf_clock_get_frequency(self._c)
1708 if freq == CTFWriter._MAX_UINT64:
1709 raise ValueError("Invalid clock instance")
1713 Set the clock's frequency (Hz).
1716 def frequency(self, freq):
1717 ret = _bt_ctf_clock_set_frequency(self._c, freq)
1719 raise ValueError("Invalid frequency value.")
1722 Get the clock's precision (in clock ticks).
1725 def precision(self):
1726 precision = _bt_ctf_clock_get_precision(self._c)
1727 if precision == CTFWriter._MAX_UINT64:
1728 raise ValueError("Invalid clock instance")
1732 Set the clock's precision (in clock ticks).
1735 def precision(self, precision):
1736 ret = _bt_ctf_clock_set_precision(self._c, precision)
1739 Get the clock's offset in seconds from POSIX.1 Epoch.
1742 def offset_seconds(self):
1743 offset_s = _bt_ctf_clock_get_offset_s(self._c)
1744 if offset_s == CTFWriter._MAX_UINT64:
1745 raise ValueError("Invalid clock instance")
1749 Set the clock's offset in seconds from POSIX.1 Epoch.
1751 @offset_seconds.setter
1752 def offset_seconds(self, offset_s):
1753 ret = _bt_ctf_clock_set_offset_s(self._c, offset_s)
1755 raise ValueError("Invalid offset value.")
1758 Get the clock's offset in ticks from POSIX.1 Epoch + offset in seconds.
1762 offset = _bt_ctf_clock_get_offset(self._c)
1763 if offset == CTFWriter._MAX_UINT64:
1764 raise ValueError("Invalid clock instance")
1768 Set the clock's offset in ticks from POSIX.1 Epoch + offset in seconds.
1771 def offset(self, offset):
1772 ret = _bt_ctf_clock_set_offset(self._c, offset)
1774 raise ValueError("Invalid offset value.")
1777 Get a clock's absolute attribute. A clock is absolute if the clock
1778 is a global reference across the trace's other clocks.
1782 is_absolute = _bt_ctf_clock_get_is_absolute(self._c)
1783 if is_absolute == -1:
1784 raise ValueError("Invalid clock instance")
1785 return False if is_absolute == 0 else True
1788 Set a clock's absolute attribute. A clock is absolute if the clock
1789 is a global reference across the trace's other clocks.
1792 def absolute(self, is_absolute):
1793 ret = _bt_ctf_clock_set_is_absolute(self._c, int(is_absolute))
1796 "Could not set the clock's absolute attribute.")
1799 Get a clock's UUID (an object of type UUID).
1805 ret, value = _bt_python_ctf_clock_get_uuid_index(self._c, i)
1807 raise ValueError("Invalid clock instance")
1808 uuid_list.append(value)
1809 return UUID(bytes=bytes(uuid_list))
1812 Set a clock's UUID (an object of type UUID).
1815 def uuid(self, uuid):
1816 uuid_bytes = uuid.bytes
1817 if len(uuid_bytes) != 16:
1819 "Invalid UUID provided. UUID length must be 16 bytes")
1820 for i in range(len(uuid_bytes)):
1821 ret = _bt_python_ctf_clock_set_uuid_index(
1826 raise ValueError("Invalid clock instance")
1829 Get the current time in nanoseconds since the clock's origin (offset and
1830 offset_s attributes).
1834 time = _bt_ctf_clock_get_time(self._c)
1835 if time == CTFWriter._MAX_UINT64:
1836 raise ValueError("Invalid clock instance")
1840 Set the current time in nanoseconds since the clock's origin (offset and
1841 offset_s attributes). The clock's value will be sampled as events are
1842 appended to a stream.
1845 def time(self, time):
1846 ret = _bt_ctf_clock_set_time(self._c, time)
1848 raise ValueError("Invalid time value.")
1850 class FieldDeclaration:
1853 FieldDeclaration should not be instantiated directly. Instantiate
1854 one of the concrete FieldDeclaration classes.
1857 # These values are based on the bt_ctf_integer_base enum
1858 # declared in event-types.h.
1859 INTEGER_BASE_UNKNOWN = -1
1860 INTEGER_BASE_BINARY = 2
1861 INTEGER_BASE_OCTAL = 8
1862 INTEGER_BASE_DECIMAL = 10
1863 INTEGER_BASE_HEXADECIMAL = 16
1866 if self._ft is None:
1867 raise ValueError("FieldDeclaration creation failed.")
1870 _bt_ctf_field_type_put(self._ft)
1873 def _create_field_declaration_from_native_instance(
1874 native_field_declaration):
1876 CTFTypeId.INTEGER: CTFWriter.IntegerFieldDeclaration,
1877 CTFTypeId.FLOAT: CTFWriter.FloatFieldDeclaration,
1878 CTFTypeId.ENUM: CTFWriter.EnumerationFieldDeclaration,
1879 CTFTypeId.STRING: CTFWriter.StringFieldDeclaration,
1880 CTFTypeId.STRUCT: CTFWriter.StructureFieldDeclaration,
1881 CTFTypeId.VARIANT: CTFWriter.VariantFieldDeclaration,
1882 CTFTypeId.ARRAY: CTFWriter.ArrayFieldDeclaration,
1883 CTFTypeId.SEQUENCE: CTFWriter.SequenceFieldDeclaration
1886 field_type_id = _bt_ctf_field_type_get_type_id(
1887 native_field_declaration)
1888 if field_type_id == CTFTypeId.UNKNOWN:
1889 raise TypeError("Invalid field instance")
1891 declaration = CTFWriter.Field.__new__(CTFWriter.Field)
1892 declaration._ft = native_field_declaration
1893 declaration.__class__ = type_dict[field_type_id]
1897 Get the field declaration's alignment. Returns -1 on error.
1900 def alignment(self):
1901 return _bt_ctf_field_type_get_alignment(self._ft)
1904 Set the field declaration's alignment. Defaults to 1 (bit-aligned). However,
1905 some types, such as structures and string, may impose other alignment
1909 def alignment(self, alignment):
1910 ret = _bt_ctf_field_type_set_alignment(self._ft, alignment)
1912 raise ValueError("Invalid alignment value.")
1915 Get the field declaration's byte order. One of the ByteOrder's constant.
1918 def byte_order(self):
1919 return _bt_ctf_field_type_get_byte_order(self._ft)
1922 Set the field declaration's byte order. Use constants defined in the ByteOrder
1926 def byte_order(self, byte_order):
1927 ret = _bt_ctf_field_type_set_byte_order(self._ft, byte_order)
1929 raise ValueError("Could not set byte order value.")
1931 class IntegerFieldDeclaration(FieldDeclaration):
1934 Create a new integer field declaration of the given size.
1937 def __init__(self, size):
1938 self._ft = _bt_ctf_field_type_integer_create(size)
1942 Get an integer's size.
1946 ret = _bt_ctf_field_type_integer_get_size(self._ft)
1948 raise ValueError("Could not get Integer's size attribute.")
1953 Get an integer's signedness attribute.
1957 ret = _bt_ctf_field_type_integer_get_signed(self._ft)
1959 raise ValueError("Could not get Integer's signed attribute.")
1966 Set an integer's signedness attribute.
1969 def signed(self, signed):
1970 ret = _bt_ctf_field_type_integer_set_signed(self._ft, signed)
1972 raise ValueError("Could not set Integer's signed attribute.")
1975 Get the integer's base used to pretty-print the resulting trace.
1976 Returns a constant from the FieldDeclaration.IntegerBase class.
1980 return _bt_ctf_field_type_integer_get_base(self._ft)
1983 Set the integer's base used to pretty-print the resulting trace.
1984 The base must be a constant of the FieldDeclarationIntegerBase class.
1987 def base(self, base):
1988 ret = _bt_ctf_field_type_integer_set_base(self._ft, base)
1990 raise ValueError("Could not set Integer's base.")
1993 Get the integer's encoding (one of the constants of the
1994 CTFStringEncoding class).
1995 Returns a constant from the CTFStringEncoding class.
1999 return _bt_ctf_field_type_integer_get_encoding(self._ft)
2002 An integer encoding may be set to signal that the integer must be printed
2003 as a text character. Must be a constant from the CTFStringEncoding class.
2006 def encoding(self, encoding):
2007 ret = _bt_ctf_field_type_integer_set_encoding(self._ft, encoding)
2009 raise ValueError("Could not set Integer's encoding.")
2011 class EnumerationFieldDeclaration(FieldDeclaration):
2014 Create a new enumeration field declaration with the given underlying container type.
2017 def __init__(self, integer_type):
2018 if integer_type is None or not isinstance(
2019 integer_type, CTFWriter.IntegerFieldDeclaration):
2020 raise TypeError("Invalid integer container.")
2022 self._ft = _bt_ctf_field_type_enumeration_create(integer_type._ft)
2026 Get the enumeration's underlying container type.
2029 def container(self):
2030 ret = _bt_ctf_field_type_enumeration_get_container_type(self._ft)
2032 raise TypeError("Invalid enumeration declaration")
2033 return CTFWriter.FieldDeclaration._create_field_declaration_from_native_instance(
2037 Add a mapping to the enumeration. The range's values are inclusive.
2040 def add_mapping(self, name, range_start, range_end):
2041 if range_start < 0 or range_end < 0:
2042 ret = _bt_ctf_field_type_enumeration_add_mapping(
2048 ret = _bt_ctf_field_type_enumeration_add_mapping_unsigned(
2056 "Could not add mapping to enumeration declaration.")
2059 Generator returning instances of EnumerationMapping.
2063 signed = self.container.signed
2065 count = _bt_ctf_field_type_enumeration_get_mapping_count(self._ft)
2066 for i in range(count):
2068 ret = _bt_python_ctf_field_type_enumeration_get_mapping(
2072 ret = _bt_python_ctf_field_type_enumeration_get_mapping_unsigned(
2078 "Could not get Enumeration mapping at index {}".format(i))
2079 name, range_start, range_end = ret
2080 yield CTFWriter.EnumerationMapping(name, range_start, range_end)
2083 Get a mapping by name (EnumerationMapping).
2086 def get_mapping_by_name(self, name):
2087 index = _bt_ctf_field_type_enumeration_get_mapping_index_by_name(
2092 if self.container.signed:
2093 ret = _bt_python_ctf_field_type_enumeration_get_mapping(
2097 ret = _bt_python_ctf_field_type_enumeration_get_mapping_unsigned(
2103 "Could not get Enumeration mapping at index {}".format(i))
2104 name, range_start, range_end = ret
2105 return CTFWriter.EnumerationMapping(name, range_start, range_end)
2108 Get a mapping by value (EnumerationMapping).
2111 def get_mapping_by_value(self, value):
2113 index = _bt_ctf_field_type_enumeration_get_mapping_index_by_value(
2116 index = _bt_ctf_field_type_enumeration_get_mapping_index_by_unsigned_value(
2122 if self.container.signed:
2123 ret = _bt_python_ctf_field_type_enumeration_get_mapping(
2127 ret = _bt_python_ctf_field_type_enumeration_get_mapping_unsigned(
2133 "Could not get Enumeration mapping at index {}".format(i))
2134 name, range_start, range_end = ret
2135 return CTFWriter.EnumerationMapping(name, range_start, range_end)
2137 class FloatFieldDeclaration(FieldDeclaration):
2144 Create a new floating point field declaration.
2148 self._ft = _bt_ctf_field_type_floating_point_create()
2152 Get the number of exponent digits used to store the floating point field.
2155 def exponent_digits(self):
2156 ret = _bt_ctf_field_type_floating_point_get_exponent_digits(
2160 "Could not get Floating point exponent digit count")
2164 Set the number of exponent digits to use to store the floating point field.
2165 The only values currently supported are FLT_EXP_DIG and DBL_EXP_DIG which
2166 are defined as constants of this class.
2168 @exponent_digits.setter
2169 def exponent_digits(self, exponent_digits):
2170 ret = _bt_ctf_field_type_floating_point_set_exponent_digits(
2174 raise ValueError("Could not set exponent digit count.")
2177 Get the number of mantissa digits used to store the floating point field.
2180 def mantissa_digits(self):
2181 ret = _bt_ctf_field_type_floating_point_get_mantissa_digits(
2185 "Could not get Floating point mantissa digit count")
2189 Set the number of mantissa digits to use to store the floating point field.
2190 The only values currently supported are FLT_MANT_DIG and DBL_MANT_DIG which
2191 are defined as constants of this class.
2193 @mantissa_digits.setter
2194 def mantissa_digits(self, mantissa_digits):
2195 ret = _bt_ctf_field_type_floating_point_set_mantissa_digits(
2199 raise ValueError("Could not set mantissa digit count.")
2201 class StructureFieldDeclaration(FieldDeclaration):
2204 Create a new structure field declaration.
2208 self._ft = _bt_ctf_field_type_structure_create()
2212 Add a field of type "field_type" to the structure.
2215 def add_field(self, field_type, field_name):
2216 ret = _bt_ctf_field_type_structure_add_field(
2221 raise ValueError("Could not add field to structure.")
2224 Generator returning the structure's field as tuples of (field name, field declaration).
2228 count = _bt_ctf_field_type_structure_get_field_count(self._ft)
2230 raise TypeError("Could not get Structure field count")
2232 for i in range(count):
2233 field_name = _bt_python_ctf_field_type_structure_get_field_name(
2236 if field_name is None:
2238 "Could not get Structure field name at index {}".format(i))
2240 field_type_native = _bt_python_ctf_field_type_structure_get_field_type(
2243 if field_type_native is None:
2245 "Could not get Structure field type at index {}".format(i))
2247 field_type = CTFWriter.FieldDeclaration._create_field_declaration_from_native_instance(
2249 yield (field_name, field_type)
2252 Get a field declaration by name (FieldDeclaration).
2255 def get_field_by_name(self, name):
2256 field_type_native = _bt_ctf_field_type_structure_get_field_type_by_name(
2259 if field_type_native is None:
2261 "Could not find Structure field with name {}".format(name))
2263 return CTFWriter.FieldDeclaration._create_field_declaration_from_native_instance(
2266 class VariantFieldDeclaration(FieldDeclaration):
2269 Create a new variant field declaration.
2272 def __init__(self, enum_tag, tag_name):
2273 if enum_tag is None or not isinstance(
2274 enum_tag, CTFWriter.EnumerationFieldDeclaration):
2276 "Invalid tag type; must be of type EnumerationFieldDeclaration.")
2278 self._ft = _bt_ctf_field_type_variant_create(
2284 Get the variant's tag name.
2288 ret = _bt_ctf_field_type_variant_get_tag_name(self._ft)
2290 raise TypeError("Could not get Variant tag name")
2294 Get the variant's tag type.
2298 ret = _bt_ctf_field_type_variant_get_tag_type(self._ft)
2300 raise TypeError("Could not get Variant tag type")
2301 return CTFWriter.FieldDeclaration._create_field_declaration_from_native_instance(
2305 Add a field of type "field_type" to the variant.
2308 def add_field(self, field_type, field_name):
2309 ret = _bt_ctf_field_type_variant_add_field(
2314 raise ValueError("Could not add field to variant.")
2317 Generator returning the variant's field as tuples of (field name, field declaration).
2321 count = _bt_ctf_field_type_variant_get_field_count(self._ft)
2323 raise TypeError("Could not get Variant field count")
2325 for i in range(count):
2326 field_name = _bt_python_ctf_field_type_variant_get_field_name(
2329 if field_name is None:
2331 "Could not get Variant field name at index {}".format(i))
2333 field_type_native = _bt_python_ctf_field_type_variant_get_field_type(
2336 if field_type_native is None:
2338 "Could not get Variant field type at index {}".format(i))
2340 field_type = CTFWriter.FieldDeclaration._create_field_declaration_from_native_instance(
2342 yield (field_name, field_type)
2345 Get a field declaration by name (FieldDeclaration).
2348 def get_field_by_name(self, name):
2349 field_type_native = _bt_ctf_field_type_variant_get_field_type_by_name(
2352 if field_type_native is None:
2354 "Could not find Variant field with name {}".format(name))
2356 return CTFWriter.FieldDeclaration._create_field_declaration_from_native_instance(
2360 Get a field declaration from tag (EnumerationField).
2363 def get_field_from_tag(self, tag):
2364 field_type_native = _bt_ctf_field_type_variant_get_field_type_from_tag(
2367 if field_type_native is None:
2369 "Could not find Variant field with tag value {}".format(
2372 return CTFWriter.FieldDeclaration._create_field_declaration_from_native_instance(
2375 class ArrayFieldDeclaration(FieldDeclaration):
2378 Create a new array field declaration.
2381 def __init__(self, element_type, length):
2382 self._ft = _bt_ctf_field_type_array_create(
2388 Get the array's element type.
2391 def element_type(self):
2392 ret = _bt_ctf_field_type_array_get_element_type(self._ft)
2394 raise TypeError("Could not get Array element type")
2395 return CTFWriter.FieldDeclaration._create_field_declaration_from_native_instance(
2399 Get the array's length.
2403 ret = _bt_ctf_field_type_array_get_length(self._ft)
2405 raise TypeError("Could not get Array length")
2408 class SequenceFieldDeclaration(FieldDeclaration):
2411 Create a new sequence field declaration.
2414 def __init__(self, element_type, length_field_name):
2415 self._ft = _bt_ctf_field_type_sequence_create(
2417 str(length_field_name))
2421 Get the sequence's element type.
2424 def element_type(self):
2425 ret = _bt_ctf_field_type_sequence_get_element_type(self._ft)
2427 raise TypeError("Could not get Sequence element type")
2428 return CTFWriter.FieldDeclaration._create_field_declaration_from_native_instance(
2432 Get the sequence's length field name.
2435 def length_field_name(self):
2436 ret = _bt_ctf_field_type_sequence_get_length_field_name(self._ft)
2438 raise TypeError("Could not get Sequence length field name")
2441 class StringFieldDeclaration(FieldDeclaration):
2444 Create a new string field declaration.
2448 self._ft = _bt_ctf_field_type_string_create()
2452 Get a string declaration's encoding (a constant from the CTFStringEncoding class).
2456 return _bt_ctf_field_type_string_get_encoding(self._ft)
2459 Set a string declaration's encoding. Must be a constant from the CTFStringEncoding class.
2462 def encoding(self, encoding):
2463 ret = _bt_ctf_field_type_string_set_encoding(self._ft, encoding)
2465 raise ValueError("Could not set string encoding.")
2468 Create an instance of a field.
2471 def create_field(field_type):
2472 if field_type is None or not isinstance(
2473 field_type, CTFWriter.FieldDeclaration):
2475 "Invalid field_type. Type must be a FieldDeclaration-derived class.")
2477 if isinstance(field_type, CTFWriter.IntegerFieldDeclaration):
2478 return CTFWriter.IntegerField(field_type)
2479 elif isinstance(field_type, CTFWriter.EnumerationFieldDeclaration):
2480 return CTFWriter.EnumerationField(field_type)
2481 elif isinstance(field_type, CTFWriter.FloatFieldDeclaration):
2482 return CTFWriter.FloatFieldingPoint(field_type)
2483 elif isinstance(field_type, CTFWriter.StructureFieldDeclaration):
2484 return CTFWriter.StructureField(field_type)
2485 elif isinstance(field_type, CTFWriter.VariantFieldDeclaration):
2486 return CTFWriter.VariantField(field_type)
2487 elif isinstance(field_type, CTFWriter.ArrayFieldDeclaration):
2488 return CTFWriter.ArrayField(field_type)
2489 elif isinstance(field_type, CTFWriter.SequenceFieldDeclaration):
2490 return CTFWriter.SequenceField(field_type)
2491 elif isinstance(field_type, CTFWriter.StringFieldDeclaration):
2492 return CTFWriter.StringField(field_type)
2497 Base class, do not instantiate.
2500 def __init__(self, field_type):
2501 if not isinstance(field_type, CTFWriter.FieldDeclaration):
2502 raise TypeError("Invalid field_type argument.")
2504 self._f = _bt_ctf_field_create(field_type._ft)
2506 raise ValueError("Field creation failed.")
2509 _bt_ctf_field_put(self._f)
2512 def _create_field_from_native_instance(native_field_instance):
2514 CTFTypeId.INTEGER: CTFWriter.IntegerField,
2515 CTFTypeId.FLOAT: CTFWriter.FloatFieldingPoint,
2516 CTFTypeId.ENUM: CTFWriter.EnumerationField,
2517 CTFTypeId.STRING: CTFWriter.StringField,
2518 CTFTypeId.STRUCT: CTFWriter.StructureField,
2519 CTFTypeId.VARIANT: CTFWriter.VariantField,
2520 CTFTypeId.ARRAY: CTFWriter.ArrayField,
2521 CTFTypeId.SEQUENCE: CTFWriter.SequenceField
2524 field_type = _bt_python_get_field_type(native_field_instance)
2525 if field_type == CTFTypeId.UNKNOWN:
2526 raise TypeError("Invalid field instance")
2528 field = CTFWriter.Field.__new__(CTFWriter.Field)
2529 field._f = native_field_instance
2530 field.__class__ = type_dict[field_type]
2534 def declaration(self):
2535 native_field_type = _bt_ctf_field_get_type(self._f)
2536 if native_field_type is None:
2537 raise TypeError("Invalid field instance")
2538 return CTFWriter.FieldDeclaration._create_field_declaration_from_native_instance(
2541 class IntegerField(Field):
2544 Get an integer field's value.
2548 signedness = _bt_python_field_integer_get_signedness(self._f)
2550 raise TypeError("Invalid integer instance.")
2553 ret, value = _bt_ctf_field_unsigned_integer_get_value(self._f)
2555 ret, value = _bt_ctf_field_signed_integer_get_value(self._f)
2558 raise ValueError("Could not get integer field value.")
2562 Set an integer field's value.
2565 def value(self, value):
2566 if not isinstance(value, int):
2567 raise TypeError("IntegerField's value must be an int")
2569 signedness = _bt_python_field_integer_get_signedness(self._f)
2571 raise TypeError("Invalid integer instance.")
2574 ret = _bt_ctf_field_unsigned_integer_set_value(self._f, value)
2576 ret = _bt_ctf_field_signed_integer_set_value(self._f, value)
2579 raise ValueError("Could not set integer field value.")
2581 class EnumerationField(Field):
2584 Return the enumeration's underlying container field (an integer field).
2587 def container(self):
2588 container = CTFWriter.IntegerField.__new__(CTFWriter.IntegerField)
2589 container._f = _bt_ctf_field_enumeration_get_container(self._f)
2590 if container._f is None:
2591 raise TypeError("Invalid enumeration field type.")
2595 Get the enumeration field's mapping name.
2599 value = _bt_ctf_field_enumeration_get_mapping_name(self._f)
2601 raise ValueError("Could not get enumeration's mapping name.")
2605 Set the enumeration field's value. Must be an integer as mapping names
2609 def value(self, value):
2610 if not isinstance(value, int):
2611 raise TypeError("EnumerationField value must be an int")
2612 self.container.value = value
2614 class FloatFieldingPoint(Field):
2617 Get a floating point field's value.
2621 ret, value = _bt_ctf_field_floating_point_get_value(self._f)
2623 raise ValueError("Could not get floating point field value.")
2627 Set a floating point field's value.
2630 def value(self, value):
2631 if not isinstance(value, int) and not isinstance(value, float):
2632 raise TypeError("Value must be either a float or an int")
2634 ret = _bt_ctf_field_floating_point_set_value(self._f, float(value))
2636 raise ValueError("Could not set floating point field value.")
2638 class StructureField(Field):
2641 Get the structure's field corresponding to the provided field name.
2644 def field(self, field_name):
2645 native_instance = _bt_ctf_field_structure_get_field(
2648 if native_instance is None:
2649 raise ValueError("Invalid field_name provided.")
2650 return CTFWriter.Field._create_field_from_native_instance(
2653 class VariantField(Field):
2656 Return the variant's selected field. The "tag" field is the selector enum field.
2659 def field(self, tag):
2660 native_instance = _bt_ctf_field_variant_get_field(self._f, tag._f)
2661 if native_instance is None:
2662 raise ValueError("Invalid tag provided.")
2663 return CTFWriter.Field._create_field_from_native_instance(
2666 class ArrayField(Field):
2669 Return the array's field at position "index".
2672 def field(self, index):
2673 native_instance = _bt_ctf_field_array_get_field(self._f, index)
2674 if native_instance is None:
2675 raise IndexError("Invalid index provided.")
2676 return CTFWriter.Field._create_field_from_native_instance(
2679 class SequenceField(Field):
2682 Get the sequence's length field (IntegerField).
2686 native_instance = _bt_ctf_field_sequence_get_length(self._f)
2687 if native_instance is None:
2689 return CTFWriter.Field._create_field_from_native_instance(
2693 Set the sequence's length field (IntegerField).
2696 def length(self, length_field):
2697 if not isinstance(length_field, CTFWriter.IntegerField):
2698 raise TypeError("Invalid length field.")
2699 if length_field.declaration.signed:
2700 raise TypeError("Sequence field length must be unsigned")
2701 ret = _bt_ctf_field_sequence_set_length(self._f, length_field._f)
2703 raise ValueError("Could not set sequence length.")
2706 Return the sequence's field at position "index".
2709 def field(self, index):
2710 native_instance = _bt_ctf_field_sequence_get_field(self._f, index)
2711 if native_instance is None:
2712 raise ValueError("Could not get sequence element at index.")
2713 return CTFWriter.Field._create_field_from_native_instance(
2716 class StringField(Field):
2719 Get a string field's value.
2723 return _bt_ctf_field_string_get_value(self._f)
2726 Set a string field's value.
2729 def value(self, value):
2730 ret = _bt_ctf_field_string_set_value(self._f, str(value))
2732 raise ValueError("Could not set string field value.")
2737 Create a new event class of the given name.
2740 def __init__(self, name):
2741 self._ec = _bt_ctf_event_class_create(name)
2742 if self._ec is None:
2743 raise ValueError("Event class creation failed.")
2746 _bt_ctf_event_class_put(self._ec)
2749 Add a field of type "field_type" to the event class.
2752 def add_field(self, field_type, field_name):
2753 ret = _bt_ctf_event_class_add_field(
2758 raise ValueError("Could not add field to event class.")
2761 Get the event class' name.
2765 name = _bt_ctf_event_class_get_name(self._ec)
2767 raise TypeError("Could not get EventClass name")
2771 Get the event class' id. Returns a negative value if unset.
2775 id = _bt_ctf_event_class_get_id(self._ec)
2777 raise TypeError("Could not get EventClass id")
2781 Set the event class' id. Throws a TypeError if the event class
2782 is already registered to a stream class.
2786 ret = _bt_ctf_event_class_set_id(self._ec, id)
2789 "Can't change an Event Class's id after it has been assigned to a stream class")
2792 Get the event class' stream class. Returns None if unset.
2795 def stream_class(self):
2796 stream_class_native = _bt_ctf_event_class_get_stream_class(
2798 if stream_class_native is None:
2800 stream_class = CTFWriter.StreamClass.__new__(CTFWriter.StreamClass)
2801 stream_class._sc = stream_class_native
2805 Generator returning the event class' fields as tuples of (field name, field declaration).
2809 count = _bt_ctf_event_class_get_field_count(self._ec)
2811 raise TypeError("Could not get EventClass' field count")
2813 for i in range(count):
2814 field_name = _bt_python_ctf_event_class_get_field_name(
2817 if field_name is None:
2819 "Could not get EventClass' field name at index {}".format(i))
2821 field_type_native = _bt_python_ctf_event_class_get_field_type(
2824 if field_type_native is None:
2826 "Could not get EventClass' field type at index {}".format(i))
2828 field_type = CTFWriter.FieldDeclaration._create_field_declaration_from_native_instance(
2830 yield (field_name, field_type)
2833 Get a field declaration by name (FieldDeclaration).
2836 def get_field_by_name(self, name):
2837 field_type_native = _bt_ctf_event_class_get_field_by_name(
2840 if field_type_native is None:
2842 "Could not find EventClass field with name {}".format(name))
2843 return CTFWriter.FieldDeclaration._create_field_declaration_from_native_instance(
2849 Create a new event of the given event class.
2852 def __init__(self, event_class):
2853 if not isinstance(event_class, CTFWriter.EventClass):
2854 raise TypeError("Invalid event_class argument.")
2856 self._e = _bt_ctf_event_create(event_class._ec)
2858 raise ValueError("Event creation failed.")
2861 _bt_ctf_event_put(self._e)
2864 Get the event's class.
2867 def event_class(self):
2868 event_class_native = _bt_ctf_event_get_class(self._e)
2869 if event_class_native is None:
2871 event_class = CTFWriter.EventClass.__new__(CTFWriter.EventClass)
2872 event_class._ec = event_class_native
2876 Get a clock from event. Returns None if the event's class
2877 is not registered to a stream class.
2881 clock_instance = _bt_ctf_event_get_clock(self._e)
2882 if clock_instance is None:
2884 clock = CTFWriter.Clock.__new__(CTFWriter.Clock)
2885 clock._c = clock_instance
2889 Get a field from event.
2892 def payload(self, field_name):
2893 native_instance = _bt_ctf_event_get_payload(
2896 if native_instance is None:
2897 raise ValueError("Could not get event payload.")
2898 return CTFWriter.Field._create_field_from_native_instance(
2902 Set a manually created field as an event's payload.
2905 def set_payload(self, field_name, value_field):
2906 if not isinstance(value, CTFWriter.Field):
2907 raise TypeError("Invalid value type.")
2908 ret = _bt_ctf_event_set_payload(
2913 raise ValueError("Could not set event field payload.")
2918 Create a new stream class of the given name.
2921 def __init__(self, name):
2922 self._sc = _bt_ctf_stream_class_create(name)
2923 if self._sc is None:
2924 raise ValueError("Stream class creation failed.")
2927 _bt_ctf_stream_class_put(self._sc)
2930 Get a stream class' name.
2934 name = _bt_ctf_stream_class_get_name(self._sc)
2936 raise TypeError("Could not get StreamClass name")
2940 Get a stream class' clock.
2944 clock_instance = _bt_ctf_stream_class_get_clock(self._sc)
2945 if clock_instance is None:
2947 clock = CTFWriter.Clock.__new__(CTFWriter.Clock)
2948 clock._c = clock_instance
2952 Assign a clock to a stream class.
2955 def clock(self, clock):
2956 if not isinstance(clock, CTFWriter.Clock):
2957 raise TypeError("Invalid clock type.")
2959 ret = _bt_ctf_stream_class_set_clock(self._sc, clock._c)
2961 raise ValueError("Could not set stream class clock.")
2964 Get a stream class' id.
2968 ret = _bt_ctf_stream_class_get_id(self._sc)
2970 raise TypeError("Could not get StreamClass id")
2974 Assign an id to a stream class.
2978 ret = _bt_ctf_stream_class_set_id(self._sc, id)
2980 raise TypeError("Could not set stream class id.")
2983 Generator returning the stream class' event classes.
2986 def event_classes(self):
2987 count = _bt_ctf_stream_class_get_event_class_count(self._sc)
2989 raise TypeError("Could not get StreamClass' event class count")
2991 for i in range(count):
2992 event_class_native = _bt_ctf_stream_class_get_event_class(
2995 if event_class_native is None:
2997 "Could not get StreamClass' event class at index {}".format(i))
2999 event_class = CTFWriter.EventClass.__new__(
3000 CTFWriter.EventClass)
3001 event_class._ec = event_class_native
3005 Add an event class to a stream class. New events can be added even after a
3006 stream has been instantiated and events have been appended. However, a stream
3007 will not accept events of a class that has not been added to the stream
3011 def add_event_class(self, event_class):
3012 if not isinstance(event_class, CTFWriter.EventClass):
3013 raise TypeError("Invalid event_class type.")
3015 ret = _bt_ctf_stream_class_add_event_class(
3019 raise ValueError("Could not add event class.")
3022 Get the StreamClass' packet context type (StructureFieldDeclaration)
3025 def packet_context_type(self):
3026 field_type_native = _bt_ctf_stream_class_get_packet_context_type(
3028 if field_type_native is None:
3029 raise ValueError("Invalid StreamClass")
3030 field_type = CTFWriter.FieldDeclaration._create_field_declaration_from_native_instance(
3035 Set a StreamClass' packet context type. Must be of type
3036 StructureFieldDeclaration.
3038 @packet_context_type.setter
3039 def packet_context_type(self, field_type):
3040 if not isinstance(field_type, CTFWriter.StructureFieldDeclaration):
3042 "field_type argument must be of type StructureFieldDeclaration.")
3043 ret = _bt_ctf_stream_class_set_packet_context_type(
3047 raise ValueError("Failed to set packet context type.")
3052 Create a stream of the given class.
3055 def __init__(self, stream_class):
3056 if not isinstance(stream_class, CTFWriter.StreamClass):
3058 "Invalid stream_class argument must be of type StreamClass.")
3060 self._s = _bt_ctf_stream_create(stream_class._sc)
3062 raise ValueError("Stream creation failed.")
3065 _bt_ctf_stream_put(self._s)
3068 Get a stream's discarded event count.
3071 def discarded_events(self):
3072 ret, count = _bt_ctf_stream_get_discarded_events_count(self._s)
3075 "Could not get the stream's discarded events count")
3079 Increase the current packet's discarded event count.
3082 def append_discarded_events(self, event_count):
3083 _bt_ctf_stream_append_discarded_events(self._s, event_count)
3086 Append "event" to the stream's current packet. The stream's associated clock
3087 will be sampled during this call. The event shall not be modified after
3088 being appended to a stream.
3091 def append_event(self, event):
3092 ret = _bt_ctf_stream_append_event(self._s, event._e)
3094 raise ValueError("Could not append event to stream.")
3097 Get a Stream's packet context field (a StructureField).
3100 def packet_context(self):
3101 native_field = _bt_ctf_stream_get_packet_context(self._s)
3102 if native_field is None:
3103 raise ValueError("Invalid Stream.")
3104 return CTFWriter.Field._create_field_from_native_instance(
3108 Set a Stream's packet context field (must be a StructureField).
3110 @packet_context.setter
3111 def packet_context(self, field):
3112 if not isinstance(field, CTFWriter.StructureField):
3114 "Argument field must be of type StructureField")
3115 ret = _bt_ctf_stream_set_packet_context(self._s, field._f)
3117 raise ValueError("Invalid packet context field.")
3120 The stream's current packet's events will be flushed to disk. Events
3121 subsequently appended to the stream will be added to a new packet.
3125 ret = _bt_ctf_stream_flush(self._s)
3127 raise ValueError("Could not flush stream.")
3132 Create a new writer that will produce a trace in the given path.
3135 def __init__(self, path):
3136 self._w = _bt_ctf_writer_create(path)
3138 raise ValueError("Writer creation failed.")
3141 _bt_ctf_writer_put(self._w)
3144 Create a new stream instance and register it to the writer.
3147 def create_stream(self, stream_class):
3148 if not isinstance(stream_class, CTFWriter.StreamClass):
3149 raise TypeError("Invalid stream_class type.")
3151 stream = CTFWriter.Stream.__new__(CTFWriter.Stream)
3152 stream._s = _bt_ctf_writer_create_stream(self._w, stream_class._sc)
3156 Add an environment field to the trace.
3159 def add_environment_field(self, name, value):
3160 ret = _bt_ctf_writer_add_environment_field(
3165 raise ValueError("Could not add environment field to trace.")
3168 Add a clock to the trace. Clocks assigned to stream classes must be
3169 registered to the writer.
3172 def add_clock(self, clock):
3173 ret = _bt_ctf_writer_add_clock(self._w, clock._c)
3175 raise ValueError("Could not add clock to Writer.")
3178 Get the trace's TSDL meta-data.
3182 return _bt_ctf_writer_get_metadata_string(self._w)
3185 Flush the trace's metadata to the metadata file.
3188 def flush_metadata(self):
3189 _bt_ctf_writer_flush_metadata(self._w)
3192 Get the trace's byte order. Must be a constant from the ByteOrder
3196 def byte_order(self):
3197 raise NotImplementedError("Getter not implemented.")
3200 Set the trace's byte order. Must be a constant from the ByteOrder
3201 class. Defaults to the host machine's endianness.
3204 def byte_order(self, byte_order):
3205 ret = _bt_ctf_writer_set_byte_order(self._w, byte_order)
3207 raise ValueError("Could not set trace's byte order.")