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