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