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