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