4 * Babeltrace Python Module interface file
6 * Copyright 2012 EfficiOS Inc.
8 * Author: Danny Serres <danny.serres@efficios.com>
9 * Author: Jérémie Galarneau <jeremie.galarneau@efficios.com>
11 * Permission is hereby granted, free of charge, to any person obtaining a copy
12 * of this software and associated documentation files (the "Software"), to deal
13 * in the Software without restriction, including without limitation the rights
14 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
15 * copies of the Software, and to permit persons to whom the Software is
16 * furnished to do so, subject to the following conditions:
18 * The above copyright notice and this permission notice shall be included in
19 * all copies or substantial portions of the Software.
24 "BABELTRACE_VERSION_STR
26 Babeltrace is a trace viewer and converter reading and writing the
27 Common Trace Format (CTF). Its main use is to pretty-print CTF
28 traces into a human-readable text output.
30 To use this module, the first step is to create a TraceCollection and add a
34 %module(docstring=DOCSTRING) babeltrace
39 #define SWIG_FILE_WITH_INIT
40 #include <babeltrace/babeltrace.h>
41 #include <babeltrace/babeltrace-internal.h>
42 #include <babeltrace/trace-handle.h>
43 #include <babeltrace/trace-handle-internal.h>
44 #include <babeltrace/context.h>
45 #include <babeltrace/context-internal.h>
46 #include <babeltrace/iterator.h>
47 #include <babeltrace/iterator-internal.h>
48 #include <babeltrace/format.h>
49 #include <babeltrace/list.h>
50 #include <babeltrace/types.h>
51 #include <babeltrace/ctf/iterator.h>
52 #include "python-complements.h"
53 #include <babeltrace/ctf-writer/clock.h>
54 #include <babeltrace/ctf-writer/event-fields.h>
55 #include <babeltrace/ctf-writer/event-types.h>
56 #include <babeltrace/ctf-writer/event.h>
57 #include <babeltrace/ctf-writer/stream.h>
58 #include <babeltrace/ctf-writer/writer.h>
61 typedef int bt_intern_str;
62 typedef int64_t ssize_t;
64 /* =================================================================
66 ¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯
69 struct bt_definition **_bt_python_field_listcaller(
70 const struct bt_ctf_event *ctf_event,
71 const struct bt_definition *scope,
72 unsigned int *OUTPUT);
73 struct bt_definition *_bt_python_field_one_from_list(
74 struct bt_definition **list, int index);
75 struct bt_ctf_event_decl **_bt_python_event_decl_listcaller(
77 struct bt_context *ctx,
78 unsigned int *OUTPUT);
79 struct bt_ctf_event_decl *_bt_python_decl_one_from_list(
80 struct bt_ctf_event_decl **list, int index);
81 struct bt_ctf_field_decl **_by_python_field_decl_listcaller(
82 struct bt_ctf_event_decl *event_decl,
83 enum bt_ctf_scope scope,
84 unsigned int *OUTPUT);
85 struct bt_ctf_field_decl *_bt_python_field_decl_one_from_list(
86 struct bt_ctf_field_decl **list, int index);
87 struct definition_array *_bt_python_get_array_from_def(
88 struct bt_definition *field);
89 struct definition_sequence *_bt_python_get_sequence_from_def(
90 struct bt_definition *field);
91 struct bt_declaration *_bt_python_get_array_element_declaration(
92 struct bt_declaration *field);
93 struct bt_declaration *_bt_python_get_sequence_element_declaration(
94 struct bt_declaration *field);
95 const char *_bt_python_get_array_string(struct bt_definition *field);
96 const char *_bt_python_get_sequence_string(struct bt_definition *field);
97 int _bt_python_field_integer_get_signedness(const struct bt_ctf_field *field);
98 enum ctf_type_id _bt_python_get_field_type(const struct bt_ctf_field *field);
99 const char *_bt_python_ctf_field_type_enumeration_get_mapping(
100 struct bt_ctf_field_type *enumeration, size_t index,
101 int64_t *OUTPUT, int64_t *OUTPUT);
102 const char *_bt_python_ctf_field_type_enumeration_get_mapping_unsigned(
103 struct bt_ctf_field_type *enumeration, size_t index,
104 uint64_t *OUTPUT, uint64_t *OUTPUT);
105 const char *_bt_python_ctf_field_type_structure_get_field_name(
106 struct bt_ctf_field_type *structure, size_t index);
107 struct bt_ctf_field_type *_bt_python_ctf_field_type_structure_get_field_type(
108 struct bt_ctf_field_type *structure, size_t index);
109 const char *_bt_python_ctf_field_type_variant_get_field_name(
110 struct bt_ctf_field_type *variant, size_t index);
111 struct bt_ctf_field_type *_bt_python_ctf_field_type_variant_get_field_type(
112 struct bt_ctf_field_type *variant, size_t index);
113 const char *_bt_python_ctf_event_class_get_field_name(
114 struct bt_ctf_event_class *event_class, size_t index);
115 struct bt_ctf_field_type *_bt_python_ctf_event_class_get_field_type(
116 struct bt_ctf_event_class *event_class, size_t index);
118 /* =================================================================
119 CONTEXT.H, CONTEXT-INTERNAL.H
120 ¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯
123 %rename("_bt_context_create") bt_context_create(void);
124 %rename("_bt_context_add_trace") bt_context_add_trace(
125 struct bt_context *ctx, const char *path, const char *format,
126 void (*packet_seek)(struct bt_stream_pos *pos, size_t index, int whence),
127 struct bt_mmap_stream_list *stream_list, FILE *metadata);
128 %rename("_bt_context_remove_trace") bt_context_remove_trace(
129 struct bt_context *ctx, int trace_id);
130 %rename("_bt_context_get") bt_context_get(struct bt_context *ctx);
131 %rename("_bt_context_put") bt_context_put(struct bt_context *ctx);
132 %rename("_bt_ctf_event_get_context") bt_ctf_event_get_context(
133 const struct bt_ctf_event *event);
135 struct bt_context *bt_context_create(void);
136 int bt_context_add_trace(struct bt_context *ctx, const char *path, const char *format,
137 void (*packet_seek)(struct bt_stream_pos *pos, size_t index, int whence),
138 struct bt_mmap_stream_list *stream_list, FILE *metadata);
139 void bt_context_remove_trace(struct bt_context *ctx, int trace_id);
140 void bt_context_get(struct bt_context *ctx);
141 void bt_context_put(struct bt_context *ctx);
142 struct bt_context *bt_ctf_event_get_context(const struct bt_ctf_event *event);
144 // class TraceCollection to prevent direct access to struct bt_context
146 class TraceCollection:
148 The TraceCollection is the object that contains all currently opened traces.
152 self._tc = _bt_context_create()
155 _bt_context_put(self._tc)
157 def add_trace(self, path, format_str):
159 Add a trace by path to the TraceCollection.
163 path is the path to the trace, it is not recursive.
164 If "path" is None, stream_list is used instead as a list
165 of mmap streams to open for the trace.
167 format is a string containing the format name in which the trace was
170 Return: the corresponding TraceHandle on success or None on error.
172 ret = _bt_context_add_trace(self._tc, path, format_str, None, None, None)
176 th = TraceHandle.__new__(TraceHandle)
178 th._trace_collection = self
181 def add_traces_recursive(self, path, format_str):
183 Open a trace recursively.
185 Find each trace present in the subdirectory starting from the given
186 path, and add them to the TraceCollection.
188 Return a dict of TraceHandle instances (the full path is the key).
189 Return None on error.
199 for fullpath, dirs, files in os.walk(path):
200 if "metadata" in files:
201 trace_handle = self.add_trace(fullpath, format_str)
202 if trace_handle is None:
206 trace_handles[fullpath] = trace_handle
209 if noTrace and error:
213 def remove_trace(self, trace_handle):
215 Remove a trace from the TraceCollection.
216 Effectively closing the trace.
219 _bt_context_remove_trace(self._tc, trace_handle._id)
220 except AttributeError:
221 raise TypeError("in remove_trace, "
222 "argument 2 must be a TraceHandle instance")
227 Generator function to iterate over the events of open in the current
230 Due to limitations of the native Babeltrace API, only one event
231 may be "alive" at a time (i.e. a user should never store a copy
232 of the events returned by this function for ulterior use). Users
233 shall make sure to copy the information they need from an event
234 before accessing the next one.
236 Furthermore, event objects become invalid when the generator goes
237 out of scope as the underlying iterator will be reclaimed. Using an
238 event after the the generator has gone out of scope may result in a
239 crash or data corruption.
241 begin_pos_ptr = _bt_iter_pos()
242 end_pos_ptr = _bt_iter_pos()
243 begin_pos_ptr.type = SEEK_BEGIN
244 end_pos_ptr.type = SEEK_LAST
246 for event in self._events(begin_pos_ptr, end_pos_ptr):
249 def events_timestamps(self, timestamp_begin, timestamp_end):
251 Generator function to iterate over the events of open in the current
252 TraceCollection from timestamp_begin to timestamp_end.
254 begin_pos_ptr = _bt_iter_pos()
255 end_pos_ptr = _bt_iter_pos()
256 begin_pos_ptr.type = end_pos_ptr.type = SEEK_TIME
257 begin_pos_ptr.u.seek_time = timestamp_begin
258 end_pos_ptr.u.seek_time = timestamp_end
260 for event in self._events(begin_pos_ptr, end_pos_ptr):
264 def timestamp_begin(self):
265 pos_ptr = _bt_iter_pos()
266 pos_ptr.type = SEEK_BEGIN
267 return self._timestamp_at_pos(pos_ptr)
270 def timestamp_end(self):
271 pos_ptr = _bt_iter_pos()
272 pos_ptr.type = SEEK_LAST
273 return self._timestamp_at_pos(pos_ptr)
275 def _timestamp_at_pos(self, pos_ptr):
276 ctf_it_ptr = _bt_ctf_iter_create(self._tc, pos_ptr, pos_ptr)
277 if ctf_it_ptr is None:
278 raise NotImplementedError("Creation of multiple iterators is unsupported.")
279 ev_ptr = _bt_ctf_iter_read_event(ctf_it_ptr)
280 _bt_ctf_iter_destroy(ctf_it_ptr)
284 def _events(self, begin_pos_ptr, end_pos_ptr):
285 ctf_it_ptr = _bt_ctf_iter_create(self._tc, begin_pos_ptr, end_pos_ptr)
286 if ctf_it_ptr is None:
287 raise NotImplementedError(
288 "Creation of multiple iterators is unsupported.")
291 ev_ptr = _bt_ctf_iter_read_event(ctf_it_ptr)
295 ev = Event.__new__(Event)
299 except GeneratorExit:
302 ret = _bt_iter_next(_bt_ctf_get_iter(ctf_it_ptr))
306 _bt_ctf_iter_destroy(ctf_it_ptr)
312 /* =================================================================
317 %rename("lookup_format") bt_lookup_format(bt_intern_str qname);
318 %rename("_bt_print_format_list") bt_fprintf_format_list(FILE *fp);
319 %rename("register_format") bt_register_format(struct format *format);
320 %rename("unregister_format") bt_unregister_format(struct bt_format *format);
322 extern struct format *bt_lookup_format(bt_intern_str qname);
323 extern void bt_fprintf_format_list(FILE *fp);
324 extern int bt_register_format(struct bt_format *format);
325 extern void bt_unregister_format(struct bt_format *format);
329 def print_format_list(babeltrace_file):
331 Print a list of available formats to file.
333 babeltrace_file must be a File instance opened in write mode.
336 if babeltrace_file._file is not None:
337 _bt_print_format_list(babeltrace_file._file)
338 except AttributeError:
339 raise TypeError("in print_format_list, "
340 "argument 1 must be a File instance")
345 /* =================================================================
346 ITERATOR.H, ITERATOR-INTERNAL.H
347 ¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯
350 %rename("_bt_iter_create") bt_iter_create(struct bt_context *ctx,
351 const struct bt_iter_pos *begin_pos, const struct bt_iter_pos *end_pos);
352 %rename("_bt_iter_destroy") bt_iter_destroy(struct bt_iter *iter);
353 %rename("_bt_iter_next") bt_iter_next(struct bt_iter *iter);
354 %rename("_bt_iter_get_pos") bt_iter_get_pos(struct bt_iter *iter);
355 %rename("_bt_iter_free_pos") bt_iter_free_pos(struct bt_iter_pos *pos);
356 %rename("_bt_iter_set_pos") bt_iter_set_pos(struct bt_iter *iter,
357 const struct bt_iter_pos *pos);
358 %rename("_bt_iter_create_time_pos") bt_iter_create_time_pos(struct bt_iter *iter,
361 struct bt_iter *bt_iter_create(struct bt_context *ctx,
362 const struct bt_iter_pos *begin_pos, const struct bt_iter_pos *end_pos);
363 void bt_iter_destroy(struct bt_iter *iter);
364 int bt_iter_next(struct bt_iter *iter);
365 struct bt_iter_pos *bt_iter_get_pos(struct bt_iter *iter);
366 void bt_iter_free_pos(struct bt_iter_pos *pos);
367 int bt_iter_set_pos(struct bt_iter *iter, const struct bt_iter_pos *pos);
368 struct bt_iter_pos *bt_iter_create_time_pos(struct bt_iter *iter, uint64_t timestamp);
370 %rename("_bt_iter_pos") bt_iter_pos;
371 %rename("SEEK_TIME") BT_SEEK_TIME;
372 %rename("SEEK_RESTORE") BT_SEEK_RESTORE;
373 %rename("SEEK_CUR") BT_SEEK_CUR;
374 %rename("SEEK_BEGIN") BT_SEEK_BEGIN;
375 %rename("SEEK_LAST") BT_SEEK_LAST;
377 // This struct is taken from iterator.h
378 // All changes to the struct must also be made here
381 BT_SEEK_TIME, /* uses u.seek_time */
382 BT_SEEK_RESTORE, /* uses u.restore */
389 struct bt_saved_pos *restore;
393 /* =================================================================
394 TRACE-HANDLE.H, TRACE-HANDLE-INTERNAL.H
395 ¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯
398 %rename("_bt_trace_handle_create") bt_trace_handle_create(struct bt_context *ctx);
399 %rename("_bt_trace_handle_destroy") bt_trace_handle_destroy(struct bt_trace_handle *bt);
400 struct bt_trace_handle *bt_trace_handle_create(struct bt_context *ctx);
401 void bt_trace_handle_destroy(struct bt_trace_handle *bt);
403 %rename("_bt_trace_handle_get_path") bt_trace_handle_get_path(struct bt_context *ctx,
405 %rename("_bt_trace_handle_get_timestamp_begin") bt_trace_handle_get_timestamp_begin(
406 struct bt_context *ctx, int handle_id, enum bt_clock_type type);
407 %rename("_bt_trace_handle_get_timestamp_end") bt_trace_handle_get_timestamp_end(
408 struct bt_context *ctx, int handle_id, enum bt_clock_type type);
409 const char *bt_trace_handle_get_path(struct bt_context *ctx, int handle_id);
410 uint64_t bt_trace_handle_get_timestamp_begin(struct bt_context *ctx, int handle_id,
411 enum bt_clock_type type);
412 uint64_t bt_trace_handle_get_timestamp_end(struct bt_context *ctx, int handle_id,
413 enum bt_clock_type type);
415 %rename("_bt_ctf_event_get_handle_id") bt_ctf_event_get_handle_id(
416 const struct bt_ctf_event *event);
417 int bt_ctf_event_get_handle_id(const struct bt_ctf_event *event);
422 # Based on enum bt_clock_type in clock-type.h
427 class TraceHandle(object):
429 The TraceHandle allows the user to manipulate a trace file directly.
430 It is a unique identifier representing a trace file.
435 raise NotImplementedError("TraceHandle cannot be instantiated")
438 return "Babeltrace TraceHandle: trace_id('{0}')".format(self._id)
442 """Return the TraceHandle id."""
447 """Return the path of a TraceHandle."""
448 return _bt_trace_handle_get_path(self._trace_collection._tc, self._id)
451 def timestamp_begin(self):
452 """Return the creation time of the buffers of a trace."""
453 return _bt_trace_handle_get_timestamp_begin(
454 self._trace_collection._tc, self._id, ClockType.CLOCK_REAL)
457 def timestamp_end(self):
458 """Return the destruction timestamp of the buffers of a trace."""
459 return _bt_trace_handle_get_timestamp_end(
460 self._trace_collection._tc, self._id, ClockType.CLOCK_REAL)
465 Generator returning all events (EventDeclaration) in a trace.
467 ret = _bt_python_event_decl_listcaller(self.id, self._trace_collection._tc)
469 if not isinstance(ret, list):
472 ptr_list, count = ret
473 for i in range(count):
474 tmp = EventDeclaration.__new__(EventDeclaration)
475 tmp._ed = _bt_python_decl_one_from_list(ptr_list, i)
482 // =================================================================
484 // =================================================================
486 /* =================================================================
492 %rename("_bt_ctf_iter_create") bt_ctf_iter_create(struct bt_context *ctx,
493 const struct bt_iter_pos *begin_pos,
494 const struct bt_iter_pos *end_pos);
495 %rename("_bt_ctf_get_iter") bt_ctf_get_iter(struct bt_ctf_iter *iter);
496 %rename("_bt_ctf_iter_destroy") bt_ctf_iter_destroy(struct bt_ctf_iter *iter);
497 %rename("_bt_ctf_iter_read_event") bt_ctf_iter_read_event(struct bt_ctf_iter *iter);
499 struct bt_ctf_iter *bt_ctf_iter_create(struct bt_context *ctx,
500 const struct bt_iter_pos *begin_pos,
501 const struct bt_iter_pos *end_pos);
502 struct bt_iter *bt_ctf_get_iter(struct bt_ctf_iter *iter);
503 void bt_ctf_iter_destroy(struct bt_ctf_iter *iter);
504 struct bt_ctf_event *bt_ctf_iter_read_event(struct bt_ctf_iter *iter);
508 %rename("_bt_ctf_get_top_level_scope") bt_ctf_get_top_level_scope(const struct
509 bt_ctf_event *event, enum bt_ctf_scope scope);
510 %rename("_bt_ctf_event_name") bt_ctf_event_name(const struct bt_ctf_event *ctf_event);
511 %rename("_bt_ctf_get_timestamp") bt_ctf_get_timestamp(
512 const struct bt_ctf_event *ctf_event);
513 %rename("_bt_ctf_get_cycles") bt_ctf_get_cycles(
514 const struct bt_ctf_event *ctf_event);
516 %rename("_bt_ctf_get_field") bt_ctf_get_field(const struct bt_ctf_event *ctf_event,
517 const struct bt_definition *scope, const char *field);
518 %rename("_bt_ctf_get_index") bt_ctf_get_index(const struct bt_ctf_event *ctf_event,
519 const struct bt_definition *field, unsigned int index);
520 %rename("_bt_ctf_field_name") bt_ctf_field_name(const struct bt_definition *field);
521 %rename("_bt_ctf_field_type") bt_ctf_field_type(const struct bt_declaration *field);
522 %rename("_bt_ctf_get_int_signedness") bt_ctf_get_int_signedness(
523 const struct bt_declaration *field);
524 %rename("_bt_ctf_get_int_base") bt_ctf_get_int_base(const struct bt_declaration *field);
525 %rename("_bt_ctf_get_int_byte_order") bt_ctf_get_int_byte_order(
526 const struct bt_declaration *field);
527 %rename("_bt_ctf_get_int_len") bt_ctf_get_int_len(const struct bt_declaration *field);
528 %rename("_bt_ctf_get_enum_int") bt_ctf_get_enum_int(const struct bt_definition *field);
529 %rename("_bt_ctf_get_enum_str") bt_ctf_get_enum_str(const struct bt_definition *field);
530 %rename("_bt_ctf_get_encoding") bt_ctf_get_encoding(const struct bt_declaration *field);
531 %rename("_bt_ctf_get_array_len") bt_ctf_get_array_len(const struct bt_declaration *field);
532 %rename("_bt_ctf_get_uint64") bt_ctf_get_uint64(const struct bt_definition *field);
533 %rename("_bt_ctf_get_int64") bt_ctf_get_int64(const struct bt_definition *field);
534 %rename("_bt_ctf_get_char_array") bt_ctf_get_char_array(const struct bt_definition *field);
535 %rename("_bt_ctf_get_string") bt_ctf_get_string(const struct bt_definition *field);
536 %rename("_bt_ctf_get_float") bt_ctf_get_float(const struct bt_definition *field);
537 %rename("_bt_ctf_get_variant") bt_ctf_get_variant(const struct bt_definition *field);
538 %rename("_bt_ctf_field_get_error") bt_ctf_field_get_error(void);
539 %rename("_bt_ctf_get_decl_event_name") bt_ctf_get_decl_event_name(const struct
540 bt_ctf_event_decl *event);
541 %rename("_bt_ctf_get_decl_event_id") bt_ctf_get_decl_event_id(const struct
542 bt_ctf_event_decl *event);
543 %rename("_bt_ctf_get_decl_field_name") bt_ctf_get_decl_field_name(
544 const struct bt_ctf_field_decl *field);
545 %rename("_bt_ctf_get_decl_from_def") bt_ctf_get_decl_from_def(
546 const struct bt_definition *field);
547 %rename("_bt_ctf_get_decl_from_field_decl") bt_ctf_get_decl_from_field_decl(
548 const struct bt_ctf_field_decl *field);
549 %rename("_bt_array_index") bt_array_index(struct definition_array *array, uint64_t i);
550 %rename("_bt_sequence_len") bt_sequence_len(struct definition_sequence *sequence);
551 %rename("_bt_sequence_index") bt_sequence_index(struct definition_sequence *sequence, uint64_t i);
552 %rename("_bt_ctf_get_struct_field_count") bt_ctf_get_struct_field_count(const struct bt_definition *structure);
553 %rename("_bt_ctf_get_struct_field_index") bt_ctf_get_struct_field_index(const struct bt_definition *structure, uint64_t i);
555 const struct bt_definition *bt_ctf_get_top_level_scope(const struct bt_ctf_event *ctf_event,
556 enum bt_ctf_scope scope);
557 const char *bt_ctf_event_name(const struct bt_ctf_event *ctf_event);
558 uint64_t bt_ctf_get_timestamp(const struct bt_ctf_event *ctf_event);
559 uint64_t bt_ctf_get_cycles(const struct bt_ctf_event *ctf_event);
560 const struct bt_definition *bt_ctf_get_field(const struct bt_ctf_event *ctf_event,
561 const struct bt_definition *scope,
563 const struct bt_definition *bt_ctf_get_index(const struct bt_ctf_event *ctf_event,
564 const struct bt_definition *field,
566 const char *bt_ctf_field_name(const struct bt_definition *field);
567 enum ctf_type_id bt_ctf_field_type(const struct bt_declaration *field);
568 int bt_ctf_get_int_signedness(const struct bt_declaration *field);
569 int bt_ctf_get_int_base(const struct bt_declaration *field);
570 int bt_ctf_get_int_byte_order(const struct bt_declaration *field);
571 ssize_t bt_ctf_get_int_len(const struct bt_declaration *field);
572 const struct bt_definition *bt_ctf_get_enum_int(const struct bt_definition *field);
573 const char *bt_ctf_get_enum_str(const struct bt_definition *field);
574 enum ctf_string_encoding bt_ctf_get_encoding(const struct bt_declaration *field);
575 int bt_ctf_get_array_len(const struct bt_declaration *field);
576 struct bt_definition *bt_array_index(struct definition_array *array, uint64_t i);
577 uint64_t bt_ctf_get_uint64(const struct bt_definition *field);
578 int64_t bt_ctf_get_int64(const struct bt_definition *field);
579 char *bt_ctf_get_char_array(const struct bt_definition *field);
580 char *bt_ctf_get_string(const struct bt_definition *field);
581 double bt_ctf_get_float(const struct bt_definition *field);
582 const struct bt_definition *bt_ctf_get_variant(const struct bt_definition *field);
583 int bt_ctf_field_get_error(void);
584 const char *bt_ctf_get_decl_event_name(const struct bt_ctf_event_decl *event);
585 uint64_t bt_ctf_get_decl_event_id(const struct bt_ctf_event_decl *event);
586 const char *bt_ctf_get_decl_field_name(const struct bt_ctf_field_decl *field);
587 const struct bt_declaration *bt_ctf_get_decl_from_def(const struct bt_definition *field);
588 const struct bt_declaration *bt_ctf_get_decl_from_field_decl(const struct bt_ctf_field_decl *field);
589 uint64_t bt_sequence_len(struct definition_sequence *sequence);
590 struct bt_definition *bt_sequence_index(struct definition_sequence *sequence, uint64_t i);
591 uint64_t bt_ctf_get_struct_field_count(const struct bt_definition *structure);
592 const struct bt_definition *bt_ctf_get_struct_field_index(const struct bt_definition *structure, uint64_t i);
596 class CTFStringEncoding:
602 # Based on the enum in ctf-writer/writer.h
604 BYTE_ORDER_NATIVE = 0
605 BYTE_ORDER_LITTLE_ENDIAN = 1
606 BYTE_ORDER_BIG_ENDIAN = 2
607 BYTE_ORDER_NETWORK = 3
608 BYTE_ORDER_UNKNOWN = 4 # Python-specific entry
610 #enum equivalent, accessible constants
611 #These are taken directly from ctf/events.h
612 #All changes to enums must also be made here
626 name = "UNKNOWN_TYPE"
627 constants = [attr for attr in dir(CTFTypeId) if not callable(getattr(CTFTypeId, attr)) and not attr.startswith("__")]
628 for attr in constants:
629 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"
644 constants = [attr for attr in dir(CTFScope) if not callable(getattr(CTFScope, attr)) and not attr.startswith("__")]
645 for attr in constants:
646 if getattr(CTFScope, attr) == scope:
651 # Priority of the scopes when searching for event fields
652 _scopes = [CTFScope.EVENT_FIELDS, CTFScope.EVENT_CONTEXT, CTFScope.STREAM_EVENT_CONTEXT,
653 CTFScope.STREAM_EVENT_HEADER, CTFScope.STREAM_PACKET_CONTEXT, CTFScope.TRACE_PACKET_HEADER]
656 class Event(collections.Mapping):
658 This class represents an event from the trace.
659 It is obtained using the TraceCollection generator functions.
663 raise NotImplementedError("Event cannot be instantiated")
667 """Return the name of the event or None on error."""
668 return _bt_ctf_event_name(self._e)
673 Return the timestamp of the event as written in
674 the packet (in cycles) or -1ULL on error.
676 return _bt_ctf_get_cycles(self._e)
681 Return the timestamp of the event offset with the
682 system clock source or -1ULL on error.
684 return _bt_ctf_get_timestamp(self._e)
686 def field_with_scope(self, field_name, scope):
688 Get field_name's value in scope.
689 None is returned if no field matches field_name.
691 if not scope in _scopes:
692 raise ValueError("Invalid scope provided")
693 field = self._field_with_scope(field_name, scope)
694 if field is not None:
698 def field_list_with_scope(self, scope):
699 """Return a list of field names in scope."""
700 if not scope in _scopes:
701 raise ValueError("Invalid scope provided")
703 for field in self._field_list_with_scope(scope):
704 field_names.append(field.name)
710 Get the TraceHandle associated with this event
713 ret = _bt_ctf_event_get_handle_id(self._e)
717 th = TraceHandle.__new__(TraceHandle)
719 th._trace_collection = self.get_trace_collection()
723 def trace_collection(self):
725 Get the TraceCollection associated with this event.
726 Return None on error.
728 trace_collection = TraceCollection()
729 trace_collection._tc = _bt_ctf_event_get_context(self._e);
730 if trace_collection._tc is None:
733 return trace_collection
735 def __getitem__(self, field_name):
737 Get field_name's value. If the field_name exists in multiple
738 scopes, the first field found is returned. The scopes are searched
739 in the following order:
742 3) STREAM_EVENT_CONTEXT
743 4) STREAM_EVENT_HEADER
744 5) STREAM_PACKET_CONTEXT
745 6) TRACE_PACKET_HEADER
746 None is returned if no field matches field_name.
748 Use field_with_scope() to explicitly access fields in a given
751 field = self._field(field_name)
752 if field is not None:
754 raise KeyError(field_name)
757 for key in self.keys():
762 for scope in _scopes:
763 scope_ptr = _bt_ctf_get_top_level_scope(self._e, scope)
764 ret = _bt_python_field_listcaller(self._e, scope_ptr)
765 if isinstance(ret, list):
769 def __contains__(self, field_name):
770 return self._field(field_name) is not None
773 """Return a list of field names."""
775 for scope in _scopes:
776 for name in self.field_list_with_scope(scope):
777 field_names.add(name)
778 return list(field_names)
780 def get(self, field_name, default = None):
781 field = self._field(field_name)
787 for field in self.keys():
788 yield (field, self[field])
790 def _field_with_scope(self, field_name, scope):
791 scope_ptr = _bt_ctf_get_top_level_scope(self._e, scope)
792 if scope_ptr is None:
795 definition_ptr = _bt_ctf_get_field(self._e, scope_ptr, field_name)
796 if definition_ptr is None:
799 field = _Definition(definition_ptr, scope)
802 def _field(self, field_name):
804 for scope in _scopes:
805 field = self._field_with_scope(field_name, scope)
806 if field is not None:
810 def _field_list_with_scope(self, scope):
812 scope_ptr = _bt_ctf_get_top_level_scope(self._e, scope)
814 # Returns a list [list_ptr, count]. If list_ptr is NULL, SWIG will only
815 # provide the "count" return value
818 ret = _bt_python_field_listcaller(self._e, scope_ptr)
819 if isinstance(ret, list):
820 list_ptr, count = ret
822 for i in range(count):
823 definition_ptr = _bt_python_field_one_from_list(list_ptr, i)
824 if definition_ptr is not None:
825 definition = _Definition(definition_ptr, scope)
826 fields.append(definition)
829 class FieldError(Exception):
830 def __init__(self, value):
834 return repr(self.value)
836 class EventDeclaration(object):
837 """Event declaration class. Do not instantiate."""
838 MAX_UINT64 = 0xFFFFFFFFFFFFFFFF
841 raise NotImplementedError("EventDeclaration cannot be instantiated")
845 """Return the name of the event or None on error"""
846 return _bt_ctf_get_decl_event_name(self._ed)
850 """Return the event-ID of the event or -1 on error"""
851 id = _bt_ctf_get_decl_event_id(self._ed)
852 if id == self.MAX_UINT64:
859 Generator returning all FieldDeclarations of an event, going through
860 each scope in the following order:
863 3) STREAM_EVENT_CONTEXT
864 4) STREAM_EVENT_HEADER
865 5) STREAM_PACKET_CONTEXT
866 6) TRACE_PACKET_HEADER
868 for scope in _scopes:
869 for declaration in self.fields_scope(scope):
872 def fields_scope(self, scope):
874 Generator returning FieldDeclarations of the current event in scope.
876 ret = _by_python_field_decl_listcaller(self._ed, scope)
878 if not isinstance(ret, list):
881 list_ptr, count = ret
882 for i in range(count):
883 field_declaration_ptr = _bt_python_field_decl_one_from_list(list_ptr, i)
884 if field_declaration_ptr is not None:
885 declaration_ptr = _bt_ctf_get_decl_from_field_decl(field_declaration_ptr)
886 field_declaration = _create_field_declaration(declaration_ptr, _bt_ctf_get_decl_field_name(field_declaration_ptr), scope)
887 yield field_declaration
889 class FieldDeclaration(object):
890 """Field declaration class. Do not instantiate."""
892 raise NotImplementedError("FieldDeclaration cannot be instantiated")
895 return "({0}) {1} {2}".format(CTFScope.scope_name(self.scope), CTFTypeId.type_name(self.type), self.name)
899 """Return the name of a FieldDeclaration or None on error."""
905 Return the FieldDeclaration's type. One of the entries in class
908 return _bt_ctf_field_type(self._fd)
913 Return the FieldDeclaration's scope.
917 class IntegerFieldDeclaration(FieldDeclaration):
918 """Do not instantiate."""
920 raise NotImplementedError("IntegerFieldDeclaration cannot be instantiated")
923 def signedness(self):
925 Return the signedness of an integer:
926 0 if unsigned; 1 if signed; -1 on error.
928 return _bt_ctf_get_int_signedness(self._fd)
932 """Return the base of an int or a negative value on error."""
933 return _bt_ctf_get_int_base(self._fd)
936 def byte_order(self):
938 Return the byte order. One of class ByteOrder's entries.
940 ret = _bt_ctf_get_int_byte_order(self._fd)
942 return ByteOrder.BYTE_ORDER_LITTLE_ENDIAN
944 return ByteOrder.BYTE_ORDER_BIG_ENDIAN
946 return ByteOrder.BYTE_ORDER_UNKNOWN
951 Return the size, in bits, of an int or a negative
954 return _bt_ctf_get_int_len(self._fd)
959 Return the encoding. One of class CTFStringEncoding's entries.
960 Return a negative value on error.
962 return _bt_ctf_get_encoding(self._fd)
964 class EnumerationFieldDeclaration(FieldDeclaration):
965 """Do not instantiate."""
967 raise NotImplementedError("EnumerationFieldDeclaration cannot be instantiated")
969 class ArrayFieldDeclaration(FieldDeclaration):
970 """Do not instantiate."""
972 raise NotImplementedError("ArrayFieldDeclaration cannot be instantiated")
977 Return the length of an array or a negative
980 return _bt_ctf_get_array_len(self._fd)
983 def element_declaration(self):
985 Return element declaration.
987 field_decl_ptr = _bt_python_get_array_element_declaration(self._fd)
988 return _create_field_declaration(field_decl_ptr, "", self.scope)
990 class SequenceFieldDeclaration(FieldDeclaration):
991 """Do not instantiate."""
993 raise NotImplementedError("SequenceFieldDeclaration cannot be instantiated")
996 def element_declaration(self):
998 Return element declaration.
1000 field_decl_ptr = _bt_python_get_sequence_element_declaration(self._fd)
1001 return _create_field_declaration(field_decl_ptr, "", self.scope)
1003 class FloatFieldDeclaration(FieldDeclaration):
1004 """Do not instantiate."""
1006 raise NotImplementedError("FloatFieldDeclaration cannot be instantiated")
1008 class StructureFieldDeclaration(FieldDeclaration):
1009 """Do not instantiate."""
1011 raise NotImplementedError("StructureFieldDeclaration cannot be instantiated")
1013 class StringFieldDeclaration(FieldDeclaration):
1014 """Do not instantiate."""
1016 raise NotImplementedError("StringFieldDeclaration cannot be instantiated")
1018 class VariantFieldDeclaration(FieldDeclaration):
1019 """Do not instantiate."""
1021 raise NotImplementedError("VariantFieldDeclaration cannot be instantiated")
1025 Return the last error code encountered while
1026 accessing a field and reset the error flag.
1027 Return 0 if no error, a negative value otherwise.
1029 return _bt_ctf_field_get_error()
1031 def _create_field_declaration(declaration_ptr, name, scope):
1033 Private field declaration factory.
1035 if declaration_ptr is None:
1036 raise ValueError("declaration_ptr must be valid")
1037 if not scope in _scopes:
1038 raise ValueError("Invalid scope provided")
1040 type = _bt_ctf_field_type(declaration_ptr)
1042 if type == CTFTypeId.INTEGER:
1043 declaration = IntegerFieldDeclaration.__new__(IntegerFieldDeclaration)
1044 elif type == CTFTypeId.ENUM:
1045 declaration = EnumerationFieldDeclaration.__new__(EnumerationFieldDeclaration)
1046 elif type == CTFTypeId.ARRAY:
1047 declaration = ArrayFieldDeclaration.__new__(ArrayFieldDeclaration)
1048 elif type == CTFTypeId.SEQUENCE:
1049 declaration = SequenceFieldDeclaration.__new__(SequenceFieldDeclaration)
1050 elif type == CTFTypeId.FLOAT:
1051 declaration = FloatFieldDeclaration.__new__(FloatFieldDeclaration)
1052 elif type == CTFTypeId.STRUCT:
1053 declaration = StructureFieldDeclaration.__new__(StructureFieldDeclaration)
1054 elif type == CTFTypeId.STRING:
1055 declaration = StringFieldDeclaration.__new__(StringFieldDeclaration)
1056 elif type == CTFTypeId.VARIANT:
1057 declaration = VariantFieldDeclaration.__new__(VariantFieldDeclaration)
1061 declaration._fd = declaration_ptr
1062 declaration._s = scope
1063 declaration._name = name
1066 class _Definition(object):
1067 def __init__(self, definition_ptr, scope):
1068 self._d = definition_ptr
1070 if not scope in _scopes:
1071 ValueError("Invalid scope provided")
1075 """Return the name of a field or None on error."""
1076 return _bt_ctf_field_name(self._d)
1080 """Return the type of a field or -1 if unknown."""
1081 return _bt_ctf_field_type(_bt_ctf_get_decl_from_def(self._d))
1084 def declaration(self):
1085 """Return the associated Definition object."""
1086 return _create_field_declaration(_bt_ctf_get_decl_from_def(self._d), self.name, self.scope)
1088 def _get_enum_str(self):
1090 Return the string matching the current enumeration.
1091 Return None on error.
1093 return _bt_ctf_get_enum_str(self._d)
1095 def _get_array_element_at(self, index):
1097 Return the array's element at position index.
1098 Return None on error
1100 array_ptr = _bt_python_get_array_from_def(self._d)
1101 if array_ptr is None:
1104 definition_ptr = _bt_array_index(array_ptr, index)
1105 if definition_ptr is None:
1107 return _Definition(definition_ptr, self.scope)
1109 def _get_sequence_len(self):
1111 Return the len of a sequence or a negative
1114 seq = _bt_python_get_sequence_from_def(self._d)
1115 return _bt_sequence_len(seq)
1117 def _get_sequence_element_at(self, index):
1119 Return the sequence's element at position index,
1120 otherwise return None
1122 seq = _bt_python_get_sequence_from_def(self._d)
1124 definition_ptr = _bt_sequence_index(seq, index)
1125 if definition_ptr is not None:
1126 return _Definition(definition_ptr, self.scope)
1129 def _get_uint64(self):
1131 Return the value associated with the field.
1132 If the field does not exist or is not of the type requested,
1133 the value returned is undefined. To check if an error occured,
1134 use the field_error() function after accessing a field.
1136 return _bt_ctf_get_uint64(self._d)
1138 def _get_int64(self):
1140 Return the value associated with the field.
1141 If the field does not exist or is not of the type requested,
1142 the value returned is undefined. To check if an error occured,
1143 use the field_error() function after accessing a field.
1145 return _bt_ctf_get_int64(self._d)
1147 def _get_char_array(self):
1149 Return the value associated with the field.
1150 If the field does not exist or is not of the type requested,
1151 the value returned is undefined. To check if an error occurred,
1152 use the field_error() function after accessing a field.
1154 return _bt_ctf_get_char_array(self._d)
1158 Return the value associated with the field.
1159 If the field does not exist or is not of the type requested,
1160 the value returned is undefined. To check if an error occurred,
1161 use the field_error() function after accessing a field.
1163 return _bt_ctf_get_string(self._d)
1165 def _get_float(self):
1167 Return the value associated with the field.
1168 If the field does not exist or is not of the type requested,
1169 the value returned is undefined. To check if an error occurred,
1170 use the field_error() function after accessing a field.
1172 return _bt_ctf_get_float(self._d)
1174 def _get_variant(self):
1176 Return the variant's selected field.
1177 If the field does not exist or is not of the type requested,
1178 the value returned is undefined. To check if an error occurred,
1179 use the field_error() function after accessing a field.
1181 return _bt_ctf_get_variant(self._d)
1183 def _get_struct_field_count(self):
1185 Return the number of fields contained in the structure.
1186 If the field does not exist or is not of the type requested,
1187 the value returned is undefined.
1189 return _bt_ctf_get_struct_field_count(self._d)
1191 def _get_struct_field_at(self, i):
1193 Return the structure's field at position i.
1194 If the field does not exist or is not of the type requested,
1195 the value returned is undefined. To check if an error occurred,
1196 use the field_error() function after accessing a field.
1198 return _bt_ctf_get_struct_field_index(self._d, i)
1203 Return the value associated with the field according to its type.
1204 Return None on error.
1209 if id == CTFTypeId.STRING:
1210 value = self._get_str()
1211 elif id == CTFTypeId.ARRAY:
1212 element_decl = self.declaration.element_declaration
1213 if ((element_decl.type == CTFTypeId.INTEGER
1214 and element_decl.length == 8)
1215 and (element_decl.encoding == CTFStringEncoding.ASCII or element_decl.encoding == CTFStringEncoding.UTF8)):
1216 value = _bt_python_get_array_string(self._d)
1219 for i in range(self.declaration.length):
1220 element = self._get_array_element_at(i)
1221 value.append(element.value)
1222 elif id == CTFTypeId.INTEGER:
1223 if self.declaration.signedness == 0:
1224 value = self._get_uint64()
1226 value = self._get_int64()
1227 elif id == CTFTypeId.ENUM:
1228 value = self._get_enum_str()
1229 elif id == CTFTypeId.SEQUENCE:
1230 element_decl = self.declaration.element_declaration
1231 if ((element_decl.type == CTFTypeId.INTEGER
1232 and element_decl.length == 8)
1233 and (element_decl.encoding == CTFStringEncoding.ASCII or element_decl.encoding == CTFStringEncoding.UTF8)):
1234 value = _bt_python_get_sequence_string(self._d)
1236 seq_len = self._get_sequence_len()
1238 for i in range(seq_len):
1239 evDef = self._get_sequence_element_at(i)
1240 value.append(evDef.value)
1241 elif id == CTFTypeId.FLOAT:
1242 value = self._get_float()
1243 elif id == CTFTypeId.VARIANT:
1244 variant = _Definition.__new__(_Definition)
1245 variant._d = self._get_variant();
1246 value = variant.value
1247 elif id == CTFTypeId.STRUCT:
1249 for i in range(self._get_struct_field_count()):
1250 member = _Definition(self._get_struct_field_at(i), self.scope)
1251 value[member.name] = member.value
1254 raise FieldError("Error occurred while accessing field {} of type {}".format(self.name, CTFTypeId.type_name(id)))
1259 """Return the scope of a field or None on error."""
1265 // =================================================================
1267 // =================================================================
1269 /* =================================================================
1271 ¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯
1273 %rename("_bt_ctf_clock_create") bt_ctf_clock_create(const char *name);
1274 %rename("_bt_ctf_clock_get_name") bt_ctf_clock_get_name(struct bt_ctf_clock *clock);
1275 %rename("_bt_ctf_clock_get_description") bt_ctf_clock_get_description(struct bt_ctf_clock *clock);
1276 %rename("_bt_ctf_clock_set_description") bt_ctf_clock_set_description(struct bt_ctf_clock *clock, const char *desc);
1277 %rename("_bt_ctf_clock_get_frequency") bt_ctf_clock_get_frequency(struct bt_ctf_clock *clock);
1278 %rename("_bt_ctf_clock_set_frequency") bt_ctf_clock_set_frequency(struct bt_ctf_clock *clock, uint64_t freq);
1279 %rename("_bt_ctf_clock_get_precision") bt_ctf_clock_get_precision(struct bt_ctf_clock *clock);
1280 %rename("_bt_ctf_clock_set_precision") bt_ctf_clock_set_precision(struct bt_ctf_clock *clock, uint64_t precision);
1281 %rename("_bt_ctf_clock_get_offset_s") bt_ctf_clock_get_offset_s(struct bt_ctf_clock *clock);
1282 %rename("_bt_ctf_clock_set_offset_s") bt_ctf_clock_set_offset_s(struct bt_ctf_clock *clock, uint64_t offset_s);
1283 %rename("_bt_ctf_clock_get_offset") bt_ctf_clock_get_offset(struct bt_ctf_clock *clock);
1284 %rename("_bt_ctf_clock_set_offset") bt_ctf_clock_set_offset(struct bt_ctf_clock *clock, uint64_t offset);
1285 %rename("_bt_ctf_clock_get_is_absolute") bt_ctf_clock_get_is_absolute(struct bt_ctf_clock *clock);
1286 %rename("_bt_ctf_clock_set_is_absolute") bt_ctf_clock_set_is_absolute(struct bt_ctf_clock *clock, int is_absolute);
1287 %rename("_bt_ctf_clock_get_time") bt_ctf_clock_get_time(struct bt_ctf_clock *clock);
1288 %rename("_bt_ctf_clock_set_time") bt_ctf_clock_set_time(struct bt_ctf_clock *clock, uint64_t time);
1289 %rename("_bt_ctf_clock_get") bt_ctf_clock_get(struct bt_ctf_clock *clock);
1290 %rename("_bt_ctf_clock_put") bt_ctf_clock_put(struct bt_ctf_clock *clock);
1292 struct bt_ctf_clock *bt_ctf_clock_create(const char *name);
1293 const char *bt_ctf_clock_get_name(struct bt_ctf_clock *clock);
1294 const char *bt_ctf_clock_get_description(struct bt_ctf_clock *clock);
1295 int bt_ctf_clock_set_description(struct bt_ctf_clock *clock, const char *desc);
1296 uint64_t bt_ctf_clock_get_frequency(struct bt_ctf_clock *clock);
1297 int bt_ctf_clock_set_frequency(struct bt_ctf_clock *clock, uint64_t freq);
1298 uint64_t bt_ctf_clock_get_precision(struct bt_ctf_clock *clock);
1299 int bt_ctf_clock_set_precision(struct bt_ctf_clock *clock, uint64_t precision);
1300 uint64_t bt_ctf_clock_get_offset_s(struct bt_ctf_clock *clock);
1301 int bt_ctf_clock_set_offset_s(struct bt_ctf_clock *clock, uint64_t offset_s);
1302 uint64_t bt_ctf_clock_get_offset(struct bt_ctf_clock *clock);
1303 int bt_ctf_clock_set_offset(struct bt_ctf_clock *clock, uint64_t offset);
1304 int bt_ctf_clock_get_is_absolute(struct bt_ctf_clock *clock);
1305 int bt_ctf_clock_set_is_absolute(struct bt_ctf_clock *clock, int is_absolute);
1306 uint64_t bt_ctf_clock_get_time(struct bt_ctf_clock *clock);
1307 int bt_ctf_clock_set_time(struct bt_ctf_clock *clock, uint64_t time);
1308 void bt_ctf_clock_get(struct bt_ctf_clock *clock);
1309 void bt_ctf_clock_put(struct bt_ctf_clock *clock);
1311 /* =================================================================
1313 ¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯
1315 %rename("_bt_ctf_field_type_integer_create") bt_ctf_field_type_integer_create(unsigned int size);
1316 %rename("_bt_ctf_field_type_integer_get_size") bt_ctf_field_type_integer_get_size(struct bt_ctf_field_type *integer);
1317 %rename("_bt_ctf_field_type_integer_get_signed") bt_ctf_field_type_integer_get_signed(struct bt_ctf_field_type *integer);
1318 %rename("_bt_ctf_field_type_integer_set_signed") bt_ctf_field_type_integer_set_signed(struct bt_ctf_field_type *integer, int is_signed);
1319 %rename("_bt_ctf_field_type_integer_get_base") bt_ctf_field_type_integer_get_base(struct bt_ctf_field_type *integer);
1320 %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);
1321 %rename("_bt_ctf_field_type_integer_get_encoding") bt_ctf_field_type_integer_get_encoding(struct bt_ctf_field_type *integer);
1322 %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);
1323 %rename("_bt_ctf_field_type_enumeration_create") bt_ctf_field_type_enumeration_create(struct bt_ctf_field_type *integer_container_type);
1324 %rename("_bt_ctf_field_type_enumeration_get_container_type") bt_ctf_field_type_enumeration_get_container_type(struct bt_ctf_field_type *enumeration);
1325 %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);
1326 %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);
1327 %rename("_bt_ctf_field_type_enumeration_get_mapping_count") bt_ctf_field_type_enumeration_get_mapping_count(struct bt_ctf_field_type *enumeration);
1328 %rename("_bt_ctf_field_type_enumeration_get_mapping") bt_ctf_field_type_enumeration_get_mapping(struct bt_ctf_field_type *enumeration, size_t index, const char **name, int64_t *range_start, int64_t *range_end);
1329 %rename("_bt_ctf_field_type_enumeration_get_mapping_unsigned") bt_ctf_field_type_enumeration_get_mapping_unsigned(struct bt_ctf_field_type *enumeration, size_t index, const char **name, uint64_t *range_start, uint64_t *range_end);
1330 %rename("_bt_ctf_field_type_enumeration_get_mapping_index_by_name") bt_ctf_field_type_enumeration_get_mapping_index_by_name(struct bt_ctf_field_type *enumeration, const char *name, size_t *index);
1331 %rename("_bt_ctf_field_type_enumeration_get_mapping_index_by_value") bt_ctf_field_type_enumeration_get_mapping_index_by_value(struct bt_ctf_field_type *enumeration, int64_t value, size_t *index);
1332 %rename("_bt_ctf_field_type_enumeration_get_mapping_index_by_unsigned_value") bt_ctf_field_type_enumeration_get_mapping_index_by_unsigned_value(struct bt_ctf_field_type *enumeration, uint64_t value, size_t *index);
1333 %rename("_bt_ctf_field_type_floating_point_create") bt_ctf_field_type_floating_point_create(void);
1334 %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);
1335 %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);
1336 %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);
1337 %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);
1338 %rename("_bt_ctf_field_type_structure_create") bt_ctf_field_type_structure_create(void);
1339 %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);
1340 %rename("_bt_ctf_field_type_structure_get_field_count") bt_ctf_field_type_structure_get_field_count(struct bt_ctf_field_type *structure);
1341 %rename("_bt_ctf_field_type_structure_get_field") bt_ctf_field_type_structure_get_field(struct bt_ctf_field_type *structure, const char **field_name, struct bt_ctf_field_type **field_type, size_t index);
1342 %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);
1343 %rename("_bt_ctf_field_type_variant_create") bt_ctf_field_type_variant_create(struct bt_ctf_field_type *enum_tag, const char *tag_name);
1344 %rename("_bt_ctf_field_type_variant_get_tag_type") bt_ctf_field_type_variant_get_tag_type(struct bt_ctf_field_type *variant);
1345 %rename("_bt_ctf_field_type_variant_get_tag_name") bt_ctf_field_type_variant_get_tag_name(struct bt_ctf_field_type *variant);
1346 %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);
1347 %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);
1348 %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);
1349 %rename("_bt_ctf_field_type_variant_get_field_count") bt_ctf_field_type_variant_get_field_count(struct bt_ctf_field_type *variant);
1350 %rename("_bt_ctf_field_type_variant_get_field") bt_ctf_field_type_variant_get_field(struct bt_ctf_field_type *variant, const char **field_name, struct bt_ctf_field_type **field_type, size_t index);
1351 %rename("_bt_ctf_field_type_array_create") bt_ctf_field_type_array_create(struct bt_ctf_field_type *element_type, unsigned int length);
1352 %rename("_bt_ctf_field_type_array_get_element_type") bt_ctf_field_type_array_get_element_type(struct bt_ctf_field_type *array);
1353 %rename("_bt_ctf_field_type_array_get_length") bt_ctf_field_type_array_get_length(struct bt_ctf_field_type *array);
1354 %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);
1355 %rename("_bt_ctf_field_type_sequence_get_element_type") bt_ctf_field_type_sequence_get_element_type(struct bt_ctf_field_type *sequence);
1356 %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);
1357 %rename("_bt_ctf_field_type_string_create") bt_ctf_field_type_string_create(void);
1358 %rename("_bt_ctf_field_type_string_get_encoding") bt_ctf_field_type_string_get_encoding(struct bt_ctf_field_type *string_type);
1359 %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);
1360 %rename("_bt_ctf_field_type_get_alignment") bt_ctf_field_type_get_alignment(struct bt_ctf_field_type *type);
1361 %rename("_bt_ctf_field_type_set_alignment") bt_ctf_field_type_set_alignment(struct bt_ctf_field_type *type, unsigned int alignment);
1362 %rename("_bt_ctf_field_type_get_byte_order") bt_ctf_field_type_get_byte_order(struct bt_ctf_field_type *type);
1363 %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);
1364 %rename("_bt_ctf_field_type_get_type_id") bt_ctf_field_type_get_type_id(struct bt_ctf_field_type *type);
1365 %rename("_bt_ctf_field_type_get") bt_ctf_field_type_get(struct bt_ctf_field_type *type);
1366 %rename("_bt_ctf_field_type_put") bt_ctf_field_type_put(struct bt_ctf_field_type *type);
1368 struct bt_ctf_field_type *bt_ctf_field_type_integer_create(unsigned int size);
1369 int bt_ctf_field_type_integer_get_size(struct bt_ctf_field_type *integer);
1370 int bt_ctf_field_type_integer_get_signed(struct bt_ctf_field_type *integer);
1371 int bt_ctf_field_type_integer_set_signed(struct bt_ctf_field_type *integer, int is_signed);
1372 enum bt_ctf_integer_base bt_ctf_field_type_integer_get_base(struct bt_ctf_field_type *integer);
1373 int bt_ctf_field_type_integer_set_base(struct bt_ctf_field_type *integer, enum bt_ctf_integer_base base);
1374 enum ctf_string_encoding bt_ctf_field_type_integer_get_encoding(struct bt_ctf_field_type *integer);
1375 int bt_ctf_field_type_integer_set_encoding(struct bt_ctf_field_type *integer, enum ctf_string_encoding encoding);
1376 struct bt_ctf_field_type *bt_ctf_field_type_enumeration_create(struct bt_ctf_field_type *integer_container_type);
1377 struct bt_ctf_field_type *bt_ctf_field_type_enumeration_get_container_type(struct bt_ctf_field_type *enumeration);
1378 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);
1379 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);
1380 int64_t bt_ctf_field_type_enumeration_get_mapping_count(struct bt_ctf_field_type *enumeration);
1381 int bt_ctf_field_type_enumeration_get_mapping(struct bt_ctf_field_type *enumeration, size_t index, const char **OUTPUT, int64_t *OUTPUT, int64_t *OUTPUT);
1382 int bt_ctf_field_type_enumeration_get_mapping_unsigned(struct bt_ctf_field_type *enumeration, size_t index, const char **OUTPUT, uint64_t *OUTPUT, uint64_t *OUTPUT);
1383 int bt_ctf_field_type_enumeration_get_mapping_index_by_name(struct bt_ctf_field_type *enumeration, const char *name, size_t *OUTPUT);
1384 int bt_ctf_field_type_enumeration_get_mapping_index_by_value(struct bt_ctf_field_type *enumeration, int64_t value, size_t *OUTPUT);
1385 int bt_ctf_field_type_enumeration_get_mapping_index_by_unsigned_value(struct bt_ctf_field_type *enumeration, uint64_t value, size_t *OUTPUT);
1386 struct bt_ctf_field_type *bt_ctf_field_type_floating_point_create(void);
1387 int bt_ctf_field_type_floating_point_get_exponent_digits(struct bt_ctf_field_type *floating_point);
1388 int bt_ctf_field_type_floating_point_set_exponent_digits(struct bt_ctf_field_type *floating_point, unsigned int exponent_digits);
1389 int bt_ctf_field_type_floating_point_get_mantissa_digits(struct bt_ctf_field_type *floating_point);
1390 int bt_ctf_field_type_floating_point_set_mantissa_digits(struct bt_ctf_field_type *floating_point, unsigned int mantissa_digits);
1391 struct bt_ctf_field_type *bt_ctf_field_type_structure_create(void);
1392 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);
1393 int64_t bt_ctf_field_type_structure_get_field_count(struct bt_ctf_field_type *structure);
1394 int bt_ctf_field_type_structure_get_field(struct bt_ctf_field_type *structure, const char **OUTPUT, struct bt_ctf_field_type **OUTPUT, size_t index);
1395 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);
1396 struct bt_ctf_field_type *bt_ctf_field_type_variant_create(struct bt_ctf_field_type *enum_tag, const char *tag_name);
1397 struct bt_ctf_field_type *bt_ctf_field_type_variant_get_tag_type(struct bt_ctf_field_type *variant);
1398 const char *bt_ctf_field_type_variant_get_tag_name(struct bt_ctf_field_type *variant);
1399 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);
1400 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);
1401 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);
1402 int64_t bt_ctf_field_type_variant_get_field_count(struct bt_ctf_field_type *variant);
1403 int bt_ctf_field_type_variant_get_field(struct bt_ctf_field_type *variant, const char **OUTPUT, struct bt_ctf_field_type **OUTPUT, size_t index);
1404 struct bt_ctf_field_type *bt_ctf_field_type_array_create(struct bt_ctf_field_type *element_type, unsigned int length);
1405 struct bt_ctf_field_type *bt_ctf_field_type_array_get_element_type(struct bt_ctf_field_type *array);
1406 int64_t bt_ctf_field_type_array_get_length(struct bt_ctf_field_type *array);
1407 struct bt_ctf_field_type *bt_ctf_field_type_sequence_create(struct bt_ctf_field_type *element_type, const char *length_field_name);
1408 struct bt_ctf_field_type *bt_ctf_field_type_sequence_get_element_type(struct bt_ctf_field_type *sequence);
1409 const char *bt_ctf_field_type_sequence_get_length_field_name(struct bt_ctf_field_type *sequence);
1410 struct bt_ctf_field_type *bt_ctf_field_type_string_create(void);
1411 enum ctf_string_encoding bt_ctf_field_type_string_get_encoding(struct bt_ctf_field_type *string_type);
1412 int bt_ctf_field_type_string_set_encoding(struct bt_ctf_field_type *string_type, enum ctf_string_encoding encoding);
1413 int bt_ctf_field_type_get_alignment(struct bt_ctf_field_type *type);
1414 int bt_ctf_field_type_set_alignment(struct bt_ctf_field_type *type, unsigned int alignment);
1415 enum bt_ctf_byte_order bt_ctf_field_type_get_byte_order(struct bt_ctf_field_type *type);
1416 int bt_ctf_field_type_set_byte_order(struct bt_ctf_field_type *type, enum bt_ctf_byte_order byte_order);
1417 enum ctf_type_id bt_ctf_field_type_get_type_id(struct bt_ctf_field_type *type);
1418 void bt_ctf_field_type_get(struct bt_ctf_field_type *type);
1419 void bt_ctf_field_type_put(struct bt_ctf_field_type *type);
1421 /* =================================================================
1423 ¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯
1425 %rename("_bt_ctf_field_create") bt_ctf_field_create(struct bt_ctf_field_type *type);
1426 %rename("_bt_ctf_field_structure_get_field") bt_ctf_field_structure_get_field(struct bt_ctf_field *structure, const char *name);
1427 %rename("_bt_ctf_field_array_get_field") bt_ctf_field_array_get_field(struct bt_ctf_field *array, uint64_t index);
1428 %rename("_bt_ctf_field_sequence_get_length") bt_ctf_field_sequence_get_length(struct bt_ctf_field *sequence);
1429 %rename("_bt_ctf_field_sequence_set_length") bt_ctf_field_sequence_set_length(struct bt_ctf_field *sequence, struct bt_ctf_field *length_field);
1430 %rename("_bt_ctf_field_sequence_get_field") bt_ctf_field_sequence_get_field(struct bt_ctf_field *sequence, uint64_t index);
1431 %rename("_bt_ctf_field_variant_get_field") bt_ctf_field_variant_get_field(struct bt_ctf_field *variant, struct bt_ctf_field *tag);
1432 %rename("_bt_ctf_field_enumeration_get_container") bt_ctf_field_enumeration_get_container(struct bt_ctf_field *enumeration);
1433 %rename("_bt_ctf_field_enumeration_get_mapping_name") bt_ctf_field_enumeration_get_mapping_name(struct bt_ctf_field *enumeration);
1434 %rename("_bt_ctf_field_signed_integer_get_value") bt_ctf_field_signed_integer_get_value(struct bt_ctf_field *integer, int64_t *value);
1435 %rename("_bt_ctf_field_signed_integer_set_value") bt_ctf_field_signed_integer_set_value(struct bt_ctf_field *integer, int64_t value);
1436 %rename("_bt_ctf_field_unsigned_integer_get_value") bt_ctf_field_unsigned_integer_get_value(struct bt_ctf_field *integer, uint64_t *value);
1437 %rename("_bt_ctf_field_unsigned_integer_set_value") bt_ctf_field_unsigned_integer_set_value(struct bt_ctf_field *integer, uint64_t value);
1438 %rename("_bt_ctf_field_floating_point_get_value") bt_ctf_field_floating_point_get_value(struct bt_ctf_field *floating_point, double *value);
1439 %rename("_bt_ctf_field_floating_point_set_value") bt_ctf_field_floating_point_set_value(struct bt_ctf_field *floating_point, double value);
1440 %rename("_bt_ctf_field_string_get_value") bt_ctf_field_string_get_value(struct bt_ctf_field *string_field);
1441 %rename("_bt_ctf_field_string_set_value") bt_ctf_field_string_set_value(struct bt_ctf_field *string_field, const char *value);
1442 %rename("_bt_ctf_field_get_type") bt_ctf_field_get_type(struct bt_ctf_field *field);
1443 %rename("_bt_ctf_field_get") bt_ctf_field_get(struct bt_ctf_field *field);
1444 %rename("_bt_ctf_field_put") bt_ctf_field_put(struct bt_ctf_field *field);
1446 struct bt_ctf_field *bt_ctf_field_create(struct bt_ctf_field_type *type);
1447 struct bt_ctf_field *bt_ctf_field_structure_get_field(struct bt_ctf_field *structure, const char *name);
1448 struct bt_ctf_field *bt_ctf_field_array_get_field(struct bt_ctf_field *array, uint64_t index);
1449 struct bt_ctf_field * bt_ctf_field_sequence_get_length(struct bt_ctf_field *sequence);
1450 int bt_ctf_field_sequence_set_length(struct bt_ctf_field *sequence, struct bt_ctf_field *length_field);
1451 struct bt_ctf_field *bt_ctf_field_sequence_get_field(struct bt_ctf_field *sequence, uint64_t index);
1452 struct bt_ctf_field *bt_ctf_field_variant_get_field(struct bt_ctf_field *variant, struct bt_ctf_field *tag);
1453 struct bt_ctf_field *bt_ctf_field_enumeration_get_container(struct bt_ctf_field *enumeration);
1454 const char *bt_ctf_field_enumeration_get_mapping_name(struct bt_ctf_field *enumeration);
1455 int bt_ctf_field_signed_integer_get_value(struct bt_ctf_field *integer, int64_t *OUTPUT);
1456 int bt_ctf_field_signed_integer_set_value(struct bt_ctf_field *integer, int64_t value);
1457 int bt_ctf_field_unsigned_integer_get_value(struct bt_ctf_field *integer, uint64_t *OUTPUT);
1458 int bt_ctf_field_unsigned_integer_set_value(struct bt_ctf_field *integer, uint64_t value);
1459 int bt_ctf_field_floating_point_get_value(struct bt_ctf_field *floating_point, double *OUTPUT);
1460 int bt_ctf_field_floating_point_set_value(struct bt_ctf_field *floating_point, double value);
1461 const char *bt_ctf_field_string_get_value(struct bt_ctf_field *string_field);
1462 int bt_ctf_field_string_set_value(struct bt_ctf_field *string_field, const char *value);
1463 struct bt_ctf_field_type *bt_ctf_field_get_type(struct bt_ctf_field *field);
1464 void bt_ctf_field_get(struct bt_ctf_field *field);
1465 void bt_ctf_field_put(struct bt_ctf_field *field);
1467 /* =================================================================
1469 ¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯
1471 %rename("_bt_ctf_event_class_create") bt_ctf_event_class_create(const char *name);
1472 %rename("_bt_ctf_event_class_get_name") bt_ctf_event_class_get_name(struct bt_ctf_event_class *event_class);
1473 %rename("_bt_ctf_event_class_get_id") bt_ctf_event_class_get_id(struct bt_ctf_event_class *event_class);
1474 %rename("_bt_ctf_event_class_set_id") bt_ctf_event_class_set_id(struct bt_ctf_event_class *event_class, uint32_t id);
1475 %rename("_bt_ctf_event_class_get_stream_class") bt_ctf_event_class_get_stream_class(struct bt_ctf_event_class *event_class);
1476 %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);
1477 %rename("_bt_ctf_event_class_get_field_count") bt_ctf_event_class_get_field_count(struct bt_ctf_event_class *event_class);
1478 %rename("_bt_ctf_event_class_get_field") bt_ctf_event_class_get_field(struct bt_ctf_event_class *event_class, const char **field_name, struct bt_ctf_field_type **field_type, size_t index);
1479 %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);
1480 %rename("_bt_ctf_event_class_get") bt_ctf_event_class_get(struct bt_ctf_event_class *event_class);
1481 %rename("_bt_ctf_event_class_put") bt_ctf_event_class_put(struct bt_ctf_event_class *event_class);
1482 %rename("_bt_ctf_event_create") bt_ctf_event_create(struct bt_ctf_event_class *event_class);
1483 %rename("_bt_ctf_event_get_class") bt_ctf_event_get_class(struct bt_ctf_event *event);
1484 %rename("_bt_ctf_event_get_clock") bt_ctf_event_get_clock(struct bt_ctf_event *event);
1485 %rename("_bt_ctf_event_get_payload") bt_ctf_event_get_payload(struct bt_ctf_event *event, const char *name);
1486 %rename("_bt_ctf_event_set_payload") bt_ctf_event_set_payload(struct bt_ctf_event *event, const char *name, struct bt_ctf_field *value);
1487 %rename("_bt_ctf_event_get_payload_by_index") bt_ctf_event_get_payload_by_index(struct bt_ctf_event *event, size_t index);
1488 %rename("_bt_ctf_event_get") bt_ctf_event_get(struct bt_ctf_event *event);
1489 %rename("_bt_ctf_event_put") bt_ctf_event_put(struct bt_ctf_event *event);
1491 struct bt_ctf_event_class *bt_ctf_event_class_create(const char *name);
1492 const char *bt_ctf_event_class_get_name(struct bt_ctf_event_class *event_class);
1493 int64_t bt_ctf_event_class_get_id(struct bt_ctf_event_class *event_class);
1494 int bt_ctf_event_class_set_id(struct bt_ctf_event_class *event_class, uint32_t id);
1495 struct bt_ctf_stream_class *bt_ctf_event_class_get_stream_class(struct bt_ctf_event_class *event_class);
1496 int bt_ctf_event_class_add_field(struct bt_ctf_event_class *event_class, struct bt_ctf_field_type *type, const char *name);
1497 int64_t bt_ctf_event_class_get_field_count(struct bt_ctf_event_class *event_class);
1498 int bt_ctf_event_class_get_field(struct bt_ctf_event_class *event_class, const char **field_name, struct bt_ctf_field_type **field_type, size_t index);
1499 struct bt_ctf_field_type *bt_ctf_event_class_get_field_by_name(struct bt_ctf_event_class *event_class, const char *name);
1500 void bt_ctf_event_class_get(struct bt_ctf_event_class *event_class);
1501 void bt_ctf_event_class_put(struct bt_ctf_event_class *event_class);
1502 struct bt_ctf_event *bt_ctf_event_create(struct bt_ctf_event_class *event_class);
1503 struct bt_ctf_event_class *bt_ctf_event_get_class(struct bt_ctf_event *event);
1504 struct bt_ctf_clock *bt_ctf_event_get_clock(struct bt_ctf_event *event);
1505 struct bt_ctf_field *bt_ctf_event_get_payload(struct bt_ctf_event *event, const char *name);
1506 int bt_ctf_event_set_payload(struct bt_ctf_event *event, const char *name, struct bt_ctf_field *value);
1507 struct bt_ctf_field *bt_ctf_event_get_payload_by_index(struct bt_ctf_event *event, size_t index);
1508 void bt_ctf_event_get(struct bt_ctf_event *event);
1509 void bt_ctf_event_put(struct bt_ctf_event *event);
1511 /* =================================================================
1513 ¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯
1515 %rename("_bt_ctf_stream_class_create") bt_ctf_stream_class_create(const char *name);
1516 %rename("_bt_ctf_stream_class_get_name") bt_ctf_stream_class_get_name(struct bt_ctf_stream_class *stream_class);
1517 %rename("_bt_ctf_stream_class_get_clock") bt_ctf_stream_class_get_clock(struct bt_ctf_stream_class *stream_class);
1518 %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);
1519 %rename("_bt_ctf_stream_class_get_id") bt_ctf_stream_class_get_id(struct bt_ctf_stream_class *stream_class);
1520 %rename("_bt_ctf_stream_class_set_id") bt_ctf_stream_class_set_id(struct bt_ctf_stream_class *stream_class, uint32_t id);
1521 %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);
1522 %rename("_bt_ctf_stream_class_get_event_class_count") bt_ctf_stream_class_get_event_class_count(struct bt_ctf_stream_class *stream_class);
1523 %rename("_bt_ctf_stream_class_get_event_class") bt_ctf_stream_class_get_event_class(struct bt_ctf_stream_class *stream_class, size_t index);
1524 %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);
1525 %rename("_bt_ctf_stream_class_get") bt_ctf_stream_class_get(struct bt_ctf_stream_class *stream_class);
1526 %rename("_bt_ctf_stream_class_put") bt_ctf_stream_class_put(struct bt_ctf_stream_class *stream_class);
1527 %rename("_bt_ctf_stream_get_discarded_events_count") bt_ctf_stream_get_discarded_events_count(struct bt_ctf_stream *stream, uint64_t *count);
1528 %rename("_bt_ctf_stream_append_discarded_events") bt_ctf_stream_append_discarded_events(struct bt_ctf_stream *stream, uint64_t event_count);
1529 %rename("_bt_ctf_stream_append_event") bt_ctf_stream_append_event(struct bt_ctf_stream *stream, struct bt_ctf_event *event);
1530 %rename("_bt_ctf_stream_flush") bt_ctf_stream_flush(struct bt_ctf_stream *stream);
1531 %rename("_bt_ctf_stream_get") bt_ctf_stream_get(struct bt_ctf_stream *stream);
1532 %rename("_bt_ctf_stream_put") bt_ctf_stream_put(struct bt_ctf_stream *stream);
1534 struct bt_ctf_stream_class *bt_ctf_stream_class_create(const char *name);
1535 const char *bt_ctf_stream_class_get_name(struct bt_ctf_stream_class *stream_class);
1536 struct bt_ctf_clock *bt_ctf_stream_class_get_clock(struct bt_ctf_stream_class *stream_class);
1537 int bt_ctf_stream_class_set_clock(struct bt_ctf_stream_class *stream_class, struct bt_ctf_clock *clock);
1538 int64_t bt_ctf_stream_class_get_id(struct bt_ctf_stream_class *stream_class);
1539 int bt_ctf_stream_class_set_id(struct bt_ctf_stream_class *stream_class, uint32_t id);
1540 int bt_ctf_stream_class_add_event_class(struct bt_ctf_stream_class *stream_class, struct bt_ctf_event_class *event_class);
1541 int64_t bt_ctf_stream_class_get_event_class_count(struct bt_ctf_stream_class *stream_class);
1542 struct bt_ctf_event_class *bt_ctf_stream_class_get_event_class(struct bt_ctf_stream_class *stream_class, size_t index);
1543 struct bt_ctf_event_class *bt_ctf_stream_class_get_event_class_by_name(struct bt_ctf_stream_class *stream_class, const char *name);
1544 void bt_ctf_stream_class_get(struct bt_ctf_stream_class *stream_class);
1545 void bt_ctf_stream_class_put(struct bt_ctf_stream_class *stream_class);
1546 int bt_ctf_stream_get_discarded_events_count(struct bt_ctf_stream *stream, uint64_t *OUTPUT);
1547 void bt_ctf_stream_append_discarded_events(struct bt_ctf_stream *stream, uint64_t event_count);
1548 int bt_ctf_stream_append_event(struct bt_ctf_stream *stream, struct bt_ctf_event *event);
1549 int bt_ctf_stream_flush(struct bt_ctf_stream *stream);
1550 void bt_ctf_stream_get(struct bt_ctf_stream *stream);
1551 void bt_ctf_stream_put(struct bt_ctf_stream *stream);
1553 /* =================================================================
1555 ¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯
1557 %rename("_bt_ctf_writer_create") bt_ctf_writer_create(const char *path);
1558 %rename("_bt_ctf_writer_create_stream") bt_ctf_writer_create_stream(struct bt_ctf_writer *writer, struct bt_ctf_stream_class *stream_class);
1559 %rename("_bt_ctf_writer_add_environment_field") bt_ctf_writer_add_environment_field(struct bt_ctf_writer *writer, const char *name, const char *value);
1560 %rename("_bt_ctf_writer_add_clock") bt_ctf_writer_add_clock(struct bt_ctf_writer *writer, struct bt_ctf_clock *clock);
1561 %newobject bt_ctf_writer_get_metadata_string;
1562 %rename("_bt_ctf_writer_get_metadata_string") bt_ctf_writer_get_metadata_string(struct bt_ctf_writer *writer);
1563 %rename("_bt_ctf_writer_flush_metadata") bt_ctf_writer_flush_metadata(struct bt_ctf_writer *writer);
1564 %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);
1565 %rename("_bt_ctf_writer_get") bt_ctf_writer_get(struct bt_ctf_writer *writer);
1566 %rename("_bt_ctf_writer_put") bt_ctf_writer_put(struct bt_ctf_writer *writer);
1568 struct bt_ctf_writer *bt_ctf_writer_create(const char *path);
1569 struct bt_ctf_stream *bt_ctf_writer_create_stream(struct bt_ctf_writer *writer, struct bt_ctf_stream_class *stream_class);
1570 int bt_ctf_writer_add_environment_field(struct bt_ctf_writer *writer, const char *name, const char *value);
1571 int bt_ctf_writer_add_clock(struct bt_ctf_writer *writer, struct bt_ctf_clock *clock);
1572 char *bt_ctf_writer_get_metadata_string(struct bt_ctf_writer *writer);
1573 void bt_ctf_writer_flush_metadata(struct bt_ctf_writer *writer);
1574 int bt_ctf_writer_set_byte_order(struct bt_ctf_writer *writer, enum bt_ctf_byte_order byte_order);
1575 void bt_ctf_writer_get(struct bt_ctf_writer *writer);
1576 void bt_ctf_writer_put(struct bt_ctf_writer *writer);
1581 # Used to compare to -1ULL in error checks
1582 _MAX_UINT64 = 0xFFFFFFFFFFFFFFFF
1585 Enumeration mapping class. start and end values are inclusive.
1587 class EnumerationMapping:
1588 def __init__(self, name, start, end):
1594 def __init__(self, name):
1595 self._c = _bt_ctf_clock_create(name)
1597 raise ValueError("Invalid clock name.")
1600 _bt_ctf_clock_put(self._c)
1603 Get the clock's name.
1607 name = _bt_ctf_clock_get_name(self._c)
1609 raise ValueError("Invalid clock instance.")
1613 Get the clock's description. None if unset.
1616 def description(self):
1617 return _bt_ctf_clock_get_description(self._c)
1620 Set the clock's description. The description appears in the clock's TSDL
1624 def description(self, desc):
1625 ret = _bt_ctf_clock_set_description(self._c, str(desc))
1627 raise ValueError("Invalid clock description.")
1630 Get the clock's frequency (Hz).
1633 def frequency(self):
1634 freq = _bt_ctf_clock_get_frequency(self._c)
1635 if freq == CTFWriter._MAX_UINT64:
1636 raise ValueError("Invalid clock instance")
1640 Set the clock's frequency (Hz).
1643 def frequency(self, freq):
1644 ret = _bt_ctf_clock_set_frequency(self._c, freq)
1646 raise ValueError("Invalid frequency value.")
1649 Get the clock's precision (in clock ticks).
1652 def precision(self):
1653 precision = _bt_ctf_clock_get_precision(self._c)
1654 if precision == CTFWriter._MAX_UINT64:
1655 raise ValueError("Invalid clock instance")
1659 Set the clock's precision (in clock ticks).
1662 def precision(self, precision):
1663 ret = _bt_ctf_clock_set_precision(self._c, precision)
1666 Get the clock's offset in seconds from POSIX.1 Epoch.
1669 def offset_seconds(self):
1670 offset_s = _bt_ctf_clock_get_offset_s(self._c)
1671 if offset_s == CTFWriter._MAX_UINT64:
1672 raise ValueError("Invalid clock instance")
1676 Set the clock's offset in seconds from POSIX.1 Epoch.
1678 @offset_seconds.setter
1679 def offset_seconds(self, offset_s):
1680 ret = _bt_ctf_clock_set_offset_s(self._c, offset_s)
1682 raise ValueError("Invalid offset value.")
1685 Get the clock's offset in ticks from POSIX.1 Epoch + offset in seconds.
1689 offset = _bt_ctf_clock_get_offset(self._c)
1690 if offset == CTFWriter._MAX_UINT64:
1691 raise ValueError("Invalid clock instance")
1695 Set the clock's offset in ticks from POSIX.1 Epoch + offset in seconds.
1698 def offset(self, offset):
1699 ret = _bt_ctf_clock_set_offset(self._c, offset)
1701 raise ValueError("Invalid offset value.")
1704 Get a clock's absolute attribute. A clock is absolute if the clock
1705 is a global reference across the trace's other clocks.
1709 is_absolute = _bt_ctf_clock_get_is_absolute(self._c)
1710 if is_absolute == -1:
1711 raise ValueError("Invalid clock instance")
1712 return False if is_absolute == 0 else True
1715 Set a clock's absolute attribute. A clock is absolute if the clock
1716 is a global reference across the trace's other clocks.
1719 def absolute(self, is_absolute):
1720 ret = _bt_ctf_clock_set_is_absolute(self._c, int(is_absolute))
1722 raise ValueError("Could not set the clock's absolute attribute.")
1725 Get the current time in nanoseconds since the clock's origin (offset and
1726 offset_s attributes).
1730 time = _bt_ctf_clock_get_time(self._c)
1731 if time == CTFWriter._MAX_UINT64:
1732 raise ValueError("Invalid clock instance")
1736 Set the current time in nanoseconds since the clock's origin (offset and
1737 offset_s attributes). The clock's value will be sampled as events are
1738 appended to a stream.
1741 def time(self, time):
1742 ret = _bt_ctf_clock_set_time(self._c, time)
1744 raise ValueError("Invalid time value.")
1746 class FieldDeclaration:
1748 FieldDeclaration should not be instantiated directly. Instantiate
1749 one of the concrete FieldDeclaration classes.
1752 # These values are based on the bt_ctf_integer_base enum
1753 # declared in event-types.h.
1754 INTEGER_BASE_UNKNOWN = -1
1755 INTEGER_BASE_BINARY = 2
1756 INTEGER_BASE_OCTAL = 8
1757 INTEGER_BASE_DECIMAL = 10
1758 INTEGER_BASE_HEXADECIMAL = 16
1761 if self._ft is None:
1762 raise ValueError("FieldDeclaration creation failed.")
1765 _bt_ctf_field_type_put(self._ft)
1768 def _create_field_declaration_from_native_instance(native_field_declaration):
1770 CTFTypeId.INTEGER : CTFWriter.IntegerFieldDeclaration,
1771 CTFTypeId.FLOAT : CTFWriter.FloatFieldDeclaration,
1772 CTFTypeId.ENUM : CTFWriter.EnumerationFieldDeclaration,
1773 CTFTypeId.STRING : CTFWriter.StringFieldDeclaration,
1774 CTFTypeId.STRUCT : CTFWriter.StructureFieldDeclaration,
1775 CTFTypeId.VARIANT : CTFWriter.VariantFieldDeclaration,
1776 CTFTypeId.ARRAY : CTFWriter.ArrayFieldDeclaration,
1777 CTFTypeId.SEQUENCE : CTFWriter.SequenceFieldDeclaration
1780 field_type_id = _bt_ctf_field_type_get_type_id(native_field_declaration)
1781 if field_type_id == CTFTypeId.UNKNOWN:
1782 raise TypeError("Invalid field instance")
1784 declaration = CTFWriter.Field.__new__(CTFWriter.Field)
1785 declaration._ft = native_field_declaration
1786 declaration.__class__ = type_dict[field_type_id]
1790 Get the field declaration's alignment. Returns -1 on error.
1793 def alignment(self):
1794 return _bt_ctf_field_type_get_alignment(self._ft)
1797 Set the field declaration's alignment. Defaults to 1 (bit-aligned). However,
1798 some types, such as structures and string, may impose other alignment
1802 def alignment(self, alignment):
1803 ret = _bt_ctf_field_type_set_alignment(self._ft, alignment)
1805 raise ValueError("Invalid alignment value.")
1808 Get the field declaration's byte order. One of the ByteOrder's constant.
1811 def byte_order(self):
1812 return _bt_ctf_field_type_get_byte_order(self._ft)
1815 Set the field declaration's byte order. Use constants defined in the ByteOrder
1819 def byte_order(self, byte_order):
1820 ret = _bt_ctf_field_type_set_byte_order(self._ft, byte_order)
1822 raise ValueError("Could not set byte order value.")
1824 class IntegerFieldDeclaration(FieldDeclaration):
1826 Create a new integer field declaration of the given size.
1828 def __init__(self, size):
1829 self._ft = _bt_ctf_field_type_integer_create(size)
1833 Get an integer's size.
1837 ret = _bt_ctf_field_type_integer_get_size(self._ft)
1839 raise ValueError("Could not get Integer's size attribute.")
1844 Get an integer's signedness attribute.
1848 ret = _bt_ctf_field_type_integer_get_signed(self._ft)
1850 raise ValueError("Could not get Integer's signed attribute.")
1857 Set an integer's signedness attribute.
1860 def signed(self, signed):
1861 ret = _bt_ctf_field_type_integer_set_signed(self._ft, signed)
1863 raise ValueError("Could not set Integer's signed attribute.")
1866 Get the integer's base used to pretty-print the resulting trace.
1867 Returns a constant from the FieldDeclaration.IntegerBase class.
1871 return _bt_ctf_field_type_integer_get_base(self._ft)
1874 Set the integer's base used to pretty-print the resulting trace.
1875 The base must be a constant of the FieldDeclarationIntegerBase class.
1878 def base(self, base):
1879 ret = _bt_ctf_field_type_integer_set_base(self._ft, base)
1881 raise ValueError("Could not set Integer's base.")
1884 Get the integer's encoding (one of the constants of the
1885 CTFStringEncoding class).
1886 Returns a constant from the CTFStringEncoding class.
1890 return _bt_ctf_field_type_integer_get_encoding(self._ft)
1893 An integer encoding may be set to signal that the integer must be printed
1894 as a text character. Must be a constant from the CTFStringEncoding class.
1897 def encoding(self, encoding):
1898 ret = _bt_ctf_field_type_integer_set_encoding(self._ft, encoding)
1900 raise ValueError("Could not set Integer's encoding.")
1902 class EnumerationFieldDeclaration(FieldDeclaration):
1904 Create a new enumeration field declaration with the given underlying container type.
1906 def __init__(self, integer_type):
1907 if integer_type is None or not isinstance(integer_type, CTFWriter.IntegerFieldDeclaration):
1908 raise TypeError("Invalid integer container.")
1910 self._ft = _bt_ctf_field_type_enumeration_create(integer_type._ft)
1914 Get the enumeration's underlying container type.
1917 def container(self):
1918 ret = _bt_ctf_field_type_enumeration_get_container_type(self._ft)
1920 raise TypeError("Invalid enumeration declaration")
1921 return CTFWriter.FieldDeclaration._create_field_declaration_from_native_instance(ret)
1924 Add a mapping to the enumeration. The range's values are inclusive.
1926 def add_mapping(self, name, range_start, range_end):
1927 if range_start < 0 or range_end < 0:
1928 ret = _bt_ctf_field_type_enumeration_add_mapping(self._ft, str(name), range_start, range_end)
1930 ret = _bt_ctf_field_type_enumeration_add_mapping_unsigned(self._ft, str(name), range_start, range_end)
1933 raise ValueError("Could not add mapping to enumeration declaration.")
1936 Generator returning instances of EnumerationMapping.
1940 signed = self.container.signed
1942 count = _bt_ctf_field_type_enumeration_get_mapping_count(self._ft)
1943 for i in range(count):
1945 ret = _bt_python_ctf_field_type_enumeration_get_mapping(self._ft, i)
1947 ret = _bt_python_ctf_field_type_enumeration_get_mapping_unsigned(self._ft, i)
1950 raise TypeError("Could not get Enumeration mapping at index {}".format(i))
1951 name, range_start, range_end = ret
1952 yield CTFWriter.EnumerationMapping(name, range_start, range_end)
1955 Get a mapping by name (EnumerationMapping).
1957 def get_mapping_by_name(self, name):
1958 ret, index = _bt_ctf_field_type_enumeration_get_mapping_index_by_name(self._ft, name);
1962 if self.container.signed:
1963 ret = _bt_python_ctf_field_type_enumeration_get_mapping(self._ft, index)
1965 ret = _bt_python_ctf_field_type_enumeration_get_mapping_unsigned(self._ft, index)
1968 raise TypeError("Could not get Enumeration mapping at index {}".format(i))
1969 name, range_start, range_end = ret
1970 return CTFWriter.EnumerationMapping(name, range_start, range_end)
1973 Get a mapping by value (EnumerationMapping).
1975 def get_mapping_by_value(self, value):
1977 ret, index = _bt_ctf_field_type_enumeration_get_mapping_index_by_value(self._ft, value);
1979 ret, index = _bt_ctf_field_type_enumeration_get_mapping_index_by_unsigned_value(self._ft, value);
1984 if self.container.signed:
1985 ret = _bt_python_ctf_field_type_enumeration_get_mapping(self._ft, index)
1987 ret = _bt_python_ctf_field_type_enumeration_get_mapping_unsigned(self._ft, index)
1990 raise TypeError("Could not get Enumeration mapping at index {}".format(i))
1991 name, range_start, range_end = ret
1992 return CTFWriter.EnumerationMapping(name, range_start, range_end)
1994 class FloatFieldDeclaration(FieldDeclaration):
2001 Create a new floating point field declaration.
2004 self._ft = _bt_ctf_field_type_floating_point_create()
2008 Get the number of exponent digits used to store the floating point field.
2011 def exponent_digits(self):
2012 ret = _bt_ctf_field_type_floating_point_get_exponent_digits(self._ft)
2014 raise TypeError("Could not get Floating point exponent digit count")
2018 Set the number of exponent digits to use to store the floating point field.
2019 The only values currently supported are FLT_EXP_DIG and DBL_EXP_DIG which
2020 are defined as constants of this class.
2022 @exponent_digits.setter
2023 def exponent_digits(self, exponent_digits):
2024 ret = _bt_ctf_field_type_floating_point_set_exponent_digits(self._ft, exponent_digits)
2026 raise ValueError("Could not set exponent digit count.")
2029 Get the number of mantissa digits used to store the floating point field.
2032 def mantissa_digits(self):
2033 ret = _bt_ctf_field_type_floating_point_get_mantissa_digits(self._ft)
2035 raise TypeError("Could not get Floating point mantissa digit count")
2039 Set the number of mantissa digits to use to store the floating point field.
2040 The only values currently supported are FLT_MANT_DIG and DBL_MANT_DIG which
2041 are defined as constants of this class.
2043 @mantissa_digits.setter
2044 def mantissa_digits(self, mantissa_digits):
2045 ret = _bt_ctf_field_type_floating_point_set_mantissa_digits(self._ft, mantissa_digits)
2047 raise ValueError("Could not set mantissa digit count.")
2049 class StructureFieldDeclaration(FieldDeclaration):
2051 Create a new structure field declaration.
2054 self._ft = _bt_ctf_field_type_structure_create()
2058 Add a field of type "field_type" to the structure.
2060 def add_field(self, field_type, field_name):
2061 ret = _bt_ctf_field_type_structure_add_field(self._ft, field_type._ft, str(field_name))
2063 raise ValueError("Could not add field to structure.")
2066 Generator returning the structure's field as tuples of (field name, field declaration).
2070 count = _bt_ctf_field_type_structure_get_field_count(self._ft)
2072 raise TypeError("Could not get Structure field count")
2074 for i in range(count):
2075 field_name = _bt_python_ctf_field_type_structure_get_field_name(self._ft, i)
2076 if field_name is None:
2077 raise TypeError("Could not get Structure field name at index {}".format(i))
2079 field_type_native = _bt_python_ctf_field_type_structure_get_field_type(self._ft, i)
2080 if field_type_native is None:
2081 raise TypeError("Could not get Structure field type at index {}".format(i))
2083 field_type = CTFWriter.FieldDeclaration._create_field_declaration_from_native_instance(field_type_native)
2084 yield (field_name, field_type)
2087 Get a field declaration by name (FieldDeclaration).
2089 def get_field_by_name(self, name):
2090 field_type_native = _bt_ctf_field_type_structure_get_field_type_by_name(self._ft, name)
2091 if field_type_native is None:
2092 raise TypeError("Could not find Structure field with name {}".format(name))
2094 return CTFWriter.FieldDeclaration._create_field_declaration_from_native_instance(field_type_native)
2096 class VariantFieldDeclaration(FieldDeclaration):
2098 Create a new variant field declaration.
2100 def __init__(self, enum_tag, tag_name):
2101 if enum_tag is None or not isinstance(enum_tag, CTFWriter.EnumerationFieldDeclaration):
2102 raise TypeError("Invalid tag type; must be of type EnumerationFieldDeclaration.")
2104 self._ft = _bt_ctf_field_type_variant_create(enum_tag._ft, str(tag_name))
2108 Get the variant's tag name.
2112 ret = _bt_ctf_field_type_variant_get_tag_name(self._ft)
2114 raise TypeError("Could not get Variant tag name")
2118 Get the variant's tag type.
2122 ret = _bt_ctf_field_type_variant_get_tag_type(self._ft)
2124 raise TypeError("Could not get Variant tag type")
2125 return CTFWriter.FieldDeclaration._create_field_declaration_from_native_instance(ret)
2128 Add a field of type "field_type" to the variant.
2130 def add_field(self, field_type, field_name):
2131 ret = _bt_ctf_field_type_variant_add_field(self._ft, field_type._ft, str(field_name))
2133 raise ValueError("Could not add field to variant.")
2136 Generator returning the variant's field as tuples of (field name, field declaration).
2140 count = _bt_ctf_field_type_variant_get_field_count(self._ft)
2142 raise TypeError("Could not get Variant field count")
2144 for i in range(count):
2145 field_name = _bt_python_ctf_field_type_variant_get_field_name(self._ft, i)
2146 if field_name is None:
2147 raise TypeError("Could not get Variant field name at index {}".format(i))
2149 field_type_native = _bt_python_ctf_field_type_variant_get_field_type(self._ft, i)
2150 if field_type_native is None:
2151 raise TypeError("Could not get Variant field type at index {}".format(i))
2153 field_type = CTFWriter.FieldDeclaration._create_field_declaration_from_native_instance(field_type_native)
2154 yield (field_name, field_type)
2157 Get a field declaration by name (FieldDeclaration).
2159 def get_field_by_name(self, name):
2160 field_type_native = _bt_ctf_field_type_variant_get_field_type_by_name(self._ft, name)
2161 if field_type_native is None:
2162 raise TypeError("Could not find Variant field with name {}".format(name))
2164 return CTFWriter.FieldDeclaration._create_field_declaration_from_native_instance(field_type_native)
2167 Get a field declaration from tag (EnumerationField).
2169 def get_field_from_tag(self, tag):
2170 field_type_native = _bt_ctf_field_type_variant_get_field_type_from_tag(self._ft, tag._f)
2171 if field_type_native is None:
2172 raise TypeError("Could not find Variant field with tag value {}".format(tag.value))
2174 return CTFWriter.FieldDeclaration._create_field_declaration_from_native_instance(field_type_native)
2176 class ArrayFieldDeclaration(FieldDeclaration):
2178 Create a new array field declaration.
2180 def __init__(self, element_type, length):
2181 self._ft = _bt_ctf_field_type_array_create(element_type._ft, length)
2185 Get the array's element type.
2188 def element_type(self):
2189 ret = _bt_ctf_field_type_array_get_element_type(self._ft)
2191 raise TypeError("Could not get Array element type")
2192 return CTFWriter.FieldDeclaration._create_field_declaration_from_native_instance(ret)
2195 Get the array's length.
2199 ret = _bt_ctf_field_type_array_get_length(self._ft)
2201 raise TypeError("Could not get Array length")
2204 class SequenceFieldDeclaration(FieldDeclaration):
2206 Create a new sequence field declaration.
2208 def __init__(self, element_type, length_field_name):
2209 self._ft = _bt_ctf_field_type_sequence_create(element_type._ft, str(length_field_name))
2213 Get the sequence's element type.
2216 def element_type(self):
2217 ret = _bt_ctf_field_type_sequence_get_element_type(self._ft)
2219 raise TypeError("Could not get Sequence element type")
2220 return CTFWriter.FieldDeclaration._create_field_declaration_from_native_instance(ret)
2223 Get the sequence's length field name.
2226 def length_field_name(self):
2227 ret = _bt_ctf_field_type_sequence_get_length_field_name(self._ft)
2229 raise TypeError("Could not get Sequence length field name")
2232 class StringFieldDeclaration(FieldDeclaration):
2234 Create a new string field declaration.
2237 self._ft = _bt_ctf_field_type_string_create()
2241 Get a string declaration's encoding (a constant from the CTFStringEncoding class).
2245 return _bt_ctf_field_type_string_get_encoding(self._ft)
2248 Set a string declaration's encoding. Must be a constant from the CTFStringEncoding class.
2251 def encoding(self, encoding):
2252 ret = _bt_ctf_field_type_string_set_encoding(self._ft, encoding)
2254 raise ValueError("Could not set string encoding.")
2257 Create an instance of a field.
2260 def create_field(field_type):
2261 if field_type is None or not isinstance(field_type, CTFWriter.FieldDeclaration):
2262 raise TypeError("Invalid field_type. Type must be a FieldDeclaration-derived class.")
2264 if isinstance(field_type, CTFWriter.IntegerFieldDeclaration):
2265 return CTFWriter.IntegerField(field_type)
2266 elif isinstance(field_type, CTFWriter.EnumerationFieldDeclaration):
2267 return CTFWriter.EnumerationField(field_type)
2268 elif isinstance(field_type, CTFWriter.FloatFieldDeclaration):
2269 return CTFWriter.FloatFieldingPoint(field_type)
2270 elif isinstance(field_type, CTFWriter.StructureFieldDeclaration):
2271 return CTFWriter.StructureField(field_type)
2272 elif isinstance(field_type, CTFWriter.VariantFieldDeclaration):
2273 return CTFWriter.VariantField(field_type)
2274 elif isinstance(field_type, CTFWriter.ArrayFieldDeclaration):
2275 return CTFWriter.ArrayField(field_type)
2276 elif isinstance(field_type, CTFWriter.SequenceFieldDeclaration):
2277 return CTFWriter.SequenceField(field_type)
2278 elif isinstance(field_type, CTFWriter.StringFieldDeclaration):
2279 return CTFWriter.StringField(field_type)
2283 Base class, do not instantiate.
2285 def __init__(self, field_type):
2286 if not isinstance(field_type, CTFWriter.FieldDeclaration):
2287 raise TypeError("Invalid field_type argument.")
2289 self._f = _bt_ctf_field_create(field_type._ft)
2291 raise ValueError("Field creation failed.")
2294 _bt_ctf_field_put(self._f)
2297 def _create_field_from_native_instance(native_field_instance):
2299 CTFTypeId.INTEGER : CTFWriter.IntegerField,
2300 CTFTypeId.FLOAT : CTFWriter.FloatFieldingPoint,
2301 CTFTypeId.ENUM : CTFWriter.EnumerationField,
2302 CTFTypeId.STRING : CTFWriter.StringField,
2303 CTFTypeId.STRUCT : CTFWriter.StructureField,
2304 CTFTypeId.VARIANT : CTFWriter.VariantField,
2305 CTFTypeId.ARRAY : CTFWriter.ArrayField,
2306 CTFTypeId.SEQUENCE : CTFWriter.SequenceField
2309 field_type = _bt_python_get_field_type(native_field_instance)
2310 if field_type == CTFTypeId.UNKNOWN:
2311 raise TypeError("Invalid field instance")
2313 field = CTFWriter.Field.__new__(CTFWriter.Field)
2314 field._f = native_field_instance
2315 field.__class__ = type_dict[field_type]
2319 def declaration(self):
2320 native_field_type = _bt_ctf_field_get_type(self._f)
2321 if native_field_type is None:
2322 raise TypeError("Invalid field instance")
2323 return CTFWriter.FieldDeclaration._create_field_declaration_from_native_instance(native_field_type)
2325 class IntegerField(Field):
2327 Get an integer field's value.
2331 signedness = _bt_python_field_integer_get_signedness(self._f)
2333 raise TypeError("Invalid integer instance.")
2336 ret, value = _bt_ctf_field_unsigned_integer_get_value(self._f)
2338 ret, value = _bt_ctf_field_signed_integer_get_value(self._f)
2341 raise ValueError("Could not get integer field value.")
2345 Set an integer field's value.
2348 def value(self, value):
2349 if not isinstance(value, int):
2350 raise TypeError("IntegerField's value must be an int")
2352 signedness = _bt_python_field_integer_get_signedness(self._f)
2354 raise TypeError("Invalid integer instance.")
2357 ret = _bt_ctf_field_unsigned_integer_set_value(self._f, value)
2359 ret = _bt_ctf_field_signed_integer_set_value(self._f, value)
2362 raise ValueError("Could not set integer field value.")
2364 class EnumerationField(Field):
2366 Return the enumeration's underlying container field (an integer field).
2369 def container(self):
2370 container = CTFWriter.IntegerField.__new__(CTFWriter.IntegerField)
2371 container._f = _bt_ctf_field_enumeration_get_container(self._f)
2372 if container._f is None:
2373 raise TypeError("Invalid enumeration field type.")
2377 Get the enumeration field's mapping name.
2381 value = _bt_ctf_field_enumeration_get_mapping_name(self._f)
2383 raise ValueError("Could not get enumeration's mapping name.")
2387 Set the enumeration field's value. Must be an integer as mapping names
2391 def value(self, value):
2392 if not isinstance(value, int):
2393 raise TypeError("EnumerationField value must be an int")
2394 self.container.value = value
2396 class FloatFieldingPoint(Field):
2398 Get a floating point field's value.
2402 ret, value = _bt_ctf_field_floating_point_get_value(self._f)
2404 raise ValueError("Could not get floating point field value.")
2408 Set a floating point field's value.
2411 def value(self, value):
2412 if not isinstance(value, int) and not isinstance(value, float):
2413 raise TypeError("Value must be either a float or an int")
2415 ret = _bt_ctf_field_floating_point_set_value(self._f, float(value))
2417 raise ValueError("Could not set floating point field value.")
2419 class StructureField(Field):
2421 Get the structure's field corresponding to the provided field name.
2423 def field(self, field_name):
2424 native_instance = _bt_ctf_field_structure_get_field(self._f, str(field_name))
2425 if native_instance is None:
2426 raise ValueError("Invalid field_name provided.")
2427 return CTFWriter.Field._create_field_from_native_instance(native_instance)
2429 class VariantField(Field):
2431 Return the variant's selected field. The "tag" field is the selector enum field.
2433 def field(self, tag):
2434 native_instance = _bt_ctf_field_variant_get_field(self._f, tag._f)
2435 if native_instance is None:
2436 raise ValueError("Invalid tag provided.")
2437 return CTFWriter.Field._create_field_from_native_instance(native_instance)
2439 class ArrayField(Field):
2441 Return the array's field at position "index".
2443 def field(self, index):
2444 native_instance = _bt_ctf_field_array_get_field(self._f, index)
2445 if native_instance is None:
2446 raise IndexError("Invalid index provided.")
2447 return CTFWriter.Field._create_field_from_native_instance(native_instance)
2449 class SequenceField(Field):
2451 Get the sequence's length field (IntegerField).
2455 native_instance = _bt_ctf_field_sequence_get_length(self._f)
2456 if native_instance is None:
2458 return CTFWriter.Field._create_field_from_native_instance(native_instance)
2461 Set the sequence's length field (IntegerField).
2464 def length(self, length_field):
2465 if not isinstance(length_field, CTFWriter.IntegerField):
2466 raise TypeError("Invalid length field.")
2467 if length_field.declaration.signed:
2468 raise TypeError("Sequence field length must be unsigned")
2469 ret = _bt_ctf_field_sequence_set_length(self._f, length_field._f)
2471 raise ValueError("Could not set sequence length.")
2474 Return the sequence's field at position "index".
2476 def field(self, index):
2477 native_instance = _bt_ctf_field_sequence_get_field(self._f, index)
2478 if native_instance is None:
2479 raise ValueError("Could not get sequence element at index.")
2480 return CTFWriter.Field._create_field_from_native_instance(native_instance)
2482 class StringField(Field):
2484 Get a string field's value.
2488 return _bt_ctf_field_string_get_value(self._f)
2491 Set a string field's value.
2494 def value(self, value):
2495 ret = _bt_ctf_field_string_set_value(self._f, str(value))
2497 raise ValueError("Could not set string field value.")
2501 Create a new event class of the given name.
2503 def __init__(self, name):
2504 self._ec = _bt_ctf_event_class_create(name)
2505 if self._ec is None:
2506 raise ValueError("Event class creation failed.")
2509 _bt_ctf_event_class_put(self._ec)
2512 Add a field of type "field_type" to the event class.
2514 def add_field(self, field_type, field_name):
2515 ret = _bt_ctf_event_class_add_field(self._ec, field_type._ft, str(field_name))
2517 raise ValueError("Could not add field to event class.")
2520 Get the event class' name.
2524 name = _bt_ctf_event_class_get_name(self._ec)
2526 raise TypeError("Could not get EventClass name")
2530 Get the event class' id. Returns a negative value if unset.
2534 id = _bt_ctf_event_class_get_id(self._ec)
2536 raise TypeError("Could not get EventClass id")
2540 Set the event class' id. Throws a TypeError if the event class
2541 is already registered to a stream class.
2545 ret = _bt_ctf_event_class_set_id(self._ec, id)
2547 raise TypeError("Can't change an Event Class's id after it has been assigned to a stream class")
2550 Get the event class' stream class. Returns None if unset.
2553 def stream_class(self):
2554 stream_class_native = _bt_ctf_event_class_get_stream_class(self._ec)
2555 if stream_class_native is None:
2557 stream_class = CTFWriter.StreamClass.__new__(CTFWriter.StreamClass)
2558 stream_class._sc = stream_class_native
2562 Generator returning the event class' fields as tuples of (field name, field declaration).
2566 count = _bt_ctf_event_class_get_field_count(self._ec)
2568 raise TypeError("Could not get EventClass' field count")
2570 for i in range(count):
2571 field_name = _bt_python_ctf_event_class_get_field_name(self._ec, i)
2572 if field_name is None:
2573 raise TypeError("Could not get EventClass' field name at index {}".format(i))
2575 field_type_native = _bt_python_ctf_event_class_get_field_type(self._ec, i)
2576 if field_type_native is None:
2577 raise TypeError("Could not get EventClass' field type at index {}".format(i))
2579 field_type = CTFWriter.FieldDeclaration._create_field_declaration_from_native_instance(field_type_native)
2580 yield (field_name, field_type)
2583 Get a field declaration by name (FieldDeclaration).
2585 def get_field_by_name(self, name):
2586 field_type_native = _bt_ctf_event_class_get_field_by_name(self._ec, name)
2587 if field_type_native is None:
2588 raise TypeError("Could not find EventClass field with name {}".format(name))
2589 return CTFWriter.FieldDeclaration._create_field_declaration_from_native_instance(field_type_native)
2593 Create a new event of the given event class.
2595 def __init__(self, event_class):
2596 if not isinstance(event_class, CTFWriter.EventClass):
2597 raise TypeError("Invalid event_class argument.")
2599 self._e = _bt_ctf_event_create(event_class._ec)
2601 raise ValueError("Event creation failed.")
2604 _bt_ctf_event_put(self._e)
2607 Get the event's class.
2610 def event_class(self):
2611 event_class_native = _bt_ctf_event_get_class(self._e)
2612 if event_class_native is None:
2614 event_class = CTFWriter.EventClass.__new__(CTFWriter.EventClass)
2615 event_class._ec = event_class_native
2619 Get a clock from event. Returns None if the event's class
2620 is not registered to a stream class.
2623 clock_instance = _bt_ctf_event_get_clock(self._e)
2624 if clock_instance is None:
2626 clock = CTFWriter.Clock.__new__(CTFWriter.Clock)
2627 clock._c = clock_instance
2631 Get a field from event.
2633 def payload(self, field_name):
2634 native_instance = _bt_ctf_event_get_payload(self._e, str(field_name))
2635 if native_instance is None:
2636 raise ValueError("Could not get event payload.")
2637 return CTFWriter.Field._create_field_from_native_instance(native_instance)
2640 Set a manually created field as an event's payload.
2642 def set_payload(self, field_name, value_field):
2643 if not isinstance(value, CTFWriter.Field):
2644 raise TypeError("Invalid value type.")
2645 ret = _bt_ctf_event_set_payload(self._e, str(field_name), value_field._f)
2647 raise ValueError("Could not set event field payload.")
2651 Create a new stream class of the given name.
2653 def __init__(self, name):
2654 self._sc = _bt_ctf_stream_class_create(name)
2655 if self._sc is None:
2656 raise ValueError("Stream class creation failed.")
2659 _bt_ctf_stream_class_put(self._sc)
2662 Get a stream class' name.
2666 name = _bt_ctf_stream_class_get_name(self._sc)
2668 raise TypeError("Could not get StreamClass name")
2672 Get a stream class' clock.
2676 clock_instance = _bt_ctf_stream_class_get_clock(self._sc)
2677 if clock_instance is None:
2679 clock = CTFWriter.Clock.__new__(CTFWriter.Clock)
2680 clock._c = clock_instance
2684 Assign a clock to a stream class.
2687 def clock(self, clock):
2688 if not isinstance(clock, CTFWriter.Clock):
2689 raise TypeError("Invalid clock type.")
2691 ret = _bt_ctf_stream_class_set_clock(self._sc, clock._c)
2693 raise ValueError("Could not set stream class clock.")
2696 Get a stream class' id.
2700 ret = _bt_ctf_stream_class_get_id(self._sc)
2702 raise TypeError("Could not get StreamClass id")
2706 Assign an id to a stream class.
2710 ret = _bt_ctf_stream_class_set_id(self._sc, id)
2712 raise TypeError("Could not set stream class id.")
2715 Generator returning the stream class' event classes.
2718 def event_classes(self):
2719 count = _bt_ctf_stream_class_get_event_class_count(self._sc)
2721 raise TypeError("Could not get StreamClass' event class count")
2723 for i in range(count):
2724 event_class_native = _bt_ctf_stream_class_get_event_class(self._sc, i)
2725 if event_class_native is None:
2726 raise TypeError("Could not get StreamClass' event class at index {}".format(i))
2728 event_class = CTFWriter.EventClass.__new__(CTFWriter.EventClass)
2729 event_class._ec = event_class_native
2733 Add an event class to a stream class. New events can be added even after a
2734 stream has been instantiated and events have been appended. However, a stream
2735 will not accept events of a class that has not been registered beforehand.
2737 def add_event_class(self, event_class):
2738 if not isinstance(event_class, CTFWriter.EventClass):
2739 raise TypeError("Invalid event_class type.")
2741 ret = _bt_ctf_stream_class_add_event_class(self._sc, event_class._ec)
2743 raise ValueError("Could not add event class.")
2747 Create a stream of the given class.
2749 def __init__(self, stream_class):
2750 if not isinstance(stream_class, CTFWriter.StreamClass):
2751 raise TypeError("Invalid stream_class type.")
2753 self._s = _bt_ctf_stream_create(stream_class._sc)
2755 raise ValueError("Stream creation failed.")
2758 _bt_ctf_stream_put(self._s)
2761 Get a stream's discarded event count.
2764 def discarded_events(self):
2765 ret, count = _bt_ctf_stream_get_discarded_events_count(self._s)
2767 raise ValueError("Could not get the stream's discarded events count")
2771 Increase the current packet's discarded event count.
2773 def append_discarded_events(self, event_count):
2774 _bt_ctf_stream_append_discarded_events(self._s, event_count)
2777 Append "event" to the stream's current packet. The stream's associated clock
2778 will be sampled during this call. The event shall not be modified after
2779 being appended to a stream.
2781 def append_event(self, event):
2782 ret = _bt_ctf_stream_append_event(self._s, event._e)
2784 raise ValueError("Could not append event to stream.")
2787 The stream's current packet's events will be flushed to disk. Events
2788 subsequently appended to the stream will be added to a new packet.
2791 ret = _bt_ctf_stream_flush(self._s)
2793 raise ValueError("Could not flush stream.")
2797 Create a new writer that will produce a trace in the given path.
2799 def __init__(self, path):
2800 self._w = _bt_ctf_writer_create(path)
2802 raise ValueError("Writer creation failed.")
2805 _bt_ctf_writer_put(self._w)
2808 Create a new stream instance and register it to the writer.
2810 def create_stream(self, stream_class):
2811 if not isinstance(stream_class, CTFWriter.StreamClass):
2812 raise TypeError("Invalid stream_class type.")
2814 stream = CTFWriter.Stream.__new__(CTFWriter.Stream)
2815 stream._s = _bt_ctf_writer_create_stream(self._w, stream_class._sc)
2819 Add an environment field to the trace.
2821 def add_environment_field(self, name, value):
2822 ret = _bt_ctf_writer_add_environment_field(self._w, str(name), str(value))
2824 raise ValueError("Could not add environment field to trace.")
2827 Add a clock to the trace. Clocks assigned to stream classes must be
2828 registered to the writer.
2830 def add_clock(self, clock):
2831 ret = _bt_ctf_writer_add_clock(self._w, clock._c)
2833 raise ValueError("Could not add clock to Writer.")
2836 Get the trace's TSDL meta-data.
2840 return _bt_ctf_writer_get_metadata_string(self._w)
2843 Flush the trace's metadata to the metadata file.
2845 def flush_metadata(self):
2846 _bt_ctf_writer_flush_metadata(self._w)
2849 Get the trace's byte order. Must be a constant from the ByteOrder
2853 def byte_order(self):
2854 raise NotImplementedError("Getter not implemented.")
2857 Set the trace's byte order. Must be a constant from the ByteOrder
2858 class. Defaults to BYTE_ORDER_NATIVE, the host machine's endianness.
2861 def byte_order(self, byte_order):
2862 ret = _bt_ctf_writer_set_byte_order(self._w, byte_order)
2864 raise ValueError("Could not set trace's byte order.")