Python bindings clean-up: missing file headers style fixes
[babeltrace.git] / bindings / python / babeltrace.i.in
1 /*
2 * babeltrace.i.in
3 *
4 * Babeltrace Python Module interface file
5 *
6 * Copyright 2012 EfficiOS Inc.
7 *
8 * Author: Danny Serres <danny.serres@efficios.com>
9 * Author: Jérémie Galarneau <jeremie.galarneau@efficios.com>
10 *
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:
17 *
18 * The above copyright notice and this permission notice shall be included in
19 * all copies or substantial portions of the Software.
20 */
21
22
23 %define DOCSTRING
24 "BABELTRACE_VERSION_STR
25
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.
29
30 To use this module, the first step is to create a TraceCollection and add a
31 trace to it."
32 %enddef
33
34 %module(docstring=DOCSTRING) babeltrace
35
36 %include "stdint.i"
37 %include "typemaps.i"
38 %{
39 #define SWIG_FILE_WITH_INIT
40 #include <babeltrace/babeltrace.h>
41 #include <babeltrace/babeltrace-internal.h>
42 #include <babeltrace/trace-handle.h>
43 #include <babeltrace/trace-handle-internal.h>
44 #include <babeltrace/context.h>
45 #include <babeltrace/context-internal.h>
46 #include <babeltrace/iterator.h>
47 #include <babeltrace/iterator-internal.h>
48 #include <babeltrace/format.h>
49 #include <babeltrace/list.h>
50 #include <babeltrace/types.h>
51 #include <babeltrace/ctf/iterator.h>
52 #include "python-complements.h"
53 #include <babeltrace/ctf-writer/clock.h>
54 #include <babeltrace/ctf-writer/event-fields.h>
55 #include <babeltrace/ctf-writer/event-types.h>
56 #include <babeltrace/ctf-writer/event.h>
57 #include <babeltrace/ctf-writer/stream.h>
58 #include <babeltrace/ctf-writer/writer.h>
59 %}
60
61 typedef int bt_intern_str;
62 typedef int64_t ssize_t;
63
64 /* python-complements.h */
65 struct bt_definition **_bt_python_field_listcaller(
66 const struct bt_ctf_event *ctf_event,
67 const struct bt_definition *scope,
68 unsigned int *OUTPUT);
69 struct bt_definition *_bt_python_field_one_from_list(
70 struct bt_definition **list, int index);
71 struct bt_ctf_event_decl **_bt_python_event_decl_listcaller(
72 int handle_id,
73 struct bt_context *ctx,
74 unsigned int *OUTPUT);
75 struct bt_ctf_event_decl *_bt_python_decl_one_from_list(
76 struct bt_ctf_event_decl **list, int index);
77 struct bt_ctf_field_decl **_by_python_field_decl_listcaller(
78 struct bt_ctf_event_decl *event_decl,
79 enum bt_ctf_scope scope,
80 unsigned int *OUTPUT);
81 struct bt_ctf_field_decl *_bt_python_field_decl_one_from_list(
82 struct bt_ctf_field_decl **list, int index);
83 struct definition_array *_bt_python_get_array_from_def(
84 struct bt_definition *field);
85 struct definition_sequence *_bt_python_get_sequence_from_def(
86 struct bt_definition *field);
87 struct bt_declaration *_bt_python_get_array_element_declaration(
88 struct bt_declaration *field);
89 struct bt_declaration *_bt_python_get_sequence_element_declaration(
90 struct bt_declaration *field);
91 const char *_bt_python_get_array_string(struct bt_definition *field);
92 const char *_bt_python_get_sequence_string(struct bt_definition *field);
93 int _bt_python_field_integer_get_signedness(const struct bt_ctf_field *field);
94 enum ctf_type_id _bt_python_get_field_type(const struct bt_ctf_field *field);
95 const char *_bt_python_ctf_field_type_enumeration_get_mapping(
96 struct bt_ctf_field_type *enumeration, size_t index,
97 int64_t *OUTPUT, int64_t *OUTPUT);
98 const char *_bt_python_ctf_field_type_enumeration_get_mapping_unsigned(
99 struct bt_ctf_field_type *enumeration, size_t index,
100 uint64_t *OUTPUT, uint64_t *OUTPUT);
101 const char *_bt_python_ctf_field_type_structure_get_field_name(
102 struct bt_ctf_field_type *structure, size_t index);
103 struct bt_ctf_field_type *_bt_python_ctf_field_type_structure_get_field_type(
104 struct bt_ctf_field_type *structure, size_t index);
105 const char *_bt_python_ctf_field_type_variant_get_field_name(
106 struct bt_ctf_field_type *variant, size_t index);
107 struct bt_ctf_field_type *_bt_python_ctf_field_type_variant_get_field_type(
108 struct bt_ctf_field_type *variant, size_t index);
109 const char *_bt_python_ctf_event_class_get_field_name(
110 struct bt_ctf_event_class *event_class, size_t index);
111 struct bt_ctf_field_type *_bt_python_ctf_event_class_get_field_type(
112 struct bt_ctf_event_class *event_class, size_t index);
113 int _bt_python_ctf_clock_get_uuid_index(struct bt_ctf_clock *clock,
114 size_t index, unsigned char *OUTPUT);
115 int _bt_python_ctf_clock_set_uuid_index(struct bt_ctf_clock *clock,
116 size_t index, unsigned char value);
117
118 /* context.h, context-internal.h */
119 %rename("_bt_context_create") bt_context_create(void);
120 %rename("_bt_context_add_trace") bt_context_add_trace(
121 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 %rename("_bt_context_remove_trace") bt_context_remove_trace(
125 struct bt_context *ctx, int trace_id);
126 %rename("_bt_context_get") bt_context_get(struct bt_context *ctx);
127 %rename("_bt_context_put") bt_context_put(struct bt_context *ctx);
128 %rename("_bt_ctf_event_get_context") bt_ctf_event_get_context(
129 const struct bt_ctf_event *event);
130
131 struct bt_context *bt_context_create(void);
132 int bt_context_add_trace(struct bt_context *ctx, const char *path, const char *format,
133 void (*packet_seek)(struct bt_stream_pos *pos, size_t index, int whence),
134 struct bt_mmap_stream_list *stream_list, FILE *metadata);
135 void bt_context_remove_trace(struct bt_context *ctx, int trace_id);
136 void bt_context_get(struct bt_context *ctx);
137 void bt_context_put(struct bt_context *ctx);
138 struct bt_context *bt_ctf_event_get_context(const struct bt_ctf_event *event);
139
140 /* class TraceCollection to prevent direct access to struct bt_context */
141 %pythoncode%{
142
143 class TraceCollection:
144
145 """
146 The TraceCollection is the object that contains all currently opened traces.
147 """
148
149 def __init__(self):
150 self._tc = _bt_context_create()
151
152 def __del__(self):
153 _bt_context_put(self._tc)
154
155 def add_trace(self, path, format_str):
156 """
157 Add a trace by path to the TraceCollection.
158
159 Open a trace.
160
161 path is the path to the trace, it is not recursive.
162 If "path" is None, stream_list is used instead as a list
163 of mmap streams to open for the trace.
164
165 format is a string containing the format name in which the trace was
166 produced.
167
168 Return: the corresponding TraceHandle on success or None on error.
169 """
170 ret = _bt_context_add_trace(
171 self._tc,
172 path,
173 format_str,
174 None,
175 None,
176 None)
177 if ret < 0:
178 return None
179
180 th = TraceHandle.__new__(TraceHandle)
181 th._id = ret
182 th._trace_collection = self
183 return th
184
185 def add_traces_recursive(self, path, format_str):
186 """
187 Open a trace recursively.
188
189 Find each trace present in the subdirectory starting from the given
190 path, and add them to the TraceCollection.
191
192 Return a dict of TraceHandle instances (the full path is the key).
193 Return None on error.
194 """
195
196 import os
197
198 trace_handles = {}
199
200 noTrace = True
201 error = False
202
203 for fullpath, dirs, files in os.walk(path):
204 if "metadata" in files:
205 trace_handle = self.add_trace(fullpath, format_str)
206 if trace_handle is None:
207 error = True
208 continue
209
210 trace_handles[fullpath] = trace_handle
211 noTrace = False
212
213 if noTrace and error:
214 return None
215 return trace_handles
216
217 def remove_trace(self, trace_handle):
218 """
219 Remove a trace from the TraceCollection.
220 Effectively closing the trace.
221 """
222 try:
223 _bt_context_remove_trace(self._tc, trace_handle._id)
224 except AttributeError:
225 raise TypeError("in remove_trace, "
226 "argument 2 must be a TraceHandle instance")
227
228 @property
229 def events(self):
230 """
231 Generator function to iterate over the events of open in the current
232 TraceCollection.
233
234 Due to limitations of the native Babeltrace API, only one event
235 may be "alive" at a time (i.e. a user should never store a copy
236 of the events returned by this function for ulterior use). Users
237 shall make sure to copy the information they need from an event
238 before accessing the next one.
239
240 Furthermore, event objects become invalid when the generator goes
241 out of scope as the underlying iterator will be reclaimed. Using an
242 event after the the generator has gone out of scope may result in a
243 crash or data corruption.
244 """
245 begin_pos_ptr = _bt_iter_pos()
246 end_pos_ptr = _bt_iter_pos()
247 begin_pos_ptr.type = SEEK_BEGIN
248 end_pos_ptr.type = SEEK_LAST
249
250 for event in self._events(begin_pos_ptr, end_pos_ptr):
251 yield event
252
253 def events_timestamps(self, timestamp_begin, timestamp_end):
254 """
255 Generator function to iterate over the events of open in the current
256 TraceCollection from timestamp_begin to timestamp_end.
257 """
258 begin_pos_ptr = _bt_iter_pos()
259 end_pos_ptr = _bt_iter_pos()
260 begin_pos_ptr.type = end_pos_ptr.type = SEEK_TIME
261 begin_pos_ptr.u.seek_time = timestamp_begin
262 end_pos_ptr.u.seek_time = timestamp_end
263
264 for event in self._events(begin_pos_ptr, end_pos_ptr):
265 yield event
266
267 @property
268 def timestamp_begin(self):
269 pos_ptr = _bt_iter_pos()
270 pos_ptr.type = SEEK_BEGIN
271 return self._timestamp_at_pos(pos_ptr)
272
273 @property
274 def timestamp_end(self):
275 pos_ptr = _bt_iter_pos()
276 pos_ptr.type = SEEK_LAST
277 return self._timestamp_at_pos(pos_ptr)
278
279 def _timestamp_at_pos(self, pos_ptr):
280 ctf_it_ptr = _bt_ctf_iter_create(self._tc, pos_ptr, pos_ptr)
281 if ctf_it_ptr is None:
282 raise NotImplementedError(
283 "Creation of multiple iterators is unsupported.")
284 ev_ptr = _bt_ctf_iter_read_event(ctf_it_ptr)
285 _bt_ctf_iter_destroy(ctf_it_ptr)
286 if ev_ptr is None:
287 return None
288
289 def _events(self, begin_pos_ptr, end_pos_ptr):
290 ctf_it_ptr = _bt_ctf_iter_create(self._tc, begin_pos_ptr, end_pos_ptr)
291 if ctf_it_ptr is None:
292 raise NotImplementedError(
293 "Creation of multiple iterators is unsupported.")
294
295 while True:
296 ev_ptr = _bt_ctf_iter_read_event(ctf_it_ptr)
297 if ev_ptr is None:
298 break
299
300 ev = Event.__new__(Event)
301 ev._e = ev_ptr
302 try:
303 yield ev
304 except GeneratorExit:
305 break
306
307 ret = _bt_iter_next(_bt_ctf_get_iter(ctf_it_ptr))
308 if ret != 0:
309 break
310
311 _bt_ctf_iter_destroy(ctf_it_ptr)
312 %}
313
314
315
316 /* format.h */
317 %rename("lookup_format") bt_lookup_format(bt_intern_str qname);
318 %rename("_bt_print_format_list") bt_fprintf_format_list(FILE *fp);
319 %rename("register_format") bt_register_format(struct format *format);
320 %rename("unregister_format") bt_unregister_format(struct bt_format *format);
321
322 extern struct format *bt_lookup_format(bt_intern_str qname);
323 extern void bt_fprintf_format_list(FILE *fp);
324 extern int bt_register_format(struct bt_format *format);
325 extern void bt_unregister_format(struct bt_format *format);
326
327 %pythoncode %{
328
329 def print_format_list(babeltrace_file):
330 """
331 Print a list of available formats to file.
332
333 babeltrace_file must be a File instance opened in write mode.
334 """
335 try:
336 if babeltrace_file._file is not None:
337 _bt_print_format_list(babeltrace_file._file)
338 except AttributeError:
339 raise TypeError("in print_format_list, "
340 "argument 1 must be a File instance")
341
342 %}
343
344 /* iterator.h, iterator-internal.h */
345 %rename("_bt_iter_create") bt_iter_create(struct bt_context *ctx,
346 const struct bt_iter_pos *begin_pos, const struct bt_iter_pos *end_pos);
347 %rename("_bt_iter_destroy") bt_iter_destroy(struct bt_iter *iter);
348 %rename("_bt_iter_next") bt_iter_next(struct bt_iter *iter);
349 %rename("_bt_iter_get_pos") bt_iter_get_pos(struct bt_iter *iter);
350 %rename("_bt_iter_free_pos") bt_iter_free_pos(struct bt_iter_pos *pos);
351 %rename("_bt_iter_set_pos") bt_iter_set_pos(struct bt_iter *iter,
352 const struct bt_iter_pos *pos);
353 %rename("_bt_iter_create_time_pos") bt_iter_create_time_pos(struct bt_iter *iter,
354 uint64_t timestamp);
355
356 struct bt_iter *bt_iter_create(struct bt_context *ctx,
357 const struct bt_iter_pos *begin_pos, const struct bt_iter_pos *end_pos);
358 void bt_iter_destroy(struct bt_iter *iter);
359 int bt_iter_next(struct bt_iter *iter);
360 struct bt_iter_pos *bt_iter_get_pos(struct bt_iter *iter);
361 void bt_iter_free_pos(struct bt_iter_pos *pos);
362 int bt_iter_set_pos(struct bt_iter *iter, const struct bt_iter_pos *pos);
363 struct bt_iter_pos *bt_iter_create_time_pos(struct bt_iter *iter, uint64_t timestamp);
364
365 %rename("_bt_iter_pos") bt_iter_pos;
366 %rename("SEEK_TIME") BT_SEEK_TIME;
367 %rename("SEEK_RESTORE") BT_SEEK_RESTORE;
368 %rename("SEEK_CUR") BT_SEEK_CUR;
369 %rename("SEEK_BEGIN") BT_SEEK_BEGIN;
370 %rename("SEEK_LAST") BT_SEEK_LAST;
371
372 /*
373 * This struct is taken from iterator.h
374 * All changes to the struct must also be made here.
375 */
376 struct bt_iter_pos {
377 enum {
378 BT_SEEK_TIME, /* uses u.seek_time */
379 BT_SEEK_RESTORE, /* uses u.restore */
380 BT_SEEK_CUR,
381 BT_SEEK_BEGIN,
382 BT_SEEK_LAST
383 } type;
384 union {
385 uint64_t seek_time;
386 struct bt_saved_pos *restore;
387 } u;
388 };
389
390 /* trace-handle.h, trace-handle-internal.h */
391 %rename("_bt_trace_handle_create") bt_trace_handle_create(struct bt_context *ctx);
392 %rename("_bt_trace_handle_destroy") bt_trace_handle_destroy(struct bt_trace_handle *bt);
393 struct bt_trace_handle *bt_trace_handle_create(struct bt_context *ctx);
394 void bt_trace_handle_destroy(struct bt_trace_handle *bt);
395
396 %rename("_bt_trace_handle_get_path") bt_trace_handle_get_path(struct bt_context *ctx,
397 int handle_id);
398 %rename("_bt_trace_handle_get_timestamp_begin") bt_trace_handle_get_timestamp_begin(
399 struct bt_context *ctx, int handle_id, enum bt_clock_type type);
400 %rename("_bt_trace_handle_get_timestamp_end") bt_trace_handle_get_timestamp_end(
401 struct bt_context *ctx, int handle_id, enum bt_clock_type type);
402 const char *bt_trace_handle_get_path(struct bt_context *ctx, int handle_id);
403 uint64_t bt_trace_handle_get_timestamp_begin(struct bt_context *ctx, int handle_id,
404 enum bt_clock_type type);
405 uint64_t bt_trace_handle_get_timestamp_end(struct bt_context *ctx, int handle_id,
406 enum bt_clock_type type);
407
408 %rename("_bt_ctf_event_get_handle_id") bt_ctf_event_get_handle_id(
409 const struct bt_ctf_event *event);
410 int bt_ctf_event_get_handle_id(const struct bt_ctf_event *event);
411
412
413 %pythoncode%{
414
415 # Based on enum bt_clock_type in clock-type.h
416 class ClockType:
417 CLOCK_CYCLES = 0
418 CLOCK_REAL = 1
419
420
421 class TraceHandle(object):
422
423 """
424 The TraceHandle allows the user to manipulate a trace file directly.
425 It is a unique identifier representing a trace file.
426 Do not instantiate.
427 """
428
429 def __init__(self):
430 raise NotImplementedError("TraceHandle cannot be instantiated")
431
432 def __repr__(self):
433 return "Babeltrace TraceHandle: trace_id('{0}')".format(self._id)
434
435 @property
436 def id(self):
437 """Return the TraceHandle id."""
438 return self._id
439
440 @property
441 def path(self):
442 """Return the path of a TraceHandle."""
443 return _bt_trace_handle_get_path(self._trace_collection._tc, self._id)
444
445 @property
446 def timestamp_begin(self):
447 """Return the creation time of the buffers of a trace."""
448 return _bt_trace_handle_get_timestamp_begin(
449 self._trace_collection._tc, self._id, ClockType.CLOCK_REAL)
450
451 @property
452 def timestamp_end(self):
453 """Return the destruction timestamp of the buffers of a trace."""
454 return _bt_trace_handle_get_timestamp_end(
455 self._trace_collection._tc, self._id, ClockType.CLOCK_REAL)
456
457 @property
458 def events(self):
459 """
460 Generator returning all events (EventDeclaration) in a trace.
461 """
462 ret = _bt_python_event_decl_listcaller(
463 self.id,
464 self._trace_collection._tc)
465
466 if not isinstance(ret, list):
467 return
468
469 ptr_list, count = ret
470 for i in range(count):
471 tmp = EventDeclaration.__new__(EventDeclaration)
472 tmp._ed = _bt_python_decl_one_from_list(ptr_list, i)
473 yield tmp
474
475 %}
476
477 /* iterator.h, events.h */
478 %rename("_bt_ctf_iter_create") bt_ctf_iter_create(struct bt_context *ctx,
479 const struct bt_iter_pos *begin_pos,
480 const struct bt_iter_pos *end_pos);
481 %rename("_bt_ctf_get_iter") bt_ctf_get_iter(struct bt_ctf_iter *iter);
482 %rename("_bt_ctf_iter_destroy") bt_ctf_iter_destroy(struct bt_ctf_iter *iter);
483 %rename("_bt_ctf_iter_read_event") bt_ctf_iter_read_event(struct bt_ctf_iter *iter);
484
485 struct bt_ctf_iter *bt_ctf_iter_create(struct bt_context *ctx,
486 const struct bt_iter_pos *begin_pos,
487 const struct bt_iter_pos *end_pos);
488 struct bt_iter *bt_ctf_get_iter(struct bt_ctf_iter *iter);
489 void bt_ctf_iter_destroy(struct bt_ctf_iter *iter);
490 struct bt_ctf_event *bt_ctf_iter_read_event(struct bt_ctf_iter *iter);
491
492
493 /* events.h */
494 %rename("_bt_ctf_get_top_level_scope") bt_ctf_get_top_level_scope(const struct
495 bt_ctf_event *event, enum bt_ctf_scope scope);
496 %rename("_bt_ctf_event_name") bt_ctf_event_name(const struct bt_ctf_event *ctf_event);
497 %rename("_bt_ctf_get_timestamp") bt_ctf_get_timestamp(
498 const struct bt_ctf_event *ctf_event);
499 %rename("_bt_ctf_get_cycles") bt_ctf_get_cycles(
500 const struct bt_ctf_event *ctf_event);
501
502 %rename("_bt_ctf_get_field") bt_ctf_get_field(const struct bt_ctf_event *ctf_event,
503 const struct bt_definition *scope, const char *field);
504 %rename("_bt_ctf_get_index") bt_ctf_get_index(const struct bt_ctf_event *ctf_event,
505 const struct bt_definition *field, unsigned int index);
506 %rename("_bt_ctf_field_name") bt_ctf_field_name(const struct bt_definition *field);
507 %rename("_bt_ctf_field_type") bt_ctf_field_type(const struct bt_declaration *field);
508 %rename("_bt_ctf_get_int_signedness") bt_ctf_get_int_signedness(
509 const struct bt_declaration *field);
510 %rename("_bt_ctf_get_int_base") bt_ctf_get_int_base(const struct bt_declaration *field);
511 %rename("_bt_ctf_get_int_byte_order") bt_ctf_get_int_byte_order(
512 const struct bt_declaration *field);
513 %rename("_bt_ctf_get_int_len") bt_ctf_get_int_len(const struct bt_declaration *field);
514 %rename("_bt_ctf_get_enum_int") bt_ctf_get_enum_int(const struct bt_definition *field);
515 %rename("_bt_ctf_get_enum_str") bt_ctf_get_enum_str(const struct bt_definition *field);
516 %rename("_bt_ctf_get_encoding") bt_ctf_get_encoding(const struct bt_declaration *field);
517 %rename("_bt_ctf_get_array_len") bt_ctf_get_array_len(const struct bt_declaration *field);
518 %rename("_bt_ctf_get_uint64") bt_ctf_get_uint64(const struct bt_definition *field);
519 %rename("_bt_ctf_get_int64") bt_ctf_get_int64(const struct bt_definition *field);
520 %rename("_bt_ctf_get_char_array") bt_ctf_get_char_array(const struct bt_definition *field);
521 %rename("_bt_ctf_get_string") bt_ctf_get_string(const struct bt_definition *field);
522 %rename("_bt_ctf_get_float") bt_ctf_get_float(const struct bt_definition *field);
523 %rename("_bt_ctf_get_variant") bt_ctf_get_variant(const struct bt_definition *field);
524 %rename("_bt_ctf_field_get_error") bt_ctf_field_get_error(void);
525 %rename("_bt_ctf_get_decl_event_name") bt_ctf_get_decl_event_name(const struct
526 bt_ctf_event_decl *event);
527 %rename("_bt_ctf_get_decl_event_id") bt_ctf_get_decl_event_id(const struct
528 bt_ctf_event_decl *event);
529 %rename("_bt_ctf_get_decl_field_name") bt_ctf_get_decl_field_name(
530 const struct bt_ctf_field_decl *field);
531 %rename("_bt_ctf_get_decl_from_def") bt_ctf_get_decl_from_def(
532 const struct bt_definition *field);
533 %rename("_bt_ctf_get_decl_from_field_decl") bt_ctf_get_decl_from_field_decl(
534 const struct bt_ctf_field_decl *field);
535 %rename("_bt_array_index") bt_array_index(struct definition_array *array, uint64_t i);
536 %rename("_bt_sequence_len") bt_sequence_len(struct definition_sequence *sequence);
537 %rename("_bt_sequence_index") bt_sequence_index(struct definition_sequence *sequence, uint64_t i);
538 %rename("_bt_ctf_get_struct_field_count") bt_ctf_get_struct_field_count(const struct bt_definition *structure);
539 %rename("_bt_ctf_get_struct_field_index") bt_ctf_get_struct_field_index(const struct bt_definition *structure, uint64_t i);
540
541 const struct bt_definition *bt_ctf_get_top_level_scope(const struct bt_ctf_event *ctf_event,
542 enum bt_ctf_scope scope);
543 const char *bt_ctf_event_name(const struct bt_ctf_event *ctf_event);
544 uint64_t bt_ctf_get_timestamp(const struct bt_ctf_event *ctf_event);
545 uint64_t bt_ctf_get_cycles(const struct bt_ctf_event *ctf_event);
546 const struct bt_definition *bt_ctf_get_field(const struct bt_ctf_event *ctf_event,
547 const struct bt_definition *scope,
548 const char *field);
549 const struct bt_definition *bt_ctf_get_index(const struct bt_ctf_event *ctf_event,
550 const struct bt_definition *field,
551 unsigned int index);
552 const char *bt_ctf_field_name(const struct bt_definition *field);
553 enum ctf_type_id bt_ctf_field_type(const struct bt_declaration *field);
554 int bt_ctf_get_int_signedness(const struct bt_declaration *field);
555 int bt_ctf_get_int_base(const struct bt_declaration *field);
556 int bt_ctf_get_int_byte_order(const struct bt_declaration *field);
557 ssize_t bt_ctf_get_int_len(const struct bt_declaration *field);
558 const struct bt_definition *bt_ctf_get_enum_int(const struct bt_definition *field);
559 const char *bt_ctf_get_enum_str(const struct bt_definition *field);
560 enum ctf_string_encoding bt_ctf_get_encoding(const struct bt_declaration *field);
561 int bt_ctf_get_array_len(const struct bt_declaration *field);
562 struct bt_definition *bt_array_index(struct definition_array *array, uint64_t i);
563 uint64_t bt_ctf_get_uint64(const struct bt_definition *field);
564 int64_t bt_ctf_get_int64(const struct bt_definition *field);
565 char *bt_ctf_get_char_array(const struct bt_definition *field);
566 char *bt_ctf_get_string(const struct bt_definition *field);
567 double bt_ctf_get_float(const struct bt_definition *field);
568 const struct bt_definition *bt_ctf_get_variant(const struct bt_definition *field);
569 int bt_ctf_field_get_error(void);
570 const char *bt_ctf_get_decl_event_name(const struct bt_ctf_event_decl *event);
571 uint64_t bt_ctf_get_decl_event_id(const struct bt_ctf_event_decl *event);
572 const char *bt_ctf_get_decl_field_name(const struct bt_ctf_field_decl *field);
573 const struct bt_declaration *bt_ctf_get_decl_from_def(const struct bt_definition *field);
574 const struct bt_declaration *bt_ctf_get_decl_from_field_decl(const struct bt_ctf_field_decl *field);
575 uint64_t bt_sequence_len(struct definition_sequence *sequence);
576 struct bt_definition *bt_sequence_index(struct definition_sequence *sequence, uint64_t i);
577 uint64_t bt_ctf_get_struct_field_count(const struct bt_definition *structure);
578 const struct bt_definition *bt_ctf_get_struct_field_index(const struct bt_definition *structure, uint64_t i);
579
580 %pythoncode%{
581
582 class CTFStringEncoding:
583 NONE = 0
584 UTF8 = 1
585 ASCII = 2
586 UNKNOWN = 3
587
588 # Based on the enum in ctf-writer/writer.h
589 class ByteOrder:
590 BYTE_ORDER_NATIVE = 0
591 BYTE_ORDER_LITTLE_ENDIAN = 1
592 BYTE_ORDER_BIG_ENDIAN = 2
593 BYTE_ORDER_NETWORK = 3
594 BYTE_ORDER_UNKNOWN = 4 # Python-specific entry
595
596 # enum equivalent, accessible constants
597 # These are taken directly from ctf/events.h
598 # All changes to enums must also be made here
599 class CTFTypeId:
600 UNKNOWN = 0
601 INTEGER = 1
602 FLOAT = 2
603 ENUM = 3
604 STRING = 4
605 STRUCT = 5
606 UNTAGGED_VARIANT = 6
607 VARIANT = 7
608 ARRAY = 8
609 SEQUENCE = 9
610 NR_CTF_TYPES = 10
611
612 def type_name(id):
613 name = "UNKNOWN_TYPE"
614 constants = [
615 attr for attr in dir(CTFTypeId) if not callable(
616 getattr(
617 CTFTypeId,
618 attr)) and not attr.startswith("__")]
619 for attr in constants:
620 if getattr(CTFTypeId, attr) == id:
621 name = attr
622 break
623 return name
624
625
626 class CTFScope:
627 TRACE_PACKET_HEADER = 0
628 STREAM_PACKET_CONTEXT = 1
629 STREAM_EVENT_HEADER = 2
630 STREAM_EVENT_CONTEXT = 3
631 EVENT_CONTEXT = 4
632 EVENT_FIELDS = 5
633
634 def scope_name(scope):
635 name = "UNKNOWN_SCOPE"
636 constants = [
637 attr for attr in dir(CTFScope) if not callable(
638 getattr(
639 CTFScope,
640 attr)) and not attr.startswith("__")]
641 for attr in constants:
642 if getattr(CTFScope, attr) == scope:
643 name = attr
644 break
645 return name
646
647 # Priority of the scopes when searching for event fields
648 _scopes = [CTFScope.EVENT_FIELDS, CTFScope.EVENT_CONTEXT, CTFScope.STREAM_EVENT_CONTEXT,
649 CTFScope.STREAM_EVENT_HEADER, CTFScope.STREAM_PACKET_CONTEXT, CTFScope.TRACE_PACKET_HEADER]
650
651 import collections
652 from datetime import datetime
653
654
655 class Event(collections.Mapping):
656
657 """
658 This class represents an event from the trace.
659 It is obtained using the TraceCollection generator functions.
660 Do not instantiate.
661 """
662
663 def __init__(self):
664 raise NotImplementedError("Event cannot be instantiated")
665
666 @property
667 def name(self):
668 """Return the name of the event or None on error."""
669 return _bt_ctf_event_name(self._e)
670
671 @property
672 def cycles(self):
673 """
674 Return the timestamp of the event as written in
675 the packet (in cycles) or -1ULL on error.
676 """
677 return _bt_ctf_get_cycles(self._e)
678
679 @property
680 def timestamp(self):
681 """
682 Return the timestamp of the event offset with the
683 system clock source or -1ULL on error.
684 """
685 return _bt_ctf_get_timestamp(self._e)
686
687 @property
688 def datetime(self):
689 """
690 Return a datetime object based on the event's
691 timestamp. Note that the datetime class' precision
692 is limited to microseconds.
693 """
694 return datetime.fromtimestamp(self.timestamp / 1E9)
695
696 def field_with_scope(self, field_name, scope):
697 """
698 Get field_name's value in scope.
699 None is returned if no field matches field_name.
700 """
701 if not scope in _scopes:
702 raise ValueError("Invalid scope provided")
703 field = self._field_with_scope(field_name, scope)
704 if field is not None:
705 return field.value
706 return None
707
708 def field_list_with_scope(self, scope):
709 """Return a list of field names in scope."""
710 if not scope in _scopes:
711 raise ValueError("Invalid scope provided")
712 field_names = []
713 for field in self._field_list_with_scope(scope):
714 field_names.append(field.name)
715 return field_names
716
717 @property
718 def handle(self):
719 """
720 Get the TraceHandle associated with this event
721 Return None on error
722 """
723 ret = _bt_ctf_event_get_handle_id(self._e)
724 if ret < 0:
725 return None
726
727 th = TraceHandle.__new__(TraceHandle)
728 th._id = ret
729 th._trace_collection = self.get_trace_collection()
730 return th
731
732 @property
733 def trace_collection(self):
734 """
735 Get the TraceCollection associated with this event.
736 Return None on error.
737 """
738 trace_collection = TraceCollection()
739 trace_collection._tc = _bt_ctf_event_get_context(self._e)
740 if trace_collection._tc is None:
741 return None
742 else:
743 return trace_collection
744
745 def __getitem__(self, field_name):
746 """
747 Get field_name's value. If the field_name exists in multiple
748 scopes, the first field found is returned. The scopes are searched
749 in the following order:
750 1) EVENT_FIELDS
751 2) EVENT_CONTEXT
752 3) STREAM_EVENT_CONTEXT
753 4) STREAM_EVENT_HEADER
754 5) STREAM_PACKET_CONTEXT
755 6) TRACE_PACKET_HEADER
756 None is returned if no field matches field_name.
757
758 Use field_with_scope() to explicitly access fields in a given
759 scope.
760 """
761 field = self._field(field_name)
762 if field is not None:
763 return field.value
764 raise KeyError(field_name)
765
766 def __iter__(self):
767 for key in self.keys():
768 yield key
769
770 def __len__(self):
771 count = 0
772 for scope in _scopes:
773 scope_ptr = _bt_ctf_get_top_level_scope(self._e, scope)
774 ret = _bt_python_field_listcaller(self._e, scope_ptr)
775 if isinstance(ret, list):
776 count += ret[1]
777 return count
778
779 def __contains__(self, field_name):
780 return self._field(field_name) is not None
781
782 def keys(self):
783 """Return a list of field names."""
784 field_names = set()
785 for scope in _scopes:
786 for name in self.field_list_with_scope(scope):
787 field_names.add(name)
788 return list(field_names)
789
790 def get(self, field_name, default=None):
791 field = self._field(field_name)
792 if field is None:
793 return default
794 return field.value
795
796 def items(self):
797 for field in self.keys():
798 yield (field, self[field])
799
800 def _field_with_scope(self, field_name, scope):
801 scope_ptr = _bt_ctf_get_top_level_scope(self._e, scope)
802 if scope_ptr is None:
803 return None
804
805 definition_ptr = _bt_ctf_get_field(self._e, scope_ptr, field_name)
806 if definition_ptr is None:
807 return None
808
809 field = _Definition(definition_ptr, scope)
810 return field
811
812 def _field(self, field_name):
813 field = None
814 for scope in _scopes:
815 field = self._field_with_scope(field_name, scope)
816 if field is not None:
817 break
818 return field
819
820 def _field_list_with_scope(self, scope):
821 fields = []
822 scope_ptr = _bt_ctf_get_top_level_scope(self._e, scope)
823
824 # Returns a list [list_ptr, count]. If list_ptr is NULL, SWIG will only
825 # provide the "count" return value
826 count = 0
827 list_ptr = None
828 ret = _bt_python_field_listcaller(self._e, scope_ptr)
829 if isinstance(ret, list):
830 list_ptr, count = ret
831
832 for i in range(count):
833 definition_ptr = _bt_python_field_one_from_list(list_ptr, i)
834 if definition_ptr is not None:
835 definition = _Definition(definition_ptr, scope)
836 fields.append(definition)
837 return fields
838
839
840 class FieldError(Exception):
841
842 def __init__(self, value):
843 self.value = value
844
845 def __str__(self):
846 return repr(self.value)
847
848
849 class EventDeclaration(object):
850
851 """Event declaration class. Do not instantiate."""
852 MAX_UINT64 = 0xFFFFFFFFFFFFFFFF
853
854 def __init__(self):
855 raise NotImplementedError("EventDeclaration cannot be instantiated")
856
857 @property
858 def name(self):
859 """Return the name of the event or None on error"""
860 return _bt_ctf_get_decl_event_name(self._ed)
861
862 @property
863 def id(self):
864 """Return the event-ID of the event or -1 on error"""
865 id = _bt_ctf_get_decl_event_id(self._ed)
866 if id == self.MAX_UINT64:
867 id = -1
868 return id
869
870 @property
871 def fields(self):
872 """
873 Generator returning all FieldDeclarations of an event, going through
874 each scope in the following order:
875 1) EVENT_FIELDS
876 2) EVENT_CONTEXT
877 3) STREAM_EVENT_CONTEXT
878 4) STREAM_EVENT_HEADER
879 5) STREAM_PACKET_CONTEXT
880 6) TRACE_PACKET_HEADER
881 """
882 for scope in _scopes:
883 for declaration in self.fields_scope(scope):
884 yield declaration
885
886 def fields_scope(self, scope):
887 """
888 Generator returning FieldDeclarations of the current event in scope.
889 """
890 ret = _by_python_field_decl_listcaller(self._ed, scope)
891
892 if not isinstance(ret, list):
893 return
894
895 list_ptr, count = ret
896 for i in range(count):
897 field_declaration_ptr = _bt_python_field_decl_one_from_list(
898 list_ptr,
899 i)
900 if field_declaration_ptr is not None:
901 declaration_ptr = _bt_ctf_get_decl_from_field_decl(
902 field_declaration_ptr)
903 field_declaration = _create_field_declaration(
904 declaration_ptr,
905 _bt_ctf_get_decl_field_name(field_declaration_ptr),
906 scope)
907 yield field_declaration
908
909
910 class FieldDeclaration(object):
911
912 """Field declaration class. Do not instantiate."""
913
914 def __init__(self):
915 raise NotImplementedError("FieldDeclaration cannot be instantiated")
916
917 def __repr__(self):
918 return "({0}) {1} {2}".format(
919 CTFScope.scope_name(self.scope), CTFTypeId.type_name(self.type), self.name)
920
921 @property
922 def name(self):
923 """Return the name of a FieldDeclaration or None on error."""
924 return self._name
925
926 @property
927 def type(self):
928 """
929 Return the FieldDeclaration's type. One of the entries in class
930 CTFTypeId.
931 """
932 return _bt_ctf_field_type(self._fd)
933
934 @property
935 def scope(self):
936 """
937 Return the FieldDeclaration's scope.
938 """
939 return self._s
940
941
942 class IntegerFieldDeclaration(FieldDeclaration):
943
944 """Do not instantiate."""
945
946 def __init__(self):
947 raise NotImplementedError(
948 "IntegerFieldDeclaration cannot be instantiated")
949
950 @property
951 def signedness(self):
952 """
953 Return the signedness of an integer:
954 0 if unsigned; 1 if signed; -1 on error.
955 """
956 return _bt_ctf_get_int_signedness(self._fd)
957
958 @property
959 def base(self):
960 """Return the base of an int or a negative value on error."""
961 return _bt_ctf_get_int_base(self._fd)
962
963 @property
964 def byte_order(self):
965 """
966 Return the byte order. One of class ByteOrder's entries.
967 """
968 ret = _bt_ctf_get_int_byte_order(self._fd)
969 if ret == 1234:
970 return ByteOrder.BYTE_ORDER_LITTLE_ENDIAN
971 elif ret == 4321:
972 return ByteOrder.BYTE_ORDER_BIG_ENDIAN
973 else:
974 return ByteOrder.BYTE_ORDER_UNKNOWN
975
976 @property
977 def length(self):
978 """
979 Return the size, in bits, of an int or a negative
980 value on error.
981 """
982 return _bt_ctf_get_int_len(self._fd)
983
984 @property
985 def encoding(self):
986 """
987 Return the encoding. One of class CTFStringEncoding's entries.
988 Return a negative value on error.
989 """
990 return _bt_ctf_get_encoding(self._fd)
991
992
993 class EnumerationFieldDeclaration(FieldDeclaration):
994
995 """Do not instantiate."""
996
997 def __init__(self):
998 raise NotImplementedError(
999 "EnumerationFieldDeclaration cannot be instantiated")
1000
1001
1002 class ArrayFieldDeclaration(FieldDeclaration):
1003
1004 """Do not instantiate."""
1005
1006 def __init__(self):
1007 raise NotImplementedError(
1008 "ArrayFieldDeclaration cannot be instantiated")
1009
1010 @property
1011 def length(self):
1012 """
1013 Return the length of an array or a negative
1014 value on error.
1015 """
1016 return _bt_ctf_get_array_len(self._fd)
1017
1018 @property
1019 def element_declaration(self):
1020 """
1021 Return element declaration.
1022 """
1023 field_decl_ptr = _bt_python_get_array_element_declaration(self._fd)
1024 return _create_field_declaration(field_decl_ptr, "", self.scope)
1025
1026
1027 class SequenceFieldDeclaration(FieldDeclaration):
1028
1029 """Do not instantiate."""
1030
1031 def __init__(self):
1032 raise NotImplementedError(
1033 "SequenceFieldDeclaration cannot be instantiated")
1034
1035 @property
1036 def element_declaration(self):
1037 """
1038 Return element declaration.
1039 """
1040 field_decl_ptr = _bt_python_get_sequence_element_declaration(self._fd)
1041 return _create_field_declaration(field_decl_ptr, "", self.scope)
1042
1043
1044 class FloatFieldDeclaration(FieldDeclaration):
1045
1046 """Do not instantiate."""
1047
1048 def __init__(self):
1049 raise NotImplementedError(
1050 "FloatFieldDeclaration cannot be instantiated")
1051
1052
1053 class StructureFieldDeclaration(FieldDeclaration):
1054
1055 """Do not instantiate."""
1056
1057 def __init__(self):
1058 raise NotImplementedError(
1059 "StructureFieldDeclaration cannot be instantiated")
1060
1061
1062 class StringFieldDeclaration(FieldDeclaration):
1063
1064 """Do not instantiate."""
1065
1066 def __init__(self):
1067 raise NotImplementedError(
1068 "StringFieldDeclaration cannot be instantiated")
1069
1070
1071 class VariantFieldDeclaration(FieldDeclaration):
1072
1073 """Do not instantiate."""
1074
1075 def __init__(self):
1076 raise NotImplementedError(
1077 "VariantFieldDeclaration cannot be instantiated")
1078
1079
1080 def field_error():
1081 """
1082 Return the last error code encountered while
1083 accessing a field and reset the error flag.
1084 Return 0 if no error, a negative value otherwise.
1085 """
1086 return _bt_ctf_field_get_error()
1087
1088
1089 def _create_field_declaration(declaration_ptr, name, scope):
1090 """
1091 Private field declaration factory.
1092 """
1093 if declaration_ptr is None:
1094 raise ValueError("declaration_ptr must be valid")
1095 if not scope in _scopes:
1096 raise ValueError("Invalid scope provided")
1097
1098 type = _bt_ctf_field_type(declaration_ptr)
1099 declaration = None
1100 if type == CTFTypeId.INTEGER:
1101 declaration = IntegerFieldDeclaration.__new__(IntegerFieldDeclaration)
1102 elif type == CTFTypeId.ENUM:
1103 declaration = EnumerationFieldDeclaration.__new__(
1104 EnumerationFieldDeclaration)
1105 elif type == CTFTypeId.ARRAY:
1106 declaration = ArrayFieldDeclaration.__new__(ArrayFieldDeclaration)
1107 elif type == CTFTypeId.SEQUENCE:
1108 declaration = SequenceFieldDeclaration.__new__(
1109 SequenceFieldDeclaration)
1110 elif type == CTFTypeId.FLOAT:
1111 declaration = FloatFieldDeclaration.__new__(FloatFieldDeclaration)
1112 elif type == CTFTypeId.STRUCT:
1113 declaration = StructureFieldDeclaration.__new__(
1114 StructureFieldDeclaration)
1115 elif type == CTFTypeId.STRING:
1116 declaration = StringFieldDeclaration.__new__(StringFieldDeclaration)
1117 elif type == CTFTypeId.VARIANT:
1118 declaration = VariantFieldDeclaration.__new__(VariantFieldDeclaration)
1119 else:
1120 return declaration
1121
1122 declaration._fd = declaration_ptr
1123 declaration._s = scope
1124 declaration._name = name
1125 return declaration
1126
1127
1128 class _Definition(object):
1129
1130 def __init__(self, definition_ptr, scope):
1131 self._d = definition_ptr
1132 self._s = scope
1133 if not scope in _scopes:
1134 ValueError("Invalid scope provided")
1135
1136 @property
1137 def name(self):
1138 """Return the name of a field or None on error."""
1139 return _bt_ctf_field_name(self._d)
1140
1141 @property
1142 def type(self):
1143 """Return the type of a field or -1 if unknown."""
1144 return _bt_ctf_field_type(_bt_ctf_get_decl_from_def(self._d))
1145
1146 @property
1147 def declaration(self):
1148 """Return the associated Definition object."""
1149 return _create_field_declaration(
1150 _bt_ctf_get_decl_from_def(self._d), self.name, self.scope)
1151
1152 def _get_enum_str(self):
1153 """
1154 Return the string matching the current enumeration.
1155 Return None on error.
1156 """
1157 return _bt_ctf_get_enum_str(self._d)
1158
1159 def _get_array_element_at(self, index):
1160 """
1161 Return the array's element at position index.
1162 Return None on error
1163 """
1164 array_ptr = _bt_python_get_array_from_def(self._d)
1165 if array_ptr is None:
1166 return None
1167
1168 definition_ptr = _bt_array_index(array_ptr, index)
1169 if definition_ptr is None:
1170 return None
1171 return _Definition(definition_ptr, self.scope)
1172
1173 def _get_sequence_len(self):
1174 """
1175 Return the len of a sequence or a negative
1176 value on error.
1177 """
1178 seq = _bt_python_get_sequence_from_def(self._d)
1179 return _bt_sequence_len(seq)
1180
1181 def _get_sequence_element_at(self, index):
1182 """
1183 Return the sequence's element at position index,
1184 otherwise return None
1185 """
1186 seq = _bt_python_get_sequence_from_def(self._d)
1187 if seq is not None:
1188 definition_ptr = _bt_sequence_index(seq, index)
1189 if definition_ptr is not None:
1190 return _Definition(definition_ptr, self.scope)
1191 return None
1192
1193 def _get_uint64(self):
1194 """
1195 Return the value associated with the field.
1196 If the field does not exist or is not of the type requested,
1197 the value returned is undefined. To check if an error occured,
1198 use the field_error() function after accessing a field.
1199 """
1200 return _bt_ctf_get_uint64(self._d)
1201
1202 def _get_int64(self):
1203 """
1204 Return the value associated with the field.
1205 If the field does not exist or is not of the type requested,
1206 the value returned is undefined. To check if an error occured,
1207 use the field_error() function after accessing a field.
1208 """
1209 return _bt_ctf_get_int64(self._d)
1210
1211 def _get_char_array(self):
1212 """
1213 Return the value associated with the field.
1214 If the field does not exist or is not of the type requested,
1215 the value returned is undefined. To check if an error occurred,
1216 use the field_error() function after accessing a field.
1217 """
1218 return _bt_ctf_get_char_array(self._d)
1219
1220 def _get_str(self):
1221 """
1222 Return the value associated with the field.
1223 If the field does not exist or is not of the type requested,
1224 the value returned is undefined. To check if an error occurred,
1225 use the field_error() function after accessing a field.
1226 """
1227 return _bt_ctf_get_string(self._d)
1228
1229 def _get_float(self):
1230 """
1231 Return the value associated with the field.
1232 If the field does not exist or is not of the type requested,
1233 the value returned is undefined. To check if an error occurred,
1234 use the field_error() function after accessing a field.
1235 """
1236 return _bt_ctf_get_float(self._d)
1237
1238 def _get_variant(self):
1239 """
1240 Return the variant's selected field.
1241 If the field does not exist or is not of the type requested,
1242 the value returned is undefined. To check if an error occurred,
1243 use the field_error() function after accessing a field.
1244 """
1245 return _bt_ctf_get_variant(self._d)
1246
1247 def _get_struct_field_count(self):
1248 """
1249 Return the number of fields contained in the structure.
1250 If the field does not exist or is not of the type requested,
1251 the value returned is undefined.
1252 """
1253 return _bt_ctf_get_struct_field_count(self._d)
1254
1255 def _get_struct_field_at(self, i):
1256 """
1257 Return the structure's field at position i.
1258 If the field does not exist or is not of the type requested,
1259 the value returned is undefined. To check if an error occurred,
1260 use the field_error() function after accessing a field.
1261 """
1262 return _bt_ctf_get_struct_field_index(self._d, i)
1263
1264 @property
1265 def value(self):
1266 """
1267 Return the value associated with the field according to its type.
1268 Return None on error.
1269 """
1270 id = self.type
1271 value = None
1272
1273 if id == CTFTypeId.STRING:
1274 value = self._get_str()
1275 elif id == CTFTypeId.ARRAY:
1276 element_decl = self.declaration.element_declaration
1277 if ((element_decl.type == CTFTypeId.INTEGER
1278 and element_decl.length == 8)
1279 and (element_decl.encoding == CTFStringEncoding.ASCII or element_decl.encoding == CTFStringEncoding.UTF8)):
1280 value = _bt_python_get_array_string(self._d)
1281 else:
1282 value = []
1283 for i in range(self.declaration.length):
1284 element = self._get_array_element_at(i)
1285 value.append(element.value)
1286 elif id == CTFTypeId.INTEGER:
1287 if self.declaration.signedness == 0:
1288 value = self._get_uint64()
1289 else:
1290 value = self._get_int64()
1291 elif id == CTFTypeId.ENUM:
1292 value = self._get_enum_str()
1293 elif id == CTFTypeId.SEQUENCE:
1294 element_decl = self.declaration.element_declaration
1295 if ((element_decl.type == CTFTypeId.INTEGER
1296 and element_decl.length == 8)
1297 and (element_decl.encoding == CTFStringEncoding.ASCII or element_decl.encoding == CTFStringEncoding.UTF8)):
1298 value = _bt_python_get_sequence_string(self._d)
1299 else:
1300 seq_len = self._get_sequence_len()
1301 value = []
1302 for i in range(seq_len):
1303 evDef = self._get_sequence_element_at(i)
1304 value.append(evDef.value)
1305 elif id == CTFTypeId.FLOAT:
1306 value = self._get_float()
1307 elif id == CTFTypeId.VARIANT:
1308 variant = _Definition.__new__(_Definition)
1309 variant._d = self._get_variant()
1310 value = variant.value
1311 elif id == CTFTypeId.STRUCT:
1312 value = {}
1313 for i in range(self._get_struct_field_count()):
1314 member = _Definition(self._get_struct_field_at(i), self.scope)
1315 value[member.name] = member.value
1316
1317 if field_error():
1318 raise FieldError(
1319 "Error occurred while accessing field {} of type {}".format(
1320 self.name,
1321 CTFTypeId.type_name(id)))
1322 return value
1323
1324 @property
1325 def scope(self):
1326 """Return the scope of a field or None on error."""
1327 return self._s
1328
1329 %}
1330
1331 /* CTF Writer */
1332
1333 /* clock.h */
1334 %rename("_bt_ctf_clock_create") bt_ctf_clock_create(const char *name);
1335 %rename("_bt_ctf_clock_get_name") bt_ctf_clock_get_name(struct bt_ctf_clock *clock);
1336 %rename("_bt_ctf_clock_get_description") bt_ctf_clock_get_description(struct bt_ctf_clock *clock);
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_get_frequency") bt_ctf_clock_get_frequency(struct bt_ctf_clock *clock);
1339 %rename("_bt_ctf_clock_set_frequency") bt_ctf_clock_set_frequency(struct bt_ctf_clock *clock, uint64_t freq);
1340 %rename("_bt_ctf_clock_get_precision") bt_ctf_clock_get_precision(struct bt_ctf_clock *clock);
1341 %rename("_bt_ctf_clock_set_precision") bt_ctf_clock_set_precision(struct bt_ctf_clock *clock, uint64_t precision);
1342 %rename("_bt_ctf_clock_get_offset_s") bt_ctf_clock_get_offset_s(struct bt_ctf_clock *clock);
1343 %rename("_bt_ctf_clock_set_offset_s") bt_ctf_clock_set_offset_s(struct bt_ctf_clock *clock, uint64_t offset_s);
1344 %rename("_bt_ctf_clock_get_offset") bt_ctf_clock_get_offset(struct bt_ctf_clock *clock);
1345 %rename("_bt_ctf_clock_set_offset") bt_ctf_clock_set_offset(struct bt_ctf_clock *clock, uint64_t offset);
1346 %rename("_bt_ctf_clock_get_is_absolute") bt_ctf_clock_get_is_absolute(struct bt_ctf_clock *clock);
1347 %rename("_bt_ctf_clock_set_is_absolute") bt_ctf_clock_set_is_absolute(struct bt_ctf_clock *clock, int is_absolute);
1348 %rename("_bt_ctf_clock_get_time") bt_ctf_clock_get_time(struct bt_ctf_clock *clock);
1349 %rename("_bt_ctf_clock_set_time") bt_ctf_clock_set_time(struct bt_ctf_clock *clock, uint64_t time);
1350 %rename("_bt_ctf_clock_get") bt_ctf_clock_get(struct bt_ctf_clock *clock);
1351 %rename("_bt_ctf_clock_put") bt_ctf_clock_put(struct bt_ctf_clock *clock);
1352
1353 struct bt_ctf_clock *bt_ctf_clock_create(const char *name);
1354 const char *bt_ctf_clock_get_name(struct bt_ctf_clock *clock);
1355 const char *bt_ctf_clock_get_description(struct bt_ctf_clock *clock);
1356 int bt_ctf_clock_set_description(struct bt_ctf_clock *clock, const char *desc);
1357 uint64_t bt_ctf_clock_get_frequency(struct bt_ctf_clock *clock);
1358 int bt_ctf_clock_set_frequency(struct bt_ctf_clock *clock, uint64_t freq);
1359 uint64_t bt_ctf_clock_get_precision(struct bt_ctf_clock *clock);
1360 int bt_ctf_clock_set_precision(struct bt_ctf_clock *clock, uint64_t precision);
1361 uint64_t bt_ctf_clock_get_offset_s(struct bt_ctf_clock *clock);
1362 int bt_ctf_clock_set_offset_s(struct bt_ctf_clock *clock, uint64_t offset_s);
1363 uint64_t bt_ctf_clock_get_offset(struct bt_ctf_clock *clock);
1364 int bt_ctf_clock_set_offset(struct bt_ctf_clock *clock, uint64_t offset);
1365 int bt_ctf_clock_get_is_absolute(struct bt_ctf_clock *clock);
1366 int bt_ctf_clock_set_is_absolute(struct bt_ctf_clock *clock, int is_absolute);
1367 uint64_t bt_ctf_clock_get_time(struct bt_ctf_clock *clock);
1368 int bt_ctf_clock_set_time(struct bt_ctf_clock *clock, uint64_t time);
1369 void bt_ctf_clock_get(struct bt_ctf_clock *clock);
1370 void bt_ctf_clock_put(struct bt_ctf_clock *clock);
1371
1372 /* event-types.h */
1373 %rename("_bt_ctf_field_type_integer_create") bt_ctf_field_type_integer_create(unsigned int size);
1374 %rename("_bt_ctf_field_type_integer_get_size") bt_ctf_field_type_integer_get_size(struct bt_ctf_field_type *integer);
1375 %rename("_bt_ctf_field_type_integer_get_signed") bt_ctf_field_type_integer_get_signed(struct bt_ctf_field_type *integer);
1376 %rename("_bt_ctf_field_type_integer_set_signed") bt_ctf_field_type_integer_set_signed(struct bt_ctf_field_type *integer, int is_signed);
1377 %rename("_bt_ctf_field_type_integer_get_base") bt_ctf_field_type_integer_get_base(struct bt_ctf_field_type *integer);
1378 %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);
1379 %rename("_bt_ctf_field_type_integer_get_encoding") bt_ctf_field_type_integer_get_encoding(struct bt_ctf_field_type *integer);
1380 %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);
1381 %rename("_bt_ctf_field_type_enumeration_create") bt_ctf_field_type_enumeration_create(struct bt_ctf_field_type *integer_container_type);
1382 %rename("_bt_ctf_field_type_enumeration_get_container_type") bt_ctf_field_type_enumeration_get_container_type(struct bt_ctf_field_type *enumeration);
1383 %rename("_bt_ctf_field_type_enumeration_add_mapping") bt_ctf_field_type_enumeration_add_mapping(struct bt_ctf_field_type *enumeration, const char *name, int64_t range_start, int64_t range_end);
1384 %rename("_bt_ctf_field_type_enumeration_add_mapping_unsigned") bt_ctf_field_type_enumeration_add_mapping_unsigned(struct bt_ctf_field_type *enumeration, const char *name, uint64_t range_start, uint64_t range_end);
1385 %rename("_bt_ctf_field_type_enumeration_get_mapping_count") bt_ctf_field_type_enumeration_get_mapping_count(struct bt_ctf_field_type *enumeration);
1386 %rename("_bt_ctf_field_type_enumeration_get_mapping") bt_ctf_field_type_enumeration_get_mapping(struct bt_ctf_field_type *enumeration, size_t index, const char **name, int64_t *range_start, int64_t *range_end);
1387 %rename("_bt_ctf_field_type_enumeration_get_mapping_unsigned") bt_ctf_field_type_enumeration_get_mapping_unsigned(struct bt_ctf_field_type *enumeration, size_t index, const char **name, uint64_t *range_start, uint64_t *range_end);
1388 %rename("_bt_ctf_field_type_enumeration_get_mapping_index_by_name") bt_ctf_field_type_enumeration_get_mapping_index_by_name(struct bt_ctf_field_type *enumeration, const char *name, size_t *index);
1389 %rename("_bt_ctf_field_type_enumeration_get_mapping_index_by_value") bt_ctf_field_type_enumeration_get_mapping_index_by_value(struct bt_ctf_field_type *enumeration, int64_t value, size_t *index);
1390 %rename("_bt_ctf_field_type_enumeration_get_mapping_index_by_unsigned_value") bt_ctf_field_type_enumeration_get_mapping_index_by_unsigned_value(struct bt_ctf_field_type *enumeration, uint64_t value, size_t *index);
1391 %rename("_bt_ctf_field_type_floating_point_create") bt_ctf_field_type_floating_point_create(void);
1392 %rename("_bt_ctf_field_type_floating_point_get_exponent_digits") bt_ctf_field_type_floating_point_get_exponent_digits(struct bt_ctf_field_type *floating_point);
1393 %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);
1394 %rename("_bt_ctf_field_type_floating_point_get_mantissa_digits") bt_ctf_field_type_floating_point_get_mantissa_digits(struct bt_ctf_field_type *floating_point);
1395 %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);
1396 %rename("_bt_ctf_field_type_structure_create") bt_ctf_field_type_structure_create(void);
1397 %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);
1398 %rename("_bt_ctf_field_type_structure_get_field_count") bt_ctf_field_type_structure_get_field_count(struct bt_ctf_field_type *structure);
1399 %rename("_bt_ctf_field_type_structure_get_field") bt_ctf_field_type_structure_get_field(struct bt_ctf_field_type *structure, const char **field_name, struct bt_ctf_field_type **field_type, size_t index);
1400 %rename("_bt_ctf_field_type_structure_get_field_type_by_name") bt_ctf_field_type_structure_get_field_type_by_name(struct bt_ctf_field_type *structure, const char *field_name);
1401 %rename("_bt_ctf_field_type_variant_create") bt_ctf_field_type_variant_create(struct bt_ctf_field_type *enum_tag, const char *tag_name);
1402 %rename("_bt_ctf_field_type_variant_get_tag_type") bt_ctf_field_type_variant_get_tag_type(struct bt_ctf_field_type *variant);
1403 %rename("_bt_ctf_field_type_variant_get_tag_name") bt_ctf_field_type_variant_get_tag_name(struct bt_ctf_field_type *variant);
1404 %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);
1405 %rename("_bt_ctf_field_type_variant_get_field_type_by_name") bt_ctf_field_type_variant_get_field_type_by_name(struct bt_ctf_field_type *variant, const char *field_name);
1406 %rename("_bt_ctf_field_type_variant_get_field_type_from_tag") bt_ctf_field_type_variant_get_field_type_from_tag(struct bt_ctf_field_type *variant, struct bt_ctf_field *tag);
1407 %rename("_bt_ctf_field_type_variant_get_field_count") bt_ctf_field_type_variant_get_field_count(struct bt_ctf_field_type *variant);
1408 %rename("_bt_ctf_field_type_variant_get_field") bt_ctf_field_type_variant_get_field(struct bt_ctf_field_type *variant, const char **field_name, struct bt_ctf_field_type **field_type, size_t index);
1409 %rename("_bt_ctf_field_type_array_create") bt_ctf_field_type_array_create(struct bt_ctf_field_type *element_type, unsigned int length);
1410 %rename("_bt_ctf_field_type_array_get_element_type") bt_ctf_field_type_array_get_element_type(struct bt_ctf_field_type *array);
1411 %rename("_bt_ctf_field_type_array_get_length") bt_ctf_field_type_array_get_length(struct bt_ctf_field_type *array);
1412 %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);
1413 %rename("_bt_ctf_field_type_sequence_get_element_type") bt_ctf_field_type_sequence_get_element_type(struct bt_ctf_field_type *sequence);
1414 %rename("_bt_ctf_field_type_sequence_get_length_field_name") bt_ctf_field_type_sequence_get_length_field_name(struct bt_ctf_field_type *sequence);
1415 %rename("_bt_ctf_field_type_string_create") bt_ctf_field_type_string_create(void);
1416 %rename("_bt_ctf_field_type_string_get_encoding") bt_ctf_field_type_string_get_encoding(struct bt_ctf_field_type *string_type);
1417 %rename("_bt_ctf_field_type_string_set_encoding") bt_ctf_field_type_string_set_encoding(struct bt_ctf_field_type *string_type, enum ctf_string_encoding encoding);
1418 %rename("_bt_ctf_field_type_get_alignment") bt_ctf_field_type_get_alignment(struct bt_ctf_field_type *type);
1419 %rename("_bt_ctf_field_type_set_alignment") bt_ctf_field_type_set_alignment(struct bt_ctf_field_type *type, unsigned int alignment);
1420 %rename("_bt_ctf_field_type_get_byte_order") bt_ctf_field_type_get_byte_order(struct bt_ctf_field_type *type);
1421 %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);
1422 %rename("_bt_ctf_field_type_get_type_id") bt_ctf_field_type_get_type_id(struct bt_ctf_field_type *type);
1423 %rename("_bt_ctf_field_type_get") bt_ctf_field_type_get(struct bt_ctf_field_type *type);
1424 %rename("_bt_ctf_field_type_put") bt_ctf_field_type_put(struct bt_ctf_field_type *type);
1425
1426 struct bt_ctf_field_type *bt_ctf_field_type_integer_create(unsigned int size);
1427 int bt_ctf_field_type_integer_get_size(struct bt_ctf_field_type *integer);
1428 int bt_ctf_field_type_integer_get_signed(struct bt_ctf_field_type *integer);
1429 int bt_ctf_field_type_integer_set_signed(struct bt_ctf_field_type *integer, int is_signed);
1430 enum bt_ctf_integer_base bt_ctf_field_type_integer_get_base(struct bt_ctf_field_type *integer);
1431 int bt_ctf_field_type_integer_set_base(struct bt_ctf_field_type *integer, enum bt_ctf_integer_base base);
1432 enum ctf_string_encoding bt_ctf_field_type_integer_get_encoding(struct bt_ctf_field_type *integer);
1433 int bt_ctf_field_type_integer_set_encoding(struct bt_ctf_field_type *integer, enum ctf_string_encoding encoding);
1434 struct bt_ctf_field_type *bt_ctf_field_type_enumeration_create(struct bt_ctf_field_type *integer_container_type);
1435 struct bt_ctf_field_type *bt_ctf_field_type_enumeration_get_container_type(struct bt_ctf_field_type *enumeration);
1436 int bt_ctf_field_type_enumeration_add_mapping(struct bt_ctf_field_type *enumeration, const char *name, int64_t range_start, int64_t range_end);
1437 int bt_ctf_field_type_enumeration_add_mapping_unsigned(struct bt_ctf_field_type *enumeration, const char *name, uint64_t range_start, uint64_t range_end);
1438 int64_t bt_ctf_field_type_enumeration_get_mapping_count(struct bt_ctf_field_type *enumeration);
1439 int bt_ctf_field_type_enumeration_get_mapping(struct bt_ctf_field_type *enumeration, size_t index, const char **OUTPUT, int64_t *OUTPUT, int64_t *OUTPUT);
1440 int bt_ctf_field_type_enumeration_get_mapping_unsigned(struct bt_ctf_field_type *enumeration, size_t index, const char **OUTPUT, uint64_t *OUTPUT, uint64_t *OUTPUT);
1441 int bt_ctf_field_type_enumeration_get_mapping_index_by_name(struct bt_ctf_field_type *enumeration, const char *name, size_t *OUTPUT);
1442 int bt_ctf_field_type_enumeration_get_mapping_index_by_value(struct bt_ctf_field_type *enumeration, int64_t value, size_t *OUTPUT);
1443 int bt_ctf_field_type_enumeration_get_mapping_index_by_unsigned_value(struct bt_ctf_field_type *enumeration, uint64_t value, size_t *OUTPUT);
1444 struct bt_ctf_field_type *bt_ctf_field_type_floating_point_create(void);
1445 int bt_ctf_field_type_floating_point_get_exponent_digits(struct bt_ctf_field_type *floating_point);
1446 int bt_ctf_field_type_floating_point_set_exponent_digits(struct bt_ctf_field_type *floating_point, unsigned int exponent_digits);
1447 int bt_ctf_field_type_floating_point_get_mantissa_digits(struct bt_ctf_field_type *floating_point);
1448 int bt_ctf_field_type_floating_point_set_mantissa_digits(struct bt_ctf_field_type *floating_point, unsigned int mantissa_digits);
1449 struct bt_ctf_field_type *bt_ctf_field_type_structure_create(void);
1450 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);
1451 int64_t bt_ctf_field_type_structure_get_field_count(struct bt_ctf_field_type *structure);
1452 int bt_ctf_field_type_structure_get_field(struct bt_ctf_field_type *structure, const char **OUTPUT, struct bt_ctf_field_type **OUTPUT, size_t index);
1453 struct bt_ctf_field_type *bt_ctf_field_type_structure_get_field_type_by_name(struct bt_ctf_field_type *structure, const char *field_name);
1454 struct bt_ctf_field_type *bt_ctf_field_type_variant_create(struct bt_ctf_field_type *enum_tag, const char *tag_name);
1455 struct bt_ctf_field_type *bt_ctf_field_type_variant_get_tag_type(struct bt_ctf_field_type *variant);
1456 const char *bt_ctf_field_type_variant_get_tag_name(struct bt_ctf_field_type *variant);
1457 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);
1458 struct bt_ctf_field_type *bt_ctf_field_type_variant_get_field_type_by_name(struct bt_ctf_field_type *variant, const char *field_name);
1459 struct bt_ctf_field_type *bt_ctf_field_type_variant_get_field_type_from_tag(struct bt_ctf_field_type *variant, struct bt_ctf_field *tag);
1460 int64_t bt_ctf_field_type_variant_get_field_count(struct bt_ctf_field_type *variant);
1461 int bt_ctf_field_type_variant_get_field(struct bt_ctf_field_type *variant, const char **OUTPUT, struct bt_ctf_field_type **OUTPUT, size_t index);
1462 struct bt_ctf_field_type *bt_ctf_field_type_array_create(struct bt_ctf_field_type *element_type, unsigned int length);
1463 struct bt_ctf_field_type *bt_ctf_field_type_array_get_element_type(struct bt_ctf_field_type *array);
1464 int64_t bt_ctf_field_type_array_get_length(struct bt_ctf_field_type *array);
1465 struct bt_ctf_field_type *bt_ctf_field_type_sequence_create(struct bt_ctf_field_type *element_type, const char *length_field_name);
1466 struct bt_ctf_field_type *bt_ctf_field_type_sequence_get_element_type(struct bt_ctf_field_type *sequence);
1467 const char *bt_ctf_field_type_sequence_get_length_field_name(struct bt_ctf_field_type *sequence);
1468 struct bt_ctf_field_type *bt_ctf_field_type_string_create(void);
1469 enum ctf_string_encoding bt_ctf_field_type_string_get_encoding(struct bt_ctf_field_type *string_type);
1470 int bt_ctf_field_type_string_set_encoding(struct bt_ctf_field_type *string_type, enum ctf_string_encoding encoding);
1471 int bt_ctf_field_type_get_alignment(struct bt_ctf_field_type *type);
1472 int bt_ctf_field_type_set_alignment(struct bt_ctf_field_type *type, unsigned int alignment);
1473 enum bt_ctf_byte_order bt_ctf_field_type_get_byte_order(struct bt_ctf_field_type *type);
1474 int bt_ctf_field_type_set_byte_order(struct bt_ctf_field_type *type, enum bt_ctf_byte_order byte_order);
1475 enum ctf_type_id bt_ctf_field_type_get_type_id(struct bt_ctf_field_type *type);
1476 void bt_ctf_field_type_get(struct bt_ctf_field_type *type);
1477 void bt_ctf_field_type_put(struct bt_ctf_field_type *type);
1478
1479 /* event-fields.h */
1480 %rename("_bt_ctf_field_create") bt_ctf_field_create(struct bt_ctf_field_type *type);
1481 %rename("_bt_ctf_field_structure_get_field") bt_ctf_field_structure_get_field(struct bt_ctf_field *structure, const char *name);
1482 %rename("_bt_ctf_field_array_get_field") bt_ctf_field_array_get_field(struct bt_ctf_field *array, uint64_t index);
1483 %rename("_bt_ctf_field_sequence_get_length") bt_ctf_field_sequence_get_length(struct bt_ctf_field *sequence);
1484 %rename("_bt_ctf_field_sequence_set_length") bt_ctf_field_sequence_set_length(struct bt_ctf_field *sequence, struct bt_ctf_field *length_field);
1485 %rename("_bt_ctf_field_sequence_get_field") bt_ctf_field_sequence_get_field(struct bt_ctf_field *sequence, uint64_t index);
1486 %rename("_bt_ctf_field_variant_get_field") bt_ctf_field_variant_get_field(struct bt_ctf_field *variant, struct bt_ctf_field *tag);
1487 %rename("_bt_ctf_field_enumeration_get_container") bt_ctf_field_enumeration_get_container(struct bt_ctf_field *enumeration);
1488 %rename("_bt_ctf_field_enumeration_get_mapping_name") bt_ctf_field_enumeration_get_mapping_name(struct bt_ctf_field *enumeration);
1489 %rename("_bt_ctf_field_signed_integer_get_value") bt_ctf_field_signed_integer_get_value(struct bt_ctf_field *integer, int64_t *value);
1490 %rename("_bt_ctf_field_signed_integer_set_value") bt_ctf_field_signed_integer_set_value(struct bt_ctf_field *integer, int64_t value);
1491 %rename("_bt_ctf_field_unsigned_integer_get_value") bt_ctf_field_unsigned_integer_get_value(struct bt_ctf_field *integer, uint64_t *value);
1492 %rename("_bt_ctf_field_unsigned_integer_set_value") bt_ctf_field_unsigned_integer_set_value(struct bt_ctf_field *integer, uint64_t value);
1493 %rename("_bt_ctf_field_floating_point_get_value") bt_ctf_field_floating_point_get_value(struct bt_ctf_field *floating_point, double *value);
1494 %rename("_bt_ctf_field_floating_point_set_value") bt_ctf_field_floating_point_set_value(struct bt_ctf_field *floating_point, double value);
1495 %rename("_bt_ctf_field_string_get_value") bt_ctf_field_string_get_value(struct bt_ctf_field *string_field);
1496 %rename("_bt_ctf_field_string_set_value") bt_ctf_field_string_set_value(struct bt_ctf_field *string_field, const char *value);
1497 %rename("_bt_ctf_field_get_type") bt_ctf_field_get_type(struct bt_ctf_field *field);
1498 %rename("_bt_ctf_field_get") bt_ctf_field_get(struct bt_ctf_field *field);
1499 %rename("_bt_ctf_field_put") bt_ctf_field_put(struct bt_ctf_field *field);
1500
1501 struct bt_ctf_field *bt_ctf_field_create(struct bt_ctf_field_type *type);
1502 struct bt_ctf_field *bt_ctf_field_structure_get_field(struct bt_ctf_field *structure, const char *name);
1503 struct bt_ctf_field *bt_ctf_field_array_get_field(struct bt_ctf_field *array, uint64_t index);
1504 struct bt_ctf_field * bt_ctf_field_sequence_get_length(struct bt_ctf_field *sequence);
1505 int bt_ctf_field_sequence_set_length(struct bt_ctf_field *sequence, struct bt_ctf_field *length_field);
1506 struct bt_ctf_field *bt_ctf_field_sequence_get_field(struct bt_ctf_field *sequence, uint64_t index);
1507 struct bt_ctf_field *bt_ctf_field_variant_get_field(struct bt_ctf_field *variant, struct bt_ctf_field *tag);
1508 struct bt_ctf_field *bt_ctf_field_enumeration_get_container(struct bt_ctf_field *enumeration);
1509 const char *bt_ctf_field_enumeration_get_mapping_name(struct bt_ctf_field *enumeration);
1510 int bt_ctf_field_signed_integer_get_value(struct bt_ctf_field *integer, int64_t *OUTPUT);
1511 int bt_ctf_field_signed_integer_set_value(struct bt_ctf_field *integer, int64_t value);
1512 int bt_ctf_field_unsigned_integer_get_value(struct bt_ctf_field *integer, uint64_t *OUTPUT);
1513 int bt_ctf_field_unsigned_integer_set_value(struct bt_ctf_field *integer, uint64_t value);
1514 int bt_ctf_field_floating_point_get_value(struct bt_ctf_field *floating_point, double *OUTPUT);
1515 int bt_ctf_field_floating_point_set_value(struct bt_ctf_field *floating_point, double value);
1516 const char *bt_ctf_field_string_get_value(struct bt_ctf_field *string_field);
1517 int bt_ctf_field_string_set_value(struct bt_ctf_field *string_field, const char *value);
1518 struct bt_ctf_field_type *bt_ctf_field_get_type(struct bt_ctf_field *field);
1519 void bt_ctf_field_get(struct bt_ctf_field *field);
1520 void bt_ctf_field_put(struct bt_ctf_field *field);
1521
1522 /* event-class.h */
1523 %rename("_bt_ctf_event_class_create") bt_ctf_event_class_create(const char *name);
1524 %rename("_bt_ctf_event_class_get_name") bt_ctf_event_class_get_name(struct bt_ctf_event_class *event_class);
1525 %rename("_bt_ctf_event_class_get_id") bt_ctf_event_class_get_id(struct bt_ctf_event_class *event_class);
1526 %rename("_bt_ctf_event_class_set_id") bt_ctf_event_class_set_id(struct bt_ctf_event_class *event_class, uint32_t id);
1527 %rename("_bt_ctf_event_class_get_stream_class") bt_ctf_event_class_get_stream_class(struct bt_ctf_event_class *event_class);
1528 %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);
1529 %rename("_bt_ctf_event_class_get_field_count") bt_ctf_event_class_get_field_count(struct bt_ctf_event_class *event_class);
1530 %rename("_bt_ctf_event_class_get_field") bt_ctf_event_class_get_field(struct bt_ctf_event_class *event_class, const char **field_name, struct bt_ctf_field_type **field_type, size_t index);
1531 %rename("_bt_ctf_event_class_get_field_by_name") bt_ctf_event_class_get_field_by_name(struct bt_ctf_event_class *event_class, const char *name);
1532 %rename("_bt_ctf_event_class_get") bt_ctf_event_class_get(struct bt_ctf_event_class *event_class);
1533 %rename("_bt_ctf_event_class_put") bt_ctf_event_class_put(struct bt_ctf_event_class *event_class);
1534
1535 struct bt_ctf_event_class *bt_ctf_event_class_create(const char *name);
1536 const char *bt_ctf_event_class_get_name(struct bt_ctf_event_class *event_class);
1537 int64_t bt_ctf_event_class_get_id(struct bt_ctf_event_class *event_class);
1538 int bt_ctf_event_class_set_id(struct bt_ctf_event_class *event_class, uint32_t id);
1539 struct bt_ctf_stream_class *bt_ctf_event_class_get_stream_class(struct bt_ctf_event_class *event_class);
1540 int bt_ctf_event_class_add_field(struct bt_ctf_event_class *event_class, struct bt_ctf_field_type *type, const char *name);
1541 int64_t bt_ctf_event_class_get_field_count(struct bt_ctf_event_class *event_class);
1542 int bt_ctf_event_class_get_field(struct bt_ctf_event_class *event_class, const char **field_name, struct bt_ctf_field_type **field_type, size_t index);
1543 struct bt_ctf_field_type *bt_ctf_event_class_get_field_by_name(struct bt_ctf_event_class *event_class, const char *name);
1544 void bt_ctf_event_class_get(struct bt_ctf_event_class *event_class);
1545 void bt_ctf_event_class_put(struct bt_ctf_event_class *event_class);
1546
1547 /* event.h */
1548 %rename("_bt_ctf_event_create") bt_ctf_event_create(struct bt_ctf_event_class *event_class);
1549 %rename("_bt_ctf_event_get_class") bt_ctf_event_get_class(struct bt_ctf_event *event);
1550 %rename("_bt_ctf_event_get_clock") bt_ctf_event_get_clock(struct bt_ctf_event *event);
1551 %rename("_bt_ctf_event_get_payload") bt_ctf_event_get_payload(struct bt_ctf_event *event, const char *name);
1552 %rename("_bt_ctf_event_set_payload") bt_ctf_event_set_payload(struct bt_ctf_event *event, const char *name, struct bt_ctf_field *value);
1553 %rename("_bt_ctf_event_get_payload_by_index") bt_ctf_event_get_payload_by_index(struct bt_ctf_event *event, size_t index);
1554 %rename("_bt_ctf_event_get") bt_ctf_event_get(struct bt_ctf_event *event);
1555 %rename("_bt_ctf_event_put") bt_ctf_event_put(struct bt_ctf_event *event);
1556
1557 struct bt_ctf_event *bt_ctf_event_create(struct bt_ctf_event_class *event_class);
1558 struct bt_ctf_event_class *bt_ctf_event_get_class(struct bt_ctf_event *event);
1559 struct bt_ctf_clock *bt_ctf_event_get_clock(struct bt_ctf_event *event);
1560 struct bt_ctf_field *bt_ctf_event_get_payload(struct bt_ctf_event *event, const char *name);
1561 int bt_ctf_event_set_payload(struct bt_ctf_event *event, const char *name, struct bt_ctf_field *value);
1562 struct bt_ctf_field *bt_ctf_event_get_payload_by_index(struct bt_ctf_event *event, size_t index);
1563 void bt_ctf_event_get(struct bt_ctf_event *event);
1564 void bt_ctf_event_put(struct bt_ctf_event *event);
1565
1566 /* stream-class.h */
1567 %rename("_bt_ctf_stream_class_create") bt_ctf_stream_class_create(const char *name);
1568 %rename("_bt_ctf_stream_class_get_name") bt_ctf_stream_class_get_name(struct bt_ctf_stream_class *stream_class);
1569 %rename("_bt_ctf_stream_class_get_clock") bt_ctf_stream_class_get_clock(struct bt_ctf_stream_class *stream_class);
1570 %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);
1571 %rename("_bt_ctf_stream_class_get_id") bt_ctf_stream_class_get_id(struct bt_ctf_stream_class *stream_class);
1572 %rename("_bt_ctf_stream_class_set_id") bt_ctf_stream_class_set_id(struct bt_ctf_stream_class *stream_class, uint32_t id);
1573 %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);
1574 %rename("_bt_ctf_stream_class_get_event_class_count") bt_ctf_stream_class_get_event_class_count(struct bt_ctf_stream_class *stream_class);
1575 %rename("_bt_ctf_stream_class_get_event_class") bt_ctf_stream_class_get_event_class(struct bt_ctf_stream_class *stream_class, size_t index);
1576 %rename("_bt_ctf_stream_class_get_event_class_by_name") bt_ctf_stream_class_get_event_class_by_name(struct bt_ctf_stream_class *stream_class, const char *name);
1577 %rename("_bt_ctf_stream_class_get_packet_context_type") bt_ctf_stream_class_get_packet_context_type(struct bt_ctf_stream_class *stream_class);
1578 %rename("_bt_ctf_stream_class_set_packet_context_type") bt_ctf_stream_class_set_packet_context_type(struct bt_ctf_stream_class *stream_class, struct bt_ctf_field_type *packet_context_type);
1579 %rename("_bt_ctf_stream_class_get") bt_ctf_stream_class_get(struct bt_ctf_stream_class *stream_class);
1580 %rename("_bt_ctf_stream_class_put") bt_ctf_stream_class_put(struct bt_ctf_stream_class *stream_class);
1581
1582 struct bt_ctf_stream_class *bt_ctf_stream_class_create(const char *name);
1583 const char *bt_ctf_stream_class_get_name(struct bt_ctf_stream_class *stream_class);
1584 struct bt_ctf_clock *bt_ctf_stream_class_get_clock(struct bt_ctf_stream_class *stream_class);
1585 int bt_ctf_stream_class_set_clock(struct bt_ctf_stream_class *stream_class, struct bt_ctf_clock *clock);
1586 int64_t bt_ctf_stream_class_get_id(struct bt_ctf_stream_class *stream_class);
1587 int bt_ctf_stream_class_set_id(struct bt_ctf_stream_class *stream_class, uint32_t id);
1588 int bt_ctf_stream_class_add_event_class(struct bt_ctf_stream_class *stream_class, struct bt_ctf_event_class *event_class);
1589 int64_t bt_ctf_stream_class_get_event_class_count(struct bt_ctf_stream_class *stream_class);
1590 struct bt_ctf_event_class *bt_ctf_stream_class_get_event_class(struct bt_ctf_stream_class *stream_class, size_t index);
1591 struct bt_ctf_event_class *bt_ctf_stream_class_get_event_class_by_name(struct bt_ctf_stream_class *stream_class, const char *name);
1592 struct bt_ctf_field_type *bt_ctf_stream_class_get_packet_context_type(struct bt_ctf_stream_class *stream_class);
1593 int bt_ctf_stream_class_set_packet_context_type(struct bt_ctf_stream_class *stream_class, struct bt_ctf_field_type *packet_context_type);
1594 void bt_ctf_stream_class_get(struct bt_ctf_stream_class *stream_class);
1595 void bt_ctf_stream_class_put(struct bt_ctf_stream_class *stream_class);
1596
1597 /* stream.h */
1598 %rename("_bt_ctf_stream_get_discarded_events_count") bt_ctf_stream_get_discarded_events_count(struct bt_ctf_stream *stream, uint64_t *count);
1599 %rename("_bt_ctf_stream_append_discarded_events") bt_ctf_stream_append_discarded_events(struct bt_ctf_stream *stream, uint64_t event_count);
1600 %rename("_bt_ctf_stream_append_event") bt_ctf_stream_append_event(struct bt_ctf_stream *stream, struct bt_ctf_event *event);
1601 %rename("_bt_ctf_stream_get_packet_context") bt_ctf_stream_get_packet_context(struct bt_ctf_stream *stream);
1602 %rename("_bt_ctf_stream_set_packet_context") bt_ctf_stream_set_packet_context(struct bt_ctf_stream *stream, struct bt_ctf_field *packet_context);
1603 %rename("_bt_ctf_stream_flush") bt_ctf_stream_flush(struct bt_ctf_stream *stream);
1604 %rename("_bt_ctf_stream_get") bt_ctf_stream_get(struct bt_ctf_stream *stream);
1605 %rename("_bt_ctf_stream_put") bt_ctf_stream_put(struct bt_ctf_stream *stream);
1606
1607 int bt_ctf_stream_get_discarded_events_count(struct bt_ctf_stream *stream, uint64_t *OUTPUT);
1608 void bt_ctf_stream_append_discarded_events(struct bt_ctf_stream *stream, uint64_t event_count);
1609 int bt_ctf_stream_append_event(struct bt_ctf_stream *stream, struct bt_ctf_event *event);
1610 struct bt_ctf_field *bt_ctf_stream_get_packet_context(struct bt_ctf_stream *stream);
1611 int bt_ctf_stream_set_packet_context(struct bt_ctf_stream *stream, struct bt_ctf_field *packet_context);
1612 int bt_ctf_stream_flush(struct bt_ctf_stream *stream);
1613 void bt_ctf_stream_get(struct bt_ctf_stream *stream);
1614 void bt_ctf_stream_put(struct bt_ctf_stream *stream);
1615
1616 /* writer.h */
1617 %rename("_bt_ctf_writer_create") bt_ctf_writer_create(const char *path);
1618 %rename("_bt_ctf_writer_create_stream") bt_ctf_writer_create_stream(struct bt_ctf_writer *writer, struct bt_ctf_stream_class *stream_class);
1619 %rename("_bt_ctf_writer_add_environment_field") bt_ctf_writer_add_environment_field(struct bt_ctf_writer *writer, const char *name, const char *value);
1620 %rename("_bt_ctf_writer_add_clock") bt_ctf_writer_add_clock(struct bt_ctf_writer *writer, struct bt_ctf_clock *clock);
1621 %newobject bt_ctf_writer_get_metadata_string;
1622 %rename("_bt_ctf_writer_get_metadata_string") bt_ctf_writer_get_metadata_string(struct bt_ctf_writer *writer);
1623 %rename("_bt_ctf_writer_flush_metadata") bt_ctf_writer_flush_metadata(struct bt_ctf_writer *writer);
1624 %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);
1625 %rename("_bt_ctf_writer_get") bt_ctf_writer_get(struct bt_ctf_writer *writer);
1626 %rename("_bt_ctf_writer_put") bt_ctf_writer_put(struct bt_ctf_writer *writer);
1627
1628 struct bt_ctf_writer *bt_ctf_writer_create(const char *path);
1629 struct bt_ctf_stream *bt_ctf_writer_create_stream(struct bt_ctf_writer *writer, struct bt_ctf_stream_class *stream_class);
1630 int bt_ctf_writer_add_environment_field(struct bt_ctf_writer *writer, const char *name, const char *value);
1631 int bt_ctf_writer_add_clock(struct bt_ctf_writer *writer, struct bt_ctf_clock *clock);
1632 char *bt_ctf_writer_get_metadata_string(struct bt_ctf_writer *writer);
1633 void bt_ctf_writer_flush_metadata(struct bt_ctf_writer *writer);
1634 int bt_ctf_writer_set_byte_order(struct bt_ctf_writer *writer, enum bt_ctf_byte_order byte_order);
1635 void bt_ctf_writer_get(struct bt_ctf_writer *writer);
1636 void bt_ctf_writer_put(struct bt_ctf_writer *writer);
1637
1638 %pythoncode %{
1639
1640 from uuid import UUID
1641
1642
1643 class CTFWriter:
1644 # Used to compare to -1ULL in error checks
1645 _MAX_UINT64 = 0xFFFFFFFFFFFFFFFF
1646
1647 """
1648 Enumeration mapping class. start and end values are inclusive.
1649 """
1650 class EnumerationMapping:
1651
1652 def __init__(self, name, start, end):
1653 self.name = name
1654 self.start = start
1655 self.end = end
1656
1657 class Clock:
1658
1659 def __init__(self, name):
1660 self._c = _bt_ctf_clock_create(name)
1661 if self._c is None:
1662 raise ValueError("Invalid clock name.")
1663
1664 def __del__(self):
1665 _bt_ctf_clock_put(self._c)
1666
1667 """
1668 Get the clock's name.
1669 """
1670 @property
1671 def name(self):
1672 name = _bt_ctf_clock_get_name(self._c)
1673 if name is None:
1674 raise ValueError("Invalid clock instance.")
1675 return name
1676
1677 """
1678 Get the clock's description. None if unset.
1679 """
1680 @property
1681 def description(self):
1682 return _bt_ctf_clock_get_description(self._c)
1683
1684 """
1685 Set the clock's description. The description appears in the clock's TSDL
1686 meta-data.
1687 """
1688 @description.setter
1689 def description(self, desc):
1690 ret = _bt_ctf_clock_set_description(self._c, str(desc))
1691 if ret < 0:
1692 raise ValueError("Invalid clock description.")
1693
1694 """
1695 Get the clock's frequency (Hz).
1696 """
1697 @property
1698 def frequency(self):
1699 freq = _bt_ctf_clock_get_frequency(self._c)
1700 if freq == CTFWriter._MAX_UINT64:
1701 raise ValueError("Invalid clock instance")
1702 return freq
1703
1704 """
1705 Set the clock's frequency (Hz).
1706 """
1707 @frequency.setter
1708 def frequency(self, freq):
1709 ret = _bt_ctf_clock_set_frequency(self._c, freq)
1710 if ret < 0:
1711 raise ValueError("Invalid frequency value.")
1712
1713 """
1714 Get the clock's precision (in clock ticks).
1715 """
1716 @property
1717 def precision(self):
1718 precision = _bt_ctf_clock_get_precision(self._c)
1719 if precision == CTFWriter._MAX_UINT64:
1720 raise ValueError("Invalid clock instance")
1721 return precision
1722
1723 """
1724 Set the clock's precision (in clock ticks).
1725 """
1726 @precision.setter
1727 def precision(self, precision):
1728 ret = _bt_ctf_clock_set_precision(self._c, precision)
1729
1730 """
1731 Get the clock's offset in seconds from POSIX.1 Epoch.
1732 """
1733 @property
1734 def offset_seconds(self):
1735 offset_s = _bt_ctf_clock_get_offset_s(self._c)
1736 if offset_s == CTFWriter._MAX_UINT64:
1737 raise ValueError("Invalid clock instance")
1738 return offset_s
1739
1740 """
1741 Set the clock's offset in seconds from POSIX.1 Epoch.
1742 """
1743 @offset_seconds.setter
1744 def offset_seconds(self, offset_s):
1745 ret = _bt_ctf_clock_set_offset_s(self._c, offset_s)
1746 if ret < 0:
1747 raise ValueError("Invalid offset value.")
1748
1749 """
1750 Get the clock's offset in ticks from POSIX.1 Epoch + offset in seconds.
1751 """
1752 @property
1753 def offset(self):
1754 offset = _bt_ctf_clock_get_offset(self._c)
1755 if offset == CTFWriter._MAX_UINT64:
1756 raise ValueError("Invalid clock instance")
1757 return offset
1758
1759 """
1760 Set the clock's offset in ticks from POSIX.1 Epoch + offset in seconds.
1761 """
1762 @offset.setter
1763 def offset(self, offset):
1764 ret = _bt_ctf_clock_set_offset(self._c, offset)
1765 if ret < 0:
1766 raise ValueError("Invalid offset value.")
1767
1768 """
1769 Get a clock's absolute attribute. A clock is absolute if the clock
1770 is a global reference across the trace's other clocks.
1771 """
1772 @property
1773 def absolute(self):
1774 is_absolute = _bt_ctf_clock_get_is_absolute(self._c)
1775 if is_absolute == -1:
1776 raise ValueError("Invalid clock instance")
1777 return False if is_absolute == 0 else True
1778
1779 """
1780 Set a clock's absolute attribute. A clock is absolute if the clock
1781 is a global reference across the trace's other clocks.
1782 """
1783 @absolute.setter
1784 def absolute(self, is_absolute):
1785 ret = _bt_ctf_clock_set_is_absolute(self._c, int(is_absolute))
1786 if ret < 0:
1787 raise ValueError(
1788 "Could not set the clock's absolute attribute.")
1789
1790 """
1791 Get a clock's UUID (an object of type UUID).
1792 """
1793 @property
1794 def uuid(self):
1795 uuid_list = []
1796 for i in range(16):
1797 ret, value = _bt_python_ctf_clock_get_uuid_index(self._c, i)
1798 if ret < 0:
1799 raise ValueError("Invalid clock instance")
1800 uuid_list.append(value)
1801 return UUID(bytes=bytes(uuid_list))
1802
1803 """
1804 Set a clock's UUID (an object of type UUID).
1805 """
1806 @uuid.setter
1807 def uuid(self, uuid):
1808 uuid_bytes = uuid.bytes
1809 if len(uuid_bytes) != 16:
1810 raise ValueError(
1811 "Invalid UUID provided. UUID length must be 16 bytes")
1812 for i in range(len(uuid_bytes)):
1813 ret = _bt_python_ctf_clock_set_uuid_index(
1814 self._c,
1815 i,
1816 uuid_bytes[i])
1817 if ret < 0:
1818 raise ValueError("Invalid clock instance")
1819
1820 """
1821 Get the current time in nanoseconds since the clock's origin (offset and
1822 offset_s attributes).
1823 """
1824 @property
1825 def time(self):
1826 time = _bt_ctf_clock_get_time(self._c)
1827 if time == CTFWriter._MAX_UINT64:
1828 raise ValueError("Invalid clock instance")
1829 return time
1830
1831 """
1832 Set the current time in nanoseconds since the clock's origin (offset and
1833 offset_s attributes). The clock's value will be sampled as events are
1834 appended to a stream.
1835 """
1836 @time.setter
1837 def time(self, time):
1838 ret = _bt_ctf_clock_set_time(self._c, time)
1839 if ret < 0:
1840 raise ValueError("Invalid time value.")
1841
1842 class FieldDeclaration:
1843
1844 """
1845 FieldDeclaration should not be instantiated directly. Instantiate
1846 one of the concrete FieldDeclaration classes.
1847 """
1848 class IntegerBase:
1849 # These values are based on the bt_ctf_integer_base enum
1850 # declared in event-types.h.
1851 INTEGER_BASE_UNKNOWN = -1
1852 INTEGER_BASE_BINARY = 2
1853 INTEGER_BASE_OCTAL = 8
1854 INTEGER_BASE_DECIMAL = 10
1855 INTEGER_BASE_HEXADECIMAL = 16
1856
1857 def __init__(self):
1858 if self._ft is None:
1859 raise ValueError("FieldDeclaration creation failed.")
1860
1861 def __del__(self):
1862 _bt_ctf_field_type_put(self._ft)
1863
1864 @staticmethod
1865 def _create_field_declaration_from_native_instance(
1866 native_field_declaration):
1867 type_dict = {
1868 CTFTypeId.INTEGER: CTFWriter.IntegerFieldDeclaration,
1869 CTFTypeId.FLOAT: CTFWriter.FloatFieldDeclaration,
1870 CTFTypeId.ENUM: CTFWriter.EnumerationFieldDeclaration,
1871 CTFTypeId.STRING: CTFWriter.StringFieldDeclaration,
1872 CTFTypeId.STRUCT: CTFWriter.StructureFieldDeclaration,
1873 CTFTypeId.VARIANT: CTFWriter.VariantFieldDeclaration,
1874 CTFTypeId.ARRAY: CTFWriter.ArrayFieldDeclaration,
1875 CTFTypeId.SEQUENCE: CTFWriter.SequenceFieldDeclaration
1876 }
1877
1878 field_type_id = _bt_ctf_field_type_get_type_id(
1879 native_field_declaration)
1880 if field_type_id == CTFTypeId.UNKNOWN:
1881 raise TypeError("Invalid field instance")
1882
1883 declaration = CTFWriter.Field.__new__(CTFWriter.Field)
1884 declaration._ft = native_field_declaration
1885 declaration.__class__ = type_dict[field_type_id]
1886 return declaration
1887
1888 """
1889 Get the field declaration's alignment. Returns -1 on error.
1890 """
1891 @property
1892 def alignment(self):
1893 return _bt_ctf_field_type_get_alignment(self._ft)
1894
1895 """
1896 Set the field declaration's alignment. Defaults to 1 (bit-aligned). However,
1897 some types, such as structures and string, may impose other alignment
1898 constraints.
1899 """
1900 @alignment.setter
1901 def alignment(self, alignment):
1902 ret = _bt_ctf_field_type_set_alignment(self._ft, alignment)
1903 if ret < 0:
1904 raise ValueError("Invalid alignment value.")
1905
1906 """
1907 Get the field declaration's byte order. One of the ByteOrder's constant.
1908 """
1909 @property
1910 def byte_order(self):
1911 return _bt_ctf_field_type_get_byte_order(self._ft)
1912
1913 """
1914 Set the field declaration's byte order. Use constants defined in the ByteOrder
1915 class.
1916 """
1917 @byte_order.setter
1918 def byte_order(self, byte_order):
1919 ret = _bt_ctf_field_type_set_byte_order(self._ft, byte_order)
1920 if ret < 0:
1921 raise ValueError("Could not set byte order value.")
1922
1923 class IntegerFieldDeclaration(FieldDeclaration):
1924
1925 """
1926 Create a new integer field declaration of the given size.
1927 """
1928
1929 def __init__(self, size):
1930 self._ft = _bt_ctf_field_type_integer_create(size)
1931 super().__init__()
1932
1933 """
1934 Get an integer's size.
1935 """
1936 @property
1937 def size(self):
1938 ret = _bt_ctf_field_type_integer_get_size(self._ft)
1939 if ret < 0:
1940 raise ValueError("Could not get Integer's size attribute.")
1941 else:
1942 return ret
1943
1944 """
1945 Get an integer's signedness attribute.
1946 """
1947 @property
1948 def signed(self):
1949 ret = _bt_ctf_field_type_integer_get_signed(self._ft)
1950 if ret < 0:
1951 raise ValueError("Could not get Integer's signed attribute.")
1952 elif ret > 0:
1953 return True
1954 else:
1955 return False
1956
1957 """
1958 Set an integer's signedness attribute.
1959 """
1960 @signed.setter
1961 def signed(self, signed):
1962 ret = _bt_ctf_field_type_integer_set_signed(self._ft, signed)
1963 if ret < 0:
1964 raise ValueError("Could not set Integer's signed attribute.")
1965
1966 """
1967 Get the integer's base used to pretty-print the resulting trace.
1968 Returns a constant from the FieldDeclaration.IntegerBase class.
1969 """
1970 @property
1971 def base(self):
1972 return _bt_ctf_field_type_integer_get_base(self._ft)
1973
1974 """
1975 Set the integer's base used to pretty-print the resulting trace.
1976 The base must be a constant of the FieldDeclarationIntegerBase class.
1977 """
1978 @base.setter
1979 def base(self, base):
1980 ret = _bt_ctf_field_type_integer_set_base(self._ft, base)
1981 if ret < 0:
1982 raise ValueError("Could not set Integer's base.")
1983
1984 """
1985 Get the integer's encoding (one of the constants of the
1986 CTFStringEncoding class).
1987 Returns a constant from the CTFStringEncoding class.
1988 """
1989 @property
1990 def encoding(self):
1991 return _bt_ctf_field_type_integer_get_encoding(self._ft)
1992
1993 """
1994 An integer encoding may be set to signal that the integer must be printed
1995 as a text character. Must be a constant from the CTFStringEncoding class.
1996 """
1997 @encoding.setter
1998 def encoding(self, encoding):
1999 ret = _bt_ctf_field_type_integer_set_encoding(self._ft, encoding)
2000 if ret < 0:
2001 raise ValueError("Could not set Integer's encoding.")
2002
2003 class EnumerationFieldDeclaration(FieldDeclaration):
2004
2005 """
2006 Create a new enumeration field declaration with the given underlying container type.
2007 """
2008
2009 def __init__(self, integer_type):
2010 if integer_type is None or not isinstance(
2011 integer_type, CTFWriter.IntegerFieldDeclaration):
2012 raise TypeError("Invalid integer container.")
2013
2014 self._ft = _bt_ctf_field_type_enumeration_create(integer_type._ft)
2015 super().__init__()
2016
2017 """
2018 Get the enumeration's underlying container type.
2019 """
2020 @property
2021 def container(self):
2022 ret = _bt_ctf_field_type_enumeration_get_container_type(self._ft)
2023 if ret is None:
2024 raise TypeError("Invalid enumeration declaration")
2025 return CTFWriter.FieldDeclaration._create_field_declaration_from_native_instance(
2026 ret)
2027
2028 """
2029 Add a mapping to the enumeration. The range's values are inclusive.
2030 """
2031
2032 def add_mapping(self, name, range_start, range_end):
2033 if range_start < 0 or range_end < 0:
2034 ret = _bt_ctf_field_type_enumeration_add_mapping(
2035 self._ft,
2036 str(name),
2037 range_start,
2038 range_end)
2039 else:
2040 ret = _bt_ctf_field_type_enumeration_add_mapping_unsigned(
2041 self._ft,
2042 str(name),
2043 range_start,
2044 range_end)
2045
2046 if ret < 0:
2047 raise ValueError(
2048 "Could not add mapping to enumeration declaration.")
2049
2050 """
2051 Generator returning instances of EnumerationMapping.
2052 """
2053 @property
2054 def mappings(self):
2055 signed = self.container.signed
2056
2057 count = _bt_ctf_field_type_enumeration_get_mapping_count(self._ft)
2058 for i in range(count):
2059 if signed:
2060 ret = _bt_python_ctf_field_type_enumeration_get_mapping(
2061 self._ft,
2062 i)
2063 else:
2064 ret = _bt_python_ctf_field_type_enumeration_get_mapping_unsigned(
2065 self._ft,
2066 i)
2067
2068 if len(ret) != 3:
2069 raise TypeError(
2070 "Could not get Enumeration mapping at index {}".format(i))
2071 name, range_start, range_end = ret
2072 yield CTFWriter.EnumerationMapping(name, range_start, range_end)
2073
2074 """
2075 Get a mapping by name (EnumerationMapping).
2076 """
2077
2078 def get_mapping_by_name(self, name):
2079 ret, index = _bt_ctf_field_type_enumeration_get_mapping_index_by_name(
2080 self._ft, name)
2081 if ret < 0:
2082 return None
2083
2084 if self.container.signed:
2085 ret = _bt_python_ctf_field_type_enumeration_get_mapping(
2086 self._ft,
2087 index)
2088 else:
2089 ret = _bt_python_ctf_field_type_enumeration_get_mapping_unsigned(
2090 self._ft,
2091 index)
2092
2093 if len(ret) != 3:
2094 raise TypeError(
2095 "Could not get Enumeration mapping at index {}".format(i))
2096 name, range_start, range_end = ret
2097 return CTFWriter.EnumerationMapping(name, range_start, range_end)
2098
2099 """
2100 Get a mapping by value (EnumerationMapping).
2101 """
2102
2103 def get_mapping_by_value(self, value):
2104 if value < 0:
2105 ret, index = _bt_ctf_field_type_enumeration_get_mapping_index_by_value(
2106 self._ft, value)
2107 else:
2108 ret, index = _bt_ctf_field_type_enumeration_get_mapping_index_by_unsigned_value(
2109 self._ft, value)
2110
2111 if ret < 0:
2112 return None
2113
2114 if self.container.signed:
2115 ret = _bt_python_ctf_field_type_enumeration_get_mapping(
2116 self._ft,
2117 index)
2118 else:
2119 ret = _bt_python_ctf_field_type_enumeration_get_mapping_unsigned(
2120 self._ft,
2121 index)
2122
2123 if len(ret) != 3:
2124 raise TypeError(
2125 "Could not get Enumeration mapping at index {}".format(i))
2126 name, range_start, range_end = ret
2127 return CTFWriter.EnumerationMapping(name, range_start, range_end)
2128
2129 class FloatFieldDeclaration(FieldDeclaration):
2130 FLT_EXP_DIG = 8
2131 DBL_EXP_DIG = 11
2132 FLT_MANT_DIG = 24
2133 DBL_MANT_DIG = 53
2134
2135 """
2136 Create a new floating point field declaration.
2137 """
2138
2139 def __init__(self):
2140 self._ft = _bt_ctf_field_type_floating_point_create()
2141 super().__init__()
2142
2143 """
2144 Get the number of exponent digits used to store the floating point field.
2145 """
2146 @property
2147 def exponent_digits(self):
2148 ret = _bt_ctf_field_type_floating_point_get_exponent_digits(
2149 self._ft)
2150 if ret < 0:
2151 raise TypeError(
2152 "Could not get Floating point exponent digit count")
2153 return ret
2154
2155 """
2156 Set the number of exponent digits to use to store the floating point field.
2157 The only values currently supported are FLT_EXP_DIG and DBL_EXP_DIG which
2158 are defined as constants of this class.
2159 """
2160 @exponent_digits.setter
2161 def exponent_digits(self, exponent_digits):
2162 ret = _bt_ctf_field_type_floating_point_set_exponent_digits(
2163 self._ft,
2164 exponent_digits)
2165 if ret < 0:
2166 raise ValueError("Could not set exponent digit count.")
2167
2168 """
2169 Get the number of mantissa digits used to store the floating point field.
2170 """
2171 @property
2172 def mantissa_digits(self):
2173 ret = _bt_ctf_field_type_floating_point_get_mantissa_digits(
2174 self._ft)
2175 if ret < 0:
2176 raise TypeError(
2177 "Could not get Floating point mantissa digit count")
2178 return ret
2179
2180 """
2181 Set the number of mantissa digits to use to store the floating point field.
2182 The only values currently supported are FLT_MANT_DIG and DBL_MANT_DIG which
2183 are defined as constants of this class.
2184 """
2185 @mantissa_digits.setter
2186 def mantissa_digits(self, mantissa_digits):
2187 ret = _bt_ctf_field_type_floating_point_set_mantissa_digits(
2188 self._ft,
2189 mantissa_digits)
2190 if ret < 0:
2191 raise ValueError("Could not set mantissa digit count.")
2192
2193 class StructureFieldDeclaration(FieldDeclaration):
2194
2195 """
2196 Create a new structure field declaration.
2197 """
2198
2199 def __init__(self):
2200 self._ft = _bt_ctf_field_type_structure_create()
2201 super().__init__()
2202
2203 """
2204 Add a field of type "field_type" to the structure.
2205 """
2206
2207 def add_field(self, field_type, field_name):
2208 ret = _bt_ctf_field_type_structure_add_field(
2209 self._ft,
2210 field_type._ft,
2211 str(field_name))
2212 if ret < 0:
2213 raise ValueError("Could not add field to structure.")
2214
2215 """
2216 Generator returning the structure's field as tuples of (field name, field declaration).
2217 """
2218 @property
2219 def fields(self):
2220 count = _bt_ctf_field_type_structure_get_field_count(self._ft)
2221 if count < 0:
2222 raise TypeError("Could not get Structure field count")
2223
2224 for i in range(count):
2225 field_name = _bt_python_ctf_field_type_structure_get_field_name(
2226 self._ft,
2227 i)
2228 if field_name is None:
2229 raise TypeError(
2230 "Could not get Structure field name at index {}".format(i))
2231
2232 field_type_native = _bt_python_ctf_field_type_structure_get_field_type(
2233 self._ft,
2234 i)
2235 if field_type_native is None:
2236 raise TypeError(
2237 "Could not get Structure field type at index {}".format(i))
2238
2239 field_type = CTFWriter.FieldDeclaration._create_field_declaration_from_native_instance(
2240 field_type_native)
2241 yield (field_name, field_type)
2242
2243 """
2244 Get a field declaration by name (FieldDeclaration).
2245 """
2246
2247 def get_field_by_name(self, name):
2248 field_type_native = _bt_ctf_field_type_structure_get_field_type_by_name(
2249 self._ft,
2250 name)
2251 if field_type_native is None:
2252 raise TypeError(
2253 "Could not find Structure field with name {}".format(name))
2254
2255 return CTFWriter.FieldDeclaration._create_field_declaration_from_native_instance(
2256 field_type_native)
2257
2258 class VariantFieldDeclaration(FieldDeclaration):
2259
2260 """
2261 Create a new variant field declaration.
2262 """
2263
2264 def __init__(self, enum_tag, tag_name):
2265 if enum_tag is None or not isinstance(
2266 enum_tag, CTFWriter.EnumerationFieldDeclaration):
2267 raise TypeError(
2268 "Invalid tag type; must be of type EnumerationFieldDeclaration.")
2269
2270 self._ft = _bt_ctf_field_type_variant_create(
2271 enum_tag._ft,
2272 str(tag_name))
2273 super().__init__()
2274
2275 """
2276 Get the variant's tag name.
2277 """
2278 @property
2279 def tag_name(self):
2280 ret = _bt_ctf_field_type_variant_get_tag_name(self._ft)
2281 if ret is None:
2282 raise TypeError("Could not get Variant tag name")
2283 return ret
2284
2285 """
2286 Get the variant's tag type.
2287 """
2288 @property
2289 def tag_type(self):
2290 ret = _bt_ctf_field_type_variant_get_tag_type(self._ft)
2291 if ret is None:
2292 raise TypeError("Could not get Variant tag type")
2293 return CTFWriter.FieldDeclaration._create_field_declaration_from_native_instance(
2294 ret)
2295
2296 """
2297 Add a field of type "field_type" to the variant.
2298 """
2299
2300 def add_field(self, field_type, field_name):
2301 ret = _bt_ctf_field_type_variant_add_field(
2302 self._ft,
2303 field_type._ft,
2304 str(field_name))
2305 if ret < 0:
2306 raise ValueError("Could not add field to variant.")
2307
2308 """
2309 Generator returning the variant's field as tuples of (field name, field declaration).
2310 """
2311 @property
2312 def fields(self):
2313 count = _bt_ctf_field_type_variant_get_field_count(self._ft)
2314 if count < 0:
2315 raise TypeError("Could not get Variant field count")
2316
2317 for i in range(count):
2318 field_name = _bt_python_ctf_field_type_variant_get_field_name(
2319 self._ft,
2320 i)
2321 if field_name is None:
2322 raise TypeError(
2323 "Could not get Variant field name at index {}".format(i))
2324
2325 field_type_native = _bt_python_ctf_field_type_variant_get_field_type(
2326 self._ft,
2327 i)
2328 if field_type_native is None:
2329 raise TypeError(
2330 "Could not get Variant field type at index {}".format(i))
2331
2332 field_type = CTFWriter.FieldDeclaration._create_field_declaration_from_native_instance(
2333 field_type_native)
2334 yield (field_name, field_type)
2335
2336 """
2337 Get a field declaration by name (FieldDeclaration).
2338 """
2339
2340 def get_field_by_name(self, name):
2341 field_type_native = _bt_ctf_field_type_variant_get_field_type_by_name(
2342 self._ft,
2343 name)
2344 if field_type_native is None:
2345 raise TypeError(
2346 "Could not find Variant field with name {}".format(name))
2347
2348 return CTFWriter.FieldDeclaration._create_field_declaration_from_native_instance(
2349 field_type_native)
2350
2351 """
2352 Get a field declaration from tag (EnumerationField).
2353 """
2354
2355 def get_field_from_tag(self, tag):
2356 field_type_native = _bt_ctf_field_type_variant_get_field_type_from_tag(
2357 self._ft,
2358 tag._f)
2359 if field_type_native is None:
2360 raise TypeError(
2361 "Could not find Variant field with tag value {}".format(
2362 tag.value))
2363
2364 return CTFWriter.FieldDeclaration._create_field_declaration_from_native_instance(
2365 field_type_native)
2366
2367 class ArrayFieldDeclaration(FieldDeclaration):
2368
2369 """
2370 Create a new array field declaration.
2371 """
2372
2373 def __init__(self, element_type, length):
2374 self._ft = _bt_ctf_field_type_array_create(
2375 element_type._ft,
2376 length)
2377 super().__init__()
2378
2379 """
2380 Get the array's element type.
2381 """
2382 @property
2383 def element_type(self):
2384 ret = _bt_ctf_field_type_array_get_element_type(self._ft)
2385 if ret is None:
2386 raise TypeError("Could not get Array element type")
2387 return CTFWriter.FieldDeclaration._create_field_declaration_from_native_instance(
2388 ret)
2389
2390 """
2391 Get the array's length.
2392 """
2393 @property
2394 def length(self):
2395 ret = _bt_ctf_field_type_array_get_length(self._ft)
2396 if ret < 0:
2397 raise TypeError("Could not get Array length")
2398 return ret
2399
2400 class SequenceFieldDeclaration(FieldDeclaration):
2401
2402 """
2403 Create a new sequence field declaration.
2404 """
2405
2406 def __init__(self, element_type, length_field_name):
2407 self._ft = _bt_ctf_field_type_sequence_create(
2408 element_type._ft,
2409 str(length_field_name))
2410 super().__init__()
2411
2412 """
2413 Get the sequence's element type.
2414 """
2415 @property
2416 def element_type(self):
2417 ret = _bt_ctf_field_type_sequence_get_element_type(self._ft)
2418 if ret is None:
2419 raise TypeError("Could not get Sequence element type")
2420 return CTFWriter.FieldDeclaration._create_field_declaration_from_native_instance(
2421 ret)
2422
2423 """
2424 Get the sequence's length field name.
2425 """
2426 @property
2427 def length_field_name(self):
2428 ret = _bt_ctf_field_type_sequence_get_length_field_name(self._ft)
2429 if ret is None:
2430 raise TypeError("Could not get Sequence length field name")
2431 return ret
2432
2433 class StringFieldDeclaration(FieldDeclaration):
2434
2435 """
2436 Create a new string field declaration.
2437 """
2438
2439 def __init__(self):
2440 self._ft = _bt_ctf_field_type_string_create()
2441 super().__init__()
2442
2443 """
2444 Get a string declaration's encoding (a constant from the CTFStringEncoding class).
2445 """
2446 @property
2447 def encoding(self):
2448 return _bt_ctf_field_type_string_get_encoding(self._ft)
2449
2450 """
2451 Set a string declaration's encoding. Must be a constant from the CTFStringEncoding class.
2452 """
2453 @encoding.setter
2454 def encoding(self, encoding):
2455 ret = _bt_ctf_field_type_string_set_encoding(self._ft, encoding)
2456 if ret < 0:
2457 raise ValueError("Could not set string encoding.")
2458
2459 """
2460 Create an instance of a field.
2461 """
2462 @staticmethod
2463 def create_field(field_type):
2464 if field_type is None or not isinstance(
2465 field_type, CTFWriter.FieldDeclaration):
2466 raise TypeError(
2467 "Invalid field_type. Type must be a FieldDeclaration-derived class.")
2468
2469 if isinstance(field_type, CTFWriter.IntegerFieldDeclaration):
2470 return CTFWriter.IntegerField(field_type)
2471 elif isinstance(field_type, CTFWriter.EnumerationFieldDeclaration):
2472 return CTFWriter.EnumerationField(field_type)
2473 elif isinstance(field_type, CTFWriter.FloatFieldDeclaration):
2474 return CTFWriter.FloatFieldingPoint(field_type)
2475 elif isinstance(field_type, CTFWriter.StructureFieldDeclaration):
2476 return CTFWriter.StructureField(field_type)
2477 elif isinstance(field_type, CTFWriter.VariantFieldDeclaration):
2478 return CTFWriter.VariantField(field_type)
2479 elif isinstance(field_type, CTFWriter.ArrayFieldDeclaration):
2480 return CTFWriter.ArrayField(field_type)
2481 elif isinstance(field_type, CTFWriter.SequenceFieldDeclaration):
2482 return CTFWriter.SequenceField(field_type)
2483 elif isinstance(field_type, CTFWriter.StringFieldDeclaration):
2484 return CTFWriter.StringField(field_type)
2485
2486 class Field:
2487
2488 """
2489 Base class, do not instantiate.
2490 """
2491
2492 def __init__(self, field_type):
2493 if not isinstance(field_type, CTFWriter.FieldDeclaration):
2494 raise TypeError("Invalid field_type argument.")
2495
2496 self._f = _bt_ctf_field_create(field_type._ft)
2497 if self._f is None:
2498 raise ValueError("Field creation failed.")
2499
2500 def __del__(self):
2501 _bt_ctf_field_put(self._f)
2502
2503 @staticmethod
2504 def _create_field_from_native_instance(native_field_instance):
2505 type_dict = {
2506 CTFTypeId.INTEGER: CTFWriter.IntegerField,
2507 CTFTypeId.FLOAT: CTFWriter.FloatFieldingPoint,
2508 CTFTypeId.ENUM: CTFWriter.EnumerationField,
2509 CTFTypeId.STRING: CTFWriter.StringField,
2510 CTFTypeId.STRUCT: CTFWriter.StructureField,
2511 CTFTypeId.VARIANT: CTFWriter.VariantField,
2512 CTFTypeId.ARRAY: CTFWriter.ArrayField,
2513 CTFTypeId.SEQUENCE: CTFWriter.SequenceField
2514 }
2515
2516 field_type = _bt_python_get_field_type(native_field_instance)
2517 if field_type == CTFTypeId.UNKNOWN:
2518 raise TypeError("Invalid field instance")
2519
2520 field = CTFWriter.Field.__new__(CTFWriter.Field)
2521 field._f = native_field_instance
2522 field.__class__ = type_dict[field_type]
2523 return field
2524
2525 @property
2526 def declaration(self):
2527 native_field_type = _bt_ctf_field_get_type(self._f)
2528 if native_field_type is None:
2529 raise TypeError("Invalid field instance")
2530 return CTFWriter.FieldDeclaration._create_field_declaration_from_native_instance(
2531 native_field_type)
2532
2533 class IntegerField(Field):
2534
2535 """
2536 Get an integer field's value.
2537 """
2538 @property
2539 def value(self):
2540 signedness = _bt_python_field_integer_get_signedness(self._f)
2541 if signedness < 0:
2542 raise TypeError("Invalid integer instance.")
2543
2544 if signedness == 0:
2545 ret, value = _bt_ctf_field_unsigned_integer_get_value(self._f)
2546 else:
2547 ret, value = _bt_ctf_field_signed_integer_get_value(self._f)
2548
2549 if ret < 0:
2550 raise ValueError("Could not get integer field value.")
2551 return value
2552
2553 """
2554 Set an integer field's value.
2555 """
2556 @value.setter
2557 def value(self, value):
2558 if not isinstance(value, int):
2559 raise TypeError("IntegerField's value must be an int")
2560
2561 signedness = _bt_python_field_integer_get_signedness(self._f)
2562 if signedness < 0:
2563 raise TypeError("Invalid integer instance.")
2564
2565 if signedness == 0:
2566 ret = _bt_ctf_field_unsigned_integer_set_value(self._f, value)
2567 else:
2568 ret = _bt_ctf_field_signed_integer_set_value(self._f, value)
2569
2570 if ret < 0:
2571 raise ValueError("Could not set integer field value.")
2572
2573 class EnumerationField(Field):
2574
2575 """
2576 Return the enumeration's underlying container field (an integer field).
2577 """
2578 @property
2579 def container(self):
2580 container = CTFWriter.IntegerField.__new__(CTFWriter.IntegerField)
2581 container._f = _bt_ctf_field_enumeration_get_container(self._f)
2582 if container._f is None:
2583 raise TypeError("Invalid enumeration field type.")
2584 return container
2585
2586 """
2587 Get the enumeration field's mapping name.
2588 """
2589 @property
2590 def value(self):
2591 value = _bt_ctf_field_enumeration_get_mapping_name(self._f)
2592 if value is None:
2593 raise ValueError("Could not get enumeration's mapping name.")
2594 return value
2595
2596 """
2597 Set the enumeration field's value. Must be an integer as mapping names
2598 may be ambiguous.
2599 """
2600 @value.setter
2601 def value(self, value):
2602 if not isinstance(value, int):
2603 raise TypeError("EnumerationField value must be an int")
2604 self.container.value = value
2605
2606 class FloatFieldingPoint(Field):
2607
2608 """
2609 Get a floating point field's value.
2610 """
2611 @property
2612 def value(self):
2613 ret, value = _bt_ctf_field_floating_point_get_value(self._f)
2614 if ret < 0:
2615 raise ValueError("Could not get floating point field value.")
2616 return value
2617
2618 """
2619 Set a floating point field's value.
2620 """
2621 @value.setter
2622 def value(self, value):
2623 if not isinstance(value, int) and not isinstance(value, float):
2624 raise TypeError("Value must be either a float or an int")
2625
2626 ret = _bt_ctf_field_floating_point_set_value(self._f, float(value))
2627 if ret < 0:
2628 raise ValueError("Could not set floating point field value.")
2629
2630 class StructureField(Field):
2631
2632 """
2633 Get the structure's field corresponding to the provided field name.
2634 """
2635
2636 def field(self, field_name):
2637 native_instance = _bt_ctf_field_structure_get_field(
2638 self._f,
2639 str(field_name))
2640 if native_instance is None:
2641 raise ValueError("Invalid field_name provided.")
2642 return CTFWriter.Field._create_field_from_native_instance(
2643 native_instance)
2644
2645 class VariantField(Field):
2646
2647 """
2648 Return the variant's selected field. The "tag" field is the selector enum field.
2649 """
2650
2651 def field(self, tag):
2652 native_instance = _bt_ctf_field_variant_get_field(self._f, tag._f)
2653 if native_instance is None:
2654 raise ValueError("Invalid tag provided.")
2655 return CTFWriter.Field._create_field_from_native_instance(
2656 native_instance)
2657
2658 class ArrayField(Field):
2659
2660 """
2661 Return the array's field at position "index".
2662 """
2663
2664 def field(self, index):
2665 native_instance = _bt_ctf_field_array_get_field(self._f, index)
2666 if native_instance is None:
2667 raise IndexError("Invalid index provided.")
2668 return CTFWriter.Field._create_field_from_native_instance(
2669 native_instance)
2670
2671 class SequenceField(Field):
2672
2673 """
2674 Get the sequence's length field (IntegerField).
2675 """
2676 @property
2677 def length(self):
2678 native_instance = _bt_ctf_field_sequence_get_length(self._f)
2679 if native_instance is None:
2680 length = -1
2681 return CTFWriter.Field._create_field_from_native_instance(
2682 native_instance)
2683
2684 """
2685 Set the sequence's length field (IntegerField).
2686 """
2687 @length.setter
2688 def length(self, length_field):
2689 if not isinstance(length_field, CTFWriter.IntegerField):
2690 raise TypeError("Invalid length field.")
2691 if length_field.declaration.signed:
2692 raise TypeError("Sequence field length must be unsigned")
2693 ret = _bt_ctf_field_sequence_set_length(self._f, length_field._f)
2694 if ret < 0:
2695 raise ValueError("Could not set sequence length.")
2696
2697 """
2698 Return the sequence's field at position "index".
2699 """
2700
2701 def field(self, index):
2702 native_instance = _bt_ctf_field_sequence_get_field(self._f, index)
2703 if native_instance is None:
2704 raise ValueError("Could not get sequence element at index.")
2705 return CTFWriter.Field._create_field_from_native_instance(
2706 native_instance)
2707
2708 class StringField(Field):
2709
2710 """
2711 Get a string field's value.
2712 """
2713 @property
2714 def value(self):
2715 return _bt_ctf_field_string_get_value(self._f)
2716
2717 """
2718 Set a string field's value.
2719 """
2720 @value.setter
2721 def value(self, value):
2722 ret = _bt_ctf_field_string_set_value(self._f, str(value))
2723 if ret < 0:
2724 raise ValueError("Could not set string field value.")
2725
2726 class EventClass:
2727
2728 """
2729 Create a new event class of the given name.
2730 """
2731
2732 def __init__(self, name):
2733 self._ec = _bt_ctf_event_class_create(name)
2734 if self._ec is None:
2735 raise ValueError("Event class creation failed.")
2736
2737 def __del__(self):
2738 _bt_ctf_event_class_put(self._ec)
2739
2740 """
2741 Add a field of type "field_type" to the event class.
2742 """
2743
2744 def add_field(self, field_type, field_name):
2745 ret = _bt_ctf_event_class_add_field(
2746 self._ec,
2747 field_type._ft,
2748 str(field_name))
2749 if ret < 0:
2750 raise ValueError("Could not add field to event class.")
2751
2752 """
2753 Get the event class' name.
2754 """
2755 @property
2756 def name(self):
2757 name = _bt_ctf_event_class_get_name(self._ec)
2758 if name is None:
2759 raise TypeError("Could not get EventClass name")
2760 return name
2761
2762 """
2763 Get the event class' id. Returns a negative value if unset.
2764 """
2765 @property
2766 def id(self):
2767 id = _bt_ctf_event_class_get_id(self._ec)
2768 if id < 0:
2769 raise TypeError("Could not get EventClass id")
2770 return id
2771
2772 """
2773 Set the event class' id. Throws a TypeError if the event class
2774 is already registered to a stream class.
2775 """
2776 @id.setter
2777 def id(self, id):
2778 ret = _bt_ctf_event_class_set_id(self._ec, id)
2779 if ret < 0:
2780 raise TypeError(
2781 "Can't change an Event Class's id after it has been assigned to a stream class")
2782
2783 """
2784 Get the event class' stream class. Returns None if unset.
2785 """
2786 @property
2787 def stream_class(self):
2788 stream_class_native = _bt_ctf_event_class_get_stream_class(
2789 self._ec)
2790 if stream_class_native is None:
2791 return None
2792 stream_class = CTFWriter.StreamClass.__new__(CTFWriter.StreamClass)
2793 stream_class._sc = stream_class_native
2794 return stream_class
2795
2796 """
2797 Generator returning the event class' fields as tuples of (field name, field declaration).
2798 """
2799 @property
2800 def fields(self):
2801 count = _bt_ctf_event_class_get_field_count(self._ec)
2802 if count < 0:
2803 raise TypeError("Could not get EventClass' field count")
2804
2805 for i in range(count):
2806 field_name = _bt_python_ctf_event_class_get_field_name(
2807 self._ec,
2808 i)
2809 if field_name is None:
2810 raise TypeError(
2811 "Could not get EventClass' field name at index {}".format(i))
2812
2813 field_type_native = _bt_python_ctf_event_class_get_field_type(
2814 self._ec,
2815 i)
2816 if field_type_native is None:
2817 raise TypeError(
2818 "Could not get EventClass' field type at index {}".format(i))
2819
2820 field_type = CTFWriter.FieldDeclaration._create_field_declaration_from_native_instance(
2821 field_type_native)
2822 yield (field_name, field_type)
2823
2824 """
2825 Get a field declaration by name (FieldDeclaration).
2826 """
2827
2828 def get_field_by_name(self, name):
2829 field_type_native = _bt_ctf_event_class_get_field_by_name(
2830 self._ec,
2831 name)
2832 if field_type_native is None:
2833 raise TypeError(
2834 "Could not find EventClass field with name {}".format(name))
2835 return CTFWriter.FieldDeclaration._create_field_declaration_from_native_instance(
2836 field_type_native)
2837
2838 class Event:
2839
2840 """
2841 Create a new event of the given event class.
2842 """
2843
2844 def __init__(self, event_class):
2845 if not isinstance(event_class, CTFWriter.EventClass):
2846 raise TypeError("Invalid event_class argument.")
2847
2848 self._e = _bt_ctf_event_create(event_class._ec)
2849 if self._e is None:
2850 raise ValueError("Event creation failed.")
2851
2852 def __del__(self):
2853 _bt_ctf_event_put(self._e)
2854
2855 """
2856 Get the event's class.
2857 """
2858 @property
2859 def event_class(self):
2860 event_class_native = _bt_ctf_event_get_class(self._e)
2861 if event_class_native is None:
2862 return None
2863 event_class = CTFWriter.EventClass.__new__(CTFWriter.EventClass)
2864 event_class._ec = event_class_native
2865 return event_class
2866
2867 """
2868 Get a clock from event. Returns None if the event's class
2869 is not registered to a stream class.
2870 """
2871
2872 def clock(self):
2873 clock_instance = _bt_ctf_event_get_clock(self._e)
2874 if clock_instance is None:
2875 return None
2876 clock = CTFWriter.Clock.__new__(CTFWriter.Clock)
2877 clock._c = clock_instance
2878 return clock
2879
2880 """
2881 Get a field from event.
2882 """
2883
2884 def payload(self, field_name):
2885 native_instance = _bt_ctf_event_get_payload(
2886 self._e,
2887 str(field_name))
2888 if native_instance is None:
2889 raise ValueError("Could not get event payload.")
2890 return CTFWriter.Field._create_field_from_native_instance(
2891 native_instance)
2892
2893 """
2894 Set a manually created field as an event's payload.
2895 """
2896
2897 def set_payload(self, field_name, value_field):
2898 if not isinstance(value, CTFWriter.Field):
2899 raise TypeError("Invalid value type.")
2900 ret = _bt_ctf_event_set_payload(
2901 self._e,
2902 str(field_name),
2903 value_field._f)
2904 if ret < 0:
2905 raise ValueError("Could not set event field payload.")
2906
2907 class StreamClass:
2908
2909 """
2910 Create a new stream class of the given name.
2911 """
2912
2913 def __init__(self, name):
2914 self._sc = _bt_ctf_stream_class_create(name)
2915 if self._sc is None:
2916 raise ValueError("Stream class creation failed.")
2917
2918 def __del__(self):
2919 _bt_ctf_stream_class_put(self._sc)
2920
2921 """
2922 Get a stream class' name.
2923 """
2924 @property
2925 def name(self):
2926 name = _bt_ctf_stream_class_get_name(self._sc)
2927 if name is None:
2928 raise TypeError("Could not get StreamClass name")
2929 return name
2930
2931 """
2932 Get a stream class' clock.
2933 """
2934 @property
2935 def clock(self):
2936 clock_instance = _bt_ctf_stream_class_get_clock(self._sc)
2937 if clock_instance is None:
2938 return None
2939 clock = CTFWriter.Clock.__new__(CTFWriter.Clock)
2940 clock._c = clock_instance
2941 return clock
2942
2943 """
2944 Assign a clock to a stream class.
2945 """
2946 @clock.setter
2947 def clock(self, clock):
2948 if not isinstance(clock, CTFWriter.Clock):
2949 raise TypeError("Invalid clock type.")
2950
2951 ret = _bt_ctf_stream_class_set_clock(self._sc, clock._c)
2952 if ret < 0:
2953 raise ValueError("Could not set stream class clock.")
2954
2955 """
2956 Get a stream class' id.
2957 """
2958 @property
2959 def id(self):
2960 ret = _bt_ctf_stream_class_get_id(self._sc)
2961 if ret < 0:
2962 raise TypeError("Could not get StreamClass id")
2963 return ret
2964
2965 """
2966 Assign an id to a stream class.
2967 """
2968 @id.setter
2969 def id(self, id):
2970 ret = _bt_ctf_stream_class_set_id(self._sc, id)
2971 if ret < 0:
2972 raise TypeError("Could not set stream class id.")
2973
2974 """
2975 Generator returning the stream class' event classes.
2976 """
2977 @property
2978 def event_classes(self):
2979 count = _bt_ctf_stream_class_get_event_class_count(self._sc)
2980 if count < 0:
2981 raise TypeError("Could not get StreamClass' event class count")
2982
2983 for i in range(count):
2984 event_class_native = _bt_ctf_stream_class_get_event_class(
2985 self._sc,
2986 i)
2987 if event_class_native is None:
2988 raise TypeError(
2989 "Could not get StreamClass' event class at index {}".format(i))
2990
2991 event_class = CTFWriter.EventClass.__new__(
2992 CTFWriter.EventClass)
2993 event_class._ec = event_class_native
2994 yield event_class
2995
2996 """
2997 Add an event class to a stream class. New events can be added even after a
2998 stream has been instantiated and events have been appended. However, a stream
2999 will not accept events of a class that has not been added to the stream
3000 class beforehand.
3001 """
3002
3003 def add_event_class(self, event_class):
3004 if not isinstance(event_class, CTFWriter.EventClass):
3005 raise TypeError("Invalid event_class type.")
3006
3007 ret = _bt_ctf_stream_class_add_event_class(
3008 self._sc,
3009 event_class._ec)
3010 if ret < 0:
3011 raise ValueError("Could not add event class.")
3012
3013 """
3014 Get the StreamClass' packet context type (StructureFieldDeclaration)
3015 """
3016 @property
3017 def packet_context_type(self):
3018 field_type_native = _bt_ctf_stream_class_get_packet_context_type(
3019 self._sc)
3020 if field_type_native is None:
3021 raise ValueError("Invalid StreamClass")
3022 field_type = CTFWriter.FieldDeclaration._create_field_declaration_from_native_instance(
3023 field_type_native)
3024 return field_type
3025
3026 """
3027 Set a StreamClass' packet context type. Must be of type
3028 StructureFieldDeclaration.
3029 """
3030 @packet_context_type.setter
3031 def packet_context_type(self, field_type):
3032 if not isinstance(field_type, CTFWriter.StructureFieldDeclaration):
3033 raise TypeError(
3034 "field_type argument must be of type StructureFieldDeclaration.")
3035 ret = _bt_ctf_stream_class_set_packet_context_type(
3036 self._sc,
3037 field_type._ft)
3038 if ret < 0:
3039 raise ValueError("Failed to set packet context type.")
3040
3041 class Stream:
3042
3043 """
3044 Create a stream of the given class.
3045 """
3046
3047 def __init__(self, stream_class):
3048 if not isinstance(stream_class, CTFWriter.StreamClass):
3049 raise TypeError(
3050 "Invalid stream_class argument must be of type StreamClass.")
3051
3052 self._s = _bt_ctf_stream_create(stream_class._sc)
3053 if self._s is None:
3054 raise ValueError("Stream creation failed.")
3055
3056 def __del__(self):
3057 _bt_ctf_stream_put(self._s)
3058
3059 """
3060 Get a stream's discarded event count.
3061 """
3062 @property
3063 def discarded_events(self):
3064 ret, count = _bt_ctf_stream_get_discarded_events_count(self._s)
3065 if ret < 0:
3066 raise ValueError(
3067 "Could not get the stream's discarded events count")
3068 return count
3069
3070 """
3071 Increase the current packet's discarded event count.
3072 """
3073
3074 def append_discarded_events(self, event_count):
3075 _bt_ctf_stream_append_discarded_events(self._s, event_count)
3076
3077 """
3078 Append "event" to the stream's current packet. The stream's associated clock
3079 will be sampled during this call. The event shall not be modified after
3080 being appended to a stream.
3081 """
3082
3083 def append_event(self, event):
3084 ret = _bt_ctf_stream_append_event(self._s, event._e)
3085 if ret < 0:
3086 raise ValueError("Could not append event to stream.")
3087
3088 """
3089 Get a Stream's packet context field (a StructureField).
3090 """
3091 @property
3092 def packet_context(self):
3093 native_field = _bt_ctf_stream_get_packet_context(self._s)
3094 if native_field is None:
3095 raise ValueError("Invalid Stream.")
3096 return CTFWriter.Field._create_field_from_native_instance(
3097 native_field)
3098
3099 """
3100 Set a Stream's packet context field (must be a StructureField).
3101 """
3102 @packet_context.setter
3103 def packet_context(self, field):
3104 if not isinstance(field, CTFWriter.StructureField):
3105 raise TypeError(
3106 "Argument field must be of type StructureField")
3107 ret = _bt_ctf_stream_set_packet_context(self._s, field._f)
3108 if ret < 0:
3109 raise ValueError("Invalid packet context field.")
3110
3111 """
3112 The stream's current packet's events will be flushed to disk. Events
3113 subsequently appended to the stream will be added to a new packet.
3114 """
3115
3116 def flush(self):
3117 ret = _bt_ctf_stream_flush(self._s)
3118 if ret < 0:
3119 raise ValueError("Could not flush stream.")
3120
3121 class Writer:
3122
3123 """
3124 Create a new writer that will produce a trace in the given path.
3125 """
3126
3127 def __init__(self, path):
3128 self._w = _bt_ctf_writer_create(path)
3129 if self._w is None:
3130 raise ValueError("Writer creation failed.")
3131
3132 def __del__(self):
3133 _bt_ctf_writer_put(self._w)
3134
3135 """
3136 Create a new stream instance and register it to the writer.
3137 """
3138
3139 def create_stream(self, stream_class):
3140 if not isinstance(stream_class, CTFWriter.StreamClass):
3141 raise TypeError("Invalid stream_class type.")
3142
3143 stream = CTFWriter.Stream.__new__(CTFWriter.Stream)
3144 stream._s = _bt_ctf_writer_create_stream(self._w, stream_class._sc)
3145 return stream
3146
3147 """
3148 Add an environment field to the trace.
3149 """
3150
3151 def add_environment_field(self, name, value):
3152 ret = _bt_ctf_writer_add_environment_field(
3153 self._w,
3154 str(name),
3155 str(value))
3156 if ret < 0:
3157 raise ValueError("Could not add environment field to trace.")
3158
3159 """
3160 Add a clock to the trace. Clocks assigned to stream classes must be
3161 registered to the writer.
3162 """
3163
3164 def add_clock(self, clock):
3165 ret = _bt_ctf_writer_add_clock(self._w, clock._c)
3166 if ret < 0:
3167 raise ValueError("Could not add clock to Writer.")
3168
3169 """
3170 Get the trace's TSDL meta-data.
3171 """
3172 @property
3173 def metadata(self):
3174 return _bt_ctf_writer_get_metadata_string(self._w)
3175
3176 """
3177 Flush the trace's metadata to the metadata file.
3178 """
3179
3180 def flush_metadata(self):
3181 _bt_ctf_writer_flush_metadata(self._w)
3182
3183 """
3184 Get the trace's byte order. Must be a constant from the ByteOrder
3185 class.
3186 """
3187 @property
3188 def byte_order(self):
3189 raise NotImplementedError("Getter not implemented.")
3190
3191 """
3192 Set the trace's byte order. Must be a constant from the ByteOrder
3193 class. Defaults to BYTE_ORDER_NATIVE, the host machine's endianness.
3194 """
3195 @byte_order.setter
3196 def byte_order(self, byte_order):
3197 ret = _bt_ctf_writer_set_byte_order(self._w, byte_order)
3198 if ret < 0:
3199 raise ValueError("Could not set trace's byte order.")
3200
3201 %}
This page took 0.122609 seconds and 4 git commands to generate.