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