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);
104 /* =================================================================
105 CONTEXT.H, CONTEXT-INTERNAL.H
106 ¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯
109 %rename("_bt_context_create") bt_context_create(void);
110 %rename("_bt_context_add_trace") bt_context_add_trace(
111 struct bt_context *ctx, const char *path, const char *format,
112 void (*packet_seek)(struct bt_stream_pos *pos, size_t index, int whence),
113 struct bt_mmap_stream_list *stream_list, FILE *metadata);
114 %rename("_bt_context_remove_trace") bt_context_remove_trace(
115 struct bt_context *ctx, int trace_id);
116 %rename("_bt_context_get") bt_context_get(struct bt_context *ctx);
117 %rename("_bt_context_put") bt_context_put(struct bt_context *ctx);
118 %rename("_bt_ctf_event_get_context") bt_ctf_event_get_context(
119 const struct bt_ctf_event *event);
121 struct bt_context *bt_context_create(void);
122 int bt_context_add_trace(struct bt_context *ctx, const char *path, const char *format,
123 void (*packet_seek)(struct bt_stream_pos *pos, size_t index, int whence),
124 struct bt_mmap_stream_list *stream_list, FILE *metadata);
125 void bt_context_remove_trace(struct bt_context *ctx, int trace_id);
126 void bt_context_get(struct bt_context *ctx);
127 void bt_context_put(struct bt_context *ctx);
128 struct bt_context *bt_ctf_event_get_context(const struct bt_ctf_event *event);
130 // class TraceCollection to prevent direct access to struct bt_context
132 class TraceCollection:
134 The TraceCollection is the object that contains all currently opened traces.
138 self._tc = _bt_context_create()
141 _bt_context_put(self._tc)
143 def add_trace(self, path, format_str):
145 Add a trace by path to the TraceCollection.
149 path is the path to the trace, it is not recursive.
150 If "path" is None, stream_list is used instead as a list
151 of mmap streams to open for the trace.
153 format is a string containing the format name in which the trace was
156 Return: the corresponding TraceHandle on success or None on error.
158 ret = _bt_context_add_trace(self._tc, path, format_str, None, None, None)
162 th = TraceHandle.__new__(TraceHandle)
164 th._trace_collection = self
167 def add_traces_recursive(self, path, format_str):
169 Open a trace recursively.
171 Find each trace present in the subdirectory starting from the given
172 path, and add them to the TraceCollection.
174 Return a dict of TraceHandle instances (the full path is the key).
175 Return None on error.
185 for fullpath, dirs, files in os.walk(path):
186 if "metadata" in files:
187 trace_handle = self.add_trace(fullpath, format_str)
188 if trace_handle is None:
192 trace_handles[fullpath] = trace_handle
195 if noTrace and error:
199 def remove_trace(self, trace_handle):
201 Remove a trace from the TraceCollection.
202 Effectively closing the trace.
205 _bt_context_remove_trace(self._tc, trace_handle._id)
206 except AttributeError:
207 raise TypeError("in remove_trace, "
208 "argument 2 must be a TraceHandle instance")
213 Generator function to iterate over the events of open in the current
216 Due to limitations of the native Babeltrace API, only one event
217 may be "alive" at a time (i.e. a user should never store a copy
218 of the events returned by this function for ulterior use). Users
219 shall make sure to copy the information they need from an event
220 before accessing the next one.
222 Furthermore, event objects become invalid when the generator goes
223 out of scope as the underlying iterator will be reclaimed. Using an
224 event after the the generator has gone out of scope may result in a
225 crash or data corruption.
227 begin_pos_ptr = _bt_python_create_iter_pos()
228 end_pos_ptr = _bt_python_create_iter_pos()
229 begin_pos_ptr.type = SEEK_BEGIN
230 end_pos_ptr.type = SEEK_LAST
232 for event in self._events(begin_pos_ptr, end_pos_ptr):
235 _bt_iter_free_pos(begin_pos_ptr)
236 _bt_iter_free_pos(end_pos_ptr)
238 def events_timestamps(self, timestamp_begin, timestamp_end):
240 Generator function to iterate over the events of open in the current
241 TraceCollection from timestamp_begin to timestamp_end.
243 begin_pos_ptr = _bt_python_create_iter_pos()
244 end_pos_ptr = _bt_python_create_iter_pos()
245 begin_pos_ptr.type = end_pos_ptr.type = SEEK_TIME
246 begin_pos_ptr.u.seek_time = timestamp_begin
247 end_pos_ptr.u.seek_time = timestamp_end
249 for event in self._events(begin_pos_ptr, end_pos_ptr):
252 _bt_iter_free_pos(begin_pos_ptr)
253 _bt_iter_free_pos(end_pos_ptr)
256 def timestamp_begin(self):
257 pos_ptr = _bt_iter_pos()
258 pos_ptr.type = SEEK_BEGIN
259 return self._timestamp_at_pos(pos_ptr)
262 def timestamp_end(self):
263 pos_ptr = _bt_iter_pos()
264 pos_ptr.type = SEEK_LAST
265 return self._timestamp_at_pos(pos_ptr)
267 def _timestamp_at_pos(self, pos_ptr):
268 ctf_it_ptr = _bt_ctf_iter_create(self._tc, pos_ptr, pos_ptr)
269 if ctf_it_ptr is None:
270 raise NotImplementedError("Creation of multiple iterators is unsupported.")
271 ev_ptr = _bt_ctf_iter_read_event(ctf_it_ptr)
272 _bt_ctf_iter_destroy(ctf_it_ptr)
275 ev = Event.__new__(Event)
279 def _events(self, begin_pos_ptr, end_pos_ptr):
280 ctf_it_ptr = _bt_ctf_iter_create(self._tc, begin_pos_ptr, end_pos_ptr)
281 if ctf_it_ptr is None:
282 raise NotImplementedError(
283 "Creation of multiple iterators is unsupported.")
286 ev_ptr = _bt_ctf_iter_read_event(ctf_it_ptr)
290 ev = Event.__new__(Event)
294 except GeneratorExit:
297 ret = _bt_iter_next(_bt_ctf_get_iter(ctf_it_ptr))
301 _bt_ctf_iter_destroy(ctf_it_ptr)
307 /* =================================================================
312 %rename("lookup_format") bt_lookup_format(bt_intern_str qname);
313 %rename("_bt_print_format_list") bt_fprintf_format_list(FILE *fp);
314 %rename("register_format") bt_register_format(struct format *format);
315 %rename("unregister_format") bt_unregister_format(struct bt_format *format);
317 extern struct format *bt_lookup_format(bt_intern_str qname);
318 extern void bt_fprintf_format_list(FILE *fp);
319 extern int bt_register_format(struct bt_format *format);
320 extern void bt_unregister_format(struct bt_format *format);
324 def print_format_list(babeltrace_file):
326 Print a list of available formats to file.
328 babeltrace_file must be a File instance opened in write mode.
331 if babeltrace_file._file is not None:
332 _bt_print_format_list(babeltrace_file._file)
333 except AttributeError:
334 raise TypeError("in print_format_list, "
335 "argument 1 must be a File instance")
340 /* =================================================================
341 ITERATOR.H, ITERATOR-INTERNAL.H
342 ¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯
345 %rename("_bt_iter_create") bt_iter_create(struct bt_context *ctx,
346 const struct bt_iter_pos *begin_pos, const struct bt_iter_pos *end_pos);
347 %rename("_bt_iter_destroy") bt_iter_destroy(struct bt_iter *iter);
348 %rename("_bt_iter_next") bt_iter_next(struct bt_iter *iter);
349 %rename("_bt_iter_get_pos") bt_iter_get_pos(struct bt_iter *iter);
350 %rename("_bt_iter_free_pos") bt_iter_free_pos(struct bt_iter_pos *pos);
351 %rename("_bt_iter_set_pos") bt_iter_set_pos(struct bt_iter *iter,
352 const struct bt_iter_pos *pos);
353 %rename("_bt_iter_create_time_pos") bt_iter_create_time_pos(struct bt_iter *iter,
356 struct bt_iter *bt_iter_create(struct bt_context *ctx,
357 const struct bt_iter_pos *begin_pos, const struct bt_iter_pos *end_pos);
358 void bt_iter_destroy(struct bt_iter *iter);
359 int bt_iter_next(struct bt_iter *iter);
360 struct bt_iter_pos *bt_iter_get_pos(struct bt_iter *iter);
361 void bt_iter_free_pos(struct bt_iter_pos *pos);
362 int bt_iter_set_pos(struct bt_iter *iter, const struct bt_iter_pos *pos);
363 struct bt_iter_pos *bt_iter_create_time_pos(struct bt_iter *iter, uint64_t timestamp);
365 %rename("_bt_iter_pos") bt_iter_pos;
366 %rename("SEEK_TIME") BT_SEEK_TIME;
367 %rename("SEEK_RESTORE") BT_SEEK_RESTORE;
368 %rename("SEEK_CUR") BT_SEEK_CUR;
369 %rename("SEEK_BEGIN") BT_SEEK_BEGIN;
370 %rename("SEEK_LAST") BT_SEEK_LAST;
372 // This struct is taken from iterator.h
373 // All changes to the struct must also be made here
376 BT_SEEK_TIME, /* uses u.seek_time */
377 BT_SEEK_RESTORE, /* uses u.restore */
384 struct bt_saved_pos *restore;
388 /* =================================================================
389 TRACE-HANDLE.H, TRACE-HANDLE-INTERNAL.H
390 ¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯
393 %rename("_bt_trace_handle_create") bt_trace_handle_create(struct bt_context *ctx);
394 %rename("_bt_trace_handle_destroy") bt_trace_handle_destroy(struct bt_trace_handle *bt);
395 struct bt_trace_handle *bt_trace_handle_create(struct bt_context *ctx);
396 void bt_trace_handle_destroy(struct bt_trace_handle *bt);
398 %rename("_bt_trace_handle_get_path") bt_trace_handle_get_path(struct bt_context *ctx,
400 %rename("_bt_trace_handle_get_timestamp_begin") bt_trace_handle_get_timestamp_begin(
401 struct bt_context *ctx, int handle_id, enum bt_clock_type type);
402 %rename("_bt_trace_handle_get_timestamp_end") bt_trace_handle_get_timestamp_end(
403 struct bt_context *ctx, int handle_id, enum bt_clock_type type);
404 const char *bt_trace_handle_get_path(struct bt_context *ctx, int handle_id);
405 uint64_t bt_trace_handle_get_timestamp_begin(struct bt_context *ctx, int handle_id,
406 enum bt_clock_type type);
407 uint64_t bt_trace_handle_get_timestamp_end(struct bt_context *ctx, int handle_id,
408 enum bt_clock_type type);
410 %rename("_bt_ctf_event_get_handle_id") bt_ctf_event_get_handle_id(
411 const struct bt_ctf_event *event);
412 int bt_ctf_event_get_handle_id(const struct bt_ctf_event *event);
417 # Based on enum bt_clock_type in clock-type.h
422 class TraceHandle(object):
424 The TraceHandle allows the user to manipulate a trace file directly.
425 It is a unique identifier representing a trace file.
430 raise NotImplementedError("TraceHandle cannot be instantiated")
433 return "Babeltrace TraceHandle: trace_id('{0}')".format(self._id)
437 """Return the TraceHandle id."""
442 """Return the path of a TraceHandle."""
443 return _bt_trace_handle_get_path(self._trace_collection._tc, self._id)
446 def timestamp_begin(self):
447 """Return the creation time of the buffers of a trace."""
448 return _bt_trace_handle_get_timestamp_begin(
449 self._trace_collection._tc, self._id, ClockType.CLOCK_REAL)
452 def timestamp_end(self):
453 """Return the destruction timestamp of the buffers of a trace."""
454 return _bt_trace_handle_get_timestamp_end(
455 self._trace_collection._tc, self._id, ClockType.CLOCK_REAL)
460 Generator returning all events (EventDeclaration) in a trace.
462 ret = _bt_python_event_decl_listcaller(self.id, self._trace_collection._tc)
464 if not isinstance(ret, list):
467 ptr_list, count = ret
468 for i in range(count):
469 tmp = EventDeclaration.__new__(EventDeclaration)
470 tmp._ed = _bt_python_decl_one_from_list(ptr_list, i)
477 // =================================================================
479 // =================================================================
481 /* =================================================================
487 %rename("_bt_ctf_iter_create") bt_ctf_iter_create(struct bt_context *ctx,
488 const struct bt_iter_pos *begin_pos,
489 const struct bt_iter_pos *end_pos);
490 %rename("_bt_ctf_get_iter") bt_ctf_get_iter(struct bt_ctf_iter *iter);
491 %rename("_bt_ctf_iter_destroy") bt_ctf_iter_destroy(struct bt_ctf_iter *iter);
492 %rename("_bt_ctf_iter_read_event") bt_ctf_iter_read_event(struct bt_ctf_iter *iter);
494 struct bt_ctf_iter *bt_ctf_iter_create(struct bt_context *ctx,
495 const struct bt_iter_pos *begin_pos,
496 const struct bt_iter_pos *end_pos);
497 struct bt_iter *bt_ctf_get_iter(struct bt_ctf_iter *iter);
498 void bt_ctf_iter_destroy(struct bt_ctf_iter *iter);
499 struct bt_ctf_event *bt_ctf_iter_read_event(struct bt_ctf_iter *iter);
503 %rename("_bt_ctf_get_top_level_scope") bt_ctf_get_top_level_scope(const struct
504 bt_ctf_event *event, enum bt_ctf_scope scope);
505 %rename("_bt_ctf_event_name") bt_ctf_event_name(const struct bt_ctf_event *ctf_event);
506 %rename("_bt_ctf_get_timestamp") bt_ctf_get_timestamp(
507 const struct bt_ctf_event *ctf_event);
508 %rename("_bt_ctf_get_cycles") bt_ctf_get_cycles(
509 const struct bt_ctf_event *ctf_event);
511 %rename("_bt_ctf_get_field") bt_ctf_get_field(const struct bt_ctf_event *ctf_event,
512 const struct bt_definition *scope, const char *field);
513 %rename("_bt_ctf_get_index") bt_ctf_get_index(const struct bt_ctf_event *ctf_event,
514 const struct bt_definition *field, unsigned int index);
515 %rename("_bt_ctf_field_name") bt_ctf_field_name(const struct bt_definition *field);
516 %rename("_bt_ctf_field_type") bt_ctf_field_type(const struct bt_declaration *field);
517 %rename("_bt_ctf_get_int_signedness") bt_ctf_get_int_signedness(
518 const struct bt_declaration *field);
519 %rename("_bt_ctf_get_int_base") bt_ctf_get_int_base(const struct bt_declaration *field);
520 %rename("_bt_ctf_get_int_byte_order") bt_ctf_get_int_byte_order(
521 const struct bt_declaration *field);
522 %rename("_bt_ctf_get_int_len") bt_ctf_get_int_len(const struct bt_declaration *field);
523 %rename("_bt_ctf_get_enum_int") bt_ctf_get_enum_int(const struct bt_definition *field);
524 %rename("_bt_ctf_get_enum_str") bt_ctf_get_enum_str(const struct bt_definition *field);
525 %rename("_bt_ctf_get_encoding") bt_ctf_get_encoding(const struct bt_declaration *field);
526 %rename("_bt_ctf_get_array_len") bt_ctf_get_array_len(const struct bt_declaration *field);
527 %rename("_bt_ctf_get_uint64") bt_ctf_get_uint64(const struct bt_definition *field);
528 %rename("_bt_ctf_get_int64") bt_ctf_get_int64(const struct bt_definition *field);
529 %rename("_bt_ctf_get_char_array") bt_ctf_get_char_array(const struct bt_definition *field);
530 %rename("_bt_ctf_get_string") bt_ctf_get_string(const struct bt_definition *field);
531 %rename("_bt_ctf_get_float") bt_ctf_get_float(const struct bt_definition *field);
532 %rename("_bt_ctf_get_variant") bt_ctf_get_variant(const struct bt_definition *field);
533 %rename("_bt_ctf_field_get_error") bt_ctf_field_get_error(void);
534 %rename("_bt_ctf_get_decl_event_name") bt_ctf_get_decl_event_name(const struct
535 bt_ctf_event_decl *event);
536 %rename("_bt_ctf_get_decl_field_name") bt_ctf_get_decl_field_name(
537 const struct bt_ctf_field_decl *field);
538 %rename("_bt_ctf_get_decl_from_def") bt_ctf_get_decl_from_def(
539 const struct bt_definition *field);
540 %rename("_bt_ctf_get_decl_from_field_decl") bt_ctf_get_decl_from_field_decl(
541 const struct bt_ctf_field_decl *field);
542 %rename("_bt_array_index") bt_array_index(struct definition_array *array, uint64_t i);
543 %rename("_bt_sequence_len") bt_sequence_len(struct definition_sequence *sequence);
544 %rename("_bt_sequence_index") bt_sequence_index(struct definition_sequence *sequence, uint64_t i);
545 %rename("_bt_ctf_get_struct_field_count") bt_ctf_get_struct_field_count(const struct bt_definition *structure);
546 %rename("_bt_ctf_get_struct_field_index") bt_ctf_get_struct_field_index(const struct bt_definition *structure, uint64_t i);
548 const struct bt_definition *bt_ctf_get_top_level_scope(const struct bt_ctf_event *ctf_event,
549 enum bt_ctf_scope scope);
550 const char *bt_ctf_event_name(const struct bt_ctf_event *ctf_event);
551 uint64_t bt_ctf_get_timestamp(const struct bt_ctf_event *ctf_event);
552 uint64_t bt_ctf_get_cycles(const struct bt_ctf_event *ctf_event);
553 const struct bt_definition *bt_ctf_get_field(const struct bt_ctf_event *ctf_event,
554 const struct bt_definition *scope,
556 const struct bt_definition *bt_ctf_get_index(const struct bt_ctf_event *ctf_event,
557 const struct bt_definition *field,
559 const char *bt_ctf_field_name(const struct bt_definition *field);
560 enum ctf_type_id bt_ctf_field_type(const struct bt_declaration *field);
561 int bt_ctf_get_int_signedness(const struct bt_declaration *field);
562 int bt_ctf_get_int_base(const struct bt_declaration *field);
563 int bt_ctf_get_int_byte_order(const struct bt_declaration *field);
564 ssize_t bt_ctf_get_int_len(const struct bt_declaration *field);
565 const struct bt_definition *bt_ctf_get_enum_int(const struct bt_definition *field);
566 const char *bt_ctf_get_enum_str(const struct bt_definition *field);
567 enum ctf_string_encoding bt_ctf_get_encoding(const struct bt_declaration *field);
568 int bt_ctf_get_array_len(const struct bt_declaration *field);
569 struct bt_definition *bt_array_index(struct definition_array *array, uint64_t i);
570 uint64_t bt_ctf_get_uint64(const struct bt_definition *field);
571 int64_t bt_ctf_get_int64(const struct bt_definition *field);
572 char *bt_ctf_get_char_array(const struct bt_definition *field);
573 char *bt_ctf_get_string(const struct bt_definition *field);
574 double bt_ctf_get_float(const struct bt_definition *field);
575 const struct bt_definition *bt_ctf_get_variant(const struct bt_definition *field);
576 int bt_ctf_field_get_error(void);
577 const char *bt_ctf_get_decl_event_name(const struct bt_ctf_event_decl *event);
578 const char *bt_ctf_get_decl_field_name(const struct bt_ctf_field_decl *field);
579 const struct bt_declaration *bt_ctf_get_decl_from_def(const struct bt_definition *field);
580 const struct bt_declaration *bt_ctf_get_decl_from_field_decl(const struct bt_ctf_field_decl *field);
581 uint64_t bt_sequence_len(struct definition_sequence *sequence);
582 struct bt_definition *bt_sequence_index(struct definition_sequence *sequence, uint64_t i);
583 uint64_t bt_ctf_get_struct_field_count(const struct bt_definition *structure);
584 const struct bt_definition *bt_ctf_get_struct_field_index(const struct bt_definition *structure, uint64_t i);
588 class CTFStringEncoding:
594 # Based on the enum in ctf-writer/writer.h
596 BYTE_ORDER_NATIVE = 0
597 BYTE_ORDER_LITTLE_ENDIAN = 1
598 BYTE_ORDER_BIG_ENDIAN = 2
599 BYTE_ORDER_NETWORK = 3
600 BYTE_ORDER_UNKNOWN = 4 # Python-specific entry
602 #enum equivalent, accessible constants
603 #These are taken directly from ctf/events.h
604 #All changes to enums must also be made here
619 name = "UNKNOWN_TYPE"
620 constants = [attr for attr in dir(CTFTypeId) if not callable(getattr(CTFTypeId, attr)) and not attr.startswith("__")]
621 for attr in constants:
622 if getattr(CTFTypeId, attr) == id:
628 TRACE_PACKET_HEADER = 0
629 STREAM_PACKET_CONTEXT = 1
630 STREAM_EVENT_HEADER = 2
631 STREAM_EVENT_CONTEXT = 3
635 def scope_name(scope):
636 name = "UNKNOWN_SCOPE"
637 constants = [attr for attr in dir(CTFScope) if not callable(getattr(CTFScope, attr)) and not attr.startswith("__")]
638 for attr in constants:
639 if getattr(CTFScope, attr) == scope:
644 # Priority of the scopes when searching for event fields
645 _scopes = [CTFScope.EVENT_FIELDS, CTFScope.EVENT_CONTEXT, CTFScope.STREAM_EVENT_CONTEXT,
646 CTFScope.STREAM_EVENT_HEADER, CTFScope.STREAM_PACKET_CONTEXT, CTFScope.TRACE_PACKET_HEADER]
649 class Event(collections.Mapping):
651 This class represents an event from the trace.
652 It is obtained using the TraceCollection generator functions.
656 raise NotImplementedError("Event cannot be instantiated")
660 """Return the name of the event or None on error."""
661 return _bt_ctf_event_name(self._e)
666 Return the timestamp of the event as written in
667 the packet (in cycles) or -1ULL on error.
669 return _bt_ctf_get_cycles(self._e)
674 Return the timestamp of the event offset with the
675 system clock source or -1ULL on error.
677 return _bt_ctf_get_timestamp(self._e)
679 def field_with_scope(self, field_name, scope):
681 Get field_name's value in scope.
682 None is returned if no field matches field_name.
684 if not scope in _scopes:
685 raise ValueError("Invalid scope provided")
686 field = self._field_with_scope(field_name, scope)
687 if field is not None:
691 def field_list_with_scope(self, scope):
692 """Return a list of field names in scope."""
693 if not scope in _scopes:
694 raise ValueError("Invalid scope provided")
696 for field in self._field_list_with_scope(scope):
697 field_names.append(field.name)
703 Get the TraceHandle associated with this event
706 ret = _bt_ctf_event_get_handle_id(self._e)
710 th = TraceHandle.__new__(TraceHandle)
712 th._trace_collection = self.get_trace_collection()
716 def trace_collection(self):
718 Get the TraceCollection associated with this event.
719 Return None on error.
721 trace_collection = TraceCollection()
722 trace_collection._tc = _bt_ctf_event_get_context(self._e);
723 if trace_collection._tc is None:
726 return trace_collection
728 def __getitem__(self, field_name):
730 Get field_name's value. If the field_name exists in multiple
731 scopes, the first field found is returned. The scopes are searched
732 in the following order:
735 3) STREAM_EVENT_CONTEXT
736 4) STREAM_EVENT_HEADER
737 5) STREAM_PACKET_CONTEXT
738 6) TRACE_PACKET_HEADER
739 None is returned if no field matches field_name.
741 Use field_with_scope() to explicitly access fields in a given
744 field = self._field(field_name)
745 if field is not None:
747 raise KeyError(field_name)
750 for key in self.keys():
755 for scope in _scopes:
756 scope_ptr = _bt_ctf_get_top_level_scope(self._e, scope)
757 ret = _bt_python_field_listcaller(self._e, scope_ptr)
758 if isinstance(ret, list):
762 def __contains__(self, field_name):
763 return self._field(field_name) is not None
766 """Return a list of field names."""
768 for scope in _scopes:
769 for name in self.field_list_with_scope(scope):
770 field_names.add(name)
771 return list(field_names)
773 def get(self, field_name, default = None):
774 field = self._field(field_name)
780 for field in self.keys():
781 yield (field, self[field])
783 def _field_with_scope(self, field_name, scope):
784 scope_ptr = _bt_ctf_get_top_level_scope(self._e, scope)
785 if scope_ptr is None:
788 definition_ptr = _bt_ctf_get_field(self._e, scope_ptr, field_name)
789 if definition_ptr is None:
792 field = _Definition(definition_ptr, scope)
795 def _field(self, field_name):
797 for scope in _scopes:
798 field = self._field_with_scope(field_name, scope)
799 if field is not None:
803 def _field_list_with_scope(self, scope):
805 scope_ptr = _bt_ctf_get_top_level_scope(self._e, scope)
807 # Returns a list [list_ptr, count]. If list_ptr is NULL, SWIG will only
808 # provide the "count" return value
811 ret = _bt_python_field_listcaller(self._e, scope_ptr)
812 if isinstance(ret, list):
813 list_ptr, count = ret
815 for i in range(count):
816 definition_ptr = _bt_python_field_one_from_list(list_ptr, i)
817 if definition_ptr is not None:
818 definition = _Definition(definition_ptr, scope)
819 fields.append(definition)
822 class FieldError(Exception):
823 def __init__(self, value):
827 return repr(self.value)
829 class EventDeclaration(object):
830 """Event declaration class. Do not instantiate."""
833 raise NotImplementedError("EventDeclaration cannot be instantiated")
837 """Return the name of the event or None on error"""
838 return _bt_ctf_get_decl_event_name(self._ed)
843 Generator returning all FieldDeclarations of an event, going through
844 each scope in the following order:
847 3) STREAM_EVENT_CONTEXT
848 4) STREAM_EVENT_HEADER
849 5) STREAM_PACKET_CONTEXT
850 6) TRACE_PACKET_HEADER
852 for scope in _scopes:
853 for declaration in self.fields_scope(scope):
856 def fields_scope(self, scope):
858 Generator returning FieldDeclarations of the current event in scope.
860 ret = _by_python_field_decl_listcaller(self._ed, scope)
862 if not isinstance(ret, list):
865 list_ptr, count = ret
866 for i in range(count):
867 field_declaration_ptr = _bt_python_field_decl_one_from_list(list_ptr, i)
868 if field_declaration_ptr is not None:
869 declaration_ptr = _bt_ctf_get_decl_from_field_decl(field_declaration_ptr)
870 field_declaration = _create_field_declaration(declaration_ptr, _bt_ctf_get_decl_field_name(field_declaration_ptr), scope)
871 yield field_declaration
873 class FieldDeclaration(object):
874 """Field declaration class. Do not instantiate."""
876 raise NotImplementedError("FieldDeclaration cannot be instantiated")
879 return "({0}) {1} {2}".format(CTFScope.scope_name(self.scope), CTFTypeId.type_name(self.type), self.name)
883 """Return the name of a FieldDeclaration or None on error."""
889 Return the FieldDeclaration's type. One of the entries in class
892 return _bt_ctf_field_type(self._fd)
897 Return the FieldDeclaration's scope.
901 class IntegerFieldDeclaration(FieldDeclaration):
902 """Do not instantiate."""
904 raise NotImplementedError("IntegerFieldDeclaration cannot be instantiated")
907 def signedness(self):
909 Return the signedness of an integer:
910 0 if unsigned; 1 if signed; -1 on error.
912 return _bt_ctf_get_int_signedness(self._fd)
916 """Return the base of an int or a negative value on error."""
917 return _bt_ctf_get_int_base(self._fd)
920 def byte_order(self):
922 Return the byte order. One of class ByteOrder's entries.
924 ret = _bt_ctf_get_int_byte_order(self._fd)
926 return ByteOrder.BYTE_ORDER_LITTLE_ENDIAN
928 return ByteOrder.BYTE_ORDER_BIG_ENDIAN
930 return ByteOrder.BYTE_ORDER_UNKNOWN
935 Return the size, in bits, of an int or a negative
938 return _bt_ctf_get_int_len(self._fd)
943 Return the encoding. One of class CTFStringEncoding's entries.
944 Return a negative value on error.
946 return _bt_ctf_get_encoding(self._fd)
948 class EnumerationFieldDeclaration(FieldDeclaration):
949 """Do not instantiate."""
951 raise NotImplementedError("EnumerationFieldDeclaration cannot be instantiated")
953 class ArrayFieldDeclaration(FieldDeclaration):
954 """Do not instantiate."""
956 raise NotImplementedError("ArrayFieldDeclaration cannot be instantiated")
961 Return the length of an array or a negative
964 return _bt_ctf_get_array_len(self._fd)
967 def element_declaration(self):
969 Return element declaration.
971 field_decl_ptr = _bt_python_get_array_element_declaration(self._fd)
972 return _create_field_declaration(field_decl_ptr, "", self.scope)
974 class SequenceFieldDeclaration(FieldDeclaration):
975 """Do not instantiate."""
977 raise NotImplementedError("SequenceFieldDeclaration cannot be instantiated")
980 def element_declaration(self):
982 Return element declaration.
984 field_decl_ptr = _bt_python_get_sequence_element_declaration(self._fd)
985 return _create_field_declaration(field_decl_ptr, "", self.scope)
987 class FloatFieldDeclaration(FieldDeclaration):
988 """Do not instantiate."""
990 raise NotImplementedError("FloatFieldDeclaration cannot be instantiated")
992 class StructureFieldDeclaration(FieldDeclaration):
993 """Do not instantiate."""
995 raise NotImplementedError("StructureFieldDeclaration cannot be instantiated")
997 class StringFieldDeclaration(FieldDeclaration):
998 """Do not instantiate."""
1000 raise NotImplementedError("StringFieldDeclaration cannot be instantiated")
1002 class VariantFieldDeclaration(FieldDeclaration):
1003 """Do not instantiate."""
1005 raise NotImplementedError("VariantFieldDeclaration cannot be instantiated")
1009 Return the last error code encountered while
1010 accessing a field and reset the error flag.
1011 Return 0 if no error, a negative value otherwise.
1013 return _bt_ctf_field_get_error()
1015 def _create_field_declaration(declaration_ptr, name, scope):
1017 Private field declaration factory.
1019 if declaration_ptr is None:
1020 raise ValueError("declaration_ptr must be valid")
1021 if not scope in _scopes:
1022 raise ValueError("Invalid scope provided")
1024 type = _bt_ctf_field_type(declaration_ptr)
1026 if type == CTFTypeId.INTEGER:
1027 declaration = IntegerFieldDeclaration.__new__(IntegerFieldDeclaration)
1028 elif type == CTFTypeId.ENUM:
1029 declaration = EnumerationFieldDeclaration.__new__(EnumerationFieldDeclaration)
1030 elif type == CTFTypeId.ARRAY:
1031 declaration = ArrayFieldDeclaration.__new__(ArrayFieldDeclaration)
1032 elif type == CTFTypeId.SEQUENCE:
1033 declaration = SequenceFieldDeclaration.__new__(SequenceFieldDeclaration)
1034 elif type == CTFTypeId.FLOAT:
1035 declaration = FloatFieldDeclaration.__new__(FloatFieldDeclaration)
1036 elif type == CTFTypeId.STRUCT:
1037 declaration = StructureFieldDeclaration.__new__(StructureFieldDeclaration)
1038 elif type == CTFTypeId.STRING:
1039 declaration = StringFieldDeclaration.__new__(StringFieldDeclaration)
1040 elif type == CTFTypeId.VARIANT:
1041 declaration = VariantFieldDeclaration.__new__(VariantFieldDeclaration)
1045 declaration._fd = declaration_ptr
1046 declaration._s = scope
1047 declaration._name = name
1050 class _Definition(object):
1051 def __init__(self, definition_ptr, scope):
1052 self._d = definition_ptr
1054 if not scope in _scopes:
1055 ValueError("Invalid scope provided")
1059 """Return the name of a field or None on error."""
1060 return _bt_ctf_field_name(self._d)
1064 """Return the type of a field or -1 if unknown."""
1065 return _bt_ctf_field_type(_bt_ctf_get_decl_from_def(self._d))
1068 def declaration(self):
1069 """Return the associated Definition object."""
1070 return _create_field_declaration(_bt_ctf_get_decl_from_def(self._d), self.name, self.scope)
1072 def _get_enum_str(self):
1074 Return the string matching the current enumeration.
1075 Return None on error.
1077 return _bt_ctf_get_enum_str(self._d)
1079 def _get_array_element_at(self, index):
1081 Return the array's element at position index.
1082 Return None on error
1084 array_ptr = _bt_python_get_array_from_def(self._d)
1085 if array_ptr is None:
1088 definition_ptr = _bt_array_index(array_ptr, index)
1089 if definition_ptr is None:
1091 return _Definition(definition_ptr, self.scope)
1093 def _get_sequence_len(self):
1095 Return the len of a sequence or a negative
1098 seq = _bt_python_get_sequence_from_def(self._d)
1099 return _bt_sequence_len(seq)
1101 def _get_sequence_element_at(self, index):
1103 Return the sequence's element at position index,
1104 otherwise return None
1106 seq = _bt_python_get_sequence_from_def(self._d)
1108 definition_ptr = _bt_sequence_index(seq, index)
1109 if definition_ptr is not None:
1110 return _Definition(definition_ptr, self.scope)
1113 def _get_uint64(self):
1115 Return the value associated with the field.
1116 If the field does not exist or is not of the type requested,
1117 the value returned is undefined. To check if an error occured,
1118 use the field_error() function after accessing a field.
1120 return _bt_ctf_get_uint64(self._d)
1122 def _get_int64(self):
1124 Return the value associated with the field.
1125 If the field does not exist or is not of the type requested,
1126 the value returned is undefined. To check if an error occured,
1127 use the field_error() function after accessing a field.
1129 return _bt_ctf_get_int64(self._d)
1131 def _get_char_array(self):
1133 Return the value associated with the field.
1134 If the field does not exist or is not of the type requested,
1135 the value returned is undefined. To check if an error occurred,
1136 use the field_error() function after accessing a field.
1138 return _bt_ctf_get_char_array(self._d)
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 occurred,
1145 use the field_error() function after accessing a field.
1147 return _bt_ctf_get_string(self._d)
1149 def _get_float(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 occurred,
1154 use the field_error() function after accessing a field.
1156 return _bt_ctf_get_float(self._d)
1158 def _get_variant(self):
1160 Return the variant's selected 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_variant(self._d)
1167 def _get_struct_field_count(self):
1169 Return the number of fields contained in the structure.
1170 If the field does not exist or is not of the type requested,
1171 the value returned is undefined.
1173 return _bt_ctf_get_struct_field_count(self._d)
1175 def _get_struct_field_at(self, i):
1177 Return the structure's field at position i.
1178 If the field does not exist or is not of the type requested,
1179 the value returned is undefined. To check if an error occurred,
1180 use the field_error() function after accessing a field.
1182 return _bt_ctf_get_struct_field_index(self._d, i)
1187 Return the value associated with the field according to its type.
1188 Return None on error.
1193 if id == CTFTypeId.STRING:
1194 value = self._get_str()
1195 elif id == CTFTypeId.ARRAY:
1196 element_decl = self.declaration.element_declaration
1197 if ((element_decl.type == CTFTypeId.INTEGER
1198 and element_decl.length == 8)
1199 and (element_decl.encoding == CTFStringEncoding.ASCII or element_decl.encoding == CTFStringEncoding.UTF8)):
1200 value = _bt_python_get_array_string(self._d)
1203 for i in range(self.declaration.length):
1204 element = self._get_array_element_at(i)
1205 value.append(element.value)
1206 elif id == CTFTypeId.INTEGER:
1207 if self.declaration.signedness == 0:
1208 value = self._get_uint64()
1210 value = self._get_int64()
1211 elif id == CTFTypeId.ENUM:
1212 value = self._get_enum_str()
1213 elif id == CTFTypeId.SEQUENCE:
1214 element_decl = self.declaration.element_declaration
1215 if ((element_decl.type == CTFTypeId.INTEGER
1216 and element_decl.length == 8)
1217 and (element_decl.encoding == CTFStringEncoding.ASCII or element_decl.encoding == CTFStringEncoding.UTF8)):
1218 value = _bt_python_get_sequence_string(self._d)
1220 seq_len = self._get_sequence_len()
1222 for i in range(seq_len):
1223 evDef = self._get_sequence_element_at(i)
1224 value.append(evDef.value)
1225 elif id == CTFTypeId.FLOAT:
1226 value = self._get_float()
1227 elif id == CTFTypeId.VARIANT:
1228 variant = _Definition.__new__(_Definition)
1229 variant._d = self._get_variant();
1230 value = variant.value
1231 elif id == CTFTypeId.STRUCT:
1233 for i in range(self._get_struct_field_count()):
1234 member = _Definition(self._get_struct_field_at(i), self.scope)
1235 value[member.name] = member.value
1238 raise FieldError("Error occurred while accessing field {} of type {}".format(self.name, CTFTypeId.type_name(id)))
1243 """Return the scope of a field or None on error."""
1249 // =================================================================
1251 // =================================================================
1253 /* =================================================================
1255 ¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯
1257 %rename("_bt_ctf_clock_create") bt_ctf_clock_create(const char *name);
1258 %rename("_bt_ctf_clock_set_description") bt_ctf_clock_set_description(struct bt_ctf_clock *clock, const char *desc);
1259 %rename("_bt_ctf_clock_set_frequency") bt_ctf_clock_set_frequency(struct bt_ctf_clock *clock, uint64_t freq);
1260 %rename("_bt_ctf_clock_set_precision") bt_ctf_clock_set_precision(struct bt_ctf_clock *clock, uint64_t precision);
1261 %rename("_bt_ctf_clock_set_offset_s") bt_ctf_clock_set_offset_s(struct bt_ctf_clock *clock, uint64_t offset_s);
1262 %rename("_bt_ctf_clock_set_offset") bt_ctf_clock_set_offset(struct bt_ctf_clock *clock, uint64_t offset);
1263 %rename("_bt_ctf_clock_set_is_absolute") bt_ctf_clock_set_is_absolute(struct bt_ctf_clock *clock, int is_absolute);
1264 %rename("_bt_ctf_clock_set_time") bt_ctf_clock_set_time(struct bt_ctf_clock *clock, uint64_t time);
1265 %rename("_bt_ctf_clock_get") bt_ctf_clock_get(struct bt_ctf_clock *clock);
1266 %rename("_bt_ctf_clock_put") bt_ctf_clock_put(struct bt_ctf_clock *clock);
1268 struct bt_ctf_clock *bt_ctf_clock_create(const char *name);
1269 int bt_ctf_clock_set_description(struct bt_ctf_clock *clock, const char *desc);
1270 int bt_ctf_clock_set_frequency(struct bt_ctf_clock *clock, uint64_t freq);
1271 int bt_ctf_clock_set_precision(struct bt_ctf_clock *clock, uint64_t precision);
1272 int bt_ctf_clock_set_offset_s(struct bt_ctf_clock *clock, uint64_t offset_s);
1273 int bt_ctf_clock_set_offset(struct bt_ctf_clock *clock, uint64_t offset);
1274 int bt_ctf_clock_set_is_absolute(struct bt_ctf_clock *clock, int is_absolute);
1275 int bt_ctf_clock_set_time(struct bt_ctf_clock *clock, uint64_t time);
1276 void bt_ctf_clock_get(struct bt_ctf_clock *clock);
1277 void bt_ctf_clock_put(struct bt_ctf_clock *clock);
1279 /* =================================================================
1281 ¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯
1283 %rename("_bt_ctf_field_type_integer_create") bt_ctf_field_type_integer_create(unsigned int size);
1284 %rename("_bt_ctf_field_type_integer_set_signed") bt_ctf_field_type_integer_set_signed(struct bt_ctf_field_type *integer, int is_signed);
1285 %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);
1286 %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);
1287 %rename("_bt_ctf_field_type_enumeration_create") bt_ctf_field_type_enumeration_create(struct bt_ctf_field_type *integer_container_type);
1288 %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);
1289 %rename("_bt_ctf_field_type_floating_point_create") bt_ctf_field_type_floating_point_create(void);
1290 %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);
1291 %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);
1292 %rename("_bt_ctf_field_type_structure_create") bt_ctf_field_type_structure_create(void);
1293 %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);
1294 %rename("_bt_ctf_field_type_variant_create") bt_ctf_field_type_variant_create(struct bt_ctf_field_type *enum_tag, const char *tag_name);
1295 %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);
1296 %rename("_bt_ctf_field_type_array_create") bt_ctf_field_type_array_create(struct bt_ctf_field_type *element_type, unsigned int length);
1297 %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);
1298 %rename("_bt_ctf_field_type_string_create") bt_ctf_field_type_string_create(void);
1299 %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);
1300 %rename("_bt_ctf_field_type_set_alignment") bt_ctf_field_type_set_alignment(struct bt_ctf_field_type *type, unsigned int alignment);
1301 %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);
1302 %rename("_bt_ctf_field_type_get") bt_ctf_field_type_get(struct bt_ctf_field_type *type);
1303 %rename("_bt_ctf_field_type_put") bt_ctf_field_type_put(struct bt_ctf_field_type *type);
1305 struct bt_ctf_field_type *bt_ctf_field_type_integer_create(unsigned int size);
1306 int bt_ctf_field_type_integer_set_signed(struct bt_ctf_field_type *integer, int is_signed);
1307 int bt_ctf_field_type_integer_set_base(struct bt_ctf_field_type *integer, enum bt_ctf_integer_base base);
1308 int bt_ctf_field_type_integer_set_encoding(struct bt_ctf_field_type *integer, enum ctf_string_encoding encoding);
1309 struct bt_ctf_field_type *bt_ctf_field_type_enumeration_create(struct bt_ctf_field_type *integer_container_type);
1310 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);
1311 struct bt_ctf_field_type *bt_ctf_field_type_floating_point_create(void);
1312 int bt_ctf_field_type_floating_point_set_exponent_digits(struct bt_ctf_field_type *floating_point, unsigned int exponent_digits);
1313 int bt_ctf_field_type_floating_point_set_mantissa_digits(struct bt_ctf_field_type *floating_point, unsigned int mantissa_digits);
1314 struct bt_ctf_field_type *bt_ctf_field_type_structure_create(void);
1315 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);
1316 struct bt_ctf_field_type *bt_ctf_field_type_variant_create(struct bt_ctf_field_type *enum_tag, const char *tag_name);
1317 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);
1318 struct bt_ctf_field_type *bt_ctf_field_type_array_create(struct bt_ctf_field_type *element_type, unsigned int length);
1319 struct bt_ctf_field_type *bt_ctf_field_type_sequence_create(struct bt_ctf_field_type *element_type, const char *length_field_name);
1320 struct bt_ctf_field_type *bt_ctf_field_type_string_create(void);
1321 int bt_ctf_field_type_string_set_encoding(struct bt_ctf_field_type *string, enum ctf_string_encoding encoding);
1322 int bt_ctf_field_type_set_alignment(struct bt_ctf_field_type *type, unsigned int alignment);
1323 int bt_ctf_field_type_set_byte_order(struct bt_ctf_field_type *type, enum bt_ctf_byte_order byte_order);
1324 void bt_ctf_field_type_get(struct bt_ctf_field_type *type);
1325 void bt_ctf_field_type_put(struct bt_ctf_field_type *type);
1327 /* =================================================================
1329 ¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯
1331 %rename("_bt_ctf_field_create") bt_ctf_field_create(struct bt_ctf_field_type *type);
1332 %rename("_bt_ctf_field_structure_get_field") bt_ctf_field_structure_get_field(struct bt_ctf_field *structure, const char *name);
1333 %rename("_bt_ctf_field_array_get_field") bt_ctf_field_array_get_field(struct bt_ctf_field *array, uint64_t index);
1334 %rename("_bt_ctf_field_sequence_set_length") bt_ctf_field_sequence_set_length(struct bt_ctf_field *sequence, struct bt_ctf_field *length_field);
1335 %rename("_bt_ctf_field_sequence_get_field") bt_ctf_field_sequence_get_field(struct bt_ctf_field *sequence, uint64_t index);
1336 %rename("_bt_ctf_field_variant_get_field") bt_ctf_field_variant_get_field(struct bt_ctf_field *variant, struct bt_ctf_field *tag);
1337 %rename("_bt_ctf_field_enumeration_get_container") bt_ctf_field_enumeration_get_container(struct bt_ctf_field *enumeration);
1338 %rename("_bt_ctf_field_signed_integer_set_value") bt_ctf_field_signed_integer_set_value(struct bt_ctf_field *integer, int64_t value);
1339 %rename("_bt_ctf_field_unsigned_integer_set_value") bt_ctf_field_unsigned_integer_set_value(struct bt_ctf_field *integer, uint64_t value);
1340 %rename("_bt_ctf_field_floating_point_set_value") bt_ctf_field_floating_point_set_value(struct bt_ctf_field *floating_point, double value);
1341 %rename("_bt_ctf_field_string_set_value") bt_ctf_field_string_set_value(struct bt_ctf_field *string, const char *value);
1342 %rename("_bt_ctf_field_get") bt_ctf_field_get(struct bt_ctf_field *field);
1343 %rename("_bt_ctf_field_put") bt_ctf_field_put(struct bt_ctf_field *field);
1345 struct bt_ctf_field *bt_ctf_field_create(struct bt_ctf_field_type *type);
1346 struct bt_ctf_field *bt_ctf_field_structure_get_field(struct bt_ctf_field *structure, const char *name);
1347 struct bt_ctf_field *bt_ctf_field_array_get_field(struct bt_ctf_field *array, uint64_t index);
1348 int bt_ctf_field_sequence_set_length(struct bt_ctf_field *sequence, struct bt_ctf_field *length_field);
1349 struct bt_ctf_field *bt_ctf_field_sequence_get_field(struct bt_ctf_field *sequence, uint64_t index);
1350 struct bt_ctf_field *bt_ctf_field_variant_get_field(struct bt_ctf_field *variant, struct bt_ctf_field *tag);
1351 struct bt_ctf_field *bt_ctf_field_enumeration_get_container(struct bt_ctf_field *enumeration);
1352 int bt_ctf_field_signed_integer_set_value(struct bt_ctf_field *integer, int64_t value);
1353 int bt_ctf_field_unsigned_integer_set_value(struct bt_ctf_field *integer, uint64_t value);
1354 int bt_ctf_field_floating_point_set_value(struct bt_ctf_field *floating_point, double value);
1355 int bt_ctf_field_string_set_value(struct bt_ctf_field *string, const char *value);
1356 void bt_ctf_field_get(struct bt_ctf_field *field);
1357 void bt_ctf_field_put(struct bt_ctf_field *field);
1359 /* =================================================================
1361 ¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯
1363 %rename("_bt_ctf_event_class_create") bt_ctf_event_class_create(const char *name);
1364 %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);
1365 %rename("_bt_ctf_event_class_get") bt_ctf_event_class_get(struct bt_ctf_event_class *event_class);
1366 %rename("_bt_ctf_event_class_put") bt_ctf_event_class_put(struct bt_ctf_event_class *event_class);
1367 %rename("_bt_ctf_event_create") bt_ctf_event_create(struct bt_ctf_event_class *event_class);
1368 %rename("_bt_ctf_event_set_payload") bt_ctf_event_set_payload(struct bt_ctf_event *event, const char *name, struct bt_ctf_field *value);
1369 %rename("_bt_ctf_event_get_payload") bt_ctf_event_get_payload(struct bt_ctf_event *event, const char *name);
1370 %rename("_bt_ctf_event_get") bt_ctf_event_get(struct bt_ctf_event *event);
1371 %rename("_bt_ctf_event_put") bt_ctf_event_put(struct bt_ctf_event *event);
1373 struct bt_ctf_event_class *bt_ctf_event_class_create(const char *name);
1374 int bt_ctf_event_class_add_field(struct bt_ctf_event_class *event_class, struct bt_ctf_field_type *type, const char *name);
1375 void bt_ctf_event_class_get(struct bt_ctf_event_class *event_class);
1376 void bt_ctf_event_class_put(struct bt_ctf_event_class *event_class);
1377 struct bt_ctf_event *bt_ctf_event_create(struct bt_ctf_event_class *event_class);
1378 int bt_ctf_event_set_payload(struct bt_ctf_event *event, const char *name, struct bt_ctf_field *value);
1379 struct bt_ctf_field *bt_ctf_event_get_payload(struct bt_ctf_event *event, const char *name);
1380 void bt_ctf_event_get(struct bt_ctf_event *event);
1381 void bt_ctf_event_put(struct bt_ctf_event *event);
1383 /* =================================================================
1385 ¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯
1387 %rename("_bt_ctf_stream_class_create") bt_ctf_stream_class_create(const char *name);
1388 %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);
1389 %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);
1390 %rename("_bt_ctf_stream_class_get") bt_ctf_stream_class_get(struct bt_ctf_stream_class *stream_class);
1391 %rename("_bt_ctf_stream_class_put") bt_ctf_stream_class_put(struct bt_ctf_stream_class *stream_class);
1392 %rename("_bt_ctf_stream_append_discarded_events") bt_ctf_stream_append_discarded_events(struct bt_ctf_stream *stream, uint64_t event_count);
1393 %rename("_bt_ctf_stream_append_event") bt_ctf_stream_append_event(struct bt_ctf_stream *stream, struct bt_ctf_event *event);
1394 %rename("_bt_ctf_stream_flush") bt_ctf_stream_flush(struct bt_ctf_stream *stream);
1395 %rename("_bt_ctf_stream_get") bt_ctf_stream_get(struct bt_ctf_stream *stream);
1396 %rename("_bt_ctf_stream_put") bt_ctf_stream_put(struct bt_ctf_stream *stream);
1398 struct bt_ctf_stream_class *bt_ctf_stream_class_create(const char *name);
1399 int bt_ctf_stream_class_set_clock(struct bt_ctf_stream_class *stream_class, struct bt_ctf_clock *clock);
1400 int bt_ctf_stream_class_add_event_class(struct bt_ctf_stream_class *stream_class, struct bt_ctf_event_class *event_class);
1401 void bt_ctf_stream_class_get(struct bt_ctf_stream_class *stream_class);
1402 void bt_ctf_stream_class_put(struct bt_ctf_stream_class *stream_class);
1403 void bt_ctf_stream_append_discarded_events(struct bt_ctf_stream *stream, uint64_t event_count);
1404 int bt_ctf_stream_append_event(struct bt_ctf_stream *stream, struct bt_ctf_event *event);
1405 int bt_ctf_stream_flush(struct bt_ctf_stream *stream);
1406 void bt_ctf_stream_get(struct bt_ctf_stream *stream);
1407 void bt_ctf_stream_put(struct bt_ctf_stream *stream);
1409 /* =================================================================
1411 ¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯
1413 %rename("_bt_ctf_writer_create") bt_ctf_writer_create(const char *path);
1414 %rename("_bt_ctf_writer_create_stream") bt_ctf_writer_create_stream(struct bt_ctf_writer *writer, struct bt_ctf_stream_class *stream_class);
1415 %rename("_bt_ctf_writer_add_environment_field") bt_ctf_writer_add_environment_field(struct bt_ctf_writer *writer, const char *name, const char *value);
1416 %rename("_bt_ctf_writer_add_clock") bt_ctf_writer_add_clock(struct bt_ctf_writer *writer, struct bt_ctf_clock *clock);
1417 %newobject bt_ctf_writer_get_metadata_string;
1418 %rename("_bt_ctf_writer_get_metadata_string") bt_ctf_writer_get_metadata_string(struct bt_ctf_writer *writer);
1419 %rename("_bt_ctf_writer_flush_metadata") bt_ctf_writer_flush_metadata(struct bt_ctf_writer *writer);
1420 %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);
1421 %rename("_bt_ctf_writer_get") bt_ctf_writer_get(struct bt_ctf_writer *writer);
1422 %rename("_bt_ctf_writer_put") bt_ctf_writer_put(struct bt_ctf_writer *writer);
1424 struct bt_ctf_writer *bt_ctf_writer_create(const char *path);
1425 struct bt_ctf_stream *bt_ctf_writer_create_stream(struct bt_ctf_writer *writer, struct bt_ctf_stream_class *stream_class);
1426 int bt_ctf_writer_add_environment_field(struct bt_ctf_writer *writer, const char *name, const char *value);
1427 int bt_ctf_writer_add_clock(struct bt_ctf_writer *writer, struct bt_ctf_clock *clock);
1428 char *bt_ctf_writer_get_metadata_string(struct bt_ctf_writer *writer);
1429 void bt_ctf_writer_flush_metadata(struct bt_ctf_writer *writer);
1430 int bt_ctf_writer_set_byte_order(struct bt_ctf_writer *writer, enum bt_ctf_byte_order byte_order);
1431 void bt_ctf_writer_get(struct bt_ctf_writer *writer);
1432 void bt_ctf_writer_put(struct bt_ctf_writer *writer);
1439 def __init__(self, name):
1440 self._c = _bt_ctf_clock_create(name)
1442 raise ValueError("Invalid clock name.")
1445 _bt_ctf_clock_put(self._c)
1448 Get the clock's description.
1451 def description(self):
1452 raise NotImplementedError("Getter not implemented.")
1455 Set the clock's description. The description appears in the clock's TSDL
1459 def description(self, desc):
1460 ret = _bt_ctf_clock_set_description(self._c, str(desc))
1462 raise ValueError("Invalid clock description.")
1465 Get the clock's frequency (Hz).
1468 def frequency(self):
1469 raise NotImplementedError("Getter not implemented.")
1472 Set the clock's frequency (Hz).
1475 def frequency(self, freq):
1476 ret = _bt_ctf_clock_set_frequency(self._c, freq)
1478 raise ValueError("Invalid frequency value.")
1481 Get the clock's precision (in clock ticks).
1484 def precision(self):
1485 raise NotImplementedError("Getter not implemented.")
1488 Set the clock's precision (in clock ticks).
1491 def precision(self, precision):
1492 ret = _bt_ctf_clock_set_precision(self._c, precision)
1495 Get the clock's offset in seconds from POSIX.1 Epoch.
1498 def offset_seconds(self):
1499 raise NotImplementedError("Getter not implemented.")
1502 Set the clock's offset in seconds from POSIX.1 Epoch.
1504 @offset_seconds.setter
1505 def offset_seconds(self, offset_s):
1506 ret = _bt_ctf_clock_set_offset_s(self._c, offset_s)
1508 raise ValueError("Invalid offset value.")
1511 Get the clock's offset in ticks from POSIX.1 Epoch + offset in seconds.
1515 raise NotImplementedError("Getter not implemented.")
1518 Set the clock's offset in ticks from POSIX.1 Epoch + offset in seconds.
1521 def offset(self, offset):
1522 ret = _bt_ctf_clock_set_offset(self._c, offset)
1524 raise ValueError("Invalid offset value.")
1527 Get a clock's absolute attribute. A clock is absolute if the clock
1528 is a global reference across the trace's other clocks.
1532 raise NotImplementedError("Getter not implemented.")
1535 Set a clock's absolute attribute. A clock is absolute if the clock
1536 is a global reference across the trace's other clocks.
1539 def absolute(self, is_absolute):
1540 ret = _bt_ctf_clock_set_is_absolute(self._c, int(is_absolute))
1542 raise ValueError("Could not set the clock's absolute attribute.")
1545 Get the current time in nanoseconds since the clock's origin (offset and
1546 offset_s attributes).
1550 raise NotImplementedError("Getter not implemented.")
1553 Set the current time in nanoseconds since the clock's origin (offset and
1554 offset_s attributes). The clock's value will be sampled as events are
1555 appended to a stream.
1558 def time(self, time):
1559 ret = _bt_ctf_clock_set_time(self._c, time)
1561 raise ValueError("Invalid time value.")
1563 class FieldDeclaration:
1565 FieldDeclaration should not be instantiated directly. Please instantiate
1566 one of the concrete FieldDeclaration classes.
1569 # These values are based on the bt_ctf_integer_base enum
1570 # declared in event-types.h.
1571 INTEGER_BASE_UNKNOWN = -1
1572 INTEGER_BASE_BINARY = 2
1573 INTEGER_BASE_OCTAL = 8
1574 INTEGER_BASE_DECIMAL = 10
1575 INTEGER_BASE_HEXADECIMAL = 16
1578 if self._ft is None:
1579 raise ValueError("FieldDeclaration creation failed.")
1582 _bt_ctf_field_type_put(self._ft)
1585 Get the field type's alignment.
1588 def alignment(self):
1589 raise NotImplementedError("Getter not implemented.")
1592 Set the field type's alignment. Defaults to 1 (bit-aligned). However,
1593 some types, such as structures and string, may impose other alignment
1597 def alignment(self, alignment):
1598 ret = _bt_ctf_field_type_set_alignment(self._ft, alignment)
1600 raise ValueError("Invalid alignment value.")
1603 Get the field type's byte order. One of the ByteOrder's constant.
1606 def byte_order(self):
1607 raise NotImplementedError("Getter not implemented.")
1610 Set the field type's byte order. Use constants defined in the ByteOrder
1614 def byte_order(self, byte_order):
1615 ret = _bt_ctf_field_type_set_byte_order(self._ft, byte_order)
1617 raise ValueError("Could not set byte order value.")
1619 class IntegerFieldDeclaration(FieldDeclaration):
1621 Create a new integer field type of the given size.
1623 def __init__(self, size):
1624 self._ft = _bt_ctf_field_type_integer_create(size)
1628 Get an integer's signedness attribute.
1632 raise NotImplementedError("Getter not implemented.")
1635 Set an integer's signedness attribute.
1638 def signed(self, signed):
1639 ret = _bt_ctf_field_type_integer_set_signed(self._ft, signed)
1641 raise ValueError("Could not set signed attribute.")
1644 Get the integer's base used to pretty-print the resulting trace.
1648 raise NotImplementedError("Getter not implemented.")
1651 Set the integer's base used to pretty-print the resulting trace.
1652 The base must be a constant of the IntegerBase class.
1655 def base(self, base):
1656 ret = _bt_ctf_field_type_integer_set_base(self._ft, base)
1658 raise ValueError("Could not set base value.")
1661 Get the integer's encoding (one of the constants of the
1662 CTFStringEncoding class).
1666 raise NotImplementedError("Getter not implemented.")
1669 An integer encoding may be set to signal that the integer must be printed
1670 as a text character. Must be a constant from the CTFStringEncoding class.
1673 def encoding(self, encoding):
1674 ret = _bt_ctf_field_type_integer_set_encoding(self._ft, encoding)
1676 raise ValueError("Could not set integer encoding.")
1678 class EnumerationFieldDeclaration(FieldDeclaration):
1680 Create a new enumeration field type with the given underlying type.
1682 def __init__(self, integer_type):
1683 if integer_type is None or not isinstance(integer_type, CTFWriter.IntegerFieldDeclaration):
1684 raise TypeError("Invalid integer container.")
1686 self._ft = _bt_ctf_field_type_enumeration_create(integer_type._ft)
1690 Add a mapping to the enumeration. The range's values are inclusive.
1692 def add_mapping(self, name, range_start, range_end):
1693 ret = _bt_ctf_field_type_enumeration_add_mapping(self._ft, str(name), range_start, range_end)
1695 raise ValueError("Could not add mapping to enumeration type.")
1697 class FloatFieldDeclaration(FieldDeclaration):
1704 Create a new floating point field type.
1707 self._ft = _bt_ctf_field_type_floating_point_create()
1711 Get the number of exponent digits to use to store the floating point field.
1714 def exponent_digits(self):
1715 raise NotImplementedError("Getter not implemented.")
1718 Set the number of exponent digits to use to store the floating point field.
1719 The only values currently supported are FLT_EXP_DIG and DBL_EXP_DIG which
1720 are defined as constants of this class.
1722 @exponent_digits.setter
1723 def exponent_digits(self, exponent_digits):
1724 ret = _bt_ctf_field_type_floating_point_set_exponent_digits(self._ft, exponent_digits)
1726 raise ValueError("Could not set exponent digit count.")
1729 Get the number of mantissa digits to use to store the floating point field.
1732 def mantissa_digits(self):
1733 raise NotImplementedError("Getter not implemented.")
1736 Set the number of mantissa digits to use to store the floating point field.
1737 The only values currently supported are FLT_MANT_DIG and DBL_MANT_DIG which
1738 are defined as constants of this class.
1740 @mantissa_digits.setter
1741 def mantissa_digits(self, mantissa_digits):
1742 ret = _bt_ctf_field_type_floating_point_set_mantissa_digits(self._ft, mantissa_digits)
1744 raise ValueError("Could not set mantissa digit count.")
1746 class StructureFieldDeclaration(FieldDeclaration):
1748 Create a new structure field type.
1751 self._ft = _bt_ctf_field_type_structure_create()
1755 Add a field of type "field_type" to the structure.
1757 def add_field(self, field_type, field_name):
1758 ret = _bt_ctf_field_type_structure_add_field(self._ft, field_type._ft, str(field_name))
1760 raise ValueError("Could not add field to structure.")
1762 class VariantFieldDeclaration(FieldDeclaration):
1764 Create a new variant field type.
1766 def __init__(self, enum_tag, tag_name):
1767 if enum_tag is None or not isinstance(enum_tag, CTFWriter.EnumerationFieldDeclaration):
1768 raise TypeError("Invalid tag type; must be of type EnumerationFieldDeclaration.")
1770 self._ft = _bt_ctf_field_type_variant_create(enum_tag._ft, str(tag_name))
1774 Add a field of type "field_type" to the variant.
1776 def add_field(self, field_type, field_name):
1777 ret = _bt_ctf_field_type_variant_add_field(self._ft, field_type._ft, str(field_name))
1779 raise ValueError("Could not add field to variant.")
1781 class ArrayFieldDeclaration(FieldDeclaration):
1783 Create a new array field type.
1785 def __init__(self, element_type, length):
1786 self._ft = _bt_ctf_field_type_array_create(element_type._ft, length)
1789 class SequenceFieldDeclaration(FieldDeclaration):
1791 Create a new sequence field type.
1793 def __init__(self, element_type, length_field_name):
1794 self._ft = _bt_ctf_field_type_sequence_create(element_type._ft, str(length_field_name))
1797 class StringFieldDeclaration(FieldDeclaration):
1799 Create a new string field type.
1802 self._ft = _bt_ctf_field_type_string_create()
1806 Get a string type's encoding (a constant from the CTFStringEncoding class).
1810 raise NotImplementedError("Getter not implemented.")
1813 Set a string type's encoding. Must be a constant from the CTFStringEncoding class.
1816 def encoding(self, encoding):
1817 ret = _bt_ctf_field_type_string_set_encoding(self._ft, encoding)
1819 raise ValueError("Could not set string encoding.")
1822 Create an instance of a field.
1825 def create_field(self, field_type):
1826 if field_type is None or not isinstance(field_type, CTFWriter.FieldDeclaration):
1827 raise TypeError("Invalid field_type. Type must be a FieldDeclaration-derived class.")
1829 if isinstance(field_type, CTFWriter.IntegerFieldDeclaration):
1830 return CTFWriter.IntegerField(field_type)
1831 elif isinstance(field_type, CTFWriter.EnumerationFieldDeclaration):
1832 return CTFWriter.EnumerationField(field_type)
1833 elif isinstance(field_type, CTFWriter.FloatFieldDeclaration):
1834 return CTFWriter.FloatFieldingPoint(field_type)
1835 elif isinstance(field_type, CTFWriter.StructureFieldDeclaration):
1836 return CTFWriter.StructureField(field_type)
1837 elif isinstance(field_type, CTFWriter.VariantFieldDeclaration):
1838 return CTFWriter.VariantField(field_type)
1839 elif isinstance(field_type, CTFWriter.ArrayFieldDeclaration):
1840 return CTFWriter.ArrayField(field_type)
1841 elif isinstance(field_type, CTFWriter.SequenceFieldDeclaration):
1842 return CTFWriter.SequenceField(field_type)
1843 elif isinstance(field_type, CTFWriter.StringFieldDeclaration):
1844 return CTFWriter.StringField(field_type)
1848 Base class, do not instantiate.
1850 def __init__(self, field_type):
1851 if not isinstance(field_type, CTFWriter.FieldDeclaration):
1852 raise TypeError("Invalid field_type argument.")
1854 self._f = _bt_ctf_field_create(field_type._ft)
1856 raise ValueError("Field creation failed.")
1859 _bt_ctf_field_put(self._f)
1862 def _create_field_from_native_instance(native_field_instance):
1864 CTFTypeId.INTEGER : CTFWriter.IntegerField,
1865 CTFTypeId.FLOAT : CTFWriter.FloatFieldingPoint,
1866 CTFTypeId.ENUM : CTFWriter.EnumerationField,
1867 CTFTypeId.STRING : CTFWriter.StringField,
1868 CTFTypeId.STRUCT : CTFWriter.StructureField,
1869 CTFTypeId.VARIANT : CTFWriter.VariantField,
1870 CTFTypeId.ARRAY : CTFWriter.ArrayField,
1871 CTFTypeId.SEQUENCE : CTFWriter.SequenceField
1874 field_type = _bt_python_get_field_type(native_field_instance)
1875 if field_type == CTFTypeId.UNKNOWN:
1876 raise TypeError("Invalid field instance")
1878 field = CTFWriter.Field.__new__(CTFWriter.Field)
1879 field._f = native_field_instance
1880 field.__class__ = type_dict[field_type]
1883 class IntegerField(Field):
1885 Get an integer field's value.
1889 raise NotImplementedError("Getter not implemented.")
1892 Set an integer field's value.
1895 def value(self, value):
1896 signedness = _bt_python_field_integer_get_signedness(self._f)
1898 raise TypeError("Invalid integer instance.")
1901 ret = _bt_ctf_field_unsigned_integer_set_value(self._f, value)
1903 ret = _bt_ctf_field_signed_integer_set_value(self._f, value)
1906 raise ValueError("Could not set integer field value.")
1908 class EnumerationField(Field):
1910 Return the enumeration's underlying container field (an integer field).
1913 def container(self):
1914 container = CTFWriter.IntegerField.__new__(CTFWriter.IntegerField)
1915 container._f = _bt_ctf_field_enumeration_get_container(self._f)
1916 if container._f is None:
1917 raise TypeError("Invalid enumeration field type.")
1920 class FloatFieldingPoint(Field):
1922 Get a floating point field's value.
1926 raise NotImplementedError("Getter not implemented.")
1929 Set a floating point field's value.
1932 def value(self, value):
1933 ret = _bt_ctf_field_floating_point_set_value(self._f, float(value))
1935 raise ValueError("Could not set floating point field value.")
1937 class StructureField(Field):
1939 Get the structure's field corresponding to the provided field name.
1941 def field(self, field_name):
1942 native_instance = _bt_ctf_field_structure_get_field(self._f, str(field_name))
1943 if native_instance is None:
1944 raise ValueError("Invalid field_name provided.")
1945 return CTFWriter.Field._create_field_from_native_instance(native_instance)
1947 class VariantField(Field):
1949 Return the variant's selected field. The "tag" field is the selector enum field.
1951 def field(self, tag):
1952 native_instance = _bt_ctf_field_variant_get_field(self._f, tag._f)
1953 if native_instance is None:
1954 raise ValueError("Invalid tag provided.")
1955 return CTFWriter.Field._create_field_from_native_instance(native_instance)
1957 class ArrayField(Field):
1959 Return the array's field at position "index".
1961 def field(self, index):
1962 native_instance = _bt_ctf_field_array_get_field(self._f, index)
1963 if native_instance is None:
1964 raise IndexError("Invalid index provided.")
1965 return CTFWriter.Field._create_field_from_native_instance(native_instance)
1967 class SequenceField(Field):
1969 Get the sequence's length field (IntegerField).
1973 raise NotImplementedError("Getter not implemented.")
1976 Set the sequence's length field (IntegerField).
1979 def length(self, length_field):
1980 if not isinstance(length_field, CTFWriter.IntegerField):
1981 raise TypeError("Invalid length field.")
1982 ret = _bt_ctf_field_sequence_set_length(self._f, length_field._f)
1984 raise ValueError("Could not set sequence length.")
1987 Return the sequence's field at position "index".
1989 def field(self, index):
1990 native_instance = _bt_ctf_field_sequence_get_field(self._f, index)
1991 if native_instance is None:
1992 raise ValueError("Could not get sequence element at index.")
1993 return CTFWriter.Field._create_field_from_native_instance(native_instance)
1995 class StringField(Field):
1997 Get a string field's value.
2001 raise NotImplementedError("Getter not implemented.")
2004 Set a string field's value.
2007 def value(self, value):
2008 ret = _bt_ctf_field_string_set_value(self._f, str(value))
2010 raise ValueError("Could not set string field value.")
2014 Create a new event class of the given name.
2016 def __init__(self, name):
2017 self._ec = _bt_ctf_event_class_create(name)
2018 if self._ec is None:
2019 raise ValueError("Event class creation failed.")
2022 _bt_ctf_event_class_put(self._ec)
2025 Add a field of type "field_type" to the event class.
2027 def add_field(self, field_type, field_name):
2028 ret = _bt_ctf_event_class_add_field(self._ec, field_type._ft, str(field_name))
2030 raise ValueError("Could not add field to event class.")
2034 Create a new event of the given event class.
2036 def __init__(self, event_class):
2037 if not isinstance(event_class, CTFWriter.EventClass):
2038 raise TypeError("Invalid event_class argument.")
2040 self._e = _bt_ctf_event_create(event_class._ec)
2042 raise ValueError("Event creation failed.")
2045 _bt_ctf_event_put(self._e)
2048 Set a manually created field as an event's payload.
2050 def set_payload(self, field_name, value_field):
2051 if not isinstance(value, CTFWriter.Field):
2052 raise TypeError("Invalid value type.")
2053 ret = _bt_ctf_event_set_payload(self._e, str(field_name), value_field._f)
2055 raise ValueError("Could not set event field payload.")
2058 Get a field from event.
2060 def payload(self, field_name):
2061 native_instance = _bt_ctf_event_get_payload(self._e, str(field_name))
2062 if native_instance is None:
2063 raise ValueError("Could not get event payload.")
2064 return CTFWriter.Field._create_field_from_native_instance(native_instance)
2068 Create a new stream class of the given name.
2070 def __init__(self, name):
2071 self._sc = _bt_ctf_stream_class_create(name)
2072 if self._sc is None:
2073 raise ValueError("Stream class creation failed.")
2076 _bt_ctf_stream_class_put(self._sc)
2079 Get a stream class' clock.
2083 raise NotImplementedError("Getter not implemented.")
2086 Assign a clock to a stream class.
2089 def clock(self, clock):
2090 if not isinstance(clock, CTFWriter.Clock):
2091 raise TypeError("Invalid clock type.")
2093 ret = _bt_ctf_stream_class_set_clock(self._sc, clock._c)
2095 raise ValueError("Could not set stream class clock.")
2098 Add an event class to a stream class. New events can be added even after a
2099 stream has been instantiated and events have been appended. However, a stream
2100 will not accept events of a class that has not been registered beforehand.
2102 def add_event_class(self, event_class):
2103 if not isinstance(event_class, CTFWriter.EventClass):
2104 raise TypeError("Invalid event_class type.")
2106 ret = _bt_ctf_stream_class_add_event_class(self._sc, event_class._ec)
2108 raise ValueError("Could not add event class.")
2112 Create a stream of the given class.
2114 def __init__(self, stream_class):
2115 if not isinstance(stream_class, CTFWriter.StreamClass):
2116 raise TypeError("Invalid stream_class type.")
2118 self._s = _bt_ctf_stream_create(stream_class._sc)
2120 raise ValueError("Stream creation failed.")
2123 _bt_ctf_stream_put(self._s)
2126 Increase the current packet's discarded event count.
2128 def append_discarded_events(self, event_count):
2129 _bt_ctf_stream_append_discarded_events(self._s, event_count)
2132 Append "event" to the stream's current packet. The stream's associated clock
2133 will be sampled during this call. The event shall not be modified after
2134 being appended to a stream.
2136 def append_event(self, event):
2137 ret = _bt_ctf_stream_append_event(self._s, event._e)
2139 raise ValueError("Could not append event to stream.")
2142 The stream's current packet's events will be flushed to disk. Events
2143 subsequently appended to the stream will be added to a new packet.
2146 ret = _bt_ctf_stream_flush(self._s)
2148 raise ValueError("Could not flush stream.")
2152 Create a new writer that will produce a trace in the given path.
2154 def __init__(self, path):
2155 self._w = _bt_ctf_writer_create(path)
2157 raise ValueError("Writer creation failed.")
2160 _bt_ctf_writer_put(self._w)
2163 Create a new stream instance and register it to the writer.
2165 def create_stream(self, stream_class):
2166 if not isinstance(stream_class, CTFWriter.StreamClass):
2167 raise TypeError("Invalid stream_class type.")
2169 stream = CTFWriter.Stream.__new__(CTFWriter.Stream)
2170 stream._s = _bt_ctf_writer_create_stream(self._w, stream_class._sc)
2174 Add an environment field to the trace.
2176 def add_environment_field(self, name, value):
2177 ret = _bt_ctf_writer_add_environment_field(self._w, str(name), str(value))
2179 raise ValueError("Could not add environment field to trace.")
2182 Add a clock to the trace. Clocks assigned to stream classes must be
2183 registered to the writer.
2185 def add_clock(self, clock):
2186 ret = _bt_ctf_writer_add_clock(self._w, clock._c)
2188 raise ValueError("Could not add clock to Writer.")
2191 Get the trace's TSDL meta-data.
2195 return _bt_ctf_writer_get_metadata_string(self._w)
2198 Flush the trace's metadata to the metadata file.
2200 def flush_metadata(self):
2201 _bt_ctf_writer_flush_metadata(self._w)
2204 Get the trace's byte order. Must be a constant from the ByteOrder
2208 def byte_order(self):
2209 raise NotImplementedError("Getter not implemented.")
2212 Set the trace's byte order. Must be a constant from the ByteOrder
2213 class. Defaults to BYTE_ORDER_NATIVE, the host machine's endianness.
2216 def byte_order(self, byte_order):
2217 ret = _bt_ctf_writer_set_byte_order(self._w, byte_order)
2219 raise ValueError("Could not set trace's byte order.")