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 const char *_bt_python_get_array_string(struct bt_definition *field);
97 int _bt_python_field_integer_get_signedness(const struct bt_ctf_field *field);
98 enum ctf_type_id _bt_python_get_field_type(const struct bt_ctf_field *field);
100 /* =================================================================
101 CONTEXT.H, CONTEXT-INTERNAL.H
102 ¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯
105 %rename("_bt_context_create") bt_context_create(void);
106 %rename("_bt_context_add_trace") bt_context_add_trace(
107 struct bt_context *ctx, const char *path, const char *format,
108 void (*packet_seek)(struct bt_stream_pos *pos, size_t index, int whence),
109 struct bt_mmap_stream_list *stream_list, FILE *metadata);
110 %rename("_bt_context_remove_trace") bt_context_remove_trace(
111 struct bt_context *ctx, int trace_id);
112 %rename("_bt_context_get") bt_context_get(struct bt_context *ctx);
113 %rename("_bt_context_put") bt_context_put(struct bt_context *ctx);
114 %rename("_bt_ctf_event_get_context") bt_ctf_event_get_context(
115 const struct bt_ctf_event *event);
117 struct bt_context *bt_context_create(void);
118 int bt_context_add_trace(struct bt_context *ctx, const char *path, const char *format,
119 void (*packet_seek)(struct bt_stream_pos *pos, size_t index, int whence),
120 struct bt_mmap_stream_list *stream_list, FILE *metadata);
121 void bt_context_remove_trace(struct bt_context *ctx, int trace_id);
122 void bt_context_get(struct bt_context *ctx);
123 void bt_context_put(struct bt_context *ctx);
124 struct bt_context *bt_ctf_event_get_context(const struct bt_ctf_event *event);
126 // class TraceCollection to prevent direct access to struct bt_context
128 class TraceCollection:
130 The TraceCollection is the object that contains all currently opened traces.
134 self._tc = _bt_context_create()
137 _bt_context_put(self._tc)
139 def add_trace(self, path, format_str):
141 Add a trace by path to the TraceCollection.
145 path is the path to the trace, it is not recursive.
146 If "path" is None, stream_list is used instead as a list
147 of mmap streams to open for the trace.
149 format is a string containing the format name in which the trace was
152 Return: the corresponding TraceHandle on success or None on error.
154 ret = _bt_context_add_trace(self._tc, path, format_str, None, None, None)
158 th = TraceHandle.__new__(TraceHandle)
160 th._trace_collection = self
163 def add_traces_recursive(self, path, format_str):
165 Open a trace recursively.
167 Find each trace present in the subdirectory starting from the given
168 path, and add them to the TraceCollection.
170 Return a dict of TraceHandle instances (the full path is the key).
171 Return None on error.
181 for fullpath, dirs, files in os.walk(path):
182 if "metadata" in files:
183 trace_handle = self.add_trace(fullpath, format_str)
184 if trace_handle is None:
188 trace_handles[fullpath] = trace_handle
191 if noTrace and error:
195 def remove_trace(self, trace_handle):
197 Remove a trace from the TraceCollection.
198 Effectively closing the trace.
201 _bt_context_remove_trace(self._tc, trace_handle._id)
202 except AttributeError:
203 raise TypeError("in remove_trace, "
204 "argument 2 must be a TraceHandle instance")
209 Generator function to iterate over the events of open in the current
212 begin_pos_ptr = _bt_iter_pos()
213 end_pos_ptr = _bt_iter_pos()
214 begin_pos_ptr.type = SEEK_BEGIN
215 end_pos_ptr.type = SEEK_LAST
217 for event in self._events(begin_pos_ptr, end_pos_ptr):
220 def events_timestamps(self, timestamp_begin, timestamp_end):
222 Generator function to iterate over the events of open in the current
223 TraceCollection from timestamp_begin to timestamp_end.
225 begin_pos_ptr = _bt_iter_pos()
226 end_pos_ptr = _bt_iter_pos()
227 begin_pos_ptr.type = end_pos_ptr.type = SEEK_TIME
228 begin_pos_ptr.u.seek_time = timestamp_begin
229 end_pos_ptr.u.seek_time = timestamp_end
231 for event in self._events(begin_pos_ptr, end_pos_ptr):
235 def timestamp_begin(self):
236 pos_ptr = _bt_iter_pos()
237 pos_ptr.type = SEEK_BEGIN
238 return self._timestamp_at_pos(pos_ptr)
241 def timestamp_end(self):
242 pos_ptr = _bt_iter_pos()
243 pos_ptr.type = SEEK_LAST
244 return self._timestamp_at_pos(pos_ptr)
246 def _timestamp_at_pos(self, pos_ptr):
247 ctf_it_ptr = _bt_ctf_iter_create(self._tc, pos_ptr, pos_ptr)
248 if ctf_it_ptr is None:
249 raise NotImplementedError("Creation of multiple iterators is unsupported.")
250 ev_ptr = _bt_ctf_iter_read_event(ctf_it_ptr)
251 _bt_ctf_iter_destroy(ctf_it_ptr)
255 def _events(self, begin_pos_ptr, end_pos_ptr):
256 ctf_it_ptr = _bt_ctf_iter_create(self._tc, begin_pos_ptr, end_pos_ptr)
257 if ctf_it_ptr is None:
258 raise NotImplementedError(
259 "Creation of multiple iterators is unsupported.")
262 ev_ptr = _bt_ctf_iter_read_event(ctf_it_ptr)
266 ev = Event.__new__(Event)
270 except GeneratorExit:
273 ret = _bt_iter_next(_bt_ctf_get_iter(ctf_it_ptr))
277 _bt_ctf_iter_destroy(ctf_it_ptr)
283 /* =================================================================
288 %rename("lookup_format") bt_lookup_format(bt_intern_str qname);
289 %rename("_bt_print_format_list") bt_fprintf_format_list(FILE *fp);
290 %rename("register_format") bt_register_format(struct format *format);
291 %rename("unregister_format") bt_unregister_format(struct bt_format *format);
293 extern struct format *bt_lookup_format(bt_intern_str qname);
294 extern void bt_fprintf_format_list(FILE *fp);
295 extern int bt_register_format(struct bt_format *format);
296 extern void bt_unregister_format(struct bt_format *format);
300 def print_format_list(babeltrace_file):
302 Print a list of available formats to file.
304 babeltrace_file must be a File instance opened in write mode.
307 if babeltrace_file._file is not None:
308 _bt_print_format_list(babeltrace_file._file)
309 except AttributeError:
310 raise TypeError("in print_format_list, "
311 "argument 1 must be a File instance")
316 /* =================================================================
317 ITERATOR.H, ITERATOR-INTERNAL.H
318 ¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯
321 %rename("_bt_iter_create") bt_iter_create(struct bt_context *ctx,
322 const struct bt_iter_pos *begin_pos, const struct bt_iter_pos *end_pos);
323 %rename("_bt_iter_destroy") bt_iter_destroy(struct bt_iter *iter);
324 %rename("_bt_iter_next") bt_iter_next(struct bt_iter *iter);
325 %rename("_bt_iter_get_pos") bt_iter_get_pos(struct bt_iter *iter);
326 %rename("_bt_iter_free_pos") bt_iter_free_pos(struct bt_iter_pos *pos);
327 %rename("_bt_iter_set_pos") bt_iter_set_pos(struct bt_iter *iter,
328 const struct bt_iter_pos *pos);
329 %rename("_bt_iter_create_time_pos") bt_iter_create_time_pos(struct bt_iter *iter,
332 struct bt_iter *bt_iter_create(struct bt_context *ctx,
333 const struct bt_iter_pos *begin_pos, const struct bt_iter_pos *end_pos);
334 void bt_iter_destroy(struct bt_iter *iter);
335 int bt_iter_next(struct bt_iter *iter);
336 struct bt_iter_pos *bt_iter_get_pos(struct bt_iter *iter);
337 void bt_iter_free_pos(struct bt_iter_pos *pos);
338 int bt_iter_set_pos(struct bt_iter *iter, const struct bt_iter_pos *pos);
339 struct bt_iter_pos *bt_iter_create_time_pos(struct bt_iter *iter, uint64_t timestamp);
341 %rename("_bt_iter_pos") bt_iter_pos;
342 %rename("SEEK_TIME") BT_SEEK_TIME;
343 %rename("SEEK_RESTORE") BT_SEEK_RESTORE;
344 %rename("SEEK_CUR") BT_SEEK_CUR;
345 %rename("SEEK_BEGIN") BT_SEEK_BEGIN;
346 %rename("SEEK_LAST") BT_SEEK_LAST;
348 // This struct is taken from iterator.h
349 // All changes to the struct must also be made here
352 BT_SEEK_TIME, /* uses u.seek_time */
353 BT_SEEK_RESTORE, /* uses u.restore */
360 struct bt_saved_pos *restore;
364 /* =================================================================
365 TRACE-HANDLE.H, TRACE-HANDLE-INTERNAL.H
366 ¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯
369 %rename("_bt_trace_handle_create") bt_trace_handle_create(struct bt_context *ctx);
370 %rename("_bt_trace_handle_destroy") bt_trace_handle_destroy(struct bt_trace_handle *bt);
371 struct bt_trace_handle *bt_trace_handle_create(struct bt_context *ctx);
372 void bt_trace_handle_destroy(struct bt_trace_handle *bt);
374 %rename("_bt_trace_handle_get_path") bt_trace_handle_get_path(struct bt_context *ctx,
376 %rename("_bt_trace_handle_get_timestamp_begin") bt_trace_handle_get_timestamp_begin(
377 struct bt_context *ctx, int handle_id, enum bt_clock_type type);
378 %rename("_bt_trace_handle_get_timestamp_end") bt_trace_handle_get_timestamp_end(
379 struct bt_context *ctx, int handle_id, enum bt_clock_type type);
380 const char *bt_trace_handle_get_path(struct bt_context *ctx, int handle_id);
381 uint64_t bt_trace_handle_get_timestamp_begin(struct bt_context *ctx, int handle_id,
382 enum bt_clock_type type);
383 uint64_t bt_trace_handle_get_timestamp_end(struct bt_context *ctx, int handle_id,
384 enum bt_clock_type type);
386 %rename("_bt_ctf_event_get_handle_id") bt_ctf_event_get_handle_id(
387 const struct bt_ctf_event *event);
388 int bt_ctf_event_get_handle_id(const struct bt_ctf_event *event);
393 # Based on enum bt_clock_type in clock-type.h
398 class TraceHandle(object):
400 The TraceHandle allows the user to manipulate a trace file directly.
401 It is a unique identifier representing a trace file.
406 raise NotImplementedError("TraceHandle cannot be instantiated")
409 return "Babeltrace TraceHandle: trace_id('{0}')".format(self._id)
413 """Return the TraceHandle id."""
418 """Return the path of a TraceHandle."""
419 return _bt_trace_handle_get_path(self._trace_collection._tc, self._id)
422 def timestamp_begin(self):
423 """Return the creation time of the buffers of a trace."""
424 return _bt_trace_handle_get_timestamp_begin(
425 self._trace_collection._tc, self._id, ClockType.CLOCK_REAL)
428 def timestamp_end(self):
429 """Return the destruction timestamp of the buffers of a trace."""
430 return _bt_trace_handle_get_timestamp_end(
431 self._trace_collection._tc, self._id, ClockType.CLOCK_REAL)
436 Generator returning all events (EventDeclaration) in a trace.
438 ret = _bt_python_event_decl_listcaller(self.id, self._trace_collection._tc)
440 if not isinstance(ret, list):
443 ptr_list, count = ret
444 for i in range(count):
445 tmp = EventDeclaration.__new__(EventDeclaration)
446 tmp._ed = _bt_python_decl_one_from_list(ptr_list, i)
453 // =================================================================
455 // =================================================================
457 /* =================================================================
463 %rename("_bt_ctf_iter_create") bt_ctf_iter_create(struct bt_context *ctx,
464 const struct bt_iter_pos *begin_pos,
465 const struct bt_iter_pos *end_pos);
466 %rename("_bt_ctf_get_iter") bt_ctf_get_iter(struct bt_ctf_iter *iter);
467 %rename("_bt_ctf_iter_destroy") bt_ctf_iter_destroy(struct bt_ctf_iter *iter);
468 %rename("_bt_ctf_iter_read_event") bt_ctf_iter_read_event(struct bt_ctf_iter *iter);
470 struct bt_ctf_iter *bt_ctf_iter_create(struct bt_context *ctx,
471 const struct bt_iter_pos *begin_pos,
472 const struct bt_iter_pos *end_pos);
473 struct bt_iter *bt_ctf_get_iter(struct bt_ctf_iter *iter);
474 void bt_ctf_iter_destroy(struct bt_ctf_iter *iter);
475 struct bt_ctf_event *bt_ctf_iter_read_event(struct bt_ctf_iter *iter);
479 %rename("_bt_ctf_get_top_level_scope") bt_ctf_get_top_level_scope(const struct
480 bt_ctf_event *event, enum bt_ctf_scope scope);
481 %rename("_bt_ctf_event_name") bt_ctf_event_name(const struct bt_ctf_event *ctf_event);
482 %rename("_bt_ctf_get_timestamp") bt_ctf_get_timestamp(
483 const struct bt_ctf_event *ctf_event);
484 %rename("_bt_ctf_get_cycles") bt_ctf_get_cycles(
485 const struct bt_ctf_event *ctf_event);
487 %rename("_bt_ctf_get_field") bt_ctf_get_field(const struct bt_ctf_event *ctf_event,
488 const struct bt_definition *scope, const char *field);
489 %rename("_bt_ctf_get_index") bt_ctf_get_index(const struct bt_ctf_event *ctf_event,
490 const struct bt_definition *field, unsigned int index);
491 %rename("_bt_ctf_field_name") bt_ctf_field_name(const struct bt_definition *field);
492 %rename("_bt_ctf_field_type") bt_ctf_field_type(const struct bt_declaration *field);
493 %rename("_bt_ctf_get_int_signedness") bt_ctf_get_int_signedness(
494 const struct bt_declaration *field);
495 %rename("_bt_ctf_get_int_base") bt_ctf_get_int_base(const struct bt_declaration *field);
496 %rename("_bt_ctf_get_int_byte_order") bt_ctf_get_int_byte_order(
497 const struct bt_declaration *field);
498 %rename("_bt_ctf_get_int_len") bt_ctf_get_int_len(const struct bt_declaration *field);
499 %rename("_bt_ctf_get_enum_int") bt_ctf_get_enum_int(const struct bt_definition *field);
500 %rename("_bt_ctf_get_enum_str") bt_ctf_get_enum_str(const struct bt_definition *field);
501 %rename("_bt_ctf_get_encoding") bt_ctf_get_encoding(const struct bt_declaration *field);
502 %rename("_bt_ctf_get_array_len") bt_ctf_get_array_len(const struct bt_declaration *field);
503 %rename("_bt_ctf_get_uint64") bt_ctf_get_uint64(const struct bt_definition *field);
504 %rename("_bt_ctf_get_int64") bt_ctf_get_int64(const struct bt_definition *field);
505 %rename("_bt_ctf_get_char_array") bt_ctf_get_char_array(const struct bt_definition *field);
506 %rename("_bt_ctf_get_string") bt_ctf_get_string(const struct bt_definition *field);
507 %rename("_bt_ctf_get_float") bt_ctf_get_float(const struct bt_definition *field);
508 %rename("_bt_ctf_get_variant") bt_ctf_get_variant(const struct bt_definition *field);
509 %rename("_bt_ctf_field_get_error") bt_ctf_field_get_error(void);
510 %rename("_bt_ctf_get_decl_event_name") bt_ctf_get_decl_event_name(const struct
511 bt_ctf_event_decl *event);
512 %rename("_bt_ctf_get_decl_field_name") bt_ctf_get_decl_field_name(
513 const struct bt_ctf_field_decl *field);
514 %rename("_bt_ctf_get_decl_from_def") bt_ctf_get_decl_from_def(
515 const struct bt_definition *field);
516 %rename("_bt_ctf_get_decl_from_field_decl") bt_ctf_get_decl_from_field_decl(
517 const struct bt_ctf_field_decl *field);
518 %rename("_bt_array_index") bt_array_index(struct definition_array *array, uint64_t i);
519 %rename("_bt_sequence_len") bt_sequence_len(struct definition_sequence *sequence);
520 %rename("_bt_sequence_index") bt_sequence_index(struct definition_sequence *sequence, uint64_t i);
521 %rename("_bt_ctf_get_struct_field_count") bt_ctf_get_struct_field_count(const struct bt_definition *structure);
522 %rename("_bt_ctf_get_struct_field_index") bt_ctf_get_struct_field_index(const struct bt_definition *structure, uint64_t i);
524 const struct bt_definition *bt_ctf_get_top_level_scope(const struct bt_ctf_event *ctf_event,
525 enum bt_ctf_scope scope);
526 const char *bt_ctf_event_name(const struct bt_ctf_event *ctf_event);
527 uint64_t bt_ctf_get_timestamp(const struct bt_ctf_event *ctf_event);
528 uint64_t bt_ctf_get_cycles(const struct bt_ctf_event *ctf_event);
529 const struct bt_definition *bt_ctf_get_field(const struct bt_ctf_event *ctf_event,
530 const struct bt_definition *scope,
532 const struct bt_definition *bt_ctf_get_index(const struct bt_ctf_event *ctf_event,
533 const struct bt_definition *field,
535 const char *bt_ctf_field_name(const struct bt_definition *field);
536 enum ctf_type_id bt_ctf_field_type(const struct bt_declaration *field);
537 int bt_ctf_get_int_signedness(const struct bt_declaration *field);
538 int bt_ctf_get_int_base(const struct bt_declaration *field);
539 int bt_ctf_get_int_byte_order(const struct bt_declaration *field);
540 ssize_t bt_ctf_get_int_len(const struct bt_declaration *field);
541 const struct bt_definition *bt_ctf_get_enum_int(const struct bt_definition *field);
542 const char *bt_ctf_get_enum_str(const struct bt_definition *field);
543 enum ctf_string_encoding bt_ctf_get_encoding(const struct bt_declaration *field);
544 int bt_ctf_get_array_len(const struct bt_declaration *field);
545 struct bt_definition *bt_array_index(struct definition_array *array, uint64_t i);
546 uint64_t bt_ctf_get_uint64(const struct bt_definition *field);
547 int64_t bt_ctf_get_int64(const struct bt_definition *field);
548 char *bt_ctf_get_char_array(const struct bt_definition *field);
549 char *bt_ctf_get_string(const struct bt_definition *field);
550 double bt_ctf_get_float(const struct bt_definition *field);
551 const struct bt_definition *bt_ctf_get_variant(const struct bt_definition *field);
552 int bt_ctf_field_get_error(void);
553 const char *bt_ctf_get_decl_event_name(const struct bt_ctf_event_decl *event);
554 const char *bt_ctf_get_decl_field_name(const struct bt_ctf_field_decl *field);
555 const struct bt_declaration *bt_ctf_get_decl_from_def(const struct bt_definition *field);
556 const struct bt_declaration *bt_ctf_get_decl_from_field_decl(const struct bt_ctf_field_decl *field);
557 uint64_t bt_sequence_len(struct definition_sequence *sequence);
558 struct bt_definition *bt_sequence_index(struct definition_sequence *sequence, uint64_t i);
559 uint64_t bt_ctf_get_struct_field_count(const struct bt_definition *structure);
560 const struct bt_definition *bt_ctf_get_struct_field_index(const struct bt_definition *structure, uint64_t i);
564 class CTFStringEncoding:
570 # Based on the enum in ctf-writer/writer.h
572 BYTE_ORDER_NATIVE = 0
573 BYTE_ORDER_LITTLE_ENDIAN = 1
574 BYTE_ORDER_BIG_ENDIAN = 2
575 BYTE_ORDER_NETWORK = 3
576 BYTE_ORDER_UNKNOWN = 4 # Python-specific entry
578 #enum equivalent, accessible constants
579 #These are taken directly from ctf/events.h
580 #All changes to enums must also be made here
595 name = "UNKNOWN_TYPE"
596 constants = [attr for attr in dir(CTFTypeId) if not callable(getattr(CTFTypeId, attr)) and not attr.startswith("__")]
597 for attr in constants:
598 if getattr(CTFTypeId, attr) == id:
604 TRACE_PACKET_HEADER = 0
605 STREAM_PACKET_CONTEXT = 1
606 STREAM_EVENT_HEADER = 2
607 STREAM_EVENT_CONTEXT = 3
611 def scope_name(scope):
612 name = "UNKNOWN_SCOPE"
613 constants = [attr for attr in dir(CTFScope) if not callable(getattr(CTFScope, attr)) and not attr.startswith("__")]
614 for attr in constants:
615 if getattr(CTFScope, attr) == scope:
620 # Priority of the scopes when searching for event fields
621 _scopes = [CTFScope.EVENT_FIELDS, CTFScope.EVENT_CONTEXT, CTFScope.STREAM_EVENT_CONTEXT,
622 CTFScope.STREAM_EVENT_HEADER, CTFScope.STREAM_PACKET_CONTEXT, CTFScope.TRACE_PACKET_HEADER]
625 class Event(collections.Mapping):
627 This class represents an event from the trace.
628 It is obtained using the TraceCollection generator functions.
632 raise NotImplementedError("Event cannot be instantiated")
636 """Return the name of the event or None on error."""
637 return _bt_ctf_event_name(self._e)
642 Return the timestamp of the event as written in
643 the packet (in cycles) or -1ULL on error.
645 return _bt_ctf_get_cycles(self._e)
650 Return the timestamp of the event offset with the
651 system clock source or -1ULL on error.
653 return _bt_ctf_get_timestamp(self._e)
655 def field_with_scope(self, field_name, scope):
657 Get field_name's value in scope.
658 None is returned if no field matches field_name.
660 if not scope in _scopes:
661 raise ValueError("Invalid scope provided")
662 field = self._field_with_scope(field_name, scope)
663 if field is not None:
667 def field_list_with_scope(self, scope):
668 """Return a list of field names in scope."""
669 if not scope in _scopes:
670 raise ValueError("Invalid scope provided")
672 for field in self._field_list_with_scope(scope):
673 field_names.append(field.name)
679 Get the TraceHandle associated with this event
682 ret = _bt_ctf_event_get_handle_id(self._e)
686 th = TraceHandle.__new__(TraceHandle)
688 th._trace_collection = self.get_trace_collection()
692 def trace_collection(self):
694 Get the TraceCollection associated with this event.
695 Return None on error.
697 trace_collection = TraceCollection()
698 trace_collection._tc = _bt_ctf_event_get_context(self._e);
699 if trace_collection._tc is None:
702 return trace_collection
704 def __getitem__(self, field_name):
706 Get field_name's value. If the field_name exists in multiple
707 scopes, the first field found is returned. The scopes are searched
708 in the following order:
711 3) STREAM_EVENT_CONTEXT
712 4) STREAM_EVENT_HEADER
713 5) STREAM_PACKET_CONTEXT
714 6) TRACE_PACKET_HEADER
715 None is returned if no field matches field_name.
717 Use field_with_scope() to explicitly access fields in a given
720 field = self._field(field_name)
721 if field is not None:
723 raise KeyError(field_name)
726 for key in self.keys():
731 for scope in _scopes:
732 scope_ptr = _bt_ctf_get_top_level_scope(self._e, scope)
733 ret = _bt_python_field_listcaller(self._e, scope_ptr)
734 if isinstance(ret, list):
738 def __contains__(self, field_name):
739 return self._field(field_name) is not None
742 """Return a list of field names."""
744 for scope in _scopes:
745 for name in self.field_list_with_scope(scope):
746 field_names.add(name)
747 return list(field_names)
749 def get(self, field_name, default = None):
750 field = self._field(field_name)
756 for field in self.keys():
757 yield (field, self[field])
759 def _field_with_scope(self, field_name, scope):
760 scope_ptr = _bt_ctf_get_top_level_scope(self._e, scope)
761 if scope_ptr is None:
764 definition_ptr = _bt_ctf_get_field(self._e, scope_ptr, field_name)
765 if definition_ptr is None:
768 field = _Definition(definition_ptr, scope)
771 def _field(self, field_name):
773 for scope in _scopes:
774 field = self._field_with_scope(field_name, scope)
775 if field is not None:
779 def _field_list_with_scope(self, scope):
781 scope_ptr = _bt_ctf_get_top_level_scope(self._e, scope)
783 # Returns a list [list_ptr, count]. If list_ptr is NULL, SWIG will only
784 # provide the "count" return value
787 ret = _bt_python_field_listcaller(self._e, scope_ptr)
788 if isinstance(ret, list):
789 list_ptr, count = ret
791 for i in range(count):
792 definition_ptr = _bt_python_field_one_from_list(list_ptr, i)
793 if definition_ptr is not None:
794 definition = _Definition(definition_ptr, scope)
795 fields.append(definition)
798 class FieldError(Exception):
799 def __init__(self, value):
803 return repr(self.value)
805 class EventDeclaration(object):
806 """Event declaration class. Do not instantiate."""
809 raise NotImplementedError("EventDeclaration cannot be instantiated")
813 """Return the name of the event or None on error"""
814 return _bt_ctf_get_decl_event_name(self._ed)
819 Generator returning all FieldDeclarations of an event, going through
820 each scope in the following order:
823 3) STREAM_EVENT_CONTEXT
824 4) STREAM_EVENT_HEADER
825 5) STREAM_PACKET_CONTEXT
826 6) TRACE_PACKET_HEADER
828 for scope in _scopes:
829 for declaration in self.fields_scope(scope):
832 def fields_scope(self, scope):
834 Generator returning FieldDeclarations of the current event in scope.
836 ret = _by_python_field_decl_listcaller(self._ed, scope)
838 if not isinstance(ret, list):
841 list_ptr, count = ret
842 for i in range(count):
843 field_declaration_ptr = _bt_python_field_decl_one_from_list(list_ptr, i)
844 if field_declaration_ptr is not None:
845 declaration_ptr = _bt_ctf_get_decl_from_field_decl(field_declaration_ptr)
846 field_declaration = _create_field_declaration(declaration_ptr, _bt_ctf_get_decl_field_name(field_declaration_ptr), scope)
847 yield field_declaration
849 class FieldDeclaration(object):
850 """Field declaration class. Do not instantiate."""
852 raise NotImplementedError("FieldDeclaration cannot be instantiated")
855 return "({0}) {1} {2}".format(CTFScope.scope_name(self.scope), CTFTypeId.type_name(self.type), self.name)
859 """Return the name of a FieldDeclaration or None on error."""
865 Return the FieldDeclaration's type. One of the entries in class
868 return _bt_ctf_field_type(self._fd)
873 Return the FieldDeclaration's scope.
877 class IntegerFieldDeclaration(FieldDeclaration):
878 """Do not instantiate."""
880 raise NotImplementedError("IntegerFieldDeclaration cannot be instantiated")
883 def signedness(self):
885 Return the signedness of an integer:
886 0 if unsigned; 1 if signed; -1 on error.
888 return _bt_ctf_get_int_signedness(self._fd)
892 """Return the base of an int or a negative value on error."""
893 return _bt_ctf_get_int_base(self._fd)
896 def byte_order(self):
898 Return the byte order. One of class ByteOrder's entries.
900 ret = _bt_ctf_get_int_byte_order(self._fd)
902 return ByteOrder.BYTE_ORDER_LITTLE_ENDIAN
904 return ByteOrder.BYTE_ORDER_BIG_ENDIAN
906 return ByteOrder.BYTE_ORDER_UNKNOWN
911 Return the size, in bits, of an int or a negative
914 return _bt_ctf_get_int_len(self._fd)
919 Return the encoding. One of class CTFStringEncoding's entries.
920 Return a negative value on error.
922 return _bt_ctf_get_encoding(self._fd)
924 class EnumerationFieldDeclaration(FieldDeclaration):
925 """Do not instantiate."""
927 raise NotImplementedError("EnumerationFieldDeclaration cannot be instantiated")
929 class ArrayFieldDeclaration(FieldDeclaration):
930 """Do not instantiate."""
932 raise NotImplementedError("ArrayFieldDeclaration cannot be instantiated")
937 Return the length of an array or a negative
940 return _bt_ctf_get_array_len(self._fd)
943 def element_declaration(self):
945 Return element declaration.
947 field_decl_ptr = _bt_python_get_array_element_declaration(self._fd)
948 return _create_field_declaration(field_decl_ptr, "", self.scope)
950 class SequenceFieldDeclaration(FieldDeclaration):
951 """Do not instantiate."""
953 raise NotImplementedError("SequenceFieldDeclaration cannot be instantiated")
955 class FloatFieldDeclaration(FieldDeclaration):
956 """Do not instantiate."""
958 raise NotImplementedError("FloatFieldDeclaration cannot be instantiated")
960 class StructureFieldDeclaration(FieldDeclaration):
961 """Do not instantiate."""
963 raise NotImplementedError("StructureFieldDeclaration cannot be instantiated")
965 class StringFieldDeclaration(FieldDeclaration):
966 """Do not instantiate."""
968 raise NotImplementedError("StringFieldDeclaration cannot be instantiated")
970 class VariantFieldDeclaration(FieldDeclaration):
971 """Do not instantiate."""
973 raise NotImplementedError("VariantFieldDeclaration cannot be instantiated")
977 Return the last error code encountered while
978 accessing a field and reset the error flag.
979 Return 0 if no error, a negative value otherwise.
981 return _bt_ctf_field_get_error()
983 def _create_field_declaration(declaration_ptr, name, scope):
985 Private field declaration factory.
987 if declaration_ptr is None:
988 raise ValueError("declaration_ptr must be valid")
989 if not scope in _scopes:
990 raise ValueError("Invalid scope provided")
992 type = _bt_ctf_field_type(declaration_ptr)
994 if type == CTFTypeId.INTEGER:
995 declaration = IntegerFieldDeclaration.__new__(IntegerFieldDeclaration)
996 elif type == CTFTypeId.ENUM:
997 declaration = EnumerationFieldDeclaration.__new__(EnumerationFieldDeclaration)
998 elif type == CTFTypeId.ARRAY:
999 declaration = ArrayFieldDeclaration.__new__(ArrayFieldDeclaration)
1000 elif type == CTFTypeId.SEQUENCE:
1001 declaration = SequenceFieldDeclaration.__new__(SequenceFieldDeclaration)
1002 elif type == CTFTypeId.FLOAT:
1003 declaration = FloatFieldDeclaration.__new__(FloatFieldDeclaration)
1004 elif type == CTFTypeId.STRUCT:
1005 declaration = StructureFieldDeclaration.__new__(StructureFieldDeclaration)
1006 elif type == CTFTypeId.STRING:
1007 declaration = StringFieldDeclaration.__new__(StringFieldDeclaration)
1008 elif type == CTFTypeId.VARIANT:
1009 declaration = VariantFieldDeclaration.__new__(VariantFieldDeclaration)
1013 declaration._fd = declaration_ptr
1014 declaration._s = scope
1015 declaration._name = name
1018 class _Definition(object):
1019 def __init__(self, definition_ptr, scope):
1020 self._d = definition_ptr
1022 if not scope in _scopes:
1023 ValueError("Invalid scope provided")
1027 """Return the name of a field or None on error."""
1028 return _bt_ctf_field_name(self._d)
1032 """Return the type of a field or -1 if unknown."""
1033 return _bt_ctf_field_type(_bt_ctf_get_decl_from_def(self._d))
1036 def declaration(self):
1037 """Return the associated Definition object."""
1038 return _create_field_declaration(_bt_ctf_get_decl_from_def(self._d), self.name, self.scope)
1040 def _get_enum_str(self):
1042 Return the string matching the current enumeration.
1043 Return None on error.
1045 return _bt_ctf_get_enum_str(self._d)
1047 def _get_array_element_at(self, index):
1049 Return the array's element at position index.
1050 Return None on error
1052 array_ptr = _bt_python_get_array_from_def(self._d)
1053 if array_ptr is None:
1056 definition_ptr = _bt_array_index(array_ptr, index)
1057 if definition_ptr is None:
1059 return _Definition(definition_ptr, self.scope)
1061 def _get_sequence_len(self):
1063 Return the len of a sequence or a negative
1066 seq = _bt_python_get_sequence_from_def(self._d)
1067 return _bt_sequence_len(seq)
1069 def _get_sequence_element_at(self, index):
1071 Return the sequence's element at position index,
1072 otherwise return None
1074 seq = _bt_python_get_sequence_from_def(self._d)
1076 definition_ptr = _bt_sequence_index(seq, index)
1077 if definition_ptr is not None:
1078 return _Definition(definition_ptr, self.scope)
1081 def _get_uint64(self):
1083 Return the value associated with the field.
1084 If the field does not exist or is not of the type requested,
1085 the value returned is undefined. To check if an error occured,
1086 use the field_error() function after accessing a field.
1088 return _bt_ctf_get_uint64(self._d)
1090 def _get_int64(self):
1092 Return the value associated with the field.
1093 If the field does not exist or is not of the type requested,
1094 the value returned is undefined. To check if an error occured,
1095 use the field_error() function after accessing a field.
1097 return _bt_ctf_get_int64(self._d)
1099 def _get_char_array(self):
1101 Return the value associated with the field.
1102 If the field does not exist or is not of the type requested,
1103 the value returned is undefined. To check if an error occurred,
1104 use the field_error() function after accessing a field.
1106 return _bt_ctf_get_char_array(self._d)
1110 Return the value associated with the field.
1111 If the field does not exist or is not of the type requested,
1112 the value returned is undefined. To check if an error occurred,
1113 use the field_error() function after accessing a field.
1115 return _bt_ctf_get_string(self._d)
1117 def _get_float(self):
1119 Return the value associated with the field.
1120 If the field does not exist or is not of the type requested,
1121 the value returned is undefined. To check if an error occurred,
1122 use the field_error() function after accessing a field.
1124 return _bt_ctf_get_float(self._d)
1126 def _get_variant(self):
1128 Return the variant's selected field.
1129 If the field does not exist or is not of the type requested,
1130 the value returned is undefined. To check if an error occurred,
1131 use the field_error() function after accessing a field.
1133 return _bt_ctf_get_variant(self._d)
1135 def _get_struct_field_count(self):
1137 Return the number of fields contained in the structure.
1138 If the field does not exist or is not of the type requested,
1139 the value returned is undefined.
1141 return _bt_ctf_get_struct_field_count(self._d)
1143 def _get_struct_field_at(self, i):
1145 Return the structure's field at position i.
1146 If the field does not exist or is not of the type requested,
1147 the value returned is undefined. To check if an error occurred,
1148 use the field_error() function after accessing a field.
1150 return _bt_ctf_get_struct_field_index(self._d, i)
1155 Return the value associated with the field according to its type.
1156 Return None on error.
1161 if id == CTFTypeId.STRING:
1162 value = self._get_str()
1163 elif id == CTFTypeId.ARRAY:
1164 element_decl = self.declaration.element_declaration
1165 if ((element_decl.type == CTFTypeId.INTEGER
1166 and element_decl.length == 8)
1167 and (element_decl.encoding == CTFStringEncoding.ASCII or element_decl.encoding == CTFStringEncoding.UTF8)):
1168 value = _bt_python_get_array_string(self._d)
1171 for i in range(self.declaration.length):
1172 element = self._get_array_element_at(i)
1173 value.append(element.value)
1174 elif id == CTFTypeId.INTEGER:
1175 if self.declaration.signedness == 0:
1176 value = self._get_uint64()
1178 value = self._get_int64()
1179 elif id == CTFTypeId.ENUM:
1180 value = self._get_enum_str()
1181 elif id == CTFTypeId.SEQUENCE:
1182 seq_len = self._get_sequence_len()
1184 for i in range(seq_len):
1185 evDef = self._get_sequence_element_at(i)
1186 value.append(evDef.value)
1187 elif id == CTFTypeId.FLOAT:
1188 value = self._get_float()
1189 elif id == CTFTypeId.VARIANT:
1190 variant = _Definition.__new__(_Definition)
1191 variant._d = self._get_variant();
1192 value = variant.value
1193 elif id == CTFTypeId.STRUCT:
1195 for i in range(self._get_struct_field_count()):
1196 member = _Definition(self._get_struct_field_at(i), self.scope)
1197 value[member.name] = member.value
1200 raise FieldError("Error occurred while accessing field {} of type {}".format(self.name, CTFTypeId.type_name(id)))
1205 """Return the scope of a field or None on error."""
1211 // =================================================================
1213 // =================================================================
1215 /* =================================================================
1217 ¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯
1219 %rename("_bt_ctf_clock_create") bt_ctf_clock_create(const char *name);
1220 %rename("_bt_ctf_clock_set_description") bt_ctf_clock_set_description(struct bt_ctf_clock *clock, const char *desc);
1221 %rename("_bt_ctf_clock_set_frequency") bt_ctf_clock_set_frequency(struct bt_ctf_clock *clock, uint64_t freq);
1222 %rename("_bt_ctf_clock_set_precision") bt_ctf_clock_set_precision(struct bt_ctf_clock *clock, uint64_t precision);
1223 %rename("_bt_ctf_clock_set_offset_s") bt_ctf_clock_set_offset_s(struct bt_ctf_clock *clock, uint64_t offset_s);
1224 %rename("_bt_ctf_clock_set_offset") bt_ctf_clock_set_offset(struct bt_ctf_clock *clock, uint64_t offset);
1225 %rename("_bt_ctf_clock_set_is_absolute") bt_ctf_clock_set_is_absolute(struct bt_ctf_clock *clock, int is_absolute);
1226 %rename("_bt_ctf_clock_set_time") bt_ctf_clock_set_time(struct bt_ctf_clock *clock, uint64_t time);
1227 %rename("_bt_ctf_clock_get") bt_ctf_clock_get(struct bt_ctf_clock *clock);
1228 %rename("_bt_ctf_clock_put") bt_ctf_clock_put(struct bt_ctf_clock *clock);
1230 struct bt_ctf_clock *bt_ctf_clock_create(const char *name);
1231 int bt_ctf_clock_set_description(struct bt_ctf_clock *clock, const char *desc);
1232 int bt_ctf_clock_set_frequency(struct bt_ctf_clock *clock, uint64_t freq);
1233 int bt_ctf_clock_set_precision(struct bt_ctf_clock *clock, uint64_t precision);
1234 int bt_ctf_clock_set_offset_s(struct bt_ctf_clock *clock, uint64_t offset_s);
1235 int bt_ctf_clock_set_offset(struct bt_ctf_clock *clock, uint64_t offset);
1236 int bt_ctf_clock_set_is_absolute(struct bt_ctf_clock *clock, int is_absolute);
1237 int bt_ctf_clock_set_time(struct bt_ctf_clock *clock, uint64_t time);
1238 void bt_ctf_clock_get(struct bt_ctf_clock *clock);
1239 void bt_ctf_clock_put(struct bt_ctf_clock *clock);
1241 /* =================================================================
1243 ¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯
1245 %rename("_bt_ctf_field_type_integer_create") bt_ctf_field_type_integer_create(unsigned int size);
1246 %rename("_bt_ctf_field_type_integer_set_signed") bt_ctf_field_type_integer_set_signed(struct bt_ctf_field_type *integer, int is_signed);
1247 %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);
1248 %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);
1249 %rename("_bt_ctf_field_type_enumeration_create") bt_ctf_field_type_enumeration_create(struct bt_ctf_field_type *integer_container_type);
1250 %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);
1251 %rename("_bt_ctf_field_type_floating_point_create") bt_ctf_field_type_floating_point_create(void);
1252 %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);
1253 %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);
1254 %rename("_bt_ctf_field_type_structure_create") bt_ctf_field_type_structure_create(void);
1255 %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);
1256 %rename("_bt_ctf_field_type_variant_create") bt_ctf_field_type_variant_create(struct bt_ctf_field_type *enum_tag, const char *tag_name);
1257 %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);
1258 %rename("_bt_ctf_field_type_array_create") bt_ctf_field_type_array_create(struct bt_ctf_field_type *element_type, unsigned int length);
1259 %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);
1260 %rename("_bt_ctf_field_type_string_create") bt_ctf_field_type_string_create(void);
1261 %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);
1262 %rename("_bt_ctf_field_type_set_alignment") bt_ctf_field_type_set_alignment(struct bt_ctf_field_type *type, unsigned int alignment);
1263 %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);
1264 %rename("_bt_ctf_field_type_get") bt_ctf_field_type_get(struct bt_ctf_field_type *type);
1265 %rename("_bt_ctf_field_type_put") bt_ctf_field_type_put(struct bt_ctf_field_type *type);
1267 struct bt_ctf_field_type *bt_ctf_field_type_integer_create(unsigned int size);
1268 int bt_ctf_field_type_integer_set_signed(struct bt_ctf_field_type *integer, int is_signed);
1269 int bt_ctf_field_type_integer_set_base(struct bt_ctf_field_type *integer, enum bt_ctf_integer_base base);
1270 int bt_ctf_field_type_integer_set_encoding(struct bt_ctf_field_type *integer, enum ctf_string_encoding encoding);
1271 struct bt_ctf_field_type *bt_ctf_field_type_enumeration_create(struct bt_ctf_field_type *integer_container_type);
1272 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);
1273 struct bt_ctf_field_type *bt_ctf_field_type_floating_point_create(void);
1274 int bt_ctf_field_type_floating_point_set_exponent_digits(struct bt_ctf_field_type *floating_point, unsigned int exponent_digits);
1275 int bt_ctf_field_type_floating_point_set_mantissa_digits(struct bt_ctf_field_type *floating_point, unsigned int mantissa_digits);
1276 struct bt_ctf_field_type *bt_ctf_field_type_structure_create(void);
1277 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);
1278 struct bt_ctf_field_type *bt_ctf_field_type_variant_create(struct bt_ctf_field_type *enum_tag, const char *tag_name);
1279 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);
1280 struct bt_ctf_field_type *bt_ctf_field_type_array_create(struct bt_ctf_field_type *element_type, unsigned int length);
1281 struct bt_ctf_field_type *bt_ctf_field_type_sequence_create(struct bt_ctf_field_type *element_type, const char *length_field_name);
1282 struct bt_ctf_field_type *bt_ctf_field_type_string_create(void);
1283 int bt_ctf_field_type_string_set_encoding(struct bt_ctf_field_type *string, enum ctf_string_encoding encoding);
1284 int bt_ctf_field_type_set_alignment(struct bt_ctf_field_type *type, unsigned int alignment);
1285 int bt_ctf_field_type_set_byte_order(struct bt_ctf_field_type *type, enum bt_ctf_byte_order byte_order);
1286 void bt_ctf_field_type_get(struct bt_ctf_field_type *type);
1287 void bt_ctf_field_type_put(struct bt_ctf_field_type *type);
1289 /* =================================================================
1291 ¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯
1293 %rename("_bt_ctf_field_create") bt_ctf_field_create(struct bt_ctf_field_type *type);
1294 %rename("_bt_ctf_field_structure_get_field") bt_ctf_field_structure_get_field(struct bt_ctf_field *structure, const char *name);
1295 %rename("_bt_ctf_field_array_get_field") bt_ctf_field_array_get_field(struct bt_ctf_field *array, uint64_t index);
1296 %rename("_bt_ctf_field_sequence_set_length") bt_ctf_field_sequence_set_length(struct bt_ctf_field *sequence, struct bt_ctf_field *length_field);
1297 %rename("_bt_ctf_field_sequence_get_field") bt_ctf_field_sequence_get_field(struct bt_ctf_field *sequence, uint64_t index);
1298 %rename("_bt_ctf_field_variant_get_field") bt_ctf_field_variant_get_field(struct bt_ctf_field *variant, struct bt_ctf_field *tag);
1299 %rename("_bt_ctf_field_enumeration_get_container") bt_ctf_field_enumeration_get_container(struct bt_ctf_field *enumeration);
1300 %rename("_bt_ctf_field_signed_integer_set_value") bt_ctf_field_signed_integer_set_value(struct bt_ctf_field *integer, int64_t value);
1301 %rename("_bt_ctf_field_unsigned_integer_set_value") bt_ctf_field_unsigned_integer_set_value(struct bt_ctf_field *integer, uint64_t value);
1302 %rename("_bt_ctf_field_floating_point_set_value") bt_ctf_field_floating_point_set_value(struct bt_ctf_field *floating_point, double value);
1303 %rename("_bt_ctf_field_string_set_value") bt_ctf_field_string_set_value(struct bt_ctf_field *string, const char *value);
1304 %rename("_bt_ctf_field_get") bt_ctf_field_get(struct bt_ctf_field *field);
1305 %rename("_bt_ctf_field_put") bt_ctf_field_put(struct bt_ctf_field *field);
1307 struct bt_ctf_field *bt_ctf_field_create(struct bt_ctf_field_type *type);
1308 struct bt_ctf_field *bt_ctf_field_structure_get_field(struct bt_ctf_field *structure, const char *name);
1309 struct bt_ctf_field *bt_ctf_field_array_get_field(struct bt_ctf_field *array, uint64_t index);
1310 int bt_ctf_field_sequence_set_length(struct bt_ctf_field *sequence, struct bt_ctf_field *length_field);
1311 struct bt_ctf_field *bt_ctf_field_sequence_get_field(struct bt_ctf_field *sequence, uint64_t index);
1312 struct bt_ctf_field *bt_ctf_field_variant_get_field(struct bt_ctf_field *variant, struct bt_ctf_field *tag);
1313 struct bt_ctf_field *bt_ctf_field_enumeration_get_container(struct bt_ctf_field *enumeration);
1314 int bt_ctf_field_signed_integer_set_value(struct bt_ctf_field *integer, int64_t value);
1315 int bt_ctf_field_unsigned_integer_set_value(struct bt_ctf_field *integer, uint64_t value);
1316 int bt_ctf_field_floating_point_set_value(struct bt_ctf_field *floating_point, double value);
1317 int bt_ctf_field_string_set_value(struct bt_ctf_field *string, const char *value);
1318 void bt_ctf_field_get(struct bt_ctf_field *field);
1319 void bt_ctf_field_put(struct bt_ctf_field *field);
1321 /* =================================================================
1323 ¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯
1325 %rename("_bt_ctf_event_class_create") bt_ctf_event_class_create(const char *name);
1326 %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);
1327 %rename("_bt_ctf_event_class_get") bt_ctf_event_class_get(struct bt_ctf_event_class *event_class);
1328 %rename("_bt_ctf_event_class_put") bt_ctf_event_class_put(struct bt_ctf_event_class *event_class);
1329 %rename("_bt_ctf_event_create") bt_ctf_event_create(struct bt_ctf_event_class *event_class);
1330 %rename("_bt_ctf_event_set_payload") bt_ctf_event_set_payload(struct bt_ctf_event *event, const char *name, struct bt_ctf_field *value);
1331 %rename("_bt_ctf_event_get_payload") bt_ctf_event_get_payload(struct bt_ctf_event *event, const char *name);
1332 %rename("_bt_ctf_event_get") bt_ctf_event_get(struct bt_ctf_event *event);
1333 %rename("_bt_ctf_event_put") bt_ctf_event_put(struct bt_ctf_event *event);
1335 struct bt_ctf_event_class *bt_ctf_event_class_create(const char *name);
1336 int bt_ctf_event_class_add_field(struct bt_ctf_event_class *event_class, struct bt_ctf_field_type *type, const char *name);
1337 void bt_ctf_event_class_get(struct bt_ctf_event_class *event_class);
1338 void bt_ctf_event_class_put(struct bt_ctf_event_class *event_class);
1339 struct bt_ctf_event *bt_ctf_event_create(struct bt_ctf_event_class *event_class);
1340 int bt_ctf_event_set_payload(struct bt_ctf_event *event, const char *name, struct bt_ctf_field *value);
1341 struct bt_ctf_field *bt_ctf_event_get_payload(struct bt_ctf_event *event, const char *name);
1342 void bt_ctf_event_get(struct bt_ctf_event *event);
1343 void bt_ctf_event_put(struct bt_ctf_event *event);
1345 /* =================================================================
1347 ¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯
1349 %rename("_bt_ctf_stream_class_create") bt_ctf_stream_class_create(const char *name);
1350 %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);
1351 %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);
1352 %rename("_bt_ctf_stream_class_get") bt_ctf_stream_class_get(struct bt_ctf_stream_class *stream_class);
1353 %rename("_bt_ctf_stream_class_put") bt_ctf_stream_class_put(struct bt_ctf_stream_class *stream_class);
1354 %rename("_bt_ctf_stream_append_discarded_events") bt_ctf_stream_append_discarded_events(struct bt_ctf_stream *stream, uint64_t event_count);
1355 %rename("_bt_ctf_stream_append_event") bt_ctf_stream_append_event(struct bt_ctf_stream *stream, struct bt_ctf_event *event);
1356 %rename("_bt_ctf_stream_flush") bt_ctf_stream_flush(struct bt_ctf_stream *stream);
1357 %rename("_bt_ctf_stream_get") bt_ctf_stream_get(struct bt_ctf_stream *stream);
1358 %rename("_bt_ctf_stream_put") bt_ctf_stream_put(struct bt_ctf_stream *stream);
1360 struct bt_ctf_stream_class *bt_ctf_stream_class_create(const char *name);
1361 int bt_ctf_stream_class_set_clock(struct bt_ctf_stream_class *stream_class, struct bt_ctf_clock *clock);
1362 int bt_ctf_stream_class_add_event_class(struct bt_ctf_stream_class *stream_class, struct bt_ctf_event_class *event_class);
1363 void bt_ctf_stream_class_get(struct bt_ctf_stream_class *stream_class);
1364 void bt_ctf_stream_class_put(struct bt_ctf_stream_class *stream_class);
1365 void bt_ctf_stream_append_discarded_events(struct bt_ctf_stream *stream, uint64_t event_count);
1366 int bt_ctf_stream_append_event(struct bt_ctf_stream *stream, struct bt_ctf_event *event);
1367 int bt_ctf_stream_flush(struct bt_ctf_stream *stream);
1368 void bt_ctf_stream_get(struct bt_ctf_stream *stream);
1369 void bt_ctf_stream_put(struct bt_ctf_stream *stream);
1371 /* =================================================================
1373 ¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯
1375 %rename("_bt_ctf_writer_create") bt_ctf_writer_create(const char *path);
1376 %rename("_bt_ctf_writer_create_stream") bt_ctf_writer_create_stream(struct bt_ctf_writer *writer, struct bt_ctf_stream_class *stream_class);
1377 %rename("_bt_ctf_writer_add_environment_field") bt_ctf_writer_add_environment_field(struct bt_ctf_writer *writer, const char *name, const char *value);
1378 %rename("_bt_ctf_writer_add_clock") bt_ctf_writer_add_clock(struct bt_ctf_writer *writer, struct bt_ctf_clock *clock);
1379 %newobject bt_ctf_writer_get_metadata_string;
1380 %rename("_bt_ctf_writer_get_metadata_string") bt_ctf_writer_get_metadata_string(struct bt_ctf_writer *writer);
1381 %rename("_bt_ctf_writer_flush_metadata") bt_ctf_writer_flush_metadata(struct bt_ctf_writer *writer);
1382 %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);
1383 %rename("_bt_ctf_writer_get") bt_ctf_writer_get(struct bt_ctf_writer *writer);
1384 %rename("_bt_ctf_writer_put") bt_ctf_writer_put(struct bt_ctf_writer *writer);
1386 struct bt_ctf_writer *bt_ctf_writer_create(const char *path);
1387 struct bt_ctf_stream *bt_ctf_writer_create_stream(struct bt_ctf_writer *writer, struct bt_ctf_stream_class *stream_class);
1388 int bt_ctf_writer_add_environment_field(struct bt_ctf_writer *writer, const char *name, const char *value);
1389 int bt_ctf_writer_add_clock(struct bt_ctf_writer *writer, struct bt_ctf_clock *clock);
1390 char *bt_ctf_writer_get_metadata_string(struct bt_ctf_writer *writer);
1391 void bt_ctf_writer_flush_metadata(struct bt_ctf_writer *writer);
1392 int bt_ctf_writer_set_byte_order(struct bt_ctf_writer *writer, enum bt_ctf_byte_order byte_order);
1393 void bt_ctf_writer_get(struct bt_ctf_writer *writer);
1394 void bt_ctf_writer_put(struct bt_ctf_writer *writer);
1401 def __init__(self, name):
1402 self._c = _bt_ctf_clock_create(name)
1404 raise ValueError("Invalid clock name.")
1407 _bt_ctf_clock_put(self._c)
1410 Get the clock's description.
1413 def description(self):
1414 raise NotImplementedError("Getter not implemented.")
1417 Set the clock's description. The description appears in the clock's TSDL
1421 def description(self, desc):
1422 ret = _bt_ctf_clock_set_description(self._c, str(desc))
1424 raise ValueError("Invalid clock description.")
1427 Get the clock's frequency (Hz).
1430 def frequency(self):
1431 raise NotImplementedError("Getter not implemented.")
1434 Set the clock's frequency (Hz).
1437 def frequency(self, freq):
1438 ret = _bt_ctf_clock_set_frequency(self._c, freq)
1440 raise ValueError("Invalid frequency value.")
1443 Get the clock's precision (in clock ticks).
1446 def precision(self):
1447 raise NotImplementedError("Getter not implemented.")
1450 Set the clock's precision (in clock ticks).
1453 def precision(self, precision):
1454 ret = _bt_ctf_clock_set_precision(self._c, precision)
1457 Get the clock's offset in seconds from POSIX.1 Epoch.
1460 def offset_seconds(self):
1461 raise NotImplementedError("Getter not implemented.")
1464 Set the clock's offset in seconds from POSIX.1 Epoch.
1466 @offset_seconds.setter
1467 def offset_seconds(self, offset_s):
1468 ret = _bt_ctf_clock_set_offset_s(self._c, offset_s)
1470 raise ValueError("Invalid offset value.")
1473 Get the clock's offset in ticks from POSIX.1 Epoch + offset in seconds.
1477 raise NotImplementedError("Getter not implemented.")
1480 Set the clock's offset in ticks from POSIX.1 Epoch + offset in seconds.
1483 def offset(self, offset):
1484 ret = _bt_ctf_clock_set_offset(self._c, offset)
1486 raise ValueError("Invalid offset value.")
1489 Get a clock's absolute attribute. A clock is absolute if the clock
1490 is a global reference across the trace's other clocks.
1494 raise NotImplementedError("Getter not implemented.")
1497 Set a clock's absolute attribute. A clock is absolute if the clock
1498 is a global reference across the trace's other clocks.
1501 def absolute(self, is_absolute):
1502 ret = _bt_ctf_clock_set_is_absolute(self._c, int(is_absolute))
1504 raise ValueError("Could not set the clock's absolute attribute.")
1507 Get the current time in nanoseconds since the clock's origin (offset and
1508 offset_s attributes).
1512 raise NotImplementedError("Getter not implemented.")
1515 Set the current time in nanoseconds since the clock's origin (offset and
1516 offset_s attributes). The clock's value will be sampled as events are
1517 appended to a stream.
1520 def time(self, time):
1521 ret = _bt_ctf_clock_set_time(self._c, time)
1523 raise ValueError("Invalid time value.")
1525 class FieldDeclaration:
1527 FieldDeclaration should not be instantiated directly. Please instantiate
1528 one of the concrete FieldDeclaration classes.
1531 # These values are based on the bt_ctf_integer_base enum
1532 # declared in event-types.h.
1533 INTEGER_BASE_UNKNOWN = -1
1534 INTEGER_BASE_BINARY = 2
1535 INTEGER_BASE_OCTAL = 8
1536 INTEGER_BASE_DECIMAL = 10
1537 INTEGER_BASE_HEXADECIMAL = 16
1540 if self._ft is None:
1541 raise ValueError("FieldDeclaration creation failed.")
1544 _bt_ctf_field_type_put(self._ft)
1547 Get the field type's alignment.
1550 def alignment(self):
1551 raise NotImplementedError("Getter not implemented.")
1554 Set the field type's alignment. Defaults to 1 (bit-aligned). However,
1555 some types, such as structures and string, may impose other alignment
1559 def alignment(self, alignment):
1560 ret = _bt_ctf_field_type_set_alignment(self._ft, alignment)
1562 raise ValueError("Invalid alignment value.")
1565 Get the field type's byte order. One of the ByteOrder's constant.
1568 def byte_order(self):
1569 raise NotImplementedError("Getter not implemented.")
1572 Set the field type's byte order. Use constants defined in the ByteOrder
1576 def byte_order(self, byte_order):
1577 ret = _bt_ctf_field_type_set_byte_order(self._ft, byte_order)
1579 raise ValueError("Could not set byte order value.")
1581 class IntegerFieldDeclaration(FieldDeclaration):
1583 Create a new integer field type of the given size.
1585 def __init__(self, size):
1586 self._ft = _bt_ctf_field_type_integer_create(size)
1590 Get an integer's signedness attribute.
1594 raise NotImplementedError("Getter not implemented.")
1597 Set an integer's signedness attribute.
1600 def signed(self, signed):
1601 ret = _bt_ctf_field_type_integer_set_signed(self._ft, signed)
1603 raise ValueError("Could not set signed attribute.")
1606 Get the integer's base used to pretty-print the resulting trace.
1610 raise NotImplementedError("Getter not implemented.")
1613 Set the integer's base used to pretty-print the resulting trace.
1614 The base must be a constant of the IntegerBase class.
1617 def base(self, base):
1618 ret = _bt_ctf_field_type_integer_set_base(self._ft, base)
1620 raise ValueError("Could not set base value.")
1623 Get the integer's encoding (one of the constants of the
1624 CTFStringEncoding class).
1628 raise NotImplementedError("Getter not implemented.")
1631 An integer encoding may be set to signal that the integer must be printed
1632 as a text character. Must be a constant from the CTFStringEncoding class.
1635 def encoding(self, encoding):
1636 ret = _bt_ctf_field_type_integer_set_encoding(self._ft, encoding)
1638 raise ValueError("Could not set integer encoding.")
1640 class EnumerationFieldDeclaration(FieldDeclaration):
1642 Create a new enumeration field type with the given underlying type.
1644 def __init__(self, integer_type):
1645 if integer_type is None or not isinstance(integer_type, CTFWriter.IntegerFieldDeclaration):
1646 raise TypeError("Invalid integer container.")
1648 self._ft = _bt_ctf_field_type_enumeration_create(integer_type._ft)
1652 Add a mapping to the enumeration. The range's values are inclusive.
1654 def add_mapping(self, name, range_start, range_end):
1655 ret = _bt_ctf_field_type_enumeration_add_mapping(self._ft, str(name), range_start, range_end)
1657 raise ValueError("Could not add mapping to enumeration type.")
1659 class FloatFieldDeclaration(FieldDeclaration):
1666 Create a new floating point field type.
1669 self._ft = _bt_ctf_field_type_floating_point_create()
1673 Get the number of exponent digits to use to store the floating point field.
1676 def exponent_digits(self):
1677 raise NotImplementedError("Getter not implemented.")
1680 Set the number of exponent digits to use to store the floating point field.
1681 The only values currently supported are FLT_EXP_DIG and DBL_EXP_DIG which
1682 are defined as constants of this class.
1684 @exponent_digits.setter
1685 def exponent_digits(self, exponent_digits):
1686 ret = _bt_ctf_field_type_floating_point_set_exponent_digits(self._ft, exponent_digits)
1688 raise ValueError("Could not set exponent digit count.")
1691 Get the number of mantissa digits to use to store the floating point field.
1694 def mantissa_digits(self):
1695 raise NotImplementedError("Getter not implemented.")
1698 Set the number of mantissa digits to use to store the floating point field.
1699 The only values currently supported are FLT_MANT_DIG and DBL_MANT_DIG which
1700 are defined as constants of this class.
1702 @mantissa_digits.setter
1703 def mantissa_digits(self, mantissa_digits):
1704 ret = _bt_ctf_field_type_floating_point_set_mantissa_digits(self._ft, mantissa_digits)
1706 raise ValueError("Could not set mantissa digit count.")
1708 class StructureFieldDeclaration(FieldDeclaration):
1710 Create a new structure field type.
1713 self._ft = _bt_ctf_field_type_structure_create()
1717 Add a field of type "field_type" to the structure.
1719 def add_field(self, field_type, field_name):
1720 ret = _bt_ctf_field_type_structure_add_field(self._ft, field_type._ft, str(field_name))
1722 raise ValueError("Could not add field to structure.")
1724 class VariantFieldDeclaration(FieldDeclaration):
1726 Create a new variant field type.
1728 def __init__(self, enum_tag, tag_name):
1729 if enum_tag is None or not isinstance(enum_tag, CTFWriter.EnumerationFieldDeclaration):
1730 raise TypeError("Invalid tag type; must be of type EnumerationFieldDeclaration.")
1732 self._ft = _bt_ctf_field_type_variant_create(enum_tag._ft, str(tag_name))
1736 Add a field of type "field_type" to the variant.
1738 def add_field(self, field_type, field_name):
1739 ret = _bt_ctf_field_type_variant_add_field(self._ft, field_type._ft, str(field_name))
1741 raise ValueError("Could not add field to variant.")
1743 class ArrayFieldDeclaration(FieldDeclaration):
1745 Create a new array field type.
1747 def __init__(self, element_type, length):
1748 self._ft = _bt_ctf_field_type_array_create(element_type._ft, length)
1751 class SequenceFieldDeclaration(FieldDeclaration):
1753 Create a new sequence field type.
1755 def __init__(self, element_type, length_field_name):
1756 self._ft = _bt_ctf_field_type_sequence_create(element_type._ft, str(length_field_name))
1759 class StringFieldDeclaration(FieldDeclaration):
1761 Create a new string field type.
1764 self._ft = _bt_ctf_field_type_string_create()
1768 Get a string type's encoding (a constant from the CTFStringEncoding class).
1772 raise NotImplementedError("Getter not implemented.")
1775 Set a string type's encoding. Must be a constant from the CTFStringEncoding class.
1778 def encoding(self, encoding):
1779 ret = _bt_ctf_field_type_string_set_encoding(self._ft, encoding)
1781 raise ValueError("Could not set string encoding.")
1784 Create an instance of a field.
1787 def create_field(self, field_type):
1788 if field_type is None or not isinstance(field_type, CTFWriter.FieldDeclaration):
1789 raise TypeError("Invalid field_type. Type must be a FieldDeclaration-derived class.")
1791 if isinstance(field_type, CTFWriter.IntegerFieldDeclaration):
1792 return CTFWriter.IntegerField(field_type)
1793 elif isinstance(field_type, CTFWriter.EnumerationFieldDeclaration):
1794 return CTFWriter.EnumerationField(field_type)
1795 elif isinstance(field_type, CTFWriter.FloatFieldDeclaration):
1796 return CTFWriter.FloatFieldingPoint(field_type)
1797 elif isinstance(field_type, CTFWriter.StructureFieldDeclaration):
1798 return CTFWriter.StructureField(field_type)
1799 elif isinstance(field_type, CTFWriter.VariantFieldDeclaration):
1800 return CTFWriter.VariantField(field_type)
1801 elif isinstance(field_type, CTFWriter.ArrayFieldDeclaration):
1802 return CTFWriter.ArrayField(field_type)
1803 elif isinstance(field_type, CTFWriter.SequenceFieldDeclaration):
1804 return CTFWriter.SequenceField(field_type)
1805 elif isinstance(field_type, CTFWriter.StringFieldDeclaration):
1806 return CTFWriter.StringField(field_type)
1810 Base class, do not instantiate.
1812 def __init__(self, field_type):
1813 if not isinstance(field_type, CTFWriter.FieldDeclaration):
1814 raise TypeError("Invalid field_type argument.")
1816 self._f = _bt_ctf_field_create(field_type._ft)
1818 raise ValueError("Field creation failed.")
1821 _bt_ctf_field_put(self._f)
1824 def _create_field_from_native_instance(native_field_instance):
1826 CTFTypeId.INTEGER : CTFWriter.IntegerField,
1827 CTFTypeId.FLOAT : CTFWriter.FloatFieldingPoint,
1828 CTFTypeId.ENUM : CTFWriter.EnumerationField,
1829 CTFTypeId.STRING : CTFWriter.StringField,
1830 CTFTypeId.STRUCT : CTFWriter.StructureField,
1831 CTFTypeId.VARIANT : CTFWriter.VariantField,
1832 CTFTypeId.ARRAY : CTFWriter.ArrayField,
1833 CTFTypeId.SEQUENCE : CTFWriter.SequenceField
1836 field_type = _bt_python_get_field_type(native_field_instance)
1837 if field_type == CTFTypeId.UNKNOWN:
1838 raise TypeError("Invalid field instance")
1840 field = CTFWriter.Field.__new__(CTFWriter.Field)
1841 field._f = native_field_instance
1842 field.__class__ = type_dict[field_type]
1845 class IntegerField(Field):
1847 Get an integer field's value.
1851 raise NotImplementedError("Getter not implemented.")
1854 Set an integer field's value.
1857 def value(self, value):
1858 signedness = _bt_python_field_integer_get_signedness(self._f)
1860 raise TypeError("Invalid integer instance.")
1863 ret = _bt_ctf_field_unsigned_integer_set_value(self._f, value)
1865 ret = _bt_ctf_field_signed_integer_set_value(self._f, value)
1868 raise ValueError("Could not set integer field value.")
1870 class EnumerationField(Field):
1872 Return the enumeration's underlying container field (an integer field).
1875 def container(self):
1876 container = CTFWriter.IntegerField.__new__(CTFWriter.IntegerField)
1877 container._f = _bt_ctf_field_enumeration_get_container(self._f)
1878 if container._f is None:
1879 raise TypeError("Invalid enumeration field type.")
1882 class FloatFieldingPoint(Field):
1884 Get a floating point field's value.
1888 raise NotImplementedError("Getter not implemented.")
1891 Set a floating point field's value.
1894 def value(self, value):
1895 ret = _bt_ctf_field_floating_point_set_value(self._f, float(value))
1897 raise ValueError("Could not set floating point field value.")
1899 class StructureField(Field):
1901 Get the structure's field corresponding to the provided field name.
1903 def field(self, field_name):
1904 native_instance = _bt_ctf_field_structure_get_field(self._f, str(field_name))
1905 if native_instance is None:
1906 raise ValueError("Invalid field_name provided.")
1907 return CTFWriter.Field._create_field_from_native_instance(native_instance)
1909 class VariantField(Field):
1911 Return the variant's selected field. The "tag" field is the selector enum field.
1913 def field(self, tag):
1914 native_instance = _bt_ctf_field_variant_get_field(self._f, tag._f)
1915 if native_instance is None:
1916 raise ValueError("Invalid tag provided.")
1917 return CTFWriter.Field._create_field_from_native_instance(native_instance)
1919 class ArrayField(Field):
1921 Return the array's field at position "index".
1923 def field(self, index):
1924 native_instance = _bt_ctf_field_array_get_field(self._f, index)
1925 if native_instance is None:
1926 raise IndexError("Invalid index provided.")
1927 return CTFWriter.Field._create_field_from_native_instance(native_instance)
1929 class SequenceField(Field):
1931 Get the sequence's length field (IntegerField).
1935 raise NotImplementedError("Getter not implemented.")
1938 Set the sequence's length field (IntegerField).
1941 def length(self, length_field):
1942 if not isinstance(length_field, CTFWriter.IntegerField):
1943 raise TypeError("Invalid length field.")
1944 ret = _bt_ctf_field_sequence_set_length(self._f, length_field._f)
1946 raise ValueError("Could not set sequence length.")
1949 Return the sequence's field at position "index".
1951 def field(self, index):
1952 native_instance = _bt_ctf_field_sequence_get_field(self._f, index)
1953 if native_instance is None:
1954 raise ValueError("Could not get sequence element at index.")
1955 return CTFWriter.Field._create_field_from_native_instance(native_instance)
1957 class StringField(Field):
1959 Get a string field's value.
1963 raise NotImplementedError("Getter not implemented.")
1966 Set a string field's value.
1969 def value(self, value):
1970 ret = _bt_ctf_field_string_set_value(self._f, str(value))
1972 raise ValueError("Could not set string field value.")
1976 Create a new event class of the given name.
1978 def __init__(self, name):
1979 self._ec = _bt_ctf_event_class_create(name)
1980 if self._ec is None:
1981 raise ValueError("Event class creation failed.")
1984 _bt_ctf_event_class_put(self._ec)
1987 Add a field of type "field_type" to the event class.
1989 def add_field(self, field_type, field_name):
1990 ret = _bt_ctf_event_class_add_field(self._ec, field_type._ft, str(field_name))
1992 raise ValueError("Could not add field to event class.")
1996 Create a new event of the given event class.
1998 def __init__(self, event_class):
1999 if not isinstance(event_class, CTFWriter.EventClass):
2000 raise TypeError("Invalid event_class argument.")
2002 self._e = _bt_ctf_event_create(event_class._ec)
2004 raise ValueError("Event creation failed.")
2007 _bt_ctf_event_put(self._e)
2010 Set a manually created field as an event's payload.
2012 def set_payload(self, field_name, value_field):
2013 if not isinstance(value, CTFWriter.Field):
2014 raise TypeError("Invalid value type.")
2015 ret = _bt_ctf_event_set_payload(self._e, str(field_name), value_field._f)
2017 raise ValueError("Could not set event field payload.")
2020 Get a field from event.
2022 def payload(self, field_name):
2023 native_instance = _bt_ctf_event_get_payload(self._e, str(field_name))
2024 if native_instance is None:
2025 raise ValueError("Could not get event payload.")
2026 return CTFWriter.Field._create_field_from_native_instance(native_instance)
2030 Create a new stream class of the given name.
2032 def __init__(self, name):
2033 self._sc = _bt_ctf_stream_class_create(name)
2034 if self._sc is None:
2035 raise ValueError("Stream class creation failed.")
2038 _bt_ctf_stream_class_put(self._sc)
2041 Get a stream class' clock.
2045 raise NotImplementedError("Getter not implemented.")
2048 Assign a clock to a stream class.
2051 def clock(self, clock):
2052 if not isinstance(clock, CTFWriter.Clock):
2053 raise TypeError("Invalid clock type.")
2055 ret = _bt_ctf_stream_class_set_clock(self._sc, clock._c)
2057 raise ValueError("Could not set stream class clock.")
2060 Add an event class to a stream class. New events can be added even after a
2061 stream has been instantiated and events have been appended. However, a stream
2062 will not accept events of a class that has not been registered beforehand.
2064 def add_event_class(self, event_class):
2065 if not isinstance(event_class, CTFWriter.EventClass):
2066 raise TypeError("Invalid event_class type.")
2068 ret = _bt_ctf_stream_class_add_event_class(self._sc, event_class._ec)
2070 raise ValueError("Could not add event class.")
2074 Create a stream of the given class.
2076 def __init__(self, stream_class):
2077 if not isinstance(stream_class, CTFWriter.StreamClass):
2078 raise TypeError("Invalid stream_class type.")
2080 self._s = _bt_ctf_stream_create(stream_class._sc)
2082 raise ValueError("Stream creation failed.")
2085 _bt_ctf_stream_put(self._s)
2088 Increase the current packet's discarded event count.
2090 def append_discarded_events(self, event_count):
2091 ret = _bt_ctf_stream_append_discarded_events(self._s, event_count)
2093 raise ValueError("Could not append discarded events.")
2096 Append "event" to the stream's current packet. The stream's associated clock
2097 will be sampled during this call. The event shall not be modified after
2098 being appended to a stream.
2100 def append_event(self, event):
2101 ret = _bt_ctf_stream_append_event(self._s, event._e)
2103 raise ValueError("Could not append event to stream.")
2106 The stream's current packet's events will be flushed to disk. Events
2107 subsequently appended to the stream will be added to a new packet.
2110 ret = _bt_ctf_stream_flush(self._s)
2112 raise ValueError("Could not flush stream.")
2116 Create a new writer that will produce a trace in the given path.
2118 def __init__(self, path):
2119 self._w = _bt_ctf_writer_create(path)
2121 raise ValueError("Writer creation failed.")
2124 _bt_ctf_writer_put(self._w)
2127 Create a new stream instance and register it to the writer.
2129 def create_stream(self, stream_class):
2130 if not isinstance(stream_class, CTFWriter.StreamClass):
2131 raise TypeError("Invalid stream_class type.")
2133 stream = CTFWriter.Stream.__new__(CTFWriter.Stream)
2134 stream._s = _bt_ctf_writer_create_stream(self._w, stream_class._sc)
2138 Add an environment field to the trace.
2140 def add_environment_field(self, name, value):
2141 ret = _bt_ctf_writer_add_environment_field(self._w, str(name), str(value))
2143 raise ValueError("Could not add environment field to trace.")
2146 Add a clock to the trace. Clocks assigned to stream classes must be
2147 registered to the writer.
2149 def add_clock(self, clock):
2150 ret = _bt_ctf_writer_add_clock(self._w, clock._c)
2152 raise ValueError("Could not add clock to Writer.")
2155 Get the trace's TSDL meta-data.
2159 return _bt_ctf_writer_get_metadata_string(self._w)
2162 Flush the trace's metadata to the metadata file.
2164 def flush_metadata(self):
2165 _bt_ctf_writer_flush_metadata(self._w)
2168 Get the trace's byte order. Must be a constant from the ByteOrder
2172 def byte_order(self):
2173 raise NotImplementedError("Getter not implemented.")
2176 Set the trace's byte order. Must be a constant from the ByteOrder
2177 class. Defaults to BYTE_ORDER_NATIVE, the host machine's endianness.
2180 def byte_order(self, byte_order):
2181 ret = _bt_ctf_writer_set_byte_order(self._w, byte_order)
2183 raise ValueError("Could not set trace's byte order.")