Fix (Python bindings): Return a string if a sequence's element are chars
[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.
20 */
21
22
23%define DOCSTRING
24"BABELTRACE_VERSION_STR
25
26Babeltrace is a trace viewer and converter reading and writing the
27Common Trace Format (CTF). Its main use is to pretty-print CTF
28traces into a human-readable text output.
29
74ea15ad 30To use this module, the first step is to create a TraceCollection and add a
24a3136a
DS
31trace to it."
32%enddef
33
34%module(docstring=DOCSTRING) babeltrace
35
36%include "typemaps.i"
37%{
38#define SWIG_FILE_WITH_INIT
39#include <babeltrace/babeltrace.h>
40#include <babeltrace/babeltrace-internal.h>
41#include <babeltrace/trace-handle.h>
42#include <babeltrace/trace-handle-internal.h>
43#include <babeltrace/context.h>
44#include <babeltrace/context-internal.h>
45#include <babeltrace/iterator.h>
46#include <babeltrace/iterator-internal.h>
47#include <babeltrace/format.h>
48#include <babeltrace/list.h>
24a3136a
DS
49#include <babeltrace/types.h>
50#include <babeltrace/ctf/iterator.h>
51#include "python-complements.h"
ec8c88d7
JG
52#include <babeltrace/ctf-writer/clock.h>
53#include <babeltrace/ctf-writer/event-fields.h>
54#include <babeltrace/ctf-writer/event-types.h>
55#include <babeltrace/ctf-writer/event.h>
56#include <babeltrace/ctf-writer/stream.h>
57#include <babeltrace/ctf-writer/writer.h>
24a3136a
DS
58%}
59
60typedef unsigned long long uint64_t;
61typedef long long int64_t;
62typedef int bt_intern_str;
5792eb34 63typedef int64_t ssize_t;
24a3136a 64
cebae8c3
JG
65/* =================================================================
66 PYTHON-COMPLEMENTS.H
67 ¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯
68*/
69
70FILE *_bt_file_open(char *file_path, char *mode);
71void _bt_file_close(FILE *fp);
72struct bt_definition **_bt_python_field_listcaller(
73 const struct bt_ctf_event *ctf_event,
74 const struct bt_definition *scope,
75 unsigned int *OUTPUT);
76struct bt_definition *_bt_python_field_one_from_list(
77 struct bt_definition **list, int index);
78struct bt_ctf_event_decl **_bt_python_event_decl_listcaller(
79 int handle_id,
80 struct bt_context *ctx,
81 unsigned int *OUTPUT);
82struct bt_ctf_event_decl *_bt_python_decl_one_from_list(
83 struct bt_ctf_event_decl **list, int index);
84struct bt_ctf_field_decl **_by_python_field_decl_listcaller(
85 struct bt_ctf_event_decl *event_decl,
86 enum bt_ctf_scope scope,
87 unsigned int *OUTPUT);
88struct bt_ctf_field_decl *_bt_python_field_decl_one_from_list(
89 struct bt_ctf_field_decl **list, int index);
90struct definition_array *_bt_python_get_array_from_def(
91 struct bt_definition *field);
92struct definition_sequence *_bt_python_get_sequence_from_def(
93 struct bt_definition *field);
5792eb34
JG
94struct bt_declaration *_bt_python_get_array_element_declaration(
95 struct bt_declaration *field);
e11b8d3a
JG
96struct bt_declaration *_bt_python_get_sequence_element_declaration(
97 struct bt_declaration *field);
5792eb34 98const char *_bt_python_get_array_string(struct bt_definition *field);
e11b8d3a 99const char *_bt_python_get_sequence_string(struct bt_definition *field);
ec8c88d7
JG
100int _bt_python_field_integer_get_signedness(const struct bt_ctf_field *field);
101enum ctf_type_id _bt_python_get_field_type(const struct bt_ctf_field *field);
cebae8c3 102
24a3136a
DS
103/* =================================================================
104 CONTEXT.H, CONTEXT-INTERNAL.H
105 ¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯
106*/
107
108%rename("_bt_context_create") bt_context_create(void);
109%rename("_bt_context_add_trace") bt_context_add_trace(
110 struct bt_context *ctx, const char *path, const char *format,
2c0df204
XH
111 void (*packet_seek)(struct bt_stream_pos *pos, size_t index, int whence),
112 struct bt_mmap_stream_list *stream_list, FILE *metadata);
24a3136a
DS
113%rename("_bt_context_remove_trace") bt_context_remove_trace(
114 struct bt_context *ctx, int trace_id);
115%rename("_bt_context_get") bt_context_get(struct bt_context *ctx);
116%rename("_bt_context_put") bt_context_put(struct bt_context *ctx);
117%rename("_bt_ctf_event_get_context") bt_ctf_event_get_context(
118 const struct bt_ctf_event *event);
119
120struct bt_context *bt_context_create(void);
121int bt_context_add_trace(struct bt_context *ctx, const char *path, const char *format,
2c0df204
XH
122 void (*packet_seek)(struct bt_stream_pos *pos, size_t index, int whence),
123 struct bt_mmap_stream_list *stream_list, FILE *metadata);
24a3136a
DS
124void bt_context_remove_trace(struct bt_context *ctx, int trace_id);
125void bt_context_get(struct bt_context *ctx);
126void bt_context_put(struct bt_context *ctx);
127struct bt_context *bt_ctf_event_get_context(const struct bt_ctf_event *event);
128
74ea15ad 129// class TraceCollection to prevent direct access to struct bt_context
24a3136a 130%pythoncode%{
74ea15ad 131class TraceCollection:
24a3136a 132 """
74ea15ad 133 The TraceCollection is the object that contains all currently opened traces.
24a3136a
DS
134 """
135
136 def __init__(self):
74ea15ad 137 self._tc = _bt_context_create()
24a3136a
DS
138
139 def __del__(self):
74ea15ad 140 _bt_context_put(self._tc)
24a3136a 141
74ea15ad 142 def add_trace(self, path, format_str):
24a3136a 143 """
74ea15ad 144 Add a trace by path to the TraceCollection.
24a3136a
DS
145
146 Open a trace.
147
148 path is the path to the trace, it is not recursive.
149 If "path" is None, stream_list is used instead as a list
150 of mmap streams to open for the trace.
151
152 format is a string containing the format name in which the trace was
153 produced.
154
24a3136a
DS
155 Return: the corresponding TraceHandle on success or None on error.
156 """
464425e1 157 ret = _bt_context_add_trace(self._tc, path, format_str, None, None, None)
24a3136a
DS
158 if ret < 0:
159 return None
160
161 th = TraceHandle.__new__(TraceHandle)
162 th._id = ret
464425e1 163 th._trace_collection = self
24a3136a
DS
164 return th
165
166 def add_traces_recursive(self, path, format_str):
167 """
168 Open a trace recursively.
169
170 Find each trace present in the subdirectory starting from the given
74ea15ad 171 path, and add them to the TraceCollection.
24a3136a
DS
172
173 Return a dict of TraceHandle instances (the full path is the key).
174 Return None on error.
175 """
176
177 import os
178
179 trace_handles = {}
180
181 noTrace = True
182 error = False
183
184 for fullpath, dirs, files in os.walk(path):
185 if "metadata" in files:
186 trace_handle = self.add_trace(fullpath, format_str)
187 if trace_handle is None:
188 error = True
189 continue
190
191 trace_handles[fullpath] = trace_handle
192 noTrace = False
193
194 if noTrace and error:
195 return None
196 return trace_handles
197
198 def remove_trace(self, trace_handle):
199 """
74ea15ad 200 Remove a trace from the TraceCollection.
24a3136a
DS
201 Effectively closing the trace.
202 """
203 try:
74ea15ad 204 _bt_context_remove_trace(self._tc, trace_handle._id)
24a3136a
DS
205 except AttributeError:
206 raise TypeError("in remove_trace, "
207 "argument 2 must be a TraceHandle instance")
74ea15ad
JG
208
209 @property
210 def events(self):
211 """
212 Generator function to iterate over the events of open in the current
213 TraceCollection.
214 """
215 begin_pos_ptr = _bt_iter_pos()
216 end_pos_ptr = _bt_iter_pos()
217 begin_pos_ptr.type = SEEK_BEGIN
218 end_pos_ptr.type = SEEK_LAST
219
220 for event in self._events(begin_pos_ptr, end_pos_ptr):
221 yield event
222
223 def events_timestamps(self, timestamp_begin, timestamp_end):
224 """
225 Generator function to iterate over the events of open in the current
226 TraceCollection from timestamp_begin to timestamp_end.
227 """
228 begin_pos_ptr = _bt_iter_pos()
229 end_pos_ptr = _bt_iter_pos()
230 begin_pos_ptr.type = end_pos_ptr.type = SEEK_TIME
231 begin_pos_ptr.u.seek_time = timestamp_begin
232 end_pos_ptr.u.seek_time = timestamp_end
233
234 for event in self._events(begin_pos_ptr, end_pos_ptr):
235 yield event
236
237 @property
238 def timestamp_begin(self):
239 pos_ptr = _bt_iter_pos()
240 pos_ptr.type = SEEK_BEGIN
241 return self._timestamp_at_pos(pos_ptr)
242
243 @property
244 def timestamp_end(self):
245 pos_ptr = _bt_iter_pos()
246 pos_ptr.type = SEEK_LAST
247 return self._timestamp_at_pos(pos_ptr)
248
249 def _timestamp_at_pos(self, pos_ptr):
250 ctf_it_ptr = _bt_ctf_iter_create(self._tc, pos_ptr, pos_ptr)
251 if ctf_it_ptr is None:
252 raise NotImplementedError("Creation of multiple iterators is unsupported.")
253 ev_ptr = _bt_ctf_iter_read_event(ctf_it_ptr)
254 _bt_ctf_iter_destroy(ctf_it_ptr)
255 if ev_ptr is None:
256 return None;
257
258 def _events(self, begin_pos_ptr, end_pos_ptr):
259 ctf_it_ptr = _bt_ctf_iter_create(self._tc, begin_pos_ptr, end_pos_ptr)
260 if ctf_it_ptr is None:
261 raise NotImplementedError(
262 "Creation of multiple iterators is unsupported.")
263
264 while True:
265 ev_ptr = _bt_ctf_iter_read_event(ctf_it_ptr)
266 if ev_ptr is None:
267 break
268
78d714e8 269 ev = Event.__new__(Event)
74ea15ad
JG
270 ev._e = ev_ptr
271 try:
272 yield ev
273 except GeneratorExit:
274 break
275
276 ret = _bt_iter_next(_bt_ctf_get_iter(ctf_it_ptr))
277 if ret != 0:
278 break
279
280 _bt_ctf_iter_destroy(ctf_it_ptr)
281
24a3136a
DS
282%}
283
284
285
286/* =================================================================
287 FORMAT.H, REGISTRY
288 ¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯
289*/
290
291%rename("lookup_format") bt_lookup_format(bt_intern_str qname);
292%rename("_bt_print_format_list") bt_fprintf_format_list(FILE *fp);
293%rename("register_format") bt_register_format(struct format *format);
cc26a15a 294%rename("unregister_format") bt_unregister_format(struct bt_format *format);
24a3136a
DS
295
296extern struct format *bt_lookup_format(bt_intern_str qname);
297extern void bt_fprintf_format_list(FILE *fp);
2c0df204 298extern int bt_register_format(struct bt_format *format);
cc26a15a 299extern void bt_unregister_format(struct bt_format *format);
24a3136a 300
24a3136a
DS
301%pythoncode %{
302
303def print_format_list(babeltrace_file):
304 """
305 Print a list of available formats to file.
306
307 babeltrace_file must be a File instance opened in write mode.
308 """
309 try:
310 if babeltrace_file._file is not None:
311 _bt_print_format_list(babeltrace_file._file)
312 except AttributeError:
313 raise TypeError("in print_format_list, "
314 "argument 1 must be a File instance")
315
316%}
317
318
319/* =================================================================
320 ITERATOR.H, ITERATOR-INTERNAL.H
321 ¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯
322*/
323
324%rename("_bt_iter_create") bt_iter_create(struct bt_context *ctx,
325 const struct bt_iter_pos *begin_pos, const struct bt_iter_pos *end_pos);
326%rename("_bt_iter_destroy") bt_iter_destroy(struct bt_iter *iter);
327%rename("_bt_iter_next") bt_iter_next(struct bt_iter *iter);
328%rename("_bt_iter_get_pos") bt_iter_get_pos(struct bt_iter *iter);
329%rename("_bt_iter_free_pos") bt_iter_free_pos(struct bt_iter_pos *pos);
330%rename("_bt_iter_set_pos") bt_iter_set_pos(struct bt_iter *iter,
331 const struct bt_iter_pos *pos);
332%rename("_bt_iter_create_time_pos") bt_iter_create_time_pos(struct bt_iter *iter,
333 uint64_t timestamp);
334
335struct bt_iter *bt_iter_create(struct bt_context *ctx,
336 const struct bt_iter_pos *begin_pos, const struct bt_iter_pos *end_pos);
337void bt_iter_destroy(struct bt_iter *iter);
338int bt_iter_next(struct bt_iter *iter);
339struct bt_iter_pos *bt_iter_get_pos(struct bt_iter *iter);
340void bt_iter_free_pos(struct bt_iter_pos *pos);
341int bt_iter_set_pos(struct bt_iter *iter, const struct bt_iter_pos *pos);
342struct bt_iter_pos *bt_iter_create_time_pos(struct bt_iter *iter, uint64_t timestamp);
343
344%rename("_bt_iter_pos") bt_iter_pos;
345%rename("SEEK_TIME") BT_SEEK_TIME;
346%rename("SEEK_RESTORE") BT_SEEK_RESTORE;
347%rename("SEEK_CUR") BT_SEEK_CUR;
348%rename("SEEK_BEGIN") BT_SEEK_BEGIN;
ef42f9eb 349%rename("SEEK_LAST") BT_SEEK_LAST;
24a3136a
DS
350
351// This struct is taken from iterator.h
352// All changes to the struct must also be made here
353struct bt_iter_pos {
354 enum {
355 BT_SEEK_TIME, /* uses u.seek_time */
356 BT_SEEK_RESTORE, /* uses u.restore */
357 BT_SEEK_CUR,
358 BT_SEEK_BEGIN,
ef42f9eb 359 BT_SEEK_LAST
24a3136a
DS
360 } type;
361 union {
362 uint64_t seek_time;
363 struct bt_saved_pos *restore;
364 } u;
365};
366
24a3136a
DS
367/* =================================================================
368 TRACE-HANDLE.H, TRACE-HANDLE-INTERNAL.H
369 ¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯
370*/
371
372%rename("_bt_trace_handle_create") bt_trace_handle_create(struct bt_context *ctx);
373%rename("_bt_trace_handle_destroy") bt_trace_handle_destroy(struct bt_trace_handle *bt);
374struct bt_trace_handle *bt_trace_handle_create(struct bt_context *ctx);
375void bt_trace_handle_destroy(struct bt_trace_handle *bt);
376
377%rename("_bt_trace_handle_get_path") bt_trace_handle_get_path(struct bt_context *ctx,
378 int handle_id);
379%rename("_bt_trace_handle_get_timestamp_begin") bt_trace_handle_get_timestamp_begin(
380 struct bt_context *ctx, int handle_id, enum bt_clock_type type);
381%rename("_bt_trace_handle_get_timestamp_end") bt_trace_handle_get_timestamp_end(
382 struct bt_context *ctx, int handle_id, enum bt_clock_type type);
24a3136a
DS
383const char *bt_trace_handle_get_path(struct bt_context *ctx, int handle_id);
384uint64_t bt_trace_handle_get_timestamp_begin(struct bt_context *ctx, int handle_id,
385 enum bt_clock_type type);
386uint64_t bt_trace_handle_get_timestamp_end(struct bt_context *ctx, int handle_id,
387 enum bt_clock_type type);
388
389%rename("_bt_ctf_event_get_handle_id") bt_ctf_event_get_handle_id(
390 const struct bt_ctf_event *event);
391int bt_ctf_event_get_handle_id(const struct bt_ctf_event *event);
392
393
394%pythoncode%{
395
d0f6c523 396# Based on enum bt_clock_type in clock-type.h
464425e1
JG
397class ClockType:
398 CLOCK_CYCLES = 0
399 CLOCK_REAL = 1
400
24a3136a
DS
401class TraceHandle(object):
402 """
403 The TraceHandle allows the user to manipulate a trace file directly.
404 It is a unique identifier representing a trace file.
405 Do not instantiate.
406 """
407
408 def __init__(self):
409 raise NotImplementedError("TraceHandle cannot be instantiated")
410
411 def __repr__(self):
288209fb 412 return "Babeltrace TraceHandle: trace_id('{0}')".format(self._id)
24a3136a 413
464425e1
JG
414 @property
415 def id(self):
24a3136a
DS
416 """Return the TraceHandle id."""
417 return self._id
418
464425e1
JG
419 @property
420 def path(self):
24a3136a 421 """Return the path of a TraceHandle."""
464425e1 422 return _bt_trace_handle_get_path(self._trace_collection._tc, self._id)
24a3136a 423
464425e1
JG
424 @property
425 def timestamp_begin(self):
24a3136a 426 """Return the creation time of the buffers of a trace."""
464425e1
JG
427 return _bt_trace_handle_get_timestamp_begin(
428 self._trace_collection._tc, self._id, ClockType.CLOCK_REAL)
24a3136a 429
464425e1
JG
430 @property
431 def timestamp_end(self):
24a3136a 432 """Return the destruction timestamp of the buffers of a trace."""
464425e1
JG
433 return _bt_trace_handle_get_timestamp_end(
434 self._trace_collection._tc, self._id, ClockType.CLOCK_REAL)
24a3136a 435
8bb27181
JG
436 @property
437 def events(self):
438 """
439 Generator returning all events (EventDeclaration) in a trace.
440 """
441 ret = _bt_python_event_decl_listcaller(self.id, self._trace_collection._tc)
442
443 if not isinstance(ret, list):
444 return
445
446 ptr_list, count = ret
447 for i in range(count):
448 tmp = EventDeclaration.__new__(EventDeclaration)
449 tmp._ed = _bt_python_decl_one_from_list(ptr_list, i)
450 yield tmp
451
24a3136a
DS
452%}
453
454
455
456// =================================================================
457// CTF
458// =================================================================
459
460/* =================================================================
461 ITERATOR.H, EVENTS.H
462 ¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯
463*/
464
465//Iterator
466%rename("_bt_ctf_iter_create") bt_ctf_iter_create(struct bt_context *ctx,
467 const struct bt_iter_pos *begin_pos,
468 const struct bt_iter_pos *end_pos);
469%rename("_bt_ctf_get_iter") bt_ctf_get_iter(struct bt_ctf_iter *iter);
470%rename("_bt_ctf_iter_destroy") bt_ctf_iter_destroy(struct bt_ctf_iter *iter);
471%rename("_bt_ctf_iter_read_event") bt_ctf_iter_read_event(struct bt_ctf_iter *iter);
472
473struct bt_ctf_iter *bt_ctf_iter_create(struct bt_context *ctx,
474 const struct bt_iter_pos *begin_pos,
475 const struct bt_iter_pos *end_pos);
476struct bt_iter *bt_ctf_get_iter(struct bt_ctf_iter *iter);
477void bt_ctf_iter_destroy(struct bt_ctf_iter *iter);
478struct bt_ctf_event *bt_ctf_iter_read_event(struct bt_ctf_iter *iter);
479
480
481//Events
24a3136a
DS
482%rename("_bt_ctf_get_top_level_scope") bt_ctf_get_top_level_scope(const struct
483 bt_ctf_event *event, enum bt_ctf_scope scope);
484%rename("_bt_ctf_event_name") bt_ctf_event_name(const struct bt_ctf_event *ctf_event);
485%rename("_bt_ctf_get_timestamp") bt_ctf_get_timestamp(
486 const struct bt_ctf_event *ctf_event);
487%rename("_bt_ctf_get_cycles") bt_ctf_get_cycles(
488 const struct bt_ctf_event *ctf_event);
489
490%rename("_bt_ctf_get_field") bt_ctf_get_field(const struct bt_ctf_event *ctf_event,
2c0df204 491 const struct bt_definition *scope, const char *field);
24a3136a 492%rename("_bt_ctf_get_index") bt_ctf_get_index(const struct bt_ctf_event *ctf_event,
2c0df204
XH
493 const struct bt_definition *field, unsigned int index);
494%rename("_bt_ctf_field_name") bt_ctf_field_name(const struct bt_definition *field);
495%rename("_bt_ctf_field_type") bt_ctf_field_type(const struct bt_declaration *field);
24a3136a 496%rename("_bt_ctf_get_int_signedness") bt_ctf_get_int_signedness(
2c0df204
XH
497 const struct bt_declaration *field);
498%rename("_bt_ctf_get_int_base") bt_ctf_get_int_base(const struct bt_declaration *field);
24a3136a 499%rename("_bt_ctf_get_int_byte_order") bt_ctf_get_int_byte_order(
2c0df204
XH
500 const struct bt_declaration *field);
501%rename("_bt_ctf_get_int_len") bt_ctf_get_int_len(const struct bt_declaration *field);
4191bcd2
XH
502%rename("_bt_ctf_get_enum_int") bt_ctf_get_enum_int(const struct bt_definition *field);
503%rename("_bt_ctf_get_enum_str") bt_ctf_get_enum_str(const struct bt_definition *field);
2c0df204
XH
504%rename("_bt_ctf_get_encoding") bt_ctf_get_encoding(const struct bt_declaration *field);
505%rename("_bt_ctf_get_array_len") bt_ctf_get_array_len(const struct bt_declaration *field);
506%rename("_bt_ctf_get_uint64") bt_ctf_get_uint64(const struct bt_definition *field);
507%rename("_bt_ctf_get_int64") bt_ctf_get_int64(const struct bt_definition *field);
508%rename("_bt_ctf_get_char_array") bt_ctf_get_char_array(const struct bt_definition *field);
509%rename("_bt_ctf_get_string") bt_ctf_get_string(const struct bt_definition *field);
e5a73b90 510%rename("_bt_ctf_get_float") bt_ctf_get_float(const struct bt_definition *field);
812e6682 511%rename("_bt_ctf_get_variant") bt_ctf_get_variant(const struct bt_definition *field);
24a3136a
DS
512%rename("_bt_ctf_field_get_error") bt_ctf_field_get_error(void);
513%rename("_bt_ctf_get_decl_event_name") bt_ctf_get_decl_event_name(const struct
514 bt_ctf_event_decl *event);
515%rename("_bt_ctf_get_decl_field_name") bt_ctf_get_decl_field_name(
516 const struct bt_ctf_field_decl *field);
f01efa78 517%rename("_bt_ctf_get_decl_from_def") bt_ctf_get_decl_from_def(
2c0df204 518 const struct bt_definition *field);
8bb27181
JG
519%rename("_bt_ctf_get_decl_from_field_decl") bt_ctf_get_decl_from_field_decl(
520 const struct bt_ctf_field_decl *field);
3c2ce778 521%rename("_bt_array_index") bt_array_index(struct definition_array *array, uint64_t i);
786207e0
XH
522%rename("_bt_sequence_len") bt_sequence_len(struct definition_sequence *sequence);
523%rename("_bt_sequence_index") bt_sequence_index(struct definition_sequence *sequence, uint64_t i);
3a068915
JG
524%rename("_bt_ctf_get_struct_field_count") bt_ctf_get_struct_field_count(const struct bt_definition *structure);
525%rename("_bt_ctf_get_struct_field_index") bt_ctf_get_struct_field_index(const struct bt_definition *structure, uint64_t i);
24a3136a 526
2c0df204 527const struct bt_definition *bt_ctf_get_top_level_scope(const struct bt_ctf_event *ctf_event,
24a3136a
DS
528 enum bt_ctf_scope scope);
529const char *bt_ctf_event_name(const struct bt_ctf_event *ctf_event);
530uint64_t bt_ctf_get_timestamp(const struct bt_ctf_event *ctf_event);
531uint64_t bt_ctf_get_cycles(const struct bt_ctf_event *ctf_event);
2c0df204
XH
532const struct bt_definition *bt_ctf_get_field(const struct bt_ctf_event *ctf_event,
533 const struct bt_definition *scope,
24a3136a 534 const char *field);
2c0df204
XH
535const struct bt_definition *bt_ctf_get_index(const struct bt_ctf_event *ctf_event,
536 const struct bt_definition *field,
24a3136a 537 unsigned int index);
2c0df204
XH
538const char *bt_ctf_field_name(const struct bt_definition *field);
539enum ctf_type_id bt_ctf_field_type(const struct bt_declaration *field);
540int bt_ctf_get_int_signedness(const struct bt_declaration *field);
541int bt_ctf_get_int_base(const struct bt_declaration *field);
542int bt_ctf_get_int_byte_order(const struct bt_declaration *field);
543ssize_t bt_ctf_get_int_len(const struct bt_declaration *field);
4191bcd2
XH
544const struct bt_definition *bt_ctf_get_enum_int(const struct bt_definition *field);
545const char *bt_ctf_get_enum_str(const struct bt_definition *field);
2c0df204
XH
546enum ctf_string_encoding bt_ctf_get_encoding(const struct bt_declaration *field);
547int bt_ctf_get_array_len(const struct bt_declaration *field);
3c2ce778 548struct bt_definition *bt_array_index(struct definition_array *array, uint64_t i);
2c0df204
XH
549uint64_t bt_ctf_get_uint64(const struct bt_definition *field);
550int64_t bt_ctf_get_int64(const struct bt_definition *field);
551char *bt_ctf_get_char_array(const struct bt_definition *field);
552char *bt_ctf_get_string(const struct bt_definition *field);
e5a73b90 553double bt_ctf_get_float(const struct bt_definition *field);
812e6682 554const struct bt_definition *bt_ctf_get_variant(const struct bt_definition *field);
24a3136a
DS
555int bt_ctf_field_get_error(void);
556const char *bt_ctf_get_decl_event_name(const struct bt_ctf_event_decl *event);
557const char *bt_ctf_get_decl_field_name(const struct bt_ctf_field_decl *field);
2c0df204 558const struct bt_declaration *bt_ctf_get_decl_from_def(const struct bt_definition *field);
8bb27181 559const struct bt_declaration *bt_ctf_get_decl_from_field_decl(const struct bt_ctf_field_decl *field);
786207e0
XH
560uint64_t bt_sequence_len(struct definition_sequence *sequence);
561struct bt_definition *bt_sequence_index(struct definition_sequence *sequence, uint64_t i);
3a068915
JG
562uint64_t bt_ctf_get_struct_field_count(const struct bt_definition *structure);
563const struct bt_definition *bt_ctf_get_struct_field_index(const struct bt_definition *structure, uint64_t i);
24a3136a
DS
564
565%pythoncode%{
566
24d5c942
JG
567class CTFStringEncoding:
568 NONE = 0
569 UTF8 = 1
570 ASCII = 2
571 UNKNOWN = 3
572
8bb27181
JG
573# Based on the enum in ctf-writer/writer.h
574class ByteOrder:
575 BYTE_ORDER_NATIVE = 0
576 BYTE_ORDER_LITTLE_ENDIAN = 1
577 BYTE_ORDER_BIG_ENDIAN = 2
578 BYTE_ORDER_NETWORK = 3
579 BYTE_ORDER_UNKNOWN = 4 # Python-specific entry
580
24d5c942
JG
581#enum equivalent, accessible constants
582#These are taken directly from ctf/events.h
583#All changes to enums must also be made here
584class CTFTypeId:
585 UNKNOWN = 0
586 INTEGER = 1
587 FLOAT = 2
588 ENUM = 3
589 STRING = 4
590 STRUCT = 5
591 UNTAGGED_VARIANT = 6
592 VARIANT = 7
593 ARRAY = 8
594 SEQUENCE = 9
595 NR_CTF_TYPES = 10
596
8bb27181
JG
597 def type_name(id):
598 name = "UNKNOWN_TYPE"
24d5c942
JG
599 constants = [attr for attr in dir(CTFTypeId) if not callable(getattr(CTFTypeId, attr)) and not attr.startswith("__")]
600 for attr in constants:
601 if getattr(CTFTypeId, attr) == id:
602 name = attr
603 break
604 return name
605
8bb27181 606class CTFScope:
78d714e8
JG
607 TRACE_PACKET_HEADER = 0
608 STREAM_PACKET_CONTEXT = 1
609 STREAM_EVENT_HEADER = 2
610 STREAM_EVENT_CONTEXT = 3
611 EVENT_CONTEXT = 4
612 EVENT_FIELDS = 5
613
8bb27181
JG
614 def scope_name(scope):
615 name = "UNKNOWN_SCOPE"
616 constants = [attr for attr in dir(CTFScope) if not callable(getattr(CTFScope, attr)) and not attr.startswith("__")]
617 for attr in constants:
618 if getattr(CTFScope, attr) == scope:
619 name = attr
620 break
621 return name
622
e404272a 623# Priority of the scopes when searching for event fields
8bb27181
JG
624_scopes = [CTFScope.EVENT_FIELDS, CTFScope.EVENT_CONTEXT, CTFScope.STREAM_EVENT_CONTEXT,
625 CTFScope.STREAM_EVENT_HEADER, CTFScope.STREAM_PACKET_CONTEXT, CTFScope.TRACE_PACKET_HEADER]
e404272a 626
78d714e8
JG
627import collections
628class Event(collections.Mapping):
629 """
630 This class represents an event from the trace.
631 It is obtained using the TraceCollection generator functions.
632 Do not instantiate.
633 """
78d714e8
JG
634 def __init__(self):
635 raise NotImplementedError("Event cannot be instantiated")
636
637 @property
638 def name(self):
639 """Return the name of the event or None on error."""
640 return _bt_ctf_event_name(self._e)
641
642 @property
643 def cycles(self):
24a3136a 644 """
78d714e8
JG
645 Return the timestamp of the event as written in
646 the packet (in cycles) or -1ULL on error.
24a3136a 647 """
78d714e8 648 return _bt_ctf_get_cycles(self._e)
24a3136a 649
78d714e8
JG
650 @property
651 def timestamp(self):
652 """
653 Return the timestamp of the event offset with the
654 system clock source or -1ULL on error.
655 """
656 return _bt_ctf_get_timestamp(self._e)
657
658 def field_with_scope(self, field_name, scope):
659 """
660 Get field_name's value in scope.
661 None is returned if no field matches field_name.
662 """
e404272a 663 if not scope in _scopes:
78d714e8
JG
664 raise ValueError("Invalid scope provided")
665 field = self._field_with_scope(field_name, scope)
666 if field is not None:
667 return field.value
668 return None
669
670 def field_list_with_scope(self, scope):
671 """Return a list of field names in scope."""
e404272a 672 if not scope in _scopes:
78d714e8
JG
673 raise ValueError("Invalid scope provided")
674 field_names = []
675 for field in self._field_list_with_scope(scope):
676 field_names.append(field.name)
677 return field_names
678
679 @property
680 def handle(self):
681 """
682 Get the TraceHandle associated with this event
683 Return None on error
684 """
685 ret = _bt_ctf_event_get_handle_id(self._e)
686 if ret < 0:
786207e0
XH
687 return None
688
78d714e8
JG
689 th = TraceHandle.__new__(TraceHandle)
690 th._id = ret
691 th._trace_collection = self.get_trace_collection()
692 return th
693
694 @property
695 def trace_collection(self):
696 """
697 Get the TraceCollection associated with this event.
698 Return None on error.
24a3136a 699 """
78d714e8
JG
700 trace_collection = TraceCollection()
701 trace_collection._tc = _bt_ctf_event_get_context(self._e);
702 if trace_collection._tc is None:
703 return None
704 else:
705 return trace_collection
706
707 def __getitem__(self, field_name):
24a3136a 708 """
78d714e8
JG
709 Get field_name's value. If the field_name exists in multiple
710 scopes, the first field found is returned. The scopes are searched
711 in the following order:
712 1) EVENT_FIELDS
713 2) EVENT_CONTEXT
714 3) STREAM_EVENT_CONTEXT
715 4) STREAM_EVENT_HEADER
716 5) STREAM_PACKET_CONTEXT
717 6) TRACE_PACKET_HEADER
718 None is returned if no field matches field_name.
719
720 Use field_with_scope() to explicitly access fields in a given
721 scope.
722 """
723 field = self._field(field_name)
724 if field is not None:
725 return field.value
726 raise KeyError(field_name)
727
728 def __iter__(self):
729 for key in self.keys():
730 yield key
731
732 def __len__(self):
733 count = 0
e404272a 734 for scope in _scopes:
78d714e8
JG
735 scope_ptr = _bt_ctf_get_top_level_scope(self._e, scope)
736 ret = _bt_python_field_listcaller(self._e, scope_ptr)
737 if isinstance(ret, list):
738 count += ret[1]
739 return count
740
741 def __contains__(self, field_name):
742 return self._field(field_name) is not None
743
744 def keys(self):
745 """Return a list of field names."""
746 field_names = set()
e404272a 747 for scope in _scopes:
78d714e8
JG
748 for name in self.field_list_with_scope(scope):
749 field_names.add(name)
750 return list(field_names)
751
752 def get(self, field_name, default = None):
753 field = self._field(field_name)
754 if field is None:
755 return default
756 return field.value
757
758 def items(self):
759 for field in self.keys():
760 yield (field, self[field])
761
762 def _field_with_scope(self, field_name, scope):
763 scope_ptr = _bt_ctf_get_top_level_scope(self._e, scope)
764 if scope_ptr is None:
765 return None
766
767 definition_ptr = _bt_ctf_get_field(self._e, scope_ptr, field_name)
768 if definition_ptr is None:
769 return None
24a3136a 770
78d714e8
JG
771 field = _Definition(definition_ptr, scope)
772 return field
773
774 def _field(self, field_name):
775 field = None
e404272a 776 for scope in _scopes:
78d714e8
JG
777 field = self._field_with_scope(field_name, scope)
778 if field is not None:
779 break
780 return field
781
782 def _field_list_with_scope(self, scope):
783 fields = []
784 scope_ptr = _bt_ctf_get_top_level_scope(self._e, scope)
785
786 # Returns a list [list_ptr, count]. If list_ptr is NULL, SWIG will only
787 # provide the "count" return value
788 count = 0
789 list_ptr = None
790 ret = _bt_python_field_listcaller(self._e, scope_ptr)
791 if isinstance(ret, list):
792 list_ptr, count = ret
793
794 for i in range(count):
795 definition_ptr = _bt_python_field_one_from_list(list_ptr, i)
796 if definition_ptr is not None:
797 definition = _Definition(definition_ptr, scope)
798 fields.append(definition)
799 return fields
800
801class FieldError(Exception):
802 def __init__(self, value):
803 self.value = value
804
805 def __str__(self):
806 return repr(self.value)
807
cb1fcc68 808class EventDeclaration(object):
78d714e8
JG
809 """Event declaration class. Do not instantiate."""
810
811 def __init__(self):
cb1fcc68 812 raise NotImplementedError("EventDeclaration cannot be instantiated")
78d714e8 813
cb1fcc68
JG
814 @property
815 def name(self):
78d714e8 816 """Return the name of the event or None on error"""
cb1fcc68 817 return _bt_ctf_get_decl_event_name(self._ed)
78d714e8 818
8bb27181
JG
819 @property
820 def fields(self):
24a3136a 821 """
8bb27181
JG
822 Generator returning all FieldDeclarations of an event, going through
823 each scope in the following order:
824 1) EVENT_FIELDS
825 2) EVENT_CONTEXT
826 3) STREAM_EVENT_CONTEXT
827 4) STREAM_EVENT_HEADER
828 5) STREAM_PACKET_CONTEXT
829 6) TRACE_PACKET_HEADER
830 """
831 for scope in _scopes:
832 for declaration in self.fields_scope(scope):
833 yield declaration
834
835 def fields_scope(self, scope):
836 """
837 Generator returning FieldDeclarations of the current event in scope.
24a3136a 838 """
cb1fcc68 839 ret = _by_python_field_decl_listcaller(self._ed, scope)
24a3136a 840
cb1fcc68 841 if not isinstance(ret, list):
8bb27181 842 return
24a3136a 843
cb1fcc68 844 list_ptr, count = ret
cb1fcc68 845 for i in range(count):
8bb27181
JG
846 field_declaration_ptr = _bt_python_field_decl_one_from_list(list_ptr, i)
847 if field_declaration_ptr is not None:
848 declaration_ptr = _bt_ctf_get_decl_from_field_decl(field_declaration_ptr)
849 field_declaration = _create_field_declaration(declaration_ptr, _bt_ctf_get_decl_field_name(field_declaration_ptr), scope)
850 yield field_declaration
cb1fcc68
JG
851
852class FieldDeclaration(object):
853 """Field declaration class. Do not instantiate."""
78d714e8 854 def __init__(self):
cb1fcc68 855 raise NotImplementedError("FieldDeclaration cannot be instantiated")
78d714e8 856
8bb27181
JG
857 def __repr__(self):
858 return "({0}) {1} {2}".format(CTFScope.scope_name(self.scope), CTFTypeId.type_name(self.type), self.name)
859
cb1fcc68
JG
860 @property
861 def name(self):
8bb27181
JG
862 """Return the name of a FieldDeclaration or None on error."""
863 return self._name
864
865 @property
866 def type(self):
867 """
868 Return the FieldDeclaration's type. One of the entries in class
869 CTFTypeId.
870 """
871 return _bt_ctf_field_type(self._fd)
872
873 @property
874 def scope(self):
875 """
876 Return the FieldDeclaration's scope.
877 """
878 return self._s
879
880class IntegerFieldDeclaration(FieldDeclaration):
881 """Do not instantiate."""
882 def __init__(self):
883 raise NotImplementedError("IntegerFieldDeclaration cannot be instantiated")
884
885 @property
886 def signedness(self):
887 """
888 Return the signedness of an integer:
889 0 if unsigned; 1 if signed; -1 on error.
890 """
891 return _bt_ctf_get_int_signedness(self._fd)
892
893 @property
894 def base(self):
895 """Return the base of an int or a negative value on error."""
896 return _bt_ctf_get_int_base(self._fd)
897
898 @property
899 def byte_order(self):
900 """
901 Return the byte order. One of class ByteOrder's entries.
902 """
903 ret = _bt_ctf_get_int_byte_order(self._fd)
904 if ret == 1234:
905 return ByteOrder.BYTE_ORDER_LITTLE_ENDIAN
906 elif ret == 4321:
907 return ByteOrder.BYTE_ORDER_BIG_ENDIAN
908 else:
909 return ByteOrder.BYTE_ORDER_UNKNOWN
910
911 @property
912 def length(self):
913 """
914 Return the size, in bits, of an int or a negative
915 value on error.
916 """
917 return _bt_ctf_get_int_len(self._fd)
918
919 @property
920 def encoding(self):
921 """
922 Return the encoding. One of class CTFStringEncoding's entries.
923 Return a negative value on error.
924 """
925 return _bt_ctf_get_encoding(self._fd)
926
927class EnumerationFieldDeclaration(FieldDeclaration):
928 """Do not instantiate."""
929 def __init__(self):
930 raise NotImplementedError("EnumerationFieldDeclaration cannot be instantiated")
931
932class ArrayFieldDeclaration(FieldDeclaration):
933 """Do not instantiate."""
934 def __init__(self):
935 raise NotImplementedError("ArrayFieldDeclaration cannot be instantiated")
936
937 @property
938 def length(self):
939 """
940 Return the length of an array or a negative
941 value on error.
942 """
943 return _bt_ctf_get_array_len(self._fd)
944
5792eb34
JG
945 @property
946 def element_declaration(self):
947 """
948 Return element declaration.
949 """
950 field_decl_ptr = _bt_python_get_array_element_declaration(self._fd)
951 return _create_field_declaration(field_decl_ptr, "", self.scope)
952
8bb27181
JG
953class SequenceFieldDeclaration(FieldDeclaration):
954 """Do not instantiate."""
955 def __init__(self):
956 raise NotImplementedError("SequenceFieldDeclaration cannot be instantiated")
957
e11b8d3a
JG
958 @property
959 def element_declaration(self):
960 """
961 Return element declaration.
962 """
963 field_decl_ptr = _bt_python_get_sequence_element_declaration(self._fd)
964 return _create_field_declaration(field_decl_ptr, "", self.scope)
965
8bb27181
JG
966class FloatFieldDeclaration(FieldDeclaration):
967 """Do not instantiate."""
968 def __init__(self):
969 raise NotImplementedError("FloatFieldDeclaration cannot be instantiated")
970
971class StructureFieldDeclaration(FieldDeclaration):
972 """Do not instantiate."""
973 def __init__(self):
974 raise NotImplementedError("StructureFieldDeclaration cannot be instantiated")
975
976class StringFieldDeclaration(FieldDeclaration):
977 """Do not instantiate."""
978 def __init__(self):
979 raise NotImplementedError("StringFieldDeclaration cannot be instantiated")
980
981class VariantFieldDeclaration(FieldDeclaration):
982 """Do not instantiate."""
983 def __init__(self):
984 raise NotImplementedError("VariantFieldDeclaration cannot be instantiated")
78d714e8
JG
985
986def field_error():
987 """
988 Return the last error code encountered while
989 accessing a field and reset the error flag.
990 Return 0 if no error, a negative value otherwise.
991 """
992 return _bt_ctf_field_get_error()
993
8bb27181 994def _create_field_declaration(declaration_ptr, name, scope):
78d714e8 995 """
8bb27181 996 Private field declaration factory.
78d714e8 997 """
8bb27181
JG
998 if declaration_ptr is None:
999 raise ValueError("declaration_ptr must be valid")
1000 if not scope in _scopes:
1001 raise ValueError("Invalid scope provided")
1002
1003 type = _bt_ctf_field_type(declaration_ptr)
1004 declaration = None
1005 if type == CTFTypeId.INTEGER:
1006 declaration = IntegerFieldDeclaration.__new__(IntegerFieldDeclaration)
1007 elif type == CTFTypeId.ENUM:
1008 declaration = EnumerationFieldDeclaration.__new__(EnumerationFieldDeclaration)
1009 elif type == CTFTypeId.ARRAY:
1010 declaration = ArrayFieldDeclaration.__new__(ArrayFieldDeclaration)
1011 elif type == CTFTypeId.SEQUENCE:
1012 declaration = SequenceFieldDeclaration.__new__(SequenceFieldDeclaration)
1013 elif type == CTFTypeId.FLOAT:
1014 declaration = FloatFieldDeclaration.__new__(FloatFieldDeclaration)
1015 elif type == CTFTypeId.STRUCT:
1016 declaration = StructureFieldDeclaration.__new__(StructureFieldDeclaration)
1017 elif type == CTFTypeId.STRING:
1018 declaration = StringFieldDeclaration.__new__(StringFieldDeclaration)
1019 elif type == CTFTypeId.VARIANT:
1020 declaration = VariantFieldDeclaration.__new__(VariantFieldDeclaration)
1021 else:
1022 return declaration
1023
1024 declaration._fd = declaration_ptr
1025 declaration._s = scope
1026 declaration._name = name
1027 return declaration
78d714e8
JG
1028
1029class _Definition(object):
1030 def __init__(self, definition_ptr, scope):
1031 self._d = definition_ptr
1032 self._s = scope
e404272a 1033 if not scope in _scopes:
78d714e8
JG
1034 ValueError("Invalid scope provided")
1035
78d714e8
JG
1036 @property
1037 def name(self):
1038 """Return the name of a field or None on error."""
1039 return _bt_ctf_field_name(self._d)
1040
5792eb34 1041 @property
78d714e8
JG
1042 def type(self):
1043 """Return the type of a field or -1 if unknown."""
1044 return _bt_ctf_field_type(_bt_ctf_get_decl_from_def(self._d))
1045
8bb27181
JG
1046 @property
1047 def declaration(self):
1048 """Return the associated Definition object."""
1049 return _create_field_declaration(_bt_ctf_get_decl_from_def(self._d), self.name, self.scope)
78d714e8 1050
8bb27181 1051 def _get_enum_str(self):
78d714e8
JG
1052 """
1053 Return the string matching the current enumeration.
1054 Return None on error.
1055 """
1056 return _bt_ctf_get_enum_str(self._d)
1057
8bb27181 1058 def _get_array_element_at(self, index):
78d714e8
JG
1059 """
1060 Return the array's element at position index.
1061 Return None on error
1062 """
1063 array_ptr = _bt_python_get_array_from_def(self._d)
1064 if array_ptr is None:
1065 return None
1066
1067 definition_ptr = _bt_array_index(array_ptr, index)
1068 if definition_ptr is None:
1069 return None
1070 return _Definition(definition_ptr, self.scope)
1071
8bb27181 1072 def _get_sequence_len(self):
78d714e8
JG
1073 """
1074 Return the len of a sequence or a negative
1075 value on error.
1076 """
1077 seq = _bt_python_get_sequence_from_def(self._d)
1078 return _bt_sequence_len(seq)
1079
8bb27181 1080 def _get_sequence_element_at(self, index):
78d714e8
JG
1081 """
1082 Return the sequence's element at position index,
1083 otherwise return None
1084 """
1085 seq = _bt_python_get_sequence_from_def(self._d)
1086 if seq is not None:
1087 definition_ptr = _bt_sequence_index(seq, index)
1088 if definition_ptr is not None:
1089 return _Definition(definition_ptr, self.scope)
1090 return None
1091
8bb27181 1092 def _get_uint64(self):
78d714e8
JG
1093 """
1094 Return the value associated with the field.
1095 If the field does not exist or is not of the type requested,
1096 the value returned is undefined. To check if an error occured,
1097 use the field_error() function after accessing a field.
1098 """
1099 return _bt_ctf_get_uint64(self._d)
1100
8bb27181 1101 def _get_int64(self):
78d714e8
JG
1102 """
1103 Return the value associated with the field.
1104 If the field does not exist or is not of the type requested,
1105 the value returned is undefined. To check if an error occured,
1106 use the field_error() function after accessing a field.
1107 """
1108 return _bt_ctf_get_int64(self._d)
1109
8bb27181 1110 def _get_char_array(self):
78d714e8
JG
1111 """
1112 Return the value associated with the field.
1113 If the field does not exist or is not of the type requested,
1114 the value returned is undefined. To check if an error occurred,
1115 use the field_error() function after accessing a field.
1116 """
1117 return _bt_ctf_get_char_array(self._d)
1118
8bb27181 1119 def _get_str(self):
78d714e8
JG
1120 """
1121 Return the value associated with the field.
1122 If the field does not exist or is not of the type requested,
1123 the value returned is undefined. To check if an error occurred,
1124 use the field_error() function after accessing a field.
1125 """
1126 return _bt_ctf_get_string(self._d)
1127
8bb27181 1128 def _get_float(self):
78d714e8
JG
1129 """
1130 Return the value associated with the field.
1131 If the field does not exist or is not of the type requested,
1132 the value returned is undefined. To check if an error occurred,
1133 use the field_error() function after accessing a field.
1134 """
1135 return _bt_ctf_get_float(self._d)
1136
8bb27181 1137 def _get_variant(self):
78d714e8
JG
1138 """
1139 Return the variant's selected field.
1140 If the field does not exist or is not of the type requested,
1141 the value returned is undefined. To check if an error occurred,
1142 use the field_error() function after accessing a field.
1143 """
1144 return _bt_ctf_get_variant(self._d)
1145
8bb27181 1146 def _get_struct_field_count(self):
78d714e8
JG
1147 """
1148 Return the number of fields contained in the structure.
1149 If the field does not exist or is not of the type requested,
1150 the value returned is undefined.
1151 """
1152 return _bt_ctf_get_struct_field_count(self._d)
1153
8bb27181 1154 def _get_struct_field_at(self, i):
78d714e8
JG
1155 """
1156 Return the structure's field at position i.
1157 If the field does not exist or is not of the type requested,
1158 the value returned is undefined. To check if an error occurred,
1159 use the field_error() function after accessing a field.
1160 """
1161 return _bt_ctf_get_struct_field_index(self._d, i)
1162
1163 @property
1164 def value(self):
1165 """
1166 Return the value associated with the field according to its type.
1167 Return None on error.
1168 """
1169 id = self.type
1170 value = None
5792eb34 1171
78d714e8 1172 if id == CTFTypeId.STRING:
8bb27181 1173 value = self._get_str()
78d714e8 1174 elif id == CTFTypeId.ARRAY:
5792eb34
JG
1175 element_decl = self.declaration.element_declaration
1176 if ((element_decl.type == CTFTypeId.INTEGER
1177 and element_decl.length == 8)
1178 and (element_decl.encoding == CTFStringEncoding.ASCII or element_decl.encoding == CTFStringEncoding.UTF8)):
1179 value = _bt_python_get_array_string(self._d)
1180 else:
1181 value = []
1182 for i in range(self.declaration.length):
1183 element = self._get_array_element_at(i)
1184 value.append(element.value)
78d714e8 1185 elif id == CTFTypeId.INTEGER:
8bb27181
JG
1186 if self.declaration.signedness == 0:
1187 value = self._get_uint64()
78d714e8 1188 else:
8bb27181 1189 value = self._get_int64()
78d714e8 1190 elif id == CTFTypeId.ENUM:
8bb27181 1191 value = self._get_enum_str()
78d714e8 1192 elif id == CTFTypeId.SEQUENCE:
e11b8d3a
JG
1193 element_decl = self.declaration.element_declaration
1194 if ((element_decl.type == CTFTypeId.INTEGER
1195 and element_decl.length == 8)
1196 and (element_decl.encoding == CTFStringEncoding.ASCII or element_decl.encoding == CTFStringEncoding.UTF8)):
1197 value = _bt_python_get_sequence_string(self._d)
1198 else:
1199 seq_len = self._get_sequence_len()
1200 value = []
1201 for i in range(seq_len):
1202 evDef = self._get_sequence_element_at(i)
1203 value.append(evDef.value)
78d714e8 1204 elif id == CTFTypeId.FLOAT:
8bb27181 1205 value = self._get_float()
78d714e8 1206 elif id == CTFTypeId.VARIANT:
8bb27181
JG
1207 variant = _Definition.__new__(_Definition)
1208 variant._d = self._get_variant();
78d714e8
JG
1209 value = variant.value
1210 elif id == CTFTypeId.STRUCT:
1211 value = {}
8bb27181
JG
1212 for i in range(self._get_struct_field_count()):
1213 member = _Definition(self._get_struct_field_at(i), self.scope)
78d714e8
JG
1214 value[member.name] = member.value
1215
1216 if field_error():
5792eb34 1217 raise FieldError("Error occurred while accessing field {} of type {}".format(self.name, CTFTypeId.type_name(id)))
78d714e8
JG
1218 return value
1219
1220 @property
1221 def scope(self):
1222 """Return the scope of a field or None on error."""
1223 return self._s
1224
24a3136a
DS
1225%}
1226
1227
ec8c88d7
JG
1228// =================================================================
1229// CTF Writer
1230// =================================================================
1231
1232/* =================================================================
1233 CLOCK.H
1234 ¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯
1235*/
1236%rename("_bt_ctf_clock_create") bt_ctf_clock_create(const char *name);
1237%rename("_bt_ctf_clock_set_description") bt_ctf_clock_set_description(struct bt_ctf_clock *clock, const char *desc);
1238%rename("_bt_ctf_clock_set_frequency") bt_ctf_clock_set_frequency(struct bt_ctf_clock *clock, uint64_t freq);
1239%rename("_bt_ctf_clock_set_precision") bt_ctf_clock_set_precision(struct bt_ctf_clock *clock, uint64_t precision);
1240%rename("_bt_ctf_clock_set_offset_s") bt_ctf_clock_set_offset_s(struct bt_ctf_clock *clock, uint64_t offset_s);
1241%rename("_bt_ctf_clock_set_offset") bt_ctf_clock_set_offset(struct bt_ctf_clock *clock, uint64_t offset);
1242%rename("_bt_ctf_clock_set_is_absolute") bt_ctf_clock_set_is_absolute(struct bt_ctf_clock *clock, int is_absolute);
1243%rename("_bt_ctf_clock_set_time") bt_ctf_clock_set_time(struct bt_ctf_clock *clock, uint64_t time);
1244%rename("_bt_ctf_clock_get") bt_ctf_clock_get(struct bt_ctf_clock *clock);
1245%rename("_bt_ctf_clock_put") bt_ctf_clock_put(struct bt_ctf_clock *clock);
1246
1247struct bt_ctf_clock *bt_ctf_clock_create(const char *name);
1248int bt_ctf_clock_set_description(struct bt_ctf_clock *clock, const char *desc);
1249int bt_ctf_clock_set_frequency(struct bt_ctf_clock *clock, uint64_t freq);
1250int bt_ctf_clock_set_precision(struct bt_ctf_clock *clock, uint64_t precision);
1251int bt_ctf_clock_set_offset_s(struct bt_ctf_clock *clock, uint64_t offset_s);
1252int bt_ctf_clock_set_offset(struct bt_ctf_clock *clock, uint64_t offset);
1253int bt_ctf_clock_set_is_absolute(struct bt_ctf_clock *clock, int is_absolute);
1254int bt_ctf_clock_set_time(struct bt_ctf_clock *clock, uint64_t time);
1255void bt_ctf_clock_get(struct bt_ctf_clock *clock);
1256void bt_ctf_clock_put(struct bt_ctf_clock *clock);
1257
1258/* =================================================================
1259 EVENT-TYPES.H
1260 ¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯
1261*/
1262%rename("_bt_ctf_field_type_integer_create") bt_ctf_field_type_integer_create(unsigned int size);
1263%rename("_bt_ctf_field_type_integer_set_signed") bt_ctf_field_type_integer_set_signed(struct bt_ctf_field_type *integer, int is_signed);
1264%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);
1265%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);
1266%rename("_bt_ctf_field_type_enumeration_create") bt_ctf_field_type_enumeration_create(struct bt_ctf_field_type *integer_container_type);
1267%rename("_bt_ctf_field_type_enumeration_add_mapping") bt_ctf_field_type_enumeration_add_mapping(struct bt_ctf_field_type *enumeration, const char *string, int64_t range_start, int64_t range_end);
1268%rename("_bt_ctf_field_type_floating_point_create") bt_ctf_field_type_floating_point_create(void);
1269%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);
1270%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);
1271%rename("_bt_ctf_field_type_structure_create") bt_ctf_field_type_structure_create(void);
1272%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);
1273%rename("_bt_ctf_field_type_variant_create") bt_ctf_field_type_variant_create(struct bt_ctf_field_type *enum_tag, const char *tag_name);
1274%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);
1275%rename("_bt_ctf_field_type_array_create") bt_ctf_field_type_array_create(struct bt_ctf_field_type *element_type, unsigned int length);
1276%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);
1277%rename("_bt_ctf_field_type_string_create") bt_ctf_field_type_string_create(void);
1278%rename("_bt_ctf_field_type_string_set_encoding") bt_ctf_field_type_string_set_encoding(struct bt_ctf_field_type *string, enum ctf_string_encoding encoding);
1279%rename("_bt_ctf_field_type_set_alignment") bt_ctf_field_type_set_alignment(struct bt_ctf_field_type *type, unsigned int alignment);
1280%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);
1281%rename("_bt_ctf_field_type_get") bt_ctf_field_type_get(struct bt_ctf_field_type *type);
1282%rename("_bt_ctf_field_type_put") bt_ctf_field_type_put(struct bt_ctf_field_type *type);
1283
1284struct bt_ctf_field_type *bt_ctf_field_type_integer_create(unsigned int size);
1285int bt_ctf_field_type_integer_set_signed(struct bt_ctf_field_type *integer, int is_signed);
1286int bt_ctf_field_type_integer_set_base(struct bt_ctf_field_type *integer, enum bt_ctf_integer_base base);
1287int bt_ctf_field_type_integer_set_encoding(struct bt_ctf_field_type *integer, enum ctf_string_encoding encoding);
1288struct bt_ctf_field_type *bt_ctf_field_type_enumeration_create(struct bt_ctf_field_type *integer_container_type);
1289int bt_ctf_field_type_enumeration_add_mapping(struct bt_ctf_field_type *enumeration, const char *string, int64_t range_start, int64_t range_end);
1290struct bt_ctf_field_type *bt_ctf_field_type_floating_point_create(void);
1291int bt_ctf_field_type_floating_point_set_exponent_digits(struct bt_ctf_field_type *floating_point, unsigned int exponent_digits);
1292int bt_ctf_field_type_floating_point_set_mantissa_digits(struct bt_ctf_field_type *floating_point, unsigned int mantissa_digits);
1293struct bt_ctf_field_type *bt_ctf_field_type_structure_create(void);
1294int bt_ctf_field_type_structure_add_field(struct bt_ctf_field_type *structure, struct bt_ctf_field_type *field_type, const char *field_name);
1295struct bt_ctf_field_type *bt_ctf_field_type_variant_create(struct bt_ctf_field_type *enum_tag, const char *tag_name);
1296int bt_ctf_field_type_variant_add_field(struct bt_ctf_field_type *variant, struct bt_ctf_field_type *field_type, const char *field_name);
1297struct bt_ctf_field_type *bt_ctf_field_type_array_create(struct bt_ctf_field_type *element_type, unsigned int length);
1298struct bt_ctf_field_type *bt_ctf_field_type_sequence_create(struct bt_ctf_field_type *element_type, const char *length_field_name);
1299struct bt_ctf_field_type *bt_ctf_field_type_string_create(void);
1300int bt_ctf_field_type_string_set_encoding(struct bt_ctf_field_type *string, enum ctf_string_encoding encoding);
1301int bt_ctf_field_type_set_alignment(struct bt_ctf_field_type *type, unsigned int alignment);
1302int bt_ctf_field_type_set_byte_order(struct bt_ctf_field_type *type, enum bt_ctf_byte_order byte_order);
1303void bt_ctf_field_type_get(struct bt_ctf_field_type *type);
1304void bt_ctf_field_type_put(struct bt_ctf_field_type *type);
1305
1306/* =================================================================
1307 EVENT-FIELDS.H
1308 ¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯
1309*/
1310%rename("_bt_ctf_field_create") bt_ctf_field_create(struct bt_ctf_field_type *type);
1311%rename("_bt_ctf_field_structure_get_field") bt_ctf_field_structure_get_field(struct bt_ctf_field *structure, const char *name);
1312%rename("_bt_ctf_field_array_get_field") bt_ctf_field_array_get_field(struct bt_ctf_field *array, uint64_t index);
1313%rename("_bt_ctf_field_sequence_set_length") bt_ctf_field_sequence_set_length(struct bt_ctf_field *sequence, struct bt_ctf_field *length_field);
1314%rename("_bt_ctf_field_sequence_get_field") bt_ctf_field_sequence_get_field(struct bt_ctf_field *sequence, uint64_t index);
1315%rename("_bt_ctf_field_variant_get_field") bt_ctf_field_variant_get_field(struct bt_ctf_field *variant, struct bt_ctf_field *tag);
1316%rename("_bt_ctf_field_enumeration_get_container") bt_ctf_field_enumeration_get_container(struct bt_ctf_field *enumeration);
1317%rename("_bt_ctf_field_signed_integer_set_value") bt_ctf_field_signed_integer_set_value(struct bt_ctf_field *integer, int64_t value);
1318%rename("_bt_ctf_field_unsigned_integer_set_value") bt_ctf_field_unsigned_integer_set_value(struct bt_ctf_field *integer, uint64_t value);
1319%rename("_bt_ctf_field_floating_point_set_value") bt_ctf_field_floating_point_set_value(struct bt_ctf_field *floating_point, double value);
1320%rename("_bt_ctf_field_string_set_value") bt_ctf_field_string_set_value(struct bt_ctf_field *string, const char *value);
1321%rename("_bt_ctf_field_get") bt_ctf_field_get(struct bt_ctf_field *field);
1322%rename("_bt_ctf_field_put") bt_ctf_field_put(struct bt_ctf_field *field);
1323
1324struct bt_ctf_field *bt_ctf_field_create(struct bt_ctf_field_type *type);
1325struct bt_ctf_field *bt_ctf_field_structure_get_field(struct bt_ctf_field *structure, const char *name);
1326struct bt_ctf_field *bt_ctf_field_array_get_field(struct bt_ctf_field *array, uint64_t index);
1327int bt_ctf_field_sequence_set_length(struct bt_ctf_field *sequence, struct bt_ctf_field *length_field);
1328struct bt_ctf_field *bt_ctf_field_sequence_get_field(struct bt_ctf_field *sequence, uint64_t index);
1329struct bt_ctf_field *bt_ctf_field_variant_get_field(struct bt_ctf_field *variant, struct bt_ctf_field *tag);
1330struct bt_ctf_field *bt_ctf_field_enumeration_get_container(struct bt_ctf_field *enumeration);
1331int bt_ctf_field_signed_integer_set_value(struct bt_ctf_field *integer, int64_t value);
1332int bt_ctf_field_unsigned_integer_set_value(struct bt_ctf_field *integer, uint64_t value);
1333int bt_ctf_field_floating_point_set_value(struct bt_ctf_field *floating_point, double value);
1334int bt_ctf_field_string_set_value(struct bt_ctf_field *string, const char *value);
1335void bt_ctf_field_get(struct bt_ctf_field *field);
1336void bt_ctf_field_put(struct bt_ctf_field *field);
1337
1338/* =================================================================
1339 EVENT.H
1340 ¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯
1341*/
1342%rename("_bt_ctf_event_class_create") bt_ctf_event_class_create(const char *name);
1343%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);
1344%rename("_bt_ctf_event_class_get") bt_ctf_event_class_get(struct bt_ctf_event_class *event_class);
1345%rename("_bt_ctf_event_class_put") bt_ctf_event_class_put(struct bt_ctf_event_class *event_class);
1346%rename("_bt_ctf_event_create") bt_ctf_event_create(struct bt_ctf_event_class *event_class);
1347%rename("_bt_ctf_event_set_payload") bt_ctf_event_set_payload(struct bt_ctf_event *event, const char *name, struct bt_ctf_field *value);
1348%rename("_bt_ctf_event_get_payload") bt_ctf_event_get_payload(struct bt_ctf_event *event, const char *name);
1349%rename("_bt_ctf_event_get") bt_ctf_event_get(struct bt_ctf_event *event);
1350%rename("_bt_ctf_event_put") bt_ctf_event_put(struct bt_ctf_event *event);
1351
1352struct bt_ctf_event_class *bt_ctf_event_class_create(const char *name);
1353int bt_ctf_event_class_add_field(struct bt_ctf_event_class *event_class, struct bt_ctf_field_type *type, const char *name);
1354void bt_ctf_event_class_get(struct bt_ctf_event_class *event_class);
1355void bt_ctf_event_class_put(struct bt_ctf_event_class *event_class);
1356struct bt_ctf_event *bt_ctf_event_create(struct bt_ctf_event_class *event_class);
1357int bt_ctf_event_set_payload(struct bt_ctf_event *event, const char *name, struct bt_ctf_field *value);
1358struct bt_ctf_field *bt_ctf_event_get_payload(struct bt_ctf_event *event, const char *name);
1359void bt_ctf_event_get(struct bt_ctf_event *event);
1360void bt_ctf_event_put(struct bt_ctf_event *event);
1361
1362/* =================================================================
1363 STREAM.H
1364 ¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯
1365*/
1366%rename("_bt_ctf_stream_class_create") bt_ctf_stream_class_create(const char *name);
1367%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);
1368%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);
1369%rename("_bt_ctf_stream_class_get") bt_ctf_stream_class_get(struct bt_ctf_stream_class *stream_class);
1370%rename("_bt_ctf_stream_class_put") bt_ctf_stream_class_put(struct bt_ctf_stream_class *stream_class);
1371%rename("_bt_ctf_stream_append_discarded_events") bt_ctf_stream_append_discarded_events(struct bt_ctf_stream *stream, uint64_t event_count);
1372%rename("_bt_ctf_stream_append_event") bt_ctf_stream_append_event(struct bt_ctf_stream *stream, struct bt_ctf_event *event);
1373%rename("_bt_ctf_stream_flush") bt_ctf_stream_flush(struct bt_ctf_stream *stream);
1374%rename("_bt_ctf_stream_get") bt_ctf_stream_get(struct bt_ctf_stream *stream);
1375%rename("_bt_ctf_stream_put") bt_ctf_stream_put(struct bt_ctf_stream *stream);
1376
1377struct bt_ctf_stream_class *bt_ctf_stream_class_create(const char *name);
1378int bt_ctf_stream_class_set_clock(struct bt_ctf_stream_class *stream_class, struct bt_ctf_clock *clock);
1379int bt_ctf_stream_class_add_event_class(struct bt_ctf_stream_class *stream_class, struct bt_ctf_event_class *event_class);
1380void bt_ctf_stream_class_get(struct bt_ctf_stream_class *stream_class);
1381void bt_ctf_stream_class_put(struct bt_ctf_stream_class *stream_class);
1382void bt_ctf_stream_append_discarded_events(struct bt_ctf_stream *stream, uint64_t event_count);
1383int bt_ctf_stream_append_event(struct bt_ctf_stream *stream, struct bt_ctf_event *event);
1384int bt_ctf_stream_flush(struct bt_ctf_stream *stream);
1385void bt_ctf_stream_get(struct bt_ctf_stream *stream);
1386void bt_ctf_stream_put(struct bt_ctf_stream *stream);
1387
1388/* =================================================================
1389 WRITER.H
1390 ¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯
1391*/
1392%rename("_bt_ctf_writer_create") bt_ctf_writer_create(const char *path);
1393%rename("_bt_ctf_writer_create_stream") bt_ctf_writer_create_stream(struct bt_ctf_writer *writer, struct bt_ctf_stream_class *stream_class);
1394%rename("_bt_ctf_writer_add_environment_field") bt_ctf_writer_add_environment_field(struct bt_ctf_writer *writer, const char *name, const char *value);
1395%rename("_bt_ctf_writer_add_clock") bt_ctf_writer_add_clock(struct bt_ctf_writer *writer, struct bt_ctf_clock *clock);
1396%newobject bt_ctf_writer_get_metadata_string;
1397%rename("_bt_ctf_writer_get_metadata_string") bt_ctf_writer_get_metadata_string(struct bt_ctf_writer *writer);
1398%rename("_bt_ctf_writer_flush_metadata") bt_ctf_writer_flush_metadata(struct bt_ctf_writer *writer);
1399%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);
1400%rename("_bt_ctf_writer_get") bt_ctf_writer_get(struct bt_ctf_writer *writer);
1401%rename("_bt_ctf_writer_put") bt_ctf_writer_put(struct bt_ctf_writer *writer);
1402
1403struct bt_ctf_writer *bt_ctf_writer_create(const char *path);
1404struct bt_ctf_stream *bt_ctf_writer_create_stream(struct bt_ctf_writer *writer, struct bt_ctf_stream_class *stream_class);
1405int bt_ctf_writer_add_environment_field(struct bt_ctf_writer *writer, const char *name, const char *value);
1406int bt_ctf_writer_add_clock(struct bt_ctf_writer *writer, struct bt_ctf_clock *clock);
1407char *bt_ctf_writer_get_metadata_string(struct bt_ctf_writer *writer);
1408void bt_ctf_writer_flush_metadata(struct bt_ctf_writer *writer);
1409int bt_ctf_writer_set_byte_order(struct bt_ctf_writer *writer, enum bt_ctf_byte_order byte_order);
1410void bt_ctf_writer_get(struct bt_ctf_writer *writer);
1411void bt_ctf_writer_put(struct bt_ctf_writer *writer);
1412
1413%pythoncode %{
1414
1415class CTFWriter:
ec8c88d7
JG
1416
1417 class Clock:
1418 def __init__(self, name):
1419 self._c = _bt_ctf_clock_create(name)
1420 if self._c is None:
1421 raise ValueError("Invalid clock name.")
1422
1423 def __del__(self):
1424 _bt_ctf_clock_put(self._c)
1425
14001277
JG
1426 """
1427 Get the clock's description.
1428 """
1429 @property
1430 def description(self):
1431 raise NotImplementedError("Getter not implemented.")
1432
ec8c88d7
JG
1433 """
1434 Set the clock's description. The description appears in the clock's TSDL
1435 meta-data.
1436 """
14001277
JG
1437 @description.setter
1438 def description(self, desc):
1439 ret = _bt_ctf_clock_set_description(self._c, str(desc))
ec8c88d7
JG
1440 if ret < 0:
1441 raise ValueError("Invalid clock description.")
1442
14001277
JG
1443 """
1444 Get the clock's frequency (Hz).
1445 """
1446 @property
1447 def frequency(self):
1448 raise NotImplementedError("Getter not implemented.")
1449
ec8c88d7
JG
1450 """
1451 Set the clock's frequency (Hz).
1452 """
14001277
JG
1453 @frequency.setter
1454 def frequency(self, freq):
ec8c88d7
JG
1455 ret = _bt_ctf_clock_set_frequency(self._c, freq)
1456 if ret < 0:
1457 raise ValueError("Invalid frequency value.")
1458
14001277
JG
1459 """
1460 Get the clock's precision (in clock ticks).
1461 """
1462 @property
1463 def precision(self):
1464 raise NotImplementedError("Getter not implemented.")
1465
ec8c88d7
JG
1466 """
1467 Set the clock's precision (in clock ticks).
1468 """
14001277
JG
1469 @precision.setter
1470 def precision(self, precision):
ec8c88d7
JG
1471 ret = _bt_ctf_clock_set_precision(self._c, precision)
1472
14001277
JG
1473 """
1474 Get the clock's offset in seconds from POSIX.1 Epoch.
1475 """
1476 @property
1477 def offset_seconds(self):
1478 raise NotImplementedError("Getter not implemented.")
1479
ec8c88d7
JG
1480 """
1481 Set the clock's offset in seconds from POSIX.1 Epoch.
1482 """
14001277
JG
1483 @offset_seconds.setter
1484 def offset_seconds(self, offset_s):
ec8c88d7
JG
1485 ret = _bt_ctf_clock_set_offset_s(self._c, offset_s)
1486 if ret < 0:
1487 raise ValueError("Invalid offset value.")
1488
14001277
JG
1489 """
1490 Get the clock's offset in ticks from POSIX.1 Epoch + offset in seconds.
1491 """
1492 @property
1493 def offset(self):
1494 raise NotImplementedError("Getter not implemented.")
1495
ec8c88d7
JG
1496 """
1497 Set the clock's offset in ticks from POSIX.1 Epoch + offset in seconds.
1498 """
14001277
JG
1499 @offset.setter
1500 def offset(self, offset):
ec8c88d7
JG
1501 ret = _bt_ctf_clock_set_offset(self._c, offset)
1502 if ret < 0:
1503 raise ValueError("Invalid offset value.")
1504
14001277
JG
1505 """
1506 Get a clock's absolute attribute. A clock is absolute if the clock
1507 is a global reference across the trace's other clocks.
1508 """
1509 @property
1510 def absolute(self):
1511 raise NotImplementedError("Getter not implemented.")
1512
ec8c88d7
JG
1513 """
1514 Set a clock's absolute attribute. A clock is absolute if the clock
1515 is a global reference across the trace's other clocks.
1516 """
14001277
JG
1517 @absolute.setter
1518 def absolute(self, is_absolute):
1519 ret = _bt_ctf_clock_set_is_absolute(self._c, int(is_absolute))
ec8c88d7
JG
1520 if ret < 0:
1521 raise ValueError("Could not set the clock's absolute attribute.")
1522
14001277
JG
1523 """
1524 Get the current time in nanoseconds since the clock's origin (offset and
1525 offset_s attributes).
1526 """
1527 @property
1528 def time(self):
1529 raise NotImplementedError("Getter not implemented.")
1530
ec8c88d7
JG
1531 """
1532 Set the current time in nanoseconds since the clock's origin (offset and
1533 offset_s attributes). The clock's value will be sampled as events are
1534 appended to a stream.
1535 """
14001277
JG
1536 @time.setter
1537 def time(self, time):
ec8c88d7
JG
1538 ret = _bt_ctf_clock_set_time(self._c, time)
1539 if ret < 0:
1540 raise ValueError("Invalid time value.")
1541
14001277 1542 class FieldDeclaration:
ec8c88d7 1543 """
14001277
JG
1544 FieldDeclaration should not be instantiated directly. Please instantiate
1545 one of the concrete FieldDeclaration classes.
ec8c88d7
JG
1546 """
1547 class IntegerBase:
1548 # These values are based on the bt_ctf_integer_base enum
1549 # declared in event-types.h.
1550 INTEGER_BASE_UNKNOWN = -1
1551 INTEGER_BASE_BINARY = 2
1552 INTEGER_BASE_OCTAL = 8
1553 INTEGER_BASE_DECIMAL = 10
1554 INTEGER_BASE_HEXADECIMAL = 16
1555
1556 def __init__(self):
1557 if self._ft is None:
14001277 1558 raise ValueError("FieldDeclaration creation failed.")
ec8c88d7
JG
1559
1560 def __del__(self):
1561 _bt_ctf_field_type_put(self._ft)
1562
14001277
JG
1563 """
1564 Get the field type's alignment.
1565 """
1566 @property
1567 def alignment(self):
1568 raise NotImplementedError("Getter not implemented.")
1569
ec8c88d7
JG
1570 """
1571 Set the field type's alignment. Defaults to 1 (bit-aligned). However,
1572 some types, such as structures and string, may impose other alignment
1573 constraints.
1574 """
14001277
JG
1575 @alignment.setter
1576 def alignment(self, alignment):
ec8c88d7
JG
1577 ret = _bt_ctf_field_type_set_alignment(self._ft, alignment)
1578 if ret < 0:
1579 raise ValueError("Invalid alignment value.")
1580
14001277
JG
1581 """
1582 Get the field type's byte order. One of the ByteOrder's constant.
1583 """
1584 @property
1585 def byte_order(self):
1586 raise NotImplementedError("Getter not implemented.")
1587
ec8c88d7
JG
1588 """
1589 Set the field type's byte order. Use constants defined in the ByteOrder
1590 class.
1591 """
14001277
JG
1592 @byte_order.setter
1593 def byte_order(self, byte_order):
ec8c88d7
JG
1594 ret = _bt_ctf_field_type_set_byte_order(self._ft, byte_order)
1595 if ret < 0:
1596 raise ValueError("Could not set byte order value.")
1597
14001277 1598 class IntegerFieldDeclaration(FieldDeclaration):
ec8c88d7
JG
1599 """
1600 Create a new integer field type of the given size.
1601 """
1602 def __init__(self, size):
1603 self._ft = _bt_ctf_field_type_integer_create(size)
1604 super().__init__()
1605
1606 """
14001277
JG
1607 Get an integer's signedness attribute.
1608 """
1609 @property
1610 def signed(self):
1611 raise NotImplementedError("Getter not implemented.")
1612
1613 """
1614 Set an integer's signedness attribute.
ec8c88d7 1615 """
14001277
JG
1616 @signed.setter
1617 def signed(self, signed):
ec8c88d7
JG
1618 ret = _bt_ctf_field_type_integer_set_signed(self._ft, signed)
1619 if ret < 0:
1620 raise ValueError("Could not set signed attribute.")
1621
1622 """
14001277
JG
1623 Get the integer's base used to pretty-print the resulting trace.
1624 """
1625 @property
1626 def base(self):
1627 raise NotImplementedError("Getter not implemented.")
1628
1629 """
1630 Set the integer's base used to pretty-print the resulting trace.
ec8c88d7
JG
1631 The base must be a constant of the IntegerBase class.
1632 """
14001277
JG
1633 @base.setter
1634 def base(self, base):
ec8c88d7
JG
1635 ret = _bt_ctf_field_type_integer_set_base(self._ft, base)
1636 if ret < 0:
1637 raise ValueError("Could not set base value.")
1638
14001277
JG
1639 """
1640 Get the integer's encoding (one of the constants of the
1641 CTFStringEncoding class).
1642 """
1643 @property
1644 def encoding(self):
1645 raise NotImplementedError("Getter not implemented.")
1646
ec8c88d7
JG
1647 """
1648 An integer encoding may be set to signal that the integer must be printed
1649 as a text character. Must be a constant from the CTFStringEncoding class.
1650 """
14001277
JG
1651 @encoding.setter
1652 def encoding(self, encoding):
ec8c88d7
JG
1653 ret = _bt_ctf_field_type_integer_set_encoding(self._ft, encoding)
1654 if ret < 0:
1655 raise ValueError("Could not set integer encoding.")
1656
14001277 1657 class EnumerationFieldDeclaration(FieldDeclaration):
ec8c88d7
JG
1658 """
1659 Create a new enumeration field type with the given underlying type.
1660 """
1661 def __init__(self, integer_type):
14001277 1662 if integer_type is None or not isinstance(integer_type, CTFWriter.IntegerFieldDeclaration):
ec8c88d7
JG
1663 raise TypeError("Invalid integer container.")
1664
1665 self._ft = _bt_ctf_field_type_enumeration_create(integer_type._ft)
1666 super().__init__()
1667
1668 """
1669 Add a mapping to the enumeration. The range's values are inclusive.
1670 """
1671 def add_mapping(self, name, range_start, range_end):
14001277 1672 ret = _bt_ctf_field_type_enumeration_add_mapping(self._ft, str(name), range_start, range_end)
ec8c88d7
JG
1673 if ret < 0:
1674 raise ValueError("Could not add mapping to enumeration type.")
1675
14001277 1676 class FloatFieldDeclaration(FieldDeclaration):
ec8c88d7
JG
1677 FLT_EXP_DIG = 8
1678 DBL_EXP_DIG = 11
1679 FLT_MANT_DIG = 24
1680 DBL_MANT_DIG = 53
1681
1682 """
1683 Create a new floating point field type.
1684 """
1685 def __init__(self):
1686 self._ft = _bt_ctf_field_type_floating_point_create()
1687 super().__init__()
1688
1689 """
14001277
JG
1690 Get the number of exponent digits to use to store the floating point field.
1691 """
1692 @property
1693 def exponent_digits(self):
1694 raise NotImplementedError("Getter not implemented.")
1695
1696 """
1697 Set the number of exponent digits to use to store the floating point field.
ec8c88d7
JG
1698 The only values currently supported are FLT_EXP_DIG and DBL_EXP_DIG which
1699 are defined as constants of this class.
1700 """
14001277
JG
1701 @exponent_digits.setter
1702 def exponent_digits(self, exponent_digits):
ec8c88d7
JG
1703 ret = _bt_ctf_field_type_floating_point_set_exponent_digits(self._ft, exponent_digits)
1704 if ret < 0:
1705 raise ValueError("Could not set exponent digit count.")
1706
1707 """
14001277
JG
1708 Get the number of mantissa digits to use to store the floating point field.
1709 """
1710 @property
1711 def mantissa_digits(self):
1712 raise NotImplementedError("Getter not implemented.")
1713
1714 """
1715 Set the number of mantissa digits to use to store the floating point field.
ec8c88d7
JG
1716 The only values currently supported are FLT_MANT_DIG and DBL_MANT_DIG which
1717 are defined as constants of this class.
1718 """
14001277
JG
1719 @mantissa_digits.setter
1720 def mantissa_digits(self, mantissa_digits):
ec8c88d7
JG
1721 ret = _bt_ctf_field_type_floating_point_set_mantissa_digits(self._ft, mantissa_digits)
1722 if ret < 0:
1723 raise ValueError("Could not set mantissa digit count.")
1724
14001277 1725 class StructureFieldDeclaration(FieldDeclaration):
ec8c88d7
JG
1726 """
1727 Create a new structure field type.
1728 """
1729 def __init__(self):
1730 self._ft = _bt_ctf_field_type_structure_create()
1731 super().__init__()
1732
1733 """
1734 Add a field of type "field_type" to the structure.
1735 """
1736 def add_field(self, field_type, field_name):
14001277 1737 ret = _bt_ctf_field_type_structure_add_field(self._ft, field_type._ft, str(field_name))
ec8c88d7
JG
1738 if ret < 0:
1739 raise ValueError("Could not add field to structure.")
1740
14001277 1741 class VariantFieldDeclaration(FieldDeclaration):
ec8c88d7
JG
1742 """
1743 Create a new variant field type.
1744 """
1745 def __init__(self, enum_tag, tag_name):
14001277
JG
1746 if enum_tag is None or not isinstance(enum_tag, CTFWriter.EnumerationFieldDeclaration):
1747 raise TypeError("Invalid tag type; must be of type EnumerationFieldDeclaration.")
ec8c88d7 1748
14001277 1749 self._ft = _bt_ctf_field_type_variant_create(enum_tag._ft, str(tag_name))
ec8c88d7
JG
1750 super().__init__()
1751
1752 """
1753 Add a field of type "field_type" to the variant.
1754 """
1755 def add_field(self, field_type, field_name):
14001277 1756 ret = _bt_ctf_field_type_variant_add_field(self._ft, field_type._ft, str(field_name))
ec8c88d7
JG
1757 if ret < 0:
1758 raise ValueError("Could not add field to variant.")
1759
14001277 1760 class ArrayFieldDeclaration(FieldDeclaration):
ec8c88d7
JG
1761 """
1762 Create a new array field type.
1763 """
1764 def __init__(self, element_type, length):
1765 self._ft = _bt_ctf_field_type_array_create(element_type._ft, length)
1766 super().__init__()
1767
14001277 1768 class SequenceFieldDeclaration(FieldDeclaration):
ec8c88d7
JG
1769 """
1770 Create a new sequence field type.
1771 """
1772 def __init__(self, element_type, length_field_name):
14001277 1773 self._ft = _bt_ctf_field_type_sequence_create(element_type._ft, str(length_field_name))
ec8c88d7
JG
1774 super().__init__()
1775
14001277 1776 class StringFieldDeclaration(FieldDeclaration):
ec8c88d7
JG
1777 """
1778 Create a new string field type.
1779 """
1780 def __init__(self):
1781 self._ft = _bt_ctf_field_type_string_create()
1782 super().__init__()
1783
14001277
JG
1784 """
1785 Get a string type's encoding (a constant from the CTFStringEncoding class).
1786 """
1787 @property
1788 def encoding(self):
1789 raise NotImplementedError("Getter not implemented.")
1790
ec8c88d7
JG
1791 """
1792 Set a string type's encoding. Must be a constant from the CTFStringEncoding class.
1793 """
14001277
JG
1794 @encoding.setter
1795 def encoding(self, encoding):
ec8c88d7
JG
1796 ret = _bt_ctf_field_type_string_set_encoding(self._ft, encoding)
1797 if ret < 0:
1798 raise ValueError("Could not set string encoding.")
1799
1800 """
1801 Create an instance of a field.
1802 """
1803 @staticmethod
1804 def create_field(self, field_type):
14001277
JG
1805 if field_type is None or not isinstance(field_type, CTFWriter.FieldDeclaration):
1806 raise TypeError("Invalid field_type. Type must be a FieldDeclaration-derived class.")
1807
1808 if isinstance(field_type, CTFWriter.IntegerFieldDeclaration):
1809 return CTFWriter.IntegerField(field_type)
1810 elif isinstance(field_type, CTFWriter.EnumerationFieldDeclaration):
1811 return CTFWriter.EnumerationField(field_type)
1812 elif isinstance(field_type, CTFWriter.FloatFieldDeclaration):
1813 return CTFWriter.FloatFieldingPoint(field_type)
1814 elif isinstance(field_type, CTFWriter.StructureFieldDeclaration):
1815 return CTFWriter.StructureField(field_type)
1816 elif isinstance(field_type, CTFWriter.VariantFieldDeclaration):
1817 return CTFWriter.VariantField(field_type)
1818 elif isinstance(field_type, CTFWriter.ArrayFieldDeclaration):
1819 return CTFWriter.ArrayField(field_type)
1820 elif isinstance(field_type, CTFWriter.SequenceFieldDeclaration):
1821 return CTFWriter.SequenceField(field_type)
1822 elif isinstance(field_type, CTFWriter.StringFieldDeclaration):
1823 return CTFWriter.StringField(field_type)
ec8c88d7
JG
1824
1825 class Field:
1826 """
1827 Base class, do not instantiate.
1828 """
1829 def __init__(self, field_type):
14001277 1830 if not isinstance(field_type, CTFWriter.FieldDeclaration):
ec8c88d7
JG
1831 raise TypeError("Invalid field_type argument.")
1832
1833 self._f = _bt_ctf_field_create(field_type._ft)
1834 if self._f is None:
1835 raise ValueError("Field creation failed.")
1836
1837 def __del__(self):
1838 _bt_ctf_field_put(self._f)
1839
1840 @staticmethod
1841 def _create_field_from_native_instance(native_field_instance):
1842 type_dict = {
14001277
JG
1843 CTFTypeId.INTEGER : CTFWriter.IntegerField,
1844 CTFTypeId.FLOAT : CTFWriter.FloatFieldingPoint,
1845 CTFTypeId.ENUM : CTFWriter.EnumerationField,
1846 CTFTypeId.STRING : CTFWriter.StringField,
1847 CTFTypeId.STRUCT : CTFWriter.StructureField,
1848 CTFTypeId.VARIANT : CTFWriter.VariantField,
1849 CTFTypeId.ARRAY : CTFWriter.ArrayField,
1850 CTFTypeId.SEQUENCE : CTFWriter.SequenceField
ec8c88d7
JG
1851 }
1852
1853 field_type = _bt_python_get_field_type(native_field_instance)
1854 if field_type == CTFTypeId.UNKNOWN:
1855 raise TypeError("Invalid field instance")
1856
1857 field = CTFWriter.Field.__new__(CTFWriter.Field)
1858 field._f = native_field_instance
1859 field.__class__ = type_dict[field_type]
1860 return field
1861
14001277
JG
1862 class IntegerField(Field):
1863 """
1864 Get an integer field's value.
1865 """
1866 @property
1867 def value(self):
1868 raise NotImplementedError("Getter not implemented.")
1869
ec8c88d7
JG
1870 """
1871 Set an integer field's value.
1872 """
14001277
JG
1873 @value.setter
1874 def value(self, value):
ec8c88d7
JG
1875 signedness = _bt_python_field_integer_get_signedness(self._f)
1876 if signedness < 0:
1877 raise TypeError("Invalid integer instance.")
1878
1879 if signedness == 0:
1880 ret = _bt_ctf_field_unsigned_integer_set_value(self._f, value)
1881 else:
1882 ret = _bt_ctf_field_signed_integer_set_value(self._f, value)
1883
1884 if ret < 0:
1885 raise ValueError("Could not set integer field value.")
1886
14001277 1887 class EnumerationField(Field):
ec8c88d7
JG
1888 """
1889 Return the enumeration's underlying container field (an integer field).
1890 """
14001277
JG
1891 @property
1892 def container(self):
1893 container = CTFWriter.IntegerField.__new__(CTFWriter.IntegerField)
ec8c88d7
JG
1894 container._f = _bt_ctf_field_enumeration_get_container(self._f)
1895 if container._f is None:
1896 raise TypeError("Invalid enumeration field type.")
1897 return container
1898
14001277
JG
1899 class FloatFieldingPoint(Field):
1900 """
1901 Get a floating point field's value.
1902 """
1903 @property
1904 def value(self):
1905 raise NotImplementedError("Getter not implemented.")
1906
ec8c88d7
JG
1907 """
1908 Set a floating point field's value.
1909 """
14001277
JG
1910 @value.setter
1911 def value(self, value):
1912 ret = _bt_ctf_field_floating_point_set_value(self._f, float(value))
ec8c88d7
JG
1913 if ret < 0:
1914 raise ValueError("Could not set floating point field value.")
1915
14001277 1916 class StructureField(Field):
ec8c88d7
JG
1917 """
1918 Get the structure's field corresponding to the provided field name.
1919 """
14001277
JG
1920 def field(self, field_name):
1921 native_instance = _bt_ctf_field_structure_get_field(self._f, str(field_name))
ec8c88d7
JG
1922 if native_instance is None:
1923 raise ValueError("Invalid field_name provided.")
1924 return CTFWriter.Field._create_field_from_native_instance(native_instance)
1925
14001277 1926 class VariantField(Field):
ec8c88d7
JG
1927 """
1928 Return the variant's selected field. The "tag" field is the selector enum field.
1929 """
14001277 1930 def field(self, tag):
ec8c88d7
JG
1931 native_instance = _bt_ctf_field_variant_get_field(self._f, tag._f)
1932 if native_instance is None:
1933 raise ValueError("Invalid tag provided.")
1934 return CTFWriter.Field._create_field_from_native_instance(native_instance)
1935
14001277 1936 class ArrayField(Field):
ec8c88d7
JG
1937 """
1938 Return the array's field at position "index".
1939 """
14001277 1940 def field(self, index):
ec8c88d7
JG
1941 native_instance = _bt_ctf_field_array_get_field(self._f, index)
1942 if native_instance is None:
1943 raise IndexError("Invalid index provided.")
1944 return CTFWriter.Field._create_field_from_native_instance(native_instance)
1945
14001277
JG
1946 class SequenceField(Field):
1947 """
1948 Get the sequence's length field (IntegerField).
1949 """
1950 @property
1951 def length(self):
1952 raise NotImplementedError("Getter not implemented.")
1953
ec8c88d7
JG
1954 """
1955 Set the sequence's length field (IntegerField).
1956 """
14001277
JG
1957 @length.setter
1958 def length(self, length_field):
46395f8f 1959 if not isinstance(length_field, CTFWriter.IntegerField):
ec8c88d7 1960 raise TypeError("Invalid length field.")
46395f8f 1961 ret = _bt_ctf_field_sequence_set_length(self._f, length_field._f)
ec8c88d7
JG
1962 if ret < 0:
1963 raise ValueError("Could not set sequence length.")
1964
1965 """
1966 Return the sequence's field at position "index".
1967 """
14001277 1968 def field(self, index):
ec8c88d7
JG
1969 native_instance = _bt_ctf_field_sequence_get_field(self._f, index)
1970 if native_instance is None:
1971 raise ValueError("Could not get sequence element at index.")
1972 return CTFWriter.Field._create_field_from_native_instance(native_instance)
1973
14001277
JG
1974 class StringField(Field):
1975 """
1976 Get a string field's value.
1977 """
1978 @property
1979 def value(self):
1980 raise NotImplementedError("Getter not implemented.")
1981
ec8c88d7
JG
1982 """
1983 Set a string field's value.
1984 """
14001277
JG
1985 @value.setter
1986 def value(self, value):
1987 ret = _bt_ctf_field_string_set_value(self._f, str(value))
ec8c88d7
JG
1988 if ret < 0:
1989 raise ValueError("Could not set string field value.")
1990
1991 class EventClass:
1992 """
1993 Create a new event class of the given name.
1994 """
1995 def __init__(self, name):
1996 self._ec = _bt_ctf_event_class_create(name)
1997 if self._ec is None:
1998 raise ValueError("Event class creation failed.")
1999
2000 def __del__(self):
2001 _bt_ctf_event_class_put(self._ec)
2002
2003 """
2004 Add a field of type "field_type" to the event class.
2005 """
2006 def add_field(self, field_type, field_name):
14001277 2007 ret = _bt_ctf_event_class_add_field(self._ec, field_type._ft, str(field_name))
ec8c88d7
JG
2008 if ret < 0:
2009 raise ValueError("Could not add field to event class.")
2010
2011 class Event:
2012 """
2013 Create a new event of the given event class.
2014 """
2015 def __init__(self, event_class):
2016 if not isinstance(event_class, CTFWriter.EventClass):
2017 raise TypeError("Invalid event_class argument.")
2018
2019 self._e = _bt_ctf_event_create(event_class._ec)
2020 if self._e is None:
2021 raise ValueError("Event creation failed.")
2022
2023 def __del__(self):
2024 _bt_ctf_event_put(self._e)
2025
2026 """
2027 Set a manually created field as an event's payload.
2028 """
14001277 2029 def set_payload(self, field_name, value_field):
ec8c88d7
JG
2030 if not isinstance(value, CTFWriter.Field):
2031 raise TypeError("Invalid value type.")
46395f8f 2032 ret = _bt_ctf_event_set_payload(self._e, str(field_name), value_field._f)
ec8c88d7
JG
2033 if ret < 0:
2034 raise ValueError("Could not set event field payload.")
2035
2036 """
14001277 2037 Get a field from event.
ec8c88d7 2038 """
14001277
JG
2039 def payload(self, field_name):
2040 native_instance = _bt_ctf_event_get_payload(self._e, str(field_name))
ec8c88d7
JG
2041 if native_instance is None:
2042 raise ValueError("Could not get event payload.")
2043 return CTFWriter.Field._create_field_from_native_instance(native_instance)
2044
2045 class StreamClass:
2046 """
2047 Create a new stream class of the given name.
2048 """
2049 def __init__(self, name):
2050 self._sc = _bt_ctf_stream_class_create(name)
2051 if self._sc is None:
2052 raise ValueError("Stream class creation failed.")
2053
2054 def __del__(self):
2055 _bt_ctf_stream_class_put(self._sc)
2056
14001277
JG
2057 """
2058 Get a stream class' clock.
2059 """
2060 @property
2061 def clock(self):
2062 raise NotImplementedError("Getter not implemented.")
2063
ec8c88d7
JG
2064 """
2065 Assign a clock to a stream class.
2066 """
14001277
JG
2067 @clock.setter
2068 def clock(self, clock):
ec8c88d7
JG
2069 if not isinstance(clock, CTFWriter.Clock):
2070 raise TypeError("Invalid clock type.")
2071
2072 ret = _bt_ctf_stream_class_set_clock(self._sc, clock._c)
2073 if ret < 0:
2074 raise ValueError("Could not set stream class clock.")
2075
2076 """
2077 Add an event class to a stream class. New events can be added even after a
14001277 2078 stream has been instantiated and events have been appended. However, a stream
ec8c88d7
JG
2079 will not accept events of a class that has not been registered beforehand.
2080 """
2081 def add_event_class(self, event_class):
2082 if not isinstance(event_class, CTFWriter.EventClass):
2083 raise TypeError("Invalid event_class type.")
2084
2085 ret = _bt_ctf_stream_class_add_event_class(self._sc, event_class._ec)
2086 if ret < 0:
2087 raise ValueError("Could not add event class.")
2088
2089 class Stream:
2090 """
2091 Create a stream of the given class.
2092 """
2093 def __init__(self, stream_class):
2094 if not isinstance(stream_class, CTFWriter.StreamClass):
2095 raise TypeError("Invalid stream_class type.")
2096
2097 self._s = _bt_ctf_stream_create(stream_class._sc)
2098 if self._s is None:
2099 raise ValueError("Stream creation failed.")
2100
2101 def __del__(self):
2102 _bt_ctf_stream_put(self._s)
2103
2104 """
2105 Increase the current packet's discarded event count.
2106 """
2107 def append_discarded_events(self, event_count):
7569fbb1 2108 _bt_ctf_stream_append_discarded_events(self._s, event_count)
ec8c88d7
JG
2109
2110 """
2111 Append "event" to the stream's current packet. The stream's associated clock
2112 will be sampled during this call. The event shall not be modified after
2113 being appended to a stream.
2114 """
2115 def append_event(self, event):
2116 ret = _bt_ctf_stream_append_event(self._s, event._e)
2117 if ret < 0:
2118 raise ValueError("Could not append event to stream.")
2119
2120 """
2121 The stream's current packet's events will be flushed to disk. Events
2122 subsequently appended to the stream will be added to a new packet.
2123 """
2124 def flush(self):
2125 ret = _bt_ctf_stream_flush(self._s)
2126 if ret < 0:
2127 raise ValueError("Could not flush stream.")
2128
2129 class Writer:
2130 """
2131 Create a new writer that will produce a trace in the given path.
2132 """
2133 def __init__(self, path):
2134 self._w = _bt_ctf_writer_create(path)
2135 if self._w is None:
2136 raise ValueError("Writer creation failed.")
2137
2138 def __del__(self):
2139 _bt_ctf_writer_put(self._w)
2140
2141 """
2142 Create a new stream instance and register it to the writer.
2143 """
2144 def create_stream(self, stream_class):
2145 if not isinstance(stream_class, CTFWriter.StreamClass):
2146 raise TypeError("Invalid stream_class type.")
2147
2148 stream = CTFWriter.Stream.__new__(CTFWriter.Stream)
2149 stream._s = _bt_ctf_writer_create_stream(self._w, stream_class._sc)
2150 return stream
2151
2152 """
2153 Add an environment field to the trace.
2154 """
2155 def add_environment_field(self, name, value):
14001277 2156 ret = _bt_ctf_writer_add_environment_field(self._w, str(name), str(value))
ec8c88d7
JG
2157 if ret < 0:
2158 raise ValueError("Could not add environment field to trace.")
2159
2160 """
2161 Add a clock to the trace. Clocks assigned to stream classes must be
2162 registered to the writer.
2163 """
2164 def add_clock(self, clock):
2165 ret = _bt_ctf_writer_add_clock(self._w, clock._c)
2166 if ret < 0:
2167 raise ValueError("Could not add clock to Writer.")
2168
2169 """
2170 Get the trace's TSDL meta-data.
2171 """
14001277
JG
2172 @property
2173 def metadata(self):
ec8c88d7
JG
2174 return _bt_ctf_writer_get_metadata_string(self._w)
2175
2176 """
2177 Flush the trace's metadata to the metadata file.
2178 """
2179 def flush_metadata(self):
2180 _bt_ctf_writer_flush_metadata(self._w)
2181
14001277
JG
2182 """
2183 Get the trace's byte order. Must be a constant from the ByteOrder
2184 class.
2185 """
2186 @property
2187 def byte_order(self):
2188 raise NotImplementedError("Getter not implemented.")
2189
ec8c88d7
JG
2190 """
2191 Set the trace's byte order. Must be a constant from the ByteOrder
2192 class. Defaults to BYTE_ORDER_NATIVE, the host machine's endianness.
2193 """
14001277
JG
2194 @byte_order.setter
2195 def byte_order(self, byte_order):
ec8c88d7
JG
2196 ret = _bt_ctf_writer_set_byte_order(self._w, byte_order)
2197 if ret < 0:
2198 raise ValueError("Could not set trace's byte order.")
2199
2200%}
This page took 0.121049 seconds and 4 git commands to generate.