4 * Babeltrace Python Module interface file
6 * Copyright 2012 EfficiOS Inc.
8 * Author: Danny Serres <danny.serres@efficios.com>
9 * Author: Jérémie Galarneau <jeremie.galarneau@efficios.com>
11 * Permission is hereby granted, free of charge, to any person obtaining a copy
12 * of this software and associated documentation files (the "Software"), to deal
13 * in the Software without restriction, including without limitation the rights
14 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
15 * copies of the Software, and to permit persons to whom the Software is
16 * furnished to do so, subject to the following conditions:
18 * The above copyright notice and this permission notice shall be included in
19 * all copies or substantial portions of the Software.
24 "BABELTRACE_VERSION_STR
26 Babeltrace is a trace viewer and converter reading and writing the
27 Common Trace Format (CTF). Its main use is to pretty-print CTF
28 traces into a human-readable text output.
30 To use this module, the first step is to create a TraceCollection and add a
34 %module(docstring=DOCSTRING) babeltrace
39 #define SWIG_FILE_WITH_INIT
40 #include <babeltrace/babeltrace.h>
41 #include <babeltrace/babeltrace-internal.h>
42 #include <babeltrace/trace-handle.h>
43 #include <babeltrace/trace-handle-internal.h>
44 #include <babeltrace/context.h>
45 #include <babeltrace/context-internal.h>
46 #include <babeltrace/iterator.h>
47 #include <babeltrace/iterator-internal.h>
48 #include <babeltrace/format.h>
49 #include <babeltrace/list.h>
50 #include <babeltrace/types.h>
51 #include <babeltrace/ctf/iterator.h>
52 #include "python-complements.h"
53 #include <babeltrace/ctf-writer/clock.h>
54 #include <babeltrace/ctf-writer/event-fields.h>
55 #include <babeltrace/ctf-writer/event-types.h>
56 #include <babeltrace/ctf-writer/event.h>
57 #include <babeltrace/ctf-writer/stream.h>
58 #include <babeltrace/ctf-writer/writer.h>
61 typedef int bt_intern_str;
62 typedef int64_t ssize_t;
64 /* =================================================================
66 ¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯
69 struct bt_definition **_bt_python_field_listcaller(
70 const struct bt_ctf_event *ctf_event,
71 const struct bt_definition *scope,
72 unsigned int *OUTPUT);
73 struct bt_definition *_bt_python_field_one_from_list(
74 struct bt_definition **list, int index);
75 struct bt_ctf_event_decl **_bt_python_event_decl_listcaller(
77 struct bt_context *ctx,
78 unsigned int *OUTPUT);
79 struct bt_ctf_event_decl *_bt_python_decl_one_from_list(
80 struct bt_ctf_event_decl **list, int index);
81 struct bt_ctf_field_decl **_by_python_field_decl_listcaller(
82 struct bt_ctf_event_decl *event_decl,
83 enum bt_ctf_scope scope,
84 unsigned int *OUTPUT);
85 struct bt_ctf_field_decl *_bt_python_field_decl_one_from_list(
86 struct bt_ctf_field_decl **list, int index);
87 struct definition_array *_bt_python_get_array_from_def(
88 struct bt_definition *field);
89 struct definition_sequence *_bt_python_get_sequence_from_def(
90 struct bt_definition *field);
91 struct bt_declaration *_bt_python_get_array_element_declaration(
92 struct bt_declaration *field);
93 struct bt_declaration *_bt_python_get_sequence_element_declaration(
94 struct bt_declaration *field);
95 const char *_bt_python_get_array_string(struct bt_definition *field);
96 const char *_bt_python_get_sequence_string(struct bt_definition *field);
97 int _bt_python_field_integer_get_signedness(const struct bt_ctf_field *field);
98 enum ctf_type_id _bt_python_get_field_type(const struct bt_ctf_field *field);
99 const char *_bt_python_ctf_field_type_enumeration_get_mapping(
100 struct bt_ctf_field_type *enumeration, size_t index,
101 int64_t *OUTPUT, int64_t *OUTPUT);
102 const char *_bt_python_ctf_field_type_enumeration_get_mapping_unsigned(
103 struct bt_ctf_field_type *enumeration, size_t index,
104 uint64_t *OUTPUT, uint64_t *OUTPUT);
105 const char *_bt_python_ctf_field_type_structure_get_field_name(
106 struct bt_ctf_field_type *structure, size_t index);
107 struct bt_ctf_field_type *_bt_python_ctf_field_type_structure_get_field_type(
108 struct bt_ctf_field_type *structure, size_t index);
109 const char *_bt_python_ctf_field_type_variant_get_field_name(
110 struct bt_ctf_field_type *variant, size_t index);
111 struct bt_ctf_field_type *_bt_python_ctf_field_type_variant_get_field_type(
112 struct bt_ctf_field_type *variant, size_t index);
113 const char *_bt_python_ctf_event_class_get_field_name(
114 struct bt_ctf_event_class *event_class, size_t index);
115 struct bt_ctf_field_type *_bt_python_ctf_event_class_get_field_type(
116 struct bt_ctf_event_class *event_class, size_t index);
117 int _bt_python_ctf_clock_get_uuid_index(struct bt_ctf_clock *clock,
118 size_t index, unsigned char *OUTPUT);
119 int _bt_python_ctf_clock_set_uuid_index(struct bt_ctf_clock *clock,
120 size_t index, unsigned char value);
122 /* =================================================================
123 CONTEXT.H, CONTEXT-INTERNAL.H
124 ¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯
127 %rename("_bt_context_create") bt_context_create(void);
128 %rename("_bt_context_add_trace") bt_context_add_trace(
129 struct bt_context *ctx, const char *path, const char *format,
130 void (*packet_seek)(struct bt_stream_pos *pos, size_t index, int whence),
131 struct bt_mmap_stream_list *stream_list, FILE *metadata);
132 %rename("_bt_context_remove_trace") bt_context_remove_trace(
133 struct bt_context *ctx, int trace_id);
134 %rename("_bt_context_get") bt_context_get(struct bt_context *ctx);
135 %rename("_bt_context_put") bt_context_put(struct bt_context *ctx);
136 %rename("_bt_ctf_event_get_context") bt_ctf_event_get_context(
137 const struct bt_ctf_event *event);
139 struct bt_context *bt_context_create(void);
140 int bt_context_add_trace(struct bt_context *ctx, const char *path, const char *format,
141 void (*packet_seek)(struct bt_stream_pos *pos, size_t index, int whence),
142 struct bt_mmap_stream_list *stream_list, FILE *metadata);
143 void bt_context_remove_trace(struct bt_context *ctx, int trace_id);
144 void bt_context_get(struct bt_context *ctx);
145 void bt_context_put(struct bt_context *ctx);
146 struct bt_context *bt_ctf_event_get_context(const struct bt_ctf_event *event);
148 // class TraceCollection to prevent direct access to struct bt_context
150 class TraceCollection:
152 The TraceCollection is the object that contains all currently opened traces.
156 self._tc = _bt_context_create()
159 _bt_context_put(self._tc)
161 def add_trace(self, path, format_str):
163 Add a trace by path to the TraceCollection.
167 path is the path to the trace, it is not recursive.
168 If "path" is None, stream_list is used instead as a list
169 of mmap streams to open for the trace.
171 format is a string containing the format name in which the trace was
174 Return: the corresponding TraceHandle on success or None on error.
176 ret = _bt_context_add_trace(self._tc, path, format_str, None, None, None)
180 th = TraceHandle.__new__(TraceHandle)
182 th._trace_collection = self
185 def add_traces_recursive(self, path, format_str):
187 Open a trace recursively.
189 Find each trace present in the subdirectory starting from the given
190 path, and add them to the TraceCollection.
192 Return a dict of TraceHandle instances (the full path is the key).
193 Return None on error.
203 for fullpath, dirs, files in os.walk(path):
204 if "metadata" in files:
205 trace_handle = self.add_trace(fullpath, format_str)
206 if trace_handle is None:
210 trace_handles[fullpath] = trace_handle
213 if noTrace and error:
217 def remove_trace(self, trace_handle):
219 Remove a trace from the TraceCollection.
220 Effectively closing the trace.
223 _bt_context_remove_trace(self._tc, trace_handle._id)
224 except AttributeError:
225 raise TypeError("in remove_trace, "
226 "argument 2 must be a TraceHandle instance")
231 Generator function to iterate over the events of open in the current
234 Due to limitations of the native Babeltrace API, only one event
235 may be "alive" at a time (i.e. a user should never store a copy
236 of the events returned by this function for ulterior use). Users
237 shall make sure to copy the information they need from an event
238 before accessing the next one.
240 Furthermore, event objects become invalid when the generator goes
241 out of scope as the underlying iterator will be reclaimed. Using an
242 event after the the generator has gone out of scope may result in a
243 crash or data corruption.
245 begin_pos_ptr = _bt_iter_pos()
246 end_pos_ptr = _bt_iter_pos()
247 begin_pos_ptr.type = SEEK_BEGIN
248 end_pos_ptr.type = SEEK_LAST
250 for event in self._events(begin_pos_ptr, end_pos_ptr):
253 def events_timestamps(self, timestamp_begin, timestamp_end):
255 Generator function to iterate over the events of open in the current
256 TraceCollection from timestamp_begin to timestamp_end.
258 begin_pos_ptr = _bt_iter_pos()
259 end_pos_ptr = _bt_iter_pos()
260 begin_pos_ptr.type = end_pos_ptr.type = SEEK_TIME
261 begin_pos_ptr.u.seek_time = timestamp_begin
262 end_pos_ptr.u.seek_time = timestamp_end
264 for event in self._events(begin_pos_ptr, end_pos_ptr):
268 def timestamp_begin(self):
269 pos_ptr = _bt_iter_pos()
270 pos_ptr.type = SEEK_BEGIN
271 return self._timestamp_at_pos(pos_ptr)
274 def timestamp_end(self):
275 pos_ptr = _bt_iter_pos()
276 pos_ptr.type = SEEK_LAST
277 return self._timestamp_at_pos(pos_ptr)
279 def _timestamp_at_pos(self, pos_ptr):
280 ctf_it_ptr = _bt_ctf_iter_create(self._tc, pos_ptr, pos_ptr)
281 if ctf_it_ptr is None:
282 raise NotImplementedError("Creation of multiple iterators is unsupported.")
283 ev_ptr = _bt_ctf_iter_read_event(ctf_it_ptr)
284 _bt_ctf_iter_destroy(ctf_it_ptr)
288 def _events(self, begin_pos_ptr, end_pos_ptr):
289 ctf_it_ptr = _bt_ctf_iter_create(self._tc, begin_pos_ptr, end_pos_ptr)
290 if ctf_it_ptr is None:
291 raise NotImplementedError(
292 "Creation of multiple iterators is unsupported.")
295 ev_ptr = _bt_ctf_iter_read_event(ctf_it_ptr)
299 ev = Event.__new__(Event)
303 except GeneratorExit:
306 ret = _bt_iter_next(_bt_ctf_get_iter(ctf_it_ptr))
310 _bt_ctf_iter_destroy(ctf_it_ptr)
316 /* =================================================================
321 %rename("lookup_format") bt_lookup_format(bt_intern_str qname);
322 %rename("_bt_print_format_list") bt_fprintf_format_list(FILE *fp);
323 %rename("register_format") bt_register_format(struct format *format);
324 %rename("unregister_format") bt_unregister_format(struct bt_format *format);
326 extern struct format *bt_lookup_format(bt_intern_str qname);
327 extern void bt_fprintf_format_list(FILE *fp);
328 extern int bt_register_format(struct bt_format *format);
329 extern void bt_unregister_format(struct bt_format *format);
333 def print_format_list(babeltrace_file):
335 Print a list of available formats to file.
337 babeltrace_file must be a File instance opened in write mode.
340 if babeltrace_file._file is not None:
341 _bt_print_format_list(babeltrace_file._file)
342 except AttributeError:
343 raise TypeError("in print_format_list, "
344 "argument 1 must be a File instance")
349 /* =================================================================
350 ITERATOR.H, ITERATOR-INTERNAL.H
351 ¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯
354 %rename("_bt_iter_create") bt_iter_create(struct bt_context *ctx,
355 const struct bt_iter_pos *begin_pos, const struct bt_iter_pos *end_pos);
356 %rename("_bt_iter_destroy") bt_iter_destroy(struct bt_iter *iter);
357 %rename("_bt_iter_next") bt_iter_next(struct bt_iter *iter);
358 %rename("_bt_iter_get_pos") bt_iter_get_pos(struct bt_iter *iter);
359 %rename("_bt_iter_free_pos") bt_iter_free_pos(struct bt_iter_pos *pos);
360 %rename("_bt_iter_set_pos") bt_iter_set_pos(struct bt_iter *iter,
361 const struct bt_iter_pos *pos);
362 %rename("_bt_iter_create_time_pos") bt_iter_create_time_pos(struct bt_iter *iter,
365 struct bt_iter *bt_iter_create(struct bt_context *ctx,
366 const struct bt_iter_pos *begin_pos, const struct bt_iter_pos *end_pos);
367 void bt_iter_destroy(struct bt_iter *iter);
368 int bt_iter_next(struct bt_iter *iter);
369 struct bt_iter_pos *bt_iter_get_pos(struct bt_iter *iter);
370 void bt_iter_free_pos(struct bt_iter_pos *pos);
371 int bt_iter_set_pos(struct bt_iter *iter, const struct bt_iter_pos *pos);
372 struct bt_iter_pos *bt_iter_create_time_pos(struct bt_iter *iter, uint64_t timestamp);
374 %rename("_bt_iter_pos") bt_iter_pos;
375 %rename("SEEK_TIME") BT_SEEK_TIME;
376 %rename("SEEK_RESTORE") BT_SEEK_RESTORE;
377 %rename("SEEK_CUR") BT_SEEK_CUR;
378 %rename("SEEK_BEGIN") BT_SEEK_BEGIN;
379 %rename("SEEK_LAST") BT_SEEK_LAST;
381 // This struct is taken from iterator.h
382 // All changes to the struct must also be made here
385 BT_SEEK_TIME, /* uses u.seek_time */
386 BT_SEEK_RESTORE, /* uses u.restore */
393 struct bt_saved_pos *restore;
397 /* =================================================================
398 TRACE-HANDLE.H, TRACE-HANDLE-INTERNAL.H
399 ¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯
402 %rename("_bt_trace_handle_create") bt_trace_handle_create(struct bt_context *ctx);
403 %rename("_bt_trace_handle_destroy") bt_trace_handle_destroy(struct bt_trace_handle *bt);
404 struct bt_trace_handle *bt_trace_handle_create(struct bt_context *ctx);
405 void bt_trace_handle_destroy(struct bt_trace_handle *bt);
407 %rename("_bt_trace_handle_get_path") bt_trace_handle_get_path(struct bt_context *ctx,
409 %rename("_bt_trace_handle_get_timestamp_begin") bt_trace_handle_get_timestamp_begin(
410 struct bt_context *ctx, int handle_id, enum bt_clock_type type);
411 %rename("_bt_trace_handle_get_timestamp_end") bt_trace_handle_get_timestamp_end(
412 struct bt_context *ctx, int handle_id, enum bt_clock_type type);
413 const char *bt_trace_handle_get_path(struct bt_context *ctx, int handle_id);
414 uint64_t bt_trace_handle_get_timestamp_begin(struct bt_context *ctx, int handle_id,
415 enum bt_clock_type type);
416 uint64_t bt_trace_handle_get_timestamp_end(struct bt_context *ctx, int handle_id,
417 enum bt_clock_type type);
419 %rename("_bt_ctf_event_get_handle_id") bt_ctf_event_get_handle_id(
420 const struct bt_ctf_event *event);
421 int bt_ctf_event_get_handle_id(const struct bt_ctf_event *event);
426 # Based on enum bt_clock_type in clock-type.h
431 class TraceHandle(object):
433 The TraceHandle allows the user to manipulate a trace file directly.
434 It is a unique identifier representing a trace file.
439 raise NotImplementedError("TraceHandle cannot be instantiated")
442 return "Babeltrace TraceHandle: trace_id('{0}')".format(self._id)
446 """Return the TraceHandle id."""
451 """Return the path of a TraceHandle."""
452 return _bt_trace_handle_get_path(self._trace_collection._tc, self._id)
455 def timestamp_begin(self):
456 """Return the creation time of the buffers of a trace."""
457 return _bt_trace_handle_get_timestamp_begin(
458 self._trace_collection._tc, self._id, ClockType.CLOCK_REAL)
461 def timestamp_end(self):
462 """Return the destruction timestamp of the buffers of a trace."""
463 return _bt_trace_handle_get_timestamp_end(
464 self._trace_collection._tc, self._id, ClockType.CLOCK_REAL)
469 Generator returning all events (EventDeclaration) in a trace.
471 ret = _bt_python_event_decl_listcaller(self.id, self._trace_collection._tc)
473 if not isinstance(ret, list):
476 ptr_list, count = ret
477 for i in range(count):
478 tmp = EventDeclaration.__new__(EventDeclaration)
479 tmp._ed = _bt_python_decl_one_from_list(ptr_list, i)
486 // =================================================================
488 // =================================================================
490 /* =================================================================
496 %rename("_bt_ctf_iter_create") bt_ctf_iter_create(struct bt_context *ctx,
497 const struct bt_iter_pos *begin_pos,
498 const struct bt_iter_pos *end_pos);
499 %rename("_bt_ctf_get_iter") bt_ctf_get_iter(struct bt_ctf_iter *iter);
500 %rename("_bt_ctf_iter_destroy") bt_ctf_iter_destroy(struct bt_ctf_iter *iter);
501 %rename("_bt_ctf_iter_read_event") bt_ctf_iter_read_event(struct bt_ctf_iter *iter);
503 struct bt_ctf_iter *bt_ctf_iter_create(struct bt_context *ctx,
504 const struct bt_iter_pos *begin_pos,
505 const struct bt_iter_pos *end_pos);
506 struct bt_iter *bt_ctf_get_iter(struct bt_ctf_iter *iter);
507 void bt_ctf_iter_destroy(struct bt_ctf_iter *iter);
508 struct bt_ctf_event *bt_ctf_iter_read_event(struct bt_ctf_iter *iter);
512 %rename("_bt_ctf_get_top_level_scope") bt_ctf_get_top_level_scope(const struct
513 bt_ctf_event *event, enum bt_ctf_scope scope);
514 %rename("_bt_ctf_event_name") bt_ctf_event_name(const struct bt_ctf_event *ctf_event);
515 %rename("_bt_ctf_get_timestamp") bt_ctf_get_timestamp(
516 const struct bt_ctf_event *ctf_event);
517 %rename("_bt_ctf_get_cycles") bt_ctf_get_cycles(
518 const struct bt_ctf_event *ctf_event);
520 %rename("_bt_ctf_get_field") bt_ctf_get_field(const struct bt_ctf_event *ctf_event,
521 const struct bt_definition *scope, const char *field);
522 %rename("_bt_ctf_get_index") bt_ctf_get_index(const struct bt_ctf_event *ctf_event,
523 const struct bt_definition *field, unsigned int index);
524 %rename("_bt_ctf_field_name") bt_ctf_field_name(const struct bt_definition *field);
525 %rename("_bt_ctf_field_type") bt_ctf_field_type(const struct bt_declaration *field);
526 %rename("_bt_ctf_get_int_signedness") bt_ctf_get_int_signedness(
527 const struct bt_declaration *field);
528 %rename("_bt_ctf_get_int_base") bt_ctf_get_int_base(const struct bt_declaration *field);
529 %rename("_bt_ctf_get_int_byte_order") bt_ctf_get_int_byte_order(
530 const struct bt_declaration *field);
531 %rename("_bt_ctf_get_int_len") bt_ctf_get_int_len(const struct bt_declaration *field);
532 %rename("_bt_ctf_get_enum_int") bt_ctf_get_enum_int(const struct bt_definition *field);
533 %rename("_bt_ctf_get_enum_str") bt_ctf_get_enum_str(const struct bt_definition *field);
534 %rename("_bt_ctf_get_encoding") bt_ctf_get_encoding(const struct bt_declaration *field);
535 %rename("_bt_ctf_get_array_len") bt_ctf_get_array_len(const struct bt_declaration *field);
536 %rename("_bt_ctf_get_uint64") bt_ctf_get_uint64(const struct bt_definition *field);
537 %rename("_bt_ctf_get_int64") bt_ctf_get_int64(const struct bt_definition *field);
538 %rename("_bt_ctf_get_char_array") bt_ctf_get_char_array(const struct bt_definition *field);
539 %rename("_bt_ctf_get_string") bt_ctf_get_string(const struct bt_definition *field);
540 %rename("_bt_ctf_get_float") bt_ctf_get_float(const struct bt_definition *field);
541 %rename("_bt_ctf_get_variant") bt_ctf_get_variant(const struct bt_definition *field);
542 %rename("_bt_ctf_field_get_error") bt_ctf_field_get_error(void);
543 %rename("_bt_ctf_get_decl_event_name") bt_ctf_get_decl_event_name(const struct
544 bt_ctf_event_decl *event);
545 %rename("_bt_ctf_get_decl_event_id") bt_ctf_get_decl_event_id(const struct
546 bt_ctf_event_decl *event);
547 %rename("_bt_ctf_get_decl_field_name") bt_ctf_get_decl_field_name(
548 const struct bt_ctf_field_decl *field);
549 %rename("_bt_ctf_get_decl_from_def") bt_ctf_get_decl_from_def(
550 const struct bt_definition *field);
551 %rename("_bt_ctf_get_decl_from_field_decl") bt_ctf_get_decl_from_field_decl(
552 const struct bt_ctf_field_decl *field);
553 %rename("_bt_array_index") bt_array_index(struct definition_array *array, uint64_t i);
554 %rename("_bt_sequence_len") bt_sequence_len(struct definition_sequence *sequence);
555 %rename("_bt_sequence_index") bt_sequence_index(struct definition_sequence *sequence, uint64_t i);
556 %rename("_bt_ctf_get_struct_field_count") bt_ctf_get_struct_field_count(const struct bt_definition *structure);
557 %rename("_bt_ctf_get_struct_field_index") bt_ctf_get_struct_field_index(const struct bt_definition *structure, uint64_t i);
559 const struct bt_definition *bt_ctf_get_top_level_scope(const struct bt_ctf_event *ctf_event,
560 enum bt_ctf_scope scope);
561 const char *bt_ctf_event_name(const struct bt_ctf_event *ctf_event);
562 uint64_t bt_ctf_get_timestamp(const struct bt_ctf_event *ctf_event);
563 uint64_t bt_ctf_get_cycles(const struct bt_ctf_event *ctf_event);
564 const struct bt_definition *bt_ctf_get_field(const struct bt_ctf_event *ctf_event,
565 const struct bt_definition *scope,
567 const struct bt_definition *bt_ctf_get_index(const struct bt_ctf_event *ctf_event,
568 const struct bt_definition *field,
570 const char *bt_ctf_field_name(const struct bt_definition *field);
571 enum ctf_type_id bt_ctf_field_type(const struct bt_declaration *field);
572 int bt_ctf_get_int_signedness(const struct bt_declaration *field);
573 int bt_ctf_get_int_base(const struct bt_declaration *field);
574 int bt_ctf_get_int_byte_order(const struct bt_declaration *field);
575 ssize_t bt_ctf_get_int_len(const struct bt_declaration *field);
576 const struct bt_definition *bt_ctf_get_enum_int(const struct bt_definition *field);
577 const char *bt_ctf_get_enum_str(const struct bt_definition *field);
578 enum ctf_string_encoding bt_ctf_get_encoding(const struct bt_declaration *field);
579 int bt_ctf_get_array_len(const struct bt_declaration *field);
580 struct bt_definition *bt_array_index(struct definition_array *array, uint64_t i);
581 uint64_t bt_ctf_get_uint64(const struct bt_definition *field);
582 int64_t bt_ctf_get_int64(const struct bt_definition *field);
583 char *bt_ctf_get_char_array(const struct bt_definition *field);
584 char *bt_ctf_get_string(const struct bt_definition *field);
585 double bt_ctf_get_float(const struct bt_definition *field);
586 const struct bt_definition *bt_ctf_get_variant(const struct bt_definition *field);
587 int bt_ctf_field_get_error(void);
588 const char *bt_ctf_get_decl_event_name(const struct bt_ctf_event_decl *event);
589 uint64_t bt_ctf_get_decl_event_id(const struct bt_ctf_event_decl *event);
590 const char *bt_ctf_get_decl_field_name(const struct bt_ctf_field_decl *field);
591 const struct bt_declaration *bt_ctf_get_decl_from_def(const struct bt_definition *field);
592 const struct bt_declaration *bt_ctf_get_decl_from_field_decl(const struct bt_ctf_field_decl *field);
593 uint64_t bt_sequence_len(struct definition_sequence *sequence);
594 struct bt_definition *bt_sequence_index(struct definition_sequence *sequence, uint64_t i);
595 uint64_t bt_ctf_get_struct_field_count(const struct bt_definition *structure);
596 const struct bt_definition *bt_ctf_get_struct_field_index(const struct bt_definition *structure, uint64_t i);
600 class CTFStringEncoding:
606 # Based on the enum in ctf-writer/writer.h
608 BYTE_ORDER_NATIVE = 0
609 BYTE_ORDER_LITTLE_ENDIAN = 1
610 BYTE_ORDER_BIG_ENDIAN = 2
611 BYTE_ORDER_NETWORK = 3
612 BYTE_ORDER_UNKNOWN = 4 # Python-specific entry
614 #enum equivalent, accessible constants
615 #These are taken directly from ctf/events.h
616 #All changes to enums must also be made here
630 name = "UNKNOWN_TYPE"
631 constants = [attr for attr in dir(CTFTypeId) if not callable(getattr(CTFTypeId, attr)) and not attr.startswith("__")]
632 for attr in constants:
633 if getattr(CTFTypeId, attr) == id:
639 TRACE_PACKET_HEADER = 0
640 STREAM_PACKET_CONTEXT = 1
641 STREAM_EVENT_HEADER = 2
642 STREAM_EVENT_CONTEXT = 3
646 def scope_name(scope):
647 name = "UNKNOWN_SCOPE"
648 constants = [attr for attr in dir(CTFScope) if not callable(getattr(CTFScope, attr)) and not attr.startswith("__")]
649 for attr in constants:
650 if getattr(CTFScope, attr) == scope:
655 # Priority of the scopes when searching for event fields
656 _scopes = [CTFScope.EVENT_FIELDS, CTFScope.EVENT_CONTEXT, CTFScope.STREAM_EVENT_CONTEXT,
657 CTFScope.STREAM_EVENT_HEADER, CTFScope.STREAM_PACKET_CONTEXT, CTFScope.TRACE_PACKET_HEADER]
660 from datetime import datetime
661 class Event(collections.Mapping):
663 This class represents an event from the trace.
664 It is obtained using the TraceCollection generator functions.
668 raise NotImplementedError("Event cannot be instantiated")
672 """Return the name of the event or None on error."""
673 return _bt_ctf_event_name(self._e)
678 Return the timestamp of the event as written in
679 the packet (in cycles) or -1ULL on error.
681 return _bt_ctf_get_cycles(self._e)
686 Return the timestamp of the event offset with the
687 system clock source or -1ULL on error.
689 return _bt_ctf_get_timestamp(self._e)
694 Return a datetime object based on the event's
695 timestamp. Note that the datetime class' precision
696 is limited to microseconds.
698 return datetime.fromtimestamp(self.timestamp / 1E9)
700 def field_with_scope(self, field_name, scope):
702 Get field_name's value in scope.
703 None is returned if no field matches field_name.
705 if not scope in _scopes:
706 raise ValueError("Invalid scope provided")
707 field = self._field_with_scope(field_name, scope)
708 if field is not None:
712 def field_list_with_scope(self, scope):
713 """Return a list of field names in scope."""
714 if not scope in _scopes:
715 raise ValueError("Invalid scope provided")
717 for field in self._field_list_with_scope(scope):
718 field_names.append(field.name)
724 Get the TraceHandle associated with this event
727 ret = _bt_ctf_event_get_handle_id(self._e)
731 th = TraceHandle.__new__(TraceHandle)
733 th._trace_collection = self.get_trace_collection()
737 def trace_collection(self):
739 Get the TraceCollection associated with this event.
740 Return None on error.
742 trace_collection = TraceCollection()
743 trace_collection._tc = _bt_ctf_event_get_context(self._e);
744 if trace_collection._tc is None:
747 return trace_collection
749 def __getitem__(self, field_name):
751 Get field_name's value. If the field_name exists in multiple
752 scopes, the first field found is returned. The scopes are searched
753 in the following order:
756 3) STREAM_EVENT_CONTEXT
757 4) STREAM_EVENT_HEADER
758 5) STREAM_PACKET_CONTEXT
759 6) TRACE_PACKET_HEADER
760 None is returned if no field matches field_name.
762 Use field_with_scope() to explicitly access fields in a given
765 field = self._field(field_name)
766 if field is not None:
768 raise KeyError(field_name)
771 for key in self.keys():
776 for scope in _scopes:
777 scope_ptr = _bt_ctf_get_top_level_scope(self._e, scope)
778 ret = _bt_python_field_listcaller(self._e, scope_ptr)
779 if isinstance(ret, list):
783 def __contains__(self, field_name):
784 return self._field(field_name) is not None
787 """Return a list of field names."""
789 for scope in _scopes:
790 for name in self.field_list_with_scope(scope):
791 field_names.add(name)
792 return list(field_names)
794 def get(self, field_name, default = None):
795 field = self._field(field_name)
801 for field in self.keys():
802 yield (field, self[field])
804 def _field_with_scope(self, field_name, scope):
805 scope_ptr = _bt_ctf_get_top_level_scope(self._e, scope)
806 if scope_ptr is None:
809 definition_ptr = _bt_ctf_get_field(self._e, scope_ptr, field_name)
810 if definition_ptr is None:
813 field = _Definition(definition_ptr, scope)
816 def _field(self, field_name):
818 for scope in _scopes:
819 field = self._field_with_scope(field_name, scope)
820 if field is not None:
824 def _field_list_with_scope(self, scope):
826 scope_ptr = _bt_ctf_get_top_level_scope(self._e, scope)
828 # Returns a list [list_ptr, count]. If list_ptr is NULL, SWIG will only
829 # provide the "count" return value
832 ret = _bt_python_field_listcaller(self._e, scope_ptr)
833 if isinstance(ret, list):
834 list_ptr, count = ret
836 for i in range(count):
837 definition_ptr = _bt_python_field_one_from_list(list_ptr, i)
838 if definition_ptr is not None:
839 definition = _Definition(definition_ptr, scope)
840 fields.append(definition)
843 class FieldError(Exception):
844 def __init__(self, value):
848 return repr(self.value)
850 class EventDeclaration(object):
851 """Event declaration class. Do not instantiate."""
852 MAX_UINT64 = 0xFFFFFFFFFFFFFFFF
855 raise NotImplementedError("EventDeclaration cannot be instantiated")
859 """Return the name of the event or None on error"""
860 return _bt_ctf_get_decl_event_name(self._ed)
864 """Return the event-ID of the event or -1 on error"""
865 id = _bt_ctf_get_decl_event_id(self._ed)
866 if id == self.MAX_UINT64:
873 Generator returning all FieldDeclarations of an event, going through
874 each scope in the following order:
877 3) STREAM_EVENT_CONTEXT
878 4) STREAM_EVENT_HEADER
879 5) STREAM_PACKET_CONTEXT
880 6) TRACE_PACKET_HEADER
882 for scope in _scopes:
883 for declaration in self.fields_scope(scope):
886 def fields_scope(self, scope):
888 Generator returning FieldDeclarations of the current event in scope.
890 ret = _by_python_field_decl_listcaller(self._ed, scope)
892 if not isinstance(ret, list):
895 list_ptr, count = ret
896 for i in range(count):
897 field_declaration_ptr = _bt_python_field_decl_one_from_list(list_ptr, i)
898 if field_declaration_ptr is not None:
899 declaration_ptr = _bt_ctf_get_decl_from_field_decl(field_declaration_ptr)
900 field_declaration = _create_field_declaration(declaration_ptr, _bt_ctf_get_decl_field_name(field_declaration_ptr), scope)
901 yield field_declaration
903 class FieldDeclaration(object):
904 """Field declaration class. Do not instantiate."""
906 raise NotImplementedError("FieldDeclaration cannot be instantiated")
909 return "({0}) {1} {2}".format(CTFScope.scope_name(self.scope), CTFTypeId.type_name(self.type), self.name)
913 """Return the name of a FieldDeclaration or None on error."""
919 Return the FieldDeclaration's type. One of the entries in class
922 return _bt_ctf_field_type(self._fd)
927 Return the FieldDeclaration's scope.
931 class IntegerFieldDeclaration(FieldDeclaration):
932 """Do not instantiate."""
934 raise NotImplementedError("IntegerFieldDeclaration cannot be instantiated")
937 def signedness(self):
939 Return the signedness of an integer:
940 0 if unsigned; 1 if signed; -1 on error.
942 return _bt_ctf_get_int_signedness(self._fd)
946 """Return the base of an int or a negative value on error."""
947 return _bt_ctf_get_int_base(self._fd)
950 def byte_order(self):
952 Return the byte order. One of class ByteOrder's entries.
954 ret = _bt_ctf_get_int_byte_order(self._fd)
956 return ByteOrder.BYTE_ORDER_LITTLE_ENDIAN
958 return ByteOrder.BYTE_ORDER_BIG_ENDIAN
960 return ByteOrder.BYTE_ORDER_UNKNOWN
965 Return the size, in bits, of an int or a negative
968 return _bt_ctf_get_int_len(self._fd)
973 Return the encoding. One of class CTFStringEncoding's entries.
974 Return a negative value on error.
976 return _bt_ctf_get_encoding(self._fd)
978 class EnumerationFieldDeclaration(FieldDeclaration):
979 """Do not instantiate."""
981 raise NotImplementedError("EnumerationFieldDeclaration cannot be instantiated")
983 class ArrayFieldDeclaration(FieldDeclaration):
984 """Do not instantiate."""
986 raise NotImplementedError("ArrayFieldDeclaration cannot be instantiated")
991 Return the length of an array or a negative
994 return _bt_ctf_get_array_len(self._fd)
997 def element_declaration(self):
999 Return element declaration.
1001 field_decl_ptr = _bt_python_get_array_element_declaration(self._fd)
1002 return _create_field_declaration(field_decl_ptr, "", self.scope)
1004 class SequenceFieldDeclaration(FieldDeclaration):
1005 """Do not instantiate."""
1007 raise NotImplementedError("SequenceFieldDeclaration cannot be instantiated")
1010 def element_declaration(self):
1012 Return element declaration.
1014 field_decl_ptr = _bt_python_get_sequence_element_declaration(self._fd)
1015 return _create_field_declaration(field_decl_ptr, "", self.scope)
1017 class FloatFieldDeclaration(FieldDeclaration):
1018 """Do not instantiate."""
1020 raise NotImplementedError("FloatFieldDeclaration cannot be instantiated")
1022 class StructureFieldDeclaration(FieldDeclaration):
1023 """Do not instantiate."""
1025 raise NotImplementedError("StructureFieldDeclaration cannot be instantiated")
1027 class StringFieldDeclaration(FieldDeclaration):
1028 """Do not instantiate."""
1030 raise NotImplementedError("StringFieldDeclaration cannot be instantiated")
1032 class VariantFieldDeclaration(FieldDeclaration):
1033 """Do not instantiate."""
1035 raise NotImplementedError("VariantFieldDeclaration cannot be instantiated")
1039 Return the last error code encountered while
1040 accessing a field and reset the error flag.
1041 Return 0 if no error, a negative value otherwise.
1043 return _bt_ctf_field_get_error()
1045 def _create_field_declaration(declaration_ptr, name, scope):
1047 Private field declaration factory.
1049 if declaration_ptr is None:
1050 raise ValueError("declaration_ptr must be valid")
1051 if not scope in _scopes:
1052 raise ValueError("Invalid scope provided")
1054 type = _bt_ctf_field_type(declaration_ptr)
1056 if type == CTFTypeId.INTEGER:
1057 declaration = IntegerFieldDeclaration.__new__(IntegerFieldDeclaration)
1058 elif type == CTFTypeId.ENUM:
1059 declaration = EnumerationFieldDeclaration.__new__(EnumerationFieldDeclaration)
1060 elif type == CTFTypeId.ARRAY:
1061 declaration = ArrayFieldDeclaration.__new__(ArrayFieldDeclaration)
1062 elif type == CTFTypeId.SEQUENCE:
1063 declaration = SequenceFieldDeclaration.__new__(SequenceFieldDeclaration)
1064 elif type == CTFTypeId.FLOAT:
1065 declaration = FloatFieldDeclaration.__new__(FloatFieldDeclaration)
1066 elif type == CTFTypeId.STRUCT:
1067 declaration = StructureFieldDeclaration.__new__(StructureFieldDeclaration)
1068 elif type == CTFTypeId.STRING:
1069 declaration = StringFieldDeclaration.__new__(StringFieldDeclaration)
1070 elif type == CTFTypeId.VARIANT:
1071 declaration = VariantFieldDeclaration.__new__(VariantFieldDeclaration)
1075 declaration._fd = declaration_ptr
1076 declaration._s = scope
1077 declaration._name = name
1080 class _Definition(object):
1081 def __init__(self, definition_ptr, scope):
1082 self._d = definition_ptr
1084 if not scope in _scopes:
1085 ValueError("Invalid scope provided")
1089 """Return the name of a field or None on error."""
1090 return _bt_ctf_field_name(self._d)
1094 """Return the type of a field or -1 if unknown."""
1095 return _bt_ctf_field_type(_bt_ctf_get_decl_from_def(self._d))
1098 def declaration(self):
1099 """Return the associated Definition object."""
1100 return _create_field_declaration(_bt_ctf_get_decl_from_def(self._d), self.name, self.scope)
1102 def _get_enum_str(self):
1104 Return the string matching the current enumeration.
1105 Return None on error.
1107 return _bt_ctf_get_enum_str(self._d)
1109 def _get_array_element_at(self, index):
1111 Return the array's element at position index.
1112 Return None on error
1114 array_ptr = _bt_python_get_array_from_def(self._d)
1115 if array_ptr is None:
1118 definition_ptr = _bt_array_index(array_ptr, index)
1119 if definition_ptr is None:
1121 return _Definition(definition_ptr, self.scope)
1123 def _get_sequence_len(self):
1125 Return the len of a sequence or a negative
1128 seq = _bt_python_get_sequence_from_def(self._d)
1129 return _bt_sequence_len(seq)
1131 def _get_sequence_element_at(self, index):
1133 Return the sequence's element at position index,
1134 otherwise return None
1136 seq = _bt_python_get_sequence_from_def(self._d)
1138 definition_ptr = _bt_sequence_index(seq, index)
1139 if definition_ptr is not None:
1140 return _Definition(definition_ptr, self.scope)
1143 def _get_uint64(self):
1145 Return the value associated with the field.
1146 If the field does not exist or is not of the type requested,
1147 the value returned is undefined. To check if an error occured,
1148 use the field_error() function after accessing a field.
1150 return _bt_ctf_get_uint64(self._d)
1152 def _get_int64(self):
1154 Return the value associated with the field.
1155 If the field does not exist or is not of the type requested,
1156 the value returned is undefined. To check if an error occured,
1157 use the field_error() function after accessing a field.
1159 return _bt_ctf_get_int64(self._d)
1161 def _get_char_array(self):
1163 Return the value associated with the field.
1164 If the field does not exist or is not of the type requested,
1165 the value returned is undefined. To check if an error occurred,
1166 use the field_error() function after accessing a field.
1168 return _bt_ctf_get_char_array(self._d)
1172 Return the value associated with the field.
1173 If the field does not exist or is not of the type requested,
1174 the value returned is undefined. To check if an error occurred,
1175 use the field_error() function after accessing a field.
1177 return _bt_ctf_get_string(self._d)
1179 def _get_float(self):
1181 Return the value associated with the field.
1182 If the field does not exist or is not of the type requested,
1183 the value returned is undefined. To check if an error occurred,
1184 use the field_error() function after accessing a field.
1186 return _bt_ctf_get_float(self._d)
1188 def _get_variant(self):
1190 Return the variant's selected field.
1191 If the field does not exist or is not of the type requested,
1192 the value returned is undefined. To check if an error occurred,
1193 use the field_error() function after accessing a field.
1195 return _bt_ctf_get_variant(self._d)
1197 def _get_struct_field_count(self):
1199 Return the number of fields contained in the structure.
1200 If the field does not exist or is not of the type requested,
1201 the value returned is undefined.
1203 return _bt_ctf_get_struct_field_count(self._d)
1205 def _get_struct_field_at(self, i):
1207 Return the structure's field at position i.
1208 If the field does not exist or is not of the type requested,
1209 the value returned is undefined. To check if an error occurred,
1210 use the field_error() function after accessing a field.
1212 return _bt_ctf_get_struct_field_index(self._d, i)
1217 Return the value associated with the field according to its type.
1218 Return None on error.
1223 if id == CTFTypeId.STRING:
1224 value = self._get_str()
1225 elif id == CTFTypeId.ARRAY:
1226 element_decl = self.declaration.element_declaration
1227 if ((element_decl.type == CTFTypeId.INTEGER
1228 and element_decl.length == 8)
1229 and (element_decl.encoding == CTFStringEncoding.ASCII or element_decl.encoding == CTFStringEncoding.UTF8)):
1230 value = _bt_python_get_array_string(self._d)
1233 for i in range(self.declaration.length):
1234 element = self._get_array_element_at(i)
1235 value.append(element.value)
1236 elif id == CTFTypeId.INTEGER:
1237 if self.declaration.signedness == 0:
1238 value = self._get_uint64()
1240 value = self._get_int64()
1241 elif id == CTFTypeId.ENUM:
1242 value = self._get_enum_str()
1243 elif id == CTFTypeId.SEQUENCE:
1244 element_decl = self.declaration.element_declaration
1245 if ((element_decl.type == CTFTypeId.INTEGER
1246 and element_decl.length == 8)
1247 and (element_decl.encoding == CTFStringEncoding.ASCII or element_decl.encoding == CTFStringEncoding.UTF8)):
1248 value = _bt_python_get_sequence_string(self._d)
1250 seq_len = self._get_sequence_len()
1252 for i in range(seq_len):
1253 evDef = self._get_sequence_element_at(i)
1254 value.append(evDef.value)
1255 elif id == CTFTypeId.FLOAT:
1256 value = self._get_float()
1257 elif id == CTFTypeId.VARIANT:
1258 variant = _Definition.__new__(_Definition)
1259 variant._d = self._get_variant();
1260 value = variant.value
1261 elif id == CTFTypeId.STRUCT:
1263 for i in range(self._get_struct_field_count()):
1264 member = _Definition(self._get_struct_field_at(i), self.scope)
1265 value[member.name] = member.value
1268 raise FieldError("Error occurred while accessing field {} of type {}".format(self.name, CTFTypeId.type_name(id)))
1273 """Return the scope of a field or None on error."""
1279 // =================================================================
1281 // =================================================================
1283 /* =================================================================
1285 ¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯
1287 %rename("_bt_ctf_clock_create") bt_ctf_clock_create(const char *name);
1288 %rename("_bt_ctf_clock_get_name") bt_ctf_clock_get_name(struct bt_ctf_clock *clock);
1289 %rename("_bt_ctf_clock_get_description") bt_ctf_clock_get_description(struct bt_ctf_clock *clock);
1290 %rename("_bt_ctf_clock_set_description") bt_ctf_clock_set_description(struct bt_ctf_clock *clock, const char *desc);
1291 %rename("_bt_ctf_clock_get_frequency") bt_ctf_clock_get_frequency(struct bt_ctf_clock *clock);
1292 %rename("_bt_ctf_clock_set_frequency") bt_ctf_clock_set_frequency(struct bt_ctf_clock *clock, uint64_t freq);
1293 %rename("_bt_ctf_clock_get_precision") bt_ctf_clock_get_precision(struct bt_ctf_clock *clock);
1294 %rename("_bt_ctf_clock_set_precision") bt_ctf_clock_set_precision(struct bt_ctf_clock *clock, uint64_t precision);
1295 %rename("_bt_ctf_clock_get_offset_s") bt_ctf_clock_get_offset_s(struct bt_ctf_clock *clock);
1296 %rename("_bt_ctf_clock_set_offset_s") bt_ctf_clock_set_offset_s(struct bt_ctf_clock *clock, uint64_t offset_s);
1297 %rename("_bt_ctf_clock_get_offset") bt_ctf_clock_get_offset(struct bt_ctf_clock *clock);
1298 %rename("_bt_ctf_clock_set_offset") bt_ctf_clock_set_offset(struct bt_ctf_clock *clock, uint64_t offset);
1299 %rename("_bt_ctf_clock_get_is_absolute") bt_ctf_clock_get_is_absolute(struct bt_ctf_clock *clock);
1300 %rename("_bt_ctf_clock_set_is_absolute") bt_ctf_clock_set_is_absolute(struct bt_ctf_clock *clock, int is_absolute);
1301 %rename("_bt_ctf_clock_get_time") bt_ctf_clock_get_time(struct bt_ctf_clock *clock);
1302 %rename("_bt_ctf_clock_set_time") bt_ctf_clock_set_time(struct bt_ctf_clock *clock, uint64_t time);
1303 %rename("_bt_ctf_clock_get") bt_ctf_clock_get(struct bt_ctf_clock *clock);
1304 %rename("_bt_ctf_clock_put") bt_ctf_clock_put(struct bt_ctf_clock *clock);
1306 struct bt_ctf_clock *bt_ctf_clock_create(const char *name);
1307 const char *bt_ctf_clock_get_name(struct bt_ctf_clock *clock);
1308 const char *bt_ctf_clock_get_description(struct bt_ctf_clock *clock);
1309 int bt_ctf_clock_set_description(struct bt_ctf_clock *clock, const char *desc);
1310 uint64_t bt_ctf_clock_get_frequency(struct bt_ctf_clock *clock);
1311 int bt_ctf_clock_set_frequency(struct bt_ctf_clock *clock, uint64_t freq);
1312 uint64_t bt_ctf_clock_get_precision(struct bt_ctf_clock *clock);
1313 int bt_ctf_clock_set_precision(struct bt_ctf_clock *clock, uint64_t precision);
1314 uint64_t bt_ctf_clock_get_offset_s(struct bt_ctf_clock *clock);
1315 int bt_ctf_clock_set_offset_s(struct bt_ctf_clock *clock, uint64_t offset_s);
1316 uint64_t bt_ctf_clock_get_offset(struct bt_ctf_clock *clock);
1317 int bt_ctf_clock_set_offset(struct bt_ctf_clock *clock, uint64_t offset);
1318 int bt_ctf_clock_get_is_absolute(struct bt_ctf_clock *clock);
1319 int bt_ctf_clock_set_is_absolute(struct bt_ctf_clock *clock, int is_absolute);
1320 uint64_t bt_ctf_clock_get_time(struct bt_ctf_clock *clock);
1321 int bt_ctf_clock_set_time(struct bt_ctf_clock *clock, uint64_t time);
1322 void bt_ctf_clock_get(struct bt_ctf_clock *clock);
1323 void bt_ctf_clock_put(struct bt_ctf_clock *clock);
1325 /* =================================================================
1327 ¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯
1329 %rename("_bt_ctf_field_type_integer_create") bt_ctf_field_type_integer_create(unsigned int size);
1330 %rename("_bt_ctf_field_type_integer_get_size") bt_ctf_field_type_integer_get_size(struct bt_ctf_field_type *integer);
1331 %rename("_bt_ctf_field_type_integer_get_signed") bt_ctf_field_type_integer_get_signed(struct bt_ctf_field_type *integer);
1332 %rename("_bt_ctf_field_type_integer_set_signed") bt_ctf_field_type_integer_set_signed(struct bt_ctf_field_type *integer, int is_signed);
1333 %rename("_bt_ctf_field_type_integer_get_base") bt_ctf_field_type_integer_get_base(struct bt_ctf_field_type *integer);
1334 %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);
1335 %rename("_bt_ctf_field_type_integer_get_encoding") bt_ctf_field_type_integer_get_encoding(struct bt_ctf_field_type *integer);
1336 %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);
1337 %rename("_bt_ctf_field_type_enumeration_create") bt_ctf_field_type_enumeration_create(struct bt_ctf_field_type *integer_container_type);
1338 %rename("_bt_ctf_field_type_enumeration_get_container_type") bt_ctf_field_type_enumeration_get_container_type(struct bt_ctf_field_type *enumeration);
1339 %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);
1340 %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);
1341 %rename("_bt_ctf_field_type_enumeration_get_mapping_count") bt_ctf_field_type_enumeration_get_mapping_count(struct bt_ctf_field_type *enumeration);
1342 %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);
1343 %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);
1344 %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);
1345 %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);
1346 %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);
1347 %rename("_bt_ctf_field_type_floating_point_create") bt_ctf_field_type_floating_point_create(void);
1348 %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);
1349 %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);
1350 %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);
1351 %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);
1352 %rename("_bt_ctf_field_type_structure_create") bt_ctf_field_type_structure_create(void);
1353 %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);
1354 %rename("_bt_ctf_field_type_structure_get_field_count") bt_ctf_field_type_structure_get_field_count(struct bt_ctf_field_type *structure);
1355 %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);
1356 %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);
1357 %rename("_bt_ctf_field_type_variant_create") bt_ctf_field_type_variant_create(struct bt_ctf_field_type *enum_tag, const char *tag_name);
1358 %rename("_bt_ctf_field_type_variant_get_tag_type") bt_ctf_field_type_variant_get_tag_type(struct bt_ctf_field_type *variant);
1359 %rename("_bt_ctf_field_type_variant_get_tag_name") bt_ctf_field_type_variant_get_tag_name(struct bt_ctf_field_type *variant);
1360 %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);
1361 %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);
1362 %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);
1363 %rename("_bt_ctf_field_type_variant_get_field_count") bt_ctf_field_type_variant_get_field_count(struct bt_ctf_field_type *variant);
1364 %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);
1365 %rename("_bt_ctf_field_type_array_create") bt_ctf_field_type_array_create(struct bt_ctf_field_type *element_type, unsigned int length);
1366 %rename("_bt_ctf_field_type_array_get_element_type") bt_ctf_field_type_array_get_element_type(struct bt_ctf_field_type *array);
1367 %rename("_bt_ctf_field_type_array_get_length") bt_ctf_field_type_array_get_length(struct bt_ctf_field_type *array);
1368 %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);
1369 %rename("_bt_ctf_field_type_sequence_get_element_type") bt_ctf_field_type_sequence_get_element_type(struct bt_ctf_field_type *sequence);
1370 %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);
1371 %rename("_bt_ctf_field_type_string_create") bt_ctf_field_type_string_create(void);
1372 %rename("_bt_ctf_field_type_string_get_encoding") bt_ctf_field_type_string_get_encoding(struct bt_ctf_field_type *string_type);
1373 %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);
1374 %rename("_bt_ctf_field_type_get_alignment") bt_ctf_field_type_get_alignment(struct bt_ctf_field_type *type);
1375 %rename("_bt_ctf_field_type_set_alignment") bt_ctf_field_type_set_alignment(struct bt_ctf_field_type *type, unsigned int alignment);
1376 %rename("_bt_ctf_field_type_get_byte_order") bt_ctf_field_type_get_byte_order(struct bt_ctf_field_type *type);
1377 %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);
1378 %rename("_bt_ctf_field_type_get_type_id") bt_ctf_field_type_get_type_id(struct bt_ctf_field_type *type);
1379 %rename("_bt_ctf_field_type_get") bt_ctf_field_type_get(struct bt_ctf_field_type *type);
1380 %rename("_bt_ctf_field_type_put") bt_ctf_field_type_put(struct bt_ctf_field_type *type);
1382 struct bt_ctf_field_type *bt_ctf_field_type_integer_create(unsigned int size);
1383 int bt_ctf_field_type_integer_get_size(struct bt_ctf_field_type *integer);
1384 int bt_ctf_field_type_integer_get_signed(struct bt_ctf_field_type *integer);
1385 int bt_ctf_field_type_integer_set_signed(struct bt_ctf_field_type *integer, int is_signed);
1386 enum bt_ctf_integer_base bt_ctf_field_type_integer_get_base(struct bt_ctf_field_type *integer);
1387 int bt_ctf_field_type_integer_set_base(struct bt_ctf_field_type *integer, enum bt_ctf_integer_base base);
1388 enum ctf_string_encoding bt_ctf_field_type_integer_get_encoding(struct bt_ctf_field_type *integer);
1389 int bt_ctf_field_type_integer_set_encoding(struct bt_ctf_field_type *integer, enum ctf_string_encoding encoding);
1390 struct bt_ctf_field_type *bt_ctf_field_type_enumeration_create(struct bt_ctf_field_type *integer_container_type);
1391 struct bt_ctf_field_type *bt_ctf_field_type_enumeration_get_container_type(struct bt_ctf_field_type *enumeration);
1392 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);
1393 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);
1394 int64_t bt_ctf_field_type_enumeration_get_mapping_count(struct bt_ctf_field_type *enumeration);
1395 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);
1396 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);
1397 int bt_ctf_field_type_enumeration_get_mapping_index_by_name(struct bt_ctf_field_type *enumeration, const char *name, size_t *OUTPUT);
1398 int bt_ctf_field_type_enumeration_get_mapping_index_by_value(struct bt_ctf_field_type *enumeration, int64_t value, size_t *OUTPUT);
1399 int bt_ctf_field_type_enumeration_get_mapping_index_by_unsigned_value(struct bt_ctf_field_type *enumeration, uint64_t value, size_t *OUTPUT);
1400 struct bt_ctf_field_type *bt_ctf_field_type_floating_point_create(void);
1401 int bt_ctf_field_type_floating_point_get_exponent_digits(struct bt_ctf_field_type *floating_point);
1402 int bt_ctf_field_type_floating_point_set_exponent_digits(struct bt_ctf_field_type *floating_point, unsigned int exponent_digits);
1403 int bt_ctf_field_type_floating_point_get_mantissa_digits(struct bt_ctf_field_type *floating_point);
1404 int bt_ctf_field_type_floating_point_set_mantissa_digits(struct bt_ctf_field_type *floating_point, unsigned int mantissa_digits);
1405 struct bt_ctf_field_type *bt_ctf_field_type_structure_create(void);
1406 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);
1407 int64_t bt_ctf_field_type_structure_get_field_count(struct bt_ctf_field_type *structure);
1408 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);
1409 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);
1410 struct bt_ctf_field_type *bt_ctf_field_type_variant_create(struct bt_ctf_field_type *enum_tag, const char *tag_name);
1411 struct bt_ctf_field_type *bt_ctf_field_type_variant_get_tag_type(struct bt_ctf_field_type *variant);
1412 const char *bt_ctf_field_type_variant_get_tag_name(struct bt_ctf_field_type *variant);
1413 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);
1414 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);
1415 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);
1416 int64_t bt_ctf_field_type_variant_get_field_count(struct bt_ctf_field_type *variant);
1417 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);
1418 struct bt_ctf_field_type *bt_ctf_field_type_array_create(struct bt_ctf_field_type *element_type, unsigned int length);
1419 struct bt_ctf_field_type *bt_ctf_field_type_array_get_element_type(struct bt_ctf_field_type *array);
1420 int64_t bt_ctf_field_type_array_get_length(struct bt_ctf_field_type *array);
1421 struct bt_ctf_field_type *bt_ctf_field_type_sequence_create(struct bt_ctf_field_type *element_type, const char *length_field_name);
1422 struct bt_ctf_field_type *bt_ctf_field_type_sequence_get_element_type(struct bt_ctf_field_type *sequence);
1423 const char *bt_ctf_field_type_sequence_get_length_field_name(struct bt_ctf_field_type *sequence);
1424 struct bt_ctf_field_type *bt_ctf_field_type_string_create(void);
1425 enum ctf_string_encoding bt_ctf_field_type_string_get_encoding(struct bt_ctf_field_type *string_type);
1426 int bt_ctf_field_type_string_set_encoding(struct bt_ctf_field_type *string_type, enum ctf_string_encoding encoding);
1427 int bt_ctf_field_type_get_alignment(struct bt_ctf_field_type *type);
1428 int bt_ctf_field_type_set_alignment(struct bt_ctf_field_type *type, unsigned int alignment);
1429 enum bt_ctf_byte_order bt_ctf_field_type_get_byte_order(struct bt_ctf_field_type *type);
1430 int bt_ctf_field_type_set_byte_order(struct bt_ctf_field_type *type, enum bt_ctf_byte_order byte_order);
1431 enum ctf_type_id bt_ctf_field_type_get_type_id(struct bt_ctf_field_type *type);
1432 void bt_ctf_field_type_get(struct bt_ctf_field_type *type);
1433 void bt_ctf_field_type_put(struct bt_ctf_field_type *type);
1435 /* =================================================================
1437 ¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯
1439 %rename("_bt_ctf_field_create") bt_ctf_field_create(struct bt_ctf_field_type *type);
1440 %rename("_bt_ctf_field_structure_get_field") bt_ctf_field_structure_get_field(struct bt_ctf_field *structure, const char *name);
1441 %rename("_bt_ctf_field_array_get_field") bt_ctf_field_array_get_field(struct bt_ctf_field *array, uint64_t index);
1442 %rename("_bt_ctf_field_sequence_get_length") bt_ctf_field_sequence_get_length(struct bt_ctf_field *sequence);
1443 %rename("_bt_ctf_field_sequence_set_length") bt_ctf_field_sequence_set_length(struct bt_ctf_field *sequence, struct bt_ctf_field *length_field);
1444 %rename("_bt_ctf_field_sequence_get_field") bt_ctf_field_sequence_get_field(struct bt_ctf_field *sequence, uint64_t index);
1445 %rename("_bt_ctf_field_variant_get_field") bt_ctf_field_variant_get_field(struct bt_ctf_field *variant, struct bt_ctf_field *tag);
1446 %rename("_bt_ctf_field_enumeration_get_container") bt_ctf_field_enumeration_get_container(struct bt_ctf_field *enumeration);
1447 %rename("_bt_ctf_field_enumeration_get_mapping_name") bt_ctf_field_enumeration_get_mapping_name(struct bt_ctf_field *enumeration);
1448 %rename("_bt_ctf_field_signed_integer_get_value") bt_ctf_field_signed_integer_get_value(struct bt_ctf_field *integer, int64_t *value);
1449 %rename("_bt_ctf_field_signed_integer_set_value") bt_ctf_field_signed_integer_set_value(struct bt_ctf_field *integer, int64_t value);
1450 %rename("_bt_ctf_field_unsigned_integer_get_value") bt_ctf_field_unsigned_integer_get_value(struct bt_ctf_field *integer, uint64_t *value);
1451 %rename("_bt_ctf_field_unsigned_integer_set_value") bt_ctf_field_unsigned_integer_set_value(struct bt_ctf_field *integer, uint64_t value);
1452 %rename("_bt_ctf_field_floating_point_get_value") bt_ctf_field_floating_point_get_value(struct bt_ctf_field *floating_point, double *value);
1453 %rename("_bt_ctf_field_floating_point_set_value") bt_ctf_field_floating_point_set_value(struct bt_ctf_field *floating_point, double value);
1454 %rename("_bt_ctf_field_string_get_value") bt_ctf_field_string_get_value(struct bt_ctf_field *string_field);
1455 %rename("_bt_ctf_field_string_set_value") bt_ctf_field_string_set_value(struct bt_ctf_field *string_field, const char *value);
1456 %rename("_bt_ctf_field_get_type") bt_ctf_field_get_type(struct bt_ctf_field *field);
1457 %rename("_bt_ctf_field_get") bt_ctf_field_get(struct bt_ctf_field *field);
1458 %rename("_bt_ctf_field_put") bt_ctf_field_put(struct bt_ctf_field *field);
1460 struct bt_ctf_field *bt_ctf_field_create(struct bt_ctf_field_type *type);
1461 struct bt_ctf_field *bt_ctf_field_structure_get_field(struct bt_ctf_field *structure, const char *name);
1462 struct bt_ctf_field *bt_ctf_field_array_get_field(struct bt_ctf_field *array, uint64_t index);
1463 struct bt_ctf_field * bt_ctf_field_sequence_get_length(struct bt_ctf_field *sequence);
1464 int bt_ctf_field_sequence_set_length(struct bt_ctf_field *sequence, struct bt_ctf_field *length_field);
1465 struct bt_ctf_field *bt_ctf_field_sequence_get_field(struct bt_ctf_field *sequence, uint64_t index);
1466 struct bt_ctf_field *bt_ctf_field_variant_get_field(struct bt_ctf_field *variant, struct bt_ctf_field *tag);
1467 struct bt_ctf_field *bt_ctf_field_enumeration_get_container(struct bt_ctf_field *enumeration);
1468 const char *bt_ctf_field_enumeration_get_mapping_name(struct bt_ctf_field *enumeration);
1469 int bt_ctf_field_signed_integer_get_value(struct bt_ctf_field *integer, int64_t *OUTPUT);
1470 int bt_ctf_field_signed_integer_set_value(struct bt_ctf_field *integer, int64_t value);
1471 int bt_ctf_field_unsigned_integer_get_value(struct bt_ctf_field *integer, uint64_t *OUTPUT);
1472 int bt_ctf_field_unsigned_integer_set_value(struct bt_ctf_field *integer, uint64_t value);
1473 int bt_ctf_field_floating_point_get_value(struct bt_ctf_field *floating_point, double *OUTPUT);
1474 int bt_ctf_field_floating_point_set_value(struct bt_ctf_field *floating_point, double value);
1475 const char *bt_ctf_field_string_get_value(struct bt_ctf_field *string_field);
1476 int bt_ctf_field_string_set_value(struct bt_ctf_field *string_field, const char *value);
1477 struct bt_ctf_field_type *bt_ctf_field_get_type(struct bt_ctf_field *field);
1478 void bt_ctf_field_get(struct bt_ctf_field *field);
1479 void bt_ctf_field_put(struct bt_ctf_field *field);
1481 /* =================================================================
1483 ¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯
1485 %rename("_bt_ctf_event_class_create") bt_ctf_event_class_create(const char *name);
1486 %rename("_bt_ctf_event_class_get_name") bt_ctf_event_class_get_name(struct bt_ctf_event_class *event_class);
1487 %rename("_bt_ctf_event_class_get_id") bt_ctf_event_class_get_id(struct bt_ctf_event_class *event_class);
1488 %rename("_bt_ctf_event_class_set_id") bt_ctf_event_class_set_id(struct bt_ctf_event_class *event_class, uint32_t id);
1489 %rename("_bt_ctf_event_class_get_stream_class") bt_ctf_event_class_get_stream_class(struct bt_ctf_event_class *event_class);
1490 %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);
1491 %rename("_bt_ctf_event_class_get_field_count") bt_ctf_event_class_get_field_count(struct bt_ctf_event_class *event_class);
1492 %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);
1493 %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);
1494 %rename("_bt_ctf_event_class_get") bt_ctf_event_class_get(struct bt_ctf_event_class *event_class);
1495 %rename("_bt_ctf_event_class_put") bt_ctf_event_class_put(struct bt_ctf_event_class *event_class);
1496 %rename("_bt_ctf_event_create") bt_ctf_event_create(struct bt_ctf_event_class *event_class);
1497 %rename("_bt_ctf_event_get_class") bt_ctf_event_get_class(struct bt_ctf_event *event);
1498 %rename("_bt_ctf_event_get_clock") bt_ctf_event_get_clock(struct bt_ctf_event *event);
1499 %rename("_bt_ctf_event_get_payload") bt_ctf_event_get_payload(struct bt_ctf_event *event, const char *name);
1500 %rename("_bt_ctf_event_set_payload") bt_ctf_event_set_payload(struct bt_ctf_event *event, const char *name, struct bt_ctf_field *value);
1501 %rename("_bt_ctf_event_get_payload_by_index") bt_ctf_event_get_payload_by_index(struct bt_ctf_event *event, size_t index);
1502 %rename("_bt_ctf_event_get") bt_ctf_event_get(struct bt_ctf_event *event);
1503 %rename("_bt_ctf_event_put") bt_ctf_event_put(struct bt_ctf_event *event);
1505 struct bt_ctf_event_class *bt_ctf_event_class_create(const char *name);
1506 const char *bt_ctf_event_class_get_name(struct bt_ctf_event_class *event_class);
1507 int64_t bt_ctf_event_class_get_id(struct bt_ctf_event_class *event_class);
1508 int bt_ctf_event_class_set_id(struct bt_ctf_event_class *event_class, uint32_t id);
1509 struct bt_ctf_stream_class *bt_ctf_event_class_get_stream_class(struct bt_ctf_event_class *event_class);
1510 int bt_ctf_event_class_add_field(struct bt_ctf_event_class *event_class, struct bt_ctf_field_type *type, const char *name);
1511 int64_t bt_ctf_event_class_get_field_count(struct bt_ctf_event_class *event_class);
1512 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);
1513 struct bt_ctf_field_type *bt_ctf_event_class_get_field_by_name(struct bt_ctf_event_class *event_class, const char *name);
1514 void bt_ctf_event_class_get(struct bt_ctf_event_class *event_class);
1515 void bt_ctf_event_class_put(struct bt_ctf_event_class *event_class);
1516 struct bt_ctf_event *bt_ctf_event_create(struct bt_ctf_event_class *event_class);
1517 struct bt_ctf_event_class *bt_ctf_event_get_class(struct bt_ctf_event *event);
1518 struct bt_ctf_clock *bt_ctf_event_get_clock(struct bt_ctf_event *event);
1519 struct bt_ctf_field *bt_ctf_event_get_payload(struct bt_ctf_event *event, const char *name);
1520 int bt_ctf_event_set_payload(struct bt_ctf_event *event, const char *name, struct bt_ctf_field *value);
1521 struct bt_ctf_field *bt_ctf_event_get_payload_by_index(struct bt_ctf_event *event, size_t index);
1522 void bt_ctf_event_get(struct bt_ctf_event *event);
1523 void bt_ctf_event_put(struct bt_ctf_event *event);
1525 /* =================================================================
1527 ¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯
1529 %rename("_bt_ctf_stream_class_create") bt_ctf_stream_class_create(const char *name);
1530 %rename("_bt_ctf_stream_class_get_name") bt_ctf_stream_class_get_name(struct bt_ctf_stream_class *stream_class);
1531 %rename("_bt_ctf_stream_class_get_clock") bt_ctf_stream_class_get_clock(struct bt_ctf_stream_class *stream_class);
1532 %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);
1533 %rename("_bt_ctf_stream_class_get_id") bt_ctf_stream_class_get_id(struct bt_ctf_stream_class *stream_class);
1534 %rename("_bt_ctf_stream_class_set_id") bt_ctf_stream_class_set_id(struct bt_ctf_stream_class *stream_class, uint32_t id);
1535 %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);
1536 %rename("_bt_ctf_stream_class_get_event_class_count") bt_ctf_stream_class_get_event_class_count(struct bt_ctf_stream_class *stream_class);
1537 %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);
1538 %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);
1539 %rename("_bt_ctf_stream_class_get") bt_ctf_stream_class_get(struct bt_ctf_stream_class *stream_class);
1540 %rename("_bt_ctf_stream_class_put") bt_ctf_stream_class_put(struct bt_ctf_stream_class *stream_class);
1541 %rename("_bt_ctf_stream_get_discarded_events_count") bt_ctf_stream_get_discarded_events_count(struct bt_ctf_stream *stream, uint64_t *count);
1542 %rename("_bt_ctf_stream_append_discarded_events") bt_ctf_stream_append_discarded_events(struct bt_ctf_stream *stream, uint64_t event_count);
1543 %rename("_bt_ctf_stream_append_event") bt_ctf_stream_append_event(struct bt_ctf_stream *stream, struct bt_ctf_event *event);
1544 %rename("_bt_ctf_stream_flush") bt_ctf_stream_flush(struct bt_ctf_stream *stream);
1545 %rename("_bt_ctf_stream_get") bt_ctf_stream_get(struct bt_ctf_stream *stream);
1546 %rename("_bt_ctf_stream_put") bt_ctf_stream_put(struct bt_ctf_stream *stream);
1548 struct bt_ctf_stream_class *bt_ctf_stream_class_create(const char *name);
1549 const char *bt_ctf_stream_class_get_name(struct bt_ctf_stream_class *stream_class);
1550 struct bt_ctf_clock *bt_ctf_stream_class_get_clock(struct bt_ctf_stream_class *stream_class);
1551 int bt_ctf_stream_class_set_clock(struct bt_ctf_stream_class *stream_class, struct bt_ctf_clock *clock);
1552 int64_t bt_ctf_stream_class_get_id(struct bt_ctf_stream_class *stream_class);
1553 int bt_ctf_stream_class_set_id(struct bt_ctf_stream_class *stream_class, uint32_t id);
1554 int bt_ctf_stream_class_add_event_class(struct bt_ctf_stream_class *stream_class, struct bt_ctf_event_class *event_class);
1555 int64_t bt_ctf_stream_class_get_event_class_count(struct bt_ctf_stream_class *stream_class);
1556 struct bt_ctf_event_class *bt_ctf_stream_class_get_event_class(struct bt_ctf_stream_class *stream_class, size_t index);
1557 struct bt_ctf_event_class *bt_ctf_stream_class_get_event_class_by_name(struct bt_ctf_stream_class *stream_class, const char *name);
1558 void bt_ctf_stream_class_get(struct bt_ctf_stream_class *stream_class);
1559 void bt_ctf_stream_class_put(struct bt_ctf_stream_class *stream_class);
1560 int bt_ctf_stream_get_discarded_events_count(struct bt_ctf_stream *stream, uint64_t *OUTPUT);
1561 void bt_ctf_stream_append_discarded_events(struct bt_ctf_stream *stream, uint64_t event_count);
1562 int bt_ctf_stream_append_event(struct bt_ctf_stream *stream, struct bt_ctf_event *event);
1563 int bt_ctf_stream_flush(struct bt_ctf_stream *stream);
1564 void bt_ctf_stream_get(struct bt_ctf_stream *stream);
1565 void bt_ctf_stream_put(struct bt_ctf_stream *stream);
1567 /* =================================================================
1569 ¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯
1571 %rename("_bt_ctf_writer_create") bt_ctf_writer_create(const char *path);
1572 %rename("_bt_ctf_writer_create_stream") bt_ctf_writer_create_stream(struct bt_ctf_writer *writer, struct bt_ctf_stream_class *stream_class);
1573 %rename("_bt_ctf_writer_add_environment_field") bt_ctf_writer_add_environment_field(struct bt_ctf_writer *writer, const char *name, const char *value);
1574 %rename("_bt_ctf_writer_add_clock") bt_ctf_writer_add_clock(struct bt_ctf_writer *writer, struct bt_ctf_clock *clock);
1575 %newobject bt_ctf_writer_get_metadata_string;
1576 %rename("_bt_ctf_writer_get_metadata_string") bt_ctf_writer_get_metadata_string(struct bt_ctf_writer *writer);
1577 %rename("_bt_ctf_writer_flush_metadata") bt_ctf_writer_flush_metadata(struct bt_ctf_writer *writer);
1578 %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);
1579 %rename("_bt_ctf_writer_get") bt_ctf_writer_get(struct bt_ctf_writer *writer);
1580 %rename("_bt_ctf_writer_put") bt_ctf_writer_put(struct bt_ctf_writer *writer);
1582 struct bt_ctf_writer *bt_ctf_writer_create(const char *path);
1583 struct bt_ctf_stream *bt_ctf_writer_create_stream(struct bt_ctf_writer *writer, struct bt_ctf_stream_class *stream_class);
1584 int bt_ctf_writer_add_environment_field(struct bt_ctf_writer *writer, const char *name, const char *value);
1585 int bt_ctf_writer_add_clock(struct bt_ctf_writer *writer, struct bt_ctf_clock *clock);
1586 char *bt_ctf_writer_get_metadata_string(struct bt_ctf_writer *writer);
1587 void bt_ctf_writer_flush_metadata(struct bt_ctf_writer *writer);
1588 int bt_ctf_writer_set_byte_order(struct bt_ctf_writer *writer, enum bt_ctf_byte_order byte_order);
1589 void bt_ctf_writer_get(struct bt_ctf_writer *writer);
1590 void bt_ctf_writer_put(struct bt_ctf_writer *writer);
1596 # Used to compare to -1ULL in error checks
1597 _MAX_UINT64 = 0xFFFFFFFFFFFFFFFF
1600 Enumeration mapping class. start and end values are inclusive.
1602 class EnumerationMapping:
1603 def __init__(self, name, start, end):
1609 def __init__(self, name):
1610 self._c = _bt_ctf_clock_create(name)
1612 raise ValueError("Invalid clock name.")
1615 _bt_ctf_clock_put(self._c)
1618 Get the clock's name.
1622 name = _bt_ctf_clock_get_name(self._c)
1624 raise ValueError("Invalid clock instance.")
1628 Get the clock's description. None if unset.
1631 def description(self):
1632 return _bt_ctf_clock_get_description(self._c)
1635 Set the clock's description. The description appears in the clock's TSDL
1639 def description(self, desc):
1640 ret = _bt_ctf_clock_set_description(self._c, str(desc))
1642 raise ValueError("Invalid clock description.")
1645 Get the clock's frequency (Hz).
1648 def frequency(self):
1649 freq = _bt_ctf_clock_get_frequency(self._c)
1650 if freq == CTFWriter._MAX_UINT64:
1651 raise ValueError("Invalid clock instance")
1655 Set the clock's frequency (Hz).
1658 def frequency(self, freq):
1659 ret = _bt_ctf_clock_set_frequency(self._c, freq)
1661 raise ValueError("Invalid frequency value.")
1664 Get the clock's precision (in clock ticks).
1667 def precision(self):
1668 precision = _bt_ctf_clock_get_precision(self._c)
1669 if precision == CTFWriter._MAX_UINT64:
1670 raise ValueError("Invalid clock instance")
1674 Set the clock's precision (in clock ticks).
1677 def precision(self, precision):
1678 ret = _bt_ctf_clock_set_precision(self._c, precision)
1681 Get the clock's offset in seconds from POSIX.1 Epoch.
1684 def offset_seconds(self):
1685 offset_s = _bt_ctf_clock_get_offset_s(self._c)
1686 if offset_s == CTFWriter._MAX_UINT64:
1687 raise ValueError("Invalid clock instance")
1691 Set the clock's offset in seconds from POSIX.1 Epoch.
1693 @offset_seconds.setter
1694 def offset_seconds(self, offset_s):
1695 ret = _bt_ctf_clock_set_offset_s(self._c, offset_s)
1697 raise ValueError("Invalid offset value.")
1700 Get the clock's offset in ticks from POSIX.1 Epoch + offset in seconds.
1704 offset = _bt_ctf_clock_get_offset(self._c)
1705 if offset == CTFWriter._MAX_UINT64:
1706 raise ValueError("Invalid clock instance")
1710 Set the clock's offset in ticks from POSIX.1 Epoch + offset in seconds.
1713 def offset(self, offset):
1714 ret = _bt_ctf_clock_set_offset(self._c, offset)
1716 raise ValueError("Invalid offset value.")
1719 Get a clock's absolute attribute. A clock is absolute if the clock
1720 is a global reference across the trace's other clocks.
1724 is_absolute = _bt_ctf_clock_get_is_absolute(self._c)
1725 if is_absolute == -1:
1726 raise ValueError("Invalid clock instance")
1727 return False if is_absolute == 0 else True
1730 Set a clock's absolute attribute. A clock is absolute if the clock
1731 is a global reference across the trace's other clocks.
1734 def absolute(self, is_absolute):
1735 ret = _bt_ctf_clock_set_is_absolute(self._c, int(is_absolute))
1737 raise ValueError("Could not set the clock's absolute attribute.")
1740 Get a clock's UUID (an object of type UUID).
1746 ret, value = _bt_python_ctf_clock_get_uuid_index(self._c, i)
1748 raise ValueError("Invalid clock instance")
1749 uuid_list.append(value)
1750 return uuid.UUID(bytes=bytes(uuid_list))
1753 Set a clock's UUID (an object of type UUID).
1756 def uuid(self, uuid):
1757 uuid_bytes = uuid.bytes
1758 if len(uuid_bytes) != 16:
1759 raise ValueError("Invalid UUID provided. UUID length must be 16 bytes")
1760 for i in range(len(uuid_bytes)):
1761 ret = _bt_python_ctf_clock_set_uuid_index(self._c, i, uuid_bytes[i])
1763 raise ValueError("Invalid clock instance")
1766 Get the current time in nanoseconds since the clock's origin (offset and
1767 offset_s attributes).
1771 time = _bt_ctf_clock_get_time(self._c)
1772 if time == CTFWriter._MAX_UINT64:
1773 raise ValueError("Invalid clock instance")
1777 Set the current time in nanoseconds since the clock's origin (offset and
1778 offset_s attributes). The clock's value will be sampled as events are
1779 appended to a stream.
1782 def time(self, time):
1783 ret = _bt_ctf_clock_set_time(self._c, time)
1785 raise ValueError("Invalid time value.")
1787 class FieldDeclaration:
1789 FieldDeclaration should not be instantiated directly. Instantiate
1790 one of the concrete FieldDeclaration classes.
1793 # These values are based on the bt_ctf_integer_base enum
1794 # declared in event-types.h.
1795 INTEGER_BASE_UNKNOWN = -1
1796 INTEGER_BASE_BINARY = 2
1797 INTEGER_BASE_OCTAL = 8
1798 INTEGER_BASE_DECIMAL = 10
1799 INTEGER_BASE_HEXADECIMAL = 16
1802 if self._ft is None:
1803 raise ValueError("FieldDeclaration creation failed.")
1806 _bt_ctf_field_type_put(self._ft)
1809 def _create_field_declaration_from_native_instance(native_field_declaration):
1811 CTFTypeId.INTEGER : CTFWriter.IntegerFieldDeclaration,
1812 CTFTypeId.FLOAT : CTFWriter.FloatFieldDeclaration,
1813 CTFTypeId.ENUM : CTFWriter.EnumerationFieldDeclaration,
1814 CTFTypeId.STRING : CTFWriter.StringFieldDeclaration,
1815 CTFTypeId.STRUCT : CTFWriter.StructureFieldDeclaration,
1816 CTFTypeId.VARIANT : CTFWriter.VariantFieldDeclaration,
1817 CTFTypeId.ARRAY : CTFWriter.ArrayFieldDeclaration,
1818 CTFTypeId.SEQUENCE : CTFWriter.SequenceFieldDeclaration
1821 field_type_id = _bt_ctf_field_type_get_type_id(native_field_declaration)
1822 if field_type_id == CTFTypeId.UNKNOWN:
1823 raise TypeError("Invalid field instance")
1825 declaration = CTFWriter.Field.__new__(CTFWriter.Field)
1826 declaration._ft = native_field_declaration
1827 declaration.__class__ = type_dict[field_type_id]
1831 Get the field declaration's alignment. Returns -1 on error.
1834 def alignment(self):
1835 return _bt_ctf_field_type_get_alignment(self._ft)
1838 Set the field declaration's alignment. Defaults to 1 (bit-aligned). However,
1839 some types, such as structures and string, may impose other alignment
1843 def alignment(self, alignment):
1844 ret = _bt_ctf_field_type_set_alignment(self._ft, alignment)
1846 raise ValueError("Invalid alignment value.")
1849 Get the field declaration's byte order. One of the ByteOrder's constant.
1852 def byte_order(self):
1853 return _bt_ctf_field_type_get_byte_order(self._ft)
1856 Set the field declaration's byte order. Use constants defined in the ByteOrder
1860 def byte_order(self, byte_order):
1861 ret = _bt_ctf_field_type_set_byte_order(self._ft, byte_order)
1863 raise ValueError("Could not set byte order value.")
1865 class IntegerFieldDeclaration(FieldDeclaration):
1867 Create a new integer field declaration of the given size.
1869 def __init__(self, size):
1870 self._ft = _bt_ctf_field_type_integer_create(size)
1874 Get an integer's size.
1878 ret = _bt_ctf_field_type_integer_get_size(self._ft)
1880 raise ValueError("Could not get Integer's size attribute.")
1885 Get an integer's signedness attribute.
1889 ret = _bt_ctf_field_type_integer_get_signed(self._ft)
1891 raise ValueError("Could not get Integer's signed attribute.")
1898 Set an integer's signedness attribute.
1901 def signed(self, signed):
1902 ret = _bt_ctf_field_type_integer_set_signed(self._ft, signed)
1904 raise ValueError("Could not set Integer's signed attribute.")
1907 Get the integer's base used to pretty-print the resulting trace.
1908 Returns a constant from the FieldDeclaration.IntegerBase class.
1912 return _bt_ctf_field_type_integer_get_base(self._ft)
1915 Set the integer's base used to pretty-print the resulting trace.
1916 The base must be a constant of the FieldDeclarationIntegerBase class.
1919 def base(self, base):
1920 ret = _bt_ctf_field_type_integer_set_base(self._ft, base)
1922 raise ValueError("Could not set Integer's base.")
1925 Get the integer's encoding (one of the constants of the
1926 CTFStringEncoding class).
1927 Returns a constant from the CTFStringEncoding class.
1931 return _bt_ctf_field_type_integer_get_encoding(self._ft)
1934 An integer encoding may be set to signal that the integer must be printed
1935 as a text character. Must be a constant from the CTFStringEncoding class.
1938 def encoding(self, encoding):
1939 ret = _bt_ctf_field_type_integer_set_encoding(self._ft, encoding)
1941 raise ValueError("Could not set Integer's encoding.")
1943 class EnumerationFieldDeclaration(FieldDeclaration):
1945 Create a new enumeration field declaration with the given underlying container type.
1947 def __init__(self, integer_type):
1948 if integer_type is None or not isinstance(integer_type, CTFWriter.IntegerFieldDeclaration):
1949 raise TypeError("Invalid integer container.")
1951 self._ft = _bt_ctf_field_type_enumeration_create(integer_type._ft)
1955 Get the enumeration's underlying container type.
1958 def container(self):
1959 ret = _bt_ctf_field_type_enumeration_get_container_type(self._ft)
1961 raise TypeError("Invalid enumeration declaration")
1962 return CTFWriter.FieldDeclaration._create_field_declaration_from_native_instance(ret)
1965 Add a mapping to the enumeration. The range's values are inclusive.
1967 def add_mapping(self, name, range_start, range_end):
1968 if range_start < 0 or range_end < 0:
1969 ret = _bt_ctf_field_type_enumeration_add_mapping(self._ft, str(name), range_start, range_end)
1971 ret = _bt_ctf_field_type_enumeration_add_mapping_unsigned(self._ft, str(name), range_start, range_end)
1974 raise ValueError("Could not add mapping to enumeration declaration.")
1977 Generator returning instances of EnumerationMapping.
1981 signed = self.container.signed
1983 count = _bt_ctf_field_type_enumeration_get_mapping_count(self._ft)
1984 for i in range(count):
1986 ret = _bt_python_ctf_field_type_enumeration_get_mapping(self._ft, i)
1988 ret = _bt_python_ctf_field_type_enumeration_get_mapping_unsigned(self._ft, i)
1991 raise TypeError("Could not get Enumeration mapping at index {}".format(i))
1992 name, range_start, range_end = ret
1993 yield CTFWriter.EnumerationMapping(name, range_start, range_end)
1996 Get a mapping by name (EnumerationMapping).
1998 def get_mapping_by_name(self, name):
1999 ret, index = _bt_ctf_field_type_enumeration_get_mapping_index_by_name(self._ft, name);
2003 if self.container.signed:
2004 ret = _bt_python_ctf_field_type_enumeration_get_mapping(self._ft, index)
2006 ret = _bt_python_ctf_field_type_enumeration_get_mapping_unsigned(self._ft, index)
2009 raise TypeError("Could not get Enumeration mapping at index {}".format(i))
2010 name, range_start, range_end = ret
2011 return CTFWriter.EnumerationMapping(name, range_start, range_end)
2014 Get a mapping by value (EnumerationMapping).
2016 def get_mapping_by_value(self, value):
2018 ret, index = _bt_ctf_field_type_enumeration_get_mapping_index_by_value(self._ft, value);
2020 ret, index = _bt_ctf_field_type_enumeration_get_mapping_index_by_unsigned_value(self._ft, value);
2025 if self.container.signed:
2026 ret = _bt_python_ctf_field_type_enumeration_get_mapping(self._ft, index)
2028 ret = _bt_python_ctf_field_type_enumeration_get_mapping_unsigned(self._ft, index)
2031 raise TypeError("Could not get Enumeration mapping at index {}".format(i))
2032 name, range_start, range_end = ret
2033 return CTFWriter.EnumerationMapping(name, range_start, range_end)
2035 class FloatFieldDeclaration(FieldDeclaration):
2042 Create a new floating point field declaration.
2045 self._ft = _bt_ctf_field_type_floating_point_create()
2049 Get the number of exponent digits used to store the floating point field.
2052 def exponent_digits(self):
2053 ret = _bt_ctf_field_type_floating_point_get_exponent_digits(self._ft)
2055 raise TypeError("Could not get Floating point exponent digit count")
2059 Set the number of exponent digits to use to store the floating point field.
2060 The only values currently supported are FLT_EXP_DIG and DBL_EXP_DIG which
2061 are defined as constants of this class.
2063 @exponent_digits.setter
2064 def exponent_digits(self, exponent_digits):
2065 ret = _bt_ctf_field_type_floating_point_set_exponent_digits(self._ft, exponent_digits)
2067 raise ValueError("Could not set exponent digit count.")
2070 Get the number of mantissa digits used to store the floating point field.
2073 def mantissa_digits(self):
2074 ret = _bt_ctf_field_type_floating_point_get_mantissa_digits(self._ft)
2076 raise TypeError("Could not get Floating point mantissa digit count")
2080 Set the number of mantissa digits to use to store the floating point field.
2081 The only values currently supported are FLT_MANT_DIG and DBL_MANT_DIG which
2082 are defined as constants of this class.
2084 @mantissa_digits.setter
2085 def mantissa_digits(self, mantissa_digits):
2086 ret = _bt_ctf_field_type_floating_point_set_mantissa_digits(self._ft, mantissa_digits)
2088 raise ValueError("Could not set mantissa digit count.")
2090 class StructureFieldDeclaration(FieldDeclaration):
2092 Create a new structure field declaration.
2095 self._ft = _bt_ctf_field_type_structure_create()
2099 Add a field of type "field_type" to the structure.
2101 def add_field(self, field_type, field_name):
2102 ret = _bt_ctf_field_type_structure_add_field(self._ft, field_type._ft, str(field_name))
2104 raise ValueError("Could not add field to structure.")
2107 Generator returning the structure's field as tuples of (field name, field declaration).
2111 count = _bt_ctf_field_type_structure_get_field_count(self._ft)
2113 raise TypeError("Could not get Structure field count")
2115 for i in range(count):
2116 field_name = _bt_python_ctf_field_type_structure_get_field_name(self._ft, i)
2117 if field_name is None:
2118 raise TypeError("Could not get Structure field name at index {}".format(i))
2120 field_type_native = _bt_python_ctf_field_type_structure_get_field_type(self._ft, i)
2121 if field_type_native is None:
2122 raise TypeError("Could not get Structure field type at index {}".format(i))
2124 field_type = CTFWriter.FieldDeclaration._create_field_declaration_from_native_instance(field_type_native)
2125 yield (field_name, field_type)
2128 Get a field declaration by name (FieldDeclaration).
2130 def get_field_by_name(self, name):
2131 field_type_native = _bt_ctf_field_type_structure_get_field_type_by_name(self._ft, name)
2132 if field_type_native is None:
2133 raise TypeError("Could not find Structure field with name {}".format(name))
2135 return CTFWriter.FieldDeclaration._create_field_declaration_from_native_instance(field_type_native)
2137 class VariantFieldDeclaration(FieldDeclaration):
2139 Create a new variant field declaration.
2141 def __init__(self, enum_tag, tag_name):
2142 if enum_tag is None or not isinstance(enum_tag, CTFWriter.EnumerationFieldDeclaration):
2143 raise TypeError("Invalid tag type; must be of type EnumerationFieldDeclaration.")
2145 self._ft = _bt_ctf_field_type_variant_create(enum_tag._ft, str(tag_name))
2149 Get the variant's tag name.
2153 ret = _bt_ctf_field_type_variant_get_tag_name(self._ft)
2155 raise TypeError("Could not get Variant tag name")
2159 Get the variant's tag type.
2163 ret = _bt_ctf_field_type_variant_get_tag_type(self._ft)
2165 raise TypeError("Could not get Variant tag type")
2166 return CTFWriter.FieldDeclaration._create_field_declaration_from_native_instance(ret)
2169 Add a field of type "field_type" to the variant.
2171 def add_field(self, field_type, field_name):
2172 ret = _bt_ctf_field_type_variant_add_field(self._ft, field_type._ft, str(field_name))
2174 raise ValueError("Could not add field to variant.")
2177 Generator returning the variant's field as tuples of (field name, field declaration).
2181 count = _bt_ctf_field_type_variant_get_field_count(self._ft)
2183 raise TypeError("Could not get Variant field count")
2185 for i in range(count):
2186 field_name = _bt_python_ctf_field_type_variant_get_field_name(self._ft, i)
2187 if field_name is None:
2188 raise TypeError("Could not get Variant field name at index {}".format(i))
2190 field_type_native = _bt_python_ctf_field_type_variant_get_field_type(self._ft, i)
2191 if field_type_native is None:
2192 raise TypeError("Could not get Variant field type at index {}".format(i))
2194 field_type = CTFWriter.FieldDeclaration._create_field_declaration_from_native_instance(field_type_native)
2195 yield (field_name, field_type)
2198 Get a field declaration by name (FieldDeclaration).
2200 def get_field_by_name(self, name):
2201 field_type_native = _bt_ctf_field_type_variant_get_field_type_by_name(self._ft, name)
2202 if field_type_native is None:
2203 raise TypeError("Could not find Variant field with name {}".format(name))
2205 return CTFWriter.FieldDeclaration._create_field_declaration_from_native_instance(field_type_native)
2208 Get a field declaration from tag (EnumerationField).
2210 def get_field_from_tag(self, tag):
2211 field_type_native = _bt_ctf_field_type_variant_get_field_type_from_tag(self._ft, tag._f)
2212 if field_type_native is None:
2213 raise TypeError("Could not find Variant field with tag value {}".format(tag.value))
2215 return CTFWriter.FieldDeclaration._create_field_declaration_from_native_instance(field_type_native)
2217 class ArrayFieldDeclaration(FieldDeclaration):
2219 Create a new array field declaration.
2221 def __init__(self, element_type, length):
2222 self._ft = _bt_ctf_field_type_array_create(element_type._ft, length)
2226 Get the array's element type.
2229 def element_type(self):
2230 ret = _bt_ctf_field_type_array_get_element_type(self._ft)
2232 raise TypeError("Could not get Array element type")
2233 return CTFWriter.FieldDeclaration._create_field_declaration_from_native_instance(ret)
2236 Get the array's length.
2240 ret = _bt_ctf_field_type_array_get_length(self._ft)
2242 raise TypeError("Could not get Array length")
2245 class SequenceFieldDeclaration(FieldDeclaration):
2247 Create a new sequence field declaration.
2249 def __init__(self, element_type, length_field_name):
2250 self._ft = _bt_ctf_field_type_sequence_create(element_type._ft, str(length_field_name))
2254 Get the sequence's element type.
2257 def element_type(self):
2258 ret = _bt_ctf_field_type_sequence_get_element_type(self._ft)
2260 raise TypeError("Could not get Sequence element type")
2261 return CTFWriter.FieldDeclaration._create_field_declaration_from_native_instance(ret)
2264 Get the sequence's length field name.
2267 def length_field_name(self):
2268 ret = _bt_ctf_field_type_sequence_get_length_field_name(self._ft)
2270 raise TypeError("Could not get Sequence length field name")
2273 class StringFieldDeclaration(FieldDeclaration):
2275 Create a new string field declaration.
2278 self._ft = _bt_ctf_field_type_string_create()
2282 Get a string declaration's encoding (a constant from the CTFStringEncoding class).
2286 return _bt_ctf_field_type_string_get_encoding(self._ft)
2289 Set a string declaration's encoding. Must be a constant from the CTFStringEncoding class.
2292 def encoding(self, encoding):
2293 ret = _bt_ctf_field_type_string_set_encoding(self._ft, encoding)
2295 raise ValueError("Could not set string encoding.")
2298 Create an instance of a field.
2301 def create_field(field_type):
2302 if field_type is None or not isinstance(field_type, CTFWriter.FieldDeclaration):
2303 raise TypeError("Invalid field_type. Type must be a FieldDeclaration-derived class.")
2305 if isinstance(field_type, CTFWriter.IntegerFieldDeclaration):
2306 return CTFWriter.IntegerField(field_type)
2307 elif isinstance(field_type, CTFWriter.EnumerationFieldDeclaration):
2308 return CTFWriter.EnumerationField(field_type)
2309 elif isinstance(field_type, CTFWriter.FloatFieldDeclaration):
2310 return CTFWriter.FloatFieldingPoint(field_type)
2311 elif isinstance(field_type, CTFWriter.StructureFieldDeclaration):
2312 return CTFWriter.StructureField(field_type)
2313 elif isinstance(field_type, CTFWriter.VariantFieldDeclaration):
2314 return CTFWriter.VariantField(field_type)
2315 elif isinstance(field_type, CTFWriter.ArrayFieldDeclaration):
2316 return CTFWriter.ArrayField(field_type)
2317 elif isinstance(field_type, CTFWriter.SequenceFieldDeclaration):
2318 return CTFWriter.SequenceField(field_type)
2319 elif isinstance(field_type, CTFWriter.StringFieldDeclaration):
2320 return CTFWriter.StringField(field_type)
2324 Base class, do not instantiate.
2326 def __init__(self, field_type):
2327 if not isinstance(field_type, CTFWriter.FieldDeclaration):
2328 raise TypeError("Invalid field_type argument.")
2330 self._f = _bt_ctf_field_create(field_type._ft)
2332 raise ValueError("Field creation failed.")
2335 _bt_ctf_field_put(self._f)
2338 def _create_field_from_native_instance(native_field_instance):
2340 CTFTypeId.INTEGER : CTFWriter.IntegerField,
2341 CTFTypeId.FLOAT : CTFWriter.FloatFieldingPoint,
2342 CTFTypeId.ENUM : CTFWriter.EnumerationField,
2343 CTFTypeId.STRING : CTFWriter.StringField,
2344 CTFTypeId.STRUCT : CTFWriter.StructureField,
2345 CTFTypeId.VARIANT : CTFWriter.VariantField,
2346 CTFTypeId.ARRAY : CTFWriter.ArrayField,
2347 CTFTypeId.SEQUENCE : CTFWriter.SequenceField
2350 field_type = _bt_python_get_field_type(native_field_instance)
2351 if field_type == CTFTypeId.UNKNOWN:
2352 raise TypeError("Invalid field instance")
2354 field = CTFWriter.Field.__new__(CTFWriter.Field)
2355 field._f = native_field_instance
2356 field.__class__ = type_dict[field_type]
2360 def declaration(self):
2361 native_field_type = _bt_ctf_field_get_type(self._f)
2362 if native_field_type is None:
2363 raise TypeError("Invalid field instance")
2364 return CTFWriter.FieldDeclaration._create_field_declaration_from_native_instance(native_field_type)
2366 class IntegerField(Field):
2368 Get an integer field's value.
2372 signedness = _bt_python_field_integer_get_signedness(self._f)
2374 raise TypeError("Invalid integer instance.")
2377 ret, value = _bt_ctf_field_unsigned_integer_get_value(self._f)
2379 ret, value = _bt_ctf_field_signed_integer_get_value(self._f)
2382 raise ValueError("Could not get integer field value.")
2386 Set an integer field's value.
2389 def value(self, value):
2390 if not isinstance(value, int):
2391 raise TypeError("IntegerField's value must be an int")
2393 signedness = _bt_python_field_integer_get_signedness(self._f)
2395 raise TypeError("Invalid integer instance.")
2398 ret = _bt_ctf_field_unsigned_integer_set_value(self._f, value)
2400 ret = _bt_ctf_field_signed_integer_set_value(self._f, value)
2403 raise ValueError("Could not set integer field value.")
2405 class EnumerationField(Field):
2407 Return the enumeration's underlying container field (an integer field).
2410 def container(self):
2411 container = CTFWriter.IntegerField.__new__(CTFWriter.IntegerField)
2412 container._f = _bt_ctf_field_enumeration_get_container(self._f)
2413 if container._f is None:
2414 raise TypeError("Invalid enumeration field type.")
2418 Get the enumeration field's mapping name.
2422 value = _bt_ctf_field_enumeration_get_mapping_name(self._f)
2424 raise ValueError("Could not get enumeration's mapping name.")
2428 Set the enumeration field's value. Must be an integer as mapping names
2432 def value(self, value):
2433 if not isinstance(value, int):
2434 raise TypeError("EnumerationField value must be an int")
2435 self.container.value = value
2437 class FloatFieldingPoint(Field):
2439 Get a floating point field's value.
2443 ret, value = _bt_ctf_field_floating_point_get_value(self._f)
2445 raise ValueError("Could not get floating point field value.")
2449 Set a floating point field's value.
2452 def value(self, value):
2453 if not isinstance(value, int) and not isinstance(value, float):
2454 raise TypeError("Value must be either a float or an int")
2456 ret = _bt_ctf_field_floating_point_set_value(self._f, float(value))
2458 raise ValueError("Could not set floating point field value.")
2460 class StructureField(Field):
2462 Get the structure's field corresponding to the provided field name.
2464 def field(self, field_name):
2465 native_instance = _bt_ctf_field_structure_get_field(self._f, str(field_name))
2466 if native_instance is None:
2467 raise ValueError("Invalid field_name provided.")
2468 return CTFWriter.Field._create_field_from_native_instance(native_instance)
2470 class VariantField(Field):
2472 Return the variant's selected field. The "tag" field is the selector enum field.
2474 def field(self, tag):
2475 native_instance = _bt_ctf_field_variant_get_field(self._f, tag._f)
2476 if native_instance is None:
2477 raise ValueError("Invalid tag provided.")
2478 return CTFWriter.Field._create_field_from_native_instance(native_instance)
2480 class ArrayField(Field):
2482 Return the array's field at position "index".
2484 def field(self, index):
2485 native_instance = _bt_ctf_field_array_get_field(self._f, index)
2486 if native_instance is None:
2487 raise IndexError("Invalid index provided.")
2488 return CTFWriter.Field._create_field_from_native_instance(native_instance)
2490 class SequenceField(Field):
2492 Get the sequence's length field (IntegerField).
2496 native_instance = _bt_ctf_field_sequence_get_length(self._f)
2497 if native_instance is None:
2499 return CTFWriter.Field._create_field_from_native_instance(native_instance)
2502 Set the sequence's length field (IntegerField).
2505 def length(self, length_field):
2506 if not isinstance(length_field, CTFWriter.IntegerField):
2507 raise TypeError("Invalid length field.")
2508 if length_field.declaration.signed:
2509 raise TypeError("Sequence field length must be unsigned")
2510 ret = _bt_ctf_field_sequence_set_length(self._f, length_field._f)
2512 raise ValueError("Could not set sequence length.")
2515 Return the sequence's field at position "index".
2517 def field(self, index):
2518 native_instance = _bt_ctf_field_sequence_get_field(self._f, index)
2519 if native_instance is None:
2520 raise ValueError("Could not get sequence element at index.")
2521 return CTFWriter.Field._create_field_from_native_instance(native_instance)
2523 class StringField(Field):
2525 Get a string field's value.
2529 return _bt_ctf_field_string_get_value(self._f)
2532 Set a string field's value.
2535 def value(self, value):
2536 ret = _bt_ctf_field_string_set_value(self._f, str(value))
2538 raise ValueError("Could not set string field value.")
2542 Create a new event class of the given name.
2544 def __init__(self, name):
2545 self._ec = _bt_ctf_event_class_create(name)
2546 if self._ec is None:
2547 raise ValueError("Event class creation failed.")
2550 _bt_ctf_event_class_put(self._ec)
2553 Add a field of type "field_type" to the event class.
2555 def add_field(self, field_type, field_name):
2556 ret = _bt_ctf_event_class_add_field(self._ec, field_type._ft, str(field_name))
2558 raise ValueError("Could not add field to event class.")
2561 Get the event class' name.
2565 name = _bt_ctf_event_class_get_name(self._ec)
2567 raise TypeError("Could not get EventClass name")
2571 Get the event class' id. Returns a negative value if unset.
2575 id = _bt_ctf_event_class_get_id(self._ec)
2577 raise TypeError("Could not get EventClass id")
2581 Set the event class' id. Throws a TypeError if the event class
2582 is already registered to a stream class.
2586 ret = _bt_ctf_event_class_set_id(self._ec, id)
2588 raise TypeError("Can't change an Event Class's id after it has been assigned to a stream class")
2591 Get the event class' stream class. Returns None if unset.
2594 def stream_class(self):
2595 stream_class_native = _bt_ctf_event_class_get_stream_class(self._ec)
2596 if stream_class_native is None:
2598 stream_class = CTFWriter.StreamClass.__new__(CTFWriter.StreamClass)
2599 stream_class._sc = stream_class_native
2603 Generator returning the event class' fields as tuples of (field name, field declaration).
2607 count = _bt_ctf_event_class_get_field_count(self._ec)
2609 raise TypeError("Could not get EventClass' field count")
2611 for i in range(count):
2612 field_name = _bt_python_ctf_event_class_get_field_name(self._ec, i)
2613 if field_name is None:
2614 raise TypeError("Could not get EventClass' field name at index {}".format(i))
2616 field_type_native = _bt_python_ctf_event_class_get_field_type(self._ec, i)
2617 if field_type_native is None:
2618 raise TypeError("Could not get EventClass' field type at index {}".format(i))
2620 field_type = CTFWriter.FieldDeclaration._create_field_declaration_from_native_instance(field_type_native)
2621 yield (field_name, field_type)
2624 Get a field declaration by name (FieldDeclaration).
2626 def get_field_by_name(self, name):
2627 field_type_native = _bt_ctf_event_class_get_field_by_name(self._ec, name)
2628 if field_type_native is None:
2629 raise TypeError("Could not find EventClass field with name {}".format(name))
2630 return CTFWriter.FieldDeclaration._create_field_declaration_from_native_instance(field_type_native)
2634 Create a new event of the given event class.
2636 def __init__(self, event_class):
2637 if not isinstance(event_class, CTFWriter.EventClass):
2638 raise TypeError("Invalid event_class argument.")
2640 self._e = _bt_ctf_event_create(event_class._ec)
2642 raise ValueError("Event creation failed.")
2645 _bt_ctf_event_put(self._e)
2648 Get the event's class.
2651 def event_class(self):
2652 event_class_native = _bt_ctf_event_get_class(self._e)
2653 if event_class_native is None:
2655 event_class = CTFWriter.EventClass.__new__(CTFWriter.EventClass)
2656 event_class._ec = event_class_native
2660 Get a clock from event. Returns None if the event's class
2661 is not registered to a stream class.
2664 clock_instance = _bt_ctf_event_get_clock(self._e)
2665 if clock_instance is None:
2667 clock = CTFWriter.Clock.__new__(CTFWriter.Clock)
2668 clock._c = clock_instance
2672 Get a field from event.
2674 def payload(self, field_name):
2675 native_instance = _bt_ctf_event_get_payload(self._e, str(field_name))
2676 if native_instance is None:
2677 raise ValueError("Could not get event payload.")
2678 return CTFWriter.Field._create_field_from_native_instance(native_instance)
2681 Set a manually created field as an event's payload.
2683 def set_payload(self, field_name, value_field):
2684 if not isinstance(value, CTFWriter.Field):
2685 raise TypeError("Invalid value type.")
2686 ret = _bt_ctf_event_set_payload(self._e, str(field_name), value_field._f)
2688 raise ValueError("Could not set event field payload.")
2692 Create a new stream class of the given name.
2694 def __init__(self, name):
2695 self._sc = _bt_ctf_stream_class_create(name)
2696 if self._sc is None:
2697 raise ValueError("Stream class creation failed.")
2700 _bt_ctf_stream_class_put(self._sc)
2703 Get a stream class' name.
2707 name = _bt_ctf_stream_class_get_name(self._sc)
2709 raise TypeError("Could not get StreamClass name")
2713 Get a stream class' clock.
2717 clock_instance = _bt_ctf_stream_class_get_clock(self._sc)
2718 if clock_instance is None:
2720 clock = CTFWriter.Clock.__new__(CTFWriter.Clock)
2721 clock._c = clock_instance
2725 Assign a clock to a stream class.
2728 def clock(self, clock):
2729 if not isinstance(clock, CTFWriter.Clock):
2730 raise TypeError("Invalid clock type.")
2732 ret = _bt_ctf_stream_class_set_clock(self._sc, clock._c)
2734 raise ValueError("Could not set stream class clock.")
2737 Get a stream class' id.
2741 ret = _bt_ctf_stream_class_get_id(self._sc)
2743 raise TypeError("Could not get StreamClass id")
2747 Assign an id to a stream class.
2751 ret = _bt_ctf_stream_class_set_id(self._sc, id)
2753 raise TypeError("Could not set stream class id.")
2756 Generator returning the stream class' event classes.
2759 def event_classes(self):
2760 count = _bt_ctf_stream_class_get_event_class_count(self._sc)
2762 raise TypeError("Could not get StreamClass' event class count")
2764 for i in range(count):
2765 event_class_native = _bt_ctf_stream_class_get_event_class(self._sc, i)
2766 if event_class_native is None:
2767 raise TypeError("Could not get StreamClass' event class at index {}".format(i))
2769 event_class = CTFWriter.EventClass.__new__(CTFWriter.EventClass)
2770 event_class._ec = event_class_native
2774 Add an event class to a stream class. New events can be added even after a
2775 stream has been instantiated and events have been appended. However, a stream
2776 will not accept events of a class that has not been registered beforehand.
2778 def add_event_class(self, event_class):
2779 if not isinstance(event_class, CTFWriter.EventClass):
2780 raise TypeError("Invalid event_class type.")
2782 ret = _bt_ctf_stream_class_add_event_class(self._sc, event_class._ec)
2784 raise ValueError("Could not add event class.")
2788 Create a stream of the given class.
2790 def __init__(self, stream_class):
2791 if not isinstance(stream_class, CTFWriter.StreamClass):
2792 raise TypeError("Invalid stream_class type.")
2794 self._s = _bt_ctf_stream_create(stream_class._sc)
2796 raise ValueError("Stream creation failed.")
2799 _bt_ctf_stream_put(self._s)
2802 Get a stream's discarded event count.
2805 def discarded_events(self):
2806 ret, count = _bt_ctf_stream_get_discarded_events_count(self._s)
2808 raise ValueError("Could not get the stream's discarded events count")
2812 Increase the current packet's discarded event count.
2814 def append_discarded_events(self, event_count):
2815 _bt_ctf_stream_append_discarded_events(self._s, event_count)
2818 Append "event" to the stream's current packet. The stream's associated clock
2819 will be sampled during this call. The event shall not be modified after
2820 being appended to a stream.
2822 def append_event(self, event):
2823 ret = _bt_ctf_stream_append_event(self._s, event._e)
2825 raise ValueError("Could not append event to stream.")
2828 The stream's current packet's events will be flushed to disk. Events
2829 subsequently appended to the stream will be added to a new packet.
2832 ret = _bt_ctf_stream_flush(self._s)
2834 raise ValueError("Could not flush stream.")
2838 Create a new writer that will produce a trace in the given path.
2840 def __init__(self, path):
2841 self._w = _bt_ctf_writer_create(path)
2843 raise ValueError("Writer creation failed.")
2846 _bt_ctf_writer_put(self._w)
2849 Create a new stream instance and register it to the writer.
2851 def create_stream(self, stream_class):
2852 if not isinstance(stream_class, CTFWriter.StreamClass):
2853 raise TypeError("Invalid stream_class type.")
2855 stream = CTFWriter.Stream.__new__(CTFWriter.Stream)
2856 stream._s = _bt_ctf_writer_create_stream(self._w, stream_class._sc)
2860 Add an environment field to the trace.
2862 def add_environment_field(self, name, value):
2863 ret = _bt_ctf_writer_add_environment_field(self._w, str(name), str(value))
2865 raise ValueError("Could not add environment field to trace.")
2868 Add a clock to the trace. Clocks assigned to stream classes must be
2869 registered to the writer.
2871 def add_clock(self, clock):
2872 ret = _bt_ctf_writer_add_clock(self._w, clock._c)
2874 raise ValueError("Could not add clock to Writer.")
2877 Get the trace's TSDL meta-data.
2881 return _bt_ctf_writer_get_metadata_string(self._w)
2884 Flush the trace's metadata to the metadata file.
2886 def flush_metadata(self):
2887 _bt_ctf_writer_flush_metadata(self._w)
2890 Get the trace's byte order. Must be a constant from the ByteOrder
2894 def byte_order(self):
2895 raise NotImplementedError("Getter not implemented.")
2898 Set the trace's byte order. Must be a constant from the ByteOrder
2899 class. Defaults to BYTE_ORDER_NATIVE, the host machine's endianness.
2902 def byte_order(self, byte_order):
2903 ret = _bt_ctf_writer_set_byte_order(self._w, byte_order)
2905 raise ValueError("Could not set trace's byte order.")