4 * Babeltrace Python Module interface file
6 * Copyright 2012 EfficiOS Inc.
8 * Author: Danny Serres <danny.serres@efficios.com>
9 * Author: Jérémie Galarneau <jeremie.galarneau@efficios.com>
11 * Permission is hereby granted, free of charge, to any person obtaining a copy
12 * of this software and associated documentation files (the "Software"), to deal
13 * in the Software without restriction, including without limitation the rights
14 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
15 * copies of the Software, and to permit persons to whom the Software is
16 * furnished to do so, subject to the following conditions:
18 * The above copyright notice and this permission notice shall be included in
19 * all copies or substantial portions of the Software.
24 "BABELTRACE_VERSION_STR
26 Babeltrace is a trace viewer and converter reading and writing the
27 Common Trace Format (CTF). Its main use is to pretty-print CTF
28 traces into a human-readable text output.
30 To use this module, the first step is to create a TraceCollection and add a
34 %module(docstring=DOCSTRING) babeltrace
39 #define SWIG_FILE_WITH_INIT
40 #include <babeltrace/babeltrace.h>
41 #include <babeltrace/babeltrace-internal.h>
42 #include <babeltrace/trace-handle.h>
43 #include <babeltrace/trace-handle-internal.h>
44 #include <babeltrace/context.h>
45 #include <babeltrace/context-internal.h>
46 #include <babeltrace/iterator.h>
47 #include <babeltrace/iterator-internal.h>
48 #include <babeltrace/format.h>
49 #include <babeltrace/list.h>
50 #include <babeltrace/types.h>
51 #include <babeltrace/ctf/iterator.h>
52 #include "python-complements.h"
53 #include <babeltrace/ctf-writer/clock.h>
54 #include <babeltrace/ctf-writer/event-fields.h>
55 #include <babeltrace/ctf-writer/event-types.h>
56 #include <babeltrace/ctf-writer/event.h>
57 #include <babeltrace/ctf-writer/stream.h>
58 #include <babeltrace/ctf-writer/writer.h>
61 typedef int bt_intern_str;
62 typedef int64_t ssize_t;
64 /* python-complements.h */
65 struct bt_definition **_bt_python_field_listcaller(
66 const struct bt_ctf_event *ctf_event,
67 const struct bt_definition *scope,
68 unsigned int *OUTPUT);
69 struct bt_definition *_bt_python_field_one_from_list(
70 struct bt_definition **list, int index);
71 struct bt_ctf_event_decl **_bt_python_event_decl_listcaller(
73 struct bt_context *ctx,
74 unsigned int *OUTPUT);
75 struct bt_ctf_event_decl *_bt_python_decl_one_from_list(
76 struct bt_ctf_event_decl **list, int index);
77 struct bt_ctf_field_decl **_by_python_field_decl_listcaller(
78 struct bt_ctf_event_decl *event_decl,
79 enum bt_ctf_scope scope,
80 unsigned int *OUTPUT);
81 struct bt_ctf_field_decl *_bt_python_field_decl_one_from_list(
82 struct bt_ctf_field_decl **list, int index);
83 struct definition_array *_bt_python_get_array_from_def(
84 struct bt_definition *field);
85 struct definition_sequence *_bt_python_get_sequence_from_def(
86 struct bt_definition *field);
87 struct bt_declaration *_bt_python_get_array_element_declaration(
88 struct bt_declaration *field);
89 struct bt_declaration *_bt_python_get_sequence_element_declaration(
90 struct bt_declaration *field);
91 const char *_bt_python_get_array_string(struct bt_definition *field);
92 const char *_bt_python_get_sequence_string(struct bt_definition *field);
93 int _bt_python_field_integer_get_signedness(const struct bt_ctf_field *field);
94 enum ctf_type_id _bt_python_get_field_type(const struct bt_ctf_field *field);
95 const char *_bt_python_ctf_field_type_enumeration_get_mapping(
96 struct bt_ctf_field_type *enumeration, size_t index,
97 int64_t *OUTPUT, int64_t *OUTPUT);
98 const char *_bt_python_ctf_field_type_enumeration_get_mapping_unsigned(
99 struct bt_ctf_field_type *enumeration, size_t index,
100 uint64_t *OUTPUT, uint64_t *OUTPUT);
101 const char *_bt_python_ctf_field_type_structure_get_field_name(
102 struct bt_ctf_field_type *structure, size_t index);
103 struct bt_ctf_field_type *_bt_python_ctf_field_type_structure_get_field_type(
104 struct bt_ctf_field_type *structure, size_t index);
105 const char *_bt_python_ctf_field_type_variant_get_field_name(
106 struct bt_ctf_field_type *variant, size_t index);
107 struct bt_ctf_field_type *_bt_python_ctf_field_type_variant_get_field_type(
108 struct bt_ctf_field_type *variant, size_t index);
109 const char *_bt_python_ctf_event_class_get_field_name(
110 struct bt_ctf_event_class *event_class, size_t index);
111 struct bt_ctf_field_type *_bt_python_ctf_event_class_get_field_type(
112 struct bt_ctf_event_class *event_class, size_t index);
113 int _bt_python_ctf_clock_get_uuid_index(struct bt_ctf_clock *clock,
114 size_t index, unsigned char *OUTPUT);
115 int _bt_python_ctf_clock_set_uuid_index(struct bt_ctf_clock *clock,
116 size_t index, unsigned char value);
118 /* context.h, context-internal.h */
119 %rename("_bt_context_create") bt_context_create(void);
120 %rename("_bt_context_add_trace") bt_context_add_trace(
121 struct bt_context *ctx, const char *path, const char *format,
122 void (*packet_seek)(struct bt_stream_pos *pos, size_t index, int whence),
123 struct bt_mmap_stream_list *stream_list, FILE *metadata);
124 %rename("_bt_context_remove_trace") bt_context_remove_trace(
125 struct bt_context *ctx, int trace_id);
126 %rename("_bt_context_get") bt_context_get(struct bt_context *ctx);
127 %rename("_bt_context_put") bt_context_put(struct bt_context *ctx);
128 %rename("_bt_ctf_event_get_context") bt_ctf_event_get_context(
129 const struct bt_ctf_event *event);
131 struct bt_context *bt_context_create(void);
132 int bt_context_add_trace(struct bt_context *ctx, const char *path, const char *format,
133 void (*packet_seek)(struct bt_stream_pos *pos, size_t index, int whence),
134 struct bt_mmap_stream_list *stream_list, FILE *metadata);
135 void bt_context_remove_trace(struct bt_context *ctx, int trace_id);
136 void bt_context_get(struct bt_context *ctx);
137 void bt_context_put(struct bt_context *ctx);
138 struct bt_context *bt_ctf_event_get_context(const struct bt_ctf_event *event);
140 /* class TraceCollection to prevent direct access to struct bt_context */
143 class TraceCollection:
146 The TraceCollection is the object that contains all currently opened traces.
150 self._tc = _bt_context_create()
153 _bt_context_put(self._tc)
155 def add_trace(self, path, format_str):
157 Add a trace by path to the TraceCollection.
161 path is the path to the trace, it is not recursive.
162 If "path" is None, stream_list is used instead as a list
163 of mmap streams to open for the trace.
165 format is a string containing the format name in which the trace was
168 Return: the corresponding TraceHandle on success or None on error.
170 ret = _bt_context_add_trace(
180 th = TraceHandle.__new__(TraceHandle)
182 th._trace_collection = self
185 def add_traces_recursive(self, path, format_str):
187 Open a trace recursively.
189 Find each trace present in the subdirectory starting from the given
190 path, and add them to the TraceCollection.
192 Return a dict of TraceHandle instances (the full path is the key).
193 Return None on error.
203 for fullpath, dirs, files in os.walk(path):
204 if "metadata" in files:
205 trace_handle = self.add_trace(fullpath, format_str)
206 if trace_handle is None:
210 trace_handles[fullpath] = trace_handle
213 if noTrace and error:
217 def remove_trace(self, trace_handle):
219 Remove a trace from the TraceCollection.
220 Effectively closing the trace.
223 _bt_context_remove_trace(self._tc, trace_handle._id)
224 except AttributeError:
225 raise TypeError("in remove_trace, "
226 "argument 2 must be a TraceHandle instance")
231 Generator function to iterate over the events of open in the current
234 Due to limitations of the native Babeltrace API, only one event
235 may be "alive" at a time (i.e. a user should never store a copy
236 of the events returned by this function for ulterior use). Users
237 shall make sure to copy the information they need from an event
238 before accessing the next one.
240 Furthermore, event objects become invalid when the generator goes
241 out of scope as the underlying iterator will be reclaimed. Using an
242 event after the the generator has gone out of scope may result in a
243 crash or data corruption.
245 begin_pos_ptr = _bt_iter_pos()
246 end_pos_ptr = _bt_iter_pos()
247 begin_pos_ptr.type = SEEK_BEGIN
248 end_pos_ptr.type = SEEK_LAST
250 for event in self._events(begin_pos_ptr, end_pos_ptr):
253 def events_timestamps(self, timestamp_begin, timestamp_end):
255 Generator function to iterate over the events of open in the current
256 TraceCollection from timestamp_begin to timestamp_end.
258 begin_pos_ptr = _bt_iter_pos()
259 end_pos_ptr = _bt_iter_pos()
260 begin_pos_ptr.type = end_pos_ptr.type = SEEK_TIME
261 begin_pos_ptr.u.seek_time = timestamp_begin
262 end_pos_ptr.u.seek_time = timestamp_end
264 for event in self._events(begin_pos_ptr, end_pos_ptr):
268 def timestamp_begin(self):
269 pos_ptr = _bt_iter_pos()
270 pos_ptr.type = SEEK_BEGIN
271 return self._timestamp_at_pos(pos_ptr)
274 def timestamp_end(self):
275 pos_ptr = _bt_iter_pos()
276 pos_ptr.type = SEEK_LAST
277 return self._timestamp_at_pos(pos_ptr)
279 def _timestamp_at_pos(self, pos_ptr):
280 ctf_it_ptr = _bt_ctf_iter_create(self._tc, pos_ptr, pos_ptr)
281 if ctf_it_ptr is None:
282 raise NotImplementedError(
283 "Creation of multiple iterators is unsupported.")
284 ev_ptr = _bt_ctf_iter_read_event(ctf_it_ptr)
285 _bt_ctf_iter_destroy(ctf_it_ptr)
289 def _events(self, begin_pos_ptr, end_pos_ptr):
290 ctf_it_ptr = _bt_ctf_iter_create(self._tc, begin_pos_ptr, end_pos_ptr)
291 if ctf_it_ptr is None:
292 raise NotImplementedError(
293 "Creation of multiple iterators is unsupported.")
296 ev_ptr = _bt_ctf_iter_read_event(ctf_it_ptr)
300 ev = Event.__new__(Event)
304 except GeneratorExit:
307 ret = _bt_iter_next(_bt_ctf_get_iter(ctf_it_ptr))
311 _bt_ctf_iter_destroy(ctf_it_ptr)
317 %rename("lookup_format") bt_lookup_format(bt_intern_str qname);
318 %rename("_bt_print_format_list") bt_fprintf_format_list(FILE *fp);
319 %rename("register_format") bt_register_format(struct format *format);
320 %rename("unregister_format") bt_unregister_format(struct bt_format *format);
322 extern struct format *bt_lookup_format(bt_intern_str qname);
323 extern void bt_fprintf_format_list(FILE *fp);
324 extern int bt_register_format(struct bt_format *format);
325 extern void bt_unregister_format(struct bt_format *format);
329 def print_format_list(babeltrace_file):
331 Print a list of available formats to file.
333 babeltrace_file must be a File instance opened in write mode.
336 if babeltrace_file._file is not None:
337 _bt_print_format_list(babeltrace_file._file)
338 except AttributeError:
339 raise TypeError("in print_format_list, "
340 "argument 1 must be a File instance")
344 /* iterator.h, iterator-internal.h */
345 %rename("_bt_iter_create") bt_iter_create(struct bt_context *ctx,
346 const struct bt_iter_pos *begin_pos, const struct bt_iter_pos *end_pos);
347 %rename("_bt_iter_destroy") bt_iter_destroy(struct bt_iter *iter);
348 %rename("_bt_iter_next") bt_iter_next(struct bt_iter *iter);
349 %rename("_bt_iter_get_pos") bt_iter_get_pos(struct bt_iter *iter);
350 %rename("_bt_iter_free_pos") bt_iter_free_pos(struct bt_iter_pos *pos);
351 %rename("_bt_iter_set_pos") bt_iter_set_pos(struct bt_iter *iter,
352 const struct bt_iter_pos *pos);
353 %rename("_bt_iter_create_time_pos") bt_iter_create_time_pos(struct bt_iter *iter,
356 struct bt_iter *bt_iter_create(struct bt_context *ctx,
357 const struct bt_iter_pos *begin_pos, const struct bt_iter_pos *end_pos);
358 void bt_iter_destroy(struct bt_iter *iter);
359 int bt_iter_next(struct bt_iter *iter);
360 struct bt_iter_pos *bt_iter_get_pos(struct bt_iter *iter);
361 void bt_iter_free_pos(struct bt_iter_pos *pos);
362 int bt_iter_set_pos(struct bt_iter *iter, const struct bt_iter_pos *pos);
363 struct bt_iter_pos *bt_iter_create_time_pos(struct bt_iter *iter, uint64_t timestamp);
365 %rename("_bt_iter_pos") bt_iter_pos;
366 %rename("SEEK_TIME") BT_SEEK_TIME;
367 %rename("SEEK_RESTORE") BT_SEEK_RESTORE;
368 %rename("SEEK_CUR") BT_SEEK_CUR;
369 %rename("SEEK_BEGIN") BT_SEEK_BEGIN;
370 %rename("SEEK_LAST") BT_SEEK_LAST;
373 * This struct is taken from iterator.h
374 * All changes to the struct must also be made here.
378 BT_SEEK_TIME, /* uses u.seek_time */
379 BT_SEEK_RESTORE, /* uses u.restore */
386 struct bt_saved_pos *restore;
390 /* trace-handle.h, trace-handle-internal.h */
391 %rename("_bt_trace_handle_create") bt_trace_handle_create(struct bt_context *ctx);
392 %rename("_bt_trace_handle_destroy") bt_trace_handle_destroy(struct bt_trace_handle *bt);
393 struct bt_trace_handle *bt_trace_handle_create(struct bt_context *ctx);
394 void bt_trace_handle_destroy(struct bt_trace_handle *bt);
396 %rename("_bt_trace_handle_get_path") bt_trace_handle_get_path(struct bt_context *ctx,
398 %rename("_bt_trace_handle_get_timestamp_begin") bt_trace_handle_get_timestamp_begin(
399 struct bt_context *ctx, int handle_id, enum bt_clock_type type);
400 %rename("_bt_trace_handle_get_timestamp_end") bt_trace_handle_get_timestamp_end(
401 struct bt_context *ctx, int handle_id, enum bt_clock_type type);
402 const char *bt_trace_handle_get_path(struct bt_context *ctx, int handle_id);
403 uint64_t bt_trace_handle_get_timestamp_begin(struct bt_context *ctx, int handle_id,
404 enum bt_clock_type type);
405 uint64_t bt_trace_handle_get_timestamp_end(struct bt_context *ctx, int handle_id,
406 enum bt_clock_type type);
408 %rename("_bt_ctf_event_get_handle_id") bt_ctf_event_get_handle_id(
409 const struct bt_ctf_event *event);
410 int bt_ctf_event_get_handle_id(const struct bt_ctf_event *event);
415 # Based on enum bt_clock_type in clock-type.h
421 class TraceHandle(object):
424 The TraceHandle allows the user to manipulate a trace file directly.
425 It is a unique identifier representing a trace file.
430 raise NotImplementedError("TraceHandle cannot be instantiated")
433 return "Babeltrace TraceHandle: trace_id('{0}')".format(self._id)
437 """Return the TraceHandle id."""
442 """Return the path of a TraceHandle."""
443 return _bt_trace_handle_get_path(self._trace_collection._tc, self._id)
446 def timestamp_begin(self):
447 """Return the creation time of the buffers of a trace."""
448 return _bt_trace_handle_get_timestamp_begin(
449 self._trace_collection._tc, self._id, ClockType.CLOCK_REAL)
452 def timestamp_end(self):
453 """Return the destruction timestamp of the buffers of a trace."""
454 return _bt_trace_handle_get_timestamp_end(
455 self._trace_collection._tc, self._id, ClockType.CLOCK_REAL)
460 Generator returning all events (EventDeclaration) in a trace.
462 ret = _bt_python_event_decl_listcaller(
464 self._trace_collection._tc)
466 if not isinstance(ret, list):
469 ptr_list, count = ret
470 for i in range(count):
471 tmp = EventDeclaration.__new__(EventDeclaration)
472 tmp._ed = _bt_python_decl_one_from_list(ptr_list, i)
477 /* iterator.h, events.h */
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
613 name = "UNKNOWN_TYPE"
615 attr for attr in dir(CTFTypeId) if not callable(
618 attr)) and not attr.startswith("__")]
619 for attr in constants:
620 if getattr(CTFTypeId, attr) == id:
627 TRACE_PACKET_HEADER = 0
628 STREAM_PACKET_CONTEXT = 1
629 STREAM_EVENT_HEADER = 2
630 STREAM_EVENT_CONTEXT = 3
634 def scope_name(scope):
635 name = "UNKNOWN_SCOPE"
637 attr for attr in dir(CTFScope) if not callable(
640 attr)) and not attr.startswith("__")]
641 for attr in constants:
642 if getattr(CTFScope, attr) == scope:
647 # Priority of the scopes when searching for event fields
648 _scopes = [CTFScope.EVENT_FIELDS, CTFScope.EVENT_CONTEXT, CTFScope.STREAM_EVENT_CONTEXT,
649 CTFScope.STREAM_EVENT_HEADER, CTFScope.STREAM_PACKET_CONTEXT, CTFScope.TRACE_PACKET_HEADER]
652 from datetime import datetime
655 class Event(collections.Mapping):
658 This class represents an event from the trace.
659 It is obtained using the TraceCollection generator functions.
664 raise NotImplementedError("Event cannot be instantiated")
668 """Return the name of the event or None on error."""
669 return _bt_ctf_event_name(self._e)
674 Return the timestamp of the event as written in
675 the packet (in cycles) or -1ULL on error.
677 return _bt_ctf_get_cycles(self._e)
682 Return the timestamp of the event offset with the
683 system clock source or -1ULL on error.
685 return _bt_ctf_get_timestamp(self._e)
690 Return a datetime object based on the event's
691 timestamp. Note that the datetime class' precision
692 is limited to microseconds.
694 return datetime.fromtimestamp(self.timestamp / 1E9)
696 def field_with_scope(self, field_name, scope):
698 Get field_name's value in scope.
699 None is returned if no field matches field_name.
701 if not scope in _scopes:
702 raise ValueError("Invalid scope provided")
703 field = self._field_with_scope(field_name, scope)
704 if field is not None:
708 def field_list_with_scope(self, scope):
709 """Return a list of field names in scope."""
710 if not scope in _scopes:
711 raise ValueError("Invalid scope provided")
713 for field in self._field_list_with_scope(scope):
714 field_names.append(field.name)
720 Get the TraceHandle associated with this event
723 ret = _bt_ctf_event_get_handle_id(self._e)
727 th = TraceHandle.__new__(TraceHandle)
729 th._trace_collection = self.get_trace_collection()
733 def trace_collection(self):
735 Get the TraceCollection associated with this event.
736 Return None on error.
738 trace_collection = TraceCollection()
739 trace_collection._tc = _bt_ctf_event_get_context(self._e)
740 if trace_collection._tc is None:
743 return trace_collection
745 def __getitem__(self, field_name):
747 Get field_name's value. If the field_name exists in multiple
748 scopes, the first field found is returned. The scopes are searched
749 in the following order:
752 3) STREAM_EVENT_CONTEXT
753 4) STREAM_EVENT_HEADER
754 5) STREAM_PACKET_CONTEXT
755 6) TRACE_PACKET_HEADER
756 None is returned if no field matches field_name.
758 Use field_with_scope() to explicitly access fields in a given
761 field = self._field(field_name)
762 if field is not None:
764 raise KeyError(field_name)
767 for key in self.keys():
772 for scope in _scopes:
773 scope_ptr = _bt_ctf_get_top_level_scope(self._e, scope)
774 ret = _bt_python_field_listcaller(self._e, scope_ptr)
775 if isinstance(ret, list):
779 def __contains__(self, field_name):
780 return self._field(field_name) is not None
783 """Return a list of field names."""
785 for scope in _scopes:
786 for name in self.field_list_with_scope(scope):
787 field_names.add(name)
788 return list(field_names)
790 def get(self, field_name, default=None):
791 field = self._field(field_name)
797 for field in self.keys():
798 yield (field, self[field])
800 def _field_with_scope(self, field_name, scope):
801 scope_ptr = _bt_ctf_get_top_level_scope(self._e, scope)
802 if scope_ptr is None:
805 definition_ptr = _bt_ctf_get_field(self._e, scope_ptr, field_name)
806 if definition_ptr is None:
809 field = _Definition(definition_ptr, scope)
812 def _field(self, field_name):
814 for scope in _scopes:
815 field = self._field_with_scope(field_name, scope)
816 if field is not None:
820 def _field_list_with_scope(self, scope):
822 scope_ptr = _bt_ctf_get_top_level_scope(self._e, scope)
824 # Returns a list [list_ptr, count]. If list_ptr is NULL, SWIG will only
825 # provide the "count" return value
828 ret = _bt_python_field_listcaller(self._e, scope_ptr)
829 if isinstance(ret, list):
830 list_ptr, count = ret
832 for i in range(count):
833 definition_ptr = _bt_python_field_one_from_list(list_ptr, i)
834 if definition_ptr is not None:
835 definition = _Definition(definition_ptr, scope)
836 fields.append(definition)
840 class FieldError(Exception):
842 def __init__(self, value):
846 return repr(self.value)
849 class EventDeclaration(object):
851 """Event declaration class. Do not instantiate."""
852 MAX_UINT64 = 0xFFFFFFFFFFFFFFFF
855 raise NotImplementedError("EventDeclaration cannot be instantiated")
859 """Return the name of the event or None on error"""
860 return _bt_ctf_get_decl_event_name(self._ed)
864 """Return the event-ID of the event or -1 on error"""
865 id = _bt_ctf_get_decl_event_id(self._ed)
866 if id == self.MAX_UINT64:
873 Generator returning all FieldDeclarations of an event, going through
874 each scope in the following order:
877 3) STREAM_EVENT_CONTEXT
878 4) STREAM_EVENT_HEADER
879 5) STREAM_PACKET_CONTEXT
880 6) TRACE_PACKET_HEADER
882 for scope in _scopes:
883 for declaration in self.fields_scope(scope):
886 def fields_scope(self, scope):
888 Generator returning FieldDeclarations of the current event in scope.
890 ret = _by_python_field_decl_listcaller(self._ed, scope)
892 if not isinstance(ret, list):
895 list_ptr, count = ret
896 for i in range(count):
897 field_declaration_ptr = _bt_python_field_decl_one_from_list(
900 if field_declaration_ptr is not None:
901 declaration_ptr = _bt_ctf_get_decl_from_field_decl(
902 field_declaration_ptr)
903 field_declaration = _create_field_declaration(
905 _bt_ctf_get_decl_field_name(field_declaration_ptr),
907 yield field_declaration
910 class FieldDeclaration(object):
912 """Field declaration class. Do not instantiate."""
915 raise NotImplementedError("FieldDeclaration cannot be instantiated")
918 return "({0}) {1} {2}".format(
919 CTFScope.scope_name(self.scope), CTFTypeId.type_name(self.type), self.name)
923 """Return the name of a FieldDeclaration or None on error."""
929 Return the FieldDeclaration's type. One of the entries in class
932 return _bt_ctf_field_type(self._fd)
937 Return the FieldDeclaration's scope.
942 class IntegerFieldDeclaration(FieldDeclaration):
944 """Do not instantiate."""
947 raise NotImplementedError(
948 "IntegerFieldDeclaration cannot be instantiated")
951 def signedness(self):
953 Return the signedness of an integer:
954 0 if unsigned; 1 if signed; -1 on error.
956 return _bt_ctf_get_int_signedness(self._fd)
960 """Return the base of an int or a negative value on error."""
961 return _bt_ctf_get_int_base(self._fd)
964 def byte_order(self):
966 Return the byte order. One of class ByteOrder's entries.
968 ret = _bt_ctf_get_int_byte_order(self._fd)
970 return ByteOrder.BYTE_ORDER_LITTLE_ENDIAN
972 return ByteOrder.BYTE_ORDER_BIG_ENDIAN
974 return ByteOrder.BYTE_ORDER_UNKNOWN
979 Return the size, in bits, of an int or a negative
982 return _bt_ctf_get_int_len(self._fd)
987 Return the encoding. One of class CTFStringEncoding's entries.
988 Return a negative value on error.
990 return _bt_ctf_get_encoding(self._fd)
993 class EnumerationFieldDeclaration(FieldDeclaration):
995 """Do not instantiate."""
998 raise NotImplementedError(
999 "EnumerationFieldDeclaration cannot be instantiated")
1002 class ArrayFieldDeclaration(FieldDeclaration):
1004 """Do not instantiate."""
1007 raise NotImplementedError(
1008 "ArrayFieldDeclaration cannot be instantiated")
1013 Return the length of an array or a negative
1016 return _bt_ctf_get_array_len(self._fd)
1019 def element_declaration(self):
1021 Return element declaration.
1023 field_decl_ptr = _bt_python_get_array_element_declaration(self._fd)
1024 return _create_field_declaration(field_decl_ptr, "", self.scope)
1027 class SequenceFieldDeclaration(FieldDeclaration):
1029 """Do not instantiate."""
1032 raise NotImplementedError(
1033 "SequenceFieldDeclaration cannot be instantiated")
1036 def element_declaration(self):
1038 Return element declaration.
1040 field_decl_ptr = _bt_python_get_sequence_element_declaration(self._fd)
1041 return _create_field_declaration(field_decl_ptr, "", self.scope)
1044 class FloatFieldDeclaration(FieldDeclaration):
1046 """Do not instantiate."""
1049 raise NotImplementedError(
1050 "FloatFieldDeclaration cannot be instantiated")
1053 class StructureFieldDeclaration(FieldDeclaration):
1055 """Do not instantiate."""
1058 raise NotImplementedError(
1059 "StructureFieldDeclaration cannot be instantiated")
1062 class StringFieldDeclaration(FieldDeclaration):
1064 """Do not instantiate."""
1067 raise NotImplementedError(
1068 "StringFieldDeclaration cannot be instantiated")
1071 class VariantFieldDeclaration(FieldDeclaration):
1073 """Do not instantiate."""
1076 raise NotImplementedError(
1077 "VariantFieldDeclaration cannot be instantiated")
1082 Return the last error code encountered while
1083 accessing a field and reset the error flag.
1084 Return 0 if no error, a negative value otherwise.
1086 return _bt_ctf_field_get_error()
1089 def _create_field_declaration(declaration_ptr, name, scope):
1091 Private field declaration factory.
1093 if declaration_ptr is None:
1094 raise ValueError("declaration_ptr must be valid")
1095 if not scope in _scopes:
1096 raise ValueError("Invalid scope provided")
1098 type = _bt_ctf_field_type(declaration_ptr)
1100 if type == CTFTypeId.INTEGER:
1101 declaration = IntegerFieldDeclaration.__new__(IntegerFieldDeclaration)
1102 elif type == CTFTypeId.ENUM:
1103 declaration = EnumerationFieldDeclaration.__new__(
1104 EnumerationFieldDeclaration)
1105 elif type == CTFTypeId.ARRAY:
1106 declaration = ArrayFieldDeclaration.__new__(ArrayFieldDeclaration)
1107 elif type == CTFTypeId.SEQUENCE:
1108 declaration = SequenceFieldDeclaration.__new__(
1109 SequenceFieldDeclaration)
1110 elif type == CTFTypeId.FLOAT:
1111 declaration = FloatFieldDeclaration.__new__(FloatFieldDeclaration)
1112 elif type == CTFTypeId.STRUCT:
1113 declaration = StructureFieldDeclaration.__new__(
1114 StructureFieldDeclaration)
1115 elif type == CTFTypeId.STRING:
1116 declaration = StringFieldDeclaration.__new__(StringFieldDeclaration)
1117 elif type == CTFTypeId.VARIANT:
1118 declaration = VariantFieldDeclaration.__new__(VariantFieldDeclaration)
1122 declaration._fd = declaration_ptr
1123 declaration._s = scope
1124 declaration._name = name
1128 class _Definition(object):
1130 def __init__(self, definition_ptr, scope):
1131 self._d = definition_ptr
1133 if not scope in _scopes:
1134 ValueError("Invalid scope provided")
1138 """Return the name of a field or None on error."""
1139 return _bt_ctf_field_name(self._d)
1143 """Return the type of a field or -1 if unknown."""
1144 return _bt_ctf_field_type(_bt_ctf_get_decl_from_def(self._d))
1147 def declaration(self):
1148 """Return the associated Definition object."""
1149 return _create_field_declaration(
1150 _bt_ctf_get_decl_from_def(self._d), self.name, self.scope)
1152 def _get_enum_str(self):
1154 Return the string matching the current enumeration.
1155 Return None on error.
1157 return _bt_ctf_get_enum_str(self._d)
1159 def _get_array_element_at(self, index):
1161 Return the array's element at position index.
1162 Return None on error
1164 array_ptr = _bt_python_get_array_from_def(self._d)
1165 if array_ptr is None:
1168 definition_ptr = _bt_array_index(array_ptr, index)
1169 if definition_ptr is None:
1171 return _Definition(definition_ptr, self.scope)
1173 def _get_sequence_len(self):
1175 Return the len of a sequence or a negative
1178 seq = _bt_python_get_sequence_from_def(self._d)
1179 return _bt_sequence_len(seq)
1181 def _get_sequence_element_at(self, index):
1183 Return the sequence's element at position index,
1184 otherwise return None
1186 seq = _bt_python_get_sequence_from_def(self._d)
1188 definition_ptr = _bt_sequence_index(seq, index)
1189 if definition_ptr is not None:
1190 return _Definition(definition_ptr, self.scope)
1193 def _get_uint64(self):
1195 Return the value associated with the field.
1196 If the field does not exist or is not of the type requested,
1197 the value returned is undefined. To check if an error occured,
1198 use the field_error() function after accessing a field.
1200 return _bt_ctf_get_uint64(self._d)
1202 def _get_int64(self):
1204 Return the value associated with the field.
1205 If the field does not exist or is not of the type requested,
1206 the value returned is undefined. To check if an error occured,
1207 use the field_error() function after accessing a field.
1209 return _bt_ctf_get_int64(self._d)
1211 def _get_char_array(self):
1213 Return the value associated with the field.
1214 If the field does not exist or is not of the type requested,
1215 the value returned is undefined. To check if an error occurred,
1216 use the field_error() function after accessing a field.
1218 return _bt_ctf_get_char_array(self._d)
1222 Return the value associated with the field.
1223 If the field does not exist or is not of the type requested,
1224 the value returned is undefined. To check if an error occurred,
1225 use the field_error() function after accessing a field.
1227 return _bt_ctf_get_string(self._d)
1229 def _get_float(self):
1231 Return the value associated with the field.
1232 If the field does not exist or is not of the type requested,
1233 the value returned is undefined. To check if an error occurred,
1234 use the field_error() function after accessing a field.
1236 return _bt_ctf_get_float(self._d)
1238 def _get_variant(self):
1240 Return the variant's selected field.
1241 If the field does not exist or is not of the type requested,
1242 the value returned is undefined. To check if an error occurred,
1243 use the field_error() function after accessing a field.
1245 return _bt_ctf_get_variant(self._d)
1247 def _get_struct_field_count(self):
1249 Return the number of fields contained in the structure.
1250 If the field does not exist or is not of the type requested,
1251 the value returned is undefined.
1253 return _bt_ctf_get_struct_field_count(self._d)
1255 def _get_struct_field_at(self, i):
1257 Return the structure's field at position i.
1258 If the field does not exist or is not of the type requested,
1259 the value returned is undefined. To check if an error occurred,
1260 use the field_error() function after accessing a field.
1262 return _bt_ctf_get_struct_field_index(self._d, i)
1267 Return the value associated with the field according to its type.
1268 Return None on error.
1273 if id == CTFTypeId.STRING:
1274 value = self._get_str()
1275 elif id == CTFTypeId.ARRAY:
1276 element_decl = self.declaration.element_declaration
1277 if ((element_decl.type == CTFTypeId.INTEGER
1278 and element_decl.length == 8)
1279 and (element_decl.encoding == CTFStringEncoding.ASCII or element_decl.encoding == CTFStringEncoding.UTF8)):
1280 value = _bt_python_get_array_string(self._d)
1283 for i in range(self.declaration.length):
1284 element = self._get_array_element_at(i)
1285 value.append(element.value)
1286 elif id == CTFTypeId.INTEGER:
1287 if self.declaration.signedness == 0:
1288 value = self._get_uint64()
1290 value = self._get_int64()
1291 elif id == CTFTypeId.ENUM:
1292 value = self._get_enum_str()
1293 elif id == CTFTypeId.SEQUENCE:
1294 element_decl = self.declaration.element_declaration
1295 if ((element_decl.type == CTFTypeId.INTEGER
1296 and element_decl.length == 8)
1297 and (element_decl.encoding == CTFStringEncoding.ASCII or element_decl.encoding == CTFStringEncoding.UTF8)):
1298 value = _bt_python_get_sequence_string(self._d)
1300 seq_len = self._get_sequence_len()
1302 for i in range(seq_len):
1303 evDef = self._get_sequence_element_at(i)
1304 value.append(evDef.value)
1305 elif id == CTFTypeId.FLOAT:
1306 value = self._get_float()
1307 elif id == CTFTypeId.VARIANT:
1308 variant = _Definition.__new__(_Definition)
1309 variant._d = self._get_variant()
1310 value = variant.value
1311 elif id == CTFTypeId.STRUCT:
1313 for i in range(self._get_struct_field_count()):
1314 member = _Definition(self._get_struct_field_at(i), self.scope)
1315 value[member.name] = member.value
1319 "Error occurred while accessing field {} of type {}".format(
1321 CTFTypeId.type_name(id)))
1326 """Return the scope of a field or None on error."""
1334 %rename("_bt_ctf_clock_create") bt_ctf_clock_create(const char *name);
1335 %rename("_bt_ctf_clock_get_name") bt_ctf_clock_get_name(struct bt_ctf_clock *clock);
1336 %rename("_bt_ctf_clock_get_description") bt_ctf_clock_get_description(struct bt_ctf_clock *clock);
1337 %rename("_bt_ctf_clock_set_description") bt_ctf_clock_set_description(struct bt_ctf_clock *clock, const char *desc);
1338 %rename("_bt_ctf_clock_get_frequency") bt_ctf_clock_get_frequency(struct bt_ctf_clock *clock);
1339 %rename("_bt_ctf_clock_set_frequency") bt_ctf_clock_set_frequency(struct bt_ctf_clock *clock, uint64_t freq);
1340 %rename("_bt_ctf_clock_get_precision") bt_ctf_clock_get_precision(struct bt_ctf_clock *clock);
1341 %rename("_bt_ctf_clock_set_precision") bt_ctf_clock_set_precision(struct bt_ctf_clock *clock, uint64_t precision);
1342 %rename("_bt_ctf_clock_get_offset_s") bt_ctf_clock_get_offset_s(struct bt_ctf_clock *clock);
1343 %rename("_bt_ctf_clock_set_offset_s") bt_ctf_clock_set_offset_s(struct bt_ctf_clock *clock, uint64_t offset_s);
1344 %rename("_bt_ctf_clock_get_offset") bt_ctf_clock_get_offset(struct bt_ctf_clock *clock);
1345 %rename("_bt_ctf_clock_set_offset") bt_ctf_clock_set_offset(struct bt_ctf_clock *clock, uint64_t offset);
1346 %rename("_bt_ctf_clock_get_is_absolute") bt_ctf_clock_get_is_absolute(struct bt_ctf_clock *clock);
1347 %rename("_bt_ctf_clock_set_is_absolute") bt_ctf_clock_set_is_absolute(struct bt_ctf_clock *clock, int is_absolute);
1348 %rename("_bt_ctf_clock_get_time") bt_ctf_clock_get_time(struct bt_ctf_clock *clock);
1349 %rename("_bt_ctf_clock_set_time") bt_ctf_clock_set_time(struct bt_ctf_clock *clock, uint64_t time);
1350 %rename("_bt_ctf_clock_get") bt_ctf_clock_get(struct bt_ctf_clock *clock);
1351 %rename("_bt_ctf_clock_put") bt_ctf_clock_put(struct bt_ctf_clock *clock);
1353 struct bt_ctf_clock *bt_ctf_clock_create(const char *name);
1354 const char *bt_ctf_clock_get_name(struct bt_ctf_clock *clock);
1355 const char *bt_ctf_clock_get_description(struct bt_ctf_clock *clock);
1356 int bt_ctf_clock_set_description(struct bt_ctf_clock *clock, const char *desc);
1357 uint64_t bt_ctf_clock_get_frequency(struct bt_ctf_clock *clock);
1358 int bt_ctf_clock_set_frequency(struct bt_ctf_clock *clock, uint64_t freq);
1359 uint64_t bt_ctf_clock_get_precision(struct bt_ctf_clock *clock);
1360 int bt_ctf_clock_set_precision(struct bt_ctf_clock *clock, uint64_t precision);
1361 uint64_t bt_ctf_clock_get_offset_s(struct bt_ctf_clock *clock);
1362 int bt_ctf_clock_set_offset_s(struct bt_ctf_clock *clock, uint64_t offset_s);
1363 uint64_t bt_ctf_clock_get_offset(struct bt_ctf_clock *clock);
1364 int bt_ctf_clock_set_offset(struct bt_ctf_clock *clock, uint64_t offset);
1365 int bt_ctf_clock_get_is_absolute(struct bt_ctf_clock *clock);
1366 int bt_ctf_clock_set_is_absolute(struct bt_ctf_clock *clock, int is_absolute);
1367 uint64_t bt_ctf_clock_get_time(struct bt_ctf_clock *clock);
1368 int bt_ctf_clock_set_time(struct bt_ctf_clock *clock, uint64_t time);
1369 void bt_ctf_clock_get(struct bt_ctf_clock *clock);
1370 void bt_ctf_clock_put(struct bt_ctf_clock *clock);
1373 %rename("_bt_ctf_field_type_integer_create") bt_ctf_field_type_integer_create(unsigned int size);
1374 %rename("_bt_ctf_field_type_integer_get_size") bt_ctf_field_type_integer_get_size(struct bt_ctf_field_type *integer);
1375 %rename("_bt_ctf_field_type_integer_get_signed") bt_ctf_field_type_integer_get_signed(struct bt_ctf_field_type *integer);
1376 %rename("_bt_ctf_field_type_integer_set_signed") bt_ctf_field_type_integer_set_signed(struct bt_ctf_field_type *integer, int is_signed);
1377 %rename("_bt_ctf_field_type_integer_get_base") bt_ctf_field_type_integer_get_base(struct bt_ctf_field_type *integer);
1378 %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);
1379 %rename("_bt_ctf_field_type_integer_get_encoding") bt_ctf_field_type_integer_get_encoding(struct bt_ctf_field_type *integer);
1380 %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);
1381 %rename("_bt_ctf_field_type_enumeration_create") bt_ctf_field_type_enumeration_create(struct bt_ctf_field_type *integer_container_type);
1382 %rename("_bt_ctf_field_type_enumeration_get_container_type") bt_ctf_field_type_enumeration_get_container_type(struct bt_ctf_field_type *enumeration);
1383 %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);
1384 %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);
1385 %rename("_bt_ctf_field_type_enumeration_get_mapping_count") bt_ctf_field_type_enumeration_get_mapping_count(struct bt_ctf_field_type *enumeration);
1386 %rename("_bt_ctf_field_type_enumeration_get_mapping") bt_ctf_field_type_enumeration_get_mapping(struct bt_ctf_field_type *enumeration, int index, const char **name, int64_t *range_start, int64_t *range_end);
1387 %rename("_bt_ctf_field_type_enumeration_get_mapping_unsigned") bt_ctf_field_type_enumeration_get_mapping_unsigned(struct bt_ctf_field_type *enumeration, int index, const char **name, uint64_t *range_start, uint64_t *range_end);
1388 %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);
1389 %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);
1390 %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);
1391 %rename("_bt_ctf_field_type_floating_point_create") bt_ctf_field_type_floating_point_create(void);
1392 %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);
1393 %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);
1394 %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);
1395 %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);
1396 %rename("_bt_ctf_field_type_structure_create") bt_ctf_field_type_structure_create(void);
1397 %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);
1398 %rename("_bt_ctf_field_type_structure_get_field_count") bt_ctf_field_type_structure_get_field_count(struct bt_ctf_field_type *structure);
1399 %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, int index);
1400 %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);
1401 %rename("_bt_ctf_field_type_variant_create") bt_ctf_field_type_variant_create(struct bt_ctf_field_type *enum_tag, const char *tag_name);
1402 %rename("_bt_ctf_field_type_variant_get_tag_type") bt_ctf_field_type_variant_get_tag_type(struct bt_ctf_field_type *variant);
1403 %rename("_bt_ctf_field_type_variant_get_tag_name") bt_ctf_field_type_variant_get_tag_name(struct bt_ctf_field_type *variant);
1404 %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);
1405 %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);
1406 %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);
1407 %rename("_bt_ctf_field_type_variant_get_field_count") bt_ctf_field_type_variant_get_field_count(struct bt_ctf_field_type *variant);
1408 %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, int index);
1409 %rename("_bt_ctf_field_type_array_create") bt_ctf_field_type_array_create(struct bt_ctf_field_type *element_type, unsigned int length);
1410 %rename("_bt_ctf_field_type_array_get_element_type") bt_ctf_field_type_array_get_element_type(struct bt_ctf_field_type *array);
1411 %rename("_bt_ctf_field_type_array_get_length") bt_ctf_field_type_array_get_length(struct bt_ctf_field_type *array);
1412 %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);
1413 %rename("_bt_ctf_field_type_sequence_get_element_type") bt_ctf_field_type_sequence_get_element_type(struct bt_ctf_field_type *sequence);
1414 %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);
1415 %rename("_bt_ctf_field_type_string_create") bt_ctf_field_type_string_create(void);
1416 %rename("_bt_ctf_field_type_string_get_encoding") bt_ctf_field_type_string_get_encoding(struct bt_ctf_field_type *string_type);
1417 %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);
1418 %rename("_bt_ctf_field_type_get_alignment") bt_ctf_field_type_get_alignment(struct bt_ctf_field_type *type);
1419 %rename("_bt_ctf_field_type_set_alignment") bt_ctf_field_type_set_alignment(struct bt_ctf_field_type *type, unsigned int alignment);
1420 %rename("_bt_ctf_field_type_get_byte_order") bt_ctf_field_type_get_byte_order(struct bt_ctf_field_type *type);
1421 %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);
1422 %rename("_bt_ctf_field_type_get_type_id") bt_ctf_field_type_get_type_id(struct bt_ctf_field_type *type);
1423 %rename("_bt_ctf_field_type_get") bt_ctf_field_type_get(struct bt_ctf_field_type *type);
1424 %rename("_bt_ctf_field_type_put") bt_ctf_field_type_put(struct bt_ctf_field_type *type);
1426 struct bt_ctf_field_type *bt_ctf_field_type_integer_create(unsigned int size);
1427 int bt_ctf_field_type_integer_get_size(struct bt_ctf_field_type *integer);
1428 int bt_ctf_field_type_integer_get_signed(struct bt_ctf_field_type *integer);
1429 int bt_ctf_field_type_integer_set_signed(struct bt_ctf_field_type *integer, int is_signed);
1430 enum bt_ctf_integer_base bt_ctf_field_type_integer_get_base(struct bt_ctf_field_type *integer);
1431 int bt_ctf_field_type_integer_set_base(struct bt_ctf_field_type *integer, enum bt_ctf_integer_base base);
1432 enum ctf_string_encoding bt_ctf_field_type_integer_get_encoding(struct bt_ctf_field_type *integer);
1433 int bt_ctf_field_type_integer_set_encoding(struct bt_ctf_field_type *integer, enum ctf_string_encoding encoding);
1434 struct bt_ctf_field_type *bt_ctf_field_type_enumeration_create(struct bt_ctf_field_type *integer_container_type);
1435 struct bt_ctf_field_type *bt_ctf_field_type_enumeration_get_container_type(struct bt_ctf_field_type *enumeration);
1436 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);
1437 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);
1438 int bt_ctf_field_type_enumeration_get_mapping_count(struct bt_ctf_field_type *enumeration);
1439 int bt_ctf_field_type_enumeration_get_mapping(struct bt_ctf_field_type *enumeration, int index, const char **OUTPUT, int64_t *OUTPUT, int64_t *OUTPUT);
1440 int bt_ctf_field_type_enumeration_get_mapping_unsigned(struct bt_ctf_field_type *enumeration, int index, const char **OUTPUT, uint64_t *OUTPUT, uint64_t *OUTPUT);
1441 int bt_ctf_field_type_enumeration_get_mapping_index_by_name(struct bt_ctf_field_type *enumeration, const char *name);
1442 int bt_ctf_field_type_enumeration_get_mapping_index_by_value(struct bt_ctf_field_type *enumeration, int64_t value);
1443 int bt_ctf_field_type_enumeration_get_mapping_index_by_unsigned_value(struct bt_ctf_field_type *enumeration, uint64_t value);
1444 struct bt_ctf_field_type *bt_ctf_field_type_floating_point_create(void);
1445 int bt_ctf_field_type_floating_point_get_exponent_digits(struct bt_ctf_field_type *floating_point);
1446 int bt_ctf_field_type_floating_point_set_exponent_digits(struct bt_ctf_field_type *floating_point, unsigned int exponent_digits);
1447 int bt_ctf_field_type_floating_point_get_mantissa_digits(struct bt_ctf_field_type *floating_point);
1448 int bt_ctf_field_type_floating_point_set_mantissa_digits(struct bt_ctf_field_type *floating_point, unsigned int mantissa_digits);
1449 struct bt_ctf_field_type *bt_ctf_field_type_structure_create(void);
1450 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);
1451 int bt_ctf_field_type_structure_get_field_count(struct bt_ctf_field_type *structure);
1452 int bt_ctf_field_type_structure_get_field(struct bt_ctf_field_type *structure, const char **OUTPUT, struct bt_ctf_field_type **OUTPUT, int index);
1453 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);
1454 struct bt_ctf_field_type *bt_ctf_field_type_variant_create(struct bt_ctf_field_type *enum_tag, const char *tag_name);
1455 struct bt_ctf_field_type *bt_ctf_field_type_variant_get_tag_type(struct bt_ctf_field_type *variant);
1456 const char *bt_ctf_field_type_variant_get_tag_name(struct bt_ctf_field_type *variant);
1457 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);
1458 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);
1459 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);
1460 int bt_ctf_field_type_variant_get_field_count(struct bt_ctf_field_type *variant);
1461 int bt_ctf_field_type_variant_get_field(struct bt_ctf_field_type *variant, const char **OUTPUT, struct bt_ctf_field_type **OUTPUT, int index);
1462 struct bt_ctf_field_type *bt_ctf_field_type_array_create(struct bt_ctf_field_type *element_type, unsigned int length);
1463 struct bt_ctf_field_type *bt_ctf_field_type_array_get_element_type(struct bt_ctf_field_type *array);
1464 int64_t bt_ctf_field_type_array_get_length(struct bt_ctf_field_type *array);
1465 struct bt_ctf_field_type *bt_ctf_field_type_sequence_create(struct bt_ctf_field_type *element_type, const char *length_field_name);
1466 struct bt_ctf_field_type *bt_ctf_field_type_sequence_get_element_type(struct bt_ctf_field_type *sequence);
1467 const char *bt_ctf_field_type_sequence_get_length_field_name(struct bt_ctf_field_type *sequence);
1468 struct bt_ctf_field_type *bt_ctf_field_type_string_create(void);
1469 enum ctf_string_encoding bt_ctf_field_type_string_get_encoding(struct bt_ctf_field_type *string_type);
1470 int bt_ctf_field_type_string_set_encoding(struct bt_ctf_field_type *string_type, enum ctf_string_encoding encoding);
1471 int bt_ctf_field_type_get_alignment(struct bt_ctf_field_type *type);
1472 int bt_ctf_field_type_set_alignment(struct bt_ctf_field_type *type, unsigned int alignment);
1473 enum bt_ctf_byte_order bt_ctf_field_type_get_byte_order(struct bt_ctf_field_type *type);
1474 int bt_ctf_field_type_set_byte_order(struct bt_ctf_field_type *type, enum bt_ctf_byte_order byte_order);
1475 enum ctf_type_id bt_ctf_field_type_get_type_id(struct bt_ctf_field_type *type);
1476 void bt_ctf_field_type_get(struct bt_ctf_field_type *type);
1477 void bt_ctf_field_type_put(struct bt_ctf_field_type *type);
1479 /* event-fields.h */
1480 %rename("_bt_ctf_field_create") bt_ctf_field_create(struct bt_ctf_field_type *type);
1481 %rename("_bt_ctf_field_structure_get_field") bt_ctf_field_structure_get_field(struct bt_ctf_field *structure, const char *name);
1482 %rename("_bt_ctf_field_array_get_field") bt_ctf_field_array_get_field(struct bt_ctf_field *array, uint64_t index);
1483 %rename("_bt_ctf_field_sequence_get_length") bt_ctf_field_sequence_get_length(struct bt_ctf_field *sequence);
1484 %rename("_bt_ctf_field_sequence_set_length") bt_ctf_field_sequence_set_length(struct bt_ctf_field *sequence, struct bt_ctf_field *length_field);
1485 %rename("_bt_ctf_field_sequence_get_field") bt_ctf_field_sequence_get_field(struct bt_ctf_field *sequence, uint64_t index);
1486 %rename("_bt_ctf_field_variant_get_field") bt_ctf_field_variant_get_field(struct bt_ctf_field *variant, struct bt_ctf_field *tag);
1487 %rename("_bt_ctf_field_enumeration_get_container") bt_ctf_field_enumeration_get_container(struct bt_ctf_field *enumeration);
1488 %rename("_bt_ctf_field_enumeration_get_mapping_name") bt_ctf_field_enumeration_get_mapping_name(struct bt_ctf_field *enumeration);
1489 %rename("_bt_ctf_field_signed_integer_get_value") bt_ctf_field_signed_integer_get_value(struct bt_ctf_field *integer, int64_t *value);
1490 %rename("_bt_ctf_field_signed_integer_set_value") bt_ctf_field_signed_integer_set_value(struct bt_ctf_field *integer, int64_t value);
1491 %rename("_bt_ctf_field_unsigned_integer_get_value") bt_ctf_field_unsigned_integer_get_value(struct bt_ctf_field *integer, uint64_t *value);
1492 %rename("_bt_ctf_field_unsigned_integer_set_value") bt_ctf_field_unsigned_integer_set_value(struct bt_ctf_field *integer, uint64_t value);
1493 %rename("_bt_ctf_field_floating_point_get_value") bt_ctf_field_floating_point_get_value(struct bt_ctf_field *floating_point, double *value);
1494 %rename("_bt_ctf_field_floating_point_set_value") bt_ctf_field_floating_point_set_value(struct bt_ctf_field *floating_point, double value);
1495 %rename("_bt_ctf_field_string_get_value") bt_ctf_field_string_get_value(struct bt_ctf_field *string_field);
1496 %rename("_bt_ctf_field_string_set_value") bt_ctf_field_string_set_value(struct bt_ctf_field *string_field, const char *value);
1497 %rename("_bt_ctf_field_get_type") bt_ctf_field_get_type(struct bt_ctf_field *field);
1498 %rename("_bt_ctf_field_get") bt_ctf_field_get(struct bt_ctf_field *field);
1499 %rename("_bt_ctf_field_put") bt_ctf_field_put(struct bt_ctf_field *field);
1501 struct bt_ctf_field *bt_ctf_field_create(struct bt_ctf_field_type *type);
1502 struct bt_ctf_field *bt_ctf_field_structure_get_field(struct bt_ctf_field *structure, const char *name);
1503 struct bt_ctf_field *bt_ctf_field_array_get_field(struct bt_ctf_field *array, uint64_t index);
1504 struct bt_ctf_field * bt_ctf_field_sequence_get_length(struct bt_ctf_field *sequence);
1505 int bt_ctf_field_sequence_set_length(struct bt_ctf_field *sequence, struct bt_ctf_field *length_field);
1506 struct bt_ctf_field *bt_ctf_field_sequence_get_field(struct bt_ctf_field *sequence, uint64_t index);
1507 struct bt_ctf_field *bt_ctf_field_variant_get_field(struct bt_ctf_field *variant, struct bt_ctf_field *tag);
1508 struct bt_ctf_field *bt_ctf_field_enumeration_get_container(struct bt_ctf_field *enumeration);
1509 const char *bt_ctf_field_enumeration_get_mapping_name(struct bt_ctf_field *enumeration);
1510 int bt_ctf_field_signed_integer_get_value(struct bt_ctf_field *integer, int64_t *OUTPUT);
1511 int bt_ctf_field_signed_integer_set_value(struct bt_ctf_field *integer, int64_t value);
1512 int bt_ctf_field_unsigned_integer_get_value(struct bt_ctf_field *integer, uint64_t *OUTPUT);
1513 int bt_ctf_field_unsigned_integer_set_value(struct bt_ctf_field *integer, uint64_t value);
1514 int bt_ctf_field_floating_point_get_value(struct bt_ctf_field *floating_point, double *OUTPUT);
1515 int bt_ctf_field_floating_point_set_value(struct bt_ctf_field *floating_point, double value);
1516 const char *bt_ctf_field_string_get_value(struct bt_ctf_field *string_field);
1517 int bt_ctf_field_string_set_value(struct bt_ctf_field *string_field, const char *value);
1518 struct bt_ctf_field_type *bt_ctf_field_get_type(struct bt_ctf_field *field);
1519 void bt_ctf_field_get(struct bt_ctf_field *field);
1520 void bt_ctf_field_put(struct bt_ctf_field *field);
1523 %rename("_bt_ctf_event_class_create") bt_ctf_event_class_create(const char *name);
1524 %rename("_bt_ctf_event_class_get_name") bt_ctf_event_class_get_name(struct bt_ctf_event_class *event_class);
1525 %rename("_bt_ctf_event_class_get_id") bt_ctf_event_class_get_id(struct bt_ctf_event_class *event_class);
1526 %rename("_bt_ctf_event_class_set_id") bt_ctf_event_class_set_id(struct bt_ctf_event_class *event_class, uint32_t id);
1527 %rename("_bt_ctf_event_class_get_stream_class") bt_ctf_event_class_get_stream_class(struct bt_ctf_event_class *event_class);
1528 %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);
1529 %rename("_bt_ctf_event_class_get_field_count") bt_ctf_event_class_get_field_count(struct bt_ctf_event_class *event_class);
1530 %rename("_bt_ctf_event_class_get_field") bt_ctf_event_class_get_field(struct bt_ctf_event_class *event_class, const char **field_name, struct bt_ctf_field_type **field_type, int index);
1531 %rename("_bt_ctf_event_class_get_field_by_name") bt_ctf_event_class_get_field_by_name(struct bt_ctf_event_class *event_class, const char *name);
1532 %rename("_bt_ctf_event_class_get") bt_ctf_event_class_get(struct bt_ctf_event_class *event_class);
1533 %rename("_bt_ctf_event_class_put") bt_ctf_event_class_put(struct bt_ctf_event_class *event_class);
1535 struct bt_ctf_event_class *bt_ctf_event_class_create(const char *name);
1536 const char *bt_ctf_event_class_get_name(struct bt_ctf_event_class *event_class);
1537 int64_t bt_ctf_event_class_get_id(struct bt_ctf_event_class *event_class);
1538 int bt_ctf_event_class_set_id(struct bt_ctf_event_class *event_class, uint32_t id);
1539 struct bt_ctf_stream_class *bt_ctf_event_class_get_stream_class(struct bt_ctf_event_class *event_class);
1540 int bt_ctf_event_class_add_field(struct bt_ctf_event_class *event_class, struct bt_ctf_field_type *type, const char *name);
1541 int bt_ctf_event_class_get_field_count(struct bt_ctf_event_class *event_class);
1542 int bt_ctf_event_class_get_field(struct bt_ctf_event_class *event_class, const char **field_name, struct bt_ctf_field_type **field_type, int index);
1543 struct bt_ctf_field_type *bt_ctf_event_class_get_field_by_name(struct bt_ctf_event_class *event_class, const char *name);
1544 void bt_ctf_event_class_get(struct bt_ctf_event_class *event_class);
1545 void bt_ctf_event_class_put(struct bt_ctf_event_class *event_class);
1548 %rename("_bt_ctf_event_create") bt_ctf_event_create(struct bt_ctf_event_class *event_class);
1549 %rename("_bt_ctf_event_get_class") bt_ctf_event_get_class(struct bt_ctf_event *event);
1550 %rename("_bt_ctf_event_get_clock") bt_ctf_event_get_clock(struct bt_ctf_event *event);
1551 %rename("_bt_ctf_event_get_payload") bt_ctf_event_get_payload(struct bt_ctf_event *event, const char *name);
1552 %rename("_bt_ctf_event_set_payload") bt_ctf_event_set_payload(struct bt_ctf_event *event, const char *name, struct bt_ctf_field *value);
1553 %rename("_bt_ctf_event_get_payload_by_index") bt_ctf_event_get_payload_by_index(struct bt_ctf_event *event, int index);
1554 %rename("_bt_ctf_event_get") bt_ctf_event_get(struct bt_ctf_event *event);
1555 %rename("_bt_ctf_event_put") bt_ctf_event_put(struct bt_ctf_event *event);
1557 struct bt_ctf_event *bt_ctf_event_create(struct bt_ctf_event_class *event_class);
1558 struct bt_ctf_event_class *bt_ctf_event_get_class(struct bt_ctf_event *event);
1559 struct bt_ctf_clock *bt_ctf_event_get_clock(struct bt_ctf_event *event);
1560 struct bt_ctf_field *bt_ctf_event_get_payload(struct bt_ctf_event *event, const char *name);
1561 int bt_ctf_event_set_payload(struct bt_ctf_event *event, const char *name, struct bt_ctf_field *value);
1562 struct bt_ctf_field *bt_ctf_event_get_payload_by_index(struct bt_ctf_event *event, int index);
1563 void bt_ctf_event_get(struct bt_ctf_event *event);
1564 void bt_ctf_event_put(struct bt_ctf_event *event);
1566 /* stream-class.h */
1567 %rename("_bt_ctf_stream_class_create") bt_ctf_stream_class_create(const char *name);
1568 %rename("_bt_ctf_stream_class_get_name") bt_ctf_stream_class_get_name(struct bt_ctf_stream_class *stream_class);
1569 %rename("_bt_ctf_stream_class_get_clock") bt_ctf_stream_class_get_clock(struct bt_ctf_stream_class *stream_class);
1570 %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);
1571 %rename("_bt_ctf_stream_class_get_id") bt_ctf_stream_class_get_id(struct bt_ctf_stream_class *stream_class);
1572 %rename("_bt_ctf_stream_class_set_id") bt_ctf_stream_class_set_id(struct bt_ctf_stream_class *stream_class, uint32_t id);
1573 %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);
1574 %rename("_bt_ctf_stream_class_get_event_class_count") bt_ctf_stream_class_get_event_class_count(struct bt_ctf_stream_class *stream_class);
1575 %rename("_bt_ctf_stream_class_get_event_class") bt_ctf_stream_class_get_event_class(struct bt_ctf_stream_class *stream_class, int index);
1576 %rename("_bt_ctf_stream_class_get_event_class_by_name") bt_ctf_stream_class_get_event_class_by_name(struct bt_ctf_stream_class *stream_class, const char *name);
1577 %rename("_bt_ctf_stream_class_get_packet_context_type") bt_ctf_stream_class_get_packet_context_type(struct bt_ctf_stream_class *stream_class);
1578 %rename("_bt_ctf_stream_class_set_packet_context_type") bt_ctf_stream_class_set_packet_context_type(struct bt_ctf_stream_class *stream_class, struct bt_ctf_field_type *packet_context_type);
1579 %rename("_bt_ctf_stream_class_get") bt_ctf_stream_class_get(struct bt_ctf_stream_class *stream_class);
1580 %rename("_bt_ctf_stream_class_put") bt_ctf_stream_class_put(struct bt_ctf_stream_class *stream_class);
1582 struct bt_ctf_stream_class *bt_ctf_stream_class_create(const char *name);
1583 const char *bt_ctf_stream_class_get_name(struct bt_ctf_stream_class *stream_class);
1584 struct bt_ctf_clock *bt_ctf_stream_class_get_clock(struct bt_ctf_stream_class *stream_class);
1585 int bt_ctf_stream_class_set_clock(struct bt_ctf_stream_class *stream_class, struct bt_ctf_clock *clock);
1586 int64_t bt_ctf_stream_class_get_id(struct bt_ctf_stream_class *stream_class);
1587 int bt_ctf_stream_class_set_id(struct bt_ctf_stream_class *stream_class, uint32_t id);
1588 int bt_ctf_stream_class_add_event_class(struct bt_ctf_stream_class *stream_class, struct bt_ctf_event_class *event_class);
1589 int bt_ctf_stream_class_get_event_class_count(struct bt_ctf_stream_class *stream_class);
1590 struct bt_ctf_event_class *bt_ctf_stream_class_get_event_class(struct bt_ctf_stream_class *stream_class, int index);
1591 struct bt_ctf_event_class *bt_ctf_stream_class_get_event_class_by_name(struct bt_ctf_stream_class *stream_class, const char *name);
1592 struct bt_ctf_field_type *bt_ctf_stream_class_get_packet_context_type(struct bt_ctf_stream_class *stream_class);
1593 int bt_ctf_stream_class_set_packet_context_type(struct bt_ctf_stream_class *stream_class, struct bt_ctf_field_type *packet_context_type);
1594 void bt_ctf_stream_class_get(struct bt_ctf_stream_class *stream_class);
1595 void bt_ctf_stream_class_put(struct bt_ctf_stream_class *stream_class);
1598 %rename("_bt_ctf_stream_get_discarded_events_count") bt_ctf_stream_get_discarded_events_count(struct bt_ctf_stream *stream, uint64_t *count);
1599 %rename("_bt_ctf_stream_append_discarded_events") bt_ctf_stream_append_discarded_events(struct bt_ctf_stream *stream, uint64_t event_count);
1600 %rename("_bt_ctf_stream_append_event") bt_ctf_stream_append_event(struct bt_ctf_stream *stream, struct bt_ctf_event *event);
1601 %rename("_bt_ctf_stream_get_packet_context") bt_ctf_stream_get_packet_context(struct bt_ctf_stream *stream);
1602 %rename("_bt_ctf_stream_set_packet_context") bt_ctf_stream_set_packet_context(struct bt_ctf_stream *stream, struct bt_ctf_field *packet_context);
1603 %rename("_bt_ctf_stream_flush") bt_ctf_stream_flush(struct bt_ctf_stream *stream);
1604 %rename("_bt_ctf_stream_get") bt_ctf_stream_get(struct bt_ctf_stream *stream);
1605 %rename("_bt_ctf_stream_put") bt_ctf_stream_put(struct bt_ctf_stream *stream);
1607 int bt_ctf_stream_get_discarded_events_count(struct bt_ctf_stream *stream, uint64_t *OUTPUT);
1608 void bt_ctf_stream_append_discarded_events(struct bt_ctf_stream *stream, uint64_t event_count);
1609 int bt_ctf_stream_append_event(struct bt_ctf_stream *stream, struct bt_ctf_event *event);
1610 struct bt_ctf_field *bt_ctf_stream_get_packet_context(struct bt_ctf_stream *stream);
1611 int bt_ctf_stream_set_packet_context(struct bt_ctf_stream *stream, struct bt_ctf_field *packet_context);
1612 int bt_ctf_stream_flush(struct bt_ctf_stream *stream);
1613 void bt_ctf_stream_get(struct bt_ctf_stream *stream);
1614 void bt_ctf_stream_put(struct bt_ctf_stream *stream);
1617 %rename("_bt_ctf_writer_create") bt_ctf_writer_create(const char *path);
1618 %rename("_bt_ctf_writer_create_stream") bt_ctf_writer_create_stream(struct bt_ctf_writer *writer, struct bt_ctf_stream_class *stream_class);
1619 %rename("_bt_ctf_writer_add_environment_field") bt_ctf_writer_add_environment_field(struct bt_ctf_writer *writer, const char *name, const char *value);
1620 %rename("_bt_ctf_writer_add_clock") bt_ctf_writer_add_clock(struct bt_ctf_writer *writer, struct bt_ctf_clock *clock);
1621 %newobject bt_ctf_writer_get_metadata_string;
1622 %rename("_bt_ctf_writer_get_metadata_string") bt_ctf_writer_get_metadata_string(struct bt_ctf_writer *writer);
1623 %rename("_bt_ctf_writer_flush_metadata") bt_ctf_writer_flush_metadata(struct bt_ctf_writer *writer);
1624 %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);
1625 %rename("_bt_ctf_writer_get") bt_ctf_writer_get(struct bt_ctf_writer *writer);
1626 %rename("_bt_ctf_writer_put") bt_ctf_writer_put(struct bt_ctf_writer *writer);
1628 struct bt_ctf_writer *bt_ctf_writer_create(const char *path);
1629 struct bt_ctf_stream *bt_ctf_writer_create_stream(struct bt_ctf_writer *writer, struct bt_ctf_stream_class *stream_class);
1630 int bt_ctf_writer_add_environment_field(struct bt_ctf_writer *writer, const char *name, const char *value);
1631 int bt_ctf_writer_add_clock(struct bt_ctf_writer *writer, struct bt_ctf_clock *clock);
1632 char *bt_ctf_writer_get_metadata_string(struct bt_ctf_writer *writer);
1633 void bt_ctf_writer_flush_metadata(struct bt_ctf_writer *writer);
1634 int bt_ctf_writer_set_byte_order(struct bt_ctf_writer *writer, enum bt_ctf_byte_order byte_order);
1635 void bt_ctf_writer_get(struct bt_ctf_writer *writer);
1636 void bt_ctf_writer_put(struct bt_ctf_writer *writer);
1640 from uuid import UUID
1644 # Used to compare to -1ULL in error checks
1645 _MAX_UINT64 = 0xFFFFFFFFFFFFFFFF
1648 Enumeration mapping class. start and end values are inclusive.
1650 class EnumerationMapping:
1652 def __init__(self, name, start, end):
1659 def __init__(self, name):
1660 self._c = _bt_ctf_clock_create(name)
1662 raise ValueError("Invalid clock name.")
1665 _bt_ctf_clock_put(self._c)
1668 Get the clock's name.
1672 name = _bt_ctf_clock_get_name(self._c)
1674 raise ValueError("Invalid clock instance.")
1678 Get the clock's description. None if unset.
1681 def description(self):
1682 return _bt_ctf_clock_get_description(self._c)
1685 Set the clock's description. The description appears in the clock's TSDL
1689 def description(self, desc):
1690 ret = _bt_ctf_clock_set_description(self._c, str(desc))
1692 raise ValueError("Invalid clock description.")
1695 Get the clock's frequency (Hz).
1698 def frequency(self):
1699 freq = _bt_ctf_clock_get_frequency(self._c)
1700 if freq == CTFWriter._MAX_UINT64:
1701 raise ValueError("Invalid clock instance")
1705 Set the clock's frequency (Hz).
1708 def frequency(self, freq):
1709 ret = _bt_ctf_clock_set_frequency(self._c, freq)
1711 raise ValueError("Invalid frequency value.")
1714 Get the clock's precision (in clock ticks).
1717 def precision(self):
1718 precision = _bt_ctf_clock_get_precision(self._c)
1719 if precision == CTFWriter._MAX_UINT64:
1720 raise ValueError("Invalid clock instance")
1724 Set the clock's precision (in clock ticks).
1727 def precision(self, precision):
1728 ret = _bt_ctf_clock_set_precision(self._c, precision)
1731 Get the clock's offset in seconds from POSIX.1 Epoch.
1734 def offset_seconds(self):
1735 offset_s = _bt_ctf_clock_get_offset_s(self._c)
1736 if offset_s == CTFWriter._MAX_UINT64:
1737 raise ValueError("Invalid clock instance")
1741 Set the clock's offset in seconds from POSIX.1 Epoch.
1743 @offset_seconds.setter
1744 def offset_seconds(self, offset_s):
1745 ret = _bt_ctf_clock_set_offset_s(self._c, offset_s)
1747 raise ValueError("Invalid offset value.")
1750 Get the clock's offset in ticks from POSIX.1 Epoch + offset in seconds.
1754 offset = _bt_ctf_clock_get_offset(self._c)
1755 if offset == CTFWriter._MAX_UINT64:
1756 raise ValueError("Invalid clock instance")
1760 Set the clock's offset in ticks from POSIX.1 Epoch + offset in seconds.
1763 def offset(self, offset):
1764 ret = _bt_ctf_clock_set_offset(self._c, offset)
1766 raise ValueError("Invalid offset value.")
1769 Get a clock's absolute attribute. A clock is absolute if the clock
1770 is a global reference across the trace's other clocks.
1774 is_absolute = _bt_ctf_clock_get_is_absolute(self._c)
1775 if is_absolute == -1:
1776 raise ValueError("Invalid clock instance")
1777 return False if is_absolute == 0 else True
1780 Set a clock's absolute attribute. A clock is absolute if the clock
1781 is a global reference across the trace's other clocks.
1784 def absolute(self, is_absolute):
1785 ret = _bt_ctf_clock_set_is_absolute(self._c, int(is_absolute))
1788 "Could not set the clock's absolute attribute.")
1791 Get a clock's UUID (an object of type UUID).
1797 ret, value = _bt_python_ctf_clock_get_uuid_index(self._c, i)
1799 raise ValueError("Invalid clock instance")
1800 uuid_list.append(value)
1801 return UUID(bytes=bytes(uuid_list))
1804 Set a clock's UUID (an object of type UUID).
1807 def uuid(self, uuid):
1808 uuid_bytes = uuid.bytes
1809 if len(uuid_bytes) != 16:
1811 "Invalid UUID provided. UUID length must be 16 bytes")
1812 for i in range(len(uuid_bytes)):
1813 ret = _bt_python_ctf_clock_set_uuid_index(
1818 raise ValueError("Invalid clock instance")
1821 Get the current time in nanoseconds since the clock's origin (offset and
1822 offset_s attributes).
1826 time = _bt_ctf_clock_get_time(self._c)
1827 if time == CTFWriter._MAX_UINT64:
1828 raise ValueError("Invalid clock instance")
1832 Set the current time in nanoseconds since the clock's origin (offset and
1833 offset_s attributes). The clock's value will be sampled as events are
1834 appended to a stream.
1837 def time(self, time):
1838 ret = _bt_ctf_clock_set_time(self._c, time)
1840 raise ValueError("Invalid time value.")
1842 class FieldDeclaration:
1845 FieldDeclaration should not be instantiated directly. Instantiate
1846 one of the concrete FieldDeclaration classes.
1849 # These values are based on the bt_ctf_integer_base enum
1850 # declared in event-types.h.
1851 INTEGER_BASE_UNKNOWN = -1
1852 INTEGER_BASE_BINARY = 2
1853 INTEGER_BASE_OCTAL = 8
1854 INTEGER_BASE_DECIMAL = 10
1855 INTEGER_BASE_HEXADECIMAL = 16
1858 if self._ft is None:
1859 raise ValueError("FieldDeclaration creation failed.")
1862 _bt_ctf_field_type_put(self._ft)
1865 def _create_field_declaration_from_native_instance(
1866 native_field_declaration):
1868 CTFTypeId.INTEGER: CTFWriter.IntegerFieldDeclaration,
1869 CTFTypeId.FLOAT: CTFWriter.FloatFieldDeclaration,
1870 CTFTypeId.ENUM: CTFWriter.EnumerationFieldDeclaration,
1871 CTFTypeId.STRING: CTFWriter.StringFieldDeclaration,
1872 CTFTypeId.STRUCT: CTFWriter.StructureFieldDeclaration,
1873 CTFTypeId.VARIANT: CTFWriter.VariantFieldDeclaration,
1874 CTFTypeId.ARRAY: CTFWriter.ArrayFieldDeclaration,
1875 CTFTypeId.SEQUENCE: CTFWriter.SequenceFieldDeclaration
1878 field_type_id = _bt_ctf_field_type_get_type_id(
1879 native_field_declaration)
1880 if field_type_id == CTFTypeId.UNKNOWN:
1881 raise TypeError("Invalid field instance")
1883 declaration = CTFWriter.Field.__new__(CTFWriter.Field)
1884 declaration._ft = native_field_declaration
1885 declaration.__class__ = type_dict[field_type_id]
1889 Get the field declaration's alignment. Returns -1 on error.
1892 def alignment(self):
1893 return _bt_ctf_field_type_get_alignment(self._ft)
1896 Set the field declaration's alignment. Defaults to 1 (bit-aligned). However,
1897 some types, such as structures and string, may impose other alignment
1901 def alignment(self, alignment):
1902 ret = _bt_ctf_field_type_set_alignment(self._ft, alignment)
1904 raise ValueError("Invalid alignment value.")
1907 Get the field declaration's byte order. One of the ByteOrder's constant.
1910 def byte_order(self):
1911 return _bt_ctf_field_type_get_byte_order(self._ft)
1914 Set the field declaration's byte order. Use constants defined in the ByteOrder
1918 def byte_order(self, byte_order):
1919 ret = _bt_ctf_field_type_set_byte_order(self._ft, byte_order)
1921 raise ValueError("Could not set byte order value.")
1923 class IntegerFieldDeclaration(FieldDeclaration):
1926 Create a new integer field declaration of the given size.
1929 def __init__(self, size):
1930 self._ft = _bt_ctf_field_type_integer_create(size)
1934 Get an integer's size.
1938 ret = _bt_ctf_field_type_integer_get_size(self._ft)
1940 raise ValueError("Could not get Integer's size attribute.")
1945 Get an integer's signedness attribute.
1949 ret = _bt_ctf_field_type_integer_get_signed(self._ft)
1951 raise ValueError("Could not get Integer's signed attribute.")
1958 Set an integer's signedness attribute.
1961 def signed(self, signed):
1962 ret = _bt_ctf_field_type_integer_set_signed(self._ft, signed)
1964 raise ValueError("Could not set Integer's signed attribute.")
1967 Get the integer's base used to pretty-print the resulting trace.
1968 Returns a constant from the FieldDeclaration.IntegerBase class.
1972 return _bt_ctf_field_type_integer_get_base(self._ft)
1975 Set the integer's base used to pretty-print the resulting trace.
1976 The base must be a constant of the FieldDeclarationIntegerBase class.
1979 def base(self, base):
1980 ret = _bt_ctf_field_type_integer_set_base(self._ft, base)
1982 raise ValueError("Could not set Integer's base.")
1985 Get the integer's encoding (one of the constants of the
1986 CTFStringEncoding class).
1987 Returns a constant from the CTFStringEncoding class.
1991 return _bt_ctf_field_type_integer_get_encoding(self._ft)
1994 An integer encoding may be set to signal that the integer must be printed
1995 as a text character. Must be a constant from the CTFStringEncoding class.
1998 def encoding(self, encoding):
1999 ret = _bt_ctf_field_type_integer_set_encoding(self._ft, encoding)
2001 raise ValueError("Could not set Integer's encoding.")
2003 class EnumerationFieldDeclaration(FieldDeclaration):
2006 Create a new enumeration field declaration with the given underlying container type.
2009 def __init__(self, integer_type):
2010 if integer_type is None or not isinstance(
2011 integer_type, CTFWriter.IntegerFieldDeclaration):
2012 raise TypeError("Invalid integer container.")
2014 self._ft = _bt_ctf_field_type_enumeration_create(integer_type._ft)
2018 Get the enumeration's underlying container type.
2021 def container(self):
2022 ret = _bt_ctf_field_type_enumeration_get_container_type(self._ft)
2024 raise TypeError("Invalid enumeration declaration")
2025 return CTFWriter.FieldDeclaration._create_field_declaration_from_native_instance(
2029 Add a mapping to the enumeration. The range's values are inclusive.
2032 def add_mapping(self, name, range_start, range_end):
2033 if range_start < 0 or range_end < 0:
2034 ret = _bt_ctf_field_type_enumeration_add_mapping(
2040 ret = _bt_ctf_field_type_enumeration_add_mapping_unsigned(
2048 "Could not add mapping to enumeration declaration.")
2051 Generator returning instances of EnumerationMapping.
2055 signed = self.container.signed
2057 count = _bt_ctf_field_type_enumeration_get_mapping_count(self._ft)
2058 for i in range(count):
2060 ret = _bt_python_ctf_field_type_enumeration_get_mapping(
2064 ret = _bt_python_ctf_field_type_enumeration_get_mapping_unsigned(
2070 "Could not get Enumeration mapping at index {}".format(i))
2071 name, range_start, range_end = ret
2072 yield CTFWriter.EnumerationMapping(name, range_start, range_end)
2075 Get a mapping by name (EnumerationMapping).
2078 def get_mapping_by_name(self, name):
2079 index = _bt_ctf_field_type_enumeration_get_mapping_index_by_name(
2084 if self.container.signed:
2085 ret = _bt_python_ctf_field_type_enumeration_get_mapping(
2089 ret = _bt_python_ctf_field_type_enumeration_get_mapping_unsigned(
2095 "Could not get Enumeration mapping at index {}".format(i))
2096 name, range_start, range_end = ret
2097 return CTFWriter.EnumerationMapping(name, range_start, range_end)
2100 Get a mapping by value (EnumerationMapping).
2103 def get_mapping_by_value(self, value):
2105 index = _bt_ctf_field_type_enumeration_get_mapping_index_by_value(
2108 index = _bt_ctf_field_type_enumeration_get_mapping_index_by_unsigned_value(
2114 if self.container.signed:
2115 ret = _bt_python_ctf_field_type_enumeration_get_mapping(
2119 ret = _bt_python_ctf_field_type_enumeration_get_mapping_unsigned(
2125 "Could not get Enumeration mapping at index {}".format(i))
2126 name, range_start, range_end = ret
2127 return CTFWriter.EnumerationMapping(name, range_start, range_end)
2129 class FloatFieldDeclaration(FieldDeclaration):
2136 Create a new floating point field declaration.
2140 self._ft = _bt_ctf_field_type_floating_point_create()
2144 Get the number of exponent digits used to store the floating point field.
2147 def exponent_digits(self):
2148 ret = _bt_ctf_field_type_floating_point_get_exponent_digits(
2152 "Could not get Floating point exponent digit count")
2156 Set the number of exponent digits to use to store the floating point field.
2157 The only values currently supported are FLT_EXP_DIG and DBL_EXP_DIG which
2158 are defined as constants of this class.
2160 @exponent_digits.setter
2161 def exponent_digits(self, exponent_digits):
2162 ret = _bt_ctf_field_type_floating_point_set_exponent_digits(
2166 raise ValueError("Could not set exponent digit count.")
2169 Get the number of mantissa digits used to store the floating point field.
2172 def mantissa_digits(self):
2173 ret = _bt_ctf_field_type_floating_point_get_mantissa_digits(
2177 "Could not get Floating point mantissa digit count")
2181 Set the number of mantissa digits to use to store the floating point field.
2182 The only values currently supported are FLT_MANT_DIG and DBL_MANT_DIG which
2183 are defined as constants of this class.
2185 @mantissa_digits.setter
2186 def mantissa_digits(self, mantissa_digits):
2187 ret = _bt_ctf_field_type_floating_point_set_mantissa_digits(
2191 raise ValueError("Could not set mantissa digit count.")
2193 class StructureFieldDeclaration(FieldDeclaration):
2196 Create a new structure field declaration.
2200 self._ft = _bt_ctf_field_type_structure_create()
2204 Add a field of type "field_type" to the structure.
2207 def add_field(self, field_type, field_name):
2208 ret = _bt_ctf_field_type_structure_add_field(
2213 raise ValueError("Could not add field to structure.")
2216 Generator returning the structure's field as tuples of (field name, field declaration).
2220 count = _bt_ctf_field_type_structure_get_field_count(self._ft)
2222 raise TypeError("Could not get Structure field count")
2224 for i in range(count):
2225 field_name = _bt_python_ctf_field_type_structure_get_field_name(
2228 if field_name is None:
2230 "Could not get Structure field name at index {}".format(i))
2232 field_type_native = _bt_python_ctf_field_type_structure_get_field_type(
2235 if field_type_native is None:
2237 "Could not get Structure field type at index {}".format(i))
2239 field_type = CTFWriter.FieldDeclaration._create_field_declaration_from_native_instance(
2241 yield (field_name, field_type)
2244 Get a field declaration by name (FieldDeclaration).
2247 def get_field_by_name(self, name):
2248 field_type_native = _bt_ctf_field_type_structure_get_field_type_by_name(
2251 if field_type_native is None:
2253 "Could not find Structure field with name {}".format(name))
2255 return CTFWriter.FieldDeclaration._create_field_declaration_from_native_instance(
2258 class VariantFieldDeclaration(FieldDeclaration):
2261 Create a new variant field declaration.
2264 def __init__(self, enum_tag, tag_name):
2265 if enum_tag is None or not isinstance(
2266 enum_tag, CTFWriter.EnumerationFieldDeclaration):
2268 "Invalid tag type; must be of type EnumerationFieldDeclaration.")
2270 self._ft = _bt_ctf_field_type_variant_create(
2276 Get the variant's tag name.
2280 ret = _bt_ctf_field_type_variant_get_tag_name(self._ft)
2282 raise TypeError("Could not get Variant tag name")
2286 Get the variant's tag type.
2290 ret = _bt_ctf_field_type_variant_get_tag_type(self._ft)
2292 raise TypeError("Could not get Variant tag type")
2293 return CTFWriter.FieldDeclaration._create_field_declaration_from_native_instance(
2297 Add a field of type "field_type" to the variant.
2300 def add_field(self, field_type, field_name):
2301 ret = _bt_ctf_field_type_variant_add_field(
2306 raise ValueError("Could not add field to variant.")
2309 Generator returning the variant's field as tuples of (field name, field declaration).
2313 count = _bt_ctf_field_type_variant_get_field_count(self._ft)
2315 raise TypeError("Could not get Variant field count")
2317 for i in range(count):
2318 field_name = _bt_python_ctf_field_type_variant_get_field_name(
2321 if field_name is None:
2323 "Could not get Variant field name at index {}".format(i))
2325 field_type_native = _bt_python_ctf_field_type_variant_get_field_type(
2328 if field_type_native is None:
2330 "Could not get Variant field type at index {}".format(i))
2332 field_type = CTFWriter.FieldDeclaration._create_field_declaration_from_native_instance(
2334 yield (field_name, field_type)
2337 Get a field declaration by name (FieldDeclaration).
2340 def get_field_by_name(self, name):
2341 field_type_native = _bt_ctf_field_type_variant_get_field_type_by_name(
2344 if field_type_native is None:
2346 "Could not find Variant field with name {}".format(name))
2348 return CTFWriter.FieldDeclaration._create_field_declaration_from_native_instance(
2352 Get a field declaration from tag (EnumerationField).
2355 def get_field_from_tag(self, tag):
2356 field_type_native = _bt_ctf_field_type_variant_get_field_type_from_tag(
2359 if field_type_native is None:
2361 "Could not find Variant field with tag value {}".format(
2364 return CTFWriter.FieldDeclaration._create_field_declaration_from_native_instance(
2367 class ArrayFieldDeclaration(FieldDeclaration):
2370 Create a new array field declaration.
2373 def __init__(self, element_type, length):
2374 self._ft = _bt_ctf_field_type_array_create(
2380 Get the array's element type.
2383 def element_type(self):
2384 ret = _bt_ctf_field_type_array_get_element_type(self._ft)
2386 raise TypeError("Could not get Array element type")
2387 return CTFWriter.FieldDeclaration._create_field_declaration_from_native_instance(
2391 Get the array's length.
2395 ret = _bt_ctf_field_type_array_get_length(self._ft)
2397 raise TypeError("Could not get Array length")
2400 class SequenceFieldDeclaration(FieldDeclaration):
2403 Create a new sequence field declaration.
2406 def __init__(self, element_type, length_field_name):
2407 self._ft = _bt_ctf_field_type_sequence_create(
2409 str(length_field_name))
2413 Get the sequence's element type.
2416 def element_type(self):
2417 ret = _bt_ctf_field_type_sequence_get_element_type(self._ft)
2419 raise TypeError("Could not get Sequence element type")
2420 return CTFWriter.FieldDeclaration._create_field_declaration_from_native_instance(
2424 Get the sequence's length field name.
2427 def length_field_name(self):
2428 ret = _bt_ctf_field_type_sequence_get_length_field_name(self._ft)
2430 raise TypeError("Could not get Sequence length field name")
2433 class StringFieldDeclaration(FieldDeclaration):
2436 Create a new string field declaration.
2440 self._ft = _bt_ctf_field_type_string_create()
2444 Get a string declaration's encoding (a constant from the CTFStringEncoding class).
2448 return _bt_ctf_field_type_string_get_encoding(self._ft)
2451 Set a string declaration's encoding. Must be a constant from the CTFStringEncoding class.
2454 def encoding(self, encoding):
2455 ret = _bt_ctf_field_type_string_set_encoding(self._ft, encoding)
2457 raise ValueError("Could not set string encoding.")
2460 Create an instance of a field.
2463 def create_field(field_type):
2464 if field_type is None or not isinstance(
2465 field_type, CTFWriter.FieldDeclaration):
2467 "Invalid field_type. Type must be a FieldDeclaration-derived class.")
2469 if isinstance(field_type, CTFWriter.IntegerFieldDeclaration):
2470 return CTFWriter.IntegerField(field_type)
2471 elif isinstance(field_type, CTFWriter.EnumerationFieldDeclaration):
2472 return CTFWriter.EnumerationField(field_type)
2473 elif isinstance(field_type, CTFWriter.FloatFieldDeclaration):
2474 return CTFWriter.FloatFieldingPoint(field_type)
2475 elif isinstance(field_type, CTFWriter.StructureFieldDeclaration):
2476 return CTFWriter.StructureField(field_type)
2477 elif isinstance(field_type, CTFWriter.VariantFieldDeclaration):
2478 return CTFWriter.VariantField(field_type)
2479 elif isinstance(field_type, CTFWriter.ArrayFieldDeclaration):
2480 return CTFWriter.ArrayField(field_type)
2481 elif isinstance(field_type, CTFWriter.SequenceFieldDeclaration):
2482 return CTFWriter.SequenceField(field_type)
2483 elif isinstance(field_type, CTFWriter.StringFieldDeclaration):
2484 return CTFWriter.StringField(field_type)
2489 Base class, do not instantiate.
2492 def __init__(self, field_type):
2493 if not isinstance(field_type, CTFWriter.FieldDeclaration):
2494 raise TypeError("Invalid field_type argument.")
2496 self._f = _bt_ctf_field_create(field_type._ft)
2498 raise ValueError("Field creation failed.")
2501 _bt_ctf_field_put(self._f)
2504 def _create_field_from_native_instance(native_field_instance):
2506 CTFTypeId.INTEGER: CTFWriter.IntegerField,
2507 CTFTypeId.FLOAT: CTFWriter.FloatFieldingPoint,
2508 CTFTypeId.ENUM: CTFWriter.EnumerationField,
2509 CTFTypeId.STRING: CTFWriter.StringField,
2510 CTFTypeId.STRUCT: CTFWriter.StructureField,
2511 CTFTypeId.VARIANT: CTFWriter.VariantField,
2512 CTFTypeId.ARRAY: CTFWriter.ArrayField,
2513 CTFTypeId.SEQUENCE: CTFWriter.SequenceField
2516 field_type = _bt_python_get_field_type(native_field_instance)
2517 if field_type == CTFTypeId.UNKNOWN:
2518 raise TypeError("Invalid field instance")
2520 field = CTFWriter.Field.__new__(CTFWriter.Field)
2521 field._f = native_field_instance
2522 field.__class__ = type_dict[field_type]
2526 def declaration(self):
2527 native_field_type = _bt_ctf_field_get_type(self._f)
2528 if native_field_type is None:
2529 raise TypeError("Invalid field instance")
2530 return CTFWriter.FieldDeclaration._create_field_declaration_from_native_instance(
2533 class IntegerField(Field):
2536 Get an integer field's value.
2540 signedness = _bt_python_field_integer_get_signedness(self._f)
2542 raise TypeError("Invalid integer instance.")
2545 ret, value = _bt_ctf_field_unsigned_integer_get_value(self._f)
2547 ret, value = _bt_ctf_field_signed_integer_get_value(self._f)
2550 raise ValueError("Could not get integer field value.")
2554 Set an integer field's value.
2557 def value(self, value):
2558 if not isinstance(value, int):
2559 raise TypeError("IntegerField's value must be an int")
2561 signedness = _bt_python_field_integer_get_signedness(self._f)
2563 raise TypeError("Invalid integer instance.")
2566 ret = _bt_ctf_field_unsigned_integer_set_value(self._f, value)
2568 ret = _bt_ctf_field_signed_integer_set_value(self._f, value)
2571 raise ValueError("Could not set integer field value.")
2573 class EnumerationField(Field):
2576 Return the enumeration's underlying container field (an integer field).
2579 def container(self):
2580 container = CTFWriter.IntegerField.__new__(CTFWriter.IntegerField)
2581 container._f = _bt_ctf_field_enumeration_get_container(self._f)
2582 if container._f is None:
2583 raise TypeError("Invalid enumeration field type.")
2587 Get the enumeration field's mapping name.
2591 value = _bt_ctf_field_enumeration_get_mapping_name(self._f)
2593 raise ValueError("Could not get enumeration's mapping name.")
2597 Set the enumeration field's value. Must be an integer as mapping names
2601 def value(self, value):
2602 if not isinstance(value, int):
2603 raise TypeError("EnumerationField value must be an int")
2604 self.container.value = value
2606 class FloatFieldingPoint(Field):
2609 Get a floating point field's value.
2613 ret, value = _bt_ctf_field_floating_point_get_value(self._f)
2615 raise ValueError("Could not get floating point field value.")
2619 Set a floating point field's value.
2622 def value(self, value):
2623 if not isinstance(value, int) and not isinstance(value, float):
2624 raise TypeError("Value must be either a float or an int")
2626 ret = _bt_ctf_field_floating_point_set_value(self._f, float(value))
2628 raise ValueError("Could not set floating point field value.")
2630 class StructureField(Field):
2633 Get the structure's field corresponding to the provided field name.
2636 def field(self, field_name):
2637 native_instance = _bt_ctf_field_structure_get_field(
2640 if native_instance is None:
2641 raise ValueError("Invalid field_name provided.")
2642 return CTFWriter.Field._create_field_from_native_instance(
2645 class VariantField(Field):
2648 Return the variant's selected field. The "tag" field is the selector enum field.
2651 def field(self, tag):
2652 native_instance = _bt_ctf_field_variant_get_field(self._f, tag._f)
2653 if native_instance is None:
2654 raise ValueError("Invalid tag provided.")
2655 return CTFWriter.Field._create_field_from_native_instance(
2658 class ArrayField(Field):
2661 Return the array's field at position "index".
2664 def field(self, index):
2665 native_instance = _bt_ctf_field_array_get_field(self._f, index)
2666 if native_instance is None:
2667 raise IndexError("Invalid index provided.")
2668 return CTFWriter.Field._create_field_from_native_instance(
2671 class SequenceField(Field):
2674 Get the sequence's length field (IntegerField).
2678 native_instance = _bt_ctf_field_sequence_get_length(self._f)
2679 if native_instance is None:
2681 return CTFWriter.Field._create_field_from_native_instance(
2685 Set the sequence's length field (IntegerField).
2688 def length(self, length_field):
2689 if not isinstance(length_field, CTFWriter.IntegerField):
2690 raise TypeError("Invalid length field.")
2691 if length_field.declaration.signed:
2692 raise TypeError("Sequence field length must be unsigned")
2693 ret = _bt_ctf_field_sequence_set_length(self._f, length_field._f)
2695 raise ValueError("Could not set sequence length.")
2698 Return the sequence's field at position "index".
2701 def field(self, index):
2702 native_instance = _bt_ctf_field_sequence_get_field(self._f, index)
2703 if native_instance is None:
2704 raise ValueError("Could not get sequence element at index.")
2705 return CTFWriter.Field._create_field_from_native_instance(
2708 class StringField(Field):
2711 Get a string field's value.
2715 return _bt_ctf_field_string_get_value(self._f)
2718 Set a string field's value.
2721 def value(self, value):
2722 ret = _bt_ctf_field_string_set_value(self._f, str(value))
2724 raise ValueError("Could not set string field value.")
2729 Create a new event class of the given name.
2732 def __init__(self, name):
2733 self._ec = _bt_ctf_event_class_create(name)
2734 if self._ec is None:
2735 raise ValueError("Event class creation failed.")
2738 _bt_ctf_event_class_put(self._ec)
2741 Add a field of type "field_type" to the event class.
2744 def add_field(self, field_type, field_name):
2745 ret = _bt_ctf_event_class_add_field(
2750 raise ValueError("Could not add field to event class.")
2753 Get the event class' name.
2757 name = _bt_ctf_event_class_get_name(self._ec)
2759 raise TypeError("Could not get EventClass name")
2763 Get the event class' id. Returns a negative value if unset.
2767 id = _bt_ctf_event_class_get_id(self._ec)
2769 raise TypeError("Could not get EventClass id")
2773 Set the event class' id. Throws a TypeError if the event class
2774 is already registered to a stream class.
2778 ret = _bt_ctf_event_class_set_id(self._ec, id)
2781 "Can't change an Event Class's id after it has been assigned to a stream class")
2784 Get the event class' stream class. Returns None if unset.
2787 def stream_class(self):
2788 stream_class_native = _bt_ctf_event_class_get_stream_class(
2790 if stream_class_native is None:
2792 stream_class = CTFWriter.StreamClass.__new__(CTFWriter.StreamClass)
2793 stream_class._sc = stream_class_native
2797 Generator returning the event class' fields as tuples of (field name, field declaration).
2801 count = _bt_ctf_event_class_get_field_count(self._ec)
2803 raise TypeError("Could not get EventClass' field count")
2805 for i in range(count):
2806 field_name = _bt_python_ctf_event_class_get_field_name(
2809 if field_name is None:
2811 "Could not get EventClass' field name at index {}".format(i))
2813 field_type_native = _bt_python_ctf_event_class_get_field_type(
2816 if field_type_native is None:
2818 "Could not get EventClass' field type at index {}".format(i))
2820 field_type = CTFWriter.FieldDeclaration._create_field_declaration_from_native_instance(
2822 yield (field_name, field_type)
2825 Get a field declaration by name (FieldDeclaration).
2828 def get_field_by_name(self, name):
2829 field_type_native = _bt_ctf_event_class_get_field_by_name(
2832 if field_type_native is None:
2834 "Could not find EventClass field with name {}".format(name))
2835 return CTFWriter.FieldDeclaration._create_field_declaration_from_native_instance(
2841 Create a new event of the given event class.
2844 def __init__(self, event_class):
2845 if not isinstance(event_class, CTFWriter.EventClass):
2846 raise TypeError("Invalid event_class argument.")
2848 self._e = _bt_ctf_event_create(event_class._ec)
2850 raise ValueError("Event creation failed.")
2853 _bt_ctf_event_put(self._e)
2856 Get the event's class.
2859 def event_class(self):
2860 event_class_native = _bt_ctf_event_get_class(self._e)
2861 if event_class_native is None:
2863 event_class = CTFWriter.EventClass.__new__(CTFWriter.EventClass)
2864 event_class._ec = event_class_native
2868 Get a clock from event. Returns None if the event's class
2869 is not registered to a stream class.
2873 clock_instance = _bt_ctf_event_get_clock(self._e)
2874 if clock_instance is None:
2876 clock = CTFWriter.Clock.__new__(CTFWriter.Clock)
2877 clock._c = clock_instance
2881 Get a field from event.
2884 def payload(self, field_name):
2885 native_instance = _bt_ctf_event_get_payload(
2888 if native_instance is None:
2889 raise ValueError("Could not get event payload.")
2890 return CTFWriter.Field._create_field_from_native_instance(
2894 Set a manually created field as an event's payload.
2897 def set_payload(self, field_name, value_field):
2898 if not isinstance(value, CTFWriter.Field):
2899 raise TypeError("Invalid value type.")
2900 ret = _bt_ctf_event_set_payload(
2905 raise ValueError("Could not set event field payload.")
2910 Create a new stream class of the given name.
2913 def __init__(self, name):
2914 self._sc = _bt_ctf_stream_class_create(name)
2915 if self._sc is None:
2916 raise ValueError("Stream class creation failed.")
2919 _bt_ctf_stream_class_put(self._sc)
2922 Get a stream class' name.
2926 name = _bt_ctf_stream_class_get_name(self._sc)
2928 raise TypeError("Could not get StreamClass name")
2932 Get a stream class' clock.
2936 clock_instance = _bt_ctf_stream_class_get_clock(self._sc)
2937 if clock_instance is None:
2939 clock = CTFWriter.Clock.__new__(CTFWriter.Clock)
2940 clock._c = clock_instance
2944 Assign a clock to a stream class.
2947 def clock(self, clock):
2948 if not isinstance(clock, CTFWriter.Clock):
2949 raise TypeError("Invalid clock type.")
2951 ret = _bt_ctf_stream_class_set_clock(self._sc, clock._c)
2953 raise ValueError("Could not set stream class clock.")
2956 Get a stream class' id.
2960 ret = _bt_ctf_stream_class_get_id(self._sc)
2962 raise TypeError("Could not get StreamClass id")
2966 Assign an id to a stream class.
2970 ret = _bt_ctf_stream_class_set_id(self._sc, id)
2972 raise TypeError("Could not set stream class id.")
2975 Generator returning the stream class' event classes.
2978 def event_classes(self):
2979 count = _bt_ctf_stream_class_get_event_class_count(self._sc)
2981 raise TypeError("Could not get StreamClass' event class count")
2983 for i in range(count):
2984 event_class_native = _bt_ctf_stream_class_get_event_class(
2987 if event_class_native is None:
2989 "Could not get StreamClass' event class at index {}".format(i))
2991 event_class = CTFWriter.EventClass.__new__(
2992 CTFWriter.EventClass)
2993 event_class._ec = event_class_native
2997 Add an event class to a stream class. New events can be added even after a
2998 stream has been instantiated and events have been appended. However, a stream
2999 will not accept events of a class that has not been added to the stream
3003 def add_event_class(self, event_class):
3004 if not isinstance(event_class, CTFWriter.EventClass):
3005 raise TypeError("Invalid event_class type.")
3007 ret = _bt_ctf_stream_class_add_event_class(
3011 raise ValueError("Could not add event class.")
3014 Get the StreamClass' packet context type (StructureFieldDeclaration)
3017 def packet_context_type(self):
3018 field_type_native = _bt_ctf_stream_class_get_packet_context_type(
3020 if field_type_native is None:
3021 raise ValueError("Invalid StreamClass")
3022 field_type = CTFWriter.FieldDeclaration._create_field_declaration_from_native_instance(
3027 Set a StreamClass' packet context type. Must be of type
3028 StructureFieldDeclaration.
3030 @packet_context_type.setter
3031 def packet_context_type(self, field_type):
3032 if not isinstance(field_type, CTFWriter.StructureFieldDeclaration):
3034 "field_type argument must be of type StructureFieldDeclaration.")
3035 ret = _bt_ctf_stream_class_set_packet_context_type(
3039 raise ValueError("Failed to set packet context type.")
3044 Create a stream of the given class.
3047 def __init__(self, stream_class):
3048 if not isinstance(stream_class, CTFWriter.StreamClass):
3050 "Invalid stream_class argument must be of type StreamClass.")
3052 self._s = _bt_ctf_stream_create(stream_class._sc)
3054 raise ValueError("Stream creation failed.")
3057 _bt_ctf_stream_put(self._s)
3060 Get a stream's discarded event count.
3063 def discarded_events(self):
3064 ret, count = _bt_ctf_stream_get_discarded_events_count(self._s)
3067 "Could not get the stream's discarded events count")
3071 Increase the current packet's discarded event count.
3074 def append_discarded_events(self, event_count):
3075 _bt_ctf_stream_append_discarded_events(self._s, event_count)
3078 Append "event" to the stream's current packet. The stream's associated clock
3079 will be sampled during this call. The event shall not be modified after
3080 being appended to a stream.
3083 def append_event(self, event):
3084 ret = _bt_ctf_stream_append_event(self._s, event._e)
3086 raise ValueError("Could not append event to stream.")
3089 Get a Stream's packet context field (a StructureField).
3092 def packet_context(self):
3093 native_field = _bt_ctf_stream_get_packet_context(self._s)
3094 if native_field is None:
3095 raise ValueError("Invalid Stream.")
3096 return CTFWriter.Field._create_field_from_native_instance(
3100 Set a Stream's packet context field (must be a StructureField).
3102 @packet_context.setter
3103 def packet_context(self, field):
3104 if not isinstance(field, CTFWriter.StructureField):
3106 "Argument field must be of type StructureField")
3107 ret = _bt_ctf_stream_set_packet_context(self._s, field._f)
3109 raise ValueError("Invalid packet context field.")
3112 The stream's current packet's events will be flushed to disk. Events
3113 subsequently appended to the stream will be added to a new packet.
3117 ret = _bt_ctf_stream_flush(self._s)
3119 raise ValueError("Could not flush stream.")
3124 Create a new writer that will produce a trace in the given path.
3127 def __init__(self, path):
3128 self._w = _bt_ctf_writer_create(path)
3130 raise ValueError("Writer creation failed.")
3133 _bt_ctf_writer_put(self._w)
3136 Create a new stream instance and register it to the writer.
3139 def create_stream(self, stream_class):
3140 if not isinstance(stream_class, CTFWriter.StreamClass):
3141 raise TypeError("Invalid stream_class type.")
3143 stream = CTFWriter.Stream.__new__(CTFWriter.Stream)
3144 stream._s = _bt_ctf_writer_create_stream(self._w, stream_class._sc)
3148 Add an environment field to the trace.
3151 def add_environment_field(self, name, value):
3152 ret = _bt_ctf_writer_add_environment_field(
3157 raise ValueError("Could not add environment field to trace.")
3160 Add a clock to the trace. Clocks assigned to stream classes must be
3161 registered to the writer.
3164 def add_clock(self, clock):
3165 ret = _bt_ctf_writer_add_clock(self._w, clock._c)
3167 raise ValueError("Could not add clock to Writer.")
3170 Get the trace's TSDL meta-data.
3174 return _bt_ctf_writer_get_metadata_string(self._w)
3177 Flush the trace's metadata to the metadata file.
3180 def flush_metadata(self):
3181 _bt_ctf_writer_flush_metadata(self._w)
3184 Get the trace's byte order. Must be a constant from the ByteOrder
3188 def byte_order(self):
3189 raise NotImplementedError("Getter not implemented.")
3192 Set the trace's byte order. Must be a constant from the ByteOrder
3193 class. Defaults to BYTE_ORDER_NATIVE, the host machine's endianness.
3196 def byte_order(self, byte_order):
3197 ret = _bt_ctf_writer_set_byte_order(self._w, byte_order)
3199 raise ValueError("Could not set trace's byte order.")