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 from datetime import datetime
657 class Event(collections.Mapping):
659 This class represents an event from the trace.
660 It is obtained using the TraceCollection generator functions.
664 raise NotImplementedError("Event cannot be instantiated")
668 """Return the name of the event or None on error."""
669 return _bt_ctf_event_name(self._e)
674 Return the timestamp of the event as written in
675 the packet (in cycles) or -1ULL on error.
677 return _bt_ctf_get_cycles(self._e)
682 Return the timestamp of the event offset with the
683 system clock source or -1ULL on error.
685 return _bt_ctf_get_timestamp(self._e)
690 Return a datetime object based on the event's
691 timestamp. Note that the datetime class' precision
692 is limited to microseconds.
694 return datetime.fromtimestamp(self.timestamp / 1E9)
696 def field_with_scope(self, field_name, scope):
698 Get field_name's value in scope.
699 None is returned if no field matches field_name.
701 if not scope in _scopes:
702 raise ValueError("Invalid scope provided")
703 field = self._field_with_scope(field_name, scope)
704 if field is not None:
708 def field_list_with_scope(self, scope):
709 """Return a list of field names in scope."""
710 if not scope in _scopes:
711 raise ValueError("Invalid scope provided")
713 for field in self._field_list_with_scope(scope):
714 field_names.append(field.name)
720 Get the TraceHandle associated with this event
723 ret = _bt_ctf_event_get_handle_id(self._e)
727 th = TraceHandle.__new__(TraceHandle)
729 th._trace_collection = self.get_trace_collection()
733 def trace_collection(self):
735 Get the TraceCollection associated with this event.
736 Return None on error.
738 trace_collection = TraceCollection()
739 trace_collection._tc = _bt_ctf_event_get_context(self._e);
740 if trace_collection._tc is None:
743 return trace_collection
745 def __getitem__(self, field_name):
747 Get field_name's value. If the field_name exists in multiple
748 scopes, the first field found is returned. The scopes are searched
749 in the following order:
752 3) STREAM_EVENT_CONTEXT
753 4) STREAM_EVENT_HEADER
754 5) STREAM_PACKET_CONTEXT
755 6) TRACE_PACKET_HEADER
756 None is returned if no field matches field_name.
758 Use field_with_scope() to explicitly access fields in a given
761 field = self._field(field_name)
762 if field is not None:
764 raise KeyError(field_name)
767 for key in self.keys():
772 for scope in _scopes:
773 scope_ptr = _bt_ctf_get_top_level_scope(self._e, scope)
774 ret = _bt_python_field_listcaller(self._e, scope_ptr)
775 if isinstance(ret, list):
779 def __contains__(self, field_name):
780 return self._field(field_name) is not None
783 """Return a list of field names."""
785 for scope in _scopes:
786 for name in self.field_list_with_scope(scope):
787 field_names.add(name)
788 return list(field_names)
790 def get(self, field_name, default = None):
791 field = self._field(field_name)
797 for field in self.keys():
798 yield (field, self[field])
800 def _field_with_scope(self, field_name, scope):
801 scope_ptr = _bt_ctf_get_top_level_scope(self._e, scope)
802 if scope_ptr is None:
805 definition_ptr = _bt_ctf_get_field(self._e, scope_ptr, field_name)
806 if definition_ptr is None:
809 field = _Definition(definition_ptr, scope)
812 def _field(self, field_name):
814 for scope in _scopes:
815 field = self._field_with_scope(field_name, scope)
816 if field is not None:
820 def _field_list_with_scope(self, scope):
822 scope_ptr = _bt_ctf_get_top_level_scope(self._e, scope)
824 # Returns a list [list_ptr, count]. If list_ptr is NULL, SWIG will only
825 # provide the "count" return value
828 ret = _bt_python_field_listcaller(self._e, scope_ptr)
829 if isinstance(ret, list):
830 list_ptr, count = ret
832 for i in range(count):
833 definition_ptr = _bt_python_field_one_from_list(list_ptr, i)
834 if definition_ptr is not None:
835 definition = _Definition(definition_ptr, scope)
836 fields.append(definition)
839 class FieldError(Exception):
840 def __init__(self, value):
844 return repr(self.value)
846 class EventDeclaration(object):
847 """Event declaration class. Do not instantiate."""
848 MAX_UINT64 = 0xFFFFFFFFFFFFFFFF
851 raise NotImplementedError("EventDeclaration cannot be instantiated")
855 """Return the name of the event or None on error"""
856 return _bt_ctf_get_decl_event_name(self._ed)
860 """Return the event-ID of the event or -1 on error"""
861 id = _bt_ctf_get_decl_event_id(self._ed)
862 if id == self.MAX_UINT64:
869 Generator returning all FieldDeclarations of an event, going through
870 each scope in the following order:
873 3) STREAM_EVENT_CONTEXT
874 4) STREAM_EVENT_HEADER
875 5) STREAM_PACKET_CONTEXT
876 6) TRACE_PACKET_HEADER
878 for scope in _scopes:
879 for declaration in self.fields_scope(scope):
882 def fields_scope(self, scope):
884 Generator returning FieldDeclarations of the current event in scope.
886 ret = _by_python_field_decl_listcaller(self._ed, scope)
888 if not isinstance(ret, list):
891 list_ptr, count = ret
892 for i in range(count):
893 field_declaration_ptr = _bt_python_field_decl_one_from_list(list_ptr, i)
894 if field_declaration_ptr is not None:
895 declaration_ptr = _bt_ctf_get_decl_from_field_decl(field_declaration_ptr)
896 field_declaration = _create_field_declaration(declaration_ptr, _bt_ctf_get_decl_field_name(field_declaration_ptr), scope)
897 yield field_declaration
899 class FieldDeclaration(object):
900 """Field declaration class. Do not instantiate."""
902 raise NotImplementedError("FieldDeclaration cannot be instantiated")
905 return "({0}) {1} {2}".format(CTFScope.scope_name(self.scope), CTFTypeId.type_name(self.type), self.name)
909 """Return the name of a FieldDeclaration or None on error."""
915 Return the FieldDeclaration's type. One of the entries in class
918 return _bt_ctf_field_type(self._fd)
923 Return the FieldDeclaration's scope.
927 class IntegerFieldDeclaration(FieldDeclaration):
928 """Do not instantiate."""
930 raise NotImplementedError("IntegerFieldDeclaration cannot be instantiated")
933 def signedness(self):
935 Return the signedness of an integer:
936 0 if unsigned; 1 if signed; -1 on error.
938 return _bt_ctf_get_int_signedness(self._fd)
942 """Return the base of an int or a negative value on error."""
943 return _bt_ctf_get_int_base(self._fd)
946 def byte_order(self):
948 Return the byte order. One of class ByteOrder's entries.
950 ret = _bt_ctf_get_int_byte_order(self._fd)
952 return ByteOrder.BYTE_ORDER_LITTLE_ENDIAN
954 return ByteOrder.BYTE_ORDER_BIG_ENDIAN
956 return ByteOrder.BYTE_ORDER_UNKNOWN
961 Return the size, in bits, of an int or a negative
964 return _bt_ctf_get_int_len(self._fd)
969 Return the encoding. One of class CTFStringEncoding's entries.
970 Return a negative value on error.
972 return _bt_ctf_get_encoding(self._fd)
974 class EnumerationFieldDeclaration(FieldDeclaration):
975 """Do not instantiate."""
977 raise NotImplementedError("EnumerationFieldDeclaration cannot be instantiated")
979 class ArrayFieldDeclaration(FieldDeclaration):
980 """Do not instantiate."""
982 raise NotImplementedError("ArrayFieldDeclaration cannot be instantiated")
987 Return the length of an array or a negative
990 return _bt_ctf_get_array_len(self._fd)
993 def element_declaration(self):
995 Return element declaration.
997 field_decl_ptr = _bt_python_get_array_element_declaration(self._fd)
998 return _create_field_declaration(field_decl_ptr, "", self.scope)
1000 class SequenceFieldDeclaration(FieldDeclaration):
1001 """Do not instantiate."""
1003 raise NotImplementedError("SequenceFieldDeclaration cannot be instantiated")
1006 def element_declaration(self):
1008 Return element declaration.
1010 field_decl_ptr = _bt_python_get_sequence_element_declaration(self._fd)
1011 return _create_field_declaration(field_decl_ptr, "", self.scope)
1013 class FloatFieldDeclaration(FieldDeclaration):
1014 """Do not instantiate."""
1016 raise NotImplementedError("FloatFieldDeclaration cannot be instantiated")
1018 class StructureFieldDeclaration(FieldDeclaration):
1019 """Do not instantiate."""
1021 raise NotImplementedError("StructureFieldDeclaration cannot be instantiated")
1023 class StringFieldDeclaration(FieldDeclaration):
1024 """Do not instantiate."""
1026 raise NotImplementedError("StringFieldDeclaration cannot be instantiated")
1028 class VariantFieldDeclaration(FieldDeclaration):
1029 """Do not instantiate."""
1031 raise NotImplementedError("VariantFieldDeclaration cannot be instantiated")
1035 Return the last error code encountered while
1036 accessing a field and reset the error flag.
1037 Return 0 if no error, a negative value otherwise.
1039 return _bt_ctf_field_get_error()
1041 def _create_field_declaration(declaration_ptr, name, scope):
1043 Private field declaration factory.
1045 if declaration_ptr is None:
1046 raise ValueError("declaration_ptr must be valid")
1047 if not scope in _scopes:
1048 raise ValueError("Invalid scope provided")
1050 type = _bt_ctf_field_type(declaration_ptr)
1052 if type == CTFTypeId.INTEGER:
1053 declaration = IntegerFieldDeclaration.__new__(IntegerFieldDeclaration)
1054 elif type == CTFTypeId.ENUM:
1055 declaration = EnumerationFieldDeclaration.__new__(EnumerationFieldDeclaration)
1056 elif type == CTFTypeId.ARRAY:
1057 declaration = ArrayFieldDeclaration.__new__(ArrayFieldDeclaration)
1058 elif type == CTFTypeId.SEQUENCE:
1059 declaration = SequenceFieldDeclaration.__new__(SequenceFieldDeclaration)
1060 elif type == CTFTypeId.FLOAT:
1061 declaration = FloatFieldDeclaration.__new__(FloatFieldDeclaration)
1062 elif type == CTFTypeId.STRUCT:
1063 declaration = StructureFieldDeclaration.__new__(StructureFieldDeclaration)
1064 elif type == CTFTypeId.STRING:
1065 declaration = StringFieldDeclaration.__new__(StringFieldDeclaration)
1066 elif type == CTFTypeId.VARIANT:
1067 declaration = VariantFieldDeclaration.__new__(VariantFieldDeclaration)
1071 declaration._fd = declaration_ptr
1072 declaration._s = scope
1073 declaration._name = name
1076 class _Definition(object):
1077 def __init__(self, definition_ptr, scope):
1078 self._d = definition_ptr
1080 if not scope in _scopes:
1081 ValueError("Invalid scope provided")
1085 """Return the name of a field or None on error."""
1086 return _bt_ctf_field_name(self._d)
1090 """Return the type of a field or -1 if unknown."""
1091 return _bt_ctf_field_type(_bt_ctf_get_decl_from_def(self._d))
1094 def declaration(self):
1095 """Return the associated Definition object."""
1096 return _create_field_declaration(_bt_ctf_get_decl_from_def(self._d), self.name, self.scope)
1098 def _get_enum_str(self):
1100 Return the string matching the current enumeration.
1101 Return None on error.
1103 return _bt_ctf_get_enum_str(self._d)
1105 def _get_array_element_at(self, index):
1107 Return the array's element at position index.
1108 Return None on error
1110 array_ptr = _bt_python_get_array_from_def(self._d)
1111 if array_ptr is None:
1114 definition_ptr = _bt_array_index(array_ptr, index)
1115 if definition_ptr is None:
1117 return _Definition(definition_ptr, self.scope)
1119 def _get_sequence_len(self):
1121 Return the len of a sequence or a negative
1124 seq = _bt_python_get_sequence_from_def(self._d)
1125 return _bt_sequence_len(seq)
1127 def _get_sequence_element_at(self, index):
1129 Return the sequence's element at position index,
1130 otherwise return None
1132 seq = _bt_python_get_sequence_from_def(self._d)
1134 definition_ptr = _bt_sequence_index(seq, index)
1135 if definition_ptr is not None:
1136 return _Definition(definition_ptr, self.scope)
1139 def _get_uint64(self):
1141 Return the value associated with the field.
1142 If the field does not exist or is not of the type requested,
1143 the value returned is undefined. To check if an error occured,
1144 use the field_error() function after accessing a field.
1146 return _bt_ctf_get_uint64(self._d)
1148 def _get_int64(self):
1150 Return the value associated with the field.
1151 If the field does not exist or is not of the type requested,
1152 the value returned is undefined. To check if an error occured,
1153 use the field_error() function after accessing a field.
1155 return _bt_ctf_get_int64(self._d)
1157 def _get_char_array(self):
1159 Return the value associated with the field.
1160 If the field does not exist or is not of the type requested,
1161 the value returned is undefined. To check if an error occurred,
1162 use the field_error() function after accessing a field.
1164 return _bt_ctf_get_char_array(self._d)
1168 Return the value associated with the field.
1169 If the field does not exist or is not of the type requested,
1170 the value returned is undefined. To check if an error occurred,
1171 use the field_error() function after accessing a field.
1173 return _bt_ctf_get_string(self._d)
1175 def _get_float(self):
1177 Return the value associated with the field.
1178 If the field does not exist or is not of the type requested,
1179 the value returned is undefined. To check if an error occurred,
1180 use the field_error() function after accessing a field.
1182 return _bt_ctf_get_float(self._d)
1184 def _get_variant(self):
1186 Return the variant's selected field.
1187 If the field does not exist or is not of the type requested,
1188 the value returned is undefined. To check if an error occurred,
1189 use the field_error() function after accessing a field.
1191 return _bt_ctf_get_variant(self._d)
1193 def _get_struct_field_count(self):
1195 Return the number of fields contained in the structure.
1196 If the field does not exist or is not of the type requested,
1197 the value returned is undefined.
1199 return _bt_ctf_get_struct_field_count(self._d)
1201 def _get_struct_field_at(self, i):
1203 Return the structure's field at position i.
1204 If the field does not exist or is not of the type requested,
1205 the value returned is undefined. To check if an error occurred,
1206 use the field_error() function after accessing a field.
1208 return _bt_ctf_get_struct_field_index(self._d, i)
1213 Return the value associated with the field according to its type.
1214 Return None on error.
1219 if id == CTFTypeId.STRING:
1220 value = self._get_str()
1221 elif id == CTFTypeId.ARRAY:
1222 element_decl = self.declaration.element_declaration
1223 if ((element_decl.type == CTFTypeId.INTEGER
1224 and element_decl.length == 8)
1225 and (element_decl.encoding == CTFStringEncoding.ASCII or element_decl.encoding == CTFStringEncoding.UTF8)):
1226 value = _bt_python_get_array_string(self._d)
1229 for i in range(self.declaration.length):
1230 element = self._get_array_element_at(i)
1231 value.append(element.value)
1232 elif id == CTFTypeId.INTEGER:
1233 if self.declaration.signedness == 0:
1234 value = self._get_uint64()
1236 value = self._get_int64()
1237 elif id == CTFTypeId.ENUM:
1238 value = self._get_enum_str()
1239 elif id == CTFTypeId.SEQUENCE:
1240 element_decl = self.declaration.element_declaration
1241 if ((element_decl.type == CTFTypeId.INTEGER
1242 and element_decl.length == 8)
1243 and (element_decl.encoding == CTFStringEncoding.ASCII or element_decl.encoding == CTFStringEncoding.UTF8)):
1244 value = _bt_python_get_sequence_string(self._d)
1246 seq_len = self._get_sequence_len()
1248 for i in range(seq_len):
1249 evDef = self._get_sequence_element_at(i)
1250 value.append(evDef.value)
1251 elif id == CTFTypeId.FLOAT:
1252 value = self._get_float()
1253 elif id == CTFTypeId.VARIANT:
1254 variant = _Definition.__new__(_Definition)
1255 variant._d = self._get_variant();
1256 value = variant.value
1257 elif id == CTFTypeId.STRUCT:
1259 for i in range(self._get_struct_field_count()):
1260 member = _Definition(self._get_struct_field_at(i), self.scope)
1261 value[member.name] = member.value
1264 raise FieldError("Error occurred while accessing field {} of type {}".format(self.name, CTFTypeId.type_name(id)))
1269 """Return the scope of a field or None on error."""
1275 // =================================================================
1277 // =================================================================
1279 /* =================================================================
1281 ¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯
1283 %rename("_bt_ctf_clock_create") bt_ctf_clock_create(const char *name);
1284 %rename("_bt_ctf_clock_get_name") bt_ctf_clock_get_name(struct bt_ctf_clock *clock);
1285 %rename("_bt_ctf_clock_get_description") bt_ctf_clock_get_description(struct bt_ctf_clock *clock);
1286 %rename("_bt_ctf_clock_set_description") bt_ctf_clock_set_description(struct bt_ctf_clock *clock, const char *desc);
1287 %rename("_bt_ctf_clock_get_frequency") bt_ctf_clock_get_frequency(struct bt_ctf_clock *clock);
1288 %rename("_bt_ctf_clock_set_frequency") bt_ctf_clock_set_frequency(struct bt_ctf_clock *clock, uint64_t freq);
1289 %rename("_bt_ctf_clock_get_precision") bt_ctf_clock_get_precision(struct bt_ctf_clock *clock);
1290 %rename("_bt_ctf_clock_set_precision") bt_ctf_clock_set_precision(struct bt_ctf_clock *clock, uint64_t precision);
1291 %rename("_bt_ctf_clock_get_offset_s") bt_ctf_clock_get_offset_s(struct bt_ctf_clock *clock);
1292 %rename("_bt_ctf_clock_set_offset_s") bt_ctf_clock_set_offset_s(struct bt_ctf_clock *clock, uint64_t offset_s);
1293 %rename("_bt_ctf_clock_get_offset") bt_ctf_clock_get_offset(struct bt_ctf_clock *clock);
1294 %rename("_bt_ctf_clock_set_offset") bt_ctf_clock_set_offset(struct bt_ctf_clock *clock, uint64_t offset);
1295 %rename("_bt_ctf_clock_get_is_absolute") bt_ctf_clock_get_is_absolute(struct bt_ctf_clock *clock);
1296 %rename("_bt_ctf_clock_set_is_absolute") bt_ctf_clock_set_is_absolute(struct bt_ctf_clock *clock, int is_absolute);
1297 %rename("_bt_ctf_clock_get_time") bt_ctf_clock_get_time(struct bt_ctf_clock *clock);
1298 %rename("_bt_ctf_clock_set_time") bt_ctf_clock_set_time(struct bt_ctf_clock *clock, uint64_t time);
1299 %rename("_bt_ctf_clock_get") bt_ctf_clock_get(struct bt_ctf_clock *clock);
1300 %rename("_bt_ctf_clock_put") bt_ctf_clock_put(struct bt_ctf_clock *clock);
1302 struct bt_ctf_clock *bt_ctf_clock_create(const char *name);
1303 const char *bt_ctf_clock_get_name(struct bt_ctf_clock *clock);
1304 const char *bt_ctf_clock_get_description(struct bt_ctf_clock *clock);
1305 int bt_ctf_clock_set_description(struct bt_ctf_clock *clock, const char *desc);
1306 uint64_t bt_ctf_clock_get_frequency(struct bt_ctf_clock *clock);
1307 int bt_ctf_clock_set_frequency(struct bt_ctf_clock *clock, uint64_t freq);
1308 uint64_t bt_ctf_clock_get_precision(struct bt_ctf_clock *clock);
1309 int bt_ctf_clock_set_precision(struct bt_ctf_clock *clock, uint64_t precision);
1310 uint64_t bt_ctf_clock_get_offset_s(struct bt_ctf_clock *clock);
1311 int bt_ctf_clock_set_offset_s(struct bt_ctf_clock *clock, uint64_t offset_s);
1312 uint64_t bt_ctf_clock_get_offset(struct bt_ctf_clock *clock);
1313 int bt_ctf_clock_set_offset(struct bt_ctf_clock *clock, uint64_t offset);
1314 int bt_ctf_clock_get_is_absolute(struct bt_ctf_clock *clock);
1315 int bt_ctf_clock_set_is_absolute(struct bt_ctf_clock *clock, int is_absolute);
1316 uint64_t bt_ctf_clock_get_time(struct bt_ctf_clock *clock);
1317 int bt_ctf_clock_set_time(struct bt_ctf_clock *clock, uint64_t time);
1318 void bt_ctf_clock_get(struct bt_ctf_clock *clock);
1319 void bt_ctf_clock_put(struct bt_ctf_clock *clock);
1321 /* =================================================================
1323 ¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯
1325 %rename("_bt_ctf_field_type_integer_create") bt_ctf_field_type_integer_create(unsigned int size);
1326 %rename("_bt_ctf_field_type_integer_get_size") bt_ctf_field_type_integer_get_size(struct bt_ctf_field_type *integer);
1327 %rename("_bt_ctf_field_type_integer_get_signed") bt_ctf_field_type_integer_get_signed(struct bt_ctf_field_type *integer);
1328 %rename("_bt_ctf_field_type_integer_set_signed") bt_ctf_field_type_integer_set_signed(struct bt_ctf_field_type *integer, int is_signed);
1329 %rename("_bt_ctf_field_type_integer_get_base") bt_ctf_field_type_integer_get_base(struct bt_ctf_field_type *integer);
1330 %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);
1331 %rename("_bt_ctf_field_type_integer_get_encoding") bt_ctf_field_type_integer_get_encoding(struct bt_ctf_field_type *integer);
1332 %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);
1333 %rename("_bt_ctf_field_type_enumeration_create") bt_ctf_field_type_enumeration_create(struct bt_ctf_field_type *integer_container_type);
1334 %rename("_bt_ctf_field_type_enumeration_get_container_type") bt_ctf_field_type_enumeration_get_container_type(struct bt_ctf_field_type *enumeration);
1335 %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);
1336 %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);
1337 %rename("_bt_ctf_field_type_enumeration_get_mapping_count") bt_ctf_field_type_enumeration_get_mapping_count(struct bt_ctf_field_type *enumeration);
1338 %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);
1339 %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);
1340 %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);
1341 %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);
1342 %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);
1343 %rename("_bt_ctf_field_type_floating_point_create") bt_ctf_field_type_floating_point_create(void);
1344 %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);
1345 %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);
1346 %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);
1347 %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);
1348 %rename("_bt_ctf_field_type_structure_create") bt_ctf_field_type_structure_create(void);
1349 %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);
1350 %rename("_bt_ctf_field_type_structure_get_field_count") bt_ctf_field_type_structure_get_field_count(struct bt_ctf_field_type *structure);
1351 %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);
1352 %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);
1353 %rename("_bt_ctf_field_type_variant_create") bt_ctf_field_type_variant_create(struct bt_ctf_field_type *enum_tag, const char *tag_name);
1354 %rename("_bt_ctf_field_type_variant_get_tag_type") bt_ctf_field_type_variant_get_tag_type(struct bt_ctf_field_type *variant);
1355 %rename("_bt_ctf_field_type_variant_get_tag_name") bt_ctf_field_type_variant_get_tag_name(struct bt_ctf_field_type *variant);
1356 %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);
1357 %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);
1358 %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);
1359 %rename("_bt_ctf_field_type_variant_get_field_count") bt_ctf_field_type_variant_get_field_count(struct bt_ctf_field_type *variant);
1360 %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);
1361 %rename("_bt_ctf_field_type_array_create") bt_ctf_field_type_array_create(struct bt_ctf_field_type *element_type, unsigned int length);
1362 %rename("_bt_ctf_field_type_array_get_element_type") bt_ctf_field_type_array_get_element_type(struct bt_ctf_field_type *array);
1363 %rename("_bt_ctf_field_type_array_get_length") bt_ctf_field_type_array_get_length(struct bt_ctf_field_type *array);
1364 %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);
1365 %rename("_bt_ctf_field_type_sequence_get_element_type") bt_ctf_field_type_sequence_get_element_type(struct bt_ctf_field_type *sequence);
1366 %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);
1367 %rename("_bt_ctf_field_type_string_create") bt_ctf_field_type_string_create(void);
1368 %rename("_bt_ctf_field_type_string_get_encoding") bt_ctf_field_type_string_get_encoding(struct bt_ctf_field_type *string_type);
1369 %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);
1370 %rename("_bt_ctf_field_type_get_alignment") bt_ctf_field_type_get_alignment(struct bt_ctf_field_type *type);
1371 %rename("_bt_ctf_field_type_set_alignment") bt_ctf_field_type_set_alignment(struct bt_ctf_field_type *type, unsigned int alignment);
1372 %rename("_bt_ctf_field_type_get_byte_order") bt_ctf_field_type_get_byte_order(struct bt_ctf_field_type *type);
1373 %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);
1374 %rename("_bt_ctf_field_type_get_type_id") bt_ctf_field_type_get_type_id(struct bt_ctf_field_type *type);
1375 %rename("_bt_ctf_field_type_get") bt_ctf_field_type_get(struct bt_ctf_field_type *type);
1376 %rename("_bt_ctf_field_type_put") bt_ctf_field_type_put(struct bt_ctf_field_type *type);
1378 struct bt_ctf_field_type *bt_ctf_field_type_integer_create(unsigned int size);
1379 int bt_ctf_field_type_integer_get_size(struct bt_ctf_field_type *integer);
1380 int bt_ctf_field_type_integer_get_signed(struct bt_ctf_field_type *integer);
1381 int bt_ctf_field_type_integer_set_signed(struct bt_ctf_field_type *integer, int is_signed);
1382 enum bt_ctf_integer_base bt_ctf_field_type_integer_get_base(struct bt_ctf_field_type *integer);
1383 int bt_ctf_field_type_integer_set_base(struct bt_ctf_field_type *integer, enum bt_ctf_integer_base base);
1384 enum ctf_string_encoding bt_ctf_field_type_integer_get_encoding(struct bt_ctf_field_type *integer);
1385 int bt_ctf_field_type_integer_set_encoding(struct bt_ctf_field_type *integer, enum ctf_string_encoding encoding);
1386 struct bt_ctf_field_type *bt_ctf_field_type_enumeration_create(struct bt_ctf_field_type *integer_container_type);
1387 struct bt_ctf_field_type *bt_ctf_field_type_enumeration_get_container_type(struct bt_ctf_field_type *enumeration);
1388 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);
1389 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);
1390 int64_t bt_ctf_field_type_enumeration_get_mapping_count(struct bt_ctf_field_type *enumeration);
1391 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);
1392 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);
1393 int bt_ctf_field_type_enumeration_get_mapping_index_by_name(struct bt_ctf_field_type *enumeration, const char *name, size_t *OUTPUT);
1394 int bt_ctf_field_type_enumeration_get_mapping_index_by_value(struct bt_ctf_field_type *enumeration, int64_t value, size_t *OUTPUT);
1395 int bt_ctf_field_type_enumeration_get_mapping_index_by_unsigned_value(struct bt_ctf_field_type *enumeration, uint64_t value, size_t *OUTPUT);
1396 struct bt_ctf_field_type *bt_ctf_field_type_floating_point_create(void);
1397 int bt_ctf_field_type_floating_point_get_exponent_digits(struct bt_ctf_field_type *floating_point);
1398 int bt_ctf_field_type_floating_point_set_exponent_digits(struct bt_ctf_field_type *floating_point, unsigned int exponent_digits);
1399 int bt_ctf_field_type_floating_point_get_mantissa_digits(struct bt_ctf_field_type *floating_point);
1400 int bt_ctf_field_type_floating_point_set_mantissa_digits(struct bt_ctf_field_type *floating_point, unsigned int mantissa_digits);
1401 struct bt_ctf_field_type *bt_ctf_field_type_structure_create(void);
1402 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);
1403 int64_t bt_ctf_field_type_structure_get_field_count(struct bt_ctf_field_type *structure);
1404 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);
1405 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);
1406 struct bt_ctf_field_type *bt_ctf_field_type_variant_create(struct bt_ctf_field_type *enum_tag, const char *tag_name);
1407 struct bt_ctf_field_type *bt_ctf_field_type_variant_get_tag_type(struct bt_ctf_field_type *variant);
1408 const char *bt_ctf_field_type_variant_get_tag_name(struct bt_ctf_field_type *variant);
1409 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);
1410 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);
1411 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);
1412 int64_t bt_ctf_field_type_variant_get_field_count(struct bt_ctf_field_type *variant);
1413 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);
1414 struct bt_ctf_field_type *bt_ctf_field_type_array_create(struct bt_ctf_field_type *element_type, unsigned int length);
1415 struct bt_ctf_field_type *bt_ctf_field_type_array_get_element_type(struct bt_ctf_field_type *array);
1416 int64_t bt_ctf_field_type_array_get_length(struct bt_ctf_field_type *array);
1417 struct bt_ctf_field_type *bt_ctf_field_type_sequence_create(struct bt_ctf_field_type *element_type, const char *length_field_name);
1418 struct bt_ctf_field_type *bt_ctf_field_type_sequence_get_element_type(struct bt_ctf_field_type *sequence);
1419 const char *bt_ctf_field_type_sequence_get_length_field_name(struct bt_ctf_field_type *sequence);
1420 struct bt_ctf_field_type *bt_ctf_field_type_string_create(void);
1421 enum ctf_string_encoding bt_ctf_field_type_string_get_encoding(struct bt_ctf_field_type *string_type);
1422 int bt_ctf_field_type_string_set_encoding(struct bt_ctf_field_type *string_type, enum ctf_string_encoding encoding);
1423 int bt_ctf_field_type_get_alignment(struct bt_ctf_field_type *type);
1424 int bt_ctf_field_type_set_alignment(struct bt_ctf_field_type *type, unsigned int alignment);
1425 enum bt_ctf_byte_order bt_ctf_field_type_get_byte_order(struct bt_ctf_field_type *type);
1426 int bt_ctf_field_type_set_byte_order(struct bt_ctf_field_type *type, enum bt_ctf_byte_order byte_order);
1427 enum ctf_type_id bt_ctf_field_type_get_type_id(struct bt_ctf_field_type *type);
1428 void bt_ctf_field_type_get(struct bt_ctf_field_type *type);
1429 void bt_ctf_field_type_put(struct bt_ctf_field_type *type);
1431 /* =================================================================
1433 ¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯
1435 %rename("_bt_ctf_field_create") bt_ctf_field_create(struct bt_ctf_field_type *type);
1436 %rename("_bt_ctf_field_structure_get_field") bt_ctf_field_structure_get_field(struct bt_ctf_field *structure, const char *name);
1437 %rename("_bt_ctf_field_array_get_field") bt_ctf_field_array_get_field(struct bt_ctf_field *array, uint64_t index);
1438 %rename("_bt_ctf_field_sequence_get_length") bt_ctf_field_sequence_get_length(struct bt_ctf_field *sequence);
1439 %rename("_bt_ctf_field_sequence_set_length") bt_ctf_field_sequence_set_length(struct bt_ctf_field *sequence, struct bt_ctf_field *length_field);
1440 %rename("_bt_ctf_field_sequence_get_field") bt_ctf_field_sequence_get_field(struct bt_ctf_field *sequence, uint64_t index);
1441 %rename("_bt_ctf_field_variant_get_field") bt_ctf_field_variant_get_field(struct bt_ctf_field *variant, struct bt_ctf_field *tag);
1442 %rename("_bt_ctf_field_enumeration_get_container") bt_ctf_field_enumeration_get_container(struct bt_ctf_field *enumeration);
1443 %rename("_bt_ctf_field_enumeration_get_mapping_name") bt_ctf_field_enumeration_get_mapping_name(struct bt_ctf_field *enumeration);
1444 %rename("_bt_ctf_field_signed_integer_get_value") bt_ctf_field_signed_integer_get_value(struct bt_ctf_field *integer, int64_t *value);
1445 %rename("_bt_ctf_field_signed_integer_set_value") bt_ctf_field_signed_integer_set_value(struct bt_ctf_field *integer, int64_t value);
1446 %rename("_bt_ctf_field_unsigned_integer_get_value") bt_ctf_field_unsigned_integer_get_value(struct bt_ctf_field *integer, uint64_t *value);
1447 %rename("_bt_ctf_field_unsigned_integer_set_value") bt_ctf_field_unsigned_integer_set_value(struct bt_ctf_field *integer, uint64_t value);
1448 %rename("_bt_ctf_field_floating_point_get_value") bt_ctf_field_floating_point_get_value(struct bt_ctf_field *floating_point, double *value);
1449 %rename("_bt_ctf_field_floating_point_set_value") bt_ctf_field_floating_point_set_value(struct bt_ctf_field *floating_point, double value);
1450 %rename("_bt_ctf_field_string_get_value") bt_ctf_field_string_get_value(struct bt_ctf_field *string_field);
1451 %rename("_bt_ctf_field_string_set_value") bt_ctf_field_string_set_value(struct bt_ctf_field *string_field, const char *value);
1452 %rename("_bt_ctf_field_get_type") bt_ctf_field_get_type(struct bt_ctf_field *field);
1453 %rename("_bt_ctf_field_get") bt_ctf_field_get(struct bt_ctf_field *field);
1454 %rename("_bt_ctf_field_put") bt_ctf_field_put(struct bt_ctf_field *field);
1456 struct bt_ctf_field *bt_ctf_field_create(struct bt_ctf_field_type *type);
1457 struct bt_ctf_field *bt_ctf_field_structure_get_field(struct bt_ctf_field *structure, const char *name);
1458 struct bt_ctf_field *bt_ctf_field_array_get_field(struct bt_ctf_field *array, uint64_t index);
1459 struct bt_ctf_field * bt_ctf_field_sequence_get_length(struct bt_ctf_field *sequence);
1460 int bt_ctf_field_sequence_set_length(struct bt_ctf_field *sequence, struct bt_ctf_field *length_field);
1461 struct bt_ctf_field *bt_ctf_field_sequence_get_field(struct bt_ctf_field *sequence, uint64_t index);
1462 struct bt_ctf_field *bt_ctf_field_variant_get_field(struct bt_ctf_field *variant, struct bt_ctf_field *tag);
1463 struct bt_ctf_field *bt_ctf_field_enumeration_get_container(struct bt_ctf_field *enumeration);
1464 const char *bt_ctf_field_enumeration_get_mapping_name(struct bt_ctf_field *enumeration);
1465 int bt_ctf_field_signed_integer_get_value(struct bt_ctf_field *integer, int64_t *OUTPUT);
1466 int bt_ctf_field_signed_integer_set_value(struct bt_ctf_field *integer, int64_t value);
1467 int bt_ctf_field_unsigned_integer_get_value(struct bt_ctf_field *integer, uint64_t *OUTPUT);
1468 int bt_ctf_field_unsigned_integer_set_value(struct bt_ctf_field *integer, uint64_t value);
1469 int bt_ctf_field_floating_point_get_value(struct bt_ctf_field *floating_point, double *OUTPUT);
1470 int bt_ctf_field_floating_point_set_value(struct bt_ctf_field *floating_point, double value);
1471 const char *bt_ctf_field_string_get_value(struct bt_ctf_field *string_field);
1472 int bt_ctf_field_string_set_value(struct bt_ctf_field *string_field, const char *value);
1473 struct bt_ctf_field_type *bt_ctf_field_get_type(struct bt_ctf_field *field);
1474 void bt_ctf_field_get(struct bt_ctf_field *field);
1475 void bt_ctf_field_put(struct bt_ctf_field *field);
1477 /* =================================================================
1479 ¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯
1481 %rename("_bt_ctf_event_class_create") bt_ctf_event_class_create(const char *name);
1482 %rename("_bt_ctf_event_class_get_name") bt_ctf_event_class_get_name(struct bt_ctf_event_class *event_class);
1483 %rename("_bt_ctf_event_class_get_id") bt_ctf_event_class_get_id(struct bt_ctf_event_class *event_class);
1484 %rename("_bt_ctf_event_class_set_id") bt_ctf_event_class_set_id(struct bt_ctf_event_class *event_class, uint32_t id);
1485 %rename("_bt_ctf_event_class_get_stream_class") bt_ctf_event_class_get_stream_class(struct bt_ctf_event_class *event_class);
1486 %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);
1487 %rename("_bt_ctf_event_class_get_field_count") bt_ctf_event_class_get_field_count(struct bt_ctf_event_class *event_class);
1488 %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);
1489 %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);
1490 %rename("_bt_ctf_event_class_get") bt_ctf_event_class_get(struct bt_ctf_event_class *event_class);
1491 %rename("_bt_ctf_event_class_put") bt_ctf_event_class_put(struct bt_ctf_event_class *event_class);
1492 %rename("_bt_ctf_event_create") bt_ctf_event_create(struct bt_ctf_event_class *event_class);
1493 %rename("_bt_ctf_event_get_class") bt_ctf_event_get_class(struct bt_ctf_event *event);
1494 %rename("_bt_ctf_event_get_clock") bt_ctf_event_get_clock(struct bt_ctf_event *event);
1495 %rename("_bt_ctf_event_get_payload") bt_ctf_event_get_payload(struct bt_ctf_event *event, const char *name);
1496 %rename("_bt_ctf_event_set_payload") bt_ctf_event_set_payload(struct bt_ctf_event *event, const char *name, struct bt_ctf_field *value);
1497 %rename("_bt_ctf_event_get_payload_by_index") bt_ctf_event_get_payload_by_index(struct bt_ctf_event *event, size_t index);
1498 %rename("_bt_ctf_event_get") bt_ctf_event_get(struct bt_ctf_event *event);
1499 %rename("_bt_ctf_event_put") bt_ctf_event_put(struct bt_ctf_event *event);
1501 struct bt_ctf_event_class *bt_ctf_event_class_create(const char *name);
1502 const char *bt_ctf_event_class_get_name(struct bt_ctf_event_class *event_class);
1503 int64_t bt_ctf_event_class_get_id(struct bt_ctf_event_class *event_class);
1504 int bt_ctf_event_class_set_id(struct bt_ctf_event_class *event_class, uint32_t id);
1505 struct bt_ctf_stream_class *bt_ctf_event_class_get_stream_class(struct bt_ctf_event_class *event_class);
1506 int bt_ctf_event_class_add_field(struct bt_ctf_event_class *event_class, struct bt_ctf_field_type *type, const char *name);
1507 int64_t bt_ctf_event_class_get_field_count(struct bt_ctf_event_class *event_class);
1508 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);
1509 struct bt_ctf_field_type *bt_ctf_event_class_get_field_by_name(struct bt_ctf_event_class *event_class, const char *name);
1510 void bt_ctf_event_class_get(struct bt_ctf_event_class *event_class);
1511 void bt_ctf_event_class_put(struct bt_ctf_event_class *event_class);
1512 struct bt_ctf_event *bt_ctf_event_create(struct bt_ctf_event_class *event_class);
1513 struct bt_ctf_event_class *bt_ctf_event_get_class(struct bt_ctf_event *event);
1514 struct bt_ctf_clock *bt_ctf_event_get_clock(struct bt_ctf_event *event);
1515 struct bt_ctf_field *bt_ctf_event_get_payload(struct bt_ctf_event *event, const char *name);
1516 int bt_ctf_event_set_payload(struct bt_ctf_event *event, const char *name, struct bt_ctf_field *value);
1517 struct bt_ctf_field *bt_ctf_event_get_payload_by_index(struct bt_ctf_event *event, size_t index);
1518 void bt_ctf_event_get(struct bt_ctf_event *event);
1519 void bt_ctf_event_put(struct bt_ctf_event *event);
1521 /* =================================================================
1523 ¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯
1525 %rename("_bt_ctf_stream_class_create") bt_ctf_stream_class_create(const char *name);
1526 %rename("_bt_ctf_stream_class_get_name") bt_ctf_stream_class_get_name(struct bt_ctf_stream_class *stream_class);
1527 %rename("_bt_ctf_stream_class_get_clock") bt_ctf_stream_class_get_clock(struct bt_ctf_stream_class *stream_class);
1528 %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);
1529 %rename("_bt_ctf_stream_class_get_id") bt_ctf_stream_class_get_id(struct bt_ctf_stream_class *stream_class);
1530 %rename("_bt_ctf_stream_class_set_id") bt_ctf_stream_class_set_id(struct bt_ctf_stream_class *stream_class, uint32_t id);
1531 %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);
1532 %rename("_bt_ctf_stream_class_get_event_class_count") bt_ctf_stream_class_get_event_class_count(struct bt_ctf_stream_class *stream_class);
1533 %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);
1534 %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);
1535 %rename("_bt_ctf_stream_class_get") bt_ctf_stream_class_get(struct bt_ctf_stream_class *stream_class);
1536 %rename("_bt_ctf_stream_class_put") bt_ctf_stream_class_put(struct bt_ctf_stream_class *stream_class);
1537 %rename("_bt_ctf_stream_get_discarded_events_count") bt_ctf_stream_get_discarded_events_count(struct bt_ctf_stream *stream, uint64_t *count);
1538 %rename("_bt_ctf_stream_append_discarded_events") bt_ctf_stream_append_discarded_events(struct bt_ctf_stream *stream, uint64_t event_count);
1539 %rename("_bt_ctf_stream_append_event") bt_ctf_stream_append_event(struct bt_ctf_stream *stream, struct bt_ctf_event *event);
1540 %rename("_bt_ctf_stream_flush") bt_ctf_stream_flush(struct bt_ctf_stream *stream);
1541 %rename("_bt_ctf_stream_get") bt_ctf_stream_get(struct bt_ctf_stream *stream);
1542 %rename("_bt_ctf_stream_put") bt_ctf_stream_put(struct bt_ctf_stream *stream);
1544 struct bt_ctf_stream_class *bt_ctf_stream_class_create(const char *name);
1545 const char *bt_ctf_stream_class_get_name(struct bt_ctf_stream_class *stream_class);
1546 struct bt_ctf_clock *bt_ctf_stream_class_get_clock(struct bt_ctf_stream_class *stream_class);
1547 int bt_ctf_stream_class_set_clock(struct bt_ctf_stream_class *stream_class, struct bt_ctf_clock *clock);
1548 int64_t bt_ctf_stream_class_get_id(struct bt_ctf_stream_class *stream_class);
1549 int bt_ctf_stream_class_set_id(struct bt_ctf_stream_class *stream_class, uint32_t id);
1550 int bt_ctf_stream_class_add_event_class(struct bt_ctf_stream_class *stream_class, struct bt_ctf_event_class *event_class);
1551 int64_t bt_ctf_stream_class_get_event_class_count(struct bt_ctf_stream_class *stream_class);
1552 struct bt_ctf_event_class *bt_ctf_stream_class_get_event_class(struct bt_ctf_stream_class *stream_class, size_t index);
1553 struct bt_ctf_event_class *bt_ctf_stream_class_get_event_class_by_name(struct bt_ctf_stream_class *stream_class, const char *name);
1554 void bt_ctf_stream_class_get(struct bt_ctf_stream_class *stream_class);
1555 void bt_ctf_stream_class_put(struct bt_ctf_stream_class *stream_class);
1556 int bt_ctf_stream_get_discarded_events_count(struct bt_ctf_stream *stream, uint64_t *OUTPUT);
1557 void bt_ctf_stream_append_discarded_events(struct bt_ctf_stream *stream, uint64_t event_count);
1558 int bt_ctf_stream_append_event(struct bt_ctf_stream *stream, struct bt_ctf_event *event);
1559 int bt_ctf_stream_flush(struct bt_ctf_stream *stream);
1560 void bt_ctf_stream_get(struct bt_ctf_stream *stream);
1561 void bt_ctf_stream_put(struct bt_ctf_stream *stream);
1563 /* =================================================================
1565 ¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯
1567 %rename("_bt_ctf_writer_create") bt_ctf_writer_create(const char *path);
1568 %rename("_bt_ctf_writer_create_stream") bt_ctf_writer_create_stream(struct bt_ctf_writer *writer, struct bt_ctf_stream_class *stream_class);
1569 %rename("_bt_ctf_writer_add_environment_field") bt_ctf_writer_add_environment_field(struct bt_ctf_writer *writer, const char *name, const char *value);
1570 %rename("_bt_ctf_writer_add_clock") bt_ctf_writer_add_clock(struct bt_ctf_writer *writer, struct bt_ctf_clock *clock);
1571 %newobject bt_ctf_writer_get_metadata_string;
1572 %rename("_bt_ctf_writer_get_metadata_string") bt_ctf_writer_get_metadata_string(struct bt_ctf_writer *writer);
1573 %rename("_bt_ctf_writer_flush_metadata") bt_ctf_writer_flush_metadata(struct bt_ctf_writer *writer);
1574 %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);
1575 %rename("_bt_ctf_writer_get") bt_ctf_writer_get(struct bt_ctf_writer *writer);
1576 %rename("_bt_ctf_writer_put") bt_ctf_writer_put(struct bt_ctf_writer *writer);
1578 struct bt_ctf_writer *bt_ctf_writer_create(const char *path);
1579 struct bt_ctf_stream *bt_ctf_writer_create_stream(struct bt_ctf_writer *writer, struct bt_ctf_stream_class *stream_class);
1580 int bt_ctf_writer_add_environment_field(struct bt_ctf_writer *writer, const char *name, const char *value);
1581 int bt_ctf_writer_add_clock(struct bt_ctf_writer *writer, struct bt_ctf_clock *clock);
1582 char *bt_ctf_writer_get_metadata_string(struct bt_ctf_writer *writer);
1583 void bt_ctf_writer_flush_metadata(struct bt_ctf_writer *writer);
1584 int bt_ctf_writer_set_byte_order(struct bt_ctf_writer *writer, enum bt_ctf_byte_order byte_order);
1585 void bt_ctf_writer_get(struct bt_ctf_writer *writer);
1586 void bt_ctf_writer_put(struct bt_ctf_writer *writer);
1591 # Used to compare to -1ULL in error checks
1592 _MAX_UINT64 = 0xFFFFFFFFFFFFFFFF
1595 Enumeration mapping class. start and end values are inclusive.
1597 class EnumerationMapping:
1598 def __init__(self, name, start, end):
1604 def __init__(self, name):
1605 self._c = _bt_ctf_clock_create(name)
1607 raise ValueError("Invalid clock name.")
1610 _bt_ctf_clock_put(self._c)
1613 Get the clock's name.
1617 name = _bt_ctf_clock_get_name(self._c)
1619 raise ValueError("Invalid clock instance.")
1623 Get the clock's description. None if unset.
1626 def description(self):
1627 return _bt_ctf_clock_get_description(self._c)
1630 Set the clock's description. The description appears in the clock's TSDL
1634 def description(self, desc):
1635 ret = _bt_ctf_clock_set_description(self._c, str(desc))
1637 raise ValueError("Invalid clock description.")
1640 Get the clock's frequency (Hz).
1643 def frequency(self):
1644 freq = _bt_ctf_clock_get_frequency(self._c)
1645 if freq == CTFWriter._MAX_UINT64:
1646 raise ValueError("Invalid clock instance")
1650 Set the clock's frequency (Hz).
1653 def frequency(self, freq):
1654 ret = _bt_ctf_clock_set_frequency(self._c, freq)
1656 raise ValueError("Invalid frequency value.")
1659 Get the clock's precision (in clock ticks).
1662 def precision(self):
1663 precision = _bt_ctf_clock_get_precision(self._c)
1664 if precision == CTFWriter._MAX_UINT64:
1665 raise ValueError("Invalid clock instance")
1669 Set the clock's precision (in clock ticks).
1672 def precision(self, precision):
1673 ret = _bt_ctf_clock_set_precision(self._c, precision)
1676 Get the clock's offset in seconds from POSIX.1 Epoch.
1679 def offset_seconds(self):
1680 offset_s = _bt_ctf_clock_get_offset_s(self._c)
1681 if offset_s == CTFWriter._MAX_UINT64:
1682 raise ValueError("Invalid clock instance")
1686 Set the clock's offset in seconds from POSIX.1 Epoch.
1688 @offset_seconds.setter
1689 def offset_seconds(self, offset_s):
1690 ret = _bt_ctf_clock_set_offset_s(self._c, offset_s)
1692 raise ValueError("Invalid offset value.")
1695 Get the clock's offset in ticks from POSIX.1 Epoch + offset in seconds.
1699 offset = _bt_ctf_clock_get_offset(self._c)
1700 if offset == CTFWriter._MAX_UINT64:
1701 raise ValueError("Invalid clock instance")
1705 Set the clock's offset in ticks from POSIX.1 Epoch + offset in seconds.
1708 def offset(self, offset):
1709 ret = _bt_ctf_clock_set_offset(self._c, offset)
1711 raise ValueError("Invalid offset value.")
1714 Get a clock's absolute attribute. A clock is absolute if the clock
1715 is a global reference across the trace's other clocks.
1719 is_absolute = _bt_ctf_clock_get_is_absolute(self._c)
1720 if is_absolute == -1:
1721 raise ValueError("Invalid clock instance")
1722 return False if is_absolute == 0 else True
1725 Set a clock's absolute attribute. A clock is absolute if the clock
1726 is a global reference across the trace's other clocks.
1729 def absolute(self, is_absolute):
1730 ret = _bt_ctf_clock_set_is_absolute(self._c, int(is_absolute))
1732 raise ValueError("Could not set the clock's absolute attribute.")
1735 Get the current time in nanoseconds since the clock's origin (offset and
1736 offset_s attributes).
1740 time = _bt_ctf_clock_get_time(self._c)
1741 if time == CTFWriter._MAX_UINT64:
1742 raise ValueError("Invalid clock instance")
1746 Set the current time in nanoseconds since the clock's origin (offset and
1747 offset_s attributes). The clock's value will be sampled as events are
1748 appended to a stream.
1751 def time(self, time):
1752 ret = _bt_ctf_clock_set_time(self._c, time)
1754 raise ValueError("Invalid time value.")
1756 class FieldDeclaration:
1758 FieldDeclaration should not be instantiated directly. Instantiate
1759 one of the concrete FieldDeclaration classes.
1762 # These values are based on the bt_ctf_integer_base enum
1763 # declared in event-types.h.
1764 INTEGER_BASE_UNKNOWN = -1
1765 INTEGER_BASE_BINARY = 2
1766 INTEGER_BASE_OCTAL = 8
1767 INTEGER_BASE_DECIMAL = 10
1768 INTEGER_BASE_HEXADECIMAL = 16
1771 if self._ft is None:
1772 raise ValueError("FieldDeclaration creation failed.")
1775 _bt_ctf_field_type_put(self._ft)
1778 def _create_field_declaration_from_native_instance(native_field_declaration):
1780 CTFTypeId.INTEGER : CTFWriter.IntegerFieldDeclaration,
1781 CTFTypeId.FLOAT : CTFWriter.FloatFieldDeclaration,
1782 CTFTypeId.ENUM : CTFWriter.EnumerationFieldDeclaration,
1783 CTFTypeId.STRING : CTFWriter.StringFieldDeclaration,
1784 CTFTypeId.STRUCT : CTFWriter.StructureFieldDeclaration,
1785 CTFTypeId.VARIANT : CTFWriter.VariantFieldDeclaration,
1786 CTFTypeId.ARRAY : CTFWriter.ArrayFieldDeclaration,
1787 CTFTypeId.SEQUENCE : CTFWriter.SequenceFieldDeclaration
1790 field_type_id = _bt_ctf_field_type_get_type_id(native_field_declaration)
1791 if field_type_id == CTFTypeId.UNKNOWN:
1792 raise TypeError("Invalid field instance")
1794 declaration = CTFWriter.Field.__new__(CTFWriter.Field)
1795 declaration._ft = native_field_declaration
1796 declaration.__class__ = type_dict[field_type_id]
1800 Get the field declaration's alignment. Returns -1 on error.
1803 def alignment(self):
1804 return _bt_ctf_field_type_get_alignment(self._ft)
1807 Set the field declaration's alignment. Defaults to 1 (bit-aligned). However,
1808 some types, such as structures and string, may impose other alignment
1812 def alignment(self, alignment):
1813 ret = _bt_ctf_field_type_set_alignment(self._ft, alignment)
1815 raise ValueError("Invalid alignment value.")
1818 Get the field declaration's byte order. One of the ByteOrder's constant.
1821 def byte_order(self):
1822 return _bt_ctf_field_type_get_byte_order(self._ft)
1825 Set the field declaration's byte order. Use constants defined in the ByteOrder
1829 def byte_order(self, byte_order):
1830 ret = _bt_ctf_field_type_set_byte_order(self._ft, byte_order)
1832 raise ValueError("Could not set byte order value.")
1834 class IntegerFieldDeclaration(FieldDeclaration):
1836 Create a new integer field declaration of the given size.
1838 def __init__(self, size):
1839 self._ft = _bt_ctf_field_type_integer_create(size)
1843 Get an integer's size.
1847 ret = _bt_ctf_field_type_integer_get_size(self._ft)
1849 raise ValueError("Could not get Integer's size attribute.")
1854 Get an integer's signedness attribute.
1858 ret = _bt_ctf_field_type_integer_get_signed(self._ft)
1860 raise ValueError("Could not get Integer's signed attribute.")
1867 Set an integer's signedness attribute.
1870 def signed(self, signed):
1871 ret = _bt_ctf_field_type_integer_set_signed(self._ft, signed)
1873 raise ValueError("Could not set Integer's signed attribute.")
1876 Get the integer's base used to pretty-print the resulting trace.
1877 Returns a constant from the FieldDeclaration.IntegerBase class.
1881 return _bt_ctf_field_type_integer_get_base(self._ft)
1884 Set the integer's base used to pretty-print the resulting trace.
1885 The base must be a constant of the FieldDeclarationIntegerBase class.
1888 def base(self, base):
1889 ret = _bt_ctf_field_type_integer_set_base(self._ft, base)
1891 raise ValueError("Could not set Integer's base.")
1894 Get the integer's encoding (one of the constants of the
1895 CTFStringEncoding class).
1896 Returns a constant from the CTFStringEncoding class.
1900 return _bt_ctf_field_type_integer_get_encoding(self._ft)
1903 An integer encoding may be set to signal that the integer must be printed
1904 as a text character. Must be a constant from the CTFStringEncoding class.
1907 def encoding(self, encoding):
1908 ret = _bt_ctf_field_type_integer_set_encoding(self._ft, encoding)
1910 raise ValueError("Could not set Integer's encoding.")
1912 class EnumerationFieldDeclaration(FieldDeclaration):
1914 Create a new enumeration field declaration with the given underlying container type.
1916 def __init__(self, integer_type):
1917 if integer_type is None or not isinstance(integer_type, CTFWriter.IntegerFieldDeclaration):
1918 raise TypeError("Invalid integer container.")
1920 self._ft = _bt_ctf_field_type_enumeration_create(integer_type._ft)
1924 Get the enumeration's underlying container type.
1927 def container(self):
1928 ret = _bt_ctf_field_type_enumeration_get_container_type(self._ft)
1930 raise TypeError("Invalid enumeration declaration")
1931 return CTFWriter.FieldDeclaration._create_field_declaration_from_native_instance(ret)
1934 Add a mapping to the enumeration. The range's values are inclusive.
1936 def add_mapping(self, name, range_start, range_end):
1937 if range_start < 0 or range_end < 0:
1938 ret = _bt_ctf_field_type_enumeration_add_mapping(self._ft, str(name), range_start, range_end)
1940 ret = _bt_ctf_field_type_enumeration_add_mapping_unsigned(self._ft, str(name), range_start, range_end)
1943 raise ValueError("Could not add mapping to enumeration declaration.")
1946 Generator returning instances of EnumerationMapping.
1950 signed = self.container.signed
1952 count = _bt_ctf_field_type_enumeration_get_mapping_count(self._ft)
1953 for i in range(count):
1955 ret = _bt_python_ctf_field_type_enumeration_get_mapping(self._ft, i)
1957 ret = _bt_python_ctf_field_type_enumeration_get_mapping_unsigned(self._ft, i)
1960 raise TypeError("Could not get Enumeration mapping at index {}".format(i))
1961 name, range_start, range_end = ret
1962 yield CTFWriter.EnumerationMapping(name, range_start, range_end)
1965 Get a mapping by name (EnumerationMapping).
1967 def get_mapping_by_name(self, name):
1968 ret, index = _bt_ctf_field_type_enumeration_get_mapping_index_by_name(self._ft, name);
1972 if self.container.signed:
1973 ret = _bt_python_ctf_field_type_enumeration_get_mapping(self._ft, index)
1975 ret = _bt_python_ctf_field_type_enumeration_get_mapping_unsigned(self._ft, index)
1978 raise TypeError("Could not get Enumeration mapping at index {}".format(i))
1979 name, range_start, range_end = ret
1980 return CTFWriter.EnumerationMapping(name, range_start, range_end)
1983 Get a mapping by value (EnumerationMapping).
1985 def get_mapping_by_value(self, value):
1987 ret, index = _bt_ctf_field_type_enumeration_get_mapping_index_by_value(self._ft, value);
1989 ret, index = _bt_ctf_field_type_enumeration_get_mapping_index_by_unsigned_value(self._ft, value);
1994 if self.container.signed:
1995 ret = _bt_python_ctf_field_type_enumeration_get_mapping(self._ft, index)
1997 ret = _bt_python_ctf_field_type_enumeration_get_mapping_unsigned(self._ft, index)
2000 raise TypeError("Could not get Enumeration mapping at index {}".format(i))
2001 name, range_start, range_end = ret
2002 return CTFWriter.EnumerationMapping(name, range_start, range_end)
2004 class FloatFieldDeclaration(FieldDeclaration):
2011 Create a new floating point field declaration.
2014 self._ft = _bt_ctf_field_type_floating_point_create()
2018 Get the number of exponent digits used to store the floating point field.
2021 def exponent_digits(self):
2022 ret = _bt_ctf_field_type_floating_point_get_exponent_digits(self._ft)
2024 raise TypeError("Could not get Floating point exponent digit count")
2028 Set the number of exponent digits to use to store the floating point field.
2029 The only values currently supported are FLT_EXP_DIG and DBL_EXP_DIG which
2030 are defined as constants of this class.
2032 @exponent_digits.setter
2033 def exponent_digits(self, exponent_digits):
2034 ret = _bt_ctf_field_type_floating_point_set_exponent_digits(self._ft, exponent_digits)
2036 raise ValueError("Could not set exponent digit count.")
2039 Get the number of mantissa digits used to store the floating point field.
2042 def mantissa_digits(self):
2043 ret = _bt_ctf_field_type_floating_point_get_mantissa_digits(self._ft)
2045 raise TypeError("Could not get Floating point mantissa digit count")
2049 Set the number of mantissa digits to use to store the floating point field.
2050 The only values currently supported are FLT_MANT_DIG and DBL_MANT_DIG which
2051 are defined as constants of this class.
2053 @mantissa_digits.setter
2054 def mantissa_digits(self, mantissa_digits):
2055 ret = _bt_ctf_field_type_floating_point_set_mantissa_digits(self._ft, mantissa_digits)
2057 raise ValueError("Could not set mantissa digit count.")
2059 class StructureFieldDeclaration(FieldDeclaration):
2061 Create a new structure field declaration.
2064 self._ft = _bt_ctf_field_type_structure_create()
2068 Add a field of type "field_type" to the structure.
2070 def add_field(self, field_type, field_name):
2071 ret = _bt_ctf_field_type_structure_add_field(self._ft, field_type._ft, str(field_name))
2073 raise ValueError("Could not add field to structure.")
2076 Generator returning the structure's field as tuples of (field name, field declaration).
2080 count = _bt_ctf_field_type_structure_get_field_count(self._ft)
2082 raise TypeError("Could not get Structure field count")
2084 for i in range(count):
2085 field_name = _bt_python_ctf_field_type_structure_get_field_name(self._ft, i)
2086 if field_name is None:
2087 raise TypeError("Could not get Structure field name at index {}".format(i))
2089 field_type_native = _bt_python_ctf_field_type_structure_get_field_type(self._ft, i)
2090 if field_type_native is None:
2091 raise TypeError("Could not get Structure field type at index {}".format(i))
2093 field_type = CTFWriter.FieldDeclaration._create_field_declaration_from_native_instance(field_type_native)
2094 yield (field_name, field_type)
2097 Get a field declaration by name (FieldDeclaration).
2099 def get_field_by_name(self, name):
2100 field_type_native = _bt_ctf_field_type_structure_get_field_type_by_name(self._ft, name)
2101 if field_type_native is None:
2102 raise TypeError("Could not find Structure field with name {}".format(name))
2104 return CTFWriter.FieldDeclaration._create_field_declaration_from_native_instance(field_type_native)
2106 class VariantFieldDeclaration(FieldDeclaration):
2108 Create a new variant field declaration.
2110 def __init__(self, enum_tag, tag_name):
2111 if enum_tag is None or not isinstance(enum_tag, CTFWriter.EnumerationFieldDeclaration):
2112 raise TypeError("Invalid tag type; must be of type EnumerationFieldDeclaration.")
2114 self._ft = _bt_ctf_field_type_variant_create(enum_tag._ft, str(tag_name))
2118 Get the variant's tag name.
2122 ret = _bt_ctf_field_type_variant_get_tag_name(self._ft)
2124 raise TypeError("Could not get Variant tag name")
2128 Get the variant's tag type.
2132 ret = _bt_ctf_field_type_variant_get_tag_type(self._ft)
2134 raise TypeError("Could not get Variant tag type")
2135 return CTFWriter.FieldDeclaration._create_field_declaration_from_native_instance(ret)
2138 Add a field of type "field_type" to the variant.
2140 def add_field(self, field_type, field_name):
2141 ret = _bt_ctf_field_type_variant_add_field(self._ft, field_type._ft, str(field_name))
2143 raise ValueError("Could not add field to variant.")
2146 Generator returning the variant's field as tuples of (field name, field declaration).
2150 count = _bt_ctf_field_type_variant_get_field_count(self._ft)
2152 raise TypeError("Could not get Variant field count")
2154 for i in range(count):
2155 field_name = _bt_python_ctf_field_type_variant_get_field_name(self._ft, i)
2156 if field_name is None:
2157 raise TypeError("Could not get Variant field name at index {}".format(i))
2159 field_type_native = _bt_python_ctf_field_type_variant_get_field_type(self._ft, i)
2160 if field_type_native is None:
2161 raise TypeError("Could not get Variant field type at index {}".format(i))
2163 field_type = CTFWriter.FieldDeclaration._create_field_declaration_from_native_instance(field_type_native)
2164 yield (field_name, field_type)
2167 Get a field declaration by name (FieldDeclaration).
2169 def get_field_by_name(self, name):
2170 field_type_native = _bt_ctf_field_type_variant_get_field_type_by_name(self._ft, name)
2171 if field_type_native is None:
2172 raise TypeError("Could not find Variant field with name {}".format(name))
2174 return CTFWriter.FieldDeclaration._create_field_declaration_from_native_instance(field_type_native)
2177 Get a field declaration from tag (EnumerationField).
2179 def get_field_from_tag(self, tag):
2180 field_type_native = _bt_ctf_field_type_variant_get_field_type_from_tag(self._ft, tag._f)
2181 if field_type_native is None:
2182 raise TypeError("Could not find Variant field with tag value {}".format(tag.value))
2184 return CTFWriter.FieldDeclaration._create_field_declaration_from_native_instance(field_type_native)
2186 class ArrayFieldDeclaration(FieldDeclaration):
2188 Create a new array field declaration.
2190 def __init__(self, element_type, length):
2191 self._ft = _bt_ctf_field_type_array_create(element_type._ft, length)
2195 Get the array's element type.
2198 def element_type(self):
2199 ret = _bt_ctf_field_type_array_get_element_type(self._ft)
2201 raise TypeError("Could not get Array element type")
2202 return CTFWriter.FieldDeclaration._create_field_declaration_from_native_instance(ret)
2205 Get the array's length.
2209 ret = _bt_ctf_field_type_array_get_length(self._ft)
2211 raise TypeError("Could not get Array length")
2214 class SequenceFieldDeclaration(FieldDeclaration):
2216 Create a new sequence field declaration.
2218 def __init__(self, element_type, length_field_name):
2219 self._ft = _bt_ctf_field_type_sequence_create(element_type._ft, str(length_field_name))
2223 Get the sequence's element type.
2226 def element_type(self):
2227 ret = _bt_ctf_field_type_sequence_get_element_type(self._ft)
2229 raise TypeError("Could not get Sequence element type")
2230 return CTFWriter.FieldDeclaration._create_field_declaration_from_native_instance(ret)
2233 Get the sequence's length field name.
2236 def length_field_name(self):
2237 ret = _bt_ctf_field_type_sequence_get_length_field_name(self._ft)
2239 raise TypeError("Could not get Sequence length field name")
2242 class StringFieldDeclaration(FieldDeclaration):
2244 Create a new string field declaration.
2247 self._ft = _bt_ctf_field_type_string_create()
2251 Get a string declaration's encoding (a constant from the CTFStringEncoding class).
2255 return _bt_ctf_field_type_string_get_encoding(self._ft)
2258 Set a string declaration's encoding. Must be a constant from the CTFStringEncoding class.
2261 def encoding(self, encoding):
2262 ret = _bt_ctf_field_type_string_set_encoding(self._ft, encoding)
2264 raise ValueError("Could not set string encoding.")
2267 Create an instance of a field.
2270 def create_field(field_type):
2271 if field_type is None or not isinstance(field_type, CTFWriter.FieldDeclaration):
2272 raise TypeError("Invalid field_type. Type must be a FieldDeclaration-derived class.")
2274 if isinstance(field_type, CTFWriter.IntegerFieldDeclaration):
2275 return CTFWriter.IntegerField(field_type)
2276 elif isinstance(field_type, CTFWriter.EnumerationFieldDeclaration):
2277 return CTFWriter.EnumerationField(field_type)
2278 elif isinstance(field_type, CTFWriter.FloatFieldDeclaration):
2279 return CTFWriter.FloatFieldingPoint(field_type)
2280 elif isinstance(field_type, CTFWriter.StructureFieldDeclaration):
2281 return CTFWriter.StructureField(field_type)
2282 elif isinstance(field_type, CTFWriter.VariantFieldDeclaration):
2283 return CTFWriter.VariantField(field_type)
2284 elif isinstance(field_type, CTFWriter.ArrayFieldDeclaration):
2285 return CTFWriter.ArrayField(field_type)
2286 elif isinstance(field_type, CTFWriter.SequenceFieldDeclaration):
2287 return CTFWriter.SequenceField(field_type)
2288 elif isinstance(field_type, CTFWriter.StringFieldDeclaration):
2289 return CTFWriter.StringField(field_type)
2293 Base class, do not instantiate.
2295 def __init__(self, field_type):
2296 if not isinstance(field_type, CTFWriter.FieldDeclaration):
2297 raise TypeError("Invalid field_type argument.")
2299 self._f = _bt_ctf_field_create(field_type._ft)
2301 raise ValueError("Field creation failed.")
2304 _bt_ctf_field_put(self._f)
2307 def _create_field_from_native_instance(native_field_instance):
2309 CTFTypeId.INTEGER : CTFWriter.IntegerField,
2310 CTFTypeId.FLOAT : CTFWriter.FloatFieldingPoint,
2311 CTFTypeId.ENUM : CTFWriter.EnumerationField,
2312 CTFTypeId.STRING : CTFWriter.StringField,
2313 CTFTypeId.STRUCT : CTFWriter.StructureField,
2314 CTFTypeId.VARIANT : CTFWriter.VariantField,
2315 CTFTypeId.ARRAY : CTFWriter.ArrayField,
2316 CTFTypeId.SEQUENCE : CTFWriter.SequenceField
2319 field_type = _bt_python_get_field_type(native_field_instance)
2320 if field_type == CTFTypeId.UNKNOWN:
2321 raise TypeError("Invalid field instance")
2323 field = CTFWriter.Field.__new__(CTFWriter.Field)
2324 field._f = native_field_instance
2325 field.__class__ = type_dict[field_type]
2329 def declaration(self):
2330 native_field_type = _bt_ctf_field_get_type(self._f)
2331 if native_field_type is None:
2332 raise TypeError("Invalid field instance")
2333 return CTFWriter.FieldDeclaration._create_field_declaration_from_native_instance(native_field_type)
2335 class IntegerField(Field):
2337 Get an integer field's value.
2341 signedness = _bt_python_field_integer_get_signedness(self._f)
2343 raise TypeError("Invalid integer instance.")
2346 ret, value = _bt_ctf_field_unsigned_integer_get_value(self._f)
2348 ret, value = _bt_ctf_field_signed_integer_get_value(self._f)
2351 raise ValueError("Could not get integer field value.")
2355 Set an integer field's value.
2358 def value(self, value):
2359 if not isinstance(value, int):
2360 raise TypeError("IntegerField's value must be an int")
2362 signedness = _bt_python_field_integer_get_signedness(self._f)
2364 raise TypeError("Invalid integer instance.")
2367 ret = _bt_ctf_field_unsigned_integer_set_value(self._f, value)
2369 ret = _bt_ctf_field_signed_integer_set_value(self._f, value)
2372 raise ValueError("Could not set integer field value.")
2374 class EnumerationField(Field):
2376 Return the enumeration's underlying container field (an integer field).
2379 def container(self):
2380 container = CTFWriter.IntegerField.__new__(CTFWriter.IntegerField)
2381 container._f = _bt_ctf_field_enumeration_get_container(self._f)
2382 if container._f is None:
2383 raise TypeError("Invalid enumeration field type.")
2387 Get the enumeration field's mapping name.
2391 value = _bt_ctf_field_enumeration_get_mapping_name(self._f)
2393 raise ValueError("Could not get enumeration's mapping name.")
2397 Set the enumeration field's value. Must be an integer as mapping names
2401 def value(self, value):
2402 if not isinstance(value, int):
2403 raise TypeError("EnumerationField value must be an int")
2404 self.container.value = value
2406 class FloatFieldingPoint(Field):
2408 Get a floating point field's value.
2412 ret, value = _bt_ctf_field_floating_point_get_value(self._f)
2414 raise ValueError("Could not get floating point field value.")
2418 Set a floating point field's value.
2421 def value(self, value):
2422 if not isinstance(value, int) and not isinstance(value, float):
2423 raise TypeError("Value must be either a float or an int")
2425 ret = _bt_ctf_field_floating_point_set_value(self._f, float(value))
2427 raise ValueError("Could not set floating point field value.")
2429 class StructureField(Field):
2431 Get the structure's field corresponding to the provided field name.
2433 def field(self, field_name):
2434 native_instance = _bt_ctf_field_structure_get_field(self._f, str(field_name))
2435 if native_instance is None:
2436 raise ValueError("Invalid field_name provided.")
2437 return CTFWriter.Field._create_field_from_native_instance(native_instance)
2439 class VariantField(Field):
2441 Return the variant's selected field. The "tag" field is the selector enum field.
2443 def field(self, tag):
2444 native_instance = _bt_ctf_field_variant_get_field(self._f, tag._f)
2445 if native_instance is None:
2446 raise ValueError("Invalid tag provided.")
2447 return CTFWriter.Field._create_field_from_native_instance(native_instance)
2449 class ArrayField(Field):
2451 Return the array's field at position "index".
2453 def field(self, index):
2454 native_instance = _bt_ctf_field_array_get_field(self._f, index)
2455 if native_instance is None:
2456 raise IndexError("Invalid index provided.")
2457 return CTFWriter.Field._create_field_from_native_instance(native_instance)
2459 class SequenceField(Field):
2461 Get the sequence's length field (IntegerField).
2465 native_instance = _bt_ctf_field_sequence_get_length(self._f)
2466 if native_instance is None:
2468 return CTFWriter.Field._create_field_from_native_instance(native_instance)
2471 Set the sequence's length field (IntegerField).
2474 def length(self, length_field):
2475 if not isinstance(length_field, CTFWriter.IntegerField):
2476 raise TypeError("Invalid length field.")
2477 if length_field.declaration.signed:
2478 raise TypeError("Sequence field length must be unsigned")
2479 ret = _bt_ctf_field_sequence_set_length(self._f, length_field._f)
2481 raise ValueError("Could not set sequence length.")
2484 Return the sequence's field at position "index".
2486 def field(self, index):
2487 native_instance = _bt_ctf_field_sequence_get_field(self._f, index)
2488 if native_instance is None:
2489 raise ValueError("Could not get sequence element at index.")
2490 return CTFWriter.Field._create_field_from_native_instance(native_instance)
2492 class StringField(Field):
2494 Get a string field's value.
2498 return _bt_ctf_field_string_get_value(self._f)
2501 Set a string field's value.
2504 def value(self, value):
2505 ret = _bt_ctf_field_string_set_value(self._f, str(value))
2507 raise ValueError("Could not set string field value.")
2511 Create a new event class of the given name.
2513 def __init__(self, name):
2514 self._ec = _bt_ctf_event_class_create(name)
2515 if self._ec is None:
2516 raise ValueError("Event class creation failed.")
2519 _bt_ctf_event_class_put(self._ec)
2522 Add a field of type "field_type" to the event class.
2524 def add_field(self, field_type, field_name):
2525 ret = _bt_ctf_event_class_add_field(self._ec, field_type._ft, str(field_name))
2527 raise ValueError("Could not add field to event class.")
2530 Get the event class' name.
2534 name = _bt_ctf_event_class_get_name(self._ec)
2536 raise TypeError("Could not get EventClass name")
2540 Get the event class' id. Returns a negative value if unset.
2544 id = _bt_ctf_event_class_get_id(self._ec)
2546 raise TypeError("Could not get EventClass id")
2550 Set the event class' id. Throws a TypeError if the event class
2551 is already registered to a stream class.
2555 ret = _bt_ctf_event_class_set_id(self._ec, id)
2557 raise TypeError("Can't change an Event Class's id after it has been assigned to a stream class")
2560 Get the event class' stream class. Returns None if unset.
2563 def stream_class(self):
2564 stream_class_native = _bt_ctf_event_class_get_stream_class(self._ec)
2565 if stream_class_native is None:
2567 stream_class = CTFWriter.StreamClass.__new__(CTFWriter.StreamClass)
2568 stream_class._sc = stream_class_native
2572 Generator returning the event class' fields as tuples of (field name, field declaration).
2576 count = _bt_ctf_event_class_get_field_count(self._ec)
2578 raise TypeError("Could not get EventClass' field count")
2580 for i in range(count):
2581 field_name = _bt_python_ctf_event_class_get_field_name(self._ec, i)
2582 if field_name is None:
2583 raise TypeError("Could not get EventClass' field name at index {}".format(i))
2585 field_type_native = _bt_python_ctf_event_class_get_field_type(self._ec, i)
2586 if field_type_native is None:
2587 raise TypeError("Could not get EventClass' field type at index {}".format(i))
2589 field_type = CTFWriter.FieldDeclaration._create_field_declaration_from_native_instance(field_type_native)
2590 yield (field_name, field_type)
2593 Get a field declaration by name (FieldDeclaration).
2595 def get_field_by_name(self, name):
2596 field_type_native = _bt_ctf_event_class_get_field_by_name(self._ec, name)
2597 if field_type_native is None:
2598 raise TypeError("Could not find EventClass field with name {}".format(name))
2599 return CTFWriter.FieldDeclaration._create_field_declaration_from_native_instance(field_type_native)
2603 Create a new event of the given event class.
2605 def __init__(self, event_class):
2606 if not isinstance(event_class, CTFWriter.EventClass):
2607 raise TypeError("Invalid event_class argument.")
2609 self._e = _bt_ctf_event_create(event_class._ec)
2611 raise ValueError("Event creation failed.")
2614 _bt_ctf_event_put(self._e)
2617 Get the event's class.
2620 def event_class(self):
2621 event_class_native = _bt_ctf_event_get_class(self._e)
2622 if event_class_native is None:
2624 event_class = CTFWriter.EventClass.__new__(CTFWriter.EventClass)
2625 event_class._ec = event_class_native
2629 Get a clock from event. Returns None if the event's class
2630 is not registered to a stream class.
2633 clock_instance = _bt_ctf_event_get_clock(self._e)
2634 if clock_instance is None:
2636 clock = CTFWriter.Clock.__new__(CTFWriter.Clock)
2637 clock._c = clock_instance
2641 Get a field from event.
2643 def payload(self, field_name):
2644 native_instance = _bt_ctf_event_get_payload(self._e, str(field_name))
2645 if native_instance is None:
2646 raise ValueError("Could not get event payload.")
2647 return CTFWriter.Field._create_field_from_native_instance(native_instance)
2650 Set a manually created field as an event's payload.
2652 def set_payload(self, field_name, value_field):
2653 if not isinstance(value, CTFWriter.Field):
2654 raise TypeError("Invalid value type.")
2655 ret = _bt_ctf_event_set_payload(self._e, str(field_name), value_field._f)
2657 raise ValueError("Could not set event field payload.")
2661 Create a new stream class of the given name.
2663 def __init__(self, name):
2664 self._sc = _bt_ctf_stream_class_create(name)
2665 if self._sc is None:
2666 raise ValueError("Stream class creation failed.")
2669 _bt_ctf_stream_class_put(self._sc)
2672 Get a stream class' name.
2676 name = _bt_ctf_stream_class_get_name(self._sc)
2678 raise TypeError("Could not get StreamClass name")
2682 Get a stream class' clock.
2686 clock_instance = _bt_ctf_stream_class_get_clock(self._sc)
2687 if clock_instance is None:
2689 clock = CTFWriter.Clock.__new__(CTFWriter.Clock)
2690 clock._c = clock_instance
2694 Assign a clock to a stream class.
2697 def clock(self, clock):
2698 if not isinstance(clock, CTFWriter.Clock):
2699 raise TypeError("Invalid clock type.")
2701 ret = _bt_ctf_stream_class_set_clock(self._sc, clock._c)
2703 raise ValueError("Could not set stream class clock.")
2706 Get a stream class' id.
2710 ret = _bt_ctf_stream_class_get_id(self._sc)
2712 raise TypeError("Could not get StreamClass id")
2716 Assign an id to a stream class.
2720 ret = _bt_ctf_stream_class_set_id(self._sc, id)
2722 raise TypeError("Could not set stream class id.")
2725 Generator returning the stream class' event classes.
2728 def event_classes(self):
2729 count = _bt_ctf_stream_class_get_event_class_count(self._sc)
2731 raise TypeError("Could not get StreamClass' event class count")
2733 for i in range(count):
2734 event_class_native = _bt_ctf_stream_class_get_event_class(self._sc, i)
2735 if event_class_native is None:
2736 raise TypeError("Could not get StreamClass' event class at index {}".format(i))
2738 event_class = CTFWriter.EventClass.__new__(CTFWriter.EventClass)
2739 event_class._ec = event_class_native
2743 Add an event class to a stream class. New events can be added even after a
2744 stream has been instantiated and events have been appended. However, a stream
2745 will not accept events of a class that has not been registered beforehand.
2747 def add_event_class(self, event_class):
2748 if not isinstance(event_class, CTFWriter.EventClass):
2749 raise TypeError("Invalid event_class type.")
2751 ret = _bt_ctf_stream_class_add_event_class(self._sc, event_class._ec)
2753 raise ValueError("Could not add event class.")
2757 Create a stream of the given class.
2759 def __init__(self, stream_class):
2760 if not isinstance(stream_class, CTFWriter.StreamClass):
2761 raise TypeError("Invalid stream_class type.")
2763 self._s = _bt_ctf_stream_create(stream_class._sc)
2765 raise ValueError("Stream creation failed.")
2768 _bt_ctf_stream_put(self._s)
2771 Get a stream's discarded event count.
2774 def discarded_events(self):
2775 ret, count = _bt_ctf_stream_get_discarded_events_count(self._s)
2777 raise ValueError("Could not get the stream's discarded events count")
2781 Increase the current packet's discarded event count.
2783 def append_discarded_events(self, event_count):
2784 _bt_ctf_stream_append_discarded_events(self._s, event_count)
2787 Append "event" to the stream's current packet. The stream's associated clock
2788 will be sampled during this call. The event shall not be modified after
2789 being appended to a stream.
2791 def append_event(self, event):
2792 ret = _bt_ctf_stream_append_event(self._s, event._e)
2794 raise ValueError("Could not append event to stream.")
2797 The stream's current packet's events will be flushed to disk. Events
2798 subsequently appended to the stream will be added to a new packet.
2801 ret = _bt_ctf_stream_flush(self._s)
2803 raise ValueError("Could not flush stream.")
2807 Create a new writer that will produce a trace in the given path.
2809 def __init__(self, path):
2810 self._w = _bt_ctf_writer_create(path)
2812 raise ValueError("Writer creation failed.")
2815 _bt_ctf_writer_put(self._w)
2818 Create a new stream instance and register it to the writer.
2820 def create_stream(self, stream_class):
2821 if not isinstance(stream_class, CTFWriter.StreamClass):
2822 raise TypeError("Invalid stream_class type.")
2824 stream = CTFWriter.Stream.__new__(CTFWriter.Stream)
2825 stream._s = _bt_ctf_writer_create_stream(self._w, stream_class._sc)
2829 Add an environment field to the trace.
2831 def add_environment_field(self, name, value):
2832 ret = _bt_ctf_writer_add_environment_field(self._w, str(name), str(value))
2834 raise ValueError("Could not add environment field to trace.")
2837 Add a clock to the trace. Clocks assigned to stream classes must be
2838 registered to the writer.
2840 def add_clock(self, clock):
2841 ret = _bt_ctf_writer_add_clock(self._w, clock._c)
2843 raise ValueError("Could not add clock to Writer.")
2846 Get the trace's TSDL meta-data.
2850 return _bt_ctf_writer_get_metadata_string(self._w)
2853 Flush the trace's metadata to the metadata file.
2855 def flush_metadata(self):
2856 _bt_ctf_writer_flush_metadata(self._w)
2859 Get the trace's byte order. Must be a constant from the ByteOrder
2863 def byte_order(self):
2864 raise NotImplementedError("Getter not implemented.")
2867 Set the trace's byte order. Must be a constant from the ByteOrder
2868 class. Defaults to BYTE_ORDER_NATIVE, the host machine's endianness.
2871 def byte_order(self, byte_order):
2872 ret = _bt_ctf_writer_set_byte_order(self._w, byte_order)
2874 raise ValueError("Could not set trace's byte order.")