4 * Babeltrace Python Module interface file
6 * Copyright 2012 EfficiOS Inc.
8 * Author: Danny Serres <danny.serres@efficios.com>
9 * Author: Jérémie Galarneau <jeremie.galarneau@efficios.com>
11 * Permission is hereby granted, free of charge, to any person obtaining a copy
12 * of this software and associated documentation files (the "Software"), to deal
13 * in the Software without restriction, including without limitation the rights
14 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
15 * copies of the Software, and to permit persons to whom the Software is
16 * furnished to do so, subject to the following conditions:
18 * The above copyright notice and this permission notice shall be included in
19 * all copies or substantial portions of the Software.
24 "BABELTRACE_VERSION_STR
26 Babeltrace is a trace viewer and converter reading and writing the
27 Common Trace Format (CTF). Its main use is to pretty-print CTF
28 traces into a human-readable text output.
30 To use this module, the first step is to create a TraceCollection and add a
34 %module(docstring=DOCSTRING) babeltrace
38 #define SWIG_FILE_WITH_INIT
39 #include <babeltrace/babeltrace.h>
40 #include <babeltrace/babeltrace-internal.h>
41 #include <babeltrace/trace-handle.h>
42 #include <babeltrace/trace-handle-internal.h>
43 #include <babeltrace/context.h>
44 #include <babeltrace/context-internal.h>
45 #include <babeltrace/iterator.h>
46 #include <babeltrace/iterator-internal.h>
47 #include <babeltrace/format.h>
48 #include <babeltrace/list.h>
49 #include <babeltrace/types.h>
50 #include <babeltrace/ctf/iterator.h>
51 #include "python-complements.h"
52 #include <babeltrace/ctf-writer/clock.h>
53 #include <babeltrace/ctf-writer/event-fields.h>
54 #include <babeltrace/ctf-writer/event-types.h>
55 #include <babeltrace/ctf-writer/event.h>
56 #include <babeltrace/ctf-writer/stream.h>
57 #include <babeltrace/ctf-writer/writer.h>
60 typedef unsigned long long uint64_t;
61 typedef long long int64_t;
62 typedef int bt_intern_str;
63 typedef int64_t ssize_t;
65 /* =================================================================
67 ¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯
70 FILE *_bt_file_open(char *file_path, char *mode);
71 void _bt_file_close(FILE *fp);
72 struct bt_definition **_bt_python_field_listcaller(
73 const struct bt_ctf_event *ctf_event,
74 const struct bt_definition *scope,
75 unsigned int *OUTPUT);
76 struct bt_definition *_bt_python_field_one_from_list(
77 struct bt_definition **list, int index);
78 struct bt_ctf_event_decl **_bt_python_event_decl_listcaller(
80 struct bt_context *ctx,
81 unsigned int *OUTPUT);
82 struct bt_ctf_event_decl *_bt_python_decl_one_from_list(
83 struct bt_ctf_event_decl **list, int index);
84 struct bt_ctf_field_decl **_by_python_field_decl_listcaller(
85 struct bt_ctf_event_decl *event_decl,
86 enum bt_ctf_scope scope,
87 unsigned int *OUTPUT);
88 struct bt_ctf_field_decl *_bt_python_field_decl_one_from_list(
89 struct bt_ctf_field_decl **list, int index);
90 struct definition_array *_bt_python_get_array_from_def(
91 struct bt_definition *field);
92 struct definition_sequence *_bt_python_get_sequence_from_def(
93 struct bt_definition *field);
94 struct bt_declaration *_bt_python_get_array_element_declaration(
95 struct bt_declaration *field);
96 struct bt_declaration *_bt_python_get_sequence_element_declaration(
97 struct bt_declaration *field);
98 const char *_bt_python_get_array_string(struct bt_definition *field);
99 const char *_bt_python_get_sequence_string(struct bt_definition *field);
100 int _bt_python_field_integer_get_signedness(const struct bt_ctf_field *field);
101 enum ctf_type_id _bt_python_get_field_type(const struct bt_ctf_field *field);
102 struct bt_iter_pos *_bt_python_create_iter_pos(void);
103 struct bt_ctf_iter *_bt_python_ctf_iter_create_intersect(
104 struct bt_context *ctx,
105 struct bt_iter_pos *inter_begin_pos,
106 struct bt_iter_pos *inter_end_pos);
107 int _bt_python_has_intersection(struct bt_context *ctx);
109 /* =================================================================
110 CONTEXT.H, CONTEXT-INTERNAL.H
111 ¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯
114 %rename("_bt_context_create") bt_context_create(void);
115 %rename("_bt_context_add_trace") bt_context_add_trace(
116 struct bt_context *ctx, const char *path, const char *format,
117 void (*packet_seek)(struct bt_stream_pos *pos, size_t index, int whence),
118 struct bt_mmap_stream_list *stream_list, FILE *metadata);
119 %rename("_bt_context_remove_trace") bt_context_remove_trace(
120 struct bt_context *ctx, int trace_id);
121 %rename("_bt_context_get") bt_context_get(struct bt_context *ctx);
122 %rename("_bt_context_put") bt_context_put(struct bt_context *ctx);
123 %rename("_bt_ctf_event_get_context") bt_ctf_event_get_context(
124 const struct bt_ctf_event *event);
126 struct bt_context *bt_context_create(void);
127 int bt_context_add_trace(struct bt_context *ctx, const char *path, const char *format,
128 void (*packet_seek)(struct bt_stream_pos *pos, size_t index, int whence),
129 struct bt_mmap_stream_list *stream_list, FILE *metadata);
130 void bt_context_remove_trace(struct bt_context *ctx, int trace_id);
131 void bt_context_get(struct bt_context *ctx);
132 void bt_context_put(struct bt_context *ctx);
133 struct bt_context *bt_ctf_event_get_context(const struct bt_ctf_event *event);
135 // class TraceCollection to prevent direct access to struct bt_context
137 class TraceCollection:
139 The TraceCollection is the object that contains all currently opened traces.
142 def __init__(self, intersect_mode=False):
143 self._tc = _bt_context_create()
144 self._intersect_mode = intersect_mode
147 _bt_context_put(self._tc)
149 def add_trace(self, path, format_str):
151 Add a trace by path to the TraceCollection.
155 path is the path to the trace, it is not recursive.
156 If "path" is None, stream_list is used instead as a list
157 of mmap streams to open for the trace.
159 format is a string containing the format name in which the trace was
162 Return: the corresponding TraceHandle on success or None on error.
164 ret = _bt_context_add_trace(self._tc, path, format_str, None, None, None)
168 th = TraceHandle.__new__(TraceHandle)
170 th._trace_collection = self
173 def add_traces_recursive(self, path, format_str):
175 Open a trace recursively.
177 Find each trace present in the subdirectory starting from the given
178 path, and add them to the TraceCollection.
180 Return a dict of TraceHandle instances (the full path is the key).
181 Return None on error.
191 for fullpath, dirs, files in os.walk(path):
192 if "metadata" in files:
193 trace_handle = self.add_trace(fullpath, format_str)
194 if trace_handle is None:
198 trace_handles[fullpath] = trace_handle
201 if noTrace and error:
205 def remove_trace(self, trace_handle):
207 Remove a trace from the TraceCollection.
208 Effectively closing the trace.
211 _bt_context_remove_trace(self._tc, trace_handle._id)
212 except AttributeError:
213 raise TypeError("in remove_trace, "
214 "argument 2 must be a TraceHandle instance")
217 def intersect_mode(self):
218 return self._intersect_mode
221 def has_intersection(self):
222 return _bt_python_has_intersection(self._tc)
227 Generator function to iterate over the events of open in the current
230 Due to limitations of the native Babeltrace API, only one event
231 may be "alive" at a time (i.e. a user should never store a copy
232 of the events returned by this function for ulterior use). Users
233 shall make sure to copy the information they need from an event
234 before accessing the next one.
236 Furthermore, event objects become invalid when the generator goes
237 out of scope as the underlying iterator will be reclaimed. Using an
238 event after the the generator has gone out of scope may result in a
239 crash or data corruption.
241 begin_pos_ptr = _bt_python_create_iter_pos()
242 end_pos_ptr = _bt_python_create_iter_pos()
243 if not self.intersect_mode:
244 begin_pos_ptr.type = SEEK_BEGIN
245 end_pos_ptr.type = SEEK_LAST
247 for event in self._events(begin_pos_ptr, end_pos_ptr):
250 _bt_iter_free_pos(begin_pos_ptr)
251 _bt_iter_free_pos(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_python_create_iter_pos()
259 end_pos_ptr = _bt_python_create_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):
267 _bt_iter_free_pos(begin_pos_ptr)
268 _bt_iter_free_pos(end_pos_ptr)
271 def timestamp_begin(self):
272 pos_ptr = _bt_iter_pos()
273 pos_ptr.type = SEEK_BEGIN
274 return self._timestamp_at_pos(pos_ptr)
277 def timestamp_end(self):
278 pos_ptr = _bt_iter_pos()
279 pos_ptr.type = SEEK_LAST
280 return self._timestamp_at_pos(pos_ptr)
282 def _timestamp_at_pos(self, pos_ptr):
283 ctf_it_ptr = _bt_ctf_iter_create(self._tc, pos_ptr, pos_ptr)
284 if ctf_it_ptr is None:
285 raise NotImplementedError("Creation of multiple iterators is unsupported.")
286 ev_ptr = _bt_ctf_iter_read_event(ctf_it_ptr)
287 _bt_ctf_iter_destroy(ctf_it_ptr)
290 ev = Event.__new__(Event)
294 def _events(self, begin_pos_ptr, end_pos_ptr):
295 if self.intersect_mode:
296 if not self.has_intersection:
297 # There are no events to provide.
300 ctf_it_ptr = _bt_python_ctf_iter_create_intersect(
301 self._tc, begin_pos_ptr, end_pos_ptr
304 ctf_it_ptr = _bt_ctf_iter_create(
305 self._tc, begin_pos_ptr, end_pos_ptr
308 if ctf_it_ptr is None:
309 raise NotImplementedError(
310 "Creation of multiple iterators is unsupported.")
313 ev_ptr = _bt_ctf_iter_read_event(ctf_it_ptr)
317 ev = Event.__new__(Event)
321 except GeneratorExit:
324 ret = _bt_iter_next(_bt_ctf_get_iter(ctf_it_ptr))
328 _bt_ctf_iter_destroy(ctf_it_ptr)
334 /* =================================================================
339 %rename("lookup_format") bt_lookup_format(bt_intern_str qname);
340 %rename("_bt_print_format_list") bt_fprintf_format_list(FILE *fp);
341 %rename("register_format") bt_register_format(struct format *format);
342 %rename("unregister_format") bt_unregister_format(struct bt_format *format);
344 extern struct format *bt_lookup_format(bt_intern_str qname);
345 extern void bt_fprintf_format_list(FILE *fp);
346 extern int bt_register_format(struct bt_format *format);
347 extern void bt_unregister_format(struct bt_format *format);
351 def print_format_list(babeltrace_file):
353 Print a list of available formats to file.
355 babeltrace_file must be a File instance opened in write mode.
358 if babeltrace_file._file is not None:
359 _bt_print_format_list(babeltrace_file._file)
360 except AttributeError:
361 raise TypeError("in print_format_list, "
362 "argument 1 must be a File instance")
367 /* =================================================================
368 ITERATOR.H, ITERATOR-INTERNAL.H
369 ¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯
372 %rename("_bt_iter_create") bt_iter_create(struct bt_context *ctx,
373 const struct bt_iter_pos *begin_pos, const struct bt_iter_pos *end_pos);
374 %rename("_bt_iter_destroy") bt_iter_destroy(struct bt_iter *iter);
375 %rename("_bt_iter_next") bt_iter_next(struct bt_iter *iter);
376 %rename("_bt_iter_get_pos") bt_iter_get_pos(struct bt_iter *iter);
377 %rename("_bt_iter_free_pos") bt_iter_free_pos(struct bt_iter_pos *pos);
378 %rename("_bt_iter_set_pos") bt_iter_set_pos(struct bt_iter *iter,
379 const struct bt_iter_pos *pos);
380 %rename("_bt_iter_create_time_pos") bt_iter_create_time_pos(struct bt_iter *iter,
383 struct bt_iter *bt_iter_create(struct bt_context *ctx,
384 const struct bt_iter_pos *begin_pos, const struct bt_iter_pos *end_pos);
385 void bt_iter_destroy(struct bt_iter *iter);
386 int bt_iter_next(struct bt_iter *iter);
387 struct bt_iter_pos *bt_iter_get_pos(struct bt_iter *iter);
388 void bt_iter_free_pos(struct bt_iter_pos *pos);
389 int bt_iter_set_pos(struct bt_iter *iter, const struct bt_iter_pos *pos);
390 struct bt_iter_pos *bt_iter_create_time_pos(struct bt_iter *iter, uint64_t timestamp);
392 %rename("_bt_iter_pos") bt_iter_pos;
393 %rename("SEEK_TIME") BT_SEEK_TIME;
394 %rename("SEEK_RESTORE") BT_SEEK_RESTORE;
395 %rename("SEEK_CUR") BT_SEEK_CUR;
396 %rename("SEEK_BEGIN") BT_SEEK_BEGIN;
397 %rename("SEEK_LAST") BT_SEEK_LAST;
399 // This struct is taken from iterator.h
400 // All changes to the struct must also be made here
403 BT_SEEK_TIME, /* uses u.seek_time */
404 BT_SEEK_RESTORE, /* uses u.restore */
411 struct bt_saved_pos *restore;
415 /* =================================================================
416 TRACE-HANDLE.H, TRACE-HANDLE-INTERNAL.H
417 ¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯
420 %rename("_bt_trace_handle_create") bt_trace_handle_create(struct bt_context *ctx);
421 %rename("_bt_trace_handle_destroy") bt_trace_handle_destroy(struct bt_trace_handle *bt);
422 struct bt_trace_handle *bt_trace_handle_create(struct bt_context *ctx);
423 void bt_trace_handle_destroy(struct bt_trace_handle *bt);
425 %rename("_bt_trace_handle_get_path") bt_trace_handle_get_path(struct bt_context *ctx,
427 %rename("_bt_trace_handle_get_timestamp_begin") bt_trace_handle_get_timestamp_begin(
428 struct bt_context *ctx, int handle_id, enum bt_clock_type type);
429 %rename("_bt_trace_handle_get_timestamp_end") bt_trace_handle_get_timestamp_end(
430 struct bt_context *ctx, int handle_id, enum bt_clock_type type);
431 const char *bt_trace_handle_get_path(struct bt_context *ctx, int handle_id);
432 uint64_t bt_trace_handle_get_timestamp_begin(struct bt_context *ctx, int handle_id,
433 enum bt_clock_type type);
434 uint64_t bt_trace_handle_get_timestamp_end(struct bt_context *ctx, int handle_id,
435 enum bt_clock_type type);
437 %rename("_bt_ctf_event_get_handle_id") bt_ctf_event_get_handle_id(
438 const struct bt_ctf_event *event);
439 int bt_ctf_event_get_handle_id(const struct bt_ctf_event *event);
444 # Based on enum bt_clock_type in clock-type.h
449 class TraceHandle(object):
451 The TraceHandle allows the user to manipulate a trace file directly.
452 It is a unique identifier representing a trace file.
457 raise NotImplementedError("TraceHandle cannot be instantiated")
460 return "Babeltrace TraceHandle: trace_id('{0}')".format(self._id)
464 """Return the TraceHandle id."""
469 """Return the path of a TraceHandle."""
470 return _bt_trace_handle_get_path(self._trace_collection._tc, self._id)
473 def timestamp_begin(self):
474 """Return the creation time of the buffers of a trace."""
475 return _bt_trace_handle_get_timestamp_begin(
476 self._trace_collection._tc, self._id, ClockType.CLOCK_REAL)
479 def timestamp_end(self):
480 """Return the destruction timestamp of the buffers of a trace."""
481 return _bt_trace_handle_get_timestamp_end(
482 self._trace_collection._tc, self._id, ClockType.CLOCK_REAL)
487 Generator returning all events (EventDeclaration) in a trace.
489 ret = _bt_python_event_decl_listcaller(self.id, self._trace_collection._tc)
491 if not isinstance(ret, list):
494 ptr_list, count = ret
495 for i in range(count):
496 tmp = EventDeclaration.__new__(EventDeclaration)
497 tmp._ed = _bt_python_decl_one_from_list(ptr_list, i)
504 // =================================================================
506 // =================================================================
508 /* =================================================================
514 %rename("_bt_ctf_iter_create") bt_ctf_iter_create(struct bt_context *ctx,
515 const struct bt_iter_pos *begin_pos,
516 const struct bt_iter_pos *end_pos);
517 %rename("_bt_ctf_get_iter") bt_ctf_get_iter(struct bt_ctf_iter *iter);
518 %rename("_bt_ctf_iter_destroy") bt_ctf_iter_destroy(struct bt_ctf_iter *iter);
519 %rename("_bt_ctf_iter_read_event") bt_ctf_iter_read_event(struct bt_ctf_iter *iter);
521 struct bt_ctf_iter *bt_ctf_iter_create(struct bt_context *ctx,
522 const struct bt_iter_pos *begin_pos,
523 const struct bt_iter_pos *end_pos);
524 struct bt_iter *bt_ctf_get_iter(struct bt_ctf_iter *iter);
525 void bt_ctf_iter_destroy(struct bt_ctf_iter *iter);
526 struct bt_ctf_event *bt_ctf_iter_read_event(struct bt_ctf_iter *iter);
530 %rename("_bt_ctf_get_top_level_scope") bt_ctf_get_top_level_scope(const struct
531 bt_ctf_event *event, enum bt_ctf_scope scope);
532 %rename("_bt_ctf_event_name") bt_ctf_event_name(const struct bt_ctf_event *ctf_event);
533 %rename("_bt_ctf_get_timestamp") bt_ctf_get_timestamp(
534 const struct bt_ctf_event *ctf_event);
535 %rename("_bt_ctf_get_cycles") bt_ctf_get_cycles(
536 const struct bt_ctf_event *ctf_event);
538 %rename("_bt_ctf_get_field") bt_ctf_get_field(const struct bt_ctf_event *ctf_event,
539 const struct bt_definition *scope, const char *field);
540 %rename("_bt_ctf_get_index") bt_ctf_get_index(const struct bt_ctf_event *ctf_event,
541 const struct bt_definition *field, unsigned int index);
542 %rename("_bt_ctf_field_name") bt_ctf_field_name(const struct bt_definition *field);
543 %rename("_bt_ctf_field_type") bt_ctf_field_type(const struct bt_declaration *field);
544 %rename("_bt_ctf_get_int_signedness") bt_ctf_get_int_signedness(
545 const struct bt_declaration *field);
546 %rename("_bt_ctf_get_int_base") bt_ctf_get_int_base(const struct bt_declaration *field);
547 %rename("_bt_ctf_get_int_byte_order") bt_ctf_get_int_byte_order(
548 const struct bt_declaration *field);
549 %rename("_bt_ctf_get_int_len") bt_ctf_get_int_len(const struct bt_declaration *field);
550 %rename("_bt_ctf_get_enum_int") bt_ctf_get_enum_int(const struct bt_definition *field);
551 %rename("_bt_ctf_get_enum_str") bt_ctf_get_enum_str(const struct bt_definition *field);
552 %rename("_bt_ctf_get_encoding") bt_ctf_get_encoding(const struct bt_declaration *field);
553 %rename("_bt_ctf_get_array_len") bt_ctf_get_array_len(const struct bt_declaration *field);
554 %rename("_bt_ctf_get_uint64") bt_ctf_get_uint64(const struct bt_definition *field);
555 %rename("_bt_ctf_get_int64") bt_ctf_get_int64(const struct bt_definition *field);
556 %rename("_bt_ctf_get_char_array") bt_ctf_get_char_array(const struct bt_definition *field);
557 %rename("_bt_ctf_get_string") bt_ctf_get_string(const struct bt_definition *field);
558 %rename("_bt_ctf_get_float") bt_ctf_get_float(const struct bt_definition *field);
559 %rename("_bt_ctf_get_variant") bt_ctf_get_variant(const struct bt_definition *field);
560 %rename("_bt_ctf_field_get_error") bt_ctf_field_get_error(void);
561 %rename("_bt_ctf_get_decl_event_name") bt_ctf_get_decl_event_name(const struct
562 bt_ctf_event_decl *event);
563 %rename("_bt_ctf_get_decl_field_name") bt_ctf_get_decl_field_name(
564 const struct bt_ctf_field_decl *field);
565 %rename("_bt_ctf_get_decl_from_def") bt_ctf_get_decl_from_def(
566 const struct bt_definition *field);
567 %rename("_bt_ctf_get_decl_from_field_decl") bt_ctf_get_decl_from_field_decl(
568 const struct bt_ctf_field_decl *field);
569 %rename("_bt_array_index") bt_array_index(struct definition_array *array, uint64_t i);
570 %rename("_bt_sequence_len") bt_sequence_len(struct definition_sequence *sequence);
571 %rename("_bt_sequence_index") bt_sequence_index(struct definition_sequence *sequence, uint64_t i);
572 %rename("_bt_ctf_get_struct_field_count") bt_ctf_get_struct_field_count(const struct bt_definition *structure);
573 %rename("_bt_ctf_get_struct_field_index") bt_ctf_get_struct_field_index(const struct bt_definition *structure, uint64_t i);
575 const struct bt_definition *bt_ctf_get_top_level_scope(const struct bt_ctf_event *ctf_event,
576 enum bt_ctf_scope scope);
577 const char *bt_ctf_event_name(const struct bt_ctf_event *ctf_event);
578 uint64_t bt_ctf_get_timestamp(const struct bt_ctf_event *ctf_event);
579 uint64_t bt_ctf_get_cycles(const struct bt_ctf_event *ctf_event);
580 const struct bt_definition *bt_ctf_get_field(const struct bt_ctf_event *ctf_event,
581 const struct bt_definition *scope,
583 const struct bt_definition *bt_ctf_get_index(const struct bt_ctf_event *ctf_event,
584 const struct bt_definition *field,
586 const char *bt_ctf_field_name(const struct bt_definition *field);
587 enum ctf_type_id bt_ctf_field_type(const struct bt_declaration *field);
588 int bt_ctf_get_int_signedness(const struct bt_declaration *field);
589 int bt_ctf_get_int_base(const struct bt_declaration *field);
590 int bt_ctf_get_int_byte_order(const struct bt_declaration *field);
591 ssize_t bt_ctf_get_int_len(const struct bt_declaration *field);
592 const struct bt_definition *bt_ctf_get_enum_int(const struct bt_definition *field);
593 const char *bt_ctf_get_enum_str(const struct bt_definition *field);
594 enum ctf_string_encoding bt_ctf_get_encoding(const struct bt_declaration *field);
595 int bt_ctf_get_array_len(const struct bt_declaration *field);
596 struct bt_definition *bt_array_index(struct definition_array *array, uint64_t i);
597 uint64_t bt_ctf_get_uint64(const struct bt_definition *field);
598 int64_t bt_ctf_get_int64(const struct bt_definition *field);
599 char *bt_ctf_get_char_array(const struct bt_definition *field);
600 char *bt_ctf_get_string(const struct bt_definition *field);
601 double bt_ctf_get_float(const struct bt_definition *field);
602 const struct bt_definition *bt_ctf_get_variant(const struct bt_definition *field);
603 int bt_ctf_field_get_error(void);
604 const char *bt_ctf_get_decl_event_name(const struct bt_ctf_event_decl *event);
605 const char *bt_ctf_get_decl_field_name(const struct bt_ctf_field_decl *field);
606 const struct bt_declaration *bt_ctf_get_decl_from_def(const struct bt_definition *field);
607 const struct bt_declaration *bt_ctf_get_decl_from_field_decl(const struct bt_ctf_field_decl *field);
608 uint64_t bt_sequence_len(struct definition_sequence *sequence);
609 struct bt_definition *bt_sequence_index(struct definition_sequence *sequence, uint64_t i);
610 uint64_t bt_ctf_get_struct_field_count(const struct bt_definition *structure);
611 const struct bt_definition *bt_ctf_get_struct_field_index(const struct bt_definition *structure, uint64_t i);
615 class CTFStringEncoding:
621 # Based on the enum in ctf-writer/writer.h
623 BYTE_ORDER_NATIVE = 0
624 BYTE_ORDER_LITTLE_ENDIAN = 1
625 BYTE_ORDER_BIG_ENDIAN = 2
626 BYTE_ORDER_NETWORK = 3
627 BYTE_ORDER_UNKNOWN = 4 # Python-specific entry
629 #enum equivalent, accessible constants
630 #These are taken directly from ctf/events.h
631 #All changes to enums must also be made here
646 name = "UNKNOWN_TYPE"
647 constants = [attr for attr in dir(CTFTypeId) if not callable(getattr(CTFTypeId, attr)) and not attr.startswith("__")]
648 for attr in constants:
649 if getattr(CTFTypeId, attr) == id:
655 TRACE_PACKET_HEADER = 0
656 STREAM_PACKET_CONTEXT = 1
657 STREAM_EVENT_HEADER = 2
658 STREAM_EVENT_CONTEXT = 3
662 def scope_name(scope):
663 name = "UNKNOWN_SCOPE"
664 constants = [attr for attr in dir(CTFScope) if not callable(getattr(CTFScope, attr)) and not attr.startswith("__")]
665 for attr in constants:
666 if getattr(CTFScope, attr) == scope:
671 # Priority of the scopes when searching for event fields
672 _scopes = [CTFScope.EVENT_FIELDS, CTFScope.EVENT_CONTEXT, CTFScope.STREAM_EVENT_CONTEXT,
673 CTFScope.STREAM_EVENT_HEADER, CTFScope.STREAM_PACKET_CONTEXT, CTFScope.TRACE_PACKET_HEADER]
676 class Event(collections.Mapping):
678 This class represents an event from the trace.
679 It is obtained using the TraceCollection generator functions.
683 raise NotImplementedError("Event cannot be instantiated")
687 """Return the name of the event or None on error."""
688 return _bt_ctf_event_name(self._e)
693 Return the timestamp of the event as written in
694 the packet (in cycles) or -1ULL on error.
696 return _bt_ctf_get_cycles(self._e)
701 Return the timestamp of the event offset with the
702 system clock source or -1ULL on error.
704 return _bt_ctf_get_timestamp(self._e)
706 def field_with_scope(self, field_name, scope):
708 Get field_name's value in scope.
709 None is returned if no field matches field_name.
711 if not scope in _scopes:
712 raise ValueError("Invalid scope provided")
713 field = self._field_with_scope(field_name, scope)
714 if field is not None:
718 def field_list_with_scope(self, scope):
719 """Return a list of field names in scope."""
720 if not scope in _scopes:
721 raise ValueError("Invalid scope provided")
723 for field in self._field_list_with_scope(scope):
724 field_names.append(field.name)
730 Get the TraceHandle associated with this event
733 ret = _bt_ctf_event_get_handle_id(self._e)
737 th = TraceHandle.__new__(TraceHandle)
739 th._trace_collection = self.get_trace_collection()
743 def trace_collection(self):
745 Get the TraceCollection associated with this event.
746 Return None on error.
748 trace_collection = TraceCollection()
749 trace_collection._tc = _bt_ctf_event_get_context(self._e);
750 if trace_collection._tc is None:
753 return trace_collection
755 def __getitem__(self, field_name):
757 Get field_name's value. If the field_name exists in multiple
758 scopes, the first field found is returned. The scopes are searched
759 in the following order:
762 3) STREAM_EVENT_CONTEXT
763 4) STREAM_EVENT_HEADER
764 5) STREAM_PACKET_CONTEXT
765 6) TRACE_PACKET_HEADER
766 None is returned if no field matches field_name.
768 Use field_with_scope() to explicitly access fields in a given
771 field = self._field(field_name)
772 if field is not None:
774 raise KeyError(field_name)
777 for key in self.keys():
782 for scope in _scopes:
783 scope_ptr = _bt_ctf_get_top_level_scope(self._e, scope)
784 ret = _bt_python_field_listcaller(self._e, scope_ptr)
785 if isinstance(ret, list):
789 def __contains__(self, field_name):
790 return self._field(field_name) is not None
793 """Return a list of field names."""
795 for scope in _scopes:
796 for name in self.field_list_with_scope(scope):
797 field_names.add(name)
798 return list(field_names)
800 def get(self, field_name, default = None):
801 field = self._field(field_name)
807 for field in self.keys():
808 yield (field, self[field])
810 def _field_with_scope(self, field_name, scope):
811 scope_ptr = _bt_ctf_get_top_level_scope(self._e, scope)
812 if scope_ptr is None:
815 definition_ptr = _bt_ctf_get_field(self._e, scope_ptr, field_name)
816 if definition_ptr is None:
819 field = _Definition(definition_ptr, scope)
822 def _field(self, field_name):
824 for scope in _scopes:
825 field = self._field_with_scope(field_name, scope)
826 if field is not None:
830 def _field_list_with_scope(self, scope):
832 scope_ptr = _bt_ctf_get_top_level_scope(self._e, scope)
834 # Returns a list [list_ptr, count]. If list_ptr is NULL, SWIG will only
835 # provide the "count" return value
838 ret = _bt_python_field_listcaller(self._e, scope_ptr)
839 if isinstance(ret, list):
840 list_ptr, count = ret
842 for i in range(count):
843 definition_ptr = _bt_python_field_one_from_list(list_ptr, i)
844 if definition_ptr is not None:
845 definition = _Definition(definition_ptr, scope)
846 fields.append(definition)
849 class FieldError(Exception):
850 def __init__(self, value):
854 return repr(self.value)
856 class EventDeclaration(object):
857 """Event declaration class. Do not instantiate."""
860 raise NotImplementedError("EventDeclaration cannot be instantiated")
864 """Return the name of the event or None on error"""
865 return _bt_ctf_get_decl_event_name(self._ed)
870 Generator returning all FieldDeclarations of an event, going through
871 each scope in the following order:
874 3) STREAM_EVENT_CONTEXT
875 4) STREAM_EVENT_HEADER
876 5) STREAM_PACKET_CONTEXT
877 6) TRACE_PACKET_HEADER
879 for scope in _scopes:
880 for declaration in self.fields_scope(scope):
883 def fields_scope(self, scope):
885 Generator returning FieldDeclarations of the current event in scope.
887 ret = _by_python_field_decl_listcaller(self._ed, scope)
889 if not isinstance(ret, list):
892 list_ptr, count = ret
893 for i in range(count):
894 field_declaration_ptr = _bt_python_field_decl_one_from_list(list_ptr, i)
895 if field_declaration_ptr is not None:
896 declaration_ptr = _bt_ctf_get_decl_from_field_decl(field_declaration_ptr)
897 field_declaration = _create_field_declaration(declaration_ptr, _bt_ctf_get_decl_field_name(field_declaration_ptr), scope)
898 yield field_declaration
900 class FieldDeclaration(object):
901 """Field declaration class. Do not instantiate."""
903 raise NotImplementedError("FieldDeclaration cannot be instantiated")
906 return "({0}) {1} {2}".format(CTFScope.scope_name(self.scope), CTFTypeId.type_name(self.type), self.name)
910 """Return the name of a FieldDeclaration or None on error."""
916 Return the FieldDeclaration's type. One of the entries in class
919 return _bt_ctf_field_type(self._fd)
924 Return the FieldDeclaration's scope.
928 class IntegerFieldDeclaration(FieldDeclaration):
929 """Do not instantiate."""
931 raise NotImplementedError("IntegerFieldDeclaration cannot be instantiated")
934 def signedness(self):
936 Return the signedness of an integer:
937 0 if unsigned; 1 if signed; -1 on error.
939 return _bt_ctf_get_int_signedness(self._fd)
943 """Return the base of an int or a negative value on error."""
944 return _bt_ctf_get_int_base(self._fd)
947 def byte_order(self):
949 Return the byte order. One of class ByteOrder's entries.
951 ret = _bt_ctf_get_int_byte_order(self._fd)
953 return ByteOrder.BYTE_ORDER_LITTLE_ENDIAN
955 return ByteOrder.BYTE_ORDER_BIG_ENDIAN
957 return ByteOrder.BYTE_ORDER_UNKNOWN
962 Return the size, in bits, of an int or a negative
965 return _bt_ctf_get_int_len(self._fd)
970 Return the encoding. One of class CTFStringEncoding's entries.
971 Return a negative value on error.
973 return _bt_ctf_get_encoding(self._fd)
975 class EnumerationFieldDeclaration(FieldDeclaration):
976 """Do not instantiate."""
978 raise NotImplementedError("EnumerationFieldDeclaration cannot be instantiated")
980 class ArrayFieldDeclaration(FieldDeclaration):
981 """Do not instantiate."""
983 raise NotImplementedError("ArrayFieldDeclaration cannot be instantiated")
988 Return the length of an array or a negative
991 return _bt_ctf_get_array_len(self._fd)
994 def element_declaration(self):
996 Return element declaration.
998 field_decl_ptr = _bt_python_get_array_element_declaration(self._fd)
999 return _create_field_declaration(field_decl_ptr, "", self.scope)
1001 class SequenceFieldDeclaration(FieldDeclaration):
1002 """Do not instantiate."""
1004 raise NotImplementedError("SequenceFieldDeclaration cannot be instantiated")
1007 def element_declaration(self):
1009 Return element declaration.
1011 field_decl_ptr = _bt_python_get_sequence_element_declaration(self._fd)
1012 return _create_field_declaration(field_decl_ptr, "", self.scope)
1014 class FloatFieldDeclaration(FieldDeclaration):
1015 """Do not instantiate."""
1017 raise NotImplementedError("FloatFieldDeclaration cannot be instantiated")
1019 class StructureFieldDeclaration(FieldDeclaration):
1020 """Do not instantiate."""
1022 raise NotImplementedError("StructureFieldDeclaration cannot be instantiated")
1024 class StringFieldDeclaration(FieldDeclaration):
1025 """Do not instantiate."""
1027 raise NotImplementedError("StringFieldDeclaration cannot be instantiated")
1029 class VariantFieldDeclaration(FieldDeclaration):
1030 """Do not instantiate."""
1032 raise NotImplementedError("VariantFieldDeclaration cannot be instantiated")
1036 Return the last error code encountered while
1037 accessing a field and reset the error flag.
1038 Return 0 if no error, a negative value otherwise.
1040 return _bt_ctf_field_get_error()
1042 def _create_field_declaration(declaration_ptr, name, scope):
1044 Private field declaration factory.
1046 if declaration_ptr is None:
1047 raise ValueError("declaration_ptr must be valid")
1048 if not scope in _scopes:
1049 raise ValueError("Invalid scope provided")
1051 type = _bt_ctf_field_type(declaration_ptr)
1053 if type == CTFTypeId.INTEGER:
1054 declaration = IntegerFieldDeclaration.__new__(IntegerFieldDeclaration)
1055 elif type == CTFTypeId.ENUM:
1056 declaration = EnumerationFieldDeclaration.__new__(EnumerationFieldDeclaration)
1057 elif type == CTFTypeId.ARRAY:
1058 declaration = ArrayFieldDeclaration.__new__(ArrayFieldDeclaration)
1059 elif type == CTFTypeId.SEQUENCE:
1060 declaration = SequenceFieldDeclaration.__new__(SequenceFieldDeclaration)
1061 elif type == CTFTypeId.FLOAT:
1062 declaration = FloatFieldDeclaration.__new__(FloatFieldDeclaration)
1063 elif type == CTFTypeId.STRUCT:
1064 declaration = StructureFieldDeclaration.__new__(StructureFieldDeclaration)
1065 elif type == CTFTypeId.STRING:
1066 declaration = StringFieldDeclaration.__new__(StringFieldDeclaration)
1067 elif type == CTFTypeId.VARIANT:
1068 declaration = VariantFieldDeclaration.__new__(VariantFieldDeclaration)
1072 declaration._fd = declaration_ptr
1073 declaration._s = scope
1074 declaration._name = name
1077 class _Definition(object):
1078 def __init__(self, definition_ptr, scope):
1079 self._d = definition_ptr
1081 if not scope in _scopes:
1082 ValueError("Invalid scope provided")
1086 """Return the name of a field or None on error."""
1087 return _bt_ctf_field_name(self._d)
1091 """Return the type of a field or -1 if unknown."""
1092 return _bt_ctf_field_type(_bt_ctf_get_decl_from_def(self._d))
1095 def declaration(self):
1096 """Return the associated Definition object."""
1097 return _create_field_declaration(_bt_ctf_get_decl_from_def(self._d), self.name, self.scope)
1099 def _get_enum_str(self):
1101 Return the string matching the current enumeration.
1102 Return None on error.
1104 return _bt_ctf_get_enum_str(self._d)
1106 def _get_array_element_at(self, index):
1108 Return the array's element at position index.
1109 Return None on error
1111 array_ptr = _bt_python_get_array_from_def(self._d)
1112 if array_ptr is None:
1115 definition_ptr = _bt_array_index(array_ptr, index)
1116 if definition_ptr is None:
1118 return _Definition(definition_ptr, self.scope)
1120 def _get_sequence_len(self):
1122 Return the len of a sequence or a negative
1125 seq = _bt_python_get_sequence_from_def(self._d)
1126 return _bt_sequence_len(seq)
1128 def _get_sequence_element_at(self, index):
1130 Return the sequence's element at position index,
1131 otherwise return None
1133 seq = _bt_python_get_sequence_from_def(self._d)
1135 definition_ptr = _bt_sequence_index(seq, index)
1136 if definition_ptr is not None:
1137 return _Definition(definition_ptr, self.scope)
1140 def _get_uint64(self):
1142 Return the value associated with the field.
1143 If the field does not exist or is not of the type requested,
1144 the value returned is undefined. To check if an error occured,
1145 use the field_error() function after accessing a field.
1147 return _bt_ctf_get_uint64(self._d)
1149 def _get_int64(self):
1151 Return the value associated with the field.
1152 If the field does not exist or is not of the type requested,
1153 the value returned is undefined. To check if an error occured,
1154 use the field_error() function after accessing a field.
1156 return _bt_ctf_get_int64(self._d)
1158 def _get_char_array(self):
1160 Return the value associated with the field.
1161 If the field does not exist or is not of the type requested,
1162 the value returned is undefined. To check if an error occurred,
1163 use the field_error() function after accessing a field.
1165 return _bt_ctf_get_char_array(self._d)
1169 Return the value associated with the field.
1170 If the field does not exist or is not of the type requested,
1171 the value returned is undefined. To check if an error occurred,
1172 use the field_error() function after accessing a field.
1174 return _bt_ctf_get_string(self._d)
1176 def _get_float(self):
1178 Return the value associated with the field.
1179 If the field does not exist or is not of the type requested,
1180 the value returned is undefined. To check if an error occurred,
1181 use the field_error() function after accessing a field.
1183 return _bt_ctf_get_float(self._d)
1185 def _get_variant(self):
1187 Return the variant's selected field.
1188 If the field does not exist or is not of the type requested,
1189 the value returned is undefined. To check if an error occurred,
1190 use the field_error() function after accessing a field.
1192 return _bt_ctf_get_variant(self._d)
1194 def _get_struct_field_count(self):
1196 Return the number of fields contained in the structure.
1197 If the field does not exist or is not of the type requested,
1198 the value returned is undefined.
1200 return _bt_ctf_get_struct_field_count(self._d)
1202 def _get_struct_field_at(self, i):
1204 Return the structure's field at position i.
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 occurred,
1207 use the field_error() function after accessing a field.
1209 return _bt_ctf_get_struct_field_index(self._d, i)
1214 Return the value associated with the field according to its type.
1215 Return None on error.
1220 if id == CTFTypeId.STRING:
1221 value = self._get_str()
1222 elif id == CTFTypeId.ARRAY:
1223 element_decl = self.declaration.element_declaration
1224 if ((element_decl.type == CTFTypeId.INTEGER
1225 and element_decl.length == 8)
1226 and (element_decl.encoding == CTFStringEncoding.ASCII or element_decl.encoding == CTFStringEncoding.UTF8)):
1227 value = _bt_python_get_array_string(self._d)
1230 for i in range(self.declaration.length):
1231 element = self._get_array_element_at(i)
1232 value.append(element.value)
1233 elif id == CTFTypeId.INTEGER:
1234 if self.declaration.signedness == 0:
1235 value = self._get_uint64()
1237 value = self._get_int64()
1238 elif id == CTFTypeId.ENUM:
1239 value = self._get_enum_str()
1240 elif id == CTFTypeId.SEQUENCE:
1241 element_decl = self.declaration.element_declaration
1242 if ((element_decl.type == CTFTypeId.INTEGER
1243 and element_decl.length == 8)
1244 and (element_decl.encoding == CTFStringEncoding.ASCII or element_decl.encoding == CTFStringEncoding.UTF8)):
1245 value = _bt_python_get_sequence_string(self._d)
1247 seq_len = self._get_sequence_len()
1249 for i in range(seq_len):
1250 evDef = self._get_sequence_element_at(i)
1251 value.append(evDef.value)
1252 elif id == CTFTypeId.FLOAT:
1253 value = self._get_float()
1254 elif id == CTFTypeId.VARIANT:
1255 variant = _Definition.__new__(_Definition)
1256 variant._d = self._get_variant();
1257 value = variant.value
1258 elif id == CTFTypeId.STRUCT:
1260 for i in range(self._get_struct_field_count()):
1261 member = _Definition(self._get_struct_field_at(i), self.scope)
1262 value[member.name] = member.value
1265 raise FieldError("Error occurred while accessing field {} of type {}".format(self.name, CTFTypeId.type_name(id)))
1270 """Return the scope of a field or None on error."""
1276 // =================================================================
1278 // =================================================================
1280 /* =================================================================
1282 ¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯
1284 %rename("_bt_ctf_clock_create") bt_ctf_clock_create(const char *name);
1285 %rename("_bt_ctf_clock_set_description") bt_ctf_clock_set_description(struct bt_ctf_clock *clock, const char *desc);
1286 %rename("_bt_ctf_clock_set_frequency") bt_ctf_clock_set_frequency(struct bt_ctf_clock *clock, uint64_t freq);
1287 %rename("_bt_ctf_clock_set_precision") bt_ctf_clock_set_precision(struct bt_ctf_clock *clock, uint64_t precision);
1288 %rename("_bt_ctf_clock_set_offset_s") bt_ctf_clock_set_offset_s(struct bt_ctf_clock *clock, uint64_t offset_s);
1289 %rename("_bt_ctf_clock_set_offset") bt_ctf_clock_set_offset(struct bt_ctf_clock *clock, uint64_t offset);
1290 %rename("_bt_ctf_clock_set_is_absolute") bt_ctf_clock_set_is_absolute(struct bt_ctf_clock *clock, int is_absolute);
1291 %rename("_bt_ctf_clock_set_time") bt_ctf_clock_set_time(struct bt_ctf_clock *clock, uint64_t time);
1292 %rename("_bt_ctf_clock_get") bt_ctf_clock_get(struct bt_ctf_clock *clock);
1293 %rename("_bt_ctf_clock_put") bt_ctf_clock_put(struct bt_ctf_clock *clock);
1295 struct bt_ctf_clock *bt_ctf_clock_create(const char *name);
1296 int bt_ctf_clock_set_description(struct bt_ctf_clock *clock, const char *desc);
1297 int bt_ctf_clock_set_frequency(struct bt_ctf_clock *clock, uint64_t freq);
1298 int bt_ctf_clock_set_precision(struct bt_ctf_clock *clock, uint64_t precision);
1299 int bt_ctf_clock_set_offset_s(struct bt_ctf_clock *clock, uint64_t offset_s);
1300 int bt_ctf_clock_set_offset(struct bt_ctf_clock *clock, uint64_t offset);
1301 int bt_ctf_clock_set_is_absolute(struct bt_ctf_clock *clock, int is_absolute);
1302 int bt_ctf_clock_set_time(struct bt_ctf_clock *clock, uint64_t time);
1303 void bt_ctf_clock_get(struct bt_ctf_clock *clock);
1304 void bt_ctf_clock_put(struct bt_ctf_clock *clock);
1306 /* =================================================================
1308 ¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯
1310 %rename("_bt_ctf_field_type_integer_create") bt_ctf_field_type_integer_create(unsigned int size);
1311 %rename("_bt_ctf_field_type_integer_set_signed") bt_ctf_field_type_integer_set_signed(struct bt_ctf_field_type *integer, int is_signed);
1312 %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);
1313 %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);
1314 %rename("_bt_ctf_field_type_enumeration_create") bt_ctf_field_type_enumeration_create(struct bt_ctf_field_type *integer_container_type);
1315 %rename("_bt_ctf_field_type_enumeration_add_mapping") bt_ctf_field_type_enumeration_add_mapping(struct bt_ctf_field_type *enumeration, const char *string, int64_t range_start, int64_t range_end);
1316 %rename("_bt_ctf_field_type_floating_point_create") bt_ctf_field_type_floating_point_create(void);
1317 %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);
1318 %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);
1319 %rename("_bt_ctf_field_type_structure_create") bt_ctf_field_type_structure_create(void);
1320 %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);
1321 %rename("_bt_ctf_field_type_variant_create") bt_ctf_field_type_variant_create(struct bt_ctf_field_type *enum_tag, const char *tag_name);
1322 %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);
1323 %rename("_bt_ctf_field_type_array_create") bt_ctf_field_type_array_create(struct bt_ctf_field_type *element_type, unsigned int length);
1324 %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);
1325 %rename("_bt_ctf_field_type_string_create") bt_ctf_field_type_string_create(void);
1326 %rename("_bt_ctf_field_type_string_set_encoding") bt_ctf_field_type_string_set_encoding(struct bt_ctf_field_type *string, enum ctf_string_encoding encoding);
1327 %rename("_bt_ctf_field_type_set_alignment") bt_ctf_field_type_set_alignment(struct bt_ctf_field_type *type, unsigned int alignment);
1328 %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);
1329 %rename("_bt_ctf_field_type_get") bt_ctf_field_type_get(struct bt_ctf_field_type *type);
1330 %rename("_bt_ctf_field_type_put") bt_ctf_field_type_put(struct bt_ctf_field_type *type);
1332 struct bt_ctf_field_type *bt_ctf_field_type_integer_create(unsigned int size);
1333 int bt_ctf_field_type_integer_set_signed(struct bt_ctf_field_type *integer, int is_signed);
1334 int bt_ctf_field_type_integer_set_base(struct bt_ctf_field_type *integer, enum bt_ctf_integer_base base);
1335 int bt_ctf_field_type_integer_set_encoding(struct bt_ctf_field_type *integer, enum ctf_string_encoding encoding);
1336 struct bt_ctf_field_type *bt_ctf_field_type_enumeration_create(struct bt_ctf_field_type *integer_container_type);
1337 int bt_ctf_field_type_enumeration_add_mapping(struct bt_ctf_field_type *enumeration, const char *string, int64_t range_start, int64_t range_end);
1338 struct bt_ctf_field_type *bt_ctf_field_type_floating_point_create(void);
1339 int bt_ctf_field_type_floating_point_set_exponent_digits(struct bt_ctf_field_type *floating_point, unsigned int exponent_digits);
1340 int bt_ctf_field_type_floating_point_set_mantissa_digits(struct bt_ctf_field_type *floating_point, unsigned int mantissa_digits);
1341 struct bt_ctf_field_type *bt_ctf_field_type_structure_create(void);
1342 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);
1343 struct bt_ctf_field_type *bt_ctf_field_type_variant_create(struct bt_ctf_field_type *enum_tag, const char *tag_name);
1344 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);
1345 struct bt_ctf_field_type *bt_ctf_field_type_array_create(struct bt_ctf_field_type *element_type, unsigned int length);
1346 struct bt_ctf_field_type *bt_ctf_field_type_sequence_create(struct bt_ctf_field_type *element_type, const char *length_field_name);
1347 struct bt_ctf_field_type *bt_ctf_field_type_string_create(void);
1348 int bt_ctf_field_type_string_set_encoding(struct bt_ctf_field_type *string, enum ctf_string_encoding encoding);
1349 int bt_ctf_field_type_set_alignment(struct bt_ctf_field_type *type, unsigned int alignment);
1350 int bt_ctf_field_type_set_byte_order(struct bt_ctf_field_type *type, enum bt_ctf_byte_order byte_order);
1351 void bt_ctf_field_type_get(struct bt_ctf_field_type *type);
1352 void bt_ctf_field_type_put(struct bt_ctf_field_type *type);
1354 /* =================================================================
1356 ¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯
1358 %rename("_bt_ctf_field_create") bt_ctf_field_create(struct bt_ctf_field_type *type);
1359 %rename("_bt_ctf_field_structure_get_field") bt_ctf_field_structure_get_field(struct bt_ctf_field *structure, const char *name);
1360 %rename("_bt_ctf_field_array_get_field") bt_ctf_field_array_get_field(struct bt_ctf_field *array, uint64_t index);
1361 %rename("_bt_ctf_field_sequence_set_length") bt_ctf_field_sequence_set_length(struct bt_ctf_field *sequence, struct bt_ctf_field *length_field);
1362 %rename("_bt_ctf_field_sequence_get_field") bt_ctf_field_sequence_get_field(struct bt_ctf_field *sequence, uint64_t index);
1363 %rename("_bt_ctf_field_variant_get_field") bt_ctf_field_variant_get_field(struct bt_ctf_field *variant, struct bt_ctf_field *tag);
1364 %rename("_bt_ctf_field_enumeration_get_container") bt_ctf_field_enumeration_get_container(struct bt_ctf_field *enumeration);
1365 %rename("_bt_ctf_field_signed_integer_set_value") bt_ctf_field_signed_integer_set_value(struct bt_ctf_field *integer, int64_t value);
1366 %rename("_bt_ctf_field_unsigned_integer_set_value") bt_ctf_field_unsigned_integer_set_value(struct bt_ctf_field *integer, uint64_t value);
1367 %rename("_bt_ctf_field_floating_point_set_value") bt_ctf_field_floating_point_set_value(struct bt_ctf_field *floating_point, double value);
1368 %rename("_bt_ctf_field_string_set_value") bt_ctf_field_string_set_value(struct bt_ctf_field *string, const char *value);
1369 %rename("_bt_ctf_field_get") bt_ctf_field_get(struct bt_ctf_field *field);
1370 %rename("_bt_ctf_field_put") bt_ctf_field_put(struct bt_ctf_field *field);
1372 struct bt_ctf_field *bt_ctf_field_create(struct bt_ctf_field_type *type);
1373 struct bt_ctf_field *bt_ctf_field_structure_get_field(struct bt_ctf_field *structure, const char *name);
1374 struct bt_ctf_field *bt_ctf_field_array_get_field(struct bt_ctf_field *array, uint64_t index);
1375 int bt_ctf_field_sequence_set_length(struct bt_ctf_field *sequence, struct bt_ctf_field *length_field);
1376 struct bt_ctf_field *bt_ctf_field_sequence_get_field(struct bt_ctf_field *sequence, uint64_t index);
1377 struct bt_ctf_field *bt_ctf_field_variant_get_field(struct bt_ctf_field *variant, struct bt_ctf_field *tag);
1378 struct bt_ctf_field *bt_ctf_field_enumeration_get_container(struct bt_ctf_field *enumeration);
1379 int bt_ctf_field_signed_integer_set_value(struct bt_ctf_field *integer, int64_t value);
1380 int bt_ctf_field_unsigned_integer_set_value(struct bt_ctf_field *integer, uint64_t value);
1381 int bt_ctf_field_floating_point_set_value(struct bt_ctf_field *floating_point, double value);
1382 int bt_ctf_field_string_set_value(struct bt_ctf_field *string, const char *value);
1383 void bt_ctf_field_get(struct bt_ctf_field *field);
1384 void bt_ctf_field_put(struct bt_ctf_field *field);
1386 /* =================================================================
1388 ¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯
1390 %rename("_bt_ctf_event_class_create") bt_ctf_event_class_create(const char *name);
1391 %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);
1392 %rename("_bt_ctf_event_class_get") bt_ctf_event_class_get(struct bt_ctf_event_class *event_class);
1393 %rename("_bt_ctf_event_class_put") bt_ctf_event_class_put(struct bt_ctf_event_class *event_class);
1394 %rename("_bt_ctf_event_create") bt_ctf_event_create(struct bt_ctf_event_class *event_class);
1395 %rename("_bt_ctf_event_set_payload") bt_ctf_event_set_payload(struct bt_ctf_event *event, const char *name, struct bt_ctf_field *value);
1396 %rename("_bt_ctf_event_get_payload") bt_ctf_event_get_payload(struct bt_ctf_event *event, const char *name);
1397 %rename("_bt_ctf_event_get") bt_ctf_event_get(struct bt_ctf_event *event);
1398 %rename("_bt_ctf_event_put") bt_ctf_event_put(struct bt_ctf_event *event);
1400 struct bt_ctf_event_class *bt_ctf_event_class_create(const char *name);
1401 int bt_ctf_event_class_add_field(struct bt_ctf_event_class *event_class, struct bt_ctf_field_type *type, const char *name);
1402 void bt_ctf_event_class_get(struct bt_ctf_event_class *event_class);
1403 void bt_ctf_event_class_put(struct bt_ctf_event_class *event_class);
1404 struct bt_ctf_event *bt_ctf_event_create(struct bt_ctf_event_class *event_class);
1405 int bt_ctf_event_set_payload(struct bt_ctf_event *event, const char *name, struct bt_ctf_field *value);
1406 struct bt_ctf_field *bt_ctf_event_get_payload(struct bt_ctf_event *event, const char *name);
1407 void bt_ctf_event_get(struct bt_ctf_event *event);
1408 void bt_ctf_event_put(struct bt_ctf_event *event);
1410 /* =================================================================
1412 ¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯
1414 %rename("_bt_ctf_stream_class_create") bt_ctf_stream_class_create(const char *name);
1415 %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);
1416 %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);
1417 %rename("_bt_ctf_stream_class_get") bt_ctf_stream_class_get(struct bt_ctf_stream_class *stream_class);
1418 %rename("_bt_ctf_stream_class_put") bt_ctf_stream_class_put(struct bt_ctf_stream_class *stream_class);
1419 %rename("_bt_ctf_stream_append_discarded_events") bt_ctf_stream_append_discarded_events(struct bt_ctf_stream *stream, uint64_t event_count);
1420 %rename("_bt_ctf_stream_append_event") bt_ctf_stream_append_event(struct bt_ctf_stream *stream, struct bt_ctf_event *event);
1421 %rename("_bt_ctf_stream_flush") bt_ctf_stream_flush(struct bt_ctf_stream *stream);
1422 %rename("_bt_ctf_stream_get") bt_ctf_stream_get(struct bt_ctf_stream *stream);
1423 %rename("_bt_ctf_stream_put") bt_ctf_stream_put(struct bt_ctf_stream *stream);
1425 struct bt_ctf_stream_class *bt_ctf_stream_class_create(const char *name);
1426 int bt_ctf_stream_class_set_clock(struct bt_ctf_stream_class *stream_class, struct bt_ctf_clock *clock);
1427 int bt_ctf_stream_class_add_event_class(struct bt_ctf_stream_class *stream_class, struct bt_ctf_event_class *event_class);
1428 void bt_ctf_stream_class_get(struct bt_ctf_stream_class *stream_class);
1429 void bt_ctf_stream_class_put(struct bt_ctf_stream_class *stream_class);
1430 void bt_ctf_stream_append_discarded_events(struct bt_ctf_stream *stream, uint64_t event_count);
1431 int bt_ctf_stream_append_event(struct bt_ctf_stream *stream, struct bt_ctf_event *event);
1432 int bt_ctf_stream_flush(struct bt_ctf_stream *stream);
1433 void bt_ctf_stream_get(struct bt_ctf_stream *stream);
1434 void bt_ctf_stream_put(struct bt_ctf_stream *stream);
1436 /* =================================================================
1438 ¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯
1440 %rename("_bt_ctf_writer_create") bt_ctf_writer_create(const char *path);
1441 %rename("_bt_ctf_writer_create_stream") bt_ctf_writer_create_stream(struct bt_ctf_writer *writer, struct bt_ctf_stream_class *stream_class);
1442 %rename("_bt_ctf_writer_add_environment_field") bt_ctf_writer_add_environment_field(struct bt_ctf_writer *writer, const char *name, const char *value);
1443 %rename("_bt_ctf_writer_add_clock") bt_ctf_writer_add_clock(struct bt_ctf_writer *writer, struct bt_ctf_clock *clock);
1444 %newobject bt_ctf_writer_get_metadata_string;
1445 %rename("_bt_ctf_writer_get_metadata_string") bt_ctf_writer_get_metadata_string(struct bt_ctf_writer *writer);
1446 %rename("_bt_ctf_writer_flush_metadata") bt_ctf_writer_flush_metadata(struct bt_ctf_writer *writer);
1447 %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);
1448 %rename("_bt_ctf_writer_get") bt_ctf_writer_get(struct bt_ctf_writer *writer);
1449 %rename("_bt_ctf_writer_put") bt_ctf_writer_put(struct bt_ctf_writer *writer);
1451 struct bt_ctf_writer *bt_ctf_writer_create(const char *path);
1452 struct bt_ctf_stream *bt_ctf_writer_create_stream(struct bt_ctf_writer *writer, struct bt_ctf_stream_class *stream_class);
1453 int bt_ctf_writer_add_environment_field(struct bt_ctf_writer *writer, const char *name, const char *value);
1454 int bt_ctf_writer_add_clock(struct bt_ctf_writer *writer, struct bt_ctf_clock *clock);
1455 char *bt_ctf_writer_get_metadata_string(struct bt_ctf_writer *writer);
1456 void bt_ctf_writer_flush_metadata(struct bt_ctf_writer *writer);
1457 int bt_ctf_writer_set_byte_order(struct bt_ctf_writer *writer, enum bt_ctf_byte_order byte_order);
1458 void bt_ctf_writer_get(struct bt_ctf_writer *writer);
1459 void bt_ctf_writer_put(struct bt_ctf_writer *writer);
1466 def __init__(self, name):
1467 self._c = _bt_ctf_clock_create(name)
1469 raise ValueError("Invalid clock name.")
1472 _bt_ctf_clock_put(self._c)
1475 Get the clock's description.
1478 def description(self):
1479 raise NotImplementedError("Getter not implemented.")
1482 Set the clock's description. The description appears in the clock's TSDL
1486 def description(self, desc):
1487 ret = _bt_ctf_clock_set_description(self._c, str(desc))
1489 raise ValueError("Invalid clock description.")
1492 Get the clock's frequency (Hz).
1495 def frequency(self):
1496 raise NotImplementedError("Getter not implemented.")
1499 Set the clock's frequency (Hz).
1502 def frequency(self, freq):
1503 ret = _bt_ctf_clock_set_frequency(self._c, freq)
1505 raise ValueError("Invalid frequency value.")
1508 Get the clock's precision (in clock ticks).
1511 def precision(self):
1512 raise NotImplementedError("Getter not implemented.")
1515 Set the clock's precision (in clock ticks).
1518 def precision(self, precision):
1519 ret = _bt_ctf_clock_set_precision(self._c, precision)
1522 Get the clock's offset in seconds from POSIX.1 Epoch.
1525 def offset_seconds(self):
1526 raise NotImplementedError("Getter not implemented.")
1529 Set the clock's offset in seconds from POSIX.1 Epoch.
1531 @offset_seconds.setter
1532 def offset_seconds(self, offset_s):
1533 ret = _bt_ctf_clock_set_offset_s(self._c, offset_s)
1535 raise ValueError("Invalid offset value.")
1538 Get the clock's offset in ticks from POSIX.1 Epoch + offset in seconds.
1542 raise NotImplementedError("Getter not implemented.")
1545 Set the clock's offset in ticks from POSIX.1 Epoch + offset in seconds.
1548 def offset(self, offset):
1549 ret = _bt_ctf_clock_set_offset(self._c, offset)
1551 raise ValueError("Invalid offset value.")
1554 Get a clock's absolute attribute. A clock is absolute if the clock
1555 is a global reference across the trace's other clocks.
1559 raise NotImplementedError("Getter not implemented.")
1562 Set a clock's absolute attribute. A clock is absolute if the clock
1563 is a global reference across the trace's other clocks.
1566 def absolute(self, is_absolute):
1567 ret = _bt_ctf_clock_set_is_absolute(self._c, int(is_absolute))
1569 raise ValueError("Could not set the clock's absolute attribute.")
1572 Get the current time in nanoseconds since the clock's origin (offset and
1573 offset_s attributes).
1577 raise NotImplementedError("Getter not implemented.")
1580 Set the current time in nanoseconds since the clock's origin (offset and
1581 offset_s attributes). The clock's value will be sampled as events are
1582 appended to a stream.
1585 def time(self, time):
1586 ret = _bt_ctf_clock_set_time(self._c, time)
1588 raise ValueError("Invalid time value.")
1590 class FieldDeclaration:
1592 FieldDeclaration should not be instantiated directly. Please instantiate
1593 one of the concrete FieldDeclaration classes.
1596 # These values are based on the bt_ctf_integer_base enum
1597 # declared in event-types.h.
1598 INTEGER_BASE_UNKNOWN = -1
1599 INTEGER_BASE_BINARY = 2
1600 INTEGER_BASE_OCTAL = 8
1601 INTEGER_BASE_DECIMAL = 10
1602 INTEGER_BASE_HEXADECIMAL = 16
1605 if self._ft is None:
1606 raise ValueError("FieldDeclaration creation failed.")
1609 _bt_ctf_field_type_put(self._ft)
1612 Get the field type's alignment.
1615 def alignment(self):
1616 raise NotImplementedError("Getter not implemented.")
1619 Set the field type's alignment. Defaults to 1 (bit-aligned). However,
1620 some types, such as structures and string, may impose other alignment
1624 def alignment(self, alignment):
1625 ret = _bt_ctf_field_type_set_alignment(self._ft, alignment)
1627 raise ValueError("Invalid alignment value.")
1630 Get the field type's byte order. One of the ByteOrder's constant.
1633 def byte_order(self):
1634 raise NotImplementedError("Getter not implemented.")
1637 Set the field type's byte order. Use constants defined in the ByteOrder
1641 def byte_order(self, byte_order):
1642 ret = _bt_ctf_field_type_set_byte_order(self._ft, byte_order)
1644 raise ValueError("Could not set byte order value.")
1646 class IntegerFieldDeclaration(FieldDeclaration):
1648 Create a new integer field type of the given size.
1650 def __init__(self, size):
1651 self._ft = _bt_ctf_field_type_integer_create(size)
1655 Get an integer's signedness attribute.
1659 raise NotImplementedError("Getter not implemented.")
1662 Set an integer's signedness attribute.
1665 def signed(self, signed):
1666 ret = _bt_ctf_field_type_integer_set_signed(self._ft, signed)
1668 raise ValueError("Could not set signed attribute.")
1671 Get the integer's base used to pretty-print the resulting trace.
1675 raise NotImplementedError("Getter not implemented.")
1678 Set the integer's base used to pretty-print the resulting trace.
1679 The base must be a constant of the IntegerBase class.
1682 def base(self, base):
1683 ret = _bt_ctf_field_type_integer_set_base(self._ft, base)
1685 raise ValueError("Could not set base value.")
1688 Get the integer's encoding (one of the constants of the
1689 CTFStringEncoding class).
1693 raise NotImplementedError("Getter not implemented.")
1696 An integer encoding may be set to signal that the integer must be printed
1697 as a text character. Must be a constant from the CTFStringEncoding class.
1700 def encoding(self, encoding):
1701 ret = _bt_ctf_field_type_integer_set_encoding(self._ft, encoding)
1703 raise ValueError("Could not set integer encoding.")
1705 class EnumerationFieldDeclaration(FieldDeclaration):
1707 Create a new enumeration field type with the given underlying type.
1709 def __init__(self, integer_type):
1710 if integer_type is None or not isinstance(integer_type, CTFWriter.IntegerFieldDeclaration):
1711 raise TypeError("Invalid integer container.")
1713 self._ft = _bt_ctf_field_type_enumeration_create(integer_type._ft)
1717 Add a mapping to the enumeration. The range's values are inclusive.
1719 def add_mapping(self, name, range_start, range_end):
1720 ret = _bt_ctf_field_type_enumeration_add_mapping(self._ft, str(name), range_start, range_end)
1722 raise ValueError("Could not add mapping to enumeration type.")
1724 class FloatFieldDeclaration(FieldDeclaration):
1731 Create a new floating point field type.
1734 self._ft = _bt_ctf_field_type_floating_point_create()
1738 Get the number of exponent digits to use to store the floating point field.
1741 def exponent_digits(self):
1742 raise NotImplementedError("Getter not implemented.")
1745 Set the number of exponent digits to use to store the floating point field.
1746 The only values currently supported are FLT_EXP_DIG and DBL_EXP_DIG which
1747 are defined as constants of this class.
1749 @exponent_digits.setter
1750 def exponent_digits(self, exponent_digits):
1751 ret = _bt_ctf_field_type_floating_point_set_exponent_digits(self._ft, exponent_digits)
1753 raise ValueError("Could not set exponent digit count.")
1756 Get the number of mantissa digits to use to store the floating point field.
1759 def mantissa_digits(self):
1760 raise NotImplementedError("Getter not implemented.")
1763 Set the number of mantissa digits to use to store the floating point field.
1764 The only values currently supported are FLT_MANT_DIG and DBL_MANT_DIG which
1765 are defined as constants of this class.
1767 @mantissa_digits.setter
1768 def mantissa_digits(self, mantissa_digits):
1769 ret = _bt_ctf_field_type_floating_point_set_mantissa_digits(self._ft, mantissa_digits)
1771 raise ValueError("Could not set mantissa digit count.")
1773 class StructureFieldDeclaration(FieldDeclaration):
1775 Create a new structure field type.
1778 self._ft = _bt_ctf_field_type_structure_create()
1782 Add a field of type "field_type" to the structure.
1784 def add_field(self, field_type, field_name):
1785 ret = _bt_ctf_field_type_structure_add_field(self._ft, field_type._ft, str(field_name))
1787 raise ValueError("Could not add field to structure.")
1789 class VariantFieldDeclaration(FieldDeclaration):
1791 Create a new variant field type.
1793 def __init__(self, enum_tag, tag_name):
1794 if enum_tag is None or not isinstance(enum_tag, CTFWriter.EnumerationFieldDeclaration):
1795 raise TypeError("Invalid tag type; must be of type EnumerationFieldDeclaration.")
1797 self._ft = _bt_ctf_field_type_variant_create(enum_tag._ft, str(tag_name))
1801 Add a field of type "field_type" to the variant.
1803 def add_field(self, field_type, field_name):
1804 ret = _bt_ctf_field_type_variant_add_field(self._ft, field_type._ft, str(field_name))
1806 raise ValueError("Could not add field to variant.")
1808 class ArrayFieldDeclaration(FieldDeclaration):
1810 Create a new array field type.
1812 def __init__(self, element_type, length):
1813 self._ft = _bt_ctf_field_type_array_create(element_type._ft, length)
1816 class SequenceFieldDeclaration(FieldDeclaration):
1818 Create a new sequence field type.
1820 def __init__(self, element_type, length_field_name):
1821 self._ft = _bt_ctf_field_type_sequence_create(element_type._ft, str(length_field_name))
1824 class StringFieldDeclaration(FieldDeclaration):
1826 Create a new string field type.
1829 self._ft = _bt_ctf_field_type_string_create()
1833 Get a string type's encoding (a constant from the CTFStringEncoding class).
1837 raise NotImplementedError("Getter not implemented.")
1840 Set a string type's encoding. Must be a constant from the CTFStringEncoding class.
1843 def encoding(self, encoding):
1844 ret = _bt_ctf_field_type_string_set_encoding(self._ft, encoding)
1846 raise ValueError("Could not set string encoding.")
1849 Create an instance of a field.
1852 def create_field(self, field_type):
1853 if field_type is None or not isinstance(field_type, CTFWriter.FieldDeclaration):
1854 raise TypeError("Invalid field_type. Type must be a FieldDeclaration-derived class.")
1856 if isinstance(field_type, CTFWriter.IntegerFieldDeclaration):
1857 return CTFWriter.IntegerField(field_type)
1858 elif isinstance(field_type, CTFWriter.EnumerationFieldDeclaration):
1859 return CTFWriter.EnumerationField(field_type)
1860 elif isinstance(field_type, CTFWriter.FloatFieldDeclaration):
1861 return CTFWriter.FloatFieldingPoint(field_type)
1862 elif isinstance(field_type, CTFWriter.StructureFieldDeclaration):
1863 return CTFWriter.StructureField(field_type)
1864 elif isinstance(field_type, CTFWriter.VariantFieldDeclaration):
1865 return CTFWriter.VariantField(field_type)
1866 elif isinstance(field_type, CTFWriter.ArrayFieldDeclaration):
1867 return CTFWriter.ArrayField(field_type)
1868 elif isinstance(field_type, CTFWriter.SequenceFieldDeclaration):
1869 return CTFWriter.SequenceField(field_type)
1870 elif isinstance(field_type, CTFWriter.StringFieldDeclaration):
1871 return CTFWriter.StringField(field_type)
1875 Base class, do not instantiate.
1877 def __init__(self, field_type):
1878 if not isinstance(field_type, CTFWriter.FieldDeclaration):
1879 raise TypeError("Invalid field_type argument.")
1881 self._f = _bt_ctf_field_create(field_type._ft)
1883 raise ValueError("Field creation failed.")
1886 _bt_ctf_field_put(self._f)
1889 def _create_field_from_native_instance(native_field_instance):
1891 CTFTypeId.INTEGER : CTFWriter.IntegerField,
1892 CTFTypeId.FLOAT : CTFWriter.FloatFieldingPoint,
1893 CTFTypeId.ENUM : CTFWriter.EnumerationField,
1894 CTFTypeId.STRING : CTFWriter.StringField,
1895 CTFTypeId.STRUCT : CTFWriter.StructureField,
1896 CTFTypeId.VARIANT : CTFWriter.VariantField,
1897 CTFTypeId.ARRAY : CTFWriter.ArrayField,
1898 CTFTypeId.SEQUENCE : CTFWriter.SequenceField
1901 field_type = _bt_python_get_field_type(native_field_instance)
1902 if field_type == CTFTypeId.UNKNOWN:
1903 raise TypeError("Invalid field instance")
1905 field = CTFWriter.Field.__new__(CTFWriter.Field)
1906 field._f = native_field_instance
1907 field.__class__ = type_dict[field_type]
1910 class IntegerField(Field):
1912 Get an integer field's value.
1916 raise NotImplementedError("Getter not implemented.")
1919 Set an integer field's value.
1922 def value(self, value):
1923 signedness = _bt_python_field_integer_get_signedness(self._f)
1925 raise TypeError("Invalid integer instance.")
1928 ret = _bt_ctf_field_unsigned_integer_set_value(self._f, value)
1930 ret = _bt_ctf_field_signed_integer_set_value(self._f, value)
1933 raise ValueError("Could not set integer field value.")
1935 class EnumerationField(Field):
1937 Return the enumeration's underlying container field (an integer field).
1940 def container(self):
1941 container = CTFWriter.IntegerField.__new__(CTFWriter.IntegerField)
1942 container._f = _bt_ctf_field_enumeration_get_container(self._f)
1943 if container._f is None:
1944 raise TypeError("Invalid enumeration field type.")
1947 class FloatFieldingPoint(Field):
1949 Get a floating point field's value.
1953 raise NotImplementedError("Getter not implemented.")
1956 Set a floating point field's value.
1959 def value(self, value):
1960 ret = _bt_ctf_field_floating_point_set_value(self._f, float(value))
1962 raise ValueError("Could not set floating point field value.")
1964 class StructureField(Field):
1966 Get the structure's field corresponding to the provided field name.
1968 def field(self, field_name):
1969 native_instance = _bt_ctf_field_structure_get_field(self._f, str(field_name))
1970 if native_instance is None:
1971 raise ValueError("Invalid field_name provided.")
1972 return CTFWriter.Field._create_field_from_native_instance(native_instance)
1974 class VariantField(Field):
1976 Return the variant's selected field. The "tag" field is the selector enum field.
1978 def field(self, tag):
1979 native_instance = _bt_ctf_field_variant_get_field(self._f, tag._f)
1980 if native_instance is None:
1981 raise ValueError("Invalid tag provided.")
1982 return CTFWriter.Field._create_field_from_native_instance(native_instance)
1984 class ArrayField(Field):
1986 Return the array's field at position "index".
1988 def field(self, index):
1989 native_instance = _bt_ctf_field_array_get_field(self._f, index)
1990 if native_instance is None:
1991 raise IndexError("Invalid index provided.")
1992 return CTFWriter.Field._create_field_from_native_instance(native_instance)
1994 class SequenceField(Field):
1996 Get the sequence's length field (IntegerField).
2000 raise NotImplementedError("Getter not implemented.")
2003 Set the sequence's length field (IntegerField).
2006 def length(self, length_field):
2007 if not isinstance(length_field, CTFWriter.IntegerField):
2008 raise TypeError("Invalid length field.")
2009 ret = _bt_ctf_field_sequence_set_length(self._f, length_field._f)
2011 raise ValueError("Could not set sequence length.")
2014 Return the sequence's field at position "index".
2016 def field(self, index):
2017 native_instance = _bt_ctf_field_sequence_get_field(self._f, index)
2018 if native_instance is None:
2019 raise ValueError("Could not get sequence element at index.")
2020 return CTFWriter.Field._create_field_from_native_instance(native_instance)
2022 class StringField(Field):
2024 Get a string field's value.
2028 raise NotImplementedError("Getter not implemented.")
2031 Set a string field's value.
2034 def value(self, value):
2035 ret = _bt_ctf_field_string_set_value(self._f, str(value))
2037 raise ValueError("Could not set string field value.")
2041 Create a new event class of the given name.
2043 def __init__(self, name):
2044 self._ec = _bt_ctf_event_class_create(name)
2045 if self._ec is None:
2046 raise ValueError("Event class creation failed.")
2049 _bt_ctf_event_class_put(self._ec)
2052 Add a field of type "field_type" to the event class.
2054 def add_field(self, field_type, field_name):
2055 ret = _bt_ctf_event_class_add_field(self._ec, field_type._ft, str(field_name))
2057 raise ValueError("Could not add field to event class.")
2061 Create a new event of the given event class.
2063 def __init__(self, event_class):
2064 if not isinstance(event_class, CTFWriter.EventClass):
2065 raise TypeError("Invalid event_class argument.")
2067 self._e = _bt_ctf_event_create(event_class._ec)
2069 raise ValueError("Event creation failed.")
2072 _bt_ctf_event_put(self._e)
2075 Set a manually created field as an event's payload.
2077 def set_payload(self, field_name, value_field):
2078 if not isinstance(value, CTFWriter.Field):
2079 raise TypeError("Invalid value type.")
2080 ret = _bt_ctf_event_set_payload(self._e, str(field_name), value_field._f)
2082 raise ValueError("Could not set event field payload.")
2085 Get a field from event.
2087 def payload(self, field_name):
2088 native_instance = _bt_ctf_event_get_payload(self._e, str(field_name))
2089 if native_instance is None:
2090 raise ValueError("Could not get event payload.")
2091 return CTFWriter.Field._create_field_from_native_instance(native_instance)
2095 Create a new stream class of the given name.
2097 def __init__(self, name):
2098 self._sc = _bt_ctf_stream_class_create(name)
2099 if self._sc is None:
2100 raise ValueError("Stream class creation failed.")
2103 _bt_ctf_stream_class_put(self._sc)
2106 Get a stream class' clock.
2110 raise NotImplementedError("Getter not implemented.")
2113 Assign a clock to a stream class.
2116 def clock(self, clock):
2117 if not isinstance(clock, CTFWriter.Clock):
2118 raise TypeError("Invalid clock type.")
2120 ret = _bt_ctf_stream_class_set_clock(self._sc, clock._c)
2122 raise ValueError("Could not set stream class clock.")
2125 Add an event class to a stream class. New events can be added even after a
2126 stream has been instantiated and events have been appended. However, a stream
2127 will not accept events of a class that has not been registered beforehand.
2129 def add_event_class(self, event_class):
2130 if not isinstance(event_class, CTFWriter.EventClass):
2131 raise TypeError("Invalid event_class type.")
2133 ret = _bt_ctf_stream_class_add_event_class(self._sc, event_class._ec)
2135 raise ValueError("Could not add event class.")
2139 Create a stream of the given class.
2141 def __init__(self, stream_class):
2142 if not isinstance(stream_class, CTFWriter.StreamClass):
2143 raise TypeError("Invalid stream_class type.")
2145 self._s = _bt_ctf_stream_create(stream_class._sc)
2147 raise ValueError("Stream creation failed.")
2150 _bt_ctf_stream_put(self._s)
2153 Increase the current packet's discarded event count.
2155 def append_discarded_events(self, event_count):
2156 _bt_ctf_stream_append_discarded_events(self._s, event_count)
2159 Append "event" to the stream's current packet. The stream's associated clock
2160 will be sampled during this call. The event shall not be modified after
2161 being appended to a stream.
2163 def append_event(self, event):
2164 ret = _bt_ctf_stream_append_event(self._s, event._e)
2166 raise ValueError("Could not append event to stream.")
2169 The stream's current packet's events will be flushed to disk. Events
2170 subsequently appended to the stream will be added to a new packet.
2173 ret = _bt_ctf_stream_flush(self._s)
2175 raise ValueError("Could not flush stream.")
2179 Create a new writer that will produce a trace in the given path.
2181 def __init__(self, path):
2182 self._w = _bt_ctf_writer_create(path)
2184 raise ValueError("Writer creation failed.")
2187 _bt_ctf_writer_put(self._w)
2190 Create a new stream instance and register it to the writer.
2192 def create_stream(self, stream_class):
2193 if not isinstance(stream_class, CTFWriter.StreamClass):
2194 raise TypeError("Invalid stream_class type.")
2196 stream = CTFWriter.Stream.__new__(CTFWriter.Stream)
2197 stream._s = _bt_ctf_writer_create_stream(self._w, stream_class._sc)
2201 Add an environment field to the trace.
2203 def add_environment_field(self, name, value):
2204 ret = _bt_ctf_writer_add_environment_field(self._w, str(name), str(value))
2206 raise ValueError("Could not add environment field to trace.")
2209 Add a clock to the trace. Clocks assigned to stream classes must be
2210 registered to the writer.
2212 def add_clock(self, clock):
2213 ret = _bt_ctf_writer_add_clock(self._w, clock._c)
2215 raise ValueError("Could not add clock to Writer.")
2218 Get the trace's TSDL meta-data.
2222 return _bt_ctf_writer_get_metadata_string(self._w)
2225 Flush the trace's metadata to the metadata file.
2227 def flush_metadata(self):
2228 _bt_ctf_writer_flush_metadata(self._w)
2231 Get the trace's byte order. Must be a constant from the ByteOrder
2235 def byte_order(self):
2236 raise NotImplementedError("Getter not implemented.")
2239 Set the trace's byte order. Must be a constant from the ByteOrder
2240 class. Defaults to BYTE_ORDER_NATIVE, the host machine's endianness.
2243 def byte_order(self, byte_order):
2244 ret = _bt_ctf_writer_set_byte_order(self._w, byte_order)
2246 raise ValueError("Could not set trace's byte order.")