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
38 #define SWIG_FILE_WITH_INIT
39 #include <babeltrace/babeltrace.h>
40 #include <babeltrace/babeltrace-internal.h>
41 #include <babeltrace/trace-handle.h>
42 #include <babeltrace/trace-handle-internal.h>
43 #include <babeltrace/context.h>
44 #include <babeltrace/context-internal.h>
45 #include <babeltrace/iterator.h>
46 #include <babeltrace/iterator-internal.h>
47 #include <babeltrace/format.h>
48 #include <babeltrace/list.h>
49 #include <babeltrace/types.h>
50 #include <babeltrace/ctf/iterator.h>
51 #include "python-complements.h"
52 #include <babeltrace/ctf-writer/clock.h>
53 #include <babeltrace/ctf-writer/event-fields.h>
54 #include <babeltrace/ctf-writer/event-types.h>
55 #include <babeltrace/ctf-writer/event.h>
56 #include <babeltrace/ctf-writer/stream.h>
57 #include <babeltrace/ctf-writer/writer.h>
60 typedef unsigned long long uint64_t;
61 typedef long long int64_t;
62 typedef int bt_intern_str;
63 typedef int64_t ssize_t;
65 /* =================================================================
67 ¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯
70 struct bt_definition **_bt_python_field_listcaller(
71 const struct bt_ctf_event *ctf_event,
72 const struct bt_definition *scope,
73 unsigned int *OUTPUT);
74 struct bt_definition *_bt_python_field_one_from_list(
75 struct bt_definition **list, int index);
76 struct bt_ctf_event_decl **_bt_python_event_decl_listcaller(
78 struct bt_context *ctx,
79 unsigned int *OUTPUT);
80 struct bt_ctf_event_decl *_bt_python_decl_one_from_list(
81 struct bt_ctf_event_decl **list, int index);
82 struct bt_ctf_field_decl **_by_python_field_decl_listcaller(
83 struct bt_ctf_event_decl *event_decl,
84 enum bt_ctf_scope scope,
85 unsigned int *OUTPUT);
86 struct bt_ctf_field_decl *_bt_python_field_decl_one_from_list(
87 struct bt_ctf_field_decl **list, int index);
88 struct definition_array *_bt_python_get_array_from_def(
89 struct bt_definition *field);
90 struct definition_sequence *_bt_python_get_sequence_from_def(
91 struct bt_definition *field);
92 struct bt_declaration *_bt_python_get_array_element_declaration(
93 struct bt_declaration *field);
94 struct bt_declaration *_bt_python_get_sequence_element_declaration(
95 struct bt_declaration *field);
96 const char *_bt_python_get_array_string(struct bt_definition *field);
97 const char *_bt_python_get_sequence_string(struct bt_definition *field);
98 int _bt_python_field_integer_get_signedness(const struct bt_ctf_field *field);
99 enum ctf_type_id _bt_python_get_field_type(const struct bt_ctf_field *field);
100 const char *_bt_python_ctf_field_type_enumeration_get_mapping(
101 struct bt_ctf_field_type *enumeration, size_t index,
102 int64_t *OUTPUT, int64_t *OUTPUT);
103 const char *_bt_python_ctf_field_type_enumeration_get_mapping_unsigned(
104 struct bt_ctf_field_type *enumeration, size_t index,
105 uint64_t *OUTPUT, uint64_t *OUTPUT);
106 const char *_bt_python_ctf_field_type_structure_get_field_name(
107 struct bt_ctf_field_type *structure, size_t index);
108 struct bt_ctf_field_type *_bt_python_ctf_field_type_structure_get_field_type(
109 struct bt_ctf_field_type *structure, size_t index);
110 const char *_bt_python_ctf_field_type_variant_get_field_name(
111 struct bt_ctf_field_type *variant, size_t index);
112 struct bt_ctf_field_type *_bt_python_ctf_field_type_variant_get_field_type(
113 struct bt_ctf_field_type *variant, size_t index);
115 /* =================================================================
116 CONTEXT.H, CONTEXT-INTERNAL.H
117 ¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯
120 %rename("_bt_context_create") bt_context_create(void);
121 %rename("_bt_context_add_trace") bt_context_add_trace(
122 struct bt_context *ctx, const char *path, const char *format,
123 void (*packet_seek)(struct bt_stream_pos *pos, size_t index, int whence),
124 struct bt_mmap_stream_list *stream_list, FILE *metadata);
125 %rename("_bt_context_remove_trace") bt_context_remove_trace(
126 struct bt_context *ctx, int trace_id);
127 %rename("_bt_context_get") bt_context_get(struct bt_context *ctx);
128 %rename("_bt_context_put") bt_context_put(struct bt_context *ctx);
129 %rename("_bt_ctf_event_get_context") bt_ctf_event_get_context(
130 const struct bt_ctf_event *event);
132 struct bt_context *bt_context_create(void);
133 int bt_context_add_trace(struct bt_context *ctx, const char *path, const char *format,
134 void (*packet_seek)(struct bt_stream_pos *pos, size_t index, int whence),
135 struct bt_mmap_stream_list *stream_list, FILE *metadata);
136 void bt_context_remove_trace(struct bt_context *ctx, int trace_id);
137 void bt_context_get(struct bt_context *ctx);
138 void bt_context_put(struct bt_context *ctx);
139 struct bt_context *bt_ctf_event_get_context(const struct bt_ctf_event *event);
141 // class TraceCollection to prevent direct access to struct bt_context
143 class TraceCollection:
145 The TraceCollection is the object that contains all currently opened traces.
149 self._tc = _bt_context_create()
152 _bt_context_put(self._tc)
154 def add_trace(self, path, format_str):
156 Add a trace by path to the TraceCollection.
160 path is the path to the trace, it is not recursive.
161 If "path" is None, stream_list is used instead as a list
162 of mmap streams to open for the trace.
164 format is a string containing the format name in which the trace was
167 Return: the corresponding TraceHandle on success or None on error.
169 ret = _bt_context_add_trace(self._tc, path, format_str, None, None, None)
173 th = TraceHandle.__new__(TraceHandle)
175 th._trace_collection = self
178 def add_traces_recursive(self, path, format_str):
180 Open a trace recursively.
182 Find each trace present in the subdirectory starting from the given
183 path, and add them to the TraceCollection.
185 Return a dict of TraceHandle instances (the full path is the key).
186 Return None on error.
196 for fullpath, dirs, files in os.walk(path):
197 if "metadata" in files:
198 trace_handle = self.add_trace(fullpath, format_str)
199 if trace_handle is None:
203 trace_handles[fullpath] = trace_handle
206 if noTrace and error:
210 def remove_trace(self, trace_handle):
212 Remove a trace from the TraceCollection.
213 Effectively closing the trace.
216 _bt_context_remove_trace(self._tc, trace_handle._id)
217 except AttributeError:
218 raise TypeError("in remove_trace, "
219 "argument 2 must be a TraceHandle instance")
224 Generator function to iterate over the events of open in the current
227 begin_pos_ptr = _bt_iter_pos()
228 end_pos_ptr = _bt_iter_pos()
229 begin_pos_ptr.type = SEEK_BEGIN
230 end_pos_ptr.type = SEEK_LAST
232 for event in self._events(begin_pos_ptr, end_pos_ptr):
235 def events_timestamps(self, timestamp_begin, timestamp_end):
237 Generator function to iterate over the events of open in the current
238 TraceCollection from timestamp_begin to timestamp_end.
240 begin_pos_ptr = _bt_iter_pos()
241 end_pos_ptr = _bt_iter_pos()
242 begin_pos_ptr.type = end_pos_ptr.type = SEEK_TIME
243 begin_pos_ptr.u.seek_time = timestamp_begin
244 end_pos_ptr.u.seek_time = timestamp_end
246 for event in self._events(begin_pos_ptr, end_pos_ptr):
250 def timestamp_begin(self):
251 pos_ptr = _bt_iter_pos()
252 pos_ptr.type = SEEK_BEGIN
253 return self._timestamp_at_pos(pos_ptr)
256 def timestamp_end(self):
257 pos_ptr = _bt_iter_pos()
258 pos_ptr.type = SEEK_LAST
259 return self._timestamp_at_pos(pos_ptr)
261 def _timestamp_at_pos(self, pos_ptr):
262 ctf_it_ptr = _bt_ctf_iter_create(self._tc, pos_ptr, pos_ptr)
263 if ctf_it_ptr is None:
264 raise NotImplementedError("Creation of multiple iterators is unsupported.")
265 ev_ptr = _bt_ctf_iter_read_event(ctf_it_ptr)
266 _bt_ctf_iter_destroy(ctf_it_ptr)
270 def _events(self, begin_pos_ptr, end_pos_ptr):
271 ctf_it_ptr = _bt_ctf_iter_create(self._tc, begin_pos_ptr, end_pos_ptr)
272 if ctf_it_ptr is None:
273 raise NotImplementedError(
274 "Creation of multiple iterators is unsupported.")
277 ev_ptr = _bt_ctf_iter_read_event(ctf_it_ptr)
281 ev = Event.__new__(Event)
285 except GeneratorExit:
288 ret = _bt_iter_next(_bt_ctf_get_iter(ctf_it_ptr))
292 _bt_ctf_iter_destroy(ctf_it_ptr)
298 /* =================================================================
303 %rename("lookup_format") bt_lookup_format(bt_intern_str qname);
304 %rename("_bt_print_format_list") bt_fprintf_format_list(FILE *fp);
305 %rename("register_format") bt_register_format(struct format *format);
306 %rename("unregister_format") bt_unregister_format(struct bt_format *format);
308 extern struct format *bt_lookup_format(bt_intern_str qname);
309 extern void bt_fprintf_format_list(FILE *fp);
310 extern int bt_register_format(struct bt_format *format);
311 extern void bt_unregister_format(struct bt_format *format);
315 def print_format_list(babeltrace_file):
317 Print a list of available formats to file.
319 babeltrace_file must be a File instance opened in write mode.
322 if babeltrace_file._file is not None:
323 _bt_print_format_list(babeltrace_file._file)
324 except AttributeError:
325 raise TypeError("in print_format_list, "
326 "argument 1 must be a File instance")
331 /* =================================================================
332 ITERATOR.H, ITERATOR-INTERNAL.H
333 ¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯
336 %rename("_bt_iter_create") bt_iter_create(struct bt_context *ctx,
337 const struct bt_iter_pos *begin_pos, const struct bt_iter_pos *end_pos);
338 %rename("_bt_iter_destroy") bt_iter_destroy(struct bt_iter *iter);
339 %rename("_bt_iter_next") bt_iter_next(struct bt_iter *iter);
340 %rename("_bt_iter_get_pos") bt_iter_get_pos(struct bt_iter *iter);
341 %rename("_bt_iter_free_pos") bt_iter_free_pos(struct bt_iter_pos *pos);
342 %rename("_bt_iter_set_pos") bt_iter_set_pos(struct bt_iter *iter,
343 const struct bt_iter_pos *pos);
344 %rename("_bt_iter_create_time_pos") bt_iter_create_time_pos(struct bt_iter *iter,
347 struct bt_iter *bt_iter_create(struct bt_context *ctx,
348 const struct bt_iter_pos *begin_pos, const struct bt_iter_pos *end_pos);
349 void bt_iter_destroy(struct bt_iter *iter);
350 int bt_iter_next(struct bt_iter *iter);
351 struct bt_iter_pos *bt_iter_get_pos(struct bt_iter *iter);
352 void bt_iter_free_pos(struct bt_iter_pos *pos);
353 int bt_iter_set_pos(struct bt_iter *iter, const struct bt_iter_pos *pos);
354 struct bt_iter_pos *bt_iter_create_time_pos(struct bt_iter *iter, uint64_t timestamp);
356 %rename("_bt_iter_pos") bt_iter_pos;
357 %rename("SEEK_TIME") BT_SEEK_TIME;
358 %rename("SEEK_RESTORE") BT_SEEK_RESTORE;
359 %rename("SEEK_CUR") BT_SEEK_CUR;
360 %rename("SEEK_BEGIN") BT_SEEK_BEGIN;
361 %rename("SEEK_LAST") BT_SEEK_LAST;
363 // This struct is taken from iterator.h
364 // All changes to the struct must also be made here
367 BT_SEEK_TIME, /* uses u.seek_time */
368 BT_SEEK_RESTORE, /* uses u.restore */
375 struct bt_saved_pos *restore;
379 /* =================================================================
380 TRACE-HANDLE.H, TRACE-HANDLE-INTERNAL.H
381 ¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯
384 %rename("_bt_trace_handle_create") bt_trace_handle_create(struct bt_context *ctx);
385 %rename("_bt_trace_handle_destroy") bt_trace_handle_destroy(struct bt_trace_handle *bt);
386 struct bt_trace_handle *bt_trace_handle_create(struct bt_context *ctx);
387 void bt_trace_handle_destroy(struct bt_trace_handle *bt);
389 %rename("_bt_trace_handle_get_path") bt_trace_handle_get_path(struct bt_context *ctx,
391 %rename("_bt_trace_handle_get_timestamp_begin") bt_trace_handle_get_timestamp_begin(
392 struct bt_context *ctx, int handle_id, enum bt_clock_type type);
393 %rename("_bt_trace_handle_get_timestamp_end") bt_trace_handle_get_timestamp_end(
394 struct bt_context *ctx, int handle_id, enum bt_clock_type type);
395 const char *bt_trace_handle_get_path(struct bt_context *ctx, int handle_id);
396 uint64_t bt_trace_handle_get_timestamp_begin(struct bt_context *ctx, int handle_id,
397 enum bt_clock_type type);
398 uint64_t bt_trace_handle_get_timestamp_end(struct bt_context *ctx, int handle_id,
399 enum bt_clock_type type);
401 %rename("_bt_ctf_event_get_handle_id") bt_ctf_event_get_handle_id(
402 const struct bt_ctf_event *event);
403 int bt_ctf_event_get_handle_id(const struct bt_ctf_event *event);
408 # Based on enum bt_clock_type in clock-type.h
413 class TraceHandle(object):
415 The TraceHandle allows the user to manipulate a trace file directly.
416 It is a unique identifier representing a trace file.
421 raise NotImplementedError("TraceHandle cannot be instantiated")
424 return "Babeltrace TraceHandle: trace_id('{0}')".format(self._id)
428 """Return the TraceHandle id."""
433 """Return the path of a TraceHandle."""
434 return _bt_trace_handle_get_path(self._trace_collection._tc, self._id)
437 def timestamp_begin(self):
438 """Return the creation time of the buffers of a trace."""
439 return _bt_trace_handle_get_timestamp_begin(
440 self._trace_collection._tc, self._id, ClockType.CLOCK_REAL)
443 def timestamp_end(self):
444 """Return the destruction timestamp of the buffers of a trace."""
445 return _bt_trace_handle_get_timestamp_end(
446 self._trace_collection._tc, self._id, ClockType.CLOCK_REAL)
451 Generator returning all events (EventDeclaration) in a trace.
453 ret = _bt_python_event_decl_listcaller(self.id, self._trace_collection._tc)
455 if not isinstance(ret, list):
458 ptr_list, count = ret
459 for i in range(count):
460 tmp = EventDeclaration.__new__(EventDeclaration)
461 tmp._ed = _bt_python_decl_one_from_list(ptr_list, i)
468 // =================================================================
470 // =================================================================
472 /* =================================================================
478 %rename("_bt_ctf_iter_create") bt_ctf_iter_create(struct bt_context *ctx,
479 const struct bt_iter_pos *begin_pos,
480 const struct bt_iter_pos *end_pos);
481 %rename("_bt_ctf_get_iter") bt_ctf_get_iter(struct bt_ctf_iter *iter);
482 %rename("_bt_ctf_iter_destroy") bt_ctf_iter_destroy(struct bt_ctf_iter *iter);
483 %rename("_bt_ctf_iter_read_event") bt_ctf_iter_read_event(struct bt_ctf_iter *iter);
485 struct bt_ctf_iter *bt_ctf_iter_create(struct bt_context *ctx,
486 const struct bt_iter_pos *begin_pos,
487 const struct bt_iter_pos *end_pos);
488 struct bt_iter *bt_ctf_get_iter(struct bt_ctf_iter *iter);
489 void bt_ctf_iter_destroy(struct bt_ctf_iter *iter);
490 struct bt_ctf_event *bt_ctf_iter_read_event(struct bt_ctf_iter *iter);
494 %rename("_bt_ctf_get_top_level_scope") bt_ctf_get_top_level_scope(const struct
495 bt_ctf_event *event, enum bt_ctf_scope scope);
496 %rename("_bt_ctf_event_name") bt_ctf_event_name(const struct bt_ctf_event *ctf_event);
497 %rename("_bt_ctf_get_timestamp") bt_ctf_get_timestamp(
498 const struct bt_ctf_event *ctf_event);
499 %rename("_bt_ctf_get_cycles") bt_ctf_get_cycles(
500 const struct bt_ctf_event *ctf_event);
502 %rename("_bt_ctf_get_field") bt_ctf_get_field(const struct bt_ctf_event *ctf_event,
503 const struct bt_definition *scope, const char *field);
504 %rename("_bt_ctf_get_index") bt_ctf_get_index(const struct bt_ctf_event *ctf_event,
505 const struct bt_definition *field, unsigned int index);
506 %rename("_bt_ctf_field_name") bt_ctf_field_name(const struct bt_definition *field);
507 %rename("_bt_ctf_field_type") bt_ctf_field_type(const struct bt_declaration *field);
508 %rename("_bt_ctf_get_int_signedness") bt_ctf_get_int_signedness(
509 const struct bt_declaration *field);
510 %rename("_bt_ctf_get_int_base") bt_ctf_get_int_base(const struct bt_declaration *field);
511 %rename("_bt_ctf_get_int_byte_order") bt_ctf_get_int_byte_order(
512 const struct bt_declaration *field);
513 %rename("_bt_ctf_get_int_len") bt_ctf_get_int_len(const struct bt_declaration *field);
514 %rename("_bt_ctf_get_enum_int") bt_ctf_get_enum_int(const struct bt_definition *field);
515 %rename("_bt_ctf_get_enum_str") bt_ctf_get_enum_str(const struct bt_definition *field);
516 %rename("_bt_ctf_get_encoding") bt_ctf_get_encoding(const struct bt_declaration *field);
517 %rename("_bt_ctf_get_array_len") bt_ctf_get_array_len(const struct bt_declaration *field);
518 %rename("_bt_ctf_get_uint64") bt_ctf_get_uint64(const struct bt_definition *field);
519 %rename("_bt_ctf_get_int64") bt_ctf_get_int64(const struct bt_definition *field);
520 %rename("_bt_ctf_get_char_array") bt_ctf_get_char_array(const struct bt_definition *field);
521 %rename("_bt_ctf_get_string") bt_ctf_get_string(const struct bt_definition *field);
522 %rename("_bt_ctf_get_float") bt_ctf_get_float(const struct bt_definition *field);
523 %rename("_bt_ctf_get_variant") bt_ctf_get_variant(const struct bt_definition *field);
524 %rename("_bt_ctf_field_get_error") bt_ctf_field_get_error(void);
525 %rename("_bt_ctf_get_decl_event_name") bt_ctf_get_decl_event_name(const struct
526 bt_ctf_event_decl *event);
527 %rename("_bt_ctf_get_decl_event_id") bt_ctf_get_decl_event_id(const struct
528 bt_ctf_event_decl *event);
529 %rename("_bt_ctf_get_decl_field_name") bt_ctf_get_decl_field_name(
530 const struct bt_ctf_field_decl *field);
531 %rename("_bt_ctf_get_decl_from_def") bt_ctf_get_decl_from_def(
532 const struct bt_definition *field);
533 %rename("_bt_ctf_get_decl_from_field_decl") bt_ctf_get_decl_from_field_decl(
534 const struct bt_ctf_field_decl *field);
535 %rename("_bt_array_index") bt_array_index(struct definition_array *array, uint64_t i);
536 %rename("_bt_sequence_len") bt_sequence_len(struct definition_sequence *sequence);
537 %rename("_bt_sequence_index") bt_sequence_index(struct definition_sequence *sequence, uint64_t i);
538 %rename("_bt_ctf_get_struct_field_count") bt_ctf_get_struct_field_count(const struct bt_definition *structure);
539 %rename("_bt_ctf_get_struct_field_index") bt_ctf_get_struct_field_index(const struct bt_definition *structure, uint64_t i);
541 const struct bt_definition *bt_ctf_get_top_level_scope(const struct bt_ctf_event *ctf_event,
542 enum bt_ctf_scope scope);
543 const char *bt_ctf_event_name(const struct bt_ctf_event *ctf_event);
544 uint64_t bt_ctf_get_timestamp(const struct bt_ctf_event *ctf_event);
545 uint64_t bt_ctf_get_cycles(const struct bt_ctf_event *ctf_event);
546 const struct bt_definition *bt_ctf_get_field(const struct bt_ctf_event *ctf_event,
547 const struct bt_definition *scope,
549 const struct bt_definition *bt_ctf_get_index(const struct bt_ctf_event *ctf_event,
550 const struct bt_definition *field,
552 const char *bt_ctf_field_name(const struct bt_definition *field);
553 enum ctf_type_id bt_ctf_field_type(const struct bt_declaration *field);
554 int bt_ctf_get_int_signedness(const struct bt_declaration *field);
555 int bt_ctf_get_int_base(const struct bt_declaration *field);
556 int bt_ctf_get_int_byte_order(const struct bt_declaration *field);
557 ssize_t bt_ctf_get_int_len(const struct bt_declaration *field);
558 const struct bt_definition *bt_ctf_get_enum_int(const struct bt_definition *field);
559 const char *bt_ctf_get_enum_str(const struct bt_definition *field);
560 enum ctf_string_encoding bt_ctf_get_encoding(const struct bt_declaration *field);
561 int bt_ctf_get_array_len(const struct bt_declaration *field);
562 struct bt_definition *bt_array_index(struct definition_array *array, uint64_t i);
563 uint64_t bt_ctf_get_uint64(const struct bt_definition *field);
564 int64_t bt_ctf_get_int64(const struct bt_definition *field);
565 char *bt_ctf_get_char_array(const struct bt_definition *field);
566 char *bt_ctf_get_string(const struct bt_definition *field);
567 double bt_ctf_get_float(const struct bt_definition *field);
568 const struct bt_definition *bt_ctf_get_variant(const struct bt_definition *field);
569 int bt_ctf_field_get_error(void);
570 const char *bt_ctf_get_decl_event_name(const struct bt_ctf_event_decl *event);
571 uint64_t bt_ctf_get_decl_event_id(const struct bt_ctf_event_decl *event);
572 const char *bt_ctf_get_decl_field_name(const struct bt_ctf_field_decl *field);
573 const struct bt_declaration *bt_ctf_get_decl_from_def(const struct bt_definition *field);
574 const struct bt_declaration *bt_ctf_get_decl_from_field_decl(const struct bt_ctf_field_decl *field);
575 uint64_t bt_sequence_len(struct definition_sequence *sequence);
576 struct bt_definition *bt_sequence_index(struct definition_sequence *sequence, uint64_t i);
577 uint64_t bt_ctf_get_struct_field_count(const struct bt_definition *structure);
578 const struct bt_definition *bt_ctf_get_struct_field_index(const struct bt_definition *structure, uint64_t i);
582 class CTFStringEncoding:
588 # Based on the enum in ctf-writer/writer.h
590 BYTE_ORDER_NATIVE = 0
591 BYTE_ORDER_LITTLE_ENDIAN = 1
592 BYTE_ORDER_BIG_ENDIAN = 2
593 BYTE_ORDER_NETWORK = 3
594 BYTE_ORDER_UNKNOWN = 4 # Python-specific entry
596 #enum equivalent, accessible constants
597 #These are taken directly from ctf/events.h
598 #All changes to enums must also be made here
612 name = "UNKNOWN_TYPE"
613 constants = [attr for attr in dir(CTFTypeId) if not callable(getattr(CTFTypeId, attr)) and not attr.startswith("__")]
614 for attr in constants:
615 if getattr(CTFTypeId, attr) == id:
621 TRACE_PACKET_HEADER = 0
622 STREAM_PACKET_CONTEXT = 1
623 STREAM_EVENT_HEADER = 2
624 STREAM_EVENT_CONTEXT = 3
628 def scope_name(scope):
629 name = "UNKNOWN_SCOPE"
630 constants = [attr for attr in dir(CTFScope) if not callable(getattr(CTFScope, attr)) and not attr.startswith("__")]
631 for attr in constants:
632 if getattr(CTFScope, attr) == scope:
637 # Priority of the scopes when searching for event fields
638 _scopes = [CTFScope.EVENT_FIELDS, CTFScope.EVENT_CONTEXT, CTFScope.STREAM_EVENT_CONTEXT,
639 CTFScope.STREAM_EVENT_HEADER, CTFScope.STREAM_PACKET_CONTEXT, CTFScope.TRACE_PACKET_HEADER]
642 class Event(collections.Mapping):
644 This class represents an event from the trace.
645 It is obtained using the TraceCollection generator functions.
649 raise NotImplementedError("Event cannot be instantiated")
653 """Return the name of the event or None on error."""
654 return _bt_ctf_event_name(self._e)
659 Return the timestamp of the event as written in
660 the packet (in cycles) or -1ULL on error.
662 return _bt_ctf_get_cycles(self._e)
667 Return the timestamp of the event offset with the
668 system clock source or -1ULL on error.
670 return _bt_ctf_get_timestamp(self._e)
672 def field_with_scope(self, field_name, scope):
674 Get field_name's value in scope.
675 None is returned if no field matches field_name.
677 if not scope in _scopes:
678 raise ValueError("Invalid scope provided")
679 field = self._field_with_scope(field_name, scope)
680 if field is not None:
684 def field_list_with_scope(self, scope):
685 """Return a list of field names in scope."""
686 if not scope in _scopes:
687 raise ValueError("Invalid scope provided")
689 for field in self._field_list_with_scope(scope):
690 field_names.append(field.name)
696 Get the TraceHandle associated with this event
699 ret = _bt_ctf_event_get_handle_id(self._e)
703 th = TraceHandle.__new__(TraceHandle)
705 th._trace_collection = self.get_trace_collection()
709 def trace_collection(self):
711 Get the TraceCollection associated with this event.
712 Return None on error.
714 trace_collection = TraceCollection()
715 trace_collection._tc = _bt_ctf_event_get_context(self._e);
716 if trace_collection._tc is None:
719 return trace_collection
721 def __getitem__(self, field_name):
723 Get field_name's value. If the field_name exists in multiple
724 scopes, the first field found is returned. The scopes are searched
725 in the following order:
728 3) STREAM_EVENT_CONTEXT
729 4) STREAM_EVENT_HEADER
730 5) STREAM_PACKET_CONTEXT
731 6) TRACE_PACKET_HEADER
732 None is returned if no field matches field_name.
734 Use field_with_scope() to explicitly access fields in a given
737 field = self._field(field_name)
738 if field is not None:
740 raise KeyError(field_name)
743 for key in self.keys():
748 for scope in _scopes:
749 scope_ptr = _bt_ctf_get_top_level_scope(self._e, scope)
750 ret = _bt_python_field_listcaller(self._e, scope_ptr)
751 if isinstance(ret, list):
755 def __contains__(self, field_name):
756 return self._field(field_name) is not None
759 """Return a list of field names."""
761 for scope in _scopes:
762 for name in self.field_list_with_scope(scope):
763 field_names.add(name)
764 return list(field_names)
766 def get(self, field_name, default = None):
767 field = self._field(field_name)
773 for field in self.keys():
774 yield (field, self[field])
776 def _field_with_scope(self, field_name, scope):
777 scope_ptr = _bt_ctf_get_top_level_scope(self._e, scope)
778 if scope_ptr is None:
781 definition_ptr = _bt_ctf_get_field(self._e, scope_ptr, field_name)
782 if definition_ptr is None:
785 field = _Definition(definition_ptr, scope)
788 def _field(self, field_name):
790 for scope in _scopes:
791 field = self._field_with_scope(field_name, scope)
792 if field is not None:
796 def _field_list_with_scope(self, scope):
798 scope_ptr = _bt_ctf_get_top_level_scope(self._e, scope)
800 # Returns a list [list_ptr, count]. If list_ptr is NULL, SWIG will only
801 # provide the "count" return value
804 ret = _bt_python_field_listcaller(self._e, scope_ptr)
805 if isinstance(ret, list):
806 list_ptr, count = ret
808 for i in range(count):
809 definition_ptr = _bt_python_field_one_from_list(list_ptr, i)
810 if definition_ptr is not None:
811 definition = _Definition(definition_ptr, scope)
812 fields.append(definition)
815 class FieldError(Exception):
816 def __init__(self, value):
820 return repr(self.value)
822 class EventDeclaration(object):
823 """Event declaration class. Do not instantiate."""
824 MAX_UINT64 = 0xFFFFFFFFFFFFFFFF
827 raise NotImplementedError("EventDeclaration cannot be instantiated")
831 """Return the name of the event or None on error"""
832 return _bt_ctf_get_decl_event_name(self._ed)
836 """Return the event-ID of the event or -1 on error"""
837 id = _bt_ctf_get_decl_event_id(self._ed)
838 if id == self.MAX_UINT64:
845 Generator returning all FieldDeclarations of an event, going through
846 each scope in the following order:
849 3) STREAM_EVENT_CONTEXT
850 4) STREAM_EVENT_HEADER
851 5) STREAM_PACKET_CONTEXT
852 6) TRACE_PACKET_HEADER
854 for scope in _scopes:
855 for declaration in self.fields_scope(scope):
858 def fields_scope(self, scope):
860 Generator returning FieldDeclarations of the current event in scope.
862 ret = _by_python_field_decl_listcaller(self._ed, scope)
864 if not isinstance(ret, list):
867 list_ptr, count = ret
868 for i in range(count):
869 field_declaration_ptr = _bt_python_field_decl_one_from_list(list_ptr, i)
870 if field_declaration_ptr is not None:
871 declaration_ptr = _bt_ctf_get_decl_from_field_decl(field_declaration_ptr)
872 field_declaration = _create_field_declaration(declaration_ptr, _bt_ctf_get_decl_field_name(field_declaration_ptr), scope)
873 yield field_declaration
875 class FieldDeclaration(object):
876 """Field declaration class. Do not instantiate."""
878 raise NotImplementedError("FieldDeclaration cannot be instantiated")
881 return "({0}) {1} {2}".format(CTFScope.scope_name(self.scope), CTFTypeId.type_name(self.type), self.name)
885 """Return the name of a FieldDeclaration or None on error."""
891 Return the FieldDeclaration's type. One of the entries in class
894 return _bt_ctf_field_type(self._fd)
899 Return the FieldDeclaration's scope.
903 class IntegerFieldDeclaration(FieldDeclaration):
904 """Do not instantiate."""
906 raise NotImplementedError("IntegerFieldDeclaration cannot be instantiated")
909 def signedness(self):
911 Return the signedness of an integer:
912 0 if unsigned; 1 if signed; -1 on error.
914 return _bt_ctf_get_int_signedness(self._fd)
918 """Return the base of an int or a negative value on error."""
919 return _bt_ctf_get_int_base(self._fd)
922 def byte_order(self):
924 Return the byte order. One of class ByteOrder's entries.
926 ret = _bt_ctf_get_int_byte_order(self._fd)
928 return ByteOrder.BYTE_ORDER_LITTLE_ENDIAN
930 return ByteOrder.BYTE_ORDER_BIG_ENDIAN
932 return ByteOrder.BYTE_ORDER_UNKNOWN
937 Return the size, in bits, of an int or a negative
940 return _bt_ctf_get_int_len(self._fd)
945 Return the encoding. One of class CTFStringEncoding's entries.
946 Return a negative value on error.
948 return _bt_ctf_get_encoding(self._fd)
950 class EnumerationFieldDeclaration(FieldDeclaration):
951 """Do not instantiate."""
953 raise NotImplementedError("EnumerationFieldDeclaration cannot be instantiated")
955 class ArrayFieldDeclaration(FieldDeclaration):
956 """Do not instantiate."""
958 raise NotImplementedError("ArrayFieldDeclaration cannot be instantiated")
963 Return the length of an array or a negative
966 return _bt_ctf_get_array_len(self._fd)
969 def element_declaration(self):
971 Return element declaration.
973 field_decl_ptr = _bt_python_get_array_element_declaration(self._fd)
974 return _create_field_declaration(field_decl_ptr, "", self.scope)
976 class SequenceFieldDeclaration(FieldDeclaration):
977 """Do not instantiate."""
979 raise NotImplementedError("SequenceFieldDeclaration cannot be instantiated")
982 def element_declaration(self):
984 Return element declaration.
986 field_decl_ptr = _bt_python_get_sequence_element_declaration(self._fd)
987 return _create_field_declaration(field_decl_ptr, "", self.scope)
989 class FloatFieldDeclaration(FieldDeclaration):
990 """Do not instantiate."""
992 raise NotImplementedError("FloatFieldDeclaration cannot be instantiated")
994 class StructureFieldDeclaration(FieldDeclaration):
995 """Do not instantiate."""
997 raise NotImplementedError("StructureFieldDeclaration cannot be instantiated")
999 class StringFieldDeclaration(FieldDeclaration):
1000 """Do not instantiate."""
1002 raise NotImplementedError("StringFieldDeclaration cannot be instantiated")
1004 class VariantFieldDeclaration(FieldDeclaration):
1005 """Do not instantiate."""
1007 raise NotImplementedError("VariantFieldDeclaration cannot be instantiated")
1011 Return the last error code encountered while
1012 accessing a field and reset the error flag.
1013 Return 0 if no error, a negative value otherwise.
1015 return _bt_ctf_field_get_error()
1017 def _create_field_declaration(declaration_ptr, name, scope):
1019 Private field declaration factory.
1021 if declaration_ptr is None:
1022 raise ValueError("declaration_ptr must be valid")
1023 if not scope in _scopes:
1024 raise ValueError("Invalid scope provided")
1026 type = _bt_ctf_field_type(declaration_ptr)
1028 if type == CTFTypeId.INTEGER:
1029 declaration = IntegerFieldDeclaration.__new__(IntegerFieldDeclaration)
1030 elif type == CTFTypeId.ENUM:
1031 declaration = EnumerationFieldDeclaration.__new__(EnumerationFieldDeclaration)
1032 elif type == CTFTypeId.ARRAY:
1033 declaration = ArrayFieldDeclaration.__new__(ArrayFieldDeclaration)
1034 elif type == CTFTypeId.SEQUENCE:
1035 declaration = SequenceFieldDeclaration.__new__(SequenceFieldDeclaration)
1036 elif type == CTFTypeId.FLOAT:
1037 declaration = FloatFieldDeclaration.__new__(FloatFieldDeclaration)
1038 elif type == CTFTypeId.STRUCT:
1039 declaration = StructureFieldDeclaration.__new__(StructureFieldDeclaration)
1040 elif type == CTFTypeId.STRING:
1041 declaration = StringFieldDeclaration.__new__(StringFieldDeclaration)
1042 elif type == CTFTypeId.VARIANT:
1043 declaration = VariantFieldDeclaration.__new__(VariantFieldDeclaration)
1047 declaration._fd = declaration_ptr
1048 declaration._s = scope
1049 declaration._name = name
1052 class _Definition(object):
1053 def __init__(self, definition_ptr, scope):
1054 self._d = definition_ptr
1056 if not scope in _scopes:
1057 ValueError("Invalid scope provided")
1061 """Return the name of a field or None on error."""
1062 return _bt_ctf_field_name(self._d)
1066 """Return the type of a field or -1 if unknown."""
1067 return _bt_ctf_field_type(_bt_ctf_get_decl_from_def(self._d))
1070 def declaration(self):
1071 """Return the associated Definition object."""
1072 return _create_field_declaration(_bt_ctf_get_decl_from_def(self._d), self.name, self.scope)
1074 def _get_enum_str(self):
1076 Return the string matching the current enumeration.
1077 Return None on error.
1079 return _bt_ctf_get_enum_str(self._d)
1081 def _get_array_element_at(self, index):
1083 Return the array's element at position index.
1084 Return None on error
1086 array_ptr = _bt_python_get_array_from_def(self._d)
1087 if array_ptr is None:
1090 definition_ptr = _bt_array_index(array_ptr, index)
1091 if definition_ptr is None:
1093 return _Definition(definition_ptr, self.scope)
1095 def _get_sequence_len(self):
1097 Return the len of a sequence or a negative
1100 seq = _bt_python_get_sequence_from_def(self._d)
1101 return _bt_sequence_len(seq)
1103 def _get_sequence_element_at(self, index):
1105 Return the sequence's element at position index,
1106 otherwise return None
1108 seq = _bt_python_get_sequence_from_def(self._d)
1110 definition_ptr = _bt_sequence_index(seq, index)
1111 if definition_ptr is not None:
1112 return _Definition(definition_ptr, self.scope)
1115 def _get_uint64(self):
1117 Return the value associated with the field.
1118 If the field does not exist or is not of the type requested,
1119 the value returned is undefined. To check if an error occured,
1120 use the field_error() function after accessing a field.
1122 return _bt_ctf_get_uint64(self._d)
1124 def _get_int64(self):
1126 Return the value associated with the field.
1127 If the field does not exist or is not of the type requested,
1128 the value returned is undefined. To check if an error occured,
1129 use the field_error() function after accessing a field.
1131 return _bt_ctf_get_int64(self._d)
1133 def _get_char_array(self):
1135 Return the value associated with the field.
1136 If the field does not exist or is not of the type requested,
1137 the value returned is undefined. To check if an error occurred,
1138 use the field_error() function after accessing a field.
1140 return _bt_ctf_get_char_array(self._d)
1144 Return the value associated with the field.
1145 If the field does not exist or is not of the type requested,
1146 the value returned is undefined. To check if an error occurred,
1147 use the field_error() function after accessing a field.
1149 return _bt_ctf_get_string(self._d)
1151 def _get_float(self):
1153 Return the value associated with the field.
1154 If the field does not exist or is not of the type requested,
1155 the value returned is undefined. To check if an error occurred,
1156 use the field_error() function after accessing a field.
1158 return _bt_ctf_get_float(self._d)
1160 def _get_variant(self):
1162 Return the variant's selected field.
1163 If the field does not exist or is not of the type requested,
1164 the value returned is undefined. To check if an error occurred,
1165 use the field_error() function after accessing a field.
1167 return _bt_ctf_get_variant(self._d)
1169 def _get_struct_field_count(self):
1171 Return the number of fields contained in the structure.
1172 If the field does not exist or is not of the type requested,
1173 the value returned is undefined.
1175 return _bt_ctf_get_struct_field_count(self._d)
1177 def _get_struct_field_at(self, i):
1179 Return the structure's field at position i.
1180 If the field does not exist or is not of the type requested,
1181 the value returned is undefined. To check if an error occurred,
1182 use the field_error() function after accessing a field.
1184 return _bt_ctf_get_struct_field_index(self._d, i)
1189 Return the value associated with the field according to its type.
1190 Return None on error.
1195 if id == CTFTypeId.STRING:
1196 value = self._get_str()
1197 elif id == CTFTypeId.ARRAY:
1198 element_decl = self.declaration.element_declaration
1199 if ((element_decl.type == CTFTypeId.INTEGER
1200 and element_decl.length == 8)
1201 and (element_decl.encoding == CTFStringEncoding.ASCII or element_decl.encoding == CTFStringEncoding.UTF8)):
1202 value = _bt_python_get_array_string(self._d)
1205 for i in range(self.declaration.length):
1206 element = self._get_array_element_at(i)
1207 value.append(element.value)
1208 elif id == CTFTypeId.INTEGER:
1209 if self.declaration.signedness == 0:
1210 value = self._get_uint64()
1212 value = self._get_int64()
1213 elif id == CTFTypeId.ENUM:
1214 value = self._get_enum_str()
1215 elif id == CTFTypeId.SEQUENCE:
1216 element_decl = self.declaration.element_declaration
1217 if ((element_decl.type == CTFTypeId.INTEGER
1218 and element_decl.length == 8)
1219 and (element_decl.encoding == CTFStringEncoding.ASCII or element_decl.encoding == CTFStringEncoding.UTF8)):
1220 value = _bt_python_get_sequence_string(self._d)
1222 seq_len = self._get_sequence_len()
1224 for i in range(seq_len):
1225 evDef = self._get_sequence_element_at(i)
1226 value.append(evDef.value)
1227 elif id == CTFTypeId.FLOAT:
1228 value = self._get_float()
1229 elif id == CTFTypeId.VARIANT:
1230 variant = _Definition.__new__(_Definition)
1231 variant._d = self._get_variant();
1232 value = variant.value
1233 elif id == CTFTypeId.STRUCT:
1235 for i in range(self._get_struct_field_count()):
1236 member = _Definition(self._get_struct_field_at(i), self.scope)
1237 value[member.name] = member.value
1240 raise FieldError("Error occurred while accessing field {} of type {}".format(self.name, CTFTypeId.type_name(id)))
1245 """Return the scope of a field or None on error."""
1251 // =================================================================
1253 // =================================================================
1255 /* =================================================================
1257 ¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯
1259 %rename("_bt_ctf_clock_create") bt_ctf_clock_create(const char *name);
1260 %rename("_bt_ctf_clock_get_name") bt_ctf_clock_get_name(struct bt_ctf_clock *clock);
1261 %rename("_bt_ctf_clock_get_description") bt_ctf_clock_get_description(struct bt_ctf_clock *clock);
1262 %rename("_bt_ctf_clock_set_description") bt_ctf_clock_set_description(struct bt_ctf_clock *clock, const char *desc);
1263 %rename("_bt_ctf_clock_get_frequency") bt_ctf_clock_get_frequency(struct bt_ctf_clock *clock);
1264 %rename("_bt_ctf_clock_set_frequency") bt_ctf_clock_set_frequency(struct bt_ctf_clock *clock, uint64_t freq);
1265 %rename("_bt_ctf_clock_get_precision") bt_ctf_clock_get_precision(struct bt_ctf_clock *clock);
1266 %rename("_bt_ctf_clock_set_precision") bt_ctf_clock_set_precision(struct bt_ctf_clock *clock, uint64_t precision);
1267 %rename("_bt_ctf_clock_get_offset_s") bt_ctf_clock_get_offset_s(struct bt_ctf_clock *clock);
1268 %rename("_bt_ctf_clock_set_offset_s") bt_ctf_clock_set_offset_s(struct bt_ctf_clock *clock, uint64_t offset_s);
1269 %rename("_bt_ctf_clock_get_offset") bt_ctf_clock_get_offset(struct bt_ctf_clock *clock);
1270 %rename("_bt_ctf_clock_set_offset") bt_ctf_clock_set_offset(struct bt_ctf_clock *clock, uint64_t offset);
1271 %rename("_bt_ctf_clock_get_is_absolute") bt_ctf_clock_get_is_absolute(struct bt_ctf_clock *clock);
1272 %rename("_bt_ctf_clock_set_is_absolute") bt_ctf_clock_set_is_absolute(struct bt_ctf_clock *clock, int is_absolute);
1273 %rename("_bt_ctf_clock_get_time") bt_ctf_clock_get_time(struct bt_ctf_clock *clock);
1274 %rename("_bt_ctf_clock_set_time") bt_ctf_clock_set_time(struct bt_ctf_clock *clock, uint64_t time);
1275 %rename("_bt_ctf_clock_get") bt_ctf_clock_get(struct bt_ctf_clock *clock);
1276 %rename("_bt_ctf_clock_put") bt_ctf_clock_put(struct bt_ctf_clock *clock);
1278 struct bt_ctf_clock *bt_ctf_clock_create(const char *name);
1279 const char *bt_ctf_clock_get_name(struct bt_ctf_clock *clock);
1280 const char *bt_ctf_clock_get_description(struct bt_ctf_clock *clock);
1281 int bt_ctf_clock_set_description(struct bt_ctf_clock *clock, const char *desc);
1282 uint64_t bt_ctf_clock_get_frequency(struct bt_ctf_clock *clock);
1283 int bt_ctf_clock_set_frequency(struct bt_ctf_clock *clock, uint64_t freq);
1284 uint64_t bt_ctf_clock_get_precision(struct bt_ctf_clock *clock);
1285 int bt_ctf_clock_set_precision(struct bt_ctf_clock *clock, uint64_t precision);
1286 uint64_t bt_ctf_clock_get_offset_s(struct bt_ctf_clock *clock);
1287 int bt_ctf_clock_set_offset_s(struct bt_ctf_clock *clock, uint64_t offset_s);
1288 uint64_t bt_ctf_clock_get_offset(struct bt_ctf_clock *clock);
1289 int bt_ctf_clock_set_offset(struct bt_ctf_clock *clock, uint64_t offset);
1290 int bt_ctf_clock_get_is_absolute(struct bt_ctf_clock *clock);
1291 int bt_ctf_clock_set_is_absolute(struct bt_ctf_clock *clock, int is_absolute);
1292 uint64_t bt_ctf_clock_get_time(struct bt_ctf_clock *clock);
1293 int bt_ctf_clock_set_time(struct bt_ctf_clock *clock, uint64_t time);
1294 void bt_ctf_clock_get(struct bt_ctf_clock *clock);
1295 void bt_ctf_clock_put(struct bt_ctf_clock *clock);
1297 /* =================================================================
1299 ¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯
1301 %rename("_bt_ctf_field_type_integer_create") bt_ctf_field_type_integer_create(unsigned int size);
1302 %rename("_bt_ctf_field_type_integer_get_size") bt_ctf_field_type_integer_get_size(struct bt_ctf_field_type *integer);
1303 %rename("_bt_ctf_field_type_integer_get_signed") bt_ctf_field_type_integer_get_signed(struct bt_ctf_field_type *integer);
1304 %rename("_bt_ctf_field_type_integer_set_signed") bt_ctf_field_type_integer_set_signed(struct bt_ctf_field_type *integer, int is_signed);
1305 %rename("_bt_ctf_field_type_integer_get_base") bt_ctf_field_type_integer_get_base(struct bt_ctf_field_type *integer);
1306 %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);
1307 %rename("_bt_ctf_field_type_integer_get_encoding") bt_ctf_field_type_integer_get_encoding(struct bt_ctf_field_type *integer);
1308 %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);
1309 %rename("_bt_ctf_field_type_enumeration_create") bt_ctf_field_type_enumeration_create(struct bt_ctf_field_type *integer_container_type);
1310 %rename("_bt_ctf_field_type_enumeration_get_container_type") bt_ctf_field_type_enumeration_get_container_type(struct bt_ctf_field_type *enumeration);
1311 %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);
1312 %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);
1313 %rename("_bt_ctf_field_type_enumeration_get_mapping_count") bt_ctf_field_type_enumeration_get_mapping_count(struct bt_ctf_field_type *enumeration);
1314 %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);
1315 %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);
1316 %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);
1317 %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);
1318 %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);
1319 %rename("_bt_ctf_field_type_floating_point_create") bt_ctf_field_type_floating_point_create(void);
1320 %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);
1321 %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);
1322 %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);
1323 %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);
1324 %rename("_bt_ctf_field_type_structure_create") bt_ctf_field_type_structure_create(void);
1325 %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);
1326 %rename("_bt_ctf_field_type_structure_get_field_count") bt_ctf_field_type_structure_get_field_count(struct bt_ctf_field_type *structure);
1327 %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);
1328 %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);
1329 %rename("_bt_ctf_field_type_variant_create") bt_ctf_field_type_variant_create(struct bt_ctf_field_type *enum_tag, const char *tag_name);
1330 %rename("_bt_ctf_field_type_variant_get_tag_type") bt_ctf_field_type_variant_get_tag_type(struct bt_ctf_field_type *variant);
1331 %rename("_bt_ctf_field_type_variant_get_tag_name") bt_ctf_field_type_variant_get_tag_name(struct bt_ctf_field_type *variant);
1332 %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);
1333 %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);
1334 %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);
1335 %rename("_bt_ctf_field_type_variant_get_field_count") bt_ctf_field_type_variant_get_field_count(struct bt_ctf_field_type *variant);
1336 %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);
1337 %rename("_bt_ctf_field_type_array_create") bt_ctf_field_type_array_create(struct bt_ctf_field_type *element_type, unsigned int length);
1338 %rename("_bt_ctf_field_type_array_get_element_type") bt_ctf_field_type_array_get_element_type(struct bt_ctf_field_type *array);
1339 %rename("_bt_ctf_field_type_array_get_length") bt_ctf_field_type_array_get_length(struct bt_ctf_field_type *array);
1340 %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);
1341 %rename("_bt_ctf_field_type_sequence_get_element_type") bt_ctf_field_type_sequence_get_element_type(struct bt_ctf_field_type *sequence);
1342 %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);
1343 %rename("_bt_ctf_field_type_string_create") bt_ctf_field_type_string_create(void);
1344 %rename("_bt_ctf_field_type_string_get_encoding") bt_ctf_field_type_string_get_encoding(struct bt_ctf_field_type *string_type);
1345 %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);
1346 %rename("_bt_ctf_field_type_get_alignment") bt_ctf_field_type_get_alignment(struct bt_ctf_field_type *type);
1347 %rename("_bt_ctf_field_type_set_alignment") bt_ctf_field_type_set_alignment(struct bt_ctf_field_type *type, unsigned int alignment);
1348 %rename("_bt_ctf_field_type_get_byte_order") bt_ctf_field_type_get_byte_order(struct bt_ctf_field_type *type);
1349 %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);
1350 %rename("_bt_ctf_field_type_get_type_id") bt_ctf_field_type_get_type_id(struct bt_ctf_field_type *type);
1351 %rename("_bt_ctf_field_type_get") bt_ctf_field_type_get(struct bt_ctf_field_type *type);
1352 %rename("_bt_ctf_field_type_put") bt_ctf_field_type_put(struct bt_ctf_field_type *type);
1354 struct bt_ctf_field_type *bt_ctf_field_type_integer_create(unsigned int size);
1355 int bt_ctf_field_type_integer_get_size(struct bt_ctf_field_type *integer);
1356 int bt_ctf_field_type_integer_get_signed(struct bt_ctf_field_type *integer);
1357 int bt_ctf_field_type_integer_set_signed(struct bt_ctf_field_type *integer, int is_signed);
1358 enum bt_ctf_integer_base bt_ctf_field_type_integer_get_base(struct bt_ctf_field_type *integer);
1359 int bt_ctf_field_type_integer_set_base(struct bt_ctf_field_type *integer, enum bt_ctf_integer_base base);
1360 enum ctf_string_encoding bt_ctf_field_type_integer_get_encoding(struct bt_ctf_field_type *integer);
1361 int bt_ctf_field_type_integer_set_encoding(struct bt_ctf_field_type *integer, enum ctf_string_encoding encoding);
1362 struct bt_ctf_field_type *bt_ctf_field_type_enumeration_create(struct bt_ctf_field_type *integer_container_type);
1363 struct bt_ctf_field_type *bt_ctf_field_type_enumeration_get_container_type(struct bt_ctf_field_type *enumeration);
1364 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);
1365 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);
1366 int64_t bt_ctf_field_type_enumeration_get_mapping_count(struct bt_ctf_field_type *enumeration);
1367 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);
1368 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);
1369 int bt_ctf_field_type_enumeration_get_mapping_index_by_name(struct bt_ctf_field_type *enumeration, const char *name, size_t *OUTPUT);
1370 int bt_ctf_field_type_enumeration_get_mapping_index_by_value(struct bt_ctf_field_type *enumeration, int64_t value, size_t *OUTPUT);
1371 int bt_ctf_field_type_enumeration_get_mapping_index_by_unsigned_value(struct bt_ctf_field_type *enumeration, uint64_t value, size_t *OUTPUT);
1372 struct bt_ctf_field_type *bt_ctf_field_type_floating_point_create(void);
1373 int bt_ctf_field_type_floating_point_get_exponent_digits(struct bt_ctf_field_type *floating_point);
1374 int bt_ctf_field_type_floating_point_set_exponent_digits(struct bt_ctf_field_type *floating_point, unsigned int exponent_digits);
1375 int bt_ctf_field_type_floating_point_get_mantissa_digits(struct bt_ctf_field_type *floating_point);
1376 int bt_ctf_field_type_floating_point_set_mantissa_digits(struct bt_ctf_field_type *floating_point, unsigned int mantissa_digits);
1377 struct bt_ctf_field_type *bt_ctf_field_type_structure_create(void);
1378 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);
1379 int64_t bt_ctf_field_type_structure_get_field_count(struct bt_ctf_field_type *structure);
1380 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);
1381 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);
1382 struct bt_ctf_field_type *bt_ctf_field_type_variant_create(struct bt_ctf_field_type *enum_tag, const char *tag_name);
1383 struct bt_ctf_field_type *bt_ctf_field_type_variant_get_tag_type(struct bt_ctf_field_type *variant);
1384 const char *bt_ctf_field_type_variant_get_tag_name(struct bt_ctf_field_type *variant);
1385 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);
1386 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);
1387 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);
1388 int64_t bt_ctf_field_type_variant_get_field_count(struct bt_ctf_field_type *variant);
1389 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);
1390 struct bt_ctf_field_type *bt_ctf_field_type_array_create(struct bt_ctf_field_type *element_type, unsigned int length);
1391 struct bt_ctf_field_type *bt_ctf_field_type_array_get_element_type(struct bt_ctf_field_type *array);
1392 int64_t bt_ctf_field_type_array_get_length(struct bt_ctf_field_type *array);
1393 struct bt_ctf_field_type *bt_ctf_field_type_sequence_create(struct bt_ctf_field_type *element_type, const char *length_field_name);
1394 struct bt_ctf_field_type *bt_ctf_field_type_sequence_get_element_type(struct bt_ctf_field_type *sequence);
1395 const char *bt_ctf_field_type_sequence_get_length_field_name(struct bt_ctf_field_type *sequence);
1396 struct bt_ctf_field_type *bt_ctf_field_type_string_create(void);
1397 enum ctf_string_encoding bt_ctf_field_type_string_get_encoding(struct bt_ctf_field_type *string_type);
1398 int bt_ctf_field_type_string_set_encoding(struct bt_ctf_field_type *string_type, enum ctf_string_encoding encoding);
1399 int bt_ctf_field_type_get_alignment(struct bt_ctf_field_type *type);
1400 int bt_ctf_field_type_set_alignment(struct bt_ctf_field_type *type, unsigned int alignment);
1401 enum bt_ctf_byte_order bt_ctf_field_type_get_byte_order(struct bt_ctf_field_type *type);
1402 int bt_ctf_field_type_set_byte_order(struct bt_ctf_field_type *type, enum bt_ctf_byte_order byte_order);
1403 enum ctf_type_id bt_ctf_field_type_get_type_id(struct bt_ctf_field_type *type);
1404 void bt_ctf_field_type_get(struct bt_ctf_field_type *type);
1405 void bt_ctf_field_type_put(struct bt_ctf_field_type *type);
1407 /* =================================================================
1409 ¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯
1411 %rename("_bt_ctf_field_create") bt_ctf_field_create(struct bt_ctf_field_type *type);
1412 %rename("_bt_ctf_field_structure_get_field") bt_ctf_field_structure_get_field(struct bt_ctf_field *structure, const char *name);
1413 %rename("_bt_ctf_field_array_get_field") bt_ctf_field_array_get_field(struct bt_ctf_field *array, uint64_t index);
1414 %rename("_bt_ctf_field_sequence_get_length") bt_ctf_field_sequence_get_length(struct bt_ctf_field *sequence);
1415 %rename("_bt_ctf_field_sequence_set_length") bt_ctf_field_sequence_set_length(struct bt_ctf_field *sequence, struct bt_ctf_field *length_field);
1416 %rename("_bt_ctf_field_sequence_get_field") bt_ctf_field_sequence_get_field(struct bt_ctf_field *sequence, uint64_t index);
1417 %rename("_bt_ctf_field_variant_get_field") bt_ctf_field_variant_get_field(struct bt_ctf_field *variant, struct bt_ctf_field *tag);
1418 %rename("_bt_ctf_field_enumeration_get_container") bt_ctf_field_enumeration_get_container(struct bt_ctf_field *enumeration);
1419 %rename("_bt_ctf_field_enumeration_get_mapping_name") bt_ctf_field_enumeration_get_mapping_name(struct bt_ctf_field *enumeration);
1420 %rename("_bt_ctf_field_signed_integer_get_value") bt_ctf_field_signed_integer_get_value(struct bt_ctf_field *integer, int64_t *value);
1421 %rename("_bt_ctf_field_signed_integer_set_value") bt_ctf_field_signed_integer_set_value(struct bt_ctf_field *integer, int64_t value);
1422 %rename("_bt_ctf_field_unsigned_integer_get_value") bt_ctf_field_unsigned_integer_get_value(struct bt_ctf_field *integer, uint64_t *value);
1423 %rename("_bt_ctf_field_unsigned_integer_set_value") bt_ctf_field_unsigned_integer_set_value(struct bt_ctf_field *integer, uint64_t value);
1424 %rename("_bt_ctf_field_floating_point_get_value") bt_ctf_field_floating_point_get_value(struct bt_ctf_field *floating_point, double *value);
1425 %rename("_bt_ctf_field_floating_point_set_value") bt_ctf_field_floating_point_set_value(struct bt_ctf_field *floating_point, double value);
1426 %rename("_bt_ctf_field_string_get_value") bt_ctf_field_string_get_value(struct bt_ctf_field *string_field);
1427 %rename("_bt_ctf_field_string_set_value") bt_ctf_field_string_set_value(struct bt_ctf_field *string_field, const char *value);
1428 %rename("_bt_ctf_field_get_type") bt_ctf_field_get_type(struct bt_ctf_field *field);
1429 %rename("_bt_ctf_field_get") bt_ctf_field_get(struct bt_ctf_field *field);
1430 %rename("_bt_ctf_field_put") bt_ctf_field_put(struct bt_ctf_field *field);
1432 struct bt_ctf_field *bt_ctf_field_create(struct bt_ctf_field_type *type);
1433 struct bt_ctf_field *bt_ctf_field_structure_get_field(struct bt_ctf_field *structure, const char *name);
1434 struct bt_ctf_field *bt_ctf_field_array_get_field(struct bt_ctf_field *array, uint64_t index);
1435 struct bt_ctf_field * bt_ctf_field_sequence_get_length(struct bt_ctf_field *sequence);
1436 int bt_ctf_field_sequence_set_length(struct bt_ctf_field *sequence, struct bt_ctf_field *length_field);
1437 struct bt_ctf_field *bt_ctf_field_sequence_get_field(struct bt_ctf_field *sequence, uint64_t index);
1438 struct bt_ctf_field *bt_ctf_field_variant_get_field(struct bt_ctf_field *variant, struct bt_ctf_field *tag);
1439 struct bt_ctf_field *bt_ctf_field_enumeration_get_container(struct bt_ctf_field *enumeration);
1440 const char *bt_ctf_field_enumeration_get_mapping_name(struct bt_ctf_field *enumeration);
1441 int bt_ctf_field_signed_integer_get_value(struct bt_ctf_field *integer, int64_t *OUTPUT);
1442 int bt_ctf_field_signed_integer_set_value(struct bt_ctf_field *integer, int64_t value);
1443 int bt_ctf_field_unsigned_integer_get_value(struct bt_ctf_field *integer, uint64_t *OUTPUT);
1444 int bt_ctf_field_unsigned_integer_set_value(struct bt_ctf_field *integer, uint64_t value);
1445 int bt_ctf_field_floating_point_get_value(struct bt_ctf_field *floating_point, double *OUTPUT);
1446 int bt_ctf_field_floating_point_set_value(struct bt_ctf_field *floating_point, double value);
1447 const char *bt_ctf_field_string_get_value(struct bt_ctf_field *string_field);
1448 int bt_ctf_field_string_set_value(struct bt_ctf_field *string_field, const char *value);
1449 struct bt_ctf_field_type *bt_ctf_field_get_type(struct bt_ctf_field *field);
1450 void bt_ctf_field_get(struct bt_ctf_field *field);
1451 void bt_ctf_field_put(struct bt_ctf_field *field);
1453 /* =================================================================
1455 ¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯
1457 %rename("_bt_ctf_event_class_create") bt_ctf_event_class_create(const char *name);
1458 %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);
1459 %rename("_bt_ctf_event_class_get") bt_ctf_event_class_get(struct bt_ctf_event_class *event_class);
1460 %rename("_bt_ctf_event_class_put") bt_ctf_event_class_put(struct bt_ctf_event_class *event_class);
1461 %rename("_bt_ctf_event_create") bt_ctf_event_create(struct bt_ctf_event_class *event_class);
1462 %rename("_bt_ctf_event_set_payload") bt_ctf_event_set_payload(struct bt_ctf_event *event, const char *name, struct bt_ctf_field *value);
1463 %rename("_bt_ctf_event_get_payload") bt_ctf_event_get_payload(struct bt_ctf_event *event, const char *name);
1464 %rename("_bt_ctf_event_get") bt_ctf_event_get(struct bt_ctf_event *event);
1465 %rename("_bt_ctf_event_put") bt_ctf_event_put(struct bt_ctf_event *event);
1467 struct bt_ctf_event_class *bt_ctf_event_class_create(const char *name);
1468 int bt_ctf_event_class_add_field(struct bt_ctf_event_class *event_class, struct bt_ctf_field_type *type, const char *name);
1469 void bt_ctf_event_class_get(struct bt_ctf_event_class *event_class);
1470 void bt_ctf_event_class_put(struct bt_ctf_event_class *event_class);
1471 struct bt_ctf_event *bt_ctf_event_create(struct bt_ctf_event_class *event_class);
1472 int bt_ctf_event_set_payload(struct bt_ctf_event *event, const char *name, struct bt_ctf_field *value);
1473 struct bt_ctf_field *bt_ctf_event_get_payload(struct bt_ctf_event *event, const char *name);
1474 void bt_ctf_event_get(struct bt_ctf_event *event);
1475 void bt_ctf_event_put(struct bt_ctf_event *event);
1477 /* =================================================================
1479 ¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯
1481 %rename("_bt_ctf_stream_class_create") bt_ctf_stream_class_create(const char *name);
1482 %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);
1483 %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);
1484 %rename("_bt_ctf_stream_class_get") bt_ctf_stream_class_get(struct bt_ctf_stream_class *stream_class);
1485 %rename("_bt_ctf_stream_class_put") bt_ctf_stream_class_put(struct bt_ctf_stream_class *stream_class);
1486 %rename("_bt_ctf_stream_append_discarded_events") bt_ctf_stream_append_discarded_events(struct bt_ctf_stream *stream, uint64_t event_count);
1487 %rename("_bt_ctf_stream_append_event") bt_ctf_stream_append_event(struct bt_ctf_stream *stream, struct bt_ctf_event *event);
1488 %rename("_bt_ctf_stream_flush") bt_ctf_stream_flush(struct bt_ctf_stream *stream);
1489 %rename("_bt_ctf_stream_get") bt_ctf_stream_get(struct bt_ctf_stream *stream);
1490 %rename("_bt_ctf_stream_put") bt_ctf_stream_put(struct bt_ctf_stream *stream);
1492 struct bt_ctf_stream_class *bt_ctf_stream_class_create(const char *name);
1493 int bt_ctf_stream_class_set_clock(struct bt_ctf_stream_class *stream_class, struct bt_ctf_clock *clock);
1494 int bt_ctf_stream_class_add_event_class(struct bt_ctf_stream_class *stream_class, struct bt_ctf_event_class *event_class);
1495 void bt_ctf_stream_class_get(struct bt_ctf_stream_class *stream_class);
1496 void bt_ctf_stream_class_put(struct bt_ctf_stream_class *stream_class);
1497 void bt_ctf_stream_append_discarded_events(struct bt_ctf_stream *stream, uint64_t event_count);
1498 int bt_ctf_stream_append_event(struct bt_ctf_stream *stream, struct bt_ctf_event *event);
1499 int bt_ctf_stream_flush(struct bt_ctf_stream *stream);
1500 void bt_ctf_stream_get(struct bt_ctf_stream *stream);
1501 void bt_ctf_stream_put(struct bt_ctf_stream *stream);
1503 /* =================================================================
1505 ¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯
1507 %rename("_bt_ctf_writer_create") bt_ctf_writer_create(const char *path);
1508 %rename("_bt_ctf_writer_create_stream") bt_ctf_writer_create_stream(struct bt_ctf_writer *writer, struct bt_ctf_stream_class *stream_class);
1509 %rename("_bt_ctf_writer_add_environment_field") bt_ctf_writer_add_environment_field(struct bt_ctf_writer *writer, const char *name, const char *value);
1510 %rename("_bt_ctf_writer_add_clock") bt_ctf_writer_add_clock(struct bt_ctf_writer *writer, struct bt_ctf_clock *clock);
1511 %newobject bt_ctf_writer_get_metadata_string;
1512 %rename("_bt_ctf_writer_get_metadata_string") bt_ctf_writer_get_metadata_string(struct bt_ctf_writer *writer);
1513 %rename("_bt_ctf_writer_flush_metadata") bt_ctf_writer_flush_metadata(struct bt_ctf_writer *writer);
1514 %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);
1515 %rename("_bt_ctf_writer_get") bt_ctf_writer_get(struct bt_ctf_writer *writer);
1516 %rename("_bt_ctf_writer_put") bt_ctf_writer_put(struct bt_ctf_writer *writer);
1518 struct bt_ctf_writer *bt_ctf_writer_create(const char *path);
1519 struct bt_ctf_stream *bt_ctf_writer_create_stream(struct bt_ctf_writer *writer, struct bt_ctf_stream_class *stream_class);
1520 int bt_ctf_writer_add_environment_field(struct bt_ctf_writer *writer, const char *name, const char *value);
1521 int bt_ctf_writer_add_clock(struct bt_ctf_writer *writer, struct bt_ctf_clock *clock);
1522 char *bt_ctf_writer_get_metadata_string(struct bt_ctf_writer *writer);
1523 void bt_ctf_writer_flush_metadata(struct bt_ctf_writer *writer);
1524 int bt_ctf_writer_set_byte_order(struct bt_ctf_writer *writer, enum bt_ctf_byte_order byte_order);
1525 void bt_ctf_writer_get(struct bt_ctf_writer *writer);
1526 void bt_ctf_writer_put(struct bt_ctf_writer *writer);
1531 # Used to compare to -1ULL in error checks
1532 _MAX_UINT64 = 0xFFFFFFFFFFFFFFFF
1535 Enumeration mapping class. start and end values are inclusive.
1537 class EnumerationMapping:
1538 def __init__(self, name, start, end):
1544 def __init__(self, name):
1545 self._c = _bt_ctf_clock_create(name)
1547 raise ValueError("Invalid clock name.")
1550 _bt_ctf_clock_put(self._c)
1553 Get the clock's name.
1557 name = _bt_ctf_clock_get_name(self._c)
1559 raise ValueError("Invalid clock instance.")
1563 Get the clock's description. None if unset.
1566 def description(self):
1567 return _bt_ctf_clock_get_description(self._c)
1570 Set the clock's description. The description appears in the clock's TSDL
1574 def description(self, desc):
1575 ret = _bt_ctf_clock_set_description(self._c, str(desc))
1577 raise ValueError("Invalid clock description.")
1580 Get the clock's frequency (Hz).
1583 def frequency(self):
1584 freq = _bt_ctf_clock_get_frequency(self._c)
1585 if freq == CTFWriter._MAX_UINT64:
1586 raise ValueError("Invalid clock instance")
1590 Set the clock's frequency (Hz).
1593 def frequency(self, freq):
1594 ret = _bt_ctf_clock_set_frequency(self._c, freq)
1596 raise ValueError("Invalid frequency value.")
1599 Get the clock's precision (in clock ticks).
1602 def precision(self):
1603 precision = _bt_ctf_clock_get_precision(self._c)
1604 if precision == CTFWriter._MAX_UINT64:
1605 raise ValueError("Invalid clock instance")
1609 Set the clock's precision (in clock ticks).
1612 def precision(self, precision):
1613 ret = _bt_ctf_clock_set_precision(self._c, precision)
1616 Get the clock's offset in seconds from POSIX.1 Epoch.
1619 def offset_seconds(self):
1620 offset_s = _bt_ctf_clock_get_offset_s(self._c)
1621 if offset_s == CTFWriter._MAX_UINT64:
1622 raise ValueError("Invalid clock instance")
1626 Set the clock's offset in seconds from POSIX.1 Epoch.
1628 @offset_seconds.setter
1629 def offset_seconds(self, offset_s):
1630 ret = _bt_ctf_clock_set_offset_s(self._c, offset_s)
1632 raise ValueError("Invalid offset value.")
1635 Get the clock's offset in ticks from POSIX.1 Epoch + offset in seconds.
1639 offset = _bt_ctf_clock_get_offset(self._c)
1640 if offset == CTFWriter._MAX_UINT64:
1641 raise ValueError("Invalid clock instance")
1645 Set the clock's offset in ticks from POSIX.1 Epoch + offset in seconds.
1648 def offset(self, offset):
1649 ret = _bt_ctf_clock_set_offset(self._c, offset)
1651 raise ValueError("Invalid offset value.")
1654 Get a clock's absolute attribute. A clock is absolute if the clock
1655 is a global reference across the trace's other clocks.
1659 is_absolute = _bt_ctf_clock_get_is_absolute(self._c)
1660 if is_absolute == -1:
1661 raise ValueError("Invalid clock instance")
1662 return False if is_absolute == 0 else True
1665 Set a clock's absolute attribute. A clock is absolute if the clock
1666 is a global reference across the trace's other clocks.
1669 def absolute(self, is_absolute):
1670 ret = _bt_ctf_clock_set_is_absolute(self._c, int(is_absolute))
1672 raise ValueError("Could not set the clock's absolute attribute.")
1675 Get the current time in nanoseconds since the clock's origin (offset and
1676 offset_s attributes).
1680 time = _bt_ctf_clock_get_time(self._c)
1681 if time == CTFWriter._MAX_UINT64:
1682 raise ValueError("Invalid clock instance")
1686 Set the current time in nanoseconds since the clock's origin (offset and
1687 offset_s attributes). The clock's value will be sampled as events are
1688 appended to a stream.
1691 def time(self, time):
1692 ret = _bt_ctf_clock_set_time(self._c, time)
1694 raise ValueError("Invalid time value.")
1696 class FieldDeclaration:
1698 FieldDeclaration should not be instantiated directly. Instantiate
1699 one of the concrete FieldDeclaration classes.
1702 # These values are based on the bt_ctf_integer_base enum
1703 # declared in event-types.h.
1704 INTEGER_BASE_UNKNOWN = -1
1705 INTEGER_BASE_BINARY = 2
1706 INTEGER_BASE_OCTAL = 8
1707 INTEGER_BASE_DECIMAL = 10
1708 INTEGER_BASE_HEXADECIMAL = 16
1711 if self._ft is None:
1712 raise ValueError("FieldDeclaration creation failed.")
1715 _bt_ctf_field_type_put(self._ft)
1718 def _create_field_declaration_from_native_instance(native_field_declaration):
1720 CTFTypeId.INTEGER : CTFWriter.IntegerFieldDeclaration,
1721 CTFTypeId.FLOAT : CTFWriter.FloatFieldDeclaration,
1722 CTFTypeId.ENUM : CTFWriter.EnumerationFieldDeclaration,
1723 CTFTypeId.STRING : CTFWriter.StringFieldDeclaration,
1724 CTFTypeId.STRUCT : CTFWriter.StructureFieldDeclaration,
1725 CTFTypeId.VARIANT : CTFWriter.VariantFieldDeclaration,
1726 CTFTypeId.ARRAY : CTFWriter.ArrayFieldDeclaration,
1727 CTFTypeId.SEQUENCE : CTFWriter.SequenceFieldDeclaration
1730 field_type_id = _bt_ctf_field_type_get_type_id(native_field_declaration)
1731 if field_type_id == CTFTypeId.UNKNOWN:
1732 raise TypeError("Invalid field instance")
1734 declaration = CTFWriter.Field.__new__(CTFWriter.Field)
1735 declaration._ft = native_field_declaration
1736 declaration.__class__ = type_dict[field_type_id]
1740 Get the field declaration's alignment. Returns -1 on error.
1743 def alignment(self):
1744 return _bt_ctf_field_type_get_alignment(self._ft)
1747 Set the field declaration's alignment. Defaults to 1 (bit-aligned). However,
1748 some types, such as structures and string, may impose other alignment
1752 def alignment(self, alignment):
1753 ret = _bt_ctf_field_type_set_alignment(self._ft, alignment)
1755 raise ValueError("Invalid alignment value.")
1758 Get the field declaration's byte order. One of the ByteOrder's constant.
1761 def byte_order(self):
1762 return _bt_ctf_field_type_get_byte_order(self._ft)
1765 Set the field declaration's byte order. Use constants defined in the ByteOrder
1769 def byte_order(self, byte_order):
1770 ret = _bt_ctf_field_type_set_byte_order(self._ft, byte_order)
1772 raise ValueError("Could not set byte order value.")
1774 class IntegerFieldDeclaration(FieldDeclaration):
1776 Create a new integer field declaration of the given size.
1778 def __init__(self, size):
1779 self._ft = _bt_ctf_field_type_integer_create(size)
1783 Get an integer's size.
1787 ret = _bt_ctf_field_type_integer_get_size(self._ft)
1789 raise ValueError("Could not get Integer's size attribute.")
1794 Get an integer's signedness attribute.
1798 ret = _bt_ctf_field_type_integer_get_signed(self._ft)
1800 raise ValueError("Could not get Integer's signed attribute.")
1807 Set an integer's signedness attribute.
1810 def signed(self, signed):
1811 ret = _bt_ctf_field_type_integer_set_signed(self._ft, signed)
1813 raise ValueError("Could not set Integer's signed attribute.")
1816 Get the integer's base used to pretty-print the resulting trace.
1817 Returns a constant from the FieldDeclaration.IntegerBase class.
1821 return _bt_ctf_field_type_integer_get_base(self._ft)
1824 Set the integer's base used to pretty-print the resulting trace.
1825 The base must be a constant of the FieldDeclarationIntegerBase class.
1828 def base(self, base):
1829 ret = _bt_ctf_field_type_integer_set_base(self._ft, base)
1831 raise ValueError("Could not set Integer's base.")
1834 Get the integer's encoding (one of the constants of the
1835 CTFStringEncoding class).
1836 Returns a constant from the CTFStringEncoding class.
1840 return _bt_ctf_field_type_integer_get_encoding(self._ft)
1843 An integer encoding may be set to signal that the integer must be printed
1844 as a text character. Must be a constant from the CTFStringEncoding class.
1847 def encoding(self, encoding):
1848 ret = _bt_ctf_field_type_integer_set_encoding(self._ft, encoding)
1850 raise ValueError("Could not set Integer's encoding.")
1852 class EnumerationFieldDeclaration(FieldDeclaration):
1854 Create a new enumeration field declaration with the given underlying container type.
1856 def __init__(self, integer_type):
1857 if integer_type is None or not isinstance(integer_type, CTFWriter.IntegerFieldDeclaration):
1858 raise TypeError("Invalid integer container.")
1860 self._ft = _bt_ctf_field_type_enumeration_create(integer_type._ft)
1864 Get the enumeration's underlying container type.
1867 def container(self):
1868 ret = _bt_ctf_field_type_enumeration_get_container_type(self._ft)
1870 raise TypeError("Invalid enumeration declaration")
1871 return CTFWriter.FieldDeclaration._create_field_declaration_from_native_instance(ret)
1874 Add a mapping to the enumeration. The range's values are inclusive.
1876 def add_mapping(self, name, range_start, range_end):
1877 if range_start < 0 or range_end < 0:
1878 ret = _bt_ctf_field_type_enumeration_add_mapping(self._ft, str(name), range_start, range_end)
1880 ret = _bt_ctf_field_type_enumeration_add_mapping_unsigned(self._ft, str(name), range_start, range_end)
1883 raise ValueError("Could not add mapping to enumeration declaration.")
1886 Generator returning instances of EnumerationMapping.
1890 signed = self.container.signed
1892 count = _bt_ctf_field_type_enumeration_get_mapping_count(self._ft)
1893 for i in range(count):
1895 ret = _bt_python_ctf_field_type_enumeration_get_mapping(self._ft, i)
1897 ret = _bt_python_ctf_field_type_enumeration_get_mapping_unsigned(self._ft, i)
1900 raise TypeError("Could not get Enumeration mapping at index {}".format(i))
1901 name, range_start, range_end = ret
1902 yield CTFWriter.EnumerationMapping(name, range_start, range_end)
1905 Get a mapping by name (EnumerationMapping).
1907 def get_mapping_by_name(self, name):
1908 ret, index = _bt_ctf_field_type_enumeration_get_mapping_index_by_name(self._ft, name);
1912 if self.container.signed:
1913 ret = _bt_python_ctf_field_type_enumeration_get_mapping(self._ft, index)
1915 ret = _bt_python_ctf_field_type_enumeration_get_mapping_unsigned(self._ft, index)
1918 raise TypeError("Could not get Enumeration mapping at index {}".format(i))
1919 name, range_start, range_end = ret
1920 return CTFWriter.EnumerationMapping(name, range_start, range_end)
1923 Get a mapping by value (EnumerationMapping).
1925 def get_mapping_by_value(self, value):
1927 ret, index = _bt_ctf_field_type_enumeration_get_mapping_index_by_value(self._ft, value);
1929 ret, index = _bt_ctf_field_type_enumeration_get_mapping_index_by_unsigned_value(self._ft, value);
1934 if self.container.signed:
1935 ret = _bt_python_ctf_field_type_enumeration_get_mapping(self._ft, index)
1937 ret = _bt_python_ctf_field_type_enumeration_get_mapping_unsigned(self._ft, index)
1940 raise TypeError("Could not get Enumeration mapping at index {}".format(i))
1941 name, range_start, range_end = ret
1942 return CTFWriter.EnumerationMapping(name, range_start, range_end)
1944 class FloatFieldDeclaration(FieldDeclaration):
1951 Create a new floating point field declaration.
1954 self._ft = _bt_ctf_field_type_floating_point_create()
1958 Get the number of exponent digits used to store the floating point field.
1961 def exponent_digits(self):
1962 ret = _bt_ctf_field_type_floating_point_get_exponent_digits(self._ft)
1964 raise TypeError("Could not get Floating point exponent digit count")
1968 Set the number of exponent digits to use to store the floating point field.
1969 The only values currently supported are FLT_EXP_DIG and DBL_EXP_DIG which
1970 are defined as constants of this class.
1972 @exponent_digits.setter
1973 def exponent_digits(self, exponent_digits):
1974 ret = _bt_ctf_field_type_floating_point_set_exponent_digits(self._ft, exponent_digits)
1976 raise ValueError("Could not set exponent digit count.")
1979 Get the number of mantissa digits used to store the floating point field.
1982 def mantissa_digits(self):
1983 ret = _bt_ctf_field_type_floating_point_get_mantissa_digits(self._ft)
1985 raise TypeError("Could not get Floating point mantissa digit count")
1989 Set the number of mantissa digits to use to store the floating point field.
1990 The only values currently supported are FLT_MANT_DIG and DBL_MANT_DIG which
1991 are defined as constants of this class.
1993 @mantissa_digits.setter
1994 def mantissa_digits(self, mantissa_digits):
1995 ret = _bt_ctf_field_type_floating_point_set_mantissa_digits(self._ft, mantissa_digits)
1997 raise ValueError("Could not set mantissa digit count.")
1999 class StructureFieldDeclaration(FieldDeclaration):
2001 Create a new structure field declaration.
2004 self._ft = _bt_ctf_field_type_structure_create()
2008 Add a field of type "field_type" to the structure.
2010 def add_field(self, field_type, field_name):
2011 ret = _bt_ctf_field_type_structure_add_field(self._ft, field_type._ft, str(field_name))
2013 raise ValueError("Could not add field to structure.")
2016 Generator returning the structure's field as tuples of (field name, field declaration).
2020 count = _bt_ctf_field_type_structure_get_field_count(self._ft)
2022 raise TypeError("Could not get Structure field count")
2024 for i in range(count):
2025 field_name = _bt_python_ctf_field_type_structure_get_field_name(self._ft, i)
2026 if field_name is None:
2027 raise TypeError("Could not get Structure field name at index {}".format(i))
2029 field_type_native = _bt_python_ctf_field_type_structure_get_field_type(self._ft, i)
2030 if field_type_native is None:
2031 raise TypeError("Could not get Structure field type at index {}".format(i))
2033 field_type = CTFWriter.FieldDeclaration._create_field_declaration_from_native_instance(field_type_native)
2034 yield (field_name, field_type)
2037 Get a field declaration by name (FieldDeclaration).
2039 def get_field_by_name(self, name):
2040 field_type_native = _bt_ctf_field_type_structure_get_field_type_by_name(self._ft, name)
2041 if field_type_native is None:
2042 raise TypeError("Could not find Structure field with name {}".format(name))
2044 return CTFWriter.FieldDeclaration._create_field_declaration_from_native_instance(field_type_native)
2046 class VariantFieldDeclaration(FieldDeclaration):
2048 Create a new variant field declaration.
2050 def __init__(self, enum_tag, tag_name):
2051 if enum_tag is None or not isinstance(enum_tag, CTFWriter.EnumerationFieldDeclaration):
2052 raise TypeError("Invalid tag type; must be of type EnumerationFieldDeclaration.")
2054 self._ft = _bt_ctf_field_type_variant_create(enum_tag._ft, str(tag_name))
2058 Get the variant's tag name.
2062 ret = _bt_ctf_field_type_variant_get_tag_name(self._ft)
2064 raise TypeError("Could not get Variant tag name")
2068 Get the variant's tag type.
2072 ret = _bt_ctf_field_type_variant_get_tag_type(self._ft)
2074 raise TypeError("Could not get Variant tag type")
2075 return CTFWriter.FieldDeclaration._create_field_declaration_from_native_instance(ret)
2078 Add a field of type "field_type" to the variant.
2080 def add_field(self, field_type, field_name):
2081 ret = _bt_ctf_field_type_variant_add_field(self._ft, field_type._ft, str(field_name))
2083 raise ValueError("Could not add field to variant.")
2086 Generator returning the variant's field as tuples of (field name, field declaration).
2090 count = _bt_ctf_field_type_variant_get_field_count(self._ft)
2092 raise TypeError("Could not get Variant field count")
2094 for i in range(count):
2095 field_name = _bt_python_ctf_field_type_variant_get_field_name(self._ft, i)
2096 if field_name is None:
2097 raise TypeError("Could not get Variant field name at index {}".format(i))
2099 field_type_native = _bt_python_ctf_field_type_variant_get_field_type(self._ft, i)
2100 if field_type_native is None:
2101 raise TypeError("Could not get Variant field type at index {}".format(i))
2103 field_type = CTFWriter.FieldDeclaration._create_field_declaration_from_native_instance(field_type_native)
2104 yield (field_name, field_type)
2107 Get a field declaration by name (FieldDeclaration).
2109 def get_field_by_name(self, name):
2110 field_type_native = _bt_ctf_field_type_variant_get_field_type_by_name(self._ft, name)
2111 if field_type_native is None:
2112 raise TypeError("Could not find Variant field with name {}".format(name))
2114 return CTFWriter.FieldDeclaration._create_field_declaration_from_native_instance(field_type_native)
2117 Get a field declaration from tag (EnumerationField).
2119 def get_field_from_tag(self, tag):
2120 field_type_native = _bt_ctf_field_type_variant_get_field_type_from_tag(self._ft, tag._f)
2121 if field_type_native is None:
2122 raise TypeError("Could not find Variant field with tag value {}".format(tag.value))
2124 return CTFWriter.FieldDeclaration._create_field_declaration_from_native_instance(field_type_native)
2126 class ArrayFieldDeclaration(FieldDeclaration):
2128 Create a new array field declaration.
2130 def __init__(self, element_type, length):
2131 self._ft = _bt_ctf_field_type_array_create(element_type._ft, length)
2135 Get the array's element type.
2138 def element_type(self):
2139 ret = _bt_ctf_field_type_array_get_element_type(self._ft)
2141 raise TypeError("Could not get Array element type")
2142 return CTFWriter.FieldDeclaration._create_field_declaration_from_native_instance(ret)
2145 Get the array's length.
2149 ret = _bt_ctf_field_type_array_get_length(self._ft)
2151 raise TypeError("Could not get Array length")
2154 class SequenceFieldDeclaration(FieldDeclaration):
2156 Create a new sequence field declaration.
2158 def __init__(self, element_type, length_field_name):
2159 self._ft = _bt_ctf_field_type_sequence_create(element_type._ft, str(length_field_name))
2163 Get the sequence's element type.
2166 def element_type(self):
2167 ret = _bt_ctf_field_type_sequence_get_element_type(self._ft)
2169 raise TypeError("Could not get Sequence element type")
2170 return CTFWriter.FieldDeclaration._create_field_declaration_from_native_instance(ret)
2173 Get the sequence's length field name.
2176 def length_field_name(self):
2177 ret = _bt_ctf_field_type_sequence_get_length_field_name(self._ft)
2179 raise TypeError("Could not get Sequence length field name")
2182 class StringFieldDeclaration(FieldDeclaration):
2184 Create a new string field declaration.
2187 self._ft = _bt_ctf_field_type_string_create()
2191 Get a string declaration's encoding (a constant from the CTFStringEncoding class).
2195 return _bt_ctf_field_type_string_get_encoding(self._ft)
2198 Set a string declaration's encoding. Must be a constant from the CTFStringEncoding class.
2201 def encoding(self, encoding):
2202 ret = _bt_ctf_field_type_string_set_encoding(self._ft, encoding)
2204 raise ValueError("Could not set string encoding.")
2207 Create an instance of a field.
2210 def create_field(field_type):
2211 if field_type is None or not isinstance(field_type, CTFWriter.FieldDeclaration):
2212 raise TypeError("Invalid field_type. Type must be a FieldDeclaration-derived class.")
2214 if isinstance(field_type, CTFWriter.IntegerFieldDeclaration):
2215 return CTFWriter.IntegerField(field_type)
2216 elif isinstance(field_type, CTFWriter.EnumerationFieldDeclaration):
2217 return CTFWriter.EnumerationField(field_type)
2218 elif isinstance(field_type, CTFWriter.FloatFieldDeclaration):
2219 return CTFWriter.FloatFieldingPoint(field_type)
2220 elif isinstance(field_type, CTFWriter.StructureFieldDeclaration):
2221 return CTFWriter.StructureField(field_type)
2222 elif isinstance(field_type, CTFWriter.VariantFieldDeclaration):
2223 return CTFWriter.VariantField(field_type)
2224 elif isinstance(field_type, CTFWriter.ArrayFieldDeclaration):
2225 return CTFWriter.ArrayField(field_type)
2226 elif isinstance(field_type, CTFWriter.SequenceFieldDeclaration):
2227 return CTFWriter.SequenceField(field_type)
2228 elif isinstance(field_type, CTFWriter.StringFieldDeclaration):
2229 return CTFWriter.StringField(field_type)
2233 Base class, do not instantiate.
2235 def __init__(self, field_type):
2236 if not isinstance(field_type, CTFWriter.FieldDeclaration):
2237 raise TypeError("Invalid field_type argument.")
2239 self._f = _bt_ctf_field_create(field_type._ft)
2241 raise ValueError("Field creation failed.")
2244 _bt_ctf_field_put(self._f)
2247 def _create_field_from_native_instance(native_field_instance):
2249 CTFTypeId.INTEGER : CTFWriter.IntegerField,
2250 CTFTypeId.FLOAT : CTFWriter.FloatFieldingPoint,
2251 CTFTypeId.ENUM : CTFWriter.EnumerationField,
2252 CTFTypeId.STRING : CTFWriter.StringField,
2253 CTFTypeId.STRUCT : CTFWriter.StructureField,
2254 CTFTypeId.VARIANT : CTFWriter.VariantField,
2255 CTFTypeId.ARRAY : CTFWriter.ArrayField,
2256 CTFTypeId.SEQUENCE : CTFWriter.SequenceField
2259 field_type = _bt_python_get_field_type(native_field_instance)
2260 if field_type == CTFTypeId.UNKNOWN:
2261 raise TypeError("Invalid field instance")
2263 field = CTFWriter.Field.__new__(CTFWriter.Field)
2264 field._f = native_field_instance
2265 field.__class__ = type_dict[field_type]
2269 def declaration(self):
2270 native_field_type = _bt_ctf_field_get_type(self._f)
2271 if native_field_type is None:
2272 raise TypeError("Invalid field instance")
2273 return CTFWriter.FieldDeclaration._create_field_declaration_from_native_instance(native_field_type)
2275 class IntegerField(Field):
2277 Get an integer field's value.
2281 signedness = _bt_python_field_integer_get_signedness(self._f)
2283 raise TypeError("Invalid integer instance.")
2286 ret, value = _bt_ctf_field_unsigned_integer_get_value(self._f)
2288 ret, value = _bt_ctf_field_signed_integer_get_value(self._f)
2291 raise ValueError("Could not get integer field value.")
2295 Set an integer field's value.
2298 def value(self, value):
2299 if not isinstance(value, int):
2300 raise TypeError("IntegerField's value must be an int")
2302 signedness = _bt_python_field_integer_get_signedness(self._f)
2304 raise TypeError("Invalid integer instance.")
2307 ret = _bt_ctf_field_unsigned_integer_set_value(self._f, value)
2309 ret = _bt_ctf_field_signed_integer_set_value(self._f, value)
2312 raise ValueError("Could not set integer field value.")
2314 class EnumerationField(Field):
2316 Return the enumeration's underlying container field (an integer field).
2319 def container(self):
2320 container = CTFWriter.IntegerField.__new__(CTFWriter.IntegerField)
2321 container._f = _bt_ctf_field_enumeration_get_container(self._f)
2322 if container._f is None:
2323 raise TypeError("Invalid enumeration field type.")
2327 Get the enumeration field's mapping name.
2331 value = _bt_ctf_field_enumeration_get_mapping_name(self._f)
2333 raise ValueError("Could not get enumeration's mapping name.")
2337 Set the enumeration field's value. Must be an integer as mapping names
2341 def value(self, value):
2342 if not isinstance(value, int):
2343 raise TypeError("EnumerationField value must be an int")
2344 self.container.value = value
2346 class FloatFieldingPoint(Field):
2348 Get a floating point field's value.
2352 ret, value = _bt_ctf_field_floating_point_get_value(self._f)
2354 raise ValueError("Could not get floating point field value.")
2358 Set a floating point field's value.
2361 def value(self, value):
2362 if not isinstance(value, int) and not isinstance(value, float):
2363 raise TypeError("Value must be either a float or an int")
2365 ret = _bt_ctf_field_floating_point_set_value(self._f, float(value))
2367 raise ValueError("Could not set floating point field value.")
2369 class StructureField(Field):
2371 Get the structure's field corresponding to the provided field name.
2373 def field(self, field_name):
2374 native_instance = _bt_ctf_field_structure_get_field(self._f, str(field_name))
2375 if native_instance is None:
2376 raise ValueError("Invalid field_name provided.")
2377 return CTFWriter.Field._create_field_from_native_instance(native_instance)
2379 class VariantField(Field):
2381 Return the variant's selected field. The "tag" field is the selector enum field.
2383 def field(self, tag):
2384 native_instance = _bt_ctf_field_variant_get_field(self._f, tag._f)
2385 if native_instance is None:
2386 raise ValueError("Invalid tag provided.")
2387 return CTFWriter.Field._create_field_from_native_instance(native_instance)
2389 class ArrayField(Field):
2391 Return the array's field at position "index".
2393 def field(self, index):
2394 native_instance = _bt_ctf_field_array_get_field(self._f, index)
2395 if native_instance is None:
2396 raise IndexError("Invalid index provided.")
2397 return CTFWriter.Field._create_field_from_native_instance(native_instance)
2399 class SequenceField(Field):
2401 Get the sequence's length field (IntegerField).
2405 native_instance = _bt_ctf_field_sequence_get_length(self._f)
2406 if native_instance is None:
2408 return CTFWriter.Field._create_field_from_native_instance(native_instance)
2411 Set the sequence's length field (IntegerField).
2414 def length(self, length_field):
2415 if not isinstance(length_field, CTFWriter.IntegerField):
2416 raise TypeError("Invalid length field.")
2417 if length_field.declaration.signed:
2418 raise TypeError("Sequence field length must be unsigned")
2419 ret = _bt_ctf_field_sequence_set_length(self._f, length_field._f)
2421 raise ValueError("Could not set sequence length.")
2424 Return the sequence's field at position "index".
2426 def field(self, index):
2427 native_instance = _bt_ctf_field_sequence_get_field(self._f, index)
2428 if native_instance is None:
2429 raise ValueError("Could not get sequence element at index.")
2430 return CTFWriter.Field._create_field_from_native_instance(native_instance)
2432 class StringField(Field):
2434 Get a string field's value.
2438 return _bt_ctf_field_string_get_value(self._f)
2441 Set a string field's value.
2444 def value(self, value):
2445 ret = _bt_ctf_field_string_set_value(self._f, str(value))
2447 raise ValueError("Could not set string field value.")
2451 Create a new event class of the given name.
2453 def __init__(self, name):
2454 self._ec = _bt_ctf_event_class_create(name)
2455 if self._ec is None:
2456 raise ValueError("Event class creation failed.")
2459 _bt_ctf_event_class_put(self._ec)
2462 Add a field of type "field_type" to the event class.
2464 def add_field(self, field_type, field_name):
2465 ret = _bt_ctf_event_class_add_field(self._ec, field_type._ft, str(field_name))
2467 raise ValueError("Could not add field to event class.")
2471 Create a new event of the given event class.
2473 def __init__(self, event_class):
2474 if not isinstance(event_class, CTFWriter.EventClass):
2475 raise TypeError("Invalid event_class argument.")
2477 self._e = _bt_ctf_event_create(event_class._ec)
2479 raise ValueError("Event creation failed.")
2482 _bt_ctf_event_put(self._e)
2485 Set a manually created field as an event's payload.
2487 def set_payload(self, field_name, value_field):
2488 if not isinstance(value, CTFWriter.Field):
2489 raise TypeError("Invalid value type.")
2490 ret = _bt_ctf_event_set_payload(self._e, str(field_name), value_field._f)
2492 raise ValueError("Could not set event field payload.")
2495 Get a field from event.
2497 def payload(self, field_name):
2498 native_instance = _bt_ctf_event_get_payload(self._e, str(field_name))
2499 if native_instance is None:
2500 raise ValueError("Could not get event payload.")
2501 return CTFWriter.Field._create_field_from_native_instance(native_instance)
2505 Create a new stream class of the given name.
2507 def __init__(self, name):
2508 self._sc = _bt_ctf_stream_class_create(name)
2509 if self._sc is None:
2510 raise ValueError("Stream class creation failed.")
2513 _bt_ctf_stream_class_put(self._sc)
2516 Get a stream class' clock.
2520 raise NotImplementedError("Getter not implemented.")
2523 Assign a clock to a stream class.
2526 def clock(self, clock):
2527 if not isinstance(clock, CTFWriter.Clock):
2528 raise TypeError("Invalid clock type.")
2530 ret = _bt_ctf_stream_class_set_clock(self._sc, clock._c)
2532 raise ValueError("Could not set stream class clock.")
2535 Add an event class to a stream class. New events can be added even after a
2536 stream has been instantiated and events have been appended. However, a stream
2537 will not accept events of a class that has not been registered beforehand.
2539 def add_event_class(self, event_class):
2540 if not isinstance(event_class, CTFWriter.EventClass):
2541 raise TypeError("Invalid event_class type.")
2543 ret = _bt_ctf_stream_class_add_event_class(self._sc, event_class._ec)
2545 raise ValueError("Could not add event class.")
2549 Create a stream of the given class.
2551 def __init__(self, stream_class):
2552 if not isinstance(stream_class, CTFWriter.StreamClass):
2553 raise TypeError("Invalid stream_class type.")
2555 self._s = _bt_ctf_stream_create(stream_class._sc)
2557 raise ValueError("Stream creation failed.")
2560 _bt_ctf_stream_put(self._s)
2563 Increase the current packet's discarded event count.
2565 def append_discarded_events(self, event_count):
2566 _bt_ctf_stream_append_discarded_events(self._s, event_count)
2569 Append "event" to the stream's current packet. The stream's associated clock
2570 will be sampled during this call. The event shall not be modified after
2571 being appended to a stream.
2573 def append_event(self, event):
2574 ret = _bt_ctf_stream_append_event(self._s, event._e)
2576 raise ValueError("Could not append event to stream.")
2579 The stream's current packet's events will be flushed to disk. Events
2580 subsequently appended to the stream will be added to a new packet.
2583 ret = _bt_ctf_stream_flush(self._s)
2585 raise ValueError("Could not flush stream.")
2589 Create a new writer that will produce a trace in the given path.
2591 def __init__(self, path):
2592 self._w = _bt_ctf_writer_create(path)
2594 raise ValueError("Writer creation failed.")
2597 _bt_ctf_writer_put(self._w)
2600 Create a new stream instance and register it to the writer.
2602 def create_stream(self, stream_class):
2603 if not isinstance(stream_class, CTFWriter.StreamClass):
2604 raise TypeError("Invalid stream_class type.")
2606 stream = CTFWriter.Stream.__new__(CTFWriter.Stream)
2607 stream._s = _bt_ctf_writer_create_stream(self._w, stream_class._sc)
2611 Add an environment field to the trace.
2613 def add_environment_field(self, name, value):
2614 ret = _bt_ctf_writer_add_environment_field(self._w, str(name), str(value))
2616 raise ValueError("Could not add environment field to trace.")
2619 Add a clock to the trace. Clocks assigned to stream classes must be
2620 registered to the writer.
2622 def add_clock(self, clock):
2623 ret = _bt_ctf_writer_add_clock(self._w, clock._c)
2625 raise ValueError("Could not add clock to Writer.")
2628 Get the trace's TSDL meta-data.
2632 return _bt_ctf_writer_get_metadata_string(self._w)
2635 Flush the trace's metadata to the metadata file.
2637 def flush_metadata(self):
2638 _bt_ctf_writer_flush_metadata(self._w)
2641 Get the trace's byte order. Must be a constant from the ByteOrder
2645 def byte_order(self):
2646 raise NotImplementedError("Getter not implemented.")
2649 Set the trace's byte order. Must be a constant from the ByteOrder
2650 class. Defaults to BYTE_ORDER_NATIVE, the host machine's endianness.
2653 def byte_order(self, byte_order):
2654 ret = _bt_ctf_writer_set_byte_order(self._w, byte_order)
2656 raise ValueError("Could not set trace's byte order.")