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);
103 /* =================================================================
104 CONTEXT.H, CONTEXT-INTERNAL.H
105 ¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯
108 %rename("_bt_context_create") bt_context_create(void);
109 %rename("_bt_context_add_trace") bt_context_add_trace(
110 struct bt_context *ctx, const char *path, const char *format,
111 void (*packet_seek)(struct bt_stream_pos *pos, size_t index, int whence),
112 struct bt_mmap_stream_list *stream_list, FILE *metadata);
113 %rename("_bt_context_remove_trace") bt_context_remove_trace(
114 struct bt_context *ctx, int trace_id);
115 %rename("_bt_context_get") bt_context_get(struct bt_context *ctx);
116 %rename("_bt_context_put") bt_context_put(struct bt_context *ctx);
117 %rename("_bt_ctf_event_get_context") bt_ctf_event_get_context(
118 const struct bt_ctf_event *event);
120 struct bt_context *bt_context_create(void);
121 int bt_context_add_trace(struct bt_context *ctx, const char *path, const char *format,
122 void (*packet_seek)(struct bt_stream_pos *pos, size_t index, int whence),
123 struct bt_mmap_stream_list *stream_list, FILE *metadata);
124 void bt_context_remove_trace(struct bt_context *ctx, int trace_id);
125 void bt_context_get(struct bt_context *ctx);
126 void bt_context_put(struct bt_context *ctx);
127 struct bt_context *bt_ctf_event_get_context(const struct bt_ctf_event *event);
129 // class TraceCollection to prevent direct access to struct bt_context
131 class TraceCollection:
133 The TraceCollection is the object that contains all currently opened traces.
137 self._tc = _bt_context_create()
140 _bt_context_put(self._tc)
142 def add_trace(self, path, format_str):
144 Add a trace by path to the TraceCollection.
148 path is the path to the trace, it is not recursive.
149 If "path" is None, stream_list is used instead as a list
150 of mmap streams to open for the trace.
152 format is a string containing the format name in which the trace was
155 Return: the corresponding TraceHandle on success or None on error.
157 ret = _bt_context_add_trace(self._tc, path, format_str, None, None, None)
161 th = TraceHandle.__new__(TraceHandle)
163 th._trace_collection = self
166 def add_traces_recursive(self, path, format_str):
168 Open a trace recursively.
170 Find each trace present in the subdirectory starting from the given
171 path, and add them to the TraceCollection.
173 Return a dict of TraceHandle instances (the full path is the key).
174 Return None on error.
184 for fullpath, dirs, files in os.walk(path):
185 if "metadata" in files:
186 trace_handle = self.add_trace(fullpath, format_str)
187 if trace_handle is None:
191 trace_handles[fullpath] = trace_handle
194 if noTrace and error:
198 def remove_trace(self, trace_handle):
200 Remove a trace from the TraceCollection.
201 Effectively closing the trace.
204 _bt_context_remove_trace(self._tc, trace_handle._id)
205 except AttributeError:
206 raise TypeError("in remove_trace, "
207 "argument 2 must be a TraceHandle instance")
212 Generator function to iterate over the events of open in the current
215 Due to limitations of the native Babeltrace API, only one event
216 may be "alive" at a time (i.e. a user should never store a copy
217 of the events returned by this function for ulterior use). Users
218 shall make sure to copy the information they need from an event
219 before accessing the next one.
221 Furthermore, event objects become invalid when the generator goes
222 out of scope as the underlying iterator will be reclaimed. Using an
223 event after the the generator has gone out of scope may result in a
224 crash or data corruption.
226 begin_pos_ptr = _bt_iter_pos()
227 end_pos_ptr = _bt_iter_pos()
228 begin_pos_ptr.type = SEEK_BEGIN
229 end_pos_ptr.type = SEEK_LAST
231 for event in self._events(begin_pos_ptr, end_pos_ptr):
234 def events_timestamps(self, timestamp_begin, timestamp_end):
236 Generator function to iterate over the events of open in the current
237 TraceCollection from timestamp_begin to timestamp_end.
239 begin_pos_ptr = _bt_iter_pos()
240 end_pos_ptr = _bt_iter_pos()
241 begin_pos_ptr.type = end_pos_ptr.type = SEEK_TIME
242 begin_pos_ptr.u.seek_time = timestamp_begin
243 end_pos_ptr.u.seek_time = timestamp_end
245 for event in self._events(begin_pos_ptr, end_pos_ptr):
249 def timestamp_begin(self):
250 pos_ptr = _bt_iter_pos()
251 pos_ptr.type = SEEK_BEGIN
252 return self._timestamp_at_pos(pos_ptr)
255 def timestamp_end(self):
256 pos_ptr = _bt_iter_pos()
257 pos_ptr.type = SEEK_LAST
258 return self._timestamp_at_pos(pos_ptr)
260 def _timestamp_at_pos(self, pos_ptr):
261 ctf_it_ptr = _bt_ctf_iter_create(self._tc, pos_ptr, pos_ptr)
262 if ctf_it_ptr is None:
263 raise NotImplementedError("Creation of multiple iterators is unsupported.")
264 ev_ptr = _bt_ctf_iter_read_event(ctf_it_ptr)
265 _bt_ctf_iter_destroy(ctf_it_ptr)
269 def _events(self, begin_pos_ptr, end_pos_ptr):
270 ctf_it_ptr = _bt_ctf_iter_create(self._tc, begin_pos_ptr, end_pos_ptr)
271 if ctf_it_ptr is None:
272 raise NotImplementedError(
273 "Creation of multiple iterators is unsupported.")
276 ev_ptr = _bt_ctf_iter_read_event(ctf_it_ptr)
280 ev = Event.__new__(Event)
284 except GeneratorExit:
287 ret = _bt_iter_next(_bt_ctf_get_iter(ctf_it_ptr))
291 _bt_ctf_iter_destroy(ctf_it_ptr)
297 /* =================================================================
302 %rename("lookup_format") bt_lookup_format(bt_intern_str qname);
303 %rename("_bt_print_format_list") bt_fprintf_format_list(FILE *fp);
304 %rename("register_format") bt_register_format(struct format *format);
305 %rename("unregister_format") bt_unregister_format(struct bt_format *format);
307 extern struct format *bt_lookup_format(bt_intern_str qname);
308 extern void bt_fprintf_format_list(FILE *fp);
309 extern int bt_register_format(struct bt_format *format);
310 extern void bt_unregister_format(struct bt_format *format);
314 def print_format_list(babeltrace_file):
316 Print a list of available formats to file.
318 babeltrace_file must be a File instance opened in write mode.
321 if babeltrace_file._file is not None:
322 _bt_print_format_list(babeltrace_file._file)
323 except AttributeError:
324 raise TypeError("in print_format_list, "
325 "argument 1 must be a File instance")
330 /* =================================================================
331 ITERATOR.H, ITERATOR-INTERNAL.H
332 ¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯
335 %rename("_bt_iter_create") bt_iter_create(struct bt_context *ctx,
336 const struct bt_iter_pos *begin_pos, const struct bt_iter_pos *end_pos);
337 %rename("_bt_iter_destroy") bt_iter_destroy(struct bt_iter *iter);
338 %rename("_bt_iter_next") bt_iter_next(struct bt_iter *iter);
339 %rename("_bt_iter_get_pos") bt_iter_get_pos(struct bt_iter *iter);
340 %rename("_bt_iter_free_pos") bt_iter_free_pos(struct bt_iter_pos *pos);
341 %rename("_bt_iter_set_pos") bt_iter_set_pos(struct bt_iter *iter,
342 const struct bt_iter_pos *pos);
343 %rename("_bt_iter_create_time_pos") bt_iter_create_time_pos(struct bt_iter *iter,
346 struct bt_iter *bt_iter_create(struct bt_context *ctx,
347 const struct bt_iter_pos *begin_pos, const struct bt_iter_pos *end_pos);
348 void bt_iter_destroy(struct bt_iter *iter);
349 int bt_iter_next(struct bt_iter *iter);
350 struct bt_iter_pos *bt_iter_get_pos(struct bt_iter *iter);
351 void bt_iter_free_pos(struct bt_iter_pos *pos);
352 int bt_iter_set_pos(struct bt_iter *iter, const struct bt_iter_pos *pos);
353 struct bt_iter_pos *bt_iter_create_time_pos(struct bt_iter *iter, uint64_t timestamp);
355 %rename("_bt_iter_pos") bt_iter_pos;
356 %rename("SEEK_TIME") BT_SEEK_TIME;
357 %rename("SEEK_RESTORE") BT_SEEK_RESTORE;
358 %rename("SEEK_CUR") BT_SEEK_CUR;
359 %rename("SEEK_BEGIN") BT_SEEK_BEGIN;
360 %rename("SEEK_LAST") BT_SEEK_LAST;
362 // This struct is taken from iterator.h
363 // All changes to the struct must also be made here
366 BT_SEEK_TIME, /* uses u.seek_time */
367 BT_SEEK_RESTORE, /* uses u.restore */
374 struct bt_saved_pos *restore;
378 /* =================================================================
379 TRACE-HANDLE.H, TRACE-HANDLE-INTERNAL.H
380 ¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯
383 %rename("_bt_trace_handle_create") bt_trace_handle_create(struct bt_context *ctx);
384 %rename("_bt_trace_handle_destroy") bt_trace_handle_destroy(struct bt_trace_handle *bt);
385 struct bt_trace_handle *bt_trace_handle_create(struct bt_context *ctx);
386 void bt_trace_handle_destroy(struct bt_trace_handle *bt);
388 %rename("_bt_trace_handle_get_path") bt_trace_handle_get_path(struct bt_context *ctx,
390 %rename("_bt_trace_handle_get_timestamp_begin") bt_trace_handle_get_timestamp_begin(
391 struct bt_context *ctx, int handle_id, enum bt_clock_type type);
392 %rename("_bt_trace_handle_get_timestamp_end") bt_trace_handle_get_timestamp_end(
393 struct bt_context *ctx, int handle_id, enum bt_clock_type type);
394 const char *bt_trace_handle_get_path(struct bt_context *ctx, int handle_id);
395 uint64_t bt_trace_handle_get_timestamp_begin(struct bt_context *ctx, int handle_id,
396 enum bt_clock_type type);
397 uint64_t bt_trace_handle_get_timestamp_end(struct bt_context *ctx, int handle_id,
398 enum bt_clock_type type);
400 %rename("_bt_ctf_event_get_handle_id") bt_ctf_event_get_handle_id(
401 const struct bt_ctf_event *event);
402 int bt_ctf_event_get_handle_id(const struct bt_ctf_event *event);
407 # Based on enum bt_clock_type in clock-type.h
412 class TraceHandle(object):
414 The TraceHandle allows the user to manipulate a trace file directly.
415 It is a unique identifier representing a trace file.
420 raise NotImplementedError("TraceHandle cannot be instantiated")
423 return "Babeltrace TraceHandle: trace_id('{0}')".format(self._id)
427 """Return the TraceHandle id."""
432 """Return the path of a TraceHandle."""
433 return _bt_trace_handle_get_path(self._trace_collection._tc, self._id)
436 def timestamp_begin(self):
437 """Return the creation time of the buffers of a trace."""
438 return _bt_trace_handle_get_timestamp_begin(
439 self._trace_collection._tc, self._id, ClockType.CLOCK_REAL)
442 def timestamp_end(self):
443 """Return the destruction timestamp of the buffers of a trace."""
444 return _bt_trace_handle_get_timestamp_end(
445 self._trace_collection._tc, self._id, ClockType.CLOCK_REAL)
450 Generator returning all events (EventDeclaration) in a trace.
452 ret = _bt_python_event_decl_listcaller(self.id, self._trace_collection._tc)
454 if not isinstance(ret, list):
457 ptr_list, count = ret
458 for i in range(count):
459 tmp = EventDeclaration.__new__(EventDeclaration)
460 tmp._ed = _bt_python_decl_one_from_list(ptr_list, i)
467 // =================================================================
469 // =================================================================
471 /* =================================================================
477 %rename("_bt_ctf_iter_create") bt_ctf_iter_create(struct bt_context *ctx,
478 const struct bt_iter_pos *begin_pos,
479 const struct bt_iter_pos *end_pos);
480 %rename("_bt_ctf_get_iter") bt_ctf_get_iter(struct bt_ctf_iter *iter);
481 %rename("_bt_ctf_iter_destroy") bt_ctf_iter_destroy(struct bt_ctf_iter *iter);
482 %rename("_bt_ctf_iter_read_event") bt_ctf_iter_read_event(struct bt_ctf_iter *iter);
484 struct bt_ctf_iter *bt_ctf_iter_create(struct bt_context *ctx,
485 const struct bt_iter_pos *begin_pos,
486 const struct bt_iter_pos *end_pos);
487 struct bt_iter *bt_ctf_get_iter(struct bt_ctf_iter *iter);
488 void bt_ctf_iter_destroy(struct bt_ctf_iter *iter);
489 struct bt_ctf_event *bt_ctf_iter_read_event(struct bt_ctf_iter *iter);
493 %rename("_bt_ctf_get_top_level_scope") bt_ctf_get_top_level_scope(const struct
494 bt_ctf_event *event, enum bt_ctf_scope scope);
495 %rename("_bt_ctf_event_name") bt_ctf_event_name(const struct bt_ctf_event *ctf_event);
496 %rename("_bt_ctf_get_timestamp") bt_ctf_get_timestamp(
497 const struct bt_ctf_event *ctf_event);
498 %rename("_bt_ctf_get_cycles") bt_ctf_get_cycles(
499 const struct bt_ctf_event *ctf_event);
501 %rename("_bt_ctf_get_field") bt_ctf_get_field(const struct bt_ctf_event *ctf_event,
502 const struct bt_definition *scope, const char *field);
503 %rename("_bt_ctf_get_index") bt_ctf_get_index(const struct bt_ctf_event *ctf_event,
504 const struct bt_definition *field, unsigned int index);
505 %rename("_bt_ctf_field_name") bt_ctf_field_name(const struct bt_definition *field);
506 %rename("_bt_ctf_field_type") bt_ctf_field_type(const struct bt_declaration *field);
507 %rename("_bt_ctf_get_int_signedness") bt_ctf_get_int_signedness(
508 const struct bt_declaration *field);
509 %rename("_bt_ctf_get_int_base") bt_ctf_get_int_base(const struct bt_declaration *field);
510 %rename("_bt_ctf_get_int_byte_order") bt_ctf_get_int_byte_order(
511 const struct bt_declaration *field);
512 %rename("_bt_ctf_get_int_len") bt_ctf_get_int_len(const struct bt_declaration *field);
513 %rename("_bt_ctf_get_enum_int") bt_ctf_get_enum_int(const struct bt_definition *field);
514 %rename("_bt_ctf_get_enum_str") bt_ctf_get_enum_str(const struct bt_definition *field);
515 %rename("_bt_ctf_get_encoding") bt_ctf_get_encoding(const struct bt_declaration *field);
516 %rename("_bt_ctf_get_array_len") bt_ctf_get_array_len(const struct bt_declaration *field);
517 %rename("_bt_ctf_get_uint64") bt_ctf_get_uint64(const struct bt_definition *field);
518 %rename("_bt_ctf_get_int64") bt_ctf_get_int64(const struct bt_definition *field);
519 %rename("_bt_ctf_get_char_array") bt_ctf_get_char_array(const struct bt_definition *field);
520 %rename("_bt_ctf_get_string") bt_ctf_get_string(const struct bt_definition *field);
521 %rename("_bt_ctf_get_float") bt_ctf_get_float(const struct bt_definition *field);
522 %rename("_bt_ctf_get_variant") bt_ctf_get_variant(const struct bt_definition *field);
523 %rename("_bt_ctf_field_get_error") bt_ctf_field_get_error(void);
524 %rename("_bt_ctf_get_decl_event_name") bt_ctf_get_decl_event_name(const struct
525 bt_ctf_event_decl *event);
526 %rename("_bt_ctf_get_decl_field_name") bt_ctf_get_decl_field_name(
527 const struct bt_ctf_field_decl *field);
528 %rename("_bt_ctf_get_decl_from_def") bt_ctf_get_decl_from_def(
529 const struct bt_definition *field);
530 %rename("_bt_ctf_get_decl_from_field_decl") bt_ctf_get_decl_from_field_decl(
531 const struct bt_ctf_field_decl *field);
532 %rename("_bt_array_index") bt_array_index(struct definition_array *array, uint64_t i);
533 %rename("_bt_sequence_len") bt_sequence_len(struct definition_sequence *sequence);
534 %rename("_bt_sequence_index") bt_sequence_index(struct definition_sequence *sequence, uint64_t i);
535 %rename("_bt_ctf_get_struct_field_count") bt_ctf_get_struct_field_count(const struct bt_definition *structure);
536 %rename("_bt_ctf_get_struct_field_index") bt_ctf_get_struct_field_index(const struct bt_definition *structure, uint64_t i);
538 const struct bt_definition *bt_ctf_get_top_level_scope(const struct bt_ctf_event *ctf_event,
539 enum bt_ctf_scope scope);
540 const char *bt_ctf_event_name(const struct bt_ctf_event *ctf_event);
541 uint64_t bt_ctf_get_timestamp(const struct bt_ctf_event *ctf_event);
542 uint64_t bt_ctf_get_cycles(const struct bt_ctf_event *ctf_event);
543 const struct bt_definition *bt_ctf_get_field(const struct bt_ctf_event *ctf_event,
544 const struct bt_definition *scope,
546 const struct bt_definition *bt_ctf_get_index(const struct bt_ctf_event *ctf_event,
547 const struct bt_definition *field,
549 const char *bt_ctf_field_name(const struct bt_definition *field);
550 enum ctf_type_id bt_ctf_field_type(const struct bt_declaration *field);
551 int bt_ctf_get_int_signedness(const struct bt_declaration *field);
552 int bt_ctf_get_int_base(const struct bt_declaration *field);
553 int bt_ctf_get_int_byte_order(const struct bt_declaration *field);
554 ssize_t bt_ctf_get_int_len(const struct bt_declaration *field);
555 const struct bt_definition *bt_ctf_get_enum_int(const struct bt_definition *field);
556 const char *bt_ctf_get_enum_str(const struct bt_definition *field);
557 enum ctf_string_encoding bt_ctf_get_encoding(const struct bt_declaration *field);
558 int bt_ctf_get_array_len(const struct bt_declaration *field);
559 struct bt_definition *bt_array_index(struct definition_array *array, uint64_t i);
560 uint64_t bt_ctf_get_uint64(const struct bt_definition *field);
561 int64_t bt_ctf_get_int64(const struct bt_definition *field);
562 char *bt_ctf_get_char_array(const struct bt_definition *field);
563 char *bt_ctf_get_string(const struct bt_definition *field);
564 double bt_ctf_get_float(const struct bt_definition *field);
565 const struct bt_definition *bt_ctf_get_variant(const struct bt_definition *field);
566 int bt_ctf_field_get_error(void);
567 const char *bt_ctf_get_decl_event_name(const struct bt_ctf_event_decl *event);
568 const char *bt_ctf_get_decl_field_name(const struct bt_ctf_field_decl *field);
569 const struct bt_declaration *bt_ctf_get_decl_from_def(const struct bt_definition *field);
570 const struct bt_declaration *bt_ctf_get_decl_from_field_decl(const struct bt_ctf_field_decl *field);
571 uint64_t bt_sequence_len(struct definition_sequence *sequence);
572 struct bt_definition *bt_sequence_index(struct definition_sequence *sequence, uint64_t i);
573 uint64_t bt_ctf_get_struct_field_count(const struct bt_definition *structure);
574 const struct bt_definition *bt_ctf_get_struct_field_index(const struct bt_definition *structure, uint64_t i);
578 class CTFStringEncoding:
584 # Based on the enum in ctf-writer/writer.h
586 BYTE_ORDER_NATIVE = 0
587 BYTE_ORDER_LITTLE_ENDIAN = 1
588 BYTE_ORDER_BIG_ENDIAN = 2
589 BYTE_ORDER_NETWORK = 3
590 BYTE_ORDER_UNKNOWN = 4 # Python-specific entry
592 #enum equivalent, accessible constants
593 #These are taken directly from ctf/events.h
594 #All changes to enums must also be made here
609 name = "UNKNOWN_TYPE"
610 constants = [attr for attr in dir(CTFTypeId) if not callable(getattr(CTFTypeId, attr)) and not attr.startswith("__")]
611 for attr in constants:
612 if getattr(CTFTypeId, attr) == id:
618 TRACE_PACKET_HEADER = 0
619 STREAM_PACKET_CONTEXT = 1
620 STREAM_EVENT_HEADER = 2
621 STREAM_EVENT_CONTEXT = 3
625 def scope_name(scope):
626 name = "UNKNOWN_SCOPE"
627 constants = [attr for attr in dir(CTFScope) if not callable(getattr(CTFScope, attr)) and not attr.startswith("__")]
628 for attr in constants:
629 if getattr(CTFScope, attr) == scope:
634 # Priority of the scopes when searching for event fields
635 _scopes = [CTFScope.EVENT_FIELDS, CTFScope.EVENT_CONTEXT, CTFScope.STREAM_EVENT_CONTEXT,
636 CTFScope.STREAM_EVENT_HEADER, CTFScope.STREAM_PACKET_CONTEXT, CTFScope.TRACE_PACKET_HEADER]
639 class Event(collections.Mapping):
641 This class represents an event from the trace.
642 It is obtained using the TraceCollection generator functions.
646 raise NotImplementedError("Event cannot be instantiated")
650 """Return the name of the event or None on error."""
651 return _bt_ctf_event_name(self._e)
656 Return the timestamp of the event as written in
657 the packet (in cycles) or -1ULL on error.
659 return _bt_ctf_get_cycles(self._e)
664 Return the timestamp of the event offset with the
665 system clock source or -1ULL on error.
667 return _bt_ctf_get_timestamp(self._e)
669 def field_with_scope(self, field_name, scope):
671 Get field_name's value in scope.
672 None is returned if no field matches field_name.
674 if not scope in _scopes:
675 raise ValueError("Invalid scope provided")
676 field = self._field_with_scope(field_name, scope)
677 if field is not None:
681 def field_list_with_scope(self, scope):
682 """Return a list of field names in scope."""
683 if not scope in _scopes:
684 raise ValueError("Invalid scope provided")
686 for field in self._field_list_with_scope(scope):
687 field_names.append(field.name)
693 Get the TraceHandle associated with this event
696 ret = _bt_ctf_event_get_handle_id(self._e)
700 th = TraceHandle.__new__(TraceHandle)
702 th._trace_collection = self.get_trace_collection()
706 def trace_collection(self):
708 Get the TraceCollection associated with this event.
709 Return None on error.
711 trace_collection = TraceCollection()
712 trace_collection._tc = _bt_ctf_event_get_context(self._e);
713 if trace_collection._tc is None:
716 return trace_collection
718 def __getitem__(self, field_name):
720 Get field_name's value. If the field_name exists in multiple
721 scopes, the first field found is returned. The scopes are searched
722 in the following order:
725 3) STREAM_EVENT_CONTEXT
726 4) STREAM_EVENT_HEADER
727 5) STREAM_PACKET_CONTEXT
728 6) TRACE_PACKET_HEADER
729 None is returned if no field matches field_name.
731 Use field_with_scope() to explicitly access fields in a given
734 field = self._field(field_name)
735 if field is not None:
737 raise KeyError(field_name)
740 for key in self.keys():
745 for scope in _scopes:
746 scope_ptr = _bt_ctf_get_top_level_scope(self._e, scope)
747 ret = _bt_python_field_listcaller(self._e, scope_ptr)
748 if isinstance(ret, list):
752 def __contains__(self, field_name):
753 return self._field(field_name) is not None
756 """Return a list of field names."""
758 for scope in _scopes:
759 for name in self.field_list_with_scope(scope):
760 field_names.add(name)
761 return list(field_names)
763 def get(self, field_name, default = None):
764 field = self._field(field_name)
770 for field in self.keys():
771 yield (field, self[field])
773 def _field_with_scope(self, field_name, scope):
774 scope_ptr = _bt_ctf_get_top_level_scope(self._e, scope)
775 if scope_ptr is None:
778 definition_ptr = _bt_ctf_get_field(self._e, scope_ptr, field_name)
779 if definition_ptr is None:
782 field = _Definition(definition_ptr, scope)
785 def _field(self, field_name):
787 for scope in _scopes:
788 field = self._field_with_scope(field_name, scope)
789 if field is not None:
793 def _field_list_with_scope(self, scope):
795 scope_ptr = _bt_ctf_get_top_level_scope(self._e, scope)
797 # Returns a list [list_ptr, count]. If list_ptr is NULL, SWIG will only
798 # provide the "count" return value
801 ret = _bt_python_field_listcaller(self._e, scope_ptr)
802 if isinstance(ret, list):
803 list_ptr, count = ret
805 for i in range(count):
806 definition_ptr = _bt_python_field_one_from_list(list_ptr, i)
807 if definition_ptr is not None:
808 definition = _Definition(definition_ptr, scope)
809 fields.append(definition)
812 class FieldError(Exception):
813 def __init__(self, value):
817 return repr(self.value)
819 class EventDeclaration(object):
820 """Event declaration class. Do not instantiate."""
823 raise NotImplementedError("EventDeclaration cannot be instantiated")
827 """Return the name of the event or None on error"""
828 return _bt_ctf_get_decl_event_name(self._ed)
833 Generator returning all FieldDeclarations of an event, going through
834 each scope in the following order:
837 3) STREAM_EVENT_CONTEXT
838 4) STREAM_EVENT_HEADER
839 5) STREAM_PACKET_CONTEXT
840 6) TRACE_PACKET_HEADER
842 for scope in _scopes:
843 for declaration in self.fields_scope(scope):
846 def fields_scope(self, scope):
848 Generator returning FieldDeclarations of the current event in scope.
850 ret = _by_python_field_decl_listcaller(self._ed, scope)
852 if not isinstance(ret, list):
855 list_ptr, count = ret
856 for i in range(count):
857 field_declaration_ptr = _bt_python_field_decl_one_from_list(list_ptr, i)
858 if field_declaration_ptr is not None:
859 declaration_ptr = _bt_ctf_get_decl_from_field_decl(field_declaration_ptr)
860 field_declaration = _create_field_declaration(declaration_ptr, _bt_ctf_get_decl_field_name(field_declaration_ptr), scope)
861 yield field_declaration
863 class FieldDeclaration(object):
864 """Field declaration class. Do not instantiate."""
866 raise NotImplementedError("FieldDeclaration cannot be instantiated")
869 return "({0}) {1} {2}".format(CTFScope.scope_name(self.scope), CTFTypeId.type_name(self.type), self.name)
873 """Return the name of a FieldDeclaration or None on error."""
879 Return the FieldDeclaration's type. One of the entries in class
882 return _bt_ctf_field_type(self._fd)
887 Return the FieldDeclaration's scope.
891 class IntegerFieldDeclaration(FieldDeclaration):
892 """Do not instantiate."""
894 raise NotImplementedError("IntegerFieldDeclaration cannot be instantiated")
897 def signedness(self):
899 Return the signedness of an integer:
900 0 if unsigned; 1 if signed; -1 on error.
902 return _bt_ctf_get_int_signedness(self._fd)
906 """Return the base of an int or a negative value on error."""
907 return _bt_ctf_get_int_base(self._fd)
910 def byte_order(self):
912 Return the byte order. One of class ByteOrder's entries.
914 ret = _bt_ctf_get_int_byte_order(self._fd)
916 return ByteOrder.BYTE_ORDER_LITTLE_ENDIAN
918 return ByteOrder.BYTE_ORDER_BIG_ENDIAN
920 return ByteOrder.BYTE_ORDER_UNKNOWN
925 Return the size, in bits, of an int or a negative
928 return _bt_ctf_get_int_len(self._fd)
933 Return the encoding. One of class CTFStringEncoding's entries.
934 Return a negative value on error.
936 return _bt_ctf_get_encoding(self._fd)
938 class EnumerationFieldDeclaration(FieldDeclaration):
939 """Do not instantiate."""
941 raise NotImplementedError("EnumerationFieldDeclaration cannot be instantiated")
943 class ArrayFieldDeclaration(FieldDeclaration):
944 """Do not instantiate."""
946 raise NotImplementedError("ArrayFieldDeclaration cannot be instantiated")
951 Return the length of an array or a negative
954 return _bt_ctf_get_array_len(self._fd)
957 def element_declaration(self):
959 Return element declaration.
961 field_decl_ptr = _bt_python_get_array_element_declaration(self._fd)
962 return _create_field_declaration(field_decl_ptr, "", self.scope)
964 class SequenceFieldDeclaration(FieldDeclaration):
965 """Do not instantiate."""
967 raise NotImplementedError("SequenceFieldDeclaration cannot be instantiated")
970 def element_declaration(self):
972 Return element declaration.
974 field_decl_ptr = _bt_python_get_sequence_element_declaration(self._fd)
975 return _create_field_declaration(field_decl_ptr, "", self.scope)
977 class FloatFieldDeclaration(FieldDeclaration):
978 """Do not instantiate."""
980 raise NotImplementedError("FloatFieldDeclaration cannot be instantiated")
982 class StructureFieldDeclaration(FieldDeclaration):
983 """Do not instantiate."""
985 raise NotImplementedError("StructureFieldDeclaration cannot be instantiated")
987 class StringFieldDeclaration(FieldDeclaration):
988 """Do not instantiate."""
990 raise NotImplementedError("StringFieldDeclaration cannot be instantiated")
992 class VariantFieldDeclaration(FieldDeclaration):
993 """Do not instantiate."""
995 raise NotImplementedError("VariantFieldDeclaration cannot be instantiated")
999 Return the last error code encountered while
1000 accessing a field and reset the error flag.
1001 Return 0 if no error, a negative value otherwise.
1003 return _bt_ctf_field_get_error()
1005 def _create_field_declaration(declaration_ptr, name, scope):
1007 Private field declaration factory.
1009 if declaration_ptr is None:
1010 raise ValueError("declaration_ptr must be valid")
1011 if not scope in _scopes:
1012 raise ValueError("Invalid scope provided")
1014 type = _bt_ctf_field_type(declaration_ptr)
1016 if type == CTFTypeId.INTEGER:
1017 declaration = IntegerFieldDeclaration.__new__(IntegerFieldDeclaration)
1018 elif type == CTFTypeId.ENUM:
1019 declaration = EnumerationFieldDeclaration.__new__(EnumerationFieldDeclaration)
1020 elif type == CTFTypeId.ARRAY:
1021 declaration = ArrayFieldDeclaration.__new__(ArrayFieldDeclaration)
1022 elif type == CTFTypeId.SEQUENCE:
1023 declaration = SequenceFieldDeclaration.__new__(SequenceFieldDeclaration)
1024 elif type == CTFTypeId.FLOAT:
1025 declaration = FloatFieldDeclaration.__new__(FloatFieldDeclaration)
1026 elif type == CTFTypeId.STRUCT:
1027 declaration = StructureFieldDeclaration.__new__(StructureFieldDeclaration)
1028 elif type == CTFTypeId.STRING:
1029 declaration = StringFieldDeclaration.__new__(StringFieldDeclaration)
1030 elif type == CTFTypeId.VARIANT:
1031 declaration = VariantFieldDeclaration.__new__(VariantFieldDeclaration)
1035 declaration._fd = declaration_ptr
1036 declaration._s = scope
1037 declaration._name = name
1040 class _Definition(object):
1041 def __init__(self, definition_ptr, scope):
1042 self._d = definition_ptr
1044 if not scope in _scopes:
1045 ValueError("Invalid scope provided")
1049 """Return the name of a field or None on error."""
1050 return _bt_ctf_field_name(self._d)
1054 """Return the type of a field or -1 if unknown."""
1055 return _bt_ctf_field_type(_bt_ctf_get_decl_from_def(self._d))
1058 def declaration(self):
1059 """Return the associated Definition object."""
1060 return _create_field_declaration(_bt_ctf_get_decl_from_def(self._d), self.name, self.scope)
1062 def _get_enum_str(self):
1064 Return the string matching the current enumeration.
1065 Return None on error.
1067 return _bt_ctf_get_enum_str(self._d)
1069 def _get_array_element_at(self, index):
1071 Return the array's element at position index.
1072 Return None on error
1074 array_ptr = _bt_python_get_array_from_def(self._d)
1075 if array_ptr is None:
1078 definition_ptr = _bt_array_index(array_ptr, index)
1079 if definition_ptr is None:
1081 return _Definition(definition_ptr, self.scope)
1083 def _get_sequence_len(self):
1085 Return the len of a sequence or a negative
1088 seq = _bt_python_get_sequence_from_def(self._d)
1089 return _bt_sequence_len(seq)
1091 def _get_sequence_element_at(self, index):
1093 Return the sequence's element at position index,
1094 otherwise return None
1096 seq = _bt_python_get_sequence_from_def(self._d)
1098 definition_ptr = _bt_sequence_index(seq, index)
1099 if definition_ptr is not None:
1100 return _Definition(definition_ptr, self.scope)
1103 def _get_uint64(self):
1105 Return the value associated with the field.
1106 If the field does not exist or is not of the type requested,
1107 the value returned is undefined. To check if an error occured,
1108 use the field_error() function after accessing a field.
1110 return _bt_ctf_get_uint64(self._d)
1112 def _get_int64(self):
1114 Return the value associated with the field.
1115 If the field does not exist or is not of the type requested,
1116 the value returned is undefined. To check if an error occured,
1117 use the field_error() function after accessing a field.
1119 return _bt_ctf_get_int64(self._d)
1121 def _get_char_array(self):
1123 Return the value associated with the field.
1124 If the field does not exist or is not of the type requested,
1125 the value returned is undefined. To check if an error occurred,
1126 use the field_error() function after accessing a field.
1128 return _bt_ctf_get_char_array(self._d)
1132 Return the value associated with the field.
1133 If the field does not exist or is not of the type requested,
1134 the value returned is undefined. To check if an error occurred,
1135 use the field_error() function after accessing a field.
1137 return _bt_ctf_get_string(self._d)
1139 def _get_float(self):
1141 Return the value associated with the field.
1142 If the field does not exist or is not of the type requested,
1143 the value returned is undefined. To check if an error occurred,
1144 use the field_error() function after accessing a field.
1146 return _bt_ctf_get_float(self._d)
1148 def _get_variant(self):
1150 Return the variant's selected field.
1151 If the field does not exist or is not of the type requested,
1152 the value returned is undefined. To check if an error occurred,
1153 use the field_error() function after accessing a field.
1155 return _bt_ctf_get_variant(self._d)
1157 def _get_struct_field_count(self):
1159 Return the number of fields contained in the structure.
1160 If the field does not exist or is not of the type requested,
1161 the value returned is undefined.
1163 return _bt_ctf_get_struct_field_count(self._d)
1165 def _get_struct_field_at(self, i):
1167 Return the structure's field at position i.
1168 If the field does not exist or is not of the type requested,
1169 the value returned is undefined. To check if an error occurred,
1170 use the field_error() function after accessing a field.
1172 return _bt_ctf_get_struct_field_index(self._d, i)
1177 Return the value associated with the field according to its type.
1178 Return None on error.
1183 if id == CTFTypeId.STRING:
1184 value = self._get_str()
1185 elif id == CTFTypeId.ARRAY:
1186 element_decl = self.declaration.element_declaration
1187 if ((element_decl.type == CTFTypeId.INTEGER
1188 and element_decl.length == 8)
1189 and (element_decl.encoding == CTFStringEncoding.ASCII or element_decl.encoding == CTFStringEncoding.UTF8)):
1190 value = _bt_python_get_array_string(self._d)
1193 for i in range(self.declaration.length):
1194 element = self._get_array_element_at(i)
1195 value.append(element.value)
1196 elif id == CTFTypeId.INTEGER:
1197 if self.declaration.signedness == 0:
1198 value = self._get_uint64()
1200 value = self._get_int64()
1201 elif id == CTFTypeId.ENUM:
1202 value = self._get_enum_str()
1203 elif id == CTFTypeId.SEQUENCE:
1204 element_decl = self.declaration.element_declaration
1205 if ((element_decl.type == CTFTypeId.INTEGER
1206 and element_decl.length == 8)
1207 and (element_decl.encoding == CTFStringEncoding.ASCII or element_decl.encoding == CTFStringEncoding.UTF8)):
1208 value = _bt_python_get_sequence_string(self._d)
1210 seq_len = self._get_sequence_len()
1212 for i in range(seq_len):
1213 evDef = self._get_sequence_element_at(i)
1214 value.append(evDef.value)
1215 elif id == CTFTypeId.FLOAT:
1216 value = self._get_float()
1217 elif id == CTFTypeId.VARIANT:
1218 variant = _Definition.__new__(_Definition)
1219 variant._d = self._get_variant();
1220 value = variant.value
1221 elif id == CTFTypeId.STRUCT:
1223 for i in range(self._get_struct_field_count()):
1224 member = _Definition(self._get_struct_field_at(i), self.scope)
1225 value[member.name] = member.value
1228 raise FieldError("Error occurred while accessing field {} of type {}".format(self.name, CTFTypeId.type_name(id)))
1233 """Return the scope of a field or None on error."""
1239 // =================================================================
1241 // =================================================================
1243 /* =================================================================
1245 ¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯
1247 %rename("_bt_ctf_clock_create") bt_ctf_clock_create(const char *name);
1248 %rename("_bt_ctf_clock_set_description") bt_ctf_clock_set_description(struct bt_ctf_clock *clock, const char *desc);
1249 %rename("_bt_ctf_clock_set_frequency") bt_ctf_clock_set_frequency(struct bt_ctf_clock *clock, uint64_t freq);
1250 %rename("_bt_ctf_clock_set_precision") bt_ctf_clock_set_precision(struct bt_ctf_clock *clock, uint64_t precision);
1251 %rename("_bt_ctf_clock_set_offset_s") bt_ctf_clock_set_offset_s(struct bt_ctf_clock *clock, uint64_t offset_s);
1252 %rename("_bt_ctf_clock_set_offset") bt_ctf_clock_set_offset(struct bt_ctf_clock *clock, uint64_t offset);
1253 %rename("_bt_ctf_clock_set_is_absolute") bt_ctf_clock_set_is_absolute(struct bt_ctf_clock *clock, int is_absolute);
1254 %rename("_bt_ctf_clock_set_time") bt_ctf_clock_set_time(struct bt_ctf_clock *clock, uint64_t time);
1255 %rename("_bt_ctf_clock_get") bt_ctf_clock_get(struct bt_ctf_clock *clock);
1256 %rename("_bt_ctf_clock_put") bt_ctf_clock_put(struct bt_ctf_clock *clock);
1258 struct bt_ctf_clock *bt_ctf_clock_create(const char *name);
1259 int bt_ctf_clock_set_description(struct bt_ctf_clock *clock, const char *desc);
1260 int bt_ctf_clock_set_frequency(struct bt_ctf_clock *clock, uint64_t freq);
1261 int bt_ctf_clock_set_precision(struct bt_ctf_clock *clock, uint64_t precision);
1262 int bt_ctf_clock_set_offset_s(struct bt_ctf_clock *clock, uint64_t offset_s);
1263 int bt_ctf_clock_set_offset(struct bt_ctf_clock *clock, uint64_t offset);
1264 int bt_ctf_clock_set_is_absolute(struct bt_ctf_clock *clock, int is_absolute);
1265 int bt_ctf_clock_set_time(struct bt_ctf_clock *clock, uint64_t time);
1266 void bt_ctf_clock_get(struct bt_ctf_clock *clock);
1267 void bt_ctf_clock_put(struct bt_ctf_clock *clock);
1269 /* =================================================================
1271 ¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯
1273 %rename("_bt_ctf_field_type_integer_create") bt_ctf_field_type_integer_create(unsigned int size);
1274 %rename("_bt_ctf_field_type_integer_set_signed") bt_ctf_field_type_integer_set_signed(struct bt_ctf_field_type *integer, int is_signed);
1275 %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);
1276 %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);
1277 %rename("_bt_ctf_field_type_enumeration_create") bt_ctf_field_type_enumeration_create(struct bt_ctf_field_type *integer_container_type);
1278 %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);
1279 %rename("_bt_ctf_field_type_floating_point_create") bt_ctf_field_type_floating_point_create(void);
1280 %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);
1281 %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);
1282 %rename("_bt_ctf_field_type_structure_create") bt_ctf_field_type_structure_create(void);
1283 %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);
1284 %rename("_bt_ctf_field_type_variant_create") bt_ctf_field_type_variant_create(struct bt_ctf_field_type *enum_tag, const char *tag_name);
1285 %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);
1286 %rename("_bt_ctf_field_type_array_create") bt_ctf_field_type_array_create(struct bt_ctf_field_type *element_type, unsigned int length);
1287 %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);
1288 %rename("_bt_ctf_field_type_string_create") bt_ctf_field_type_string_create(void);
1289 %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);
1290 %rename("_bt_ctf_field_type_set_alignment") bt_ctf_field_type_set_alignment(struct bt_ctf_field_type *type, unsigned int alignment);
1291 %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);
1292 %rename("_bt_ctf_field_type_get") bt_ctf_field_type_get(struct bt_ctf_field_type *type);
1293 %rename("_bt_ctf_field_type_put") bt_ctf_field_type_put(struct bt_ctf_field_type *type);
1295 struct bt_ctf_field_type *bt_ctf_field_type_integer_create(unsigned int size);
1296 int bt_ctf_field_type_integer_set_signed(struct bt_ctf_field_type *integer, int is_signed);
1297 int bt_ctf_field_type_integer_set_base(struct bt_ctf_field_type *integer, enum bt_ctf_integer_base base);
1298 int bt_ctf_field_type_integer_set_encoding(struct bt_ctf_field_type *integer, enum ctf_string_encoding encoding);
1299 struct bt_ctf_field_type *bt_ctf_field_type_enumeration_create(struct bt_ctf_field_type *integer_container_type);
1300 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);
1301 struct bt_ctf_field_type *bt_ctf_field_type_floating_point_create(void);
1302 int bt_ctf_field_type_floating_point_set_exponent_digits(struct bt_ctf_field_type *floating_point, unsigned int exponent_digits);
1303 int bt_ctf_field_type_floating_point_set_mantissa_digits(struct bt_ctf_field_type *floating_point, unsigned int mantissa_digits);
1304 struct bt_ctf_field_type *bt_ctf_field_type_structure_create(void);
1305 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);
1306 struct bt_ctf_field_type *bt_ctf_field_type_variant_create(struct bt_ctf_field_type *enum_tag, const char *tag_name);
1307 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);
1308 struct bt_ctf_field_type *bt_ctf_field_type_array_create(struct bt_ctf_field_type *element_type, unsigned int length);
1309 struct bt_ctf_field_type *bt_ctf_field_type_sequence_create(struct bt_ctf_field_type *element_type, const char *length_field_name);
1310 struct bt_ctf_field_type *bt_ctf_field_type_string_create(void);
1311 int bt_ctf_field_type_string_set_encoding(struct bt_ctf_field_type *string, enum ctf_string_encoding encoding);
1312 int bt_ctf_field_type_set_alignment(struct bt_ctf_field_type *type, unsigned int alignment);
1313 int bt_ctf_field_type_set_byte_order(struct bt_ctf_field_type *type, enum bt_ctf_byte_order byte_order);
1314 void bt_ctf_field_type_get(struct bt_ctf_field_type *type);
1315 void bt_ctf_field_type_put(struct bt_ctf_field_type *type);
1317 /* =================================================================
1319 ¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯
1321 %rename("_bt_ctf_field_create") bt_ctf_field_create(struct bt_ctf_field_type *type);
1322 %rename("_bt_ctf_field_structure_get_field") bt_ctf_field_structure_get_field(struct bt_ctf_field *structure, const char *name);
1323 %rename("_bt_ctf_field_array_get_field") bt_ctf_field_array_get_field(struct bt_ctf_field *array, uint64_t index);
1324 %rename("_bt_ctf_field_sequence_set_length") bt_ctf_field_sequence_set_length(struct bt_ctf_field *sequence, struct bt_ctf_field *length_field);
1325 %rename("_bt_ctf_field_sequence_get_field") bt_ctf_field_sequence_get_field(struct bt_ctf_field *sequence, uint64_t index);
1326 %rename("_bt_ctf_field_variant_get_field") bt_ctf_field_variant_get_field(struct bt_ctf_field *variant, struct bt_ctf_field *tag);
1327 %rename("_bt_ctf_field_enumeration_get_container") bt_ctf_field_enumeration_get_container(struct bt_ctf_field *enumeration);
1328 %rename("_bt_ctf_field_signed_integer_set_value") bt_ctf_field_signed_integer_set_value(struct bt_ctf_field *integer, int64_t value);
1329 %rename("_bt_ctf_field_unsigned_integer_set_value") bt_ctf_field_unsigned_integer_set_value(struct bt_ctf_field *integer, uint64_t value);
1330 %rename("_bt_ctf_field_floating_point_set_value") bt_ctf_field_floating_point_set_value(struct bt_ctf_field *floating_point, double value);
1331 %rename("_bt_ctf_field_string_set_value") bt_ctf_field_string_set_value(struct bt_ctf_field *string, const char *value);
1332 %rename("_bt_ctf_field_get") bt_ctf_field_get(struct bt_ctf_field *field);
1333 %rename("_bt_ctf_field_put") bt_ctf_field_put(struct bt_ctf_field *field);
1335 struct bt_ctf_field *bt_ctf_field_create(struct bt_ctf_field_type *type);
1336 struct bt_ctf_field *bt_ctf_field_structure_get_field(struct bt_ctf_field *structure, const char *name);
1337 struct bt_ctf_field *bt_ctf_field_array_get_field(struct bt_ctf_field *array, uint64_t index);
1338 int bt_ctf_field_sequence_set_length(struct bt_ctf_field *sequence, struct bt_ctf_field *length_field);
1339 struct bt_ctf_field *bt_ctf_field_sequence_get_field(struct bt_ctf_field *sequence, uint64_t index);
1340 struct bt_ctf_field *bt_ctf_field_variant_get_field(struct bt_ctf_field *variant, struct bt_ctf_field *tag);
1341 struct bt_ctf_field *bt_ctf_field_enumeration_get_container(struct bt_ctf_field *enumeration);
1342 int bt_ctf_field_signed_integer_set_value(struct bt_ctf_field *integer, int64_t value);
1343 int bt_ctf_field_unsigned_integer_set_value(struct bt_ctf_field *integer, uint64_t value);
1344 int bt_ctf_field_floating_point_set_value(struct bt_ctf_field *floating_point, double value);
1345 int bt_ctf_field_string_set_value(struct bt_ctf_field *string, const char *value);
1346 void bt_ctf_field_get(struct bt_ctf_field *field);
1347 void bt_ctf_field_put(struct bt_ctf_field *field);
1349 /* =================================================================
1351 ¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯
1353 %rename("_bt_ctf_event_class_create") bt_ctf_event_class_create(const char *name);
1354 %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);
1355 %rename("_bt_ctf_event_class_get") bt_ctf_event_class_get(struct bt_ctf_event_class *event_class);
1356 %rename("_bt_ctf_event_class_put") bt_ctf_event_class_put(struct bt_ctf_event_class *event_class);
1357 %rename("_bt_ctf_event_create") bt_ctf_event_create(struct bt_ctf_event_class *event_class);
1358 %rename("_bt_ctf_event_set_payload") bt_ctf_event_set_payload(struct bt_ctf_event *event, const char *name, struct bt_ctf_field *value);
1359 %rename("_bt_ctf_event_get_payload") bt_ctf_event_get_payload(struct bt_ctf_event *event, const char *name);
1360 %rename("_bt_ctf_event_get") bt_ctf_event_get(struct bt_ctf_event *event);
1361 %rename("_bt_ctf_event_put") bt_ctf_event_put(struct bt_ctf_event *event);
1363 struct bt_ctf_event_class *bt_ctf_event_class_create(const char *name);
1364 int bt_ctf_event_class_add_field(struct bt_ctf_event_class *event_class, struct bt_ctf_field_type *type, const char *name);
1365 void bt_ctf_event_class_get(struct bt_ctf_event_class *event_class);
1366 void bt_ctf_event_class_put(struct bt_ctf_event_class *event_class);
1367 struct bt_ctf_event *bt_ctf_event_create(struct bt_ctf_event_class *event_class);
1368 int bt_ctf_event_set_payload(struct bt_ctf_event *event, const char *name, struct bt_ctf_field *value);
1369 struct bt_ctf_field *bt_ctf_event_get_payload(struct bt_ctf_event *event, const char *name);
1370 void bt_ctf_event_get(struct bt_ctf_event *event);
1371 void bt_ctf_event_put(struct bt_ctf_event *event);
1373 /* =================================================================
1375 ¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯
1377 %rename("_bt_ctf_stream_class_create") bt_ctf_stream_class_create(const char *name);
1378 %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);
1379 %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);
1380 %rename("_bt_ctf_stream_class_get") bt_ctf_stream_class_get(struct bt_ctf_stream_class *stream_class);
1381 %rename("_bt_ctf_stream_class_put") bt_ctf_stream_class_put(struct bt_ctf_stream_class *stream_class);
1382 %rename("_bt_ctf_stream_append_discarded_events") bt_ctf_stream_append_discarded_events(struct bt_ctf_stream *stream, uint64_t event_count);
1383 %rename("_bt_ctf_stream_append_event") bt_ctf_stream_append_event(struct bt_ctf_stream *stream, struct bt_ctf_event *event);
1384 %rename("_bt_ctf_stream_flush") bt_ctf_stream_flush(struct bt_ctf_stream *stream);
1385 %rename("_bt_ctf_stream_get") bt_ctf_stream_get(struct bt_ctf_stream *stream);
1386 %rename("_bt_ctf_stream_put") bt_ctf_stream_put(struct bt_ctf_stream *stream);
1388 struct bt_ctf_stream_class *bt_ctf_stream_class_create(const char *name);
1389 int bt_ctf_stream_class_set_clock(struct bt_ctf_stream_class *stream_class, struct bt_ctf_clock *clock);
1390 int bt_ctf_stream_class_add_event_class(struct bt_ctf_stream_class *stream_class, struct bt_ctf_event_class *event_class);
1391 void bt_ctf_stream_class_get(struct bt_ctf_stream_class *stream_class);
1392 void bt_ctf_stream_class_put(struct bt_ctf_stream_class *stream_class);
1393 void bt_ctf_stream_append_discarded_events(struct bt_ctf_stream *stream, uint64_t event_count);
1394 int bt_ctf_stream_append_event(struct bt_ctf_stream *stream, struct bt_ctf_event *event);
1395 int bt_ctf_stream_flush(struct bt_ctf_stream *stream);
1396 void bt_ctf_stream_get(struct bt_ctf_stream *stream);
1397 void bt_ctf_stream_put(struct bt_ctf_stream *stream);
1399 /* =================================================================
1401 ¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯
1403 %rename("_bt_ctf_writer_create") bt_ctf_writer_create(const char *path);
1404 %rename("_bt_ctf_writer_create_stream") bt_ctf_writer_create_stream(struct bt_ctf_writer *writer, struct bt_ctf_stream_class *stream_class);
1405 %rename("_bt_ctf_writer_add_environment_field") bt_ctf_writer_add_environment_field(struct bt_ctf_writer *writer, const char *name, const char *value);
1406 %rename("_bt_ctf_writer_add_clock") bt_ctf_writer_add_clock(struct bt_ctf_writer *writer, struct bt_ctf_clock *clock);
1407 %newobject bt_ctf_writer_get_metadata_string;
1408 %rename("_bt_ctf_writer_get_metadata_string") bt_ctf_writer_get_metadata_string(struct bt_ctf_writer *writer);
1409 %rename("_bt_ctf_writer_flush_metadata") bt_ctf_writer_flush_metadata(struct bt_ctf_writer *writer);
1410 %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);
1411 %rename("_bt_ctf_writer_get") bt_ctf_writer_get(struct bt_ctf_writer *writer);
1412 %rename("_bt_ctf_writer_put") bt_ctf_writer_put(struct bt_ctf_writer *writer);
1414 struct bt_ctf_writer *bt_ctf_writer_create(const char *path);
1415 struct bt_ctf_stream *bt_ctf_writer_create_stream(struct bt_ctf_writer *writer, struct bt_ctf_stream_class *stream_class);
1416 int bt_ctf_writer_add_environment_field(struct bt_ctf_writer *writer, const char *name, const char *value);
1417 int bt_ctf_writer_add_clock(struct bt_ctf_writer *writer, struct bt_ctf_clock *clock);
1418 char *bt_ctf_writer_get_metadata_string(struct bt_ctf_writer *writer);
1419 void bt_ctf_writer_flush_metadata(struct bt_ctf_writer *writer);
1420 int bt_ctf_writer_set_byte_order(struct bt_ctf_writer *writer, enum bt_ctf_byte_order byte_order);
1421 void bt_ctf_writer_get(struct bt_ctf_writer *writer);
1422 void bt_ctf_writer_put(struct bt_ctf_writer *writer);
1429 def __init__(self, name):
1430 self._c = _bt_ctf_clock_create(name)
1432 raise ValueError("Invalid clock name.")
1435 _bt_ctf_clock_put(self._c)
1438 Get the clock's description.
1441 def description(self):
1442 raise NotImplementedError("Getter not implemented.")
1445 Set the clock's description. The description appears in the clock's TSDL
1449 def description(self, desc):
1450 ret = _bt_ctf_clock_set_description(self._c, str(desc))
1452 raise ValueError("Invalid clock description.")
1455 Get the clock's frequency (Hz).
1458 def frequency(self):
1459 raise NotImplementedError("Getter not implemented.")
1462 Set the clock's frequency (Hz).
1465 def frequency(self, freq):
1466 ret = _bt_ctf_clock_set_frequency(self._c, freq)
1468 raise ValueError("Invalid frequency value.")
1471 Get the clock's precision (in clock ticks).
1474 def precision(self):
1475 raise NotImplementedError("Getter not implemented.")
1478 Set the clock's precision (in clock ticks).
1481 def precision(self, precision):
1482 ret = _bt_ctf_clock_set_precision(self._c, precision)
1485 Get the clock's offset in seconds from POSIX.1 Epoch.
1488 def offset_seconds(self):
1489 raise NotImplementedError("Getter not implemented.")
1492 Set the clock's offset in seconds from POSIX.1 Epoch.
1494 @offset_seconds.setter
1495 def offset_seconds(self, offset_s):
1496 ret = _bt_ctf_clock_set_offset_s(self._c, offset_s)
1498 raise ValueError("Invalid offset value.")
1501 Get the clock's offset in ticks from POSIX.1 Epoch + offset in seconds.
1505 raise NotImplementedError("Getter not implemented.")
1508 Set the clock's offset in ticks from POSIX.1 Epoch + offset in seconds.
1511 def offset(self, offset):
1512 ret = _bt_ctf_clock_set_offset(self._c, offset)
1514 raise ValueError("Invalid offset value.")
1517 Get a clock's absolute attribute. A clock is absolute if the clock
1518 is a global reference across the trace's other clocks.
1522 raise NotImplementedError("Getter not implemented.")
1525 Set a clock's absolute attribute. A clock is absolute if the clock
1526 is a global reference across the trace's other clocks.
1529 def absolute(self, is_absolute):
1530 ret = _bt_ctf_clock_set_is_absolute(self._c, int(is_absolute))
1532 raise ValueError("Could not set the clock's absolute attribute.")
1535 Get the current time in nanoseconds since the clock's origin (offset and
1536 offset_s attributes).
1540 raise NotImplementedError("Getter not implemented.")
1543 Set the current time in nanoseconds since the clock's origin (offset and
1544 offset_s attributes). The clock's value will be sampled as events are
1545 appended to a stream.
1548 def time(self, time):
1549 ret = _bt_ctf_clock_set_time(self._c, time)
1551 raise ValueError("Invalid time value.")
1553 class FieldDeclaration:
1555 FieldDeclaration should not be instantiated directly. Please instantiate
1556 one of the concrete FieldDeclaration classes.
1559 # These values are based on the bt_ctf_integer_base enum
1560 # declared in event-types.h.
1561 INTEGER_BASE_UNKNOWN = -1
1562 INTEGER_BASE_BINARY = 2
1563 INTEGER_BASE_OCTAL = 8
1564 INTEGER_BASE_DECIMAL = 10
1565 INTEGER_BASE_HEXADECIMAL = 16
1568 if self._ft is None:
1569 raise ValueError("FieldDeclaration creation failed.")
1572 _bt_ctf_field_type_put(self._ft)
1575 Get the field type's alignment.
1578 def alignment(self):
1579 raise NotImplementedError("Getter not implemented.")
1582 Set the field type's alignment. Defaults to 1 (bit-aligned). However,
1583 some types, such as structures and string, may impose other alignment
1587 def alignment(self, alignment):
1588 ret = _bt_ctf_field_type_set_alignment(self._ft, alignment)
1590 raise ValueError("Invalid alignment value.")
1593 Get the field type's byte order. One of the ByteOrder's constant.
1596 def byte_order(self):
1597 raise NotImplementedError("Getter not implemented.")
1600 Set the field type's byte order. Use constants defined in the ByteOrder
1604 def byte_order(self, byte_order):
1605 ret = _bt_ctf_field_type_set_byte_order(self._ft, byte_order)
1607 raise ValueError("Could not set byte order value.")
1609 class IntegerFieldDeclaration(FieldDeclaration):
1611 Create a new integer field type of the given size.
1613 def __init__(self, size):
1614 self._ft = _bt_ctf_field_type_integer_create(size)
1618 Get an integer's signedness attribute.
1622 raise NotImplementedError("Getter not implemented.")
1625 Set an integer's signedness attribute.
1628 def signed(self, signed):
1629 ret = _bt_ctf_field_type_integer_set_signed(self._ft, signed)
1631 raise ValueError("Could not set signed attribute.")
1634 Get the integer's base used to pretty-print the resulting trace.
1638 raise NotImplementedError("Getter not implemented.")
1641 Set the integer's base used to pretty-print the resulting trace.
1642 The base must be a constant of the IntegerBase class.
1645 def base(self, base):
1646 ret = _bt_ctf_field_type_integer_set_base(self._ft, base)
1648 raise ValueError("Could not set base value.")
1651 Get the integer's encoding (one of the constants of the
1652 CTFStringEncoding class).
1656 raise NotImplementedError("Getter not implemented.")
1659 An integer encoding may be set to signal that the integer must be printed
1660 as a text character. Must be a constant from the CTFStringEncoding class.
1663 def encoding(self, encoding):
1664 ret = _bt_ctf_field_type_integer_set_encoding(self._ft, encoding)
1666 raise ValueError("Could not set integer encoding.")
1668 class EnumerationFieldDeclaration(FieldDeclaration):
1670 Create a new enumeration field type with the given underlying type.
1672 def __init__(self, integer_type):
1673 if integer_type is None or not isinstance(integer_type, CTFWriter.IntegerFieldDeclaration):
1674 raise TypeError("Invalid integer container.")
1676 self._ft = _bt_ctf_field_type_enumeration_create(integer_type._ft)
1680 Add a mapping to the enumeration. The range's values are inclusive.
1682 def add_mapping(self, name, range_start, range_end):
1683 ret = _bt_ctf_field_type_enumeration_add_mapping(self._ft, str(name), range_start, range_end)
1685 raise ValueError("Could not add mapping to enumeration type.")
1687 class FloatFieldDeclaration(FieldDeclaration):
1694 Create a new floating point field type.
1697 self._ft = _bt_ctf_field_type_floating_point_create()
1701 Get the number of exponent digits to use to store the floating point field.
1704 def exponent_digits(self):
1705 raise NotImplementedError("Getter not implemented.")
1708 Set the number of exponent digits to use to store the floating point field.
1709 The only values currently supported are FLT_EXP_DIG and DBL_EXP_DIG which
1710 are defined as constants of this class.
1712 @exponent_digits.setter
1713 def exponent_digits(self, exponent_digits):
1714 ret = _bt_ctf_field_type_floating_point_set_exponent_digits(self._ft, exponent_digits)
1716 raise ValueError("Could not set exponent digit count.")
1719 Get the number of mantissa digits to use to store the floating point field.
1722 def mantissa_digits(self):
1723 raise NotImplementedError("Getter not implemented.")
1726 Set the number of mantissa digits to use to store the floating point field.
1727 The only values currently supported are FLT_MANT_DIG and DBL_MANT_DIG which
1728 are defined as constants of this class.
1730 @mantissa_digits.setter
1731 def mantissa_digits(self, mantissa_digits):
1732 ret = _bt_ctf_field_type_floating_point_set_mantissa_digits(self._ft, mantissa_digits)
1734 raise ValueError("Could not set mantissa digit count.")
1736 class StructureFieldDeclaration(FieldDeclaration):
1738 Create a new structure field type.
1741 self._ft = _bt_ctf_field_type_structure_create()
1745 Add a field of type "field_type" to the structure.
1747 def add_field(self, field_type, field_name):
1748 ret = _bt_ctf_field_type_structure_add_field(self._ft, field_type._ft, str(field_name))
1750 raise ValueError("Could not add field to structure.")
1752 class VariantFieldDeclaration(FieldDeclaration):
1754 Create a new variant field type.
1756 def __init__(self, enum_tag, tag_name):
1757 if enum_tag is None or not isinstance(enum_tag, CTFWriter.EnumerationFieldDeclaration):
1758 raise TypeError("Invalid tag type; must be of type EnumerationFieldDeclaration.")
1760 self._ft = _bt_ctf_field_type_variant_create(enum_tag._ft, str(tag_name))
1764 Add a field of type "field_type" to the variant.
1766 def add_field(self, field_type, field_name):
1767 ret = _bt_ctf_field_type_variant_add_field(self._ft, field_type._ft, str(field_name))
1769 raise ValueError("Could not add field to variant.")
1771 class ArrayFieldDeclaration(FieldDeclaration):
1773 Create a new array field type.
1775 def __init__(self, element_type, length):
1776 self._ft = _bt_ctf_field_type_array_create(element_type._ft, length)
1779 class SequenceFieldDeclaration(FieldDeclaration):
1781 Create a new sequence field type.
1783 def __init__(self, element_type, length_field_name):
1784 self._ft = _bt_ctf_field_type_sequence_create(element_type._ft, str(length_field_name))
1787 class StringFieldDeclaration(FieldDeclaration):
1789 Create a new string field type.
1792 self._ft = _bt_ctf_field_type_string_create()
1796 Get a string type's encoding (a constant from the CTFStringEncoding class).
1800 raise NotImplementedError("Getter not implemented.")
1803 Set a string type's encoding. Must be a constant from the CTFStringEncoding class.
1806 def encoding(self, encoding):
1807 ret = _bt_ctf_field_type_string_set_encoding(self._ft, encoding)
1809 raise ValueError("Could not set string encoding.")
1812 Create an instance of a field.
1815 def create_field(self, field_type):
1816 if field_type is None or not isinstance(field_type, CTFWriter.FieldDeclaration):
1817 raise TypeError("Invalid field_type. Type must be a FieldDeclaration-derived class.")
1819 if isinstance(field_type, CTFWriter.IntegerFieldDeclaration):
1820 return CTFWriter.IntegerField(field_type)
1821 elif isinstance(field_type, CTFWriter.EnumerationFieldDeclaration):
1822 return CTFWriter.EnumerationField(field_type)
1823 elif isinstance(field_type, CTFWriter.FloatFieldDeclaration):
1824 return CTFWriter.FloatFieldingPoint(field_type)
1825 elif isinstance(field_type, CTFWriter.StructureFieldDeclaration):
1826 return CTFWriter.StructureField(field_type)
1827 elif isinstance(field_type, CTFWriter.VariantFieldDeclaration):
1828 return CTFWriter.VariantField(field_type)
1829 elif isinstance(field_type, CTFWriter.ArrayFieldDeclaration):
1830 return CTFWriter.ArrayField(field_type)
1831 elif isinstance(field_type, CTFWriter.SequenceFieldDeclaration):
1832 return CTFWriter.SequenceField(field_type)
1833 elif isinstance(field_type, CTFWriter.StringFieldDeclaration):
1834 return CTFWriter.StringField(field_type)
1838 Base class, do not instantiate.
1840 def __init__(self, field_type):
1841 if not isinstance(field_type, CTFWriter.FieldDeclaration):
1842 raise TypeError("Invalid field_type argument.")
1844 self._f = _bt_ctf_field_create(field_type._ft)
1846 raise ValueError("Field creation failed.")
1849 _bt_ctf_field_put(self._f)
1852 def _create_field_from_native_instance(native_field_instance):
1854 CTFTypeId.INTEGER : CTFWriter.IntegerField,
1855 CTFTypeId.FLOAT : CTFWriter.FloatFieldingPoint,
1856 CTFTypeId.ENUM : CTFWriter.EnumerationField,
1857 CTFTypeId.STRING : CTFWriter.StringField,
1858 CTFTypeId.STRUCT : CTFWriter.StructureField,
1859 CTFTypeId.VARIANT : CTFWriter.VariantField,
1860 CTFTypeId.ARRAY : CTFWriter.ArrayField,
1861 CTFTypeId.SEQUENCE : CTFWriter.SequenceField
1864 field_type = _bt_python_get_field_type(native_field_instance)
1865 if field_type == CTFTypeId.UNKNOWN:
1866 raise TypeError("Invalid field instance")
1868 field = CTFWriter.Field.__new__(CTFWriter.Field)
1869 field._f = native_field_instance
1870 field.__class__ = type_dict[field_type]
1873 class IntegerField(Field):
1875 Get an integer field's value.
1879 raise NotImplementedError("Getter not implemented.")
1882 Set an integer field's value.
1885 def value(self, value):
1886 signedness = _bt_python_field_integer_get_signedness(self._f)
1888 raise TypeError("Invalid integer instance.")
1891 ret = _bt_ctf_field_unsigned_integer_set_value(self._f, value)
1893 ret = _bt_ctf_field_signed_integer_set_value(self._f, value)
1896 raise ValueError("Could not set integer field value.")
1898 class EnumerationField(Field):
1900 Return the enumeration's underlying container field (an integer field).
1903 def container(self):
1904 container = CTFWriter.IntegerField.__new__(CTFWriter.IntegerField)
1905 container._f = _bt_ctf_field_enumeration_get_container(self._f)
1906 if container._f is None:
1907 raise TypeError("Invalid enumeration field type.")
1910 class FloatFieldingPoint(Field):
1912 Get a floating point field's value.
1916 raise NotImplementedError("Getter not implemented.")
1919 Set a floating point field's value.
1922 def value(self, value):
1923 ret = _bt_ctf_field_floating_point_set_value(self._f, float(value))
1925 raise ValueError("Could not set floating point field value.")
1927 class StructureField(Field):
1929 Get the structure's field corresponding to the provided field name.
1931 def field(self, field_name):
1932 native_instance = _bt_ctf_field_structure_get_field(self._f, str(field_name))
1933 if native_instance is None:
1934 raise ValueError("Invalid field_name provided.")
1935 return CTFWriter.Field._create_field_from_native_instance(native_instance)
1937 class VariantField(Field):
1939 Return the variant's selected field. The "tag" field is the selector enum field.
1941 def field(self, tag):
1942 native_instance = _bt_ctf_field_variant_get_field(self._f, tag._f)
1943 if native_instance is None:
1944 raise ValueError("Invalid tag provided.")
1945 return CTFWriter.Field._create_field_from_native_instance(native_instance)
1947 class ArrayField(Field):
1949 Return the array's field at position "index".
1951 def field(self, index):
1952 native_instance = _bt_ctf_field_array_get_field(self._f, index)
1953 if native_instance is None:
1954 raise IndexError("Invalid index provided.")
1955 return CTFWriter.Field._create_field_from_native_instance(native_instance)
1957 class SequenceField(Field):
1959 Get the sequence's length field (IntegerField).
1963 raise NotImplementedError("Getter not implemented.")
1966 Set the sequence's length field (IntegerField).
1969 def length(self, length_field):
1970 if not isinstance(length_field, CTFWriter.IntegerField):
1971 raise TypeError("Invalid length field.")
1972 ret = _bt_ctf_field_sequence_set_length(self._f, length_field._f)
1974 raise ValueError("Could not set sequence length.")
1977 Return the sequence's field at position "index".
1979 def field(self, index):
1980 native_instance = _bt_ctf_field_sequence_get_field(self._f, index)
1981 if native_instance is None:
1982 raise ValueError("Could not get sequence element at index.")
1983 return CTFWriter.Field._create_field_from_native_instance(native_instance)
1985 class StringField(Field):
1987 Get a string field's value.
1991 raise NotImplementedError("Getter not implemented.")
1994 Set a string field's value.
1997 def value(self, value):
1998 ret = _bt_ctf_field_string_set_value(self._f, str(value))
2000 raise ValueError("Could not set string field value.")
2004 Create a new event class of the given name.
2006 def __init__(self, name):
2007 self._ec = _bt_ctf_event_class_create(name)
2008 if self._ec is None:
2009 raise ValueError("Event class creation failed.")
2012 _bt_ctf_event_class_put(self._ec)
2015 Add a field of type "field_type" to the event class.
2017 def add_field(self, field_type, field_name):
2018 ret = _bt_ctf_event_class_add_field(self._ec, field_type._ft, str(field_name))
2020 raise ValueError("Could not add field to event class.")
2024 Create a new event of the given event class.
2026 def __init__(self, event_class):
2027 if not isinstance(event_class, CTFWriter.EventClass):
2028 raise TypeError("Invalid event_class argument.")
2030 self._e = _bt_ctf_event_create(event_class._ec)
2032 raise ValueError("Event creation failed.")
2035 _bt_ctf_event_put(self._e)
2038 Set a manually created field as an event's payload.
2040 def set_payload(self, field_name, value_field):
2041 if not isinstance(value, CTFWriter.Field):
2042 raise TypeError("Invalid value type.")
2043 ret = _bt_ctf_event_set_payload(self._e, str(field_name), value_field._f)
2045 raise ValueError("Could not set event field payload.")
2048 Get a field from event.
2050 def payload(self, field_name):
2051 native_instance = _bt_ctf_event_get_payload(self._e, str(field_name))
2052 if native_instance is None:
2053 raise ValueError("Could not get event payload.")
2054 return CTFWriter.Field._create_field_from_native_instance(native_instance)
2058 Create a new stream class of the given name.
2060 def __init__(self, name):
2061 self._sc = _bt_ctf_stream_class_create(name)
2062 if self._sc is None:
2063 raise ValueError("Stream class creation failed.")
2066 _bt_ctf_stream_class_put(self._sc)
2069 Get a stream class' clock.
2073 raise NotImplementedError("Getter not implemented.")
2076 Assign a clock to a stream class.
2079 def clock(self, clock):
2080 if not isinstance(clock, CTFWriter.Clock):
2081 raise TypeError("Invalid clock type.")
2083 ret = _bt_ctf_stream_class_set_clock(self._sc, clock._c)
2085 raise ValueError("Could not set stream class clock.")
2088 Add an event class to a stream class. New events can be added even after a
2089 stream has been instantiated and events have been appended. However, a stream
2090 will not accept events of a class that has not been registered beforehand.
2092 def add_event_class(self, event_class):
2093 if not isinstance(event_class, CTFWriter.EventClass):
2094 raise TypeError("Invalid event_class type.")
2096 ret = _bt_ctf_stream_class_add_event_class(self._sc, event_class._ec)
2098 raise ValueError("Could not add event class.")
2102 Create a stream of the given class.
2104 def __init__(self, stream_class):
2105 if not isinstance(stream_class, CTFWriter.StreamClass):
2106 raise TypeError("Invalid stream_class type.")
2108 self._s = _bt_ctf_stream_create(stream_class._sc)
2110 raise ValueError("Stream creation failed.")
2113 _bt_ctf_stream_put(self._s)
2116 Increase the current packet's discarded event count.
2118 def append_discarded_events(self, event_count):
2119 _bt_ctf_stream_append_discarded_events(self._s, event_count)
2122 Append "event" to the stream's current packet. The stream's associated clock
2123 will be sampled during this call. The event shall not be modified after
2124 being appended to a stream.
2126 def append_event(self, event):
2127 ret = _bt_ctf_stream_append_event(self._s, event._e)
2129 raise ValueError("Could not append event to stream.")
2132 The stream's current packet's events will be flushed to disk. Events
2133 subsequently appended to the stream will be added to a new packet.
2136 ret = _bt_ctf_stream_flush(self._s)
2138 raise ValueError("Could not flush stream.")
2142 Create a new writer that will produce a trace in the given path.
2144 def __init__(self, path):
2145 self._w = _bt_ctf_writer_create(path)
2147 raise ValueError("Writer creation failed.")
2150 _bt_ctf_writer_put(self._w)
2153 Create a new stream instance and register it to the writer.
2155 def create_stream(self, stream_class):
2156 if not isinstance(stream_class, CTFWriter.StreamClass):
2157 raise TypeError("Invalid stream_class type.")
2159 stream = CTFWriter.Stream.__new__(CTFWriter.Stream)
2160 stream._s = _bt_ctf_writer_create_stream(self._w, stream_class._sc)
2164 Add an environment field to the trace.
2166 def add_environment_field(self, name, value):
2167 ret = _bt_ctf_writer_add_environment_field(self._w, str(name), str(value))
2169 raise ValueError("Could not add environment field to trace.")
2172 Add a clock to the trace. Clocks assigned to stream classes must be
2173 registered to the writer.
2175 def add_clock(self, clock):
2176 ret = _bt_ctf_writer_add_clock(self._w, clock._c)
2178 raise ValueError("Could not add clock to Writer.")
2181 Get the trace's TSDL meta-data.
2185 return _bt_ctf_writer_get_metadata_string(self._w)
2188 Flush the trace's metadata to the metadata file.
2190 def flush_metadata(self):
2191 _bt_ctf_writer_flush_metadata(self._w)
2194 Get the trace's byte order. Must be a constant from the ByteOrder
2198 def byte_order(self):
2199 raise NotImplementedError("Getter not implemented.")
2202 Set the trace's byte order. Must be a constant from the ByteOrder
2203 class. Defaults to BYTE_ORDER_NATIVE, the host machine's endianness.
2206 def byte_order(self, byte_order):
2207 ret = _bt_ctf_writer_set_byte_order(self._w, byte_order)
2209 raise ValueError("Could not set trace's byte order.")