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