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