4 * Babeltrace Python Module interface file
6 * Copyright 2012 EfficiOS Inc.
8 * Author: Danny Serres <danny.serres@efficios.com>
9 * Author: Jérémie Galarneau <jeremie.galarneau@efficios.com>
11 * Permission is hereby granted, free of charge, to any person obtaining a copy
12 * of this software and associated documentation files (the "Software"), to deal
13 * in the Software without restriction, including without limitation the rights
14 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
15 * copies of the Software, and to permit persons to whom the Software is
16 * furnished to do so, subject to the following conditions:
18 * The above copyright notice and this permission notice shall be included in
19 * all copies or substantial portions of the Software.
24 "BABELTRACE_VERSION_STR
26 Babeltrace is a trace viewer and converter reading and writing the
27 Common Trace Format (CTF). Its main use is to pretty-print CTF
28 traces into a human-readable text output.
30 To use this module, the first step is to create a TraceCollection and add a
34 %module(docstring=DOCSTRING) babeltrace
39 #define SWIG_FILE_WITH_INIT
40 #include <babeltrace/babeltrace.h>
41 #include <babeltrace/babeltrace-internal.h>
42 #include <babeltrace/trace-handle.h>
43 #include <babeltrace/trace-handle-internal.h>
44 #include <babeltrace/context.h>
45 #include <babeltrace/context-internal.h>
46 #include <babeltrace/iterator.h>
47 #include <babeltrace/iterator-internal.h>
48 #include <babeltrace/format.h>
49 #include <babeltrace/list.h>
50 #include <babeltrace/types.h>
51 #include <babeltrace/ctf/iterator.h>
52 #include "python-complements.h"
53 #include <babeltrace/ctf-writer/clock.h>
54 #include <babeltrace/ctf-writer/event-fields.h>
55 #include <babeltrace/ctf-writer/event-types.h>
56 #include <babeltrace/ctf-writer/event.h>
57 #include <babeltrace/ctf-writer/stream.h>
58 #include <babeltrace/ctf-writer/writer.h>
61 typedef int bt_intern_str;
62 typedef int64_t ssize_t;
64 /* =================================================================
66 ¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯
69 struct bt_definition **_bt_python_field_listcaller(
70 const struct bt_ctf_event *ctf_event,
71 const struct bt_definition *scope,
72 unsigned int *OUTPUT);
73 struct bt_definition *_bt_python_field_one_from_list(
74 struct bt_definition **list, int index);
75 struct bt_ctf_event_decl **_bt_python_event_decl_listcaller(
77 struct bt_context *ctx,
78 unsigned int *OUTPUT);
79 struct bt_ctf_event_decl *_bt_python_decl_one_from_list(
80 struct bt_ctf_event_decl **list, int index);
81 struct bt_ctf_field_decl **_by_python_field_decl_listcaller(
82 struct bt_ctf_event_decl *event_decl,
83 enum bt_ctf_scope scope,
84 unsigned int *OUTPUT);
85 struct bt_ctf_field_decl *_bt_python_field_decl_one_from_list(
86 struct bt_ctf_field_decl **list, int index);
87 struct definition_array *_bt_python_get_array_from_def(
88 struct bt_definition *field);
89 struct definition_sequence *_bt_python_get_sequence_from_def(
90 struct bt_definition *field);
91 struct bt_declaration *_bt_python_get_array_element_declaration(
92 struct bt_declaration *field);
93 struct bt_declaration *_bt_python_get_sequence_element_declaration(
94 struct bt_declaration *field);
95 const char *_bt_python_get_array_string(struct bt_definition *field);
96 const char *_bt_python_get_sequence_string(struct bt_definition *field);
97 int _bt_python_field_integer_get_signedness(const struct bt_ctf_field *field);
98 enum ctf_type_id _bt_python_get_field_type(const struct bt_ctf_field *field);
99 const char *_bt_python_ctf_field_type_enumeration_get_mapping(
100 struct bt_ctf_field_type *enumeration, size_t index,
101 int64_t *OUTPUT, int64_t *OUTPUT);
102 const char *_bt_python_ctf_field_type_enumeration_get_mapping_unsigned(
103 struct bt_ctf_field_type *enumeration, size_t index,
104 uint64_t *OUTPUT, uint64_t *OUTPUT);
105 const char *_bt_python_ctf_field_type_structure_get_field_name(
106 struct bt_ctf_field_type *structure, size_t index);
107 struct bt_ctf_field_type *_bt_python_ctf_field_type_structure_get_field_type(
108 struct bt_ctf_field_type *structure, size_t index);
109 const char *_bt_python_ctf_field_type_variant_get_field_name(
110 struct bt_ctf_field_type *variant, size_t index);
111 struct bt_ctf_field_type *_bt_python_ctf_field_type_variant_get_field_type(
112 struct bt_ctf_field_type *variant, size_t index);
113 const char *_bt_python_ctf_event_class_get_field_name(
114 struct bt_ctf_event_class *event_class, size_t index);
115 struct bt_ctf_field_type *_bt_python_ctf_event_class_get_field_type(
116 struct bt_ctf_event_class *event_class, size_t index);
118 /* =================================================================
119 CONTEXT.H, CONTEXT-INTERNAL.H
120 ¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯
123 %rename("_bt_context_create") bt_context_create(void);
124 %rename("_bt_context_add_trace") bt_context_add_trace(
125 struct bt_context *ctx, const char *path, const char *format,
126 void (*packet_seek)(struct bt_stream_pos *pos, size_t index, int whence),
127 struct bt_mmap_stream_list *stream_list, FILE *metadata);
128 %rename("_bt_context_remove_trace") bt_context_remove_trace(
129 struct bt_context *ctx, int trace_id);
130 %rename("_bt_context_get") bt_context_get(struct bt_context *ctx);
131 %rename("_bt_context_put") bt_context_put(struct bt_context *ctx);
132 %rename("_bt_ctf_event_get_context") bt_ctf_event_get_context(
133 const struct bt_ctf_event *event);
135 struct bt_context *bt_context_create(void);
136 int bt_context_add_trace(struct bt_context *ctx, const char *path, const char *format,
137 void (*packet_seek)(struct bt_stream_pos *pos, size_t index, int whence),
138 struct bt_mmap_stream_list *stream_list, FILE *metadata);
139 void bt_context_remove_trace(struct bt_context *ctx, int trace_id);
140 void bt_context_get(struct bt_context *ctx);
141 void bt_context_put(struct bt_context *ctx);
142 struct bt_context *bt_ctf_event_get_context(const struct bt_ctf_event *event);
144 // class TraceCollection to prevent direct access to struct bt_context
146 class TraceCollection:
148 The TraceCollection is the object that contains all currently opened traces.
152 self._tc = _bt_context_create()
155 _bt_context_put(self._tc)
157 def add_trace(self, path, format_str):
159 Add a trace by path to the TraceCollection.
163 path is the path to the trace, it is not recursive.
164 If "path" is None, stream_list is used instead as a list
165 of mmap streams to open for the trace.
167 format is a string containing the format name in which the trace was
170 Return: the corresponding TraceHandle on success or None on error.
172 ret = _bt_context_add_trace(self._tc, path, format_str, None, None, None)
176 th = TraceHandle.__new__(TraceHandle)
178 th._trace_collection = self
181 def add_traces_recursive(self, path, format_str):
183 Open a trace recursively.
185 Find each trace present in the subdirectory starting from the given
186 path, and add them to the TraceCollection.
188 Return a dict of TraceHandle instances (the full path is the key).
189 Return None on error.
199 for fullpath, dirs, files in os.walk(path):
200 if "metadata" in files:
201 trace_handle = self.add_trace(fullpath, format_str)
202 if trace_handle is None:
206 trace_handles[fullpath] = trace_handle
209 if noTrace and error:
213 def remove_trace(self, trace_handle):
215 Remove a trace from the TraceCollection.
216 Effectively closing the trace.
219 _bt_context_remove_trace(self._tc, trace_handle._id)
220 except AttributeError:
221 raise TypeError("in remove_trace, "
222 "argument 2 must be a TraceHandle instance")
227 Generator function to iterate over the events of open in the current
230 begin_pos_ptr = _bt_iter_pos()
231 end_pos_ptr = _bt_iter_pos()
232 begin_pos_ptr.type = SEEK_BEGIN
233 end_pos_ptr.type = SEEK_LAST
235 for event in self._events(begin_pos_ptr, end_pos_ptr):
238 def events_timestamps(self, timestamp_begin, timestamp_end):
240 Generator function to iterate over the events of open in the current
241 TraceCollection from timestamp_begin to timestamp_end.
243 begin_pos_ptr = _bt_iter_pos()
244 end_pos_ptr = _bt_iter_pos()
245 begin_pos_ptr.type = end_pos_ptr.type = SEEK_TIME
246 begin_pos_ptr.u.seek_time = timestamp_begin
247 end_pos_ptr.u.seek_time = timestamp_end
249 for event in self._events(begin_pos_ptr, end_pos_ptr):
253 def timestamp_begin(self):
254 pos_ptr = _bt_iter_pos()
255 pos_ptr.type = SEEK_BEGIN
256 return self._timestamp_at_pos(pos_ptr)
259 def timestamp_end(self):
260 pos_ptr = _bt_iter_pos()
261 pos_ptr.type = SEEK_LAST
262 return self._timestamp_at_pos(pos_ptr)
264 def _timestamp_at_pos(self, pos_ptr):
265 ctf_it_ptr = _bt_ctf_iter_create(self._tc, pos_ptr, pos_ptr)
266 if ctf_it_ptr is None:
267 raise NotImplementedError("Creation of multiple iterators is unsupported.")
268 ev_ptr = _bt_ctf_iter_read_event(ctf_it_ptr)
269 _bt_ctf_iter_destroy(ctf_it_ptr)
273 def _events(self, begin_pos_ptr, end_pos_ptr):
274 ctf_it_ptr = _bt_ctf_iter_create(self._tc, begin_pos_ptr, end_pos_ptr)
275 if ctf_it_ptr is None:
276 raise NotImplementedError(
277 "Creation of multiple iterators is unsupported.")
280 ev_ptr = _bt_ctf_iter_read_event(ctf_it_ptr)
284 ev = Event.__new__(Event)
288 except GeneratorExit:
291 ret = _bt_iter_next(_bt_ctf_get_iter(ctf_it_ptr))
295 _bt_ctf_iter_destroy(ctf_it_ptr)
301 /* =================================================================
306 %rename("lookup_format") bt_lookup_format(bt_intern_str qname);
307 %rename("_bt_print_format_list") bt_fprintf_format_list(FILE *fp);
308 %rename("register_format") bt_register_format(struct format *format);
309 %rename("unregister_format") bt_unregister_format(struct bt_format *format);
311 extern struct format *bt_lookup_format(bt_intern_str qname);
312 extern void bt_fprintf_format_list(FILE *fp);
313 extern int bt_register_format(struct bt_format *format);
314 extern void bt_unregister_format(struct bt_format *format);
318 def print_format_list(babeltrace_file):
320 Print a list of available formats to file.
322 babeltrace_file must be a File instance opened in write mode.
325 if babeltrace_file._file is not None:
326 _bt_print_format_list(babeltrace_file._file)
327 except AttributeError:
328 raise TypeError("in print_format_list, "
329 "argument 1 must be a File instance")
334 /* =================================================================
335 ITERATOR.H, ITERATOR-INTERNAL.H
336 ¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯
339 %rename("_bt_iter_create") bt_iter_create(struct bt_context *ctx,
340 const struct bt_iter_pos *begin_pos, const struct bt_iter_pos *end_pos);
341 %rename("_bt_iter_destroy") bt_iter_destroy(struct bt_iter *iter);
342 %rename("_bt_iter_next") bt_iter_next(struct bt_iter *iter);
343 %rename("_bt_iter_get_pos") bt_iter_get_pos(struct bt_iter *iter);
344 %rename("_bt_iter_free_pos") bt_iter_free_pos(struct bt_iter_pos *pos);
345 %rename("_bt_iter_set_pos") bt_iter_set_pos(struct bt_iter *iter,
346 const struct bt_iter_pos *pos);
347 %rename("_bt_iter_create_time_pos") bt_iter_create_time_pos(struct bt_iter *iter,
350 struct bt_iter *bt_iter_create(struct bt_context *ctx,
351 const struct bt_iter_pos *begin_pos, const struct bt_iter_pos *end_pos);
352 void bt_iter_destroy(struct bt_iter *iter);
353 int bt_iter_next(struct bt_iter *iter);
354 struct bt_iter_pos *bt_iter_get_pos(struct bt_iter *iter);
355 void bt_iter_free_pos(struct bt_iter_pos *pos);
356 int bt_iter_set_pos(struct bt_iter *iter, const struct bt_iter_pos *pos);
357 struct bt_iter_pos *bt_iter_create_time_pos(struct bt_iter *iter, uint64_t timestamp);
359 %rename("_bt_iter_pos") bt_iter_pos;
360 %rename("SEEK_TIME") BT_SEEK_TIME;
361 %rename("SEEK_RESTORE") BT_SEEK_RESTORE;
362 %rename("SEEK_CUR") BT_SEEK_CUR;
363 %rename("SEEK_BEGIN") BT_SEEK_BEGIN;
364 %rename("SEEK_LAST") BT_SEEK_LAST;
366 // This struct is taken from iterator.h
367 // All changes to the struct must also be made here
370 BT_SEEK_TIME, /* uses u.seek_time */
371 BT_SEEK_RESTORE, /* uses u.restore */
378 struct bt_saved_pos *restore;
382 /* =================================================================
383 TRACE-HANDLE.H, TRACE-HANDLE-INTERNAL.H
384 ¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯
387 %rename("_bt_trace_handle_create") bt_trace_handle_create(struct bt_context *ctx);
388 %rename("_bt_trace_handle_destroy") bt_trace_handle_destroy(struct bt_trace_handle *bt);
389 struct bt_trace_handle *bt_trace_handle_create(struct bt_context *ctx);
390 void bt_trace_handle_destroy(struct bt_trace_handle *bt);
392 %rename("_bt_trace_handle_get_path") bt_trace_handle_get_path(struct bt_context *ctx,
394 %rename("_bt_trace_handle_get_timestamp_begin") bt_trace_handle_get_timestamp_begin(
395 struct bt_context *ctx, int handle_id, enum bt_clock_type type);
396 %rename("_bt_trace_handle_get_timestamp_end") bt_trace_handle_get_timestamp_end(
397 struct bt_context *ctx, int handle_id, enum bt_clock_type type);
398 const char *bt_trace_handle_get_path(struct bt_context *ctx, int handle_id);
399 uint64_t bt_trace_handle_get_timestamp_begin(struct bt_context *ctx, int handle_id,
400 enum bt_clock_type type);
401 uint64_t bt_trace_handle_get_timestamp_end(struct bt_context *ctx, int handle_id,
402 enum bt_clock_type type);
404 %rename("_bt_ctf_event_get_handle_id") bt_ctf_event_get_handle_id(
405 const struct bt_ctf_event *event);
406 int bt_ctf_event_get_handle_id(const struct bt_ctf_event *event);
411 # Based on enum bt_clock_type in clock-type.h
416 class TraceHandle(object):
418 The TraceHandle allows the user to manipulate a trace file directly.
419 It is a unique identifier representing a trace file.
424 raise NotImplementedError("TraceHandle cannot be instantiated")
427 return "Babeltrace TraceHandle: trace_id('{0}')".format(self._id)
431 """Return the TraceHandle id."""
436 """Return the path of a TraceHandle."""
437 return _bt_trace_handle_get_path(self._trace_collection._tc, self._id)
440 def timestamp_begin(self):
441 """Return the creation time of the buffers of a trace."""
442 return _bt_trace_handle_get_timestamp_begin(
443 self._trace_collection._tc, self._id, ClockType.CLOCK_REAL)
446 def timestamp_end(self):
447 """Return the destruction timestamp of the buffers of a trace."""
448 return _bt_trace_handle_get_timestamp_end(
449 self._trace_collection._tc, self._id, ClockType.CLOCK_REAL)
454 Generator returning all events (EventDeclaration) in a trace.
456 ret = _bt_python_event_decl_listcaller(self.id, self._trace_collection._tc)
458 if not isinstance(ret, list):
461 ptr_list, count = ret
462 for i in range(count):
463 tmp = EventDeclaration.__new__(EventDeclaration)
464 tmp._ed = _bt_python_decl_one_from_list(ptr_list, i)
471 // =================================================================
473 // =================================================================
475 /* =================================================================
481 %rename("_bt_ctf_iter_create") bt_ctf_iter_create(struct bt_context *ctx,
482 const struct bt_iter_pos *begin_pos,
483 const struct bt_iter_pos *end_pos);
484 %rename("_bt_ctf_get_iter") bt_ctf_get_iter(struct bt_ctf_iter *iter);
485 %rename("_bt_ctf_iter_destroy") bt_ctf_iter_destroy(struct bt_ctf_iter *iter);
486 %rename("_bt_ctf_iter_read_event") bt_ctf_iter_read_event(struct bt_ctf_iter *iter);
488 struct bt_ctf_iter *bt_ctf_iter_create(struct bt_context *ctx,
489 const struct bt_iter_pos *begin_pos,
490 const struct bt_iter_pos *end_pos);
491 struct bt_iter *bt_ctf_get_iter(struct bt_ctf_iter *iter);
492 void bt_ctf_iter_destroy(struct bt_ctf_iter *iter);
493 struct bt_ctf_event *bt_ctf_iter_read_event(struct bt_ctf_iter *iter);
497 %rename("_bt_ctf_get_top_level_scope") bt_ctf_get_top_level_scope(const struct
498 bt_ctf_event *event, enum bt_ctf_scope scope);
499 %rename("_bt_ctf_event_name") bt_ctf_event_name(const struct bt_ctf_event *ctf_event);
500 %rename("_bt_ctf_get_timestamp") bt_ctf_get_timestamp(
501 const struct bt_ctf_event *ctf_event);
502 %rename("_bt_ctf_get_cycles") bt_ctf_get_cycles(
503 const struct bt_ctf_event *ctf_event);
505 %rename("_bt_ctf_get_field") bt_ctf_get_field(const struct bt_ctf_event *ctf_event,
506 const struct bt_definition *scope, const char *field);
507 %rename("_bt_ctf_get_index") bt_ctf_get_index(const struct bt_ctf_event *ctf_event,
508 const struct bt_definition *field, unsigned int index);
509 %rename("_bt_ctf_field_name") bt_ctf_field_name(const struct bt_definition *field);
510 %rename("_bt_ctf_field_type") bt_ctf_field_type(const struct bt_declaration *field);
511 %rename("_bt_ctf_get_int_signedness") bt_ctf_get_int_signedness(
512 const struct bt_declaration *field);
513 %rename("_bt_ctf_get_int_base") bt_ctf_get_int_base(const struct bt_declaration *field);
514 %rename("_bt_ctf_get_int_byte_order") bt_ctf_get_int_byte_order(
515 const struct bt_declaration *field);
516 %rename("_bt_ctf_get_int_len") bt_ctf_get_int_len(const struct bt_declaration *field);
517 %rename("_bt_ctf_get_enum_int") bt_ctf_get_enum_int(const struct bt_definition *field);
518 %rename("_bt_ctf_get_enum_str") bt_ctf_get_enum_str(const struct bt_definition *field);
519 %rename("_bt_ctf_get_encoding") bt_ctf_get_encoding(const struct bt_declaration *field);
520 %rename("_bt_ctf_get_array_len") bt_ctf_get_array_len(const struct bt_declaration *field);
521 %rename("_bt_ctf_get_uint64") bt_ctf_get_uint64(const struct bt_definition *field);
522 %rename("_bt_ctf_get_int64") bt_ctf_get_int64(const struct bt_definition *field);
523 %rename("_bt_ctf_get_char_array") bt_ctf_get_char_array(const struct bt_definition *field);
524 %rename("_bt_ctf_get_string") bt_ctf_get_string(const struct bt_definition *field);
525 %rename("_bt_ctf_get_float") bt_ctf_get_float(const struct bt_definition *field);
526 %rename("_bt_ctf_get_variant") bt_ctf_get_variant(const struct bt_definition *field);
527 %rename("_bt_ctf_field_get_error") bt_ctf_field_get_error(void);
528 %rename("_bt_ctf_get_decl_event_name") bt_ctf_get_decl_event_name(const struct
529 bt_ctf_event_decl *event);
530 %rename("_bt_ctf_get_decl_event_id") bt_ctf_get_decl_event_id(const struct
531 bt_ctf_event_decl *event);
532 %rename("_bt_ctf_get_decl_field_name") bt_ctf_get_decl_field_name(
533 const struct bt_ctf_field_decl *field);
534 %rename("_bt_ctf_get_decl_from_def") bt_ctf_get_decl_from_def(
535 const struct bt_definition *field);
536 %rename("_bt_ctf_get_decl_from_field_decl") bt_ctf_get_decl_from_field_decl(
537 const struct bt_ctf_field_decl *field);
538 %rename("_bt_array_index") bt_array_index(struct definition_array *array, uint64_t i);
539 %rename("_bt_sequence_len") bt_sequence_len(struct definition_sequence *sequence);
540 %rename("_bt_sequence_index") bt_sequence_index(struct definition_sequence *sequence, uint64_t i);
541 %rename("_bt_ctf_get_struct_field_count") bt_ctf_get_struct_field_count(const struct bt_definition *structure);
542 %rename("_bt_ctf_get_struct_field_index") bt_ctf_get_struct_field_index(const struct bt_definition *structure, uint64_t i);
544 const struct bt_definition *bt_ctf_get_top_level_scope(const struct bt_ctf_event *ctf_event,
545 enum bt_ctf_scope scope);
546 const char *bt_ctf_event_name(const struct bt_ctf_event *ctf_event);
547 uint64_t bt_ctf_get_timestamp(const struct bt_ctf_event *ctf_event);
548 uint64_t bt_ctf_get_cycles(const struct bt_ctf_event *ctf_event);
549 const struct bt_definition *bt_ctf_get_field(const struct bt_ctf_event *ctf_event,
550 const struct bt_definition *scope,
552 const struct bt_definition *bt_ctf_get_index(const struct bt_ctf_event *ctf_event,
553 const struct bt_definition *field,
555 const char *bt_ctf_field_name(const struct bt_definition *field);
556 enum ctf_type_id bt_ctf_field_type(const struct bt_declaration *field);
557 int bt_ctf_get_int_signedness(const struct bt_declaration *field);
558 int bt_ctf_get_int_base(const struct bt_declaration *field);
559 int bt_ctf_get_int_byte_order(const struct bt_declaration *field);
560 ssize_t bt_ctf_get_int_len(const struct bt_declaration *field);
561 const struct bt_definition *bt_ctf_get_enum_int(const struct bt_definition *field);
562 const char *bt_ctf_get_enum_str(const struct bt_definition *field);
563 enum ctf_string_encoding bt_ctf_get_encoding(const struct bt_declaration *field);
564 int bt_ctf_get_array_len(const struct bt_declaration *field);
565 struct bt_definition *bt_array_index(struct definition_array *array, uint64_t i);
566 uint64_t bt_ctf_get_uint64(const struct bt_definition *field);
567 int64_t bt_ctf_get_int64(const struct bt_definition *field);
568 char *bt_ctf_get_char_array(const struct bt_definition *field);
569 char *bt_ctf_get_string(const struct bt_definition *field);
570 double bt_ctf_get_float(const struct bt_definition *field);
571 const struct bt_definition *bt_ctf_get_variant(const struct bt_definition *field);
572 int bt_ctf_field_get_error(void);
573 const char *bt_ctf_get_decl_event_name(const struct bt_ctf_event_decl *event);
574 uint64_t bt_ctf_get_decl_event_id(const struct bt_ctf_event_decl *event);
575 const char *bt_ctf_get_decl_field_name(const struct bt_ctf_field_decl *field);
576 const struct bt_declaration *bt_ctf_get_decl_from_def(const struct bt_definition *field);
577 const struct bt_declaration *bt_ctf_get_decl_from_field_decl(const struct bt_ctf_field_decl *field);
578 uint64_t bt_sequence_len(struct definition_sequence *sequence);
579 struct bt_definition *bt_sequence_index(struct definition_sequence *sequence, uint64_t i);
580 uint64_t bt_ctf_get_struct_field_count(const struct bt_definition *structure);
581 const struct bt_definition *bt_ctf_get_struct_field_index(const struct bt_definition *structure, uint64_t i);
585 class CTFStringEncoding:
591 # Based on the enum in ctf-writer/writer.h
593 BYTE_ORDER_NATIVE = 0
594 BYTE_ORDER_LITTLE_ENDIAN = 1
595 BYTE_ORDER_BIG_ENDIAN = 2
596 BYTE_ORDER_NETWORK = 3
597 BYTE_ORDER_UNKNOWN = 4 # Python-specific entry
599 #enum equivalent, accessible constants
600 #These are taken directly from ctf/events.h
601 #All changes to enums must also be made here
615 name = "UNKNOWN_TYPE"
616 constants = [attr for attr in dir(CTFTypeId) if not callable(getattr(CTFTypeId, attr)) and not attr.startswith("__")]
617 for attr in constants:
618 if getattr(CTFTypeId, attr) == id:
624 TRACE_PACKET_HEADER = 0
625 STREAM_PACKET_CONTEXT = 1
626 STREAM_EVENT_HEADER = 2
627 STREAM_EVENT_CONTEXT = 3
631 def scope_name(scope):
632 name = "UNKNOWN_SCOPE"
633 constants = [attr for attr in dir(CTFScope) if not callable(getattr(CTFScope, attr)) and not attr.startswith("__")]
634 for attr in constants:
635 if getattr(CTFScope, attr) == scope:
640 # Priority of the scopes when searching for event fields
641 _scopes = [CTFScope.EVENT_FIELDS, CTFScope.EVENT_CONTEXT, CTFScope.STREAM_EVENT_CONTEXT,
642 CTFScope.STREAM_EVENT_HEADER, CTFScope.STREAM_PACKET_CONTEXT, CTFScope.TRACE_PACKET_HEADER]
645 class Event(collections.Mapping):
647 This class represents an event from the trace.
648 It is obtained using the TraceCollection generator functions.
652 raise NotImplementedError("Event cannot be instantiated")
656 """Return the name of the event or None on error."""
657 return _bt_ctf_event_name(self._e)
662 Return the timestamp of the event as written in
663 the packet (in cycles) or -1ULL on error.
665 return _bt_ctf_get_cycles(self._e)
670 Return the timestamp of the event offset with the
671 system clock source or -1ULL on error.
673 return _bt_ctf_get_timestamp(self._e)
675 def field_with_scope(self, field_name, scope):
677 Get field_name's value in scope.
678 None is returned if no field matches field_name.
680 if not scope in _scopes:
681 raise ValueError("Invalid scope provided")
682 field = self._field_with_scope(field_name, scope)
683 if field is not None:
687 def field_list_with_scope(self, scope):
688 """Return a list of field names in scope."""
689 if not scope in _scopes:
690 raise ValueError("Invalid scope provided")
692 for field in self._field_list_with_scope(scope):
693 field_names.append(field.name)
699 Get the TraceHandle associated with this event
702 ret = _bt_ctf_event_get_handle_id(self._e)
706 th = TraceHandle.__new__(TraceHandle)
708 th._trace_collection = self.get_trace_collection()
712 def trace_collection(self):
714 Get the TraceCollection associated with this event.
715 Return None on error.
717 trace_collection = TraceCollection()
718 trace_collection._tc = _bt_ctf_event_get_context(self._e);
719 if trace_collection._tc is None:
722 return trace_collection
724 def __getitem__(self, field_name):
726 Get field_name's value. If the field_name exists in multiple
727 scopes, the first field found is returned. The scopes are searched
728 in the following order:
731 3) STREAM_EVENT_CONTEXT
732 4) STREAM_EVENT_HEADER
733 5) STREAM_PACKET_CONTEXT
734 6) TRACE_PACKET_HEADER
735 None is returned if no field matches field_name.
737 Use field_with_scope() to explicitly access fields in a given
740 field = self._field(field_name)
741 if field is not None:
743 raise KeyError(field_name)
746 for key in self.keys():
751 for scope in _scopes:
752 scope_ptr = _bt_ctf_get_top_level_scope(self._e, scope)
753 ret = _bt_python_field_listcaller(self._e, scope_ptr)
754 if isinstance(ret, list):
758 def __contains__(self, field_name):
759 return self._field(field_name) is not None
762 """Return a list of field names."""
764 for scope in _scopes:
765 for name in self.field_list_with_scope(scope):
766 field_names.add(name)
767 return list(field_names)
769 def get(self, field_name, default = None):
770 field = self._field(field_name)
776 for field in self.keys():
777 yield (field, self[field])
779 def _field_with_scope(self, field_name, scope):
780 scope_ptr = _bt_ctf_get_top_level_scope(self._e, scope)
781 if scope_ptr is None:
784 definition_ptr = _bt_ctf_get_field(self._e, scope_ptr, field_name)
785 if definition_ptr is None:
788 field = _Definition(definition_ptr, scope)
791 def _field(self, field_name):
793 for scope in _scopes:
794 field = self._field_with_scope(field_name, scope)
795 if field is not None:
799 def _field_list_with_scope(self, scope):
801 scope_ptr = _bt_ctf_get_top_level_scope(self._e, scope)
803 # Returns a list [list_ptr, count]. If list_ptr is NULL, SWIG will only
804 # provide the "count" return value
807 ret = _bt_python_field_listcaller(self._e, scope_ptr)
808 if isinstance(ret, list):
809 list_ptr, count = ret
811 for i in range(count):
812 definition_ptr = _bt_python_field_one_from_list(list_ptr, i)
813 if definition_ptr is not None:
814 definition = _Definition(definition_ptr, scope)
815 fields.append(definition)
818 class FieldError(Exception):
819 def __init__(self, value):
823 return repr(self.value)
825 class EventDeclaration(object):
826 """Event declaration class. Do not instantiate."""
827 MAX_UINT64 = 0xFFFFFFFFFFFFFFFF
830 raise NotImplementedError("EventDeclaration cannot be instantiated")
834 """Return the name of the event or None on error"""
835 return _bt_ctf_get_decl_event_name(self._ed)
839 """Return the event-ID of the event or -1 on error"""
840 id = _bt_ctf_get_decl_event_id(self._ed)
841 if id == self.MAX_UINT64:
848 Generator returning all FieldDeclarations of an event, going through
849 each scope in the following order:
852 3) STREAM_EVENT_CONTEXT
853 4) STREAM_EVENT_HEADER
854 5) STREAM_PACKET_CONTEXT
855 6) TRACE_PACKET_HEADER
857 for scope in _scopes:
858 for declaration in self.fields_scope(scope):
861 def fields_scope(self, scope):
863 Generator returning FieldDeclarations of the current event in scope.
865 ret = _by_python_field_decl_listcaller(self._ed, scope)
867 if not isinstance(ret, list):
870 list_ptr, count = ret
871 for i in range(count):
872 field_declaration_ptr = _bt_python_field_decl_one_from_list(list_ptr, i)
873 if field_declaration_ptr is not None:
874 declaration_ptr = _bt_ctf_get_decl_from_field_decl(field_declaration_ptr)
875 field_declaration = _create_field_declaration(declaration_ptr, _bt_ctf_get_decl_field_name(field_declaration_ptr), scope)
876 yield field_declaration
878 class FieldDeclaration(object):
879 """Field declaration class. Do not instantiate."""
881 raise NotImplementedError("FieldDeclaration cannot be instantiated")
884 return "({0}) {1} {2}".format(CTFScope.scope_name(self.scope), CTFTypeId.type_name(self.type), self.name)
888 """Return the name of a FieldDeclaration or None on error."""
894 Return the FieldDeclaration's type. One of the entries in class
897 return _bt_ctf_field_type(self._fd)
902 Return the FieldDeclaration's scope.
906 class IntegerFieldDeclaration(FieldDeclaration):
907 """Do not instantiate."""
909 raise NotImplementedError("IntegerFieldDeclaration cannot be instantiated")
912 def signedness(self):
914 Return the signedness of an integer:
915 0 if unsigned; 1 if signed; -1 on error.
917 return _bt_ctf_get_int_signedness(self._fd)
921 """Return the base of an int or a negative value on error."""
922 return _bt_ctf_get_int_base(self._fd)
925 def byte_order(self):
927 Return the byte order. One of class ByteOrder's entries.
929 ret = _bt_ctf_get_int_byte_order(self._fd)
931 return ByteOrder.BYTE_ORDER_LITTLE_ENDIAN
933 return ByteOrder.BYTE_ORDER_BIG_ENDIAN
935 return ByteOrder.BYTE_ORDER_UNKNOWN
940 Return the size, in bits, of an int or a negative
943 return _bt_ctf_get_int_len(self._fd)
948 Return the encoding. One of class CTFStringEncoding's entries.
949 Return a negative value on error.
951 return _bt_ctf_get_encoding(self._fd)
953 class EnumerationFieldDeclaration(FieldDeclaration):
954 """Do not instantiate."""
956 raise NotImplementedError("EnumerationFieldDeclaration cannot be instantiated")
958 class ArrayFieldDeclaration(FieldDeclaration):
959 """Do not instantiate."""
961 raise NotImplementedError("ArrayFieldDeclaration cannot be instantiated")
966 Return the length of an array or a negative
969 return _bt_ctf_get_array_len(self._fd)
972 def element_declaration(self):
974 Return element declaration.
976 field_decl_ptr = _bt_python_get_array_element_declaration(self._fd)
977 return _create_field_declaration(field_decl_ptr, "", self.scope)
979 class SequenceFieldDeclaration(FieldDeclaration):
980 """Do not instantiate."""
982 raise NotImplementedError("SequenceFieldDeclaration cannot be instantiated")
985 def element_declaration(self):
987 Return element declaration.
989 field_decl_ptr = _bt_python_get_sequence_element_declaration(self._fd)
990 return _create_field_declaration(field_decl_ptr, "", self.scope)
992 class FloatFieldDeclaration(FieldDeclaration):
993 """Do not instantiate."""
995 raise NotImplementedError("FloatFieldDeclaration cannot be instantiated")
997 class StructureFieldDeclaration(FieldDeclaration):
998 """Do not instantiate."""
1000 raise NotImplementedError("StructureFieldDeclaration cannot be instantiated")
1002 class StringFieldDeclaration(FieldDeclaration):
1003 """Do not instantiate."""
1005 raise NotImplementedError("StringFieldDeclaration cannot be instantiated")
1007 class VariantFieldDeclaration(FieldDeclaration):
1008 """Do not instantiate."""
1010 raise NotImplementedError("VariantFieldDeclaration cannot be instantiated")
1014 Return the last error code encountered while
1015 accessing a field and reset the error flag.
1016 Return 0 if no error, a negative value otherwise.
1018 return _bt_ctf_field_get_error()
1020 def _create_field_declaration(declaration_ptr, name, scope):
1022 Private field declaration factory.
1024 if declaration_ptr is None:
1025 raise ValueError("declaration_ptr must be valid")
1026 if not scope in _scopes:
1027 raise ValueError("Invalid scope provided")
1029 type = _bt_ctf_field_type(declaration_ptr)
1031 if type == CTFTypeId.INTEGER:
1032 declaration = IntegerFieldDeclaration.__new__(IntegerFieldDeclaration)
1033 elif type == CTFTypeId.ENUM:
1034 declaration = EnumerationFieldDeclaration.__new__(EnumerationFieldDeclaration)
1035 elif type == CTFTypeId.ARRAY:
1036 declaration = ArrayFieldDeclaration.__new__(ArrayFieldDeclaration)
1037 elif type == CTFTypeId.SEQUENCE:
1038 declaration = SequenceFieldDeclaration.__new__(SequenceFieldDeclaration)
1039 elif type == CTFTypeId.FLOAT:
1040 declaration = FloatFieldDeclaration.__new__(FloatFieldDeclaration)
1041 elif type == CTFTypeId.STRUCT:
1042 declaration = StructureFieldDeclaration.__new__(StructureFieldDeclaration)
1043 elif type == CTFTypeId.STRING:
1044 declaration = StringFieldDeclaration.__new__(StringFieldDeclaration)
1045 elif type == CTFTypeId.VARIANT:
1046 declaration = VariantFieldDeclaration.__new__(VariantFieldDeclaration)
1050 declaration._fd = declaration_ptr
1051 declaration._s = scope
1052 declaration._name = name
1055 class _Definition(object):
1056 def __init__(self, definition_ptr, scope):
1057 self._d = definition_ptr
1059 if not scope in _scopes:
1060 ValueError("Invalid scope provided")
1064 """Return the name of a field or None on error."""
1065 return _bt_ctf_field_name(self._d)
1069 """Return the type of a field or -1 if unknown."""
1070 return _bt_ctf_field_type(_bt_ctf_get_decl_from_def(self._d))
1073 def declaration(self):
1074 """Return the associated Definition object."""
1075 return _create_field_declaration(_bt_ctf_get_decl_from_def(self._d), self.name, self.scope)
1077 def _get_enum_str(self):
1079 Return the string matching the current enumeration.
1080 Return None on error.
1082 return _bt_ctf_get_enum_str(self._d)
1084 def _get_array_element_at(self, index):
1086 Return the array's element at position index.
1087 Return None on error
1089 array_ptr = _bt_python_get_array_from_def(self._d)
1090 if array_ptr is None:
1093 definition_ptr = _bt_array_index(array_ptr, index)
1094 if definition_ptr is None:
1096 return _Definition(definition_ptr, self.scope)
1098 def _get_sequence_len(self):
1100 Return the len of a sequence or a negative
1103 seq = _bt_python_get_sequence_from_def(self._d)
1104 return _bt_sequence_len(seq)
1106 def _get_sequence_element_at(self, index):
1108 Return the sequence's element at position index,
1109 otherwise return None
1111 seq = _bt_python_get_sequence_from_def(self._d)
1113 definition_ptr = _bt_sequence_index(seq, index)
1114 if definition_ptr is not None:
1115 return _Definition(definition_ptr, self.scope)
1118 def _get_uint64(self):
1120 Return the value associated with the field.
1121 If the field does not exist or is not of the type requested,
1122 the value returned is undefined. To check if an error occured,
1123 use the field_error() function after accessing a field.
1125 return _bt_ctf_get_uint64(self._d)
1127 def _get_int64(self):
1129 Return the value associated with the field.
1130 If the field does not exist or is not of the type requested,
1131 the value returned is undefined. To check if an error occured,
1132 use the field_error() function after accessing a field.
1134 return _bt_ctf_get_int64(self._d)
1136 def _get_char_array(self):
1138 Return the value associated with the field.
1139 If the field does not exist or is not of the type requested,
1140 the value returned is undefined. To check if an error occurred,
1141 use the field_error() function after accessing a field.
1143 return _bt_ctf_get_char_array(self._d)
1147 Return the value associated with the field.
1148 If the field does not exist or is not of the type requested,
1149 the value returned is undefined. To check if an error occurred,
1150 use the field_error() function after accessing a field.
1152 return _bt_ctf_get_string(self._d)
1154 def _get_float(self):
1156 Return the value associated with the field.
1157 If the field does not exist or is not of the type requested,
1158 the value returned is undefined. To check if an error occurred,
1159 use the field_error() function after accessing a field.
1161 return _bt_ctf_get_float(self._d)
1163 def _get_variant(self):
1165 Return the variant's selected field.
1166 If the field does not exist or is not of the type requested,
1167 the value returned is undefined. To check if an error occurred,
1168 use the field_error() function after accessing a field.
1170 return _bt_ctf_get_variant(self._d)
1172 def _get_struct_field_count(self):
1174 Return the number of fields contained in the structure.
1175 If the field does not exist or is not of the type requested,
1176 the value returned is undefined.
1178 return _bt_ctf_get_struct_field_count(self._d)
1180 def _get_struct_field_at(self, i):
1182 Return the structure's field at position i.
1183 If the field does not exist or is not of the type requested,
1184 the value returned is undefined. To check if an error occurred,
1185 use the field_error() function after accessing a field.
1187 return _bt_ctf_get_struct_field_index(self._d, i)
1192 Return the value associated with the field according to its type.
1193 Return None on error.
1198 if id == CTFTypeId.STRING:
1199 value = self._get_str()
1200 elif id == CTFTypeId.ARRAY:
1201 element_decl = self.declaration.element_declaration
1202 if ((element_decl.type == CTFTypeId.INTEGER
1203 and element_decl.length == 8)
1204 and (element_decl.encoding == CTFStringEncoding.ASCII or element_decl.encoding == CTFStringEncoding.UTF8)):
1205 value = _bt_python_get_array_string(self._d)
1208 for i in range(self.declaration.length):
1209 element = self._get_array_element_at(i)
1210 value.append(element.value)
1211 elif id == CTFTypeId.INTEGER:
1212 if self.declaration.signedness == 0:
1213 value = self._get_uint64()
1215 value = self._get_int64()
1216 elif id == CTFTypeId.ENUM:
1217 value = self._get_enum_str()
1218 elif id == CTFTypeId.SEQUENCE:
1219 element_decl = self.declaration.element_declaration
1220 if ((element_decl.type == CTFTypeId.INTEGER
1221 and element_decl.length == 8)
1222 and (element_decl.encoding == CTFStringEncoding.ASCII or element_decl.encoding == CTFStringEncoding.UTF8)):
1223 value = _bt_python_get_sequence_string(self._d)
1225 seq_len = self._get_sequence_len()
1227 for i in range(seq_len):
1228 evDef = self._get_sequence_element_at(i)
1229 value.append(evDef.value)
1230 elif id == CTFTypeId.FLOAT:
1231 value = self._get_float()
1232 elif id == CTFTypeId.VARIANT:
1233 variant = _Definition.__new__(_Definition)
1234 variant._d = self._get_variant();
1235 value = variant.value
1236 elif id == CTFTypeId.STRUCT:
1238 for i in range(self._get_struct_field_count()):
1239 member = _Definition(self._get_struct_field_at(i), self.scope)
1240 value[member.name] = member.value
1243 raise FieldError("Error occurred while accessing field {} of type {}".format(self.name, CTFTypeId.type_name(id)))
1248 """Return the scope of a field or None on error."""
1254 // =================================================================
1256 // =================================================================
1258 /* =================================================================
1260 ¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯
1262 %rename("_bt_ctf_clock_create") bt_ctf_clock_create(const char *name);
1263 %rename("_bt_ctf_clock_get_name") bt_ctf_clock_get_name(struct bt_ctf_clock *clock);
1264 %rename("_bt_ctf_clock_get_description") bt_ctf_clock_get_description(struct bt_ctf_clock *clock);
1265 %rename("_bt_ctf_clock_set_description") bt_ctf_clock_set_description(struct bt_ctf_clock *clock, const char *desc);
1266 %rename("_bt_ctf_clock_get_frequency") bt_ctf_clock_get_frequency(struct bt_ctf_clock *clock);
1267 %rename("_bt_ctf_clock_set_frequency") bt_ctf_clock_set_frequency(struct bt_ctf_clock *clock, uint64_t freq);
1268 %rename("_bt_ctf_clock_get_precision") bt_ctf_clock_get_precision(struct bt_ctf_clock *clock);
1269 %rename("_bt_ctf_clock_set_precision") bt_ctf_clock_set_precision(struct bt_ctf_clock *clock, uint64_t precision);
1270 %rename("_bt_ctf_clock_get_offset_s") bt_ctf_clock_get_offset_s(struct bt_ctf_clock *clock);
1271 %rename("_bt_ctf_clock_set_offset_s") bt_ctf_clock_set_offset_s(struct bt_ctf_clock *clock, uint64_t offset_s);
1272 %rename("_bt_ctf_clock_get_offset") bt_ctf_clock_get_offset(struct bt_ctf_clock *clock);
1273 %rename("_bt_ctf_clock_set_offset") bt_ctf_clock_set_offset(struct bt_ctf_clock *clock, uint64_t offset);
1274 %rename("_bt_ctf_clock_get_is_absolute") bt_ctf_clock_get_is_absolute(struct bt_ctf_clock *clock);
1275 %rename("_bt_ctf_clock_set_is_absolute") bt_ctf_clock_set_is_absolute(struct bt_ctf_clock *clock, int is_absolute);
1276 %rename("_bt_ctf_clock_get_time") bt_ctf_clock_get_time(struct bt_ctf_clock *clock);
1277 %rename("_bt_ctf_clock_set_time") bt_ctf_clock_set_time(struct bt_ctf_clock *clock, uint64_t time);
1278 %rename("_bt_ctf_clock_get") bt_ctf_clock_get(struct bt_ctf_clock *clock);
1279 %rename("_bt_ctf_clock_put") bt_ctf_clock_put(struct bt_ctf_clock *clock);
1281 struct bt_ctf_clock *bt_ctf_clock_create(const char *name);
1282 const char *bt_ctf_clock_get_name(struct bt_ctf_clock *clock);
1283 const char *bt_ctf_clock_get_description(struct bt_ctf_clock *clock);
1284 int bt_ctf_clock_set_description(struct bt_ctf_clock *clock, const char *desc);
1285 uint64_t bt_ctf_clock_get_frequency(struct bt_ctf_clock *clock);
1286 int bt_ctf_clock_set_frequency(struct bt_ctf_clock *clock, uint64_t freq);
1287 uint64_t bt_ctf_clock_get_precision(struct bt_ctf_clock *clock);
1288 int bt_ctf_clock_set_precision(struct bt_ctf_clock *clock, uint64_t precision);
1289 uint64_t bt_ctf_clock_get_offset_s(struct bt_ctf_clock *clock);
1290 int bt_ctf_clock_set_offset_s(struct bt_ctf_clock *clock, uint64_t offset_s);
1291 uint64_t bt_ctf_clock_get_offset(struct bt_ctf_clock *clock);
1292 int bt_ctf_clock_set_offset(struct bt_ctf_clock *clock, uint64_t offset);
1293 int bt_ctf_clock_get_is_absolute(struct bt_ctf_clock *clock);
1294 int bt_ctf_clock_set_is_absolute(struct bt_ctf_clock *clock, int is_absolute);
1295 uint64_t bt_ctf_clock_get_time(struct bt_ctf_clock *clock);
1296 int bt_ctf_clock_set_time(struct bt_ctf_clock *clock, uint64_t time);
1297 void bt_ctf_clock_get(struct bt_ctf_clock *clock);
1298 void bt_ctf_clock_put(struct bt_ctf_clock *clock);
1300 /* =================================================================
1302 ¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯
1304 %rename("_bt_ctf_field_type_integer_create") bt_ctf_field_type_integer_create(unsigned int size);
1305 %rename("_bt_ctf_field_type_integer_get_size") bt_ctf_field_type_integer_get_size(struct bt_ctf_field_type *integer);
1306 %rename("_bt_ctf_field_type_integer_get_signed") bt_ctf_field_type_integer_get_signed(struct bt_ctf_field_type *integer);
1307 %rename("_bt_ctf_field_type_integer_set_signed") bt_ctf_field_type_integer_set_signed(struct bt_ctf_field_type *integer, int is_signed);
1308 %rename("_bt_ctf_field_type_integer_get_base") bt_ctf_field_type_integer_get_base(struct bt_ctf_field_type *integer);
1309 %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);
1310 %rename("_bt_ctf_field_type_integer_get_encoding") bt_ctf_field_type_integer_get_encoding(struct bt_ctf_field_type *integer);
1311 %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);
1312 %rename("_bt_ctf_field_type_enumeration_create") bt_ctf_field_type_enumeration_create(struct bt_ctf_field_type *integer_container_type);
1313 %rename("_bt_ctf_field_type_enumeration_get_container_type") bt_ctf_field_type_enumeration_get_container_type(struct bt_ctf_field_type *enumeration);
1314 %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);
1315 %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);
1316 %rename("_bt_ctf_field_type_enumeration_get_mapping_count") bt_ctf_field_type_enumeration_get_mapping_count(struct bt_ctf_field_type *enumeration);
1317 %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);
1318 %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);
1319 %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);
1320 %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);
1321 %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);
1322 %rename("_bt_ctf_field_type_floating_point_create") bt_ctf_field_type_floating_point_create(void);
1323 %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);
1324 %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);
1325 %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);
1326 %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);
1327 %rename("_bt_ctf_field_type_structure_create") bt_ctf_field_type_structure_create(void);
1328 %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);
1329 %rename("_bt_ctf_field_type_structure_get_field_count") bt_ctf_field_type_structure_get_field_count(struct bt_ctf_field_type *structure);
1330 %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);
1331 %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);
1332 %rename("_bt_ctf_field_type_variant_create") bt_ctf_field_type_variant_create(struct bt_ctf_field_type *enum_tag, const char *tag_name);
1333 %rename("_bt_ctf_field_type_variant_get_tag_type") bt_ctf_field_type_variant_get_tag_type(struct bt_ctf_field_type *variant);
1334 %rename("_bt_ctf_field_type_variant_get_tag_name") bt_ctf_field_type_variant_get_tag_name(struct bt_ctf_field_type *variant);
1335 %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);
1336 %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);
1337 %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);
1338 %rename("_bt_ctf_field_type_variant_get_field_count") bt_ctf_field_type_variant_get_field_count(struct bt_ctf_field_type *variant);
1339 %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);
1340 %rename("_bt_ctf_field_type_array_create") bt_ctf_field_type_array_create(struct bt_ctf_field_type *element_type, unsigned int length);
1341 %rename("_bt_ctf_field_type_array_get_element_type") bt_ctf_field_type_array_get_element_type(struct bt_ctf_field_type *array);
1342 %rename("_bt_ctf_field_type_array_get_length") bt_ctf_field_type_array_get_length(struct bt_ctf_field_type *array);
1343 %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);
1344 %rename("_bt_ctf_field_type_sequence_get_element_type") bt_ctf_field_type_sequence_get_element_type(struct bt_ctf_field_type *sequence);
1345 %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);
1346 %rename("_bt_ctf_field_type_string_create") bt_ctf_field_type_string_create(void);
1347 %rename("_bt_ctf_field_type_string_get_encoding") bt_ctf_field_type_string_get_encoding(struct bt_ctf_field_type *string_type);
1348 %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);
1349 %rename("_bt_ctf_field_type_get_alignment") bt_ctf_field_type_get_alignment(struct bt_ctf_field_type *type);
1350 %rename("_bt_ctf_field_type_set_alignment") bt_ctf_field_type_set_alignment(struct bt_ctf_field_type *type, unsigned int alignment);
1351 %rename("_bt_ctf_field_type_get_byte_order") bt_ctf_field_type_get_byte_order(struct bt_ctf_field_type *type);
1352 %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);
1353 %rename("_bt_ctf_field_type_get_type_id") bt_ctf_field_type_get_type_id(struct bt_ctf_field_type *type);
1354 %rename("_bt_ctf_field_type_get") bt_ctf_field_type_get(struct bt_ctf_field_type *type);
1355 %rename("_bt_ctf_field_type_put") bt_ctf_field_type_put(struct bt_ctf_field_type *type);
1357 struct bt_ctf_field_type *bt_ctf_field_type_integer_create(unsigned int size);
1358 int bt_ctf_field_type_integer_get_size(struct bt_ctf_field_type *integer);
1359 int bt_ctf_field_type_integer_get_signed(struct bt_ctf_field_type *integer);
1360 int bt_ctf_field_type_integer_set_signed(struct bt_ctf_field_type *integer, int is_signed);
1361 enum bt_ctf_integer_base bt_ctf_field_type_integer_get_base(struct bt_ctf_field_type *integer);
1362 int bt_ctf_field_type_integer_set_base(struct bt_ctf_field_type *integer, enum bt_ctf_integer_base base);
1363 enum ctf_string_encoding bt_ctf_field_type_integer_get_encoding(struct bt_ctf_field_type *integer);
1364 int bt_ctf_field_type_integer_set_encoding(struct bt_ctf_field_type *integer, enum ctf_string_encoding encoding);
1365 struct bt_ctf_field_type *bt_ctf_field_type_enumeration_create(struct bt_ctf_field_type *integer_container_type);
1366 struct bt_ctf_field_type *bt_ctf_field_type_enumeration_get_container_type(struct bt_ctf_field_type *enumeration);
1367 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);
1368 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);
1369 int64_t bt_ctf_field_type_enumeration_get_mapping_count(struct bt_ctf_field_type *enumeration);
1370 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);
1371 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);
1372 int bt_ctf_field_type_enumeration_get_mapping_index_by_name(struct bt_ctf_field_type *enumeration, const char *name, size_t *OUTPUT);
1373 int bt_ctf_field_type_enumeration_get_mapping_index_by_value(struct bt_ctf_field_type *enumeration, int64_t value, size_t *OUTPUT);
1374 int bt_ctf_field_type_enumeration_get_mapping_index_by_unsigned_value(struct bt_ctf_field_type *enumeration, uint64_t value, size_t *OUTPUT);
1375 struct bt_ctf_field_type *bt_ctf_field_type_floating_point_create(void);
1376 int bt_ctf_field_type_floating_point_get_exponent_digits(struct bt_ctf_field_type *floating_point);
1377 int bt_ctf_field_type_floating_point_set_exponent_digits(struct bt_ctf_field_type *floating_point, unsigned int exponent_digits);
1378 int bt_ctf_field_type_floating_point_get_mantissa_digits(struct bt_ctf_field_type *floating_point);
1379 int bt_ctf_field_type_floating_point_set_mantissa_digits(struct bt_ctf_field_type *floating_point, unsigned int mantissa_digits);
1380 struct bt_ctf_field_type *bt_ctf_field_type_structure_create(void);
1381 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);
1382 int64_t bt_ctf_field_type_structure_get_field_count(struct bt_ctf_field_type *structure);
1383 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);
1384 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);
1385 struct bt_ctf_field_type *bt_ctf_field_type_variant_create(struct bt_ctf_field_type *enum_tag, const char *tag_name);
1386 struct bt_ctf_field_type *bt_ctf_field_type_variant_get_tag_type(struct bt_ctf_field_type *variant);
1387 const char *bt_ctf_field_type_variant_get_tag_name(struct bt_ctf_field_type *variant);
1388 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);
1389 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);
1390 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);
1391 int64_t bt_ctf_field_type_variant_get_field_count(struct bt_ctf_field_type *variant);
1392 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);
1393 struct bt_ctf_field_type *bt_ctf_field_type_array_create(struct bt_ctf_field_type *element_type, unsigned int length);
1394 struct bt_ctf_field_type *bt_ctf_field_type_array_get_element_type(struct bt_ctf_field_type *array);
1395 int64_t bt_ctf_field_type_array_get_length(struct bt_ctf_field_type *array);
1396 struct bt_ctf_field_type *bt_ctf_field_type_sequence_create(struct bt_ctf_field_type *element_type, const char *length_field_name);
1397 struct bt_ctf_field_type *bt_ctf_field_type_sequence_get_element_type(struct bt_ctf_field_type *sequence);
1398 const char *bt_ctf_field_type_sequence_get_length_field_name(struct bt_ctf_field_type *sequence);
1399 struct bt_ctf_field_type *bt_ctf_field_type_string_create(void);
1400 enum ctf_string_encoding bt_ctf_field_type_string_get_encoding(struct bt_ctf_field_type *string_type);
1401 int bt_ctf_field_type_string_set_encoding(struct bt_ctf_field_type *string_type, enum ctf_string_encoding encoding);
1402 int bt_ctf_field_type_get_alignment(struct bt_ctf_field_type *type);
1403 int bt_ctf_field_type_set_alignment(struct bt_ctf_field_type *type, unsigned int alignment);
1404 enum bt_ctf_byte_order bt_ctf_field_type_get_byte_order(struct bt_ctf_field_type *type);
1405 int bt_ctf_field_type_set_byte_order(struct bt_ctf_field_type *type, enum bt_ctf_byte_order byte_order);
1406 enum ctf_type_id bt_ctf_field_type_get_type_id(struct bt_ctf_field_type *type);
1407 void bt_ctf_field_type_get(struct bt_ctf_field_type *type);
1408 void bt_ctf_field_type_put(struct bt_ctf_field_type *type);
1410 /* =================================================================
1412 ¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯
1414 %rename("_bt_ctf_field_create") bt_ctf_field_create(struct bt_ctf_field_type *type);
1415 %rename("_bt_ctf_field_structure_get_field") bt_ctf_field_structure_get_field(struct bt_ctf_field *structure, const char *name);
1416 %rename("_bt_ctf_field_array_get_field") bt_ctf_field_array_get_field(struct bt_ctf_field *array, uint64_t index);
1417 %rename("_bt_ctf_field_sequence_get_length") bt_ctf_field_sequence_get_length(struct bt_ctf_field *sequence);
1418 %rename("_bt_ctf_field_sequence_set_length") bt_ctf_field_sequence_set_length(struct bt_ctf_field *sequence, struct bt_ctf_field *length_field);
1419 %rename("_bt_ctf_field_sequence_get_field") bt_ctf_field_sequence_get_field(struct bt_ctf_field *sequence, uint64_t index);
1420 %rename("_bt_ctf_field_variant_get_field") bt_ctf_field_variant_get_field(struct bt_ctf_field *variant, struct bt_ctf_field *tag);
1421 %rename("_bt_ctf_field_enumeration_get_container") bt_ctf_field_enumeration_get_container(struct bt_ctf_field *enumeration);
1422 %rename("_bt_ctf_field_enumeration_get_mapping_name") bt_ctf_field_enumeration_get_mapping_name(struct bt_ctf_field *enumeration);
1423 %rename("_bt_ctf_field_signed_integer_get_value") bt_ctf_field_signed_integer_get_value(struct bt_ctf_field *integer, int64_t *value);
1424 %rename("_bt_ctf_field_signed_integer_set_value") bt_ctf_field_signed_integer_set_value(struct bt_ctf_field *integer, int64_t value);
1425 %rename("_bt_ctf_field_unsigned_integer_get_value") bt_ctf_field_unsigned_integer_get_value(struct bt_ctf_field *integer, uint64_t *value);
1426 %rename("_bt_ctf_field_unsigned_integer_set_value") bt_ctf_field_unsigned_integer_set_value(struct bt_ctf_field *integer, uint64_t value);
1427 %rename("_bt_ctf_field_floating_point_get_value") bt_ctf_field_floating_point_get_value(struct bt_ctf_field *floating_point, double *value);
1428 %rename("_bt_ctf_field_floating_point_set_value") bt_ctf_field_floating_point_set_value(struct bt_ctf_field *floating_point, double value);
1429 %rename("_bt_ctf_field_string_get_value") bt_ctf_field_string_get_value(struct bt_ctf_field *string_field);
1430 %rename("_bt_ctf_field_string_set_value") bt_ctf_field_string_set_value(struct bt_ctf_field *string_field, const char *value);
1431 %rename("_bt_ctf_field_get_type") bt_ctf_field_get_type(struct bt_ctf_field *field);
1432 %rename("_bt_ctf_field_get") bt_ctf_field_get(struct bt_ctf_field *field);
1433 %rename("_bt_ctf_field_put") bt_ctf_field_put(struct bt_ctf_field *field);
1435 struct bt_ctf_field *bt_ctf_field_create(struct bt_ctf_field_type *type);
1436 struct bt_ctf_field *bt_ctf_field_structure_get_field(struct bt_ctf_field *structure, const char *name);
1437 struct bt_ctf_field *bt_ctf_field_array_get_field(struct bt_ctf_field *array, uint64_t index);
1438 struct bt_ctf_field * bt_ctf_field_sequence_get_length(struct bt_ctf_field *sequence);
1439 int bt_ctf_field_sequence_set_length(struct bt_ctf_field *sequence, struct bt_ctf_field *length_field);
1440 struct bt_ctf_field *bt_ctf_field_sequence_get_field(struct bt_ctf_field *sequence, uint64_t index);
1441 struct bt_ctf_field *bt_ctf_field_variant_get_field(struct bt_ctf_field *variant, struct bt_ctf_field *tag);
1442 struct bt_ctf_field *bt_ctf_field_enumeration_get_container(struct bt_ctf_field *enumeration);
1443 const char *bt_ctf_field_enumeration_get_mapping_name(struct bt_ctf_field *enumeration);
1444 int bt_ctf_field_signed_integer_get_value(struct bt_ctf_field *integer, int64_t *OUTPUT);
1445 int bt_ctf_field_signed_integer_set_value(struct bt_ctf_field *integer, int64_t value);
1446 int bt_ctf_field_unsigned_integer_get_value(struct bt_ctf_field *integer, uint64_t *OUTPUT);
1447 int bt_ctf_field_unsigned_integer_set_value(struct bt_ctf_field *integer, uint64_t value);
1448 int bt_ctf_field_floating_point_get_value(struct bt_ctf_field *floating_point, double *OUTPUT);
1449 int bt_ctf_field_floating_point_set_value(struct bt_ctf_field *floating_point, double value);
1450 const char *bt_ctf_field_string_get_value(struct bt_ctf_field *string_field);
1451 int bt_ctf_field_string_set_value(struct bt_ctf_field *string_field, const char *value);
1452 struct bt_ctf_field_type *bt_ctf_field_get_type(struct bt_ctf_field *field);
1453 void bt_ctf_field_get(struct bt_ctf_field *field);
1454 void bt_ctf_field_put(struct bt_ctf_field *field);
1456 /* =================================================================
1458 ¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯
1460 %rename("_bt_ctf_event_class_create") bt_ctf_event_class_create(const char *name);
1461 %rename("_bt_ctf_event_class_get_name") bt_ctf_event_class_get_name(struct bt_ctf_event_class *event_class);
1462 %rename("_bt_ctf_event_class_get_id") bt_ctf_event_class_get_id(struct bt_ctf_event_class *event_class);
1463 %rename("_bt_ctf_event_class_set_id") bt_ctf_event_class_set_id(struct bt_ctf_event_class *event_class, uint32_t id);
1464 %rename("_bt_ctf_event_class_get_stream_class") bt_ctf_event_class_get_stream_class(struct bt_ctf_event_class *event_class);
1465 %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);
1466 %rename("_bt_ctf_event_class_get_field_count") bt_ctf_event_class_get_field_count(struct bt_ctf_event_class *event_class);
1467 %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);
1468 %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);
1469 %rename("_bt_ctf_event_class_get") bt_ctf_event_class_get(struct bt_ctf_event_class *event_class);
1470 %rename("_bt_ctf_event_class_put") bt_ctf_event_class_put(struct bt_ctf_event_class *event_class);
1471 %rename("_bt_ctf_event_create") bt_ctf_event_create(struct bt_ctf_event_class *event_class);
1472 %rename("_bt_ctf_event_get_class") bt_ctf_event_get_class(struct bt_ctf_event *event);
1473 %rename("_bt_ctf_event_get_clock") bt_ctf_event_get_clock(struct bt_ctf_event *event);
1474 %rename("_bt_ctf_event_get_payload") bt_ctf_event_get_payload(struct bt_ctf_event *event, const char *name);
1475 %rename("_bt_ctf_event_set_payload") bt_ctf_event_set_payload(struct bt_ctf_event *event, const char *name, struct bt_ctf_field *value);
1476 %rename("_bt_ctf_event_get_payload_by_index") bt_ctf_event_get_payload_by_index(struct bt_ctf_event *event, size_t index);
1477 %rename("_bt_ctf_event_get") bt_ctf_event_get(struct bt_ctf_event *event);
1478 %rename("_bt_ctf_event_put") bt_ctf_event_put(struct bt_ctf_event *event);
1480 struct bt_ctf_event_class *bt_ctf_event_class_create(const char *name);
1481 const char *bt_ctf_event_class_get_name(struct bt_ctf_event_class *event_class);
1482 int64_t bt_ctf_event_class_get_id(struct bt_ctf_event_class *event_class);
1483 int bt_ctf_event_class_set_id(struct bt_ctf_event_class *event_class, uint32_t id);
1484 struct bt_ctf_stream_class *bt_ctf_event_class_get_stream_class(struct bt_ctf_event_class *event_class);
1485 int bt_ctf_event_class_add_field(struct bt_ctf_event_class *event_class, struct bt_ctf_field_type *type, const char *name);
1486 int64_t bt_ctf_event_class_get_field_count(struct bt_ctf_event_class *event_class);
1487 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);
1488 struct bt_ctf_field_type *bt_ctf_event_class_get_field_by_name(struct bt_ctf_event_class *event_class, const char *name);
1489 void bt_ctf_event_class_get(struct bt_ctf_event_class *event_class);
1490 void bt_ctf_event_class_put(struct bt_ctf_event_class *event_class);
1491 struct bt_ctf_event *bt_ctf_event_create(struct bt_ctf_event_class *event_class);
1492 struct bt_ctf_event_class *bt_ctf_event_get_class(struct bt_ctf_event *event);
1493 struct bt_ctf_clock *bt_ctf_event_get_clock(struct bt_ctf_event *event);
1494 struct bt_ctf_field *bt_ctf_event_get_payload(struct bt_ctf_event *event, const char *name);
1495 int bt_ctf_event_set_payload(struct bt_ctf_event *event, const char *name, struct bt_ctf_field *value);
1496 struct bt_ctf_field *bt_ctf_event_get_payload_by_index(struct bt_ctf_event *event, size_t index);
1497 void bt_ctf_event_get(struct bt_ctf_event *event);
1498 void bt_ctf_event_put(struct bt_ctf_event *event);
1500 /* =================================================================
1502 ¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯
1504 %rename("_bt_ctf_stream_class_create") bt_ctf_stream_class_create(const char *name);
1505 %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);
1506 %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);
1507 %rename("_bt_ctf_stream_class_get") bt_ctf_stream_class_get(struct bt_ctf_stream_class *stream_class);
1508 %rename("_bt_ctf_stream_class_put") bt_ctf_stream_class_put(struct bt_ctf_stream_class *stream_class);
1509 %rename("_bt_ctf_stream_append_discarded_events") bt_ctf_stream_append_discarded_events(struct bt_ctf_stream *stream, uint64_t event_count);
1510 %rename("_bt_ctf_stream_append_event") bt_ctf_stream_append_event(struct bt_ctf_stream *stream, struct bt_ctf_event *event);
1511 %rename("_bt_ctf_stream_flush") bt_ctf_stream_flush(struct bt_ctf_stream *stream);
1512 %rename("_bt_ctf_stream_get") bt_ctf_stream_get(struct bt_ctf_stream *stream);
1513 %rename("_bt_ctf_stream_put") bt_ctf_stream_put(struct bt_ctf_stream *stream);
1515 struct bt_ctf_stream_class *bt_ctf_stream_class_create(const char *name);
1516 int bt_ctf_stream_class_set_clock(struct bt_ctf_stream_class *stream_class, struct bt_ctf_clock *clock);
1517 int bt_ctf_stream_class_add_event_class(struct bt_ctf_stream_class *stream_class, struct bt_ctf_event_class *event_class);
1518 void bt_ctf_stream_class_get(struct bt_ctf_stream_class *stream_class);
1519 void bt_ctf_stream_class_put(struct bt_ctf_stream_class *stream_class);
1520 void bt_ctf_stream_append_discarded_events(struct bt_ctf_stream *stream, uint64_t event_count);
1521 int bt_ctf_stream_append_event(struct bt_ctf_stream *stream, struct bt_ctf_event *event);
1522 int bt_ctf_stream_flush(struct bt_ctf_stream *stream);
1523 void bt_ctf_stream_get(struct bt_ctf_stream *stream);
1524 void bt_ctf_stream_put(struct bt_ctf_stream *stream);
1526 /* =================================================================
1528 ¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯
1530 %rename("_bt_ctf_writer_create") bt_ctf_writer_create(const char *path);
1531 %rename("_bt_ctf_writer_create_stream") bt_ctf_writer_create_stream(struct bt_ctf_writer *writer, struct bt_ctf_stream_class *stream_class);
1532 %rename("_bt_ctf_writer_add_environment_field") bt_ctf_writer_add_environment_field(struct bt_ctf_writer *writer, const char *name, const char *value);
1533 %rename("_bt_ctf_writer_add_clock") bt_ctf_writer_add_clock(struct bt_ctf_writer *writer, struct bt_ctf_clock *clock);
1534 %newobject bt_ctf_writer_get_metadata_string;
1535 %rename("_bt_ctf_writer_get_metadata_string") bt_ctf_writer_get_metadata_string(struct bt_ctf_writer *writer);
1536 %rename("_bt_ctf_writer_flush_metadata") bt_ctf_writer_flush_metadata(struct bt_ctf_writer *writer);
1537 %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);
1538 %rename("_bt_ctf_writer_get") bt_ctf_writer_get(struct bt_ctf_writer *writer);
1539 %rename("_bt_ctf_writer_put") bt_ctf_writer_put(struct bt_ctf_writer *writer);
1541 struct bt_ctf_writer *bt_ctf_writer_create(const char *path);
1542 struct bt_ctf_stream *bt_ctf_writer_create_stream(struct bt_ctf_writer *writer, struct bt_ctf_stream_class *stream_class);
1543 int bt_ctf_writer_add_environment_field(struct bt_ctf_writer *writer, const char *name, const char *value);
1544 int bt_ctf_writer_add_clock(struct bt_ctf_writer *writer, struct bt_ctf_clock *clock);
1545 char *bt_ctf_writer_get_metadata_string(struct bt_ctf_writer *writer);
1546 void bt_ctf_writer_flush_metadata(struct bt_ctf_writer *writer);
1547 int bt_ctf_writer_set_byte_order(struct bt_ctf_writer *writer, enum bt_ctf_byte_order byte_order);
1548 void bt_ctf_writer_get(struct bt_ctf_writer *writer);
1549 void bt_ctf_writer_put(struct bt_ctf_writer *writer);
1554 # Used to compare to -1ULL in error checks
1555 _MAX_UINT64 = 0xFFFFFFFFFFFFFFFF
1558 Enumeration mapping class. start and end values are inclusive.
1560 class EnumerationMapping:
1561 def __init__(self, name, start, end):
1567 def __init__(self, name):
1568 self._c = _bt_ctf_clock_create(name)
1570 raise ValueError("Invalid clock name.")
1573 _bt_ctf_clock_put(self._c)
1576 Get the clock's name.
1580 name = _bt_ctf_clock_get_name(self._c)
1582 raise ValueError("Invalid clock instance.")
1586 Get the clock's description. None if unset.
1589 def description(self):
1590 return _bt_ctf_clock_get_description(self._c)
1593 Set the clock's description. The description appears in the clock's TSDL
1597 def description(self, desc):
1598 ret = _bt_ctf_clock_set_description(self._c, str(desc))
1600 raise ValueError("Invalid clock description.")
1603 Get the clock's frequency (Hz).
1606 def frequency(self):
1607 freq = _bt_ctf_clock_get_frequency(self._c)
1608 if freq == CTFWriter._MAX_UINT64:
1609 raise ValueError("Invalid clock instance")
1613 Set the clock's frequency (Hz).
1616 def frequency(self, freq):
1617 ret = _bt_ctf_clock_set_frequency(self._c, freq)
1619 raise ValueError("Invalid frequency value.")
1622 Get the clock's precision (in clock ticks).
1625 def precision(self):
1626 precision = _bt_ctf_clock_get_precision(self._c)
1627 if precision == CTFWriter._MAX_UINT64:
1628 raise ValueError("Invalid clock instance")
1632 Set the clock's precision (in clock ticks).
1635 def precision(self, precision):
1636 ret = _bt_ctf_clock_set_precision(self._c, precision)
1639 Get the clock's offset in seconds from POSIX.1 Epoch.
1642 def offset_seconds(self):
1643 offset_s = _bt_ctf_clock_get_offset_s(self._c)
1644 if offset_s == CTFWriter._MAX_UINT64:
1645 raise ValueError("Invalid clock instance")
1649 Set the clock's offset in seconds from POSIX.1 Epoch.
1651 @offset_seconds.setter
1652 def offset_seconds(self, offset_s):
1653 ret = _bt_ctf_clock_set_offset_s(self._c, offset_s)
1655 raise ValueError("Invalid offset value.")
1658 Get the clock's offset in ticks from POSIX.1 Epoch + offset in seconds.
1662 offset = _bt_ctf_clock_get_offset(self._c)
1663 if offset == CTFWriter._MAX_UINT64:
1664 raise ValueError("Invalid clock instance")
1668 Set the clock's offset in ticks from POSIX.1 Epoch + offset in seconds.
1671 def offset(self, offset):
1672 ret = _bt_ctf_clock_set_offset(self._c, offset)
1674 raise ValueError("Invalid offset value.")
1677 Get a clock's absolute attribute. A clock is absolute if the clock
1678 is a global reference across the trace's other clocks.
1682 is_absolute = _bt_ctf_clock_get_is_absolute(self._c)
1683 if is_absolute == -1:
1684 raise ValueError("Invalid clock instance")
1685 return False if is_absolute == 0 else True
1688 Set a clock's absolute attribute. A clock is absolute if the clock
1689 is a global reference across the trace's other clocks.
1692 def absolute(self, is_absolute):
1693 ret = _bt_ctf_clock_set_is_absolute(self._c, int(is_absolute))
1695 raise ValueError("Could not set the clock's absolute attribute.")
1698 Get the current time in nanoseconds since the clock's origin (offset and
1699 offset_s attributes).
1703 time = _bt_ctf_clock_get_time(self._c)
1704 if time == CTFWriter._MAX_UINT64:
1705 raise ValueError("Invalid clock instance")
1709 Set the current time in nanoseconds since the clock's origin (offset and
1710 offset_s attributes). The clock's value will be sampled as events are
1711 appended to a stream.
1714 def time(self, time):
1715 ret = _bt_ctf_clock_set_time(self._c, time)
1717 raise ValueError("Invalid time value.")
1719 class FieldDeclaration:
1721 FieldDeclaration should not be instantiated directly. Instantiate
1722 one of the concrete FieldDeclaration classes.
1725 # These values are based on the bt_ctf_integer_base enum
1726 # declared in event-types.h.
1727 INTEGER_BASE_UNKNOWN = -1
1728 INTEGER_BASE_BINARY = 2
1729 INTEGER_BASE_OCTAL = 8
1730 INTEGER_BASE_DECIMAL = 10
1731 INTEGER_BASE_HEXADECIMAL = 16
1734 if self._ft is None:
1735 raise ValueError("FieldDeclaration creation failed.")
1738 _bt_ctf_field_type_put(self._ft)
1741 def _create_field_declaration_from_native_instance(native_field_declaration):
1743 CTFTypeId.INTEGER : CTFWriter.IntegerFieldDeclaration,
1744 CTFTypeId.FLOAT : CTFWriter.FloatFieldDeclaration,
1745 CTFTypeId.ENUM : CTFWriter.EnumerationFieldDeclaration,
1746 CTFTypeId.STRING : CTFWriter.StringFieldDeclaration,
1747 CTFTypeId.STRUCT : CTFWriter.StructureFieldDeclaration,
1748 CTFTypeId.VARIANT : CTFWriter.VariantFieldDeclaration,
1749 CTFTypeId.ARRAY : CTFWriter.ArrayFieldDeclaration,
1750 CTFTypeId.SEQUENCE : CTFWriter.SequenceFieldDeclaration
1753 field_type_id = _bt_ctf_field_type_get_type_id(native_field_declaration)
1754 if field_type_id == CTFTypeId.UNKNOWN:
1755 raise TypeError("Invalid field instance")
1757 declaration = CTFWriter.Field.__new__(CTFWriter.Field)
1758 declaration._ft = native_field_declaration
1759 declaration.__class__ = type_dict[field_type_id]
1763 Get the field declaration's alignment. Returns -1 on error.
1766 def alignment(self):
1767 return _bt_ctf_field_type_get_alignment(self._ft)
1770 Set the field declaration's alignment. Defaults to 1 (bit-aligned). However,
1771 some types, such as structures and string, may impose other alignment
1775 def alignment(self, alignment):
1776 ret = _bt_ctf_field_type_set_alignment(self._ft, alignment)
1778 raise ValueError("Invalid alignment value.")
1781 Get the field declaration's byte order. One of the ByteOrder's constant.
1784 def byte_order(self):
1785 return _bt_ctf_field_type_get_byte_order(self._ft)
1788 Set the field declaration's byte order. Use constants defined in the ByteOrder
1792 def byte_order(self, byte_order):
1793 ret = _bt_ctf_field_type_set_byte_order(self._ft, byte_order)
1795 raise ValueError("Could not set byte order value.")
1797 class IntegerFieldDeclaration(FieldDeclaration):
1799 Create a new integer field declaration of the given size.
1801 def __init__(self, size):
1802 self._ft = _bt_ctf_field_type_integer_create(size)
1806 Get an integer's size.
1810 ret = _bt_ctf_field_type_integer_get_size(self._ft)
1812 raise ValueError("Could not get Integer's size attribute.")
1817 Get an integer's signedness attribute.
1821 ret = _bt_ctf_field_type_integer_get_signed(self._ft)
1823 raise ValueError("Could not get Integer's signed attribute.")
1830 Set an integer's signedness attribute.
1833 def signed(self, signed):
1834 ret = _bt_ctf_field_type_integer_set_signed(self._ft, signed)
1836 raise ValueError("Could not set Integer's signed attribute.")
1839 Get the integer's base used to pretty-print the resulting trace.
1840 Returns a constant from the FieldDeclaration.IntegerBase class.
1844 return _bt_ctf_field_type_integer_get_base(self._ft)
1847 Set the integer's base used to pretty-print the resulting trace.
1848 The base must be a constant of the FieldDeclarationIntegerBase class.
1851 def base(self, base):
1852 ret = _bt_ctf_field_type_integer_set_base(self._ft, base)
1854 raise ValueError("Could not set Integer's base.")
1857 Get the integer's encoding (one of the constants of the
1858 CTFStringEncoding class).
1859 Returns a constant from the CTFStringEncoding class.
1863 return _bt_ctf_field_type_integer_get_encoding(self._ft)
1866 An integer encoding may be set to signal that the integer must be printed
1867 as a text character. Must be a constant from the CTFStringEncoding class.
1870 def encoding(self, encoding):
1871 ret = _bt_ctf_field_type_integer_set_encoding(self._ft, encoding)
1873 raise ValueError("Could not set Integer's encoding.")
1875 class EnumerationFieldDeclaration(FieldDeclaration):
1877 Create a new enumeration field declaration with the given underlying container type.
1879 def __init__(self, integer_type):
1880 if integer_type is None or not isinstance(integer_type, CTFWriter.IntegerFieldDeclaration):
1881 raise TypeError("Invalid integer container.")
1883 self._ft = _bt_ctf_field_type_enumeration_create(integer_type._ft)
1887 Get the enumeration's underlying container type.
1890 def container(self):
1891 ret = _bt_ctf_field_type_enumeration_get_container_type(self._ft)
1893 raise TypeError("Invalid enumeration declaration")
1894 return CTFWriter.FieldDeclaration._create_field_declaration_from_native_instance(ret)
1897 Add a mapping to the enumeration. The range's values are inclusive.
1899 def add_mapping(self, name, range_start, range_end):
1900 if range_start < 0 or range_end < 0:
1901 ret = _bt_ctf_field_type_enumeration_add_mapping(self._ft, str(name), range_start, range_end)
1903 ret = _bt_ctf_field_type_enumeration_add_mapping_unsigned(self._ft, str(name), range_start, range_end)
1906 raise ValueError("Could not add mapping to enumeration declaration.")
1909 Generator returning instances of EnumerationMapping.
1913 signed = self.container.signed
1915 count = _bt_ctf_field_type_enumeration_get_mapping_count(self._ft)
1916 for i in range(count):
1918 ret = _bt_python_ctf_field_type_enumeration_get_mapping(self._ft, i)
1920 ret = _bt_python_ctf_field_type_enumeration_get_mapping_unsigned(self._ft, i)
1923 raise TypeError("Could not get Enumeration mapping at index {}".format(i))
1924 name, range_start, range_end = ret
1925 yield CTFWriter.EnumerationMapping(name, range_start, range_end)
1928 Get a mapping by name (EnumerationMapping).
1930 def get_mapping_by_name(self, name):
1931 ret, index = _bt_ctf_field_type_enumeration_get_mapping_index_by_name(self._ft, name);
1935 if self.container.signed:
1936 ret = _bt_python_ctf_field_type_enumeration_get_mapping(self._ft, index)
1938 ret = _bt_python_ctf_field_type_enumeration_get_mapping_unsigned(self._ft, index)
1941 raise TypeError("Could not get Enumeration mapping at index {}".format(i))
1942 name, range_start, range_end = ret
1943 return CTFWriter.EnumerationMapping(name, range_start, range_end)
1946 Get a mapping by value (EnumerationMapping).
1948 def get_mapping_by_value(self, value):
1950 ret, index = _bt_ctf_field_type_enumeration_get_mapping_index_by_value(self._ft, value);
1952 ret, index = _bt_ctf_field_type_enumeration_get_mapping_index_by_unsigned_value(self._ft, value);
1957 if self.container.signed:
1958 ret = _bt_python_ctf_field_type_enumeration_get_mapping(self._ft, index)
1960 ret = _bt_python_ctf_field_type_enumeration_get_mapping_unsigned(self._ft, index)
1963 raise TypeError("Could not get Enumeration mapping at index {}".format(i))
1964 name, range_start, range_end = ret
1965 return CTFWriter.EnumerationMapping(name, range_start, range_end)
1967 class FloatFieldDeclaration(FieldDeclaration):
1974 Create a new floating point field declaration.
1977 self._ft = _bt_ctf_field_type_floating_point_create()
1981 Get the number of exponent digits used to store the floating point field.
1984 def exponent_digits(self):
1985 ret = _bt_ctf_field_type_floating_point_get_exponent_digits(self._ft)
1987 raise TypeError("Could not get Floating point exponent digit count")
1991 Set the number of exponent digits to use to store the floating point field.
1992 The only values currently supported are FLT_EXP_DIG and DBL_EXP_DIG which
1993 are defined as constants of this class.
1995 @exponent_digits.setter
1996 def exponent_digits(self, exponent_digits):
1997 ret = _bt_ctf_field_type_floating_point_set_exponent_digits(self._ft, exponent_digits)
1999 raise ValueError("Could not set exponent digit count.")
2002 Get the number of mantissa digits used to store the floating point field.
2005 def mantissa_digits(self):
2006 ret = _bt_ctf_field_type_floating_point_get_mantissa_digits(self._ft)
2008 raise TypeError("Could not get Floating point mantissa digit count")
2012 Set the number of mantissa digits to use to store the floating point field.
2013 The only values currently supported are FLT_MANT_DIG and DBL_MANT_DIG which
2014 are defined as constants of this class.
2016 @mantissa_digits.setter
2017 def mantissa_digits(self, mantissa_digits):
2018 ret = _bt_ctf_field_type_floating_point_set_mantissa_digits(self._ft, mantissa_digits)
2020 raise ValueError("Could not set mantissa digit count.")
2022 class StructureFieldDeclaration(FieldDeclaration):
2024 Create a new structure field declaration.
2027 self._ft = _bt_ctf_field_type_structure_create()
2031 Add a field of type "field_type" to the structure.
2033 def add_field(self, field_type, field_name):
2034 ret = _bt_ctf_field_type_structure_add_field(self._ft, field_type._ft, str(field_name))
2036 raise ValueError("Could not add field to structure.")
2039 Generator returning the structure's field as tuples of (field name, field declaration).
2043 count = _bt_ctf_field_type_structure_get_field_count(self._ft)
2045 raise TypeError("Could not get Structure field count")
2047 for i in range(count):
2048 field_name = _bt_python_ctf_field_type_structure_get_field_name(self._ft, i)
2049 if field_name is None:
2050 raise TypeError("Could not get Structure field name at index {}".format(i))
2052 field_type_native = _bt_python_ctf_field_type_structure_get_field_type(self._ft, i)
2053 if field_type_native is None:
2054 raise TypeError("Could not get Structure field type at index {}".format(i))
2056 field_type = CTFWriter.FieldDeclaration._create_field_declaration_from_native_instance(field_type_native)
2057 yield (field_name, field_type)
2060 Get a field declaration by name (FieldDeclaration).
2062 def get_field_by_name(self, name):
2063 field_type_native = _bt_ctf_field_type_structure_get_field_type_by_name(self._ft, name)
2064 if field_type_native is None:
2065 raise TypeError("Could not find Structure field with name {}".format(name))
2067 return CTFWriter.FieldDeclaration._create_field_declaration_from_native_instance(field_type_native)
2069 class VariantFieldDeclaration(FieldDeclaration):
2071 Create a new variant field declaration.
2073 def __init__(self, enum_tag, tag_name):
2074 if enum_tag is None or not isinstance(enum_tag, CTFWriter.EnumerationFieldDeclaration):
2075 raise TypeError("Invalid tag type; must be of type EnumerationFieldDeclaration.")
2077 self._ft = _bt_ctf_field_type_variant_create(enum_tag._ft, str(tag_name))
2081 Get the variant's tag name.
2085 ret = _bt_ctf_field_type_variant_get_tag_name(self._ft)
2087 raise TypeError("Could not get Variant tag name")
2091 Get the variant's tag type.
2095 ret = _bt_ctf_field_type_variant_get_tag_type(self._ft)
2097 raise TypeError("Could not get Variant tag type")
2098 return CTFWriter.FieldDeclaration._create_field_declaration_from_native_instance(ret)
2101 Add a field of type "field_type" to the variant.
2103 def add_field(self, field_type, field_name):
2104 ret = _bt_ctf_field_type_variant_add_field(self._ft, field_type._ft, str(field_name))
2106 raise ValueError("Could not add field to variant.")
2109 Generator returning the variant's field as tuples of (field name, field declaration).
2113 count = _bt_ctf_field_type_variant_get_field_count(self._ft)
2115 raise TypeError("Could not get Variant field count")
2117 for i in range(count):
2118 field_name = _bt_python_ctf_field_type_variant_get_field_name(self._ft, i)
2119 if field_name is None:
2120 raise TypeError("Could not get Variant field name at index {}".format(i))
2122 field_type_native = _bt_python_ctf_field_type_variant_get_field_type(self._ft, i)
2123 if field_type_native is None:
2124 raise TypeError("Could not get Variant field type at index {}".format(i))
2126 field_type = CTFWriter.FieldDeclaration._create_field_declaration_from_native_instance(field_type_native)
2127 yield (field_name, field_type)
2130 Get a field declaration by name (FieldDeclaration).
2132 def get_field_by_name(self, name):
2133 field_type_native = _bt_ctf_field_type_variant_get_field_type_by_name(self._ft, name)
2134 if field_type_native is None:
2135 raise TypeError("Could not find Variant field with name {}".format(name))
2137 return CTFWriter.FieldDeclaration._create_field_declaration_from_native_instance(field_type_native)
2140 Get a field declaration from tag (EnumerationField).
2142 def get_field_from_tag(self, tag):
2143 field_type_native = _bt_ctf_field_type_variant_get_field_type_from_tag(self._ft, tag._f)
2144 if field_type_native is None:
2145 raise TypeError("Could not find Variant field with tag value {}".format(tag.value))
2147 return CTFWriter.FieldDeclaration._create_field_declaration_from_native_instance(field_type_native)
2149 class ArrayFieldDeclaration(FieldDeclaration):
2151 Create a new array field declaration.
2153 def __init__(self, element_type, length):
2154 self._ft = _bt_ctf_field_type_array_create(element_type._ft, length)
2158 Get the array's element type.
2161 def element_type(self):
2162 ret = _bt_ctf_field_type_array_get_element_type(self._ft)
2164 raise TypeError("Could not get Array element type")
2165 return CTFWriter.FieldDeclaration._create_field_declaration_from_native_instance(ret)
2168 Get the array's length.
2172 ret = _bt_ctf_field_type_array_get_length(self._ft)
2174 raise TypeError("Could not get Array length")
2177 class SequenceFieldDeclaration(FieldDeclaration):
2179 Create a new sequence field declaration.
2181 def __init__(self, element_type, length_field_name):
2182 self._ft = _bt_ctf_field_type_sequence_create(element_type._ft, str(length_field_name))
2186 Get the sequence's element type.
2189 def element_type(self):
2190 ret = _bt_ctf_field_type_sequence_get_element_type(self._ft)
2192 raise TypeError("Could not get Sequence element type")
2193 return CTFWriter.FieldDeclaration._create_field_declaration_from_native_instance(ret)
2196 Get the sequence's length field name.
2199 def length_field_name(self):
2200 ret = _bt_ctf_field_type_sequence_get_length_field_name(self._ft)
2202 raise TypeError("Could not get Sequence length field name")
2205 class StringFieldDeclaration(FieldDeclaration):
2207 Create a new string field declaration.
2210 self._ft = _bt_ctf_field_type_string_create()
2214 Get a string declaration's encoding (a constant from the CTFStringEncoding class).
2218 return _bt_ctf_field_type_string_get_encoding(self._ft)
2221 Set a string declaration's encoding. Must be a constant from the CTFStringEncoding class.
2224 def encoding(self, encoding):
2225 ret = _bt_ctf_field_type_string_set_encoding(self._ft, encoding)
2227 raise ValueError("Could not set string encoding.")
2230 Create an instance of a field.
2233 def create_field(field_type):
2234 if field_type is None or not isinstance(field_type, CTFWriter.FieldDeclaration):
2235 raise TypeError("Invalid field_type. Type must be a FieldDeclaration-derived class.")
2237 if isinstance(field_type, CTFWriter.IntegerFieldDeclaration):
2238 return CTFWriter.IntegerField(field_type)
2239 elif isinstance(field_type, CTFWriter.EnumerationFieldDeclaration):
2240 return CTFWriter.EnumerationField(field_type)
2241 elif isinstance(field_type, CTFWriter.FloatFieldDeclaration):
2242 return CTFWriter.FloatFieldingPoint(field_type)
2243 elif isinstance(field_type, CTFWriter.StructureFieldDeclaration):
2244 return CTFWriter.StructureField(field_type)
2245 elif isinstance(field_type, CTFWriter.VariantFieldDeclaration):
2246 return CTFWriter.VariantField(field_type)
2247 elif isinstance(field_type, CTFWriter.ArrayFieldDeclaration):
2248 return CTFWriter.ArrayField(field_type)
2249 elif isinstance(field_type, CTFWriter.SequenceFieldDeclaration):
2250 return CTFWriter.SequenceField(field_type)
2251 elif isinstance(field_type, CTFWriter.StringFieldDeclaration):
2252 return CTFWriter.StringField(field_type)
2256 Base class, do not instantiate.
2258 def __init__(self, field_type):
2259 if not isinstance(field_type, CTFWriter.FieldDeclaration):
2260 raise TypeError("Invalid field_type argument.")
2262 self._f = _bt_ctf_field_create(field_type._ft)
2264 raise ValueError("Field creation failed.")
2267 _bt_ctf_field_put(self._f)
2270 def _create_field_from_native_instance(native_field_instance):
2272 CTFTypeId.INTEGER : CTFWriter.IntegerField,
2273 CTFTypeId.FLOAT : CTFWriter.FloatFieldingPoint,
2274 CTFTypeId.ENUM : CTFWriter.EnumerationField,
2275 CTFTypeId.STRING : CTFWriter.StringField,
2276 CTFTypeId.STRUCT : CTFWriter.StructureField,
2277 CTFTypeId.VARIANT : CTFWriter.VariantField,
2278 CTFTypeId.ARRAY : CTFWriter.ArrayField,
2279 CTFTypeId.SEQUENCE : CTFWriter.SequenceField
2282 field_type = _bt_python_get_field_type(native_field_instance)
2283 if field_type == CTFTypeId.UNKNOWN:
2284 raise TypeError("Invalid field instance")
2286 field = CTFWriter.Field.__new__(CTFWriter.Field)
2287 field._f = native_field_instance
2288 field.__class__ = type_dict[field_type]
2292 def declaration(self):
2293 native_field_type = _bt_ctf_field_get_type(self._f)
2294 if native_field_type is None:
2295 raise TypeError("Invalid field instance")
2296 return CTFWriter.FieldDeclaration._create_field_declaration_from_native_instance(native_field_type)
2298 class IntegerField(Field):
2300 Get an integer field's value.
2304 signedness = _bt_python_field_integer_get_signedness(self._f)
2306 raise TypeError("Invalid integer instance.")
2309 ret, value = _bt_ctf_field_unsigned_integer_get_value(self._f)
2311 ret, value = _bt_ctf_field_signed_integer_get_value(self._f)
2314 raise ValueError("Could not get integer field value.")
2318 Set an integer field's value.
2321 def value(self, value):
2322 if not isinstance(value, int):
2323 raise TypeError("IntegerField's value must be an int")
2325 signedness = _bt_python_field_integer_get_signedness(self._f)
2327 raise TypeError("Invalid integer instance.")
2330 ret = _bt_ctf_field_unsigned_integer_set_value(self._f, value)
2332 ret = _bt_ctf_field_signed_integer_set_value(self._f, value)
2335 raise ValueError("Could not set integer field value.")
2337 class EnumerationField(Field):
2339 Return the enumeration's underlying container field (an integer field).
2342 def container(self):
2343 container = CTFWriter.IntegerField.__new__(CTFWriter.IntegerField)
2344 container._f = _bt_ctf_field_enumeration_get_container(self._f)
2345 if container._f is None:
2346 raise TypeError("Invalid enumeration field type.")
2350 Get the enumeration field's mapping name.
2354 value = _bt_ctf_field_enumeration_get_mapping_name(self._f)
2356 raise ValueError("Could not get enumeration's mapping name.")
2360 Set the enumeration field's value. Must be an integer as mapping names
2364 def value(self, value):
2365 if not isinstance(value, int):
2366 raise TypeError("EnumerationField value must be an int")
2367 self.container.value = value
2369 class FloatFieldingPoint(Field):
2371 Get a floating point field's value.
2375 ret, value = _bt_ctf_field_floating_point_get_value(self._f)
2377 raise ValueError("Could not get floating point field value.")
2381 Set a floating point field's value.
2384 def value(self, value):
2385 if not isinstance(value, int) and not isinstance(value, float):
2386 raise TypeError("Value must be either a float or an int")
2388 ret = _bt_ctf_field_floating_point_set_value(self._f, float(value))
2390 raise ValueError("Could not set floating point field value.")
2392 class StructureField(Field):
2394 Get the structure's field corresponding to the provided field name.
2396 def field(self, field_name):
2397 native_instance = _bt_ctf_field_structure_get_field(self._f, str(field_name))
2398 if native_instance is None:
2399 raise ValueError("Invalid field_name provided.")
2400 return CTFWriter.Field._create_field_from_native_instance(native_instance)
2402 class VariantField(Field):
2404 Return the variant's selected field. The "tag" field is the selector enum field.
2406 def field(self, tag):
2407 native_instance = _bt_ctf_field_variant_get_field(self._f, tag._f)
2408 if native_instance is None:
2409 raise ValueError("Invalid tag provided.")
2410 return CTFWriter.Field._create_field_from_native_instance(native_instance)
2412 class ArrayField(Field):
2414 Return the array's field at position "index".
2416 def field(self, index):
2417 native_instance = _bt_ctf_field_array_get_field(self._f, index)
2418 if native_instance is None:
2419 raise IndexError("Invalid index provided.")
2420 return CTFWriter.Field._create_field_from_native_instance(native_instance)
2422 class SequenceField(Field):
2424 Get the sequence's length field (IntegerField).
2428 native_instance = _bt_ctf_field_sequence_get_length(self._f)
2429 if native_instance is None:
2431 return CTFWriter.Field._create_field_from_native_instance(native_instance)
2434 Set the sequence's length field (IntegerField).
2437 def length(self, length_field):
2438 if not isinstance(length_field, CTFWriter.IntegerField):
2439 raise TypeError("Invalid length field.")
2440 if length_field.declaration.signed:
2441 raise TypeError("Sequence field length must be unsigned")
2442 ret = _bt_ctf_field_sequence_set_length(self._f, length_field._f)
2444 raise ValueError("Could not set sequence length.")
2447 Return the sequence's field at position "index".
2449 def field(self, index):
2450 native_instance = _bt_ctf_field_sequence_get_field(self._f, index)
2451 if native_instance is None:
2452 raise ValueError("Could not get sequence element at index.")
2453 return CTFWriter.Field._create_field_from_native_instance(native_instance)
2455 class StringField(Field):
2457 Get a string field's value.
2461 return _bt_ctf_field_string_get_value(self._f)
2464 Set a string field's value.
2467 def value(self, value):
2468 ret = _bt_ctf_field_string_set_value(self._f, str(value))
2470 raise ValueError("Could not set string field value.")
2474 Create a new event class of the given name.
2476 def __init__(self, name):
2477 self._ec = _bt_ctf_event_class_create(name)
2478 if self._ec is None:
2479 raise ValueError("Event class creation failed.")
2482 _bt_ctf_event_class_put(self._ec)
2485 Add a field of type "field_type" to the event class.
2487 def add_field(self, field_type, field_name):
2488 ret = _bt_ctf_event_class_add_field(self._ec, field_type._ft, str(field_name))
2490 raise ValueError("Could not add field to event class.")
2493 Get the event class' name.
2497 name = _bt_ctf_event_class_get_name(self._ec)
2499 raise TypeError("Could not get EventClass name")
2503 Get the event class' id. Returns a negative value if unset.
2507 id = _bt_ctf_event_class_get_id(self._ec)
2509 raise TypeError("Could not get EventClass name")
2513 Set the event class' id. Throws a TypeError if the event class
2514 is already registered to a stream class.
2518 ret = _bt_ctf_event_class_set_id(self._ec, id)
2520 raise TypeError("Can't change an Event Class's id after it has been assigned to a stream class")
2523 Get the event class' stream class. Returns None if unset.
2526 def stream_class(self):
2527 stream_class_native = _bt_ctf_event_class_get_stream_class(self._ec)
2528 if stream_class_native is None:
2530 stream_class = CTFWriter.StreamClass.__new__(CTFWriter.StreamClass)
2531 stream_class._sc = stream_class_native
2535 Generator returning the event class' fields as tuples of (field name, field declaration).
2539 count = _bt_ctf_event_class_get_field_count(self._ec)
2541 raise TypeError("Could not get EventClass' field count")
2543 for i in range(count):
2544 field_name = _bt_python_ctf_event_class_get_field_name(self._ec, i)
2545 if field_name is None:
2546 raise TypeError("Could not get EventClass' field name at index {}".format(i))
2548 field_type_native = _bt_python_ctf_event_class_get_field_type(self._ec, i)
2549 if field_type_native is None:
2550 raise TypeError("Could not get EventClass' field type at index {}".format(i))
2552 field_type = CTFWriter.FieldDeclaration._create_field_declaration_from_native_instance(field_type_native)
2553 yield (field_name, field_type)
2556 Get a field declaration by name (FieldDeclaration).
2558 def get_field_by_name(self, name):
2559 field_type_native = _bt_ctf_event_class_get_field_by_name(self._ec, name)
2560 if field_type_native is None:
2561 raise TypeError("Could not find EventClass field with name {}".format(name))
2562 return CTFWriter.FieldDeclaration._create_field_declaration_from_native_instance(field_type_native)
2566 Create a new event of the given event class.
2568 def __init__(self, event_class):
2569 if not isinstance(event_class, CTFWriter.EventClass):
2570 raise TypeError("Invalid event_class argument.")
2572 self._e = _bt_ctf_event_create(event_class._ec)
2574 raise ValueError("Event creation failed.")
2577 _bt_ctf_event_put(self._e)
2580 Get the event's class.
2583 def event_class(self):
2584 event_class_native = _bt_ctf_event_get_class(self._e)
2585 if event_class_native is None:
2587 event_class = CTFWriter.EventClass.__new__(CTFWriter.EventClass)
2588 event_class._ec = event_class_native
2592 Get a clock from event. Returns None if the event's class
2593 is not registered to a stream class.
2596 clock_instance = _bt_ctf_event_get_clock(self._e)
2597 if clock_instance is None:
2599 clock = CTFWriter.Clock.__new__(CTFWriter.Clock)
2600 clock._c = clock_instance
2604 Get a field from event.
2606 def payload(self, field_name):
2607 native_instance = _bt_ctf_event_get_payload(self._e, str(field_name))
2608 if native_instance is None:
2609 raise ValueError("Could not get event payload.")
2610 return CTFWriter.Field._create_field_from_native_instance(native_instance)
2613 Set a manually created field as an event's payload.
2615 def set_payload(self, field_name, value_field):
2616 if not isinstance(value, CTFWriter.Field):
2617 raise TypeError("Invalid value type.")
2618 ret = _bt_ctf_event_set_payload(self._e, str(field_name), value_field._f)
2620 raise ValueError("Could not set event field payload.")
2624 Create a new stream class of the given name.
2626 def __init__(self, name):
2627 self._sc = _bt_ctf_stream_class_create(name)
2628 if self._sc is None:
2629 raise ValueError("Stream class creation failed.")
2632 _bt_ctf_stream_class_put(self._sc)
2635 Get a stream class' clock.
2639 raise NotImplementedError("Getter not implemented.")
2642 Assign a clock to a stream class.
2645 def clock(self, clock):
2646 if not isinstance(clock, CTFWriter.Clock):
2647 raise TypeError("Invalid clock type.")
2649 ret = _bt_ctf_stream_class_set_clock(self._sc, clock._c)
2651 raise ValueError("Could not set stream class clock.")
2654 Add an event class to a stream class. New events can be added even after a
2655 stream has been instantiated and events have been appended. However, a stream
2656 will not accept events of a class that has not been registered beforehand.
2658 def add_event_class(self, event_class):
2659 if not isinstance(event_class, CTFWriter.EventClass):
2660 raise TypeError("Invalid event_class type.")
2662 ret = _bt_ctf_stream_class_add_event_class(self._sc, event_class._ec)
2664 raise ValueError("Could not add event class.")
2668 Create a stream of the given class.
2670 def __init__(self, stream_class):
2671 if not isinstance(stream_class, CTFWriter.StreamClass):
2672 raise TypeError("Invalid stream_class type.")
2674 self._s = _bt_ctf_stream_create(stream_class._sc)
2676 raise ValueError("Stream creation failed.")
2679 _bt_ctf_stream_put(self._s)
2682 Increase the current packet's discarded event count.
2684 def append_discarded_events(self, event_count):
2685 _bt_ctf_stream_append_discarded_events(self._s, event_count)
2688 Append "event" to the stream's current packet. The stream's associated clock
2689 will be sampled during this call. The event shall not be modified after
2690 being appended to a stream.
2692 def append_event(self, event):
2693 ret = _bt_ctf_stream_append_event(self._s, event._e)
2695 raise ValueError("Could not append event to stream.")
2698 The stream's current packet's events will be flushed to disk. Events
2699 subsequently appended to the stream will be added to a new packet.
2702 ret = _bt_ctf_stream_flush(self._s)
2704 raise ValueError("Could not flush stream.")
2708 Create a new writer that will produce a trace in the given path.
2710 def __init__(self, path):
2711 self._w = _bt_ctf_writer_create(path)
2713 raise ValueError("Writer creation failed.")
2716 _bt_ctf_writer_put(self._w)
2719 Create a new stream instance and register it to the writer.
2721 def create_stream(self, stream_class):
2722 if not isinstance(stream_class, CTFWriter.StreamClass):
2723 raise TypeError("Invalid stream_class type.")
2725 stream = CTFWriter.Stream.__new__(CTFWriter.Stream)
2726 stream._s = _bt_ctf_writer_create_stream(self._w, stream_class._sc)
2730 Add an environment field to the trace.
2732 def add_environment_field(self, name, value):
2733 ret = _bt_ctf_writer_add_environment_field(self._w, str(name), str(value))
2735 raise ValueError("Could not add environment field to trace.")
2738 Add a clock to the trace. Clocks assigned to stream classes must be
2739 registered to the writer.
2741 def add_clock(self, clock):
2742 ret = _bt_ctf_writer_add_clock(self._w, clock._c)
2744 raise ValueError("Could not add clock to Writer.")
2747 Get the trace's TSDL meta-data.
2751 return _bt_ctf_writer_get_metadata_string(self._w)
2754 Flush the trace's metadata to the metadata file.
2756 def flush_metadata(self):
2757 _bt_ctf_writer_flush_metadata(self._w)
2760 Get the trace's byte order. Must be a constant from the ByteOrder
2764 def byte_order(self):
2765 raise NotImplementedError("Getter not implemented.")
2768 Set the trace's byte order. Must be a constant from the ByteOrder
2769 class. Defaults to BYTE_ORDER_NATIVE, the host machine's endianness.
2772 def byte_order(self, byte_order):
2773 ret = _bt_ctf_writer_set_byte_order(self._w, byte_order)
2775 raise ValueError("Could not set trace's byte order.")