4 * Babeltrace Python Module interface file
6 * Copyright 2012 EfficiOS Inc.
8 * Author: Danny Serres <danny.serres@efficios.com>
10 * Permission is hereby granted, free of charge, to any person obtaining a copy
11 * of this software and associated documentation files (the "Software"), to deal
12 * in the Software without restriction, including without limitation the rights
13 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
14 * copies of the Software, and to permit persons to whom the Software is
15 * furnished to do so, subject to the following conditions:
17 * The above copyright notice and this permission notice shall be included in
18 * all copies or substantial portions of the Software.
23 "BABELTRACE_VERSION_STR
25 Babeltrace is a trace viewer and converter reading and writing the
26 Common Trace Format (CTF). Its main use is to pretty-print CTF
27 traces into a human-readable text output.
29 To use this module, the first step is to create a Context and add a
33 %module(docstring=DOCSTRING) babeltrace
37 #define SWIG_FILE_WITH_INIT
38 #include <babeltrace/babeltrace.h>
39 #include <babeltrace/babeltrace-internal.h>
40 #include <babeltrace/trace-handle.h>
41 #include <babeltrace/trace-handle-internal.h>
42 #include <babeltrace/context.h>
43 #include <babeltrace/context-internal.h>
44 #include <babeltrace/iterator.h>
45 #include <babeltrace/iterator-internal.h>
46 #include <babeltrace/format.h>
47 #include <babeltrace/list.h>
48 #include <babeltrace/types.h>
49 #include <babeltrace/ctf/iterator.h>
50 #include "python-complements.h"
51 #include <babeltrace/ctf-writer/clock.h>
52 #include <babeltrace/ctf-writer/event-fields.h>
53 #include <babeltrace/ctf-writer/event-types.h>
54 #include <babeltrace/ctf-writer/event.h>
55 #include <babeltrace/ctf-writer/stream.h>
56 #include <babeltrace/ctf-writer/writer.h>
59 typedef unsigned long long uint64_t;
60 typedef long long int64_t;
61 typedef int bt_intern_str;
63 /* =================================================================
65 ¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯
68 FILE *_bt_file_open(char *file_path, char *mode);
69 void _bt_file_close(FILE *fp);
70 struct bt_definition **_bt_python_field_listcaller(
71 const struct bt_ctf_event *ctf_event,
72 const struct bt_definition *scope,
73 unsigned int *OUTPUT);
74 struct bt_definition *_bt_python_field_one_from_list(
75 struct bt_definition **list, int index);
76 struct bt_ctf_event_decl **_bt_python_event_decl_listcaller(
78 struct bt_context *ctx,
79 unsigned int *OUTPUT);
80 struct bt_ctf_event_decl *_bt_python_decl_one_from_list(
81 struct bt_ctf_event_decl **list, int index);
82 struct bt_ctf_field_decl **_by_python_field_decl_listcaller(
83 struct bt_ctf_event_decl *event_decl,
84 enum bt_ctf_scope scope,
85 unsigned int *OUTPUT);
86 struct bt_ctf_field_decl *_bt_python_field_decl_one_from_list(
87 struct bt_ctf_field_decl **list, int index);
88 struct definition_array *_bt_python_get_array_from_def(
89 struct bt_definition *field);
90 struct definition_sequence *_bt_python_get_sequence_from_def(
91 struct bt_definition *field);
92 int _bt_python_field_integer_get_signedness(const struct bt_ctf_field *field);
93 enum ctf_type_id _bt_python_get_field_type(const struct bt_ctf_field *field);
95 /* =================================================================
96 CONTEXT.H, CONTEXT-INTERNAL.H
97 ¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯
100 %rename("_bt_context_create") bt_context_create(void);
101 %rename("_bt_context_add_trace") bt_context_add_trace(
102 struct bt_context *ctx, const char *path, const char *format,
103 void (*packet_seek)(struct bt_stream_pos *pos, size_t index, int whence),
104 struct bt_mmap_stream_list *stream_list, FILE *metadata);
105 %rename("_bt_context_remove_trace") bt_context_remove_trace(
106 struct bt_context *ctx, int trace_id);
107 %rename("_bt_context_get") bt_context_get(struct bt_context *ctx);
108 %rename("_bt_context_put") bt_context_put(struct bt_context *ctx);
109 %rename("_bt_ctf_event_get_context") bt_ctf_event_get_context(
110 const struct bt_ctf_event *event);
112 struct bt_context *bt_context_create(void);
113 int bt_context_add_trace(struct bt_context *ctx, const char *path, const char *format,
114 void (*packet_seek)(struct bt_stream_pos *pos, size_t index, int whence),
115 struct bt_mmap_stream_list *stream_list, FILE *metadata);
116 void bt_context_remove_trace(struct bt_context *ctx, int trace_id);
117 void bt_context_get(struct bt_context *ctx);
118 void bt_context_put(struct bt_context *ctx);
119 struct bt_context *bt_ctf_event_get_context(const struct bt_ctf_event *event);
121 // class Context to prevent direct access to struct bt_context
125 The context represents the object in which a trace_collection is
126 open. As long as this structure is allocated, the trace_collection
127 is open and the traces it contains can be read and seeked by the
128 iterators and callbacks.
132 self._c = _bt_context_create()
135 _bt_context_put(self._c)
137 def add_trace(self, path, format_str,
138 packet_seek=None, stream_list=None, metadata=None):
140 Add a trace by path to the context.
144 path is the path to the trace, it is not recursive.
145 If "path" is None, stream_list is used instead as a list
146 of mmap streams to open for the trace.
148 format is a string containing the format name in which the trace was
151 packet_seek is not implemented for Python. Should be left None to
152 use the default packet_seek handler provided by the trace format.
154 stream_list is a linked list of streams, it is used to open a trace
155 where the trace data is located in memory mapped areas instead of
156 trace files, this argument should be None when path is not None.
158 The metadata parameter acts as a metadata override when not None,
159 otherwise the format handles the metadata opening.
161 Return: the corresponding TraceHandle on success or None on error.
163 if metadata is not None:
164 metadata = metadata._file
166 ret = _bt_context_add_trace(self._c, path, format_str, packet_seek,
167 stream_list, metadata)
171 th = TraceHandle.__new__(TraceHandle)
175 def add_traces_recursive(self, path, format_str):
177 Open a trace recursively.
179 Find each trace present in the subdirectory starting from the given
180 path, and add them to the context.
182 Return a dict of TraceHandle instances (the full path is the key).
183 Return None on error.
193 for fullpath, dirs, files in os.walk(path):
194 if "metadata" in files:
195 trace_handle = self.add_trace(fullpath, format_str)
196 if trace_handle is None:
200 trace_handles[fullpath] = trace_handle
203 if noTrace and error:
207 def remove_trace(self, trace_handle):
209 Remove a trace from the context.
210 Effectively closing the trace.
213 _bt_context_remove_trace(self._c, trace_handle._id)
214 except AttributeError:
215 raise TypeError("in remove_trace, "
216 "argument 2 must be a TraceHandle instance")
221 /* =================================================================
226 %rename("lookup_format") bt_lookup_format(bt_intern_str qname);
227 %rename("_bt_print_format_list") bt_fprintf_format_list(FILE *fp);
228 %rename("register_format") bt_register_format(struct format *format);
229 %rename("unregister_format") bt_unregister_format(struct bt_format *format);
231 extern struct format *bt_lookup_format(bt_intern_str qname);
232 extern void bt_fprintf_format_list(FILE *fp);
233 extern int bt_register_format(struct bt_format *format);
234 extern void bt_unregister_format(struct bt_format *format);
238 def print_format_list(babeltrace_file):
240 Print a list of available formats to file.
242 babeltrace_file must be a File instance opened in write mode.
245 if babeltrace_file._file is not None:
246 _bt_print_format_list(babeltrace_file._file)
247 except AttributeError:
248 raise TypeError("in print_format_list, "
249 "argument 1 must be a File instance")
254 /* =================================================================
255 ITERATOR.H, ITERATOR-INTERNAL.H
256 ¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯
259 %rename("_bt_iter_create") bt_iter_create(struct bt_context *ctx,
260 const struct bt_iter_pos *begin_pos, const struct bt_iter_pos *end_pos);
261 %rename("_bt_iter_destroy") bt_iter_destroy(struct bt_iter *iter);
262 %rename("_bt_iter_next") bt_iter_next(struct bt_iter *iter);
263 %rename("_bt_iter_get_pos") bt_iter_get_pos(struct bt_iter *iter);
264 %rename("_bt_iter_free_pos") bt_iter_free_pos(struct bt_iter_pos *pos);
265 %rename("_bt_iter_set_pos") bt_iter_set_pos(struct bt_iter *iter,
266 const struct bt_iter_pos *pos);
267 %rename("_bt_iter_create_time_pos") bt_iter_create_time_pos(struct bt_iter *iter,
270 struct bt_iter *bt_iter_create(struct bt_context *ctx,
271 const struct bt_iter_pos *begin_pos, const struct bt_iter_pos *end_pos);
272 void bt_iter_destroy(struct bt_iter *iter);
273 int bt_iter_next(struct bt_iter *iter);
274 struct bt_iter_pos *bt_iter_get_pos(struct bt_iter *iter);
275 void bt_iter_free_pos(struct bt_iter_pos *pos);
276 int bt_iter_set_pos(struct bt_iter *iter, const struct bt_iter_pos *pos);
277 struct bt_iter_pos *bt_iter_create_time_pos(struct bt_iter *iter, uint64_t timestamp);
279 %rename("_bt_iter_pos") bt_iter_pos;
280 %rename("SEEK_TIME") BT_SEEK_TIME;
281 %rename("SEEK_RESTORE") BT_SEEK_RESTORE;
282 %rename("SEEK_CUR") BT_SEEK_CUR;
283 %rename("SEEK_BEGIN") BT_SEEK_BEGIN;
284 %rename("SEEK_LAST") BT_SEEK_LAST;
286 // This struct is taken from iterator.h
287 // All changes to the struct must also be made here
290 BT_SEEK_TIME, /* uses u.seek_time */
291 BT_SEEK_RESTORE, /* uses u.restore */
298 struct bt_saved_pos *restore;
306 """This class represents the position where to set an iterator."""
310 def __init__(self, seek_type, seek_time = None):
312 seek_type represents the type of seek to use.
313 seek_time is the timestamp to seek to when using SEEK_TIME, it
314 is expressed in nanoseconds
315 Only use SEEK_RESTORE on IterPos obtained from the get_pos function
319 self._pos = _bt_iter_pos()
320 self._pos.type = seek_type
321 if seek_time and seek_type == SEEK_TIME:
322 self._pos.u.seek_time = seek_time
323 self.__can_access = True
326 if not self.__can_access:
327 _bt_iter_free_pos(self._pos)
331 raise AttributeError("seek_type is not available")
332 return self._pos.type
334 def _set_type(self, seek_type):
336 raise AttributeError("seek_type is not available")
337 self._pos.type = seek_type
341 raise AttributeError("seek_time is not available")
343 elif self._pos.type is not SEEK_TIME:
344 raise TypeError("seek_type is not SEEK_TIME")
346 return self._pos.u.seek_time
348 def _set_time(self, time):
350 raise AttributeError("seek_time is not available")
352 elif self._pos.type is not SEEK_TIME:
353 raise TypeError("seek_type is not SEEK_TIME")
355 self._pos.u.seek_time = time
361 seek_type = property(_get_type, _set_type)
362 seek_time = property(_get_time, _set_time)
369 def __init__(self, context, begin_pos = None, end_pos = None, _no_init = None):
371 Allocate a trace collection iterator.
373 begin_pos and end_pos are optional parameters to specify the
374 position at which the trace collection should be seeked upon
375 iterator creation, and the position at which iteration will
376 start returning "EOF".
378 By default, if begin_pos is None, a BT_SEEK_CUR is performed at
379 creation. By default, if end_pos is None, a BT_SEEK_END (end of
380 trace) is the EOF criterion.
383 if begin_pos is None:
388 except AttributeError:
389 raise TypeError("in __init__, "
390 "argument 3 must be a IterPos instance")
397 except AttributeError:
398 raise TypeError("in __init__, "
399 "argument 4 must be a IterPos instance")
402 self._bi = _bt_iter_create(context._c, bp, ep)
403 except AttributeError:
404 raise TypeError("in __init__, "
405 "argument 2 must be a Context instance")
407 self.__with_init = True
414 _bt_iter_destroy(self._bi)
418 Move trace collection position to the next event.
419 Returns 0 on success, a negative value on error.
421 return _bt_iter_next(self._bi)
424 """Return a IterPos class of the current iterator position."""
426 ret.__can_access = False
427 ret._pos = _bt_iter_get_pos(self._bi)
430 def set_pos(self, pos):
432 Move the iterator to a given position.
434 On error, the stream_heap is reinitialized and returned empty.
435 Return 0 for success.
436 Return EOF if the position requested is after the last event of the
438 Return -EINVAL when called with invalid parameter.
439 Return -ENOMEM if the stream_heap could not be properly initialized.
442 return _bt_iter_set_pos(self._bi, pos._pos)
443 except AttributeError:
444 raise TypeError("in set_pos, "
445 "argument 2 must be a IterPos instance")
447 def create_time_pos(self, timestamp):
449 Create a position based on time
450 This function allocates and returns a new IterPos to be able to
451 restore an iterator position based on a timestamp.
455 raise TypeError("timestamp must be an unsigned int")
458 ret.__can_access = False
459 ret._pos = _bt_iter_create_time_pos(self._bi, timestamp)
464 /* =================================================================
467 *** Enum copied from clock-type.h
468 All changes must also be made here
470 %rename("CLOCK_CYCLES") BT_CLOCK_CYCLES;
471 %rename("CLOCK_REAL") BT_CLOCK_REAL;
478 /* =================================================================
479 TRACE-HANDLE.H, TRACE-HANDLE-INTERNAL.H
480 ¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯
483 %rename("_bt_trace_handle_create") bt_trace_handle_create(struct bt_context *ctx);
484 %rename("_bt_trace_handle_destroy") bt_trace_handle_destroy(struct bt_trace_handle *bt);
485 struct bt_trace_handle *bt_trace_handle_create(struct bt_context *ctx);
486 void bt_trace_handle_destroy(struct bt_trace_handle *bt);
488 %rename("_bt_trace_handle_get_path") bt_trace_handle_get_path(struct bt_context *ctx,
490 %rename("_bt_trace_handle_get_timestamp_begin") bt_trace_handle_get_timestamp_begin(
491 struct bt_context *ctx, int handle_id, enum bt_clock_type type);
492 %rename("_bt_trace_handle_get_timestamp_end") bt_trace_handle_get_timestamp_end(
493 struct bt_context *ctx, int handle_id, enum bt_clock_type type);
494 const char *bt_trace_handle_get_path(struct bt_context *ctx, int handle_id);
495 uint64_t bt_trace_handle_get_timestamp_begin(struct bt_context *ctx, int handle_id,
496 enum bt_clock_type type);
497 uint64_t bt_trace_handle_get_timestamp_end(struct bt_context *ctx, int handle_id,
498 enum bt_clock_type type);
500 %rename("_bt_ctf_event_get_handle_id") bt_ctf_event_get_handle_id(
501 const struct bt_ctf_event *event);
502 int bt_ctf_event_get_handle_id(const struct bt_ctf_event *event);
507 class TraceHandle(object):
509 The TraceHandle allows the user to manipulate a trace file directly.
510 It is a unique identifier representing a trace file.
515 raise NotImplementedError("TraceHandle cannot be instantiated")
518 return "Babeltrace TraceHandle: trace_id('{0}')".format(self._id)
521 """Return the TraceHandle id."""
524 def get_path(self, context):
525 """Return the path of a TraceHandle."""
527 return _bt_trace_handle_get_path(context._c, self._id)
528 except AttributeError:
529 raise TypeError("in get_path, "
530 "argument 2 must be a Context instance")
532 def get_timestamp_begin(self, context, clock_type):
533 """Return the creation time of the buffers of a trace."""
535 return _bt_trace_handle_get_timestamp_begin(
536 context._c, self._id,clock_type)
537 except AttributeError:
538 raise TypeError("in get_timestamp_begin, "
539 "argument 2 must be a Context instance")
541 def get_timestamp_end(self, context, clock_type):
542 """Return the destruction timestamp of the buffers of a trace."""
544 return _bt_trace_handle_get_timestamp_end(
545 context._c, self._id, clock_type)
546 except AttributeError:
547 raise TypeError("in get_timestamp_end, "
548 "argument 2 must be a Context instance")
554 // =================================================================
556 // =================================================================
558 /* =================================================================
564 %rename("_bt_ctf_iter_create") bt_ctf_iter_create(struct bt_context *ctx,
565 const struct bt_iter_pos *begin_pos,
566 const struct bt_iter_pos *end_pos);
567 %rename("_bt_ctf_get_iter") bt_ctf_get_iter(struct bt_ctf_iter *iter);
568 %rename("_bt_ctf_iter_destroy") bt_ctf_iter_destroy(struct bt_ctf_iter *iter);
569 %rename("_bt_ctf_iter_read_event") bt_ctf_iter_read_event(struct bt_ctf_iter *iter);
571 struct bt_ctf_iter *bt_ctf_iter_create(struct bt_context *ctx,
572 const struct bt_iter_pos *begin_pos,
573 const struct bt_iter_pos *end_pos);
574 struct bt_iter *bt_ctf_get_iter(struct bt_ctf_iter *iter);
575 void bt_ctf_iter_destroy(struct bt_ctf_iter *iter);
576 struct bt_ctf_event *bt_ctf_iter_read_event(struct bt_ctf_iter *iter);
581 %rename("_bt_ctf_get_top_level_scope") bt_ctf_get_top_level_scope(const struct
582 bt_ctf_event *event, enum bt_ctf_scope scope);
583 %rename("_bt_ctf_event_name") bt_ctf_event_name(const struct bt_ctf_event *ctf_event);
584 %rename("_bt_ctf_get_timestamp") bt_ctf_get_timestamp(
585 const struct bt_ctf_event *ctf_event);
586 %rename("_bt_ctf_get_cycles") bt_ctf_get_cycles(
587 const struct bt_ctf_event *ctf_event);
589 %rename("_bt_ctf_get_field") bt_ctf_get_field(const struct bt_ctf_event *ctf_event,
590 const struct bt_definition *scope, const char *field);
591 %rename("_bt_ctf_get_index") bt_ctf_get_index(const struct bt_ctf_event *ctf_event,
592 const struct bt_definition *field, unsigned int index);
593 %rename("_bt_ctf_field_name") bt_ctf_field_name(const struct bt_definition *field);
594 %rename("_bt_ctf_field_type") bt_ctf_field_type(const struct bt_declaration *field);
595 %rename("_bt_ctf_get_int_signedness") bt_ctf_get_int_signedness(
596 const struct bt_declaration *field);
597 %rename("_bt_ctf_get_int_base") bt_ctf_get_int_base(const struct bt_declaration *field);
598 %rename("_bt_ctf_get_int_byte_order") bt_ctf_get_int_byte_order(
599 const struct bt_declaration *field);
600 %rename("_bt_ctf_get_int_len") bt_ctf_get_int_len(const struct bt_declaration *field);
601 %rename("_bt_ctf_get_enum_int") bt_ctf_get_enum_int(const struct bt_definition *field);
602 %rename("_bt_ctf_get_enum_str") bt_ctf_get_enum_str(const struct bt_definition *field);
603 %rename("_bt_ctf_get_encoding") bt_ctf_get_encoding(const struct bt_declaration *field);
604 %rename("_bt_ctf_get_array_len") bt_ctf_get_array_len(const struct bt_declaration *field);
605 %rename("_bt_ctf_get_uint64") bt_ctf_get_uint64(const struct bt_definition *field);
606 %rename("_bt_ctf_get_int64") bt_ctf_get_int64(const struct bt_definition *field);
607 %rename("_bt_ctf_get_char_array") bt_ctf_get_char_array(const struct bt_definition *field);
608 %rename("_bt_ctf_get_string") bt_ctf_get_string(const struct bt_definition *field);
609 %rename("_bt_ctf_get_float") bt_ctf_get_float(const struct bt_definition *field);
610 %rename("_bt_ctf_get_variant") bt_ctf_get_variant(const struct bt_definition *field);
611 %rename("_bt_ctf_field_get_error") bt_ctf_field_get_error(void);
612 %rename("_bt_ctf_get_decl_event_name") bt_ctf_get_decl_event_name(const struct
613 bt_ctf_event_decl *event);
614 %rename("_bt_ctf_get_decl_field_name") bt_ctf_get_decl_field_name(
615 const struct bt_ctf_field_decl *field);
616 %rename("_bt_ctf_get_decl_from_def") bt_ctf_get_decl_from_def(
617 const struct bt_definition *field);
618 %rename("_bt_array_index") bt_array_index(struct definition_array *array, uint64_t i);
619 %rename("_bt_sequence_len") bt_sequence_len(struct definition_sequence *sequence);
620 %rename("_bt_sequence_index") bt_sequence_index(struct definition_sequence *sequence, uint64_t i);
621 %rename("_bt_ctf_get_struct_field_count") bt_ctf_get_struct_field_count(const struct bt_definition *structure);
622 %rename("_bt_ctf_get_struct_field_index") bt_ctf_get_struct_field_index(const struct bt_definition *structure, uint64_t i);
624 const struct bt_definition *bt_ctf_get_top_level_scope(const struct bt_ctf_event *ctf_event,
625 enum bt_ctf_scope scope);
626 const char *bt_ctf_event_name(const struct bt_ctf_event *ctf_event);
627 uint64_t bt_ctf_get_timestamp(const struct bt_ctf_event *ctf_event);
628 uint64_t bt_ctf_get_cycles(const struct bt_ctf_event *ctf_event);
629 const struct bt_definition *bt_ctf_get_field(const struct bt_ctf_event *ctf_event,
630 const struct bt_definition *scope,
632 const struct bt_definition *bt_ctf_get_index(const struct bt_ctf_event *ctf_event,
633 const struct bt_definition *field,
635 const char *bt_ctf_field_name(const struct bt_definition *field);
636 enum ctf_type_id bt_ctf_field_type(const struct bt_declaration *field);
637 int bt_ctf_get_int_signedness(const struct bt_declaration *field);
638 int bt_ctf_get_int_base(const struct bt_declaration *field);
639 int bt_ctf_get_int_byte_order(const struct bt_declaration *field);
640 ssize_t bt_ctf_get_int_len(const struct bt_declaration *field);
641 const struct bt_definition *bt_ctf_get_enum_int(const struct bt_definition *field);
642 const char *bt_ctf_get_enum_str(const struct bt_definition *field);
643 enum ctf_string_encoding bt_ctf_get_encoding(const struct bt_declaration *field);
644 int bt_ctf_get_array_len(const struct bt_declaration *field);
645 struct bt_definition *bt_array_index(struct definition_array *array, uint64_t i);
646 uint64_t bt_ctf_get_uint64(const struct bt_definition *field);
647 int64_t bt_ctf_get_int64(const struct bt_definition *field);
648 char *bt_ctf_get_char_array(const struct bt_definition *field);
649 char *bt_ctf_get_string(const struct bt_definition *field);
650 double bt_ctf_get_float(const struct bt_definition *field);
651 const struct bt_definition *bt_ctf_get_variant(const struct bt_definition *field);
652 int bt_ctf_field_get_error(void);
653 const char *bt_ctf_get_decl_event_name(const struct bt_ctf_event_decl *event);
654 const char *bt_ctf_get_decl_field_name(const struct bt_ctf_field_decl *field);
655 const struct bt_declaration *bt_ctf_get_decl_from_def(const struct bt_definition *field);
656 uint64_t bt_sequence_len(struct definition_sequence *sequence);
657 struct bt_definition *bt_sequence_index(struct definition_sequence *sequence, uint64_t i);
658 uint64_t bt_ctf_get_struct_field_count(const struct bt_definition *structure);
659 const struct bt_definition *bt_ctf_get_struct_field_index(const struct bt_definition *structure, uint64_t i);
663 class CTFStringEncoding:
669 #enum equivalent, accessible constants
670 #These are taken directly from ctf/events.h
671 #All changes to enums must also be made here
685 def get_type_name(id):
687 constants = [attr for attr in dir(CTFTypeId) if not callable(getattr(CTFTypeId, attr)) and not attr.startswith("__")]
688 for attr in constants:
689 if getattr(CTFTypeId, attr) == id:
696 TRACE_PACKET_HEADER = 0
697 STREAM_PACKET_CONTEXT = 1
698 STREAM_EVENT_HEADER = 2
699 STREAM_EVENT_CONTEXT = 3
703 class Iterator(Iterator, object):
705 Allocate a CTF trace collection iterator.
707 begin_pos and end_pos are optional parameters to specify the
708 position at which the trace collection should be seeked upon
709 iterator creation, and the position at which iteration will
710 start returning "EOF".
712 By default, if begin_pos is None, a SEEK_CUR is performed at
713 creation. By default, if end_pos is None, a SEEK_END (end of
714 trace) is the EOF criterion.
716 Only one iterator can be created against a context. If more than one
717 iterator is being created for the same context, the second creation
718 will return None. The previous iterator must be destroyed before
719 creation of the new iterator for this function to succeed.
722 def __new__(cls, context, begin_pos = None, end_pos = None):
723 # __new__ is used to control the return value
724 # as the CTFReader.Iterator class should return None
725 # if bt_ctf_iter_create returns NULL
727 if begin_pos is None:
736 it = _bt_ctf_iter_create(context._c, bp, ep)
737 except AttributeError:
738 raise TypeError("in __init__, "
739 "argument 2 must be a Context instance")
743 ret_class = super(CTFReader.Iterator, cls).__new__(cls)
747 def __init__(self, context, begin_pos = None, end_pos = None):
748 Iterator.__init__(self, None, None, None,
749 _bt_ctf_get_iter(self._i))
752 _bt_ctf_iter_destroy(self._i)
754 def read_event(self):
756 Read the iterator's current event data.
757 Return current event on success, None on end of trace.
759 ret = _bt_ctf_iter_read_event(self._i)
762 ev = CTFReader.Event.__new__(CTFReader.Event)
769 This class represents an event from the trace.
770 It is obtained with read_event() from CTFReader.Iterator.
775 raise NotImplementedError("CTFReader.Event cannot be instantiated")
777 def get_top_level_scope(self, scope):
779 Return a definition of the top-level scope
780 Top-level scopes are defined in CTFReader.scope.
781 In order to get a field or a field list, the user needs to pass a
782 scope as argument, this scope can be a top-level scope or a scope
783 relative to an arbitrary field. This function provides the mapping
784 between the scope and the actual definition of top-level scopes.
785 On error return None.
787 evDef = CTFReader.Definition.__new__(CTFReader.Definition)
788 evDef._d = _bt_ctf_get_top_level_scope(self._e, scope)
794 """Return the name of the event or None on error."""
795 return _bt_ctf_event_name(self._e)
797 def get_cycles(self):
799 Return the timestamp of the event as written in
800 the packet (in cycles) or -1ULL on error.
802 return _bt_ctf_get_cycles(self._e)
804 def get_timestamp(self):
806 Return the timestamp of the event offsetted with the
807 system clock source or -1ULL on error.
809 return _bt_ctf_get_timestamp(self._e)
811 def get_field_with_scope(self, scope, field):
813 Return the definition of a specific field.
814 Return None on error.
816 evDef = CTFReader.Definition.__new__(CTFReader.Definition)
818 evDef._d = _bt_ctf_get_field(self._e, scope._d, field)
819 except AttributeError:
820 raise TypeError("in get_field, argument 2 must be a "
821 "Definition (scope) instance")
827 def get_field(self, field):
829 Return the definition of fields by a name
832 eventScope = self.get_top_level_scope(CTFReader.scope.EVENT_FIELDS)
833 streamScope = self.get_top_level_scope(CTFReader.scope.STREAM_EVENT_CONTEXT)
836 if eventScope is not None:
837 evDef = self.get_field_with_scope(eventScope, field)
838 if evDef is not None:
839 fields_by_name.append(evDef)
841 if streamScope is not None:
842 evDef = self.get_field_with_scope(streamScope, field)
843 if evDef is not None:
844 fields_by_name.append(evDef);
846 if not fields_by_name:
848 return fields_by_name
850 def get_field_list_with_scope(self, scope):
852 Return a list of Definitions associated with the scope
853 Return None on error.
856 field_lc, count = _bt_python_field_listcaller(self._e, scope._d)
857 except AttributeError:
858 raise TypeError("in get_field_list, argument 2 must be a "
859 "Definition (scope) instance")
865 for i in range(count):
866 tmp = CTFReader.Definition.__new__(CTFReader.Definition)
867 tmp._d = _bt_python_field_one_from_list(field_lc, i)
873 def get_field_list(self):
874 """Return a list of Definitions or None on error."""
875 eventScope = self.get_top_level_scope(CTFReader.scope.EVENT_FIELDS)
876 streamScope = self.get_top_level_scope(CTFReader.scope.STREAM_EVENT_CONTEXT)
879 if eventScope is not None:
880 event_field_list = self.get_field_list_with_scope(eventScope)
881 if event_field_list is not None:
882 def_list = event_field_list
884 if streamScope is not None:
885 event_field_list = self.get_field_list_with_scope(streamScope)
886 if event_field_list is not None:
887 def_list.extend(event_field_list)
893 def get_index(self, field, index):
895 If the field is an array or a sequence, return the element
896 at position index, otherwise return None
898 evDef = CTFReader.Definition.__new__(CTFReader.Definition)
900 evDef._d = _bt_ctf_get_index(self._e, field._d, index)
901 except AttributeError:
902 raise TypeError("in get_index, argument 2 must be a "
903 "Definition (field) instance")
909 def get_handle(self):
911 Get the TraceHandle associated with an event
914 ret = _bt_ctf_event_get_handle_id(self._e)
918 th = TraceHandle.__new__(TraceHandle)
922 def get_context(self):
924 Get the context associated with an event.
925 Return None on error.
928 ctx._c = _bt_ctf_event_get_context(self._e);
934 class FieldError(Exception):
935 def __init__(self, value):
939 return repr(self.value)
941 class Definition(object):
942 """Definition class. Do not instantiate."""
945 raise NotImplementedError("CTFReader.Definition cannot be instantiated")
948 return "Babeltrace Definition: name('{0}'), type({1})".format(
949 self.field_name(), self.field_type())
951 def field_name(self):
952 """Return the name of a field or None on error."""
953 return _bt_ctf_field_name(self._d)
955 def field_type(self):
956 """Return the type of a field or -1 if unknown."""
957 return _bt_ctf_field_type(_bt_ctf_get_decl_from_def(self._d))
959 def get_int_signedness(self):
961 Return the signedness of an integer:
962 0 if unsigned; 1 if signed; -1 on error.
964 return _bt_ctf_get_int_signedness(_bt_ctf_get_decl_from_def(self._d))
966 def get_int_base(self):
967 """Return the base of an int or a negative value on error."""
968 return _bt_ctf_get_int_base(_bt_ctf_get_decl_from_def(self._d))
970 def get_int_byte_order(self):
972 Return the byte order of an int or a negative
975 return _bt_ctf_get_int_byte_order(_bt_ctf_get_decl_from_def(self._d))
977 def get_int_len(self):
979 Return the size, in bits, of an int or a negative
982 return _bt_ctf_get_int_len(_bt_ctf_get_decl_from_def(self._d))
984 def get_enum_str(self):
986 Return the string matching the current enumeration.
987 Return None on error.
989 return _bt_ctf_get_enum_str(self._d)
991 def get_encoding(self):
993 Return the encoding of an int or a string.
994 Return a negative value on error.
996 return _bt_ctf_get_encoding(_bt_ctf_get_decl_from_def(self._d))
998 def get_array_len(self):
1000 Return the len of an array or a negative
1003 return _bt_ctf_get_array_len(_bt_ctf_get_decl_from_def(self._d))
1005 def get_array_element_at(self, index):
1007 Return the array's element at position index.
1008 Return None on error
1010 array = _bt_python_get_array_from_def(self._d)
1014 element = CTFReader.Definition.__new__(CTFReader.Definition)
1015 element._d = _bt_array_index(array, index)
1016 if element._d is None:
1020 def get_sequence_len(self):
1022 Return the len of a sequence or a negative
1025 seq = _bt_python_get_sequence_from_def(self._d)
1026 return _bt_sequence_len(seq)
1028 def get_sequence_element_at(self, index):
1030 Return the sequence's element at position index,
1031 otherwise return None
1033 seq = _bt_python_get_sequence_from_def(self._d)
1035 element = CTFReader.Definition.__new__(CTFReader.Definition)
1036 element._d = _bt_sequence_index(seq, index)
1037 if element._d is not None:
1041 def get_uint64(self):
1043 Return the value associated with the field.
1044 If the field does not exist or is not of the type requested,
1045 the value returned is undefined. To check if an error occured,
1046 use the CTFReader.field_error() function after accessing a field.
1048 return _bt_ctf_get_uint64(self._d)
1050 def get_int64(self):
1052 Return the value associated with the field.
1053 If the field does not exist or is not of the type requested,
1054 the value returned is undefined. To check if an error occured,
1055 use the CTFReader.field_error() function after accessing a field.
1057 return _bt_ctf_get_int64(self._d)
1059 def get_char_array(self):
1061 Return the value associated with the field.
1062 If the field does not exist or is not of the type requested,
1063 the value returned is undefined. To check if an error occured,
1064 use the CTFReader.field_error() function after accessing a field.
1066 return _bt_ctf_get_char_array(self._d)
1070 Return the value associated with the field.
1071 If the field does not exist or is not of the type requested,
1072 the value returned is undefined. To check if an error occured,
1073 use the CTFReader.field_error() function after accessing a field.
1075 return _bt_ctf_get_string(self._d)
1077 def get_float(self):
1079 Return the value associated with the field.
1080 If the field does not exist or is not of the type requested,
1081 the value returned is undefined. To check if an error occured,
1082 use the CTFReader.field_error() function after accessing a field.
1084 return _bt_ctf_get_float(self._d)
1086 def get_variant(self):
1088 Return the variant's selected field.
1089 If the field does not exist or is not of the type requested,
1090 the value returned is undefined. To check if an error occured,
1091 use the CTFReader.field_error() function after accessing a field.
1093 return _bt_ctf_get_variant(self._d)
1095 def get_struct_field_count(self):
1097 Return the number of fields contained in the structure.
1098 If the field does not exist or is not of the type requested,
1099 the value returned is undefined.
1101 return _bt_ctf_get_struct_field_count(self._d)
1103 def get_struct_field_at(self, i):
1105 Return the structure's field at position i.
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 CTFReader.field_error() function after accessing a field.
1110 return _bt_ctf_get_struct_field_index(self._d, i)
1112 def get_value(self):
1114 Return the value associated with the field according to its type.
1115 Return None on error.
1117 id = self.field_type()
1119 if id == CTFTypeId.STRING:
1120 value = self.get_str()
1121 elif id == CTFTypeId.ARRAY:
1123 for i in range(self.get_array_len()):
1124 element = self.get_array_element_at(i)
1125 value.append(element.get_value())
1126 elif id == CTFTypeId.INTEGER:
1127 if self.get_int_signedness() == 0:
1128 value = self.get_uint64()
1130 value = self.get_int64()
1131 elif id == CTFTypeId.ENUM:
1132 value = self.get_enum_str()
1133 elif id == CTFTypeId.SEQUENCE:
1134 seq_len = self.get_sequence_len()
1136 for i in range(seq_len):
1137 evDef = self.get_sequence_element_at(i)
1138 value.append(evDef.get_value())
1139 elif id == CTFTypeId.FLOAT:
1140 value = self.get_float()
1141 elif id == CTFTypeId.VARIANT:
1142 variant = CTFReader.Definition.__new__(CTFReader.Definition)
1143 variant._d = self.get_variant();
1144 value = variant.get_value()
1145 elif id == CTFTypeId.STRUCT:
1147 for i in range(self.get_struct_field_count()):
1148 member = CTFReader.Definition.__new__(CTFReader.Definition)
1149 member._d = self.get_struct_field_at(i);
1150 value[member.field_name()] = member.get_value()
1152 if CTFReader.field_error():
1153 raise CTFReader.FieldError("Error occured while accessing field {} of type {}".format(self.field_name(), CTFTypeId.get_type_name(self.field_type())))
1156 def get_scope(self):
1157 """Return the scope of a field or None on error."""
1160 class EventDecl(object):
1161 """Event declaration class. Do not instantiate."""
1164 raise NotImplementedError("CTFReader.EventDecl cannot be instantiated")
1167 return "Babeltrace EventDecl: name {0}".format(self.get_name())
1170 """Return the name of the event or None on error"""
1171 return _bt_ctf_get_decl_event_name(self._d)
1173 def get_decl_fields(self, scope):
1175 Return a list of CTFReader.FieldDecl
1176 Return None on error.
1178 ptr_list = _by_python_field_decl_listcaller(self._d, scope)
1180 if ptr_list is None:
1186 tmp = CTFReader.FieldDecl.__new__(CTFReader.FieldDecl)
1187 tmp._d = _bt_python_field_decl_one_from_list(
1191 #Last item of list is None
1194 decl_list.append(tmp)
1199 class FieldDecl(object):
1200 """Field declaration class. Do not instantiate."""
1203 raise NotImplementedError("CTFReader.FieldDecl cannot be instantiated")
1206 return "Babeltrace FieldDecl: name {0}".format(self.get_name())
1209 """Return the name of a FieldDecl or None on error"""
1210 return _bt_ctf_get_decl_field_name(self._d)
1216 Return the last error code encountered while
1217 accessing a field and reset the error flag.
1218 Return 0 if no error, a negative value otherwise.
1220 return _bt_ctf_field_get_error()
1223 def get_event_decl_list(trace_handle, context):
1225 Return a list of CTFReader.EventDecl
1226 Return None on error.
1229 handle_id = trace_handle._id
1230 except AttributeError:
1231 raise TypeError("in get_event_decl_list, "
1232 "argument 1 must be a TraceHandle instance")
1234 ptr_list, count = _bt_python_event_decl_listcaller(handle_id, context._c)
1235 except AttributeError:
1236 raise TypeError("in get_event_decl_list, "
1237 "argument 2 must be a Context instance")
1239 if ptr_list is None:
1243 for i in range(count):
1244 tmp = CTFReader.EventDecl.__new__(CTFReader.EventDecl)
1245 tmp._d = _bt_python_decl_one_from_list(ptr_list, i)
1246 decl_list.append(tmp)
1254 // =================================================================
1256 // File and list-related
1257 // python-complements.h
1258 // =================================================================
1264 Open a file for babeltrace.
1266 file_path is a string containing the path or None to use the
1267 standard output in writing mode.
1269 The mode can be 'r', 'w' or 'a' for reading (default), writing or
1270 appending. The file will be created if it doesn't exist when
1271 opened for writing or appending; it will be truncated when opened
1272 for writing. Add a 'b' to the mode for binary files. Add a '+'
1273 to the mode to allow simultaneous reading and writing.
1276 def __new__(cls, file_path, mode='r'):
1277 # __new__ is used to control the return value
1278 # as the File class should return None
1279 # if _bt_file_open returns NULL
1282 if file_path is not None and type(file_path) is not str:
1283 raise TypeError("in method __init__, argument 2 of type 'str'")
1284 if type(mode) is not str:
1285 raise TypeError("in method __init__, argument 3 of type 'str'")
1288 file_ptr = _bt_file_open(file_path, mode)
1289 if file_ptr is None:
1292 # Class instantiation
1293 file_inst = super(File, cls).__new__(cls)
1294 file_inst._file = file_ptr
1297 def __init__(self, file_path, mode='r'):
1299 self._use_stdout = False
1301 if file_path is None:
1303 file_path = "stdout"
1305 self._use_stdout = True
1307 self._file_path = file_path
1318 return "{0} babeltrace File; file_path('{1}'), mode('{2}')".format(
1319 stat, self._file_path, self._mode)
1322 """Close the file. Is also called using del."""
1323 if self._opened and not self._use_stdout:
1324 _bt_file_close(self._file)
1325 self._opened = False
1328 // =================================================================
1330 // =================================================================
1332 /* =================================================================
1334 ¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯
1336 %rename("_bt_ctf_clock_create") bt_ctf_clock_create(const char *name);
1337 %rename("_bt_ctf_clock_set_description") bt_ctf_clock_set_description(struct bt_ctf_clock *clock, const char *desc);
1338 %rename("_bt_ctf_clock_set_frequency") bt_ctf_clock_set_frequency(struct bt_ctf_clock *clock, uint64_t freq);
1339 %rename("_bt_ctf_clock_set_precision") bt_ctf_clock_set_precision(struct bt_ctf_clock *clock, uint64_t precision);
1340 %rename("_bt_ctf_clock_set_offset_s") bt_ctf_clock_set_offset_s(struct bt_ctf_clock *clock, uint64_t offset_s);
1341 %rename("_bt_ctf_clock_set_offset") bt_ctf_clock_set_offset(struct bt_ctf_clock *clock, uint64_t offset);
1342 %rename("_bt_ctf_clock_set_is_absolute") bt_ctf_clock_set_is_absolute(struct bt_ctf_clock *clock, int is_absolute);
1343 %rename("_bt_ctf_clock_set_time") bt_ctf_clock_set_time(struct bt_ctf_clock *clock, uint64_t time);
1344 %rename("_bt_ctf_clock_get") bt_ctf_clock_get(struct bt_ctf_clock *clock);
1345 %rename("_bt_ctf_clock_put") bt_ctf_clock_put(struct bt_ctf_clock *clock);
1347 struct bt_ctf_clock *bt_ctf_clock_create(const char *name);
1348 int bt_ctf_clock_set_description(struct bt_ctf_clock *clock, const char *desc);
1349 int bt_ctf_clock_set_frequency(struct bt_ctf_clock *clock, uint64_t freq);
1350 int bt_ctf_clock_set_precision(struct bt_ctf_clock *clock, uint64_t precision);
1351 int bt_ctf_clock_set_offset_s(struct bt_ctf_clock *clock, uint64_t offset_s);
1352 int bt_ctf_clock_set_offset(struct bt_ctf_clock *clock, uint64_t offset);
1353 int bt_ctf_clock_set_is_absolute(struct bt_ctf_clock *clock, int is_absolute);
1354 int bt_ctf_clock_set_time(struct bt_ctf_clock *clock, uint64_t time);
1355 void bt_ctf_clock_get(struct bt_ctf_clock *clock);
1356 void bt_ctf_clock_put(struct bt_ctf_clock *clock);
1358 /* =================================================================
1360 ¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯
1362 %rename("_bt_ctf_field_type_integer_create") bt_ctf_field_type_integer_create(unsigned int size);
1363 %rename("_bt_ctf_field_type_integer_set_signed") bt_ctf_field_type_integer_set_signed(struct bt_ctf_field_type *integer, int is_signed);
1364 %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);
1365 %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);
1366 %rename("_bt_ctf_field_type_enumeration_create") bt_ctf_field_type_enumeration_create(struct bt_ctf_field_type *integer_container_type);
1367 %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);
1368 %rename("_bt_ctf_field_type_floating_point_create") bt_ctf_field_type_floating_point_create(void);
1369 %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);
1370 %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);
1371 %rename("_bt_ctf_field_type_structure_create") bt_ctf_field_type_structure_create(void);
1372 %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);
1373 %rename("_bt_ctf_field_type_variant_create") bt_ctf_field_type_variant_create(struct bt_ctf_field_type *enum_tag, const char *tag_name);
1374 %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);
1375 %rename("_bt_ctf_field_type_array_create") bt_ctf_field_type_array_create(struct bt_ctf_field_type *element_type, unsigned int length);
1376 %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);
1377 %rename("_bt_ctf_field_type_string_create") bt_ctf_field_type_string_create(void);
1378 %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);
1379 %rename("_bt_ctf_field_type_set_alignment") bt_ctf_field_type_set_alignment(struct bt_ctf_field_type *type, unsigned int alignment);
1380 %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);
1381 %rename("_bt_ctf_field_type_get") bt_ctf_field_type_get(struct bt_ctf_field_type *type);
1382 %rename("_bt_ctf_field_type_put") bt_ctf_field_type_put(struct bt_ctf_field_type *type);
1384 struct bt_ctf_field_type *bt_ctf_field_type_integer_create(unsigned int size);
1385 int bt_ctf_field_type_integer_set_signed(struct bt_ctf_field_type *integer, int is_signed);
1386 int bt_ctf_field_type_integer_set_base(struct bt_ctf_field_type *integer, enum bt_ctf_integer_base base);
1387 int bt_ctf_field_type_integer_set_encoding(struct bt_ctf_field_type *integer, enum ctf_string_encoding encoding);
1388 struct bt_ctf_field_type *bt_ctf_field_type_enumeration_create(struct bt_ctf_field_type *integer_container_type);
1389 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);
1390 struct bt_ctf_field_type *bt_ctf_field_type_floating_point_create(void);
1391 int bt_ctf_field_type_floating_point_set_exponent_digits(struct bt_ctf_field_type *floating_point, unsigned int exponent_digits);
1392 int bt_ctf_field_type_floating_point_set_mantissa_digits(struct bt_ctf_field_type *floating_point, unsigned int mantissa_digits);
1393 struct bt_ctf_field_type *bt_ctf_field_type_structure_create(void);
1394 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);
1395 struct bt_ctf_field_type *bt_ctf_field_type_variant_create(struct bt_ctf_field_type *enum_tag, const char *tag_name);
1396 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);
1397 struct bt_ctf_field_type *bt_ctf_field_type_array_create(struct bt_ctf_field_type *element_type, unsigned int length);
1398 struct bt_ctf_field_type *bt_ctf_field_type_sequence_create(struct bt_ctf_field_type *element_type, const char *length_field_name);
1399 struct bt_ctf_field_type *bt_ctf_field_type_string_create(void);
1400 int bt_ctf_field_type_string_set_encoding(struct bt_ctf_field_type *string, enum ctf_string_encoding encoding);
1401 int bt_ctf_field_type_set_alignment(struct bt_ctf_field_type *type, unsigned int alignment);
1402 int bt_ctf_field_type_set_byte_order(struct bt_ctf_field_type *type, enum bt_ctf_byte_order byte_order);
1403 void bt_ctf_field_type_get(struct bt_ctf_field_type *type);
1404 void bt_ctf_field_type_put(struct bt_ctf_field_type *type);
1406 /* =================================================================
1408 ¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯
1410 %rename("_bt_ctf_field_create") bt_ctf_field_create(struct bt_ctf_field_type *type);
1411 %rename("_bt_ctf_field_structure_get_field") bt_ctf_field_structure_get_field(struct bt_ctf_field *structure, const char *name);
1412 %rename("_bt_ctf_field_array_get_field") bt_ctf_field_array_get_field(struct bt_ctf_field *array, uint64_t index);
1413 %rename("_bt_ctf_field_sequence_set_length") bt_ctf_field_sequence_set_length(struct bt_ctf_field *sequence, struct bt_ctf_field *length_field);
1414 %rename("_bt_ctf_field_sequence_get_field") bt_ctf_field_sequence_get_field(struct bt_ctf_field *sequence, uint64_t index);
1415 %rename("_bt_ctf_field_variant_get_field") bt_ctf_field_variant_get_field(struct bt_ctf_field *variant, struct bt_ctf_field *tag);
1416 %rename("_bt_ctf_field_enumeration_get_container") bt_ctf_field_enumeration_get_container(struct bt_ctf_field *enumeration);
1417 %rename("_bt_ctf_field_signed_integer_set_value") bt_ctf_field_signed_integer_set_value(struct bt_ctf_field *integer, int64_t value);
1418 %rename("_bt_ctf_field_unsigned_integer_set_value") bt_ctf_field_unsigned_integer_set_value(struct bt_ctf_field *integer, uint64_t value);
1419 %rename("_bt_ctf_field_floating_point_set_value") bt_ctf_field_floating_point_set_value(struct bt_ctf_field *floating_point, double value);
1420 %rename("_bt_ctf_field_string_set_value") bt_ctf_field_string_set_value(struct bt_ctf_field *string, const char *value);
1421 %rename("_bt_ctf_field_get") bt_ctf_field_get(struct bt_ctf_field *field);
1422 %rename("_bt_ctf_field_put") bt_ctf_field_put(struct bt_ctf_field *field);
1424 struct bt_ctf_field *bt_ctf_field_create(struct bt_ctf_field_type *type);
1425 struct bt_ctf_field *bt_ctf_field_structure_get_field(struct bt_ctf_field *structure, const char *name);
1426 struct bt_ctf_field *bt_ctf_field_array_get_field(struct bt_ctf_field *array, uint64_t index);
1427 int bt_ctf_field_sequence_set_length(struct bt_ctf_field *sequence, struct bt_ctf_field *length_field);
1428 struct bt_ctf_field *bt_ctf_field_sequence_get_field(struct bt_ctf_field *sequence, uint64_t index);
1429 struct bt_ctf_field *bt_ctf_field_variant_get_field(struct bt_ctf_field *variant, struct bt_ctf_field *tag);
1430 struct bt_ctf_field *bt_ctf_field_enumeration_get_container(struct bt_ctf_field *enumeration);
1431 int bt_ctf_field_signed_integer_set_value(struct bt_ctf_field *integer, int64_t value);
1432 int bt_ctf_field_unsigned_integer_set_value(struct bt_ctf_field *integer, uint64_t value);
1433 int bt_ctf_field_floating_point_set_value(struct bt_ctf_field *floating_point, double value);
1434 int bt_ctf_field_string_set_value(struct bt_ctf_field *string, const char *value);
1435 void bt_ctf_field_get(struct bt_ctf_field *field);
1436 void bt_ctf_field_put(struct bt_ctf_field *field);
1438 /* =================================================================
1440 ¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯
1442 %rename("_bt_ctf_event_class_create") bt_ctf_event_class_create(const char *name);
1443 %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);
1444 %rename("_bt_ctf_event_class_get") bt_ctf_event_class_get(struct bt_ctf_event_class *event_class);
1445 %rename("_bt_ctf_event_class_put") bt_ctf_event_class_put(struct bt_ctf_event_class *event_class);
1446 %rename("_bt_ctf_event_create") bt_ctf_event_create(struct bt_ctf_event_class *event_class);
1447 %rename("_bt_ctf_event_set_payload") bt_ctf_event_set_payload(struct bt_ctf_event *event, const char *name, struct bt_ctf_field *value);
1448 %rename("_bt_ctf_event_get_payload") bt_ctf_event_get_payload(struct bt_ctf_event *event, const char *name);
1449 %rename("_bt_ctf_event_get") bt_ctf_event_get(struct bt_ctf_event *event);
1450 %rename("_bt_ctf_event_put") bt_ctf_event_put(struct bt_ctf_event *event);
1452 struct bt_ctf_event_class *bt_ctf_event_class_create(const char *name);
1453 int bt_ctf_event_class_add_field(struct bt_ctf_event_class *event_class, struct bt_ctf_field_type *type, const char *name);
1454 void bt_ctf_event_class_get(struct bt_ctf_event_class *event_class);
1455 void bt_ctf_event_class_put(struct bt_ctf_event_class *event_class);
1456 struct bt_ctf_event *bt_ctf_event_create(struct bt_ctf_event_class *event_class);
1457 int bt_ctf_event_set_payload(struct bt_ctf_event *event, const char *name, struct bt_ctf_field *value);
1458 struct bt_ctf_field *bt_ctf_event_get_payload(struct bt_ctf_event *event, const char *name);
1459 void bt_ctf_event_get(struct bt_ctf_event *event);
1460 void bt_ctf_event_put(struct bt_ctf_event *event);
1462 /* =================================================================
1464 ¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯
1466 %rename("_bt_ctf_stream_class_create") bt_ctf_stream_class_create(const char *name);
1467 %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);
1468 %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);
1469 %rename("_bt_ctf_stream_class_get") bt_ctf_stream_class_get(struct bt_ctf_stream_class *stream_class);
1470 %rename("_bt_ctf_stream_class_put") bt_ctf_stream_class_put(struct bt_ctf_stream_class *stream_class);
1471 %rename("_bt_ctf_stream_append_discarded_events") bt_ctf_stream_append_discarded_events(struct bt_ctf_stream *stream, uint64_t event_count);
1472 %rename("_bt_ctf_stream_append_event") bt_ctf_stream_append_event(struct bt_ctf_stream *stream, struct bt_ctf_event *event);
1473 %rename("_bt_ctf_stream_flush") bt_ctf_stream_flush(struct bt_ctf_stream *stream);
1474 %rename("_bt_ctf_stream_get") bt_ctf_stream_get(struct bt_ctf_stream *stream);
1475 %rename("_bt_ctf_stream_put") bt_ctf_stream_put(struct bt_ctf_stream *stream);
1477 struct bt_ctf_stream_class *bt_ctf_stream_class_create(const char *name);
1478 int bt_ctf_stream_class_set_clock(struct bt_ctf_stream_class *stream_class, struct bt_ctf_clock *clock);
1479 int bt_ctf_stream_class_add_event_class(struct bt_ctf_stream_class *stream_class, struct bt_ctf_event_class *event_class);
1480 void bt_ctf_stream_class_get(struct bt_ctf_stream_class *stream_class);
1481 void bt_ctf_stream_class_put(struct bt_ctf_stream_class *stream_class);
1482 void bt_ctf_stream_append_discarded_events(struct bt_ctf_stream *stream, uint64_t event_count);
1483 int bt_ctf_stream_append_event(struct bt_ctf_stream *stream, struct bt_ctf_event *event);
1484 int bt_ctf_stream_flush(struct bt_ctf_stream *stream);
1485 void bt_ctf_stream_get(struct bt_ctf_stream *stream);
1486 void bt_ctf_stream_put(struct bt_ctf_stream *stream);
1488 /* =================================================================
1490 ¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯
1492 %rename("_bt_ctf_writer_create") bt_ctf_writer_create(const char *path);
1493 %rename("_bt_ctf_writer_create_stream") bt_ctf_writer_create_stream(struct bt_ctf_writer *writer, struct bt_ctf_stream_class *stream_class);
1494 %rename("_bt_ctf_writer_add_environment_field") bt_ctf_writer_add_environment_field(struct bt_ctf_writer *writer, const char *name, const char *value);
1495 %rename("_bt_ctf_writer_add_clock") bt_ctf_writer_add_clock(struct bt_ctf_writer *writer, struct bt_ctf_clock *clock);
1496 %newobject bt_ctf_writer_get_metadata_string;
1497 %rename("_bt_ctf_writer_get_metadata_string") bt_ctf_writer_get_metadata_string(struct bt_ctf_writer *writer);
1498 %rename("_bt_ctf_writer_flush_metadata") bt_ctf_writer_flush_metadata(struct bt_ctf_writer *writer);
1499 %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);
1500 %rename("_bt_ctf_writer_get") bt_ctf_writer_get(struct bt_ctf_writer *writer);
1501 %rename("_bt_ctf_writer_put") bt_ctf_writer_put(struct bt_ctf_writer *writer);
1503 struct bt_ctf_writer *bt_ctf_writer_create(const char *path);
1504 struct bt_ctf_stream *bt_ctf_writer_create_stream(struct bt_ctf_writer *writer, struct bt_ctf_stream_class *stream_class);
1505 int bt_ctf_writer_add_environment_field(struct bt_ctf_writer *writer, const char *name, const char *value);
1506 int bt_ctf_writer_add_clock(struct bt_ctf_writer *writer, struct bt_ctf_clock *clock);
1507 char *bt_ctf_writer_get_metadata_string(struct bt_ctf_writer *writer);
1508 void bt_ctf_writer_flush_metadata(struct bt_ctf_writer *writer);
1509 int bt_ctf_writer_set_byte_order(struct bt_ctf_writer *writer, enum bt_ctf_byte_order byte_order);
1510 void bt_ctf_writer_get(struct bt_ctf_writer *writer);
1511 void bt_ctf_writer_put(struct bt_ctf_writer *writer);
1517 BYTE_ORDER_NATIVE = 0
1518 BYTE_ORDER_LITTLE_ENDIAN = 1
1519 BYTE_ORDER_BIG_ENDIAN = 2
1520 BYTE_ORDER_NETWORK = 3
1523 def __init__(self, name):
1524 self._c = _bt_ctf_clock_create(name)
1526 raise ValueError("Invalid clock name.")
1529 _bt_ctf_clock_put(self._c)
1532 Set the clock's description. The description appears in the clock's TSDL
1535 def set_description(self, desc):
1536 ret = _bt_ctf_clock_set_description(self._c, desc)
1538 raise ValueError("Invalid clock description.")
1541 Set the clock's frequency (Hz).
1543 def set_frequency(self, freq):
1544 ret = _bt_ctf_clock_set_frequency(self._c, freq)
1546 raise ValueError("Invalid frequency value.")
1549 Set the clock's precision (in clock ticks).
1551 def set_precision(self, precision):
1552 ret = _bt_ctf_clock_set_precision(self._c, precision)
1555 Set the clock's offset in seconds from POSIX.1 Epoch.
1557 def set_offset_seconds(self, offset_s):
1558 ret = _bt_ctf_clock_set_offset_s(self._c, offset_s)
1560 raise ValueError("Invalid offset value.")
1563 Set the clock's offset in ticks from POSIX.1 Epoch + offset in seconds.
1565 def set_offset_seconds(self, offset):
1566 ret = _bt_ctf_clock_set_offset(self._c, offset)
1568 raise ValueError("Invalid offset value.")
1571 Set a clock's absolute attribute. A clock is absolute if the clock
1572 is a global reference across the trace's other clocks.
1574 def set_is_absolute(self, is_absolute):
1575 ret = _bt_ctf_clock_set_is_absolute(self._c, is_absolute)
1577 raise ValueError("Could not set the clock's absolute attribute.")
1580 Set the current time in nanoseconds since the clock's origin (offset and
1581 offset_s attributes). The clock's value will be sampled as events are
1582 appended to a stream.
1584 def set_time(self, time):
1585 ret = _bt_ctf_clock_set_time(self._c, time)
1587 raise ValueError("Invalid time value.")
1591 FieldType should not be instantiated directly. Please instantiate
1592 one of the concrete FieldType classes.
1595 # These values are based on the bt_ctf_integer_base enum
1596 # declared in event-types.h.
1597 INTEGER_BASE_UNKNOWN = -1
1598 INTEGER_BASE_BINARY = 2
1599 INTEGER_BASE_OCTAL = 8
1600 INTEGER_BASE_DECIMAL = 10
1601 INTEGER_BASE_HEXADECIMAL = 16
1604 if self._ft is None:
1605 raise ValueError("FieldType creation failed.")
1608 _bt_ctf_field_type_put(self._ft)
1611 Set the field type's alignment. Defaults to 1 (bit-aligned). However,
1612 some types, such as structures and string, may impose other alignment
1615 def set_alignment(self, alignment):
1616 ret = _bt_ctf_field_type_set_alignment(self._ft, alignment)
1618 raise ValueError("Invalid alignment value.")
1621 Set the field type's byte order. Use constants defined in the ByteOrder
1624 def set_byte_order(self, byte_order):
1625 ret = _bt_ctf_field_type_set_byte_order(self._ft, byte_order)
1627 raise ValueError("Could not set byte order value.")
1629 class FieldTypeInteger(FieldType):
1631 Create a new integer field type of the given size.
1633 def __init__(self, size):
1634 self._ft = _bt_ctf_field_type_integer_create(size)
1638 Set an integer type's signedness attribute.
1640 def set_signed(self, signed):
1641 ret = _bt_ctf_field_type_integer_set_signed(self._ft, signed)
1643 raise ValueError("Could not set signed attribute.")
1646 Set the integer type's base used to pretty-print the resulting trace.
1647 The base must be a constant of the IntegerBase class.
1649 def set_base(self, base):
1650 ret = _bt_ctf_field_type_integer_set_base(self._ft, base)
1652 raise ValueError("Could not set base value.")
1655 An integer encoding may be set to signal that the integer must be printed
1656 as a text character. Must be a constant from the CTFStringEncoding class.
1658 def set_encoding(self, encoding):
1659 ret = _bt_ctf_field_type_integer_set_encoding(self._ft, encoding)
1661 raise ValueError("Could not set integer encoding.")
1663 class FieldTypeEnumeration(FieldType):
1665 Create a new enumeration field type with the given underlying type.
1667 def __init__(self, integer_type):
1668 if integer_type is None or not isinstance(integer_type, CTFWriter.FieldTypeInteger):
1669 raise TypeError("Invalid integer container.")
1671 self._ft = _bt_ctf_field_type_enumeration_create(integer_type._ft)
1675 Add a mapping to the enumeration. The range's values are inclusive.
1677 def add_mapping(self, name, range_start, range_end):
1678 ret = _bt_ctf_field_type_enumeration_add_mapping(self._ft, name, range_start, range_end)
1680 raise ValueError("Could not add mapping to enumeration type.")
1682 class FieldTypeFloatingPoint(FieldType):
1689 Create a new floating point field type.
1692 self._ft = _bt_ctf_field_type_floating_point_create()
1696 Set the number of exponent digits to use to store the floatingpoint field.
1697 The only values currently supported are FLT_EXP_DIG and DBL_EXP_DIG which
1698 are defined as constants of this class.
1700 def set_exponent_digits(self, exponent_digits):
1701 ret = _bt_ctf_field_type_floating_point_set_exponent_digits(self._ft, exponent_digits)
1703 raise ValueError("Could not set exponent digit count.")
1706 Set the numberof mantissa digits to use to store the floatingpoint field.
1707 The only values currently supported are FLT_MANT_DIG and DBL_MANT_DIG which
1708 are defined as constants of this class.
1710 def set_mantissa_digits(self, mantissa_digits):
1711 ret = _bt_ctf_field_type_floating_point_set_mantissa_digits(self._ft, mantissa_digits)
1713 raise ValueError("Could not set mantissa digit count.")
1715 class FieldTypeStructure(FieldType):
1717 Create a new structure field type.
1720 self._ft = _bt_ctf_field_type_structure_create()
1724 Add a field of type "field_type" to the structure.
1726 def add_field(self, field_type, field_name):
1727 ret = _bt_ctf_field_type_structure_add_field(self._ft, field_type._ft, field_name)
1729 raise ValueError("Could not add field to structure.")
1731 class FieldTypeVariant(FieldType):
1733 Create a new variant field type.
1735 def __init__(self, enum_tag, tag_name):
1736 if enum_tag is None or not isinstance(enum_tag, CTFWriter.FieldTypeEnumeration):
1737 raise TypeError("Invalid tag type; must be of type FieldTypeEnumeration.")
1739 self._ft = _bt_ctf_field_type_variant_create(enum_tag._ft, tag_name)
1743 Add a field of type "field_type" to the variant.
1745 def add_field(self, field_type, field_name):
1746 ret = _bt_ctf_field_type_variant_add_field(self._ft, field_type._ft, field_name)
1748 raise ValueError("Could not add field to variant.")
1750 class FieldTypeArray(FieldType):
1752 Create a new array field type.
1754 def __init__(self, element_type, length):
1755 self._ft = _bt_ctf_field_type_array_create(element_type._ft, length)
1758 class FieldTypeSequence(FieldType):
1760 Create a new sequence field type.
1762 def __init__(self, element_type, length_field_name):
1763 self._ft = _bt_ctf_field_type_sequence_create(element_type._ft, length_field_name)
1766 class FieldTypeString(FieldType):
1768 Create a new string field type.
1771 self._ft = _bt_ctf_field_type_string_create()
1775 Set a string type's encoding. Must be a constant from the CTFStringEncoding class.
1777 def set_encoding(self, encoding):
1778 ret = _bt_ctf_field_type_string_set_encoding(self._ft, encoding)
1780 raise ValueError("Could not set string encoding.")
1783 Create an instance of a field.
1786 def create_field(self, field_type):
1787 if field_type is None or not isinstance(field_type, CTFWriter.FieldType):
1788 raise TypeError("Invalid field_type. Type must be a FieldType-derived class.")
1790 if isinstance(field_type, CTFWriter.FieldTypeInteger):
1791 return CTFWriter.FieldInteger(field_type)
1792 elif isinstance(field_type, CTFWriter.FieldTypeEnumeration):
1793 return CTFWriter.FieldEnumeration(field_type)
1794 elif isinstance(field_type, CTFWriter.FieldTypeFloatingPoint):
1795 return CTFWriter.FieldFloatingPoint(field_type)
1796 elif isinstance(field_type, CTFWriter.FieldTypeStructure):
1797 return CTFWriter.FieldStructure(field_type)
1798 elif isinstance(field_type, CTFWriter.FieldTypeVariant):
1799 return CTFWriter.FieldVariant(field_type)
1800 elif isinstance(field_type, CTFWriter.FieldTypeArray):
1801 return CTFWriter.FieldArray(field_type)
1802 elif isinstance(field_type, CTFWriter.FieldTypeSequence):
1803 return CTFWriter.FieldSequence(field_type)
1804 elif isinstance(field_type, CTFWriter.FieldTypeString):
1805 return CTFWriter.FieldString(field_type)
1809 Base class, do not instantiate.
1811 def __init__(self, field_type):
1812 if not isinstance(field_type, CTFWriter.FieldType):
1813 raise TypeError("Invalid field_type argument.")
1815 self._f = _bt_ctf_field_create(field_type._ft)
1817 raise ValueError("Field creation failed.")
1820 _bt_ctf_field_put(self._f)
1823 def _create_field_from_native_instance(native_field_instance):
1825 CTFTypeId.INTEGER : CTFWriter.FieldInteger,
1826 CTFTypeId.FLOAT : CTFWriter.FieldFloatingPoint,
1827 CTFTypeId.ENUM : CTFWriter.FieldEnumeration,
1828 CTFTypeId.STRING : CTFWriter.FieldString,
1829 CTFTypeId.STRUCT : CTFWriter.FieldStructure,
1830 CTFTypeId.VARIANT : CTFWriter.FieldVariant,
1831 CTFTypeId.ARRAY : CTFWriter.FieldArray,
1832 CTFTypeId.SEQUENCE : CTFWriter.FieldSequence
1835 field_type = _bt_python_get_field_type(native_field_instance)
1836 if field_type == CTFTypeId.UNKNOWN:
1837 raise TypeError("Invalid field instance")
1839 field = CTFWriter.Field.__new__(CTFWriter.Field)
1840 field._f = native_field_instance
1841 field.__class__ = type_dict[field_type]
1844 class FieldInteger(Field):
1846 Set an integer field's value.
1848 def set_value(self, value):
1849 signedness = _bt_python_field_integer_get_signedness(self._f)
1851 raise TypeError("Invalid integer instance.")
1854 ret = _bt_ctf_field_unsigned_integer_set_value(self._f, value)
1856 ret = _bt_ctf_field_signed_integer_set_value(self._f, value)
1859 raise ValueError("Could not set integer field value.")
1861 class FieldEnumeration(Field):
1863 Return the enumeration's underlying container field (an integer field).
1865 def get_container(self):
1866 container = CTFWriter.FieldInteger.__new__(CTFWriter.FieldInteger)
1867 container._f = _bt_ctf_field_enumeration_get_container(self._f)
1868 if container._f is None:
1869 raise TypeError("Invalid enumeration field type.")
1872 class FieldFloatingPoint(Field):
1874 Set a floating point field's value.
1876 def set_value(self, value):
1877 ret = _bt_ctf_field_floating_point_set_value(self._f, value)
1879 raise ValueError("Could not set floating point field value.")
1881 class FieldStructure(Field):
1883 Get the structure's field corresponding to the provided field name.
1885 def get_field(self, field_name):
1886 native_instance = _bt_ctf_field_structure_get_field(self._f, field_name)
1887 if native_instance is None:
1888 raise ValueError("Invalid field_name provided.")
1889 return CTFWriter.Field._create_field_from_native_instance(native_instance)
1891 class FieldVariant(Field):
1893 Return the variant's selected field. The "tag" field is the selector enum field.
1895 def get_field(self, tag):
1896 native_instance = _bt_ctf_field_variant_get_field(self._f, tag._f)
1897 if native_instance is None:
1898 raise ValueError("Invalid tag provided.")
1899 return CTFWriter.Field._create_field_from_native_instance(native_instance)
1901 class FieldArray(Field):
1903 Return the array's field at position "index".
1905 def get_field(self, index):
1906 native_instance = _bt_ctf_field_array_get_field(self._f, index)
1907 if native_instance is None:
1908 raise IndexError("Invalid index provided.")
1909 return CTFWriter.Field._create_field_from_native_instance(native_instance)
1911 class FieldSequence(Field):
1913 Set the sequence's length field (IntegerField).
1915 def set_length(self, length):
1916 if not isinstance(length, CTFWriter.FieldInteger):
1917 raise TypeError("Invalid length field.")
1918 ret = _bt_ctf_field_sequence_set_length(self._f, length._f)
1920 raise ValueError("Could not set sequence length.")
1923 Return the sequence's field at position "index".
1925 def get_field(self, index):
1926 native_instance = _bt_ctf_field_sequence_get_field(self._f, index)
1927 if native_instance is None:
1928 raise ValueError("Could not get sequence element at index.")
1929 return CTFWriter.Field._create_field_from_native_instance(native_instance)
1931 class FieldString(Field):
1933 Set a string field's value.
1935 def set_value(self, value):
1936 ret = _bt_ctf_field_string_set_value(self._f, value)
1938 raise ValueError("Could not set string field value.")
1942 Create a new event class of the given name.
1944 def __init__(self, name):
1945 self._ec = _bt_ctf_event_class_create(name)
1946 if self._ec is None:
1947 raise ValueError("Event class creation failed.")
1950 _bt_ctf_event_class_put(self._ec)
1953 Add a field of type "field_type" to the event class.
1955 def add_field(self, field_type, field_name):
1956 ret = _bt_ctf_event_class_add_field(self._ec, field_type._ft, field_name)
1958 raise ValueError("Could not add field to event class.")
1962 Create a new event of the given event class.
1964 def __init__(self, event_class):
1965 if not isinstance(event_class, CTFWriter.EventClass):
1966 raise TypeError("Invalid event_class argument.")
1968 self._e = _bt_ctf_event_create(event_class._ec)
1970 raise ValueError("Event creation failed.")
1973 _bt_ctf_event_put(self._e)
1976 Set a manually created field as an event's payload.
1978 def set_payload(self, field_name, value):
1979 if not isinstance(value, CTFWriter.Field):
1980 raise TypeError("Invalid value type.")
1981 ret = _bt_ctf_event_set_payload(self._e, field_name, value._f)
1983 raise ValueError("Could not set event field payload.")
1986 Set a manually created field as an event's payload.
1988 def get_payload(self, field_name):
1989 native_instance = _bt_ctf_event_get_payload(self._e, field_name)
1990 if native_instance is None:
1991 raise ValueError("Could not get event payload.")
1992 return CTFWriter.Field._create_field_from_native_instance(native_instance)
1996 Create a new stream class of the given name.
1998 def __init__(self, name):
1999 self._sc = _bt_ctf_stream_class_create(name)
2000 if self._sc is None:
2001 raise ValueError("Stream class creation failed.")
2004 _bt_ctf_stream_class_put(self._sc)
2007 Assign a clock to a stream class.
2009 def set_clock(self, clock):
2010 if not isinstance(clock, CTFWriter.Clock):
2011 raise TypeError("Invalid clock type.")
2013 ret = _bt_ctf_stream_class_set_clock(self._sc, clock._c)
2015 raise ValueError("Could not set stream class clock.")
2018 Add an event class to a stream class. New events can be added even after a
2019 stream has beem instanciated and events have been appended. However, a stream
2020 will not accept events of a class that has not been registered beforehand.
2022 def add_event_class(self, event_class):
2023 if not isinstance(event_class, CTFWriter.EventClass):
2024 raise TypeError("Invalid event_class type.")
2026 ret = _bt_ctf_stream_class_add_event_class(self._sc, event_class._ec)
2028 raise ValueError("Could not add event class.")
2032 Create a stream of the given class.
2034 def __init__(self, stream_class):
2035 if not isinstance(stream_class, CTFWriter.StreamClass):
2036 raise TypeError("Invalid stream_class type.")
2038 self._s = _bt_ctf_stream_create(stream_class._sc)
2040 raise ValueError("Stream creation failed.")
2043 _bt_ctf_stream_put(self._s)
2046 Increase the current packet's discarded event count.
2048 def append_discarded_events(self, event_count):
2049 ret = _bt_ctf_stream_append_discarded_events(self._s, event_count)
2051 raise ValueError("Could not append discarded events.")
2054 Append "event" to the stream's current packet. The stream's associated clock
2055 will be sampled during this call. The event shall not be modified after
2056 being appended to a stream.
2058 def append_event(self, event):
2059 ret = _bt_ctf_stream_append_event(self._s, event._e)
2061 raise ValueError("Could not append event to stream.")
2064 The stream's current packet's events will be flushed to disk. Events
2065 subsequently appended to the stream will be added to a new packet.
2068 ret = _bt_ctf_stream_flush(self._s)
2070 raise ValueError("Could not flush stream.")
2074 Create a new writer that will produce a trace in the given path.
2076 def __init__(self, path):
2077 self._w = _bt_ctf_writer_create(path)
2079 raise ValueError("Writer creation failed.")
2082 _bt_ctf_writer_put(self._w)
2085 Create a new stream instance and register it to the writer.
2087 def create_stream(self, stream_class):
2088 if not isinstance(stream_class, CTFWriter.StreamClass):
2089 raise TypeError("Invalid stream_class type.")
2091 stream = CTFWriter.Stream.__new__(CTFWriter.Stream)
2092 stream._s = _bt_ctf_writer_create_stream(self._w, stream_class._sc)
2096 Add an environment field to the trace.
2098 def add_environment_field(self, name, value):
2099 ret = _bt_ctf_writer_add_environment_field(self._w, name, value)
2101 raise ValueError("Could not add environment field to trace.")
2104 Add a clock to the trace. Clocks assigned to stream classes must be
2105 registered to the writer.
2107 def add_clock(self, clock):
2108 ret = _bt_ctf_writer_add_clock(self._w, clock._c)
2110 raise ValueError("Could not add clock to Writer.")
2113 Get the trace's TSDL meta-data.
2115 def get_metadata(self):
2116 return _bt_ctf_writer_get_metadata_string(self._w)
2119 Flush the trace's metadata to the metadata file.
2121 def flush_metadata(self):
2122 _bt_ctf_writer_flush_metadata(self._w)
2125 Set the trace's byte order. Must be a constant from the ByteOrder
2126 class. Defaults to BYTE_ORDER_NATIVE, the host machine's endianness.
2128 def set_byte_order(self, byte_order):
2129 ret = _bt_ctf_writer_set_byte_order(self._w, byte_order)
2131 raise ValueError("Could not set trace's byte order.")