| 1 | #ifndef _BABELTRACE_LIB_H |
| 2 | #define _BABELTRACE_LIB_H |
| 3 | |
| 4 | /* |
| 5 | * BabelTrace API |
| 6 | * |
| 7 | * Copyright 2010-2011 - Mathieu Desnoyers <mathieu.desnoyers@efficios.com> |
| 8 | * |
| 9 | * Permission is hereby granted, free of charge, to any person obtaining a copy |
| 10 | * of this software and associated documentation files (the "Software"), to deal |
| 11 | * in the Software without restriction, including without limitation the rights |
| 12 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
| 13 | * copies of the Software, and to permit persons to whom the Software is |
| 14 | * furnished to do so, subject to the following conditions: |
| 15 | * |
| 16 | * The above copyright notice and this permission notice shall be included in |
| 17 | * all copies or substantial portions of the Software. |
| 18 | */ |
| 19 | |
| 20 | #include <babeltrace/types.h> |
| 21 | #include <babeltrace/format.h> |
| 22 | #include <babeltrace/ctf/types.h> |
| 23 | #include <babeltrace/ctf-ir/metadata.h> |
| 24 | |
| 25 | /* |
| 26 | * struct babeltrace_iter: data structure representing an iterator on a trace |
| 27 | * collection. |
| 28 | */ |
| 29 | struct babeltrace_iter { |
| 30 | struct ptr_heap *stream_heap; |
| 31 | struct trace_collection *tc; |
| 32 | }; |
| 33 | |
| 34 | struct babeltrace_iter_pos { |
| 35 | GPtrArray *pos; /* struct babeltrace_iter_stream_pos */ |
| 36 | }; |
| 37 | |
| 38 | struct babeltrace_iter_stream_pos { |
| 39 | struct stream_pos parent; |
| 40 | ssize_t offset; |
| 41 | size_t cur_index; |
| 42 | }; |
| 43 | |
| 44 | /* |
| 45 | * Initialization/teardown. |
| 46 | */ |
| 47 | struct babeltrace_iter *babeltrace_iter_create(struct trace_collection *tc); |
| 48 | void babeltrace_iter_destroy(struct babeltrace_iter *iter); |
| 49 | |
| 50 | /* |
| 51 | * Move within the trace. |
| 52 | */ |
| 53 | /* |
| 54 | * babeltrace_iter_next: Move stream position to the next event. |
| 55 | * |
| 56 | * Returns 0 on success, a negative value on error |
| 57 | */ |
| 58 | int babeltrace_iter_next(struct babeltrace_iter *iter); |
| 59 | |
| 60 | /* Get the current position for each stream of the trace */ |
| 61 | struct babeltrace_iter_pos * |
| 62 | babeltrace_iter_get_pos(struct babeltrace_iter *iter); |
| 63 | |
| 64 | /* The position needs to be freed after use */ |
| 65 | void babeltrace_iter_free_pos(struct babeltrace_iter_pos *pos); |
| 66 | |
| 67 | /* Seek the trace to the position */ |
| 68 | int babeltrace_iter_seek_pos(struct babeltrace_iter *iter, |
| 69 | struct babeltrace_iter_pos *pos); |
| 70 | |
| 71 | /* |
| 72 | * babeltrace_iter_seek_time: Seek the trace to the given timestamp. |
| 73 | * |
| 74 | * Return EOF if timestamp is after the last event of the trace. |
| 75 | * Return other negative value for other errors. |
| 76 | * Return 0 for success. |
| 77 | */ |
| 78 | int babeltrace_iter_seek_time(struct babeltrace_iter *iter, |
| 79 | uint64_t timestamp); |
| 80 | |
| 81 | /* |
| 82 | * babeltrace_iter_read_event: Read the current event data. |
| 83 | * |
| 84 | * @iter: trace iterator (input) |
| 85 | * @stream: stream containing event at current position (output) |
| 86 | * @event: current event (output) |
| 87 | * Return 0 on success, negative error value on error. |
| 88 | */ |
| 89 | int babeltrace_iter_read_event(struct babeltrace_iter *iter, |
| 90 | struct ctf_stream **stream, |
| 91 | struct ctf_stream_event **event); |
| 92 | |
| 93 | #endif /* _BABELTRACE_LIB_H */ |