| 1 | #ifndef _BABELTRACE_H |
| 2 | #define _BABELTRACE_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 <glib.h> |
| 21 | |
| 22 | typedef GQuark bt_event_name; |
| 23 | |
| 24 | /* Forward declarations */ |
| 25 | struct babeltrace_iter; |
| 26 | struct trace_collection; |
| 27 | struct ctf_stream_event; |
| 28 | struct ctf_stream; |
| 29 | struct babeltrace_saved_pos; |
| 30 | struct bt_dependencies; |
| 31 | |
| 32 | enum bt_cb_ret { |
| 33 | BT_CB_OK = 0, |
| 34 | BT_CB_OK_STOP = 1, |
| 35 | BT_CB_ERROR_STOP = 2, |
| 36 | BT_CB_ERROR_CONTINUE = 3, |
| 37 | }; |
| 38 | |
| 39 | struct trace_collection_pos { |
| 40 | enum { |
| 41 | BT_SEEK_TIME, /* uses u.seek_time */ |
| 42 | BT_SEEK_RESTORE, /* uses u.restore */ |
| 43 | BT_SEEK_CUR, |
| 44 | BT_SEEK_BEGIN, |
| 45 | BT_SEEK_END, |
| 46 | } type; |
| 47 | union { |
| 48 | uint64_t seek_time; |
| 49 | struct babeltrace_saved_pos *restore; |
| 50 | } u; |
| 51 | }; |
| 52 | |
| 53 | struct bt_ctf_data { |
| 54 | struct ctf_stream_event *event; |
| 55 | }; |
| 56 | |
| 57 | /* |
| 58 | * babeltrace_iter_create - Allocate a trace collection iterator. |
| 59 | * |
| 60 | * begin_pos and end_pos are optional parameters to specify the position |
| 61 | * at which the trace collection should be seeked upon iterator |
| 62 | * creation, and the position at which iteration will start returning |
| 63 | * "EOF". |
| 64 | * |
| 65 | * By default, if begin_pos is NULL, a BT_SEEK_CUR is performed at |
| 66 | * creation. By default, if end_pos is NULL, a BT_SEEK_END (end of |
| 67 | * trace) is the EOF criterion. |
| 68 | */ |
| 69 | struct babeltrace_iter *babeltrace_iter_create(struct trace_collection *tc, |
| 70 | struct trace_collection_pos *begin_pos, |
| 71 | struct trace_collection_pos *end_pos); |
| 72 | |
| 73 | /* |
| 74 | * babeltrace_iter_destroy - Free a trace collection iterator. |
| 75 | */ |
| 76 | void babeltrace_iter_destroy(struct babeltrace_iter *iter); |
| 77 | |
| 78 | /* |
| 79 | * babeltrace_iter_next: Move trace collection position to the next event. |
| 80 | * |
| 81 | * Returns 0 on success, a negative value on error |
| 82 | */ |
| 83 | int babeltrace_iter_next(struct babeltrace_iter *iter); |
| 84 | |
| 85 | /* |
| 86 | * babeltrace_iter_save_pos - Save the current trace collection position. |
| 87 | * |
| 88 | * The position returned by this function needs to be freed by |
| 89 | * babeltrace_iter_free_pos after use. |
| 90 | */ |
| 91 | struct trace_collection_pos * |
| 92 | babeltrace_iter_save_pos(struct babeltrace_iter *iter); |
| 93 | |
| 94 | /* |
| 95 | * babeltrace_iter_free_pos - Free the position. |
| 96 | */ |
| 97 | void babeltrace_iter_free_pos(struct trace_collection_pos *pos); |
| 98 | |
| 99 | /* |
| 100 | * babeltrace_iter_seek: seek iterator to given position. |
| 101 | * |
| 102 | * Return EOF if position is after the last event of the trace collection. |
| 103 | * Return other negative value for other errors. |
| 104 | * Return 0 for success. |
| 105 | */ |
| 106 | int babeltrace_iter_seek(struct babeltrace_iter *iter, |
| 107 | const struct trace_collection_pos *pos); |
| 108 | |
| 109 | /* |
| 110 | * babeltrace_iter_read_event: Read the iterator's current event data. |
| 111 | * |
| 112 | * @iter: trace collection iterator (input) |
| 113 | * @stream: stream containing event at current position (output) |
| 114 | * @event: current event (output) |
| 115 | * Return 0 on success, negative error value on error. |
| 116 | */ |
| 117 | int babeltrace_iter_read_event(struct babeltrace_iter *iter, |
| 118 | struct ctf_stream **stream, |
| 119 | struct ctf_stream_event **event); |
| 120 | |
| 121 | /* |
| 122 | * Receives a variable number of strings as parameter, ended with NULL. |
| 123 | */ |
| 124 | struct bt_dependencies *babeltrace_dependencies_create(const char *first, ...); |
| 125 | |
| 126 | /* |
| 127 | * struct bt_dependencies must be destroyed explicitly if not passed as |
| 128 | * parameter to a babeltrace_iter_add_callback(). |
| 129 | */ |
| 130 | void babeltrace_dependencies_destroy(struct bt_dependencies *dep); |
| 131 | |
| 132 | /* |
| 133 | * babeltrace_iter_add_callback: Add a callback to iterator. |
| 134 | * |
| 135 | * @iter: trace collection iterator (input) |
| 136 | * @event: event to target. 0 for all events. |
| 137 | * @private_data: private data pointer to pass to the callback |
| 138 | * @flags: specific flags controlling the behavior of this callback |
| 139 | * (or'd). |
| 140 | * |
| 141 | * @callback: function pointer to call |
| 142 | * @depends: struct bt_dependency detailing the required computation results. |
| 143 | * Ends with 0. |
| 144 | * @weak_depends: struct bt_dependency detailing the optional computation |
| 145 | * results that can be optionally consumed by this |
| 146 | * callback. |
| 147 | * @provides: struct bt_dependency detailing the computation results |
| 148 | * provided by this callback. |
| 149 | * Ends with 0. |
| 150 | * |
| 151 | * "depends", "weak_depends" and "provides" memory is handled by the |
| 152 | * babeltrace library after this call succeeds or fails. These objects |
| 153 | * can still be used by the caller until the babeltrace iterator is |
| 154 | * destroyed, but they belong to the babeltrace library. |
| 155 | * |
| 156 | * (note to implementor: we need to keep a gptrarray of struct |
| 157 | * bt_dependencies to "garbage collect" in struct babeltrace_iter, and |
| 158 | * dependencies need to have a refcount to handle the case where they |
| 159 | * would be passed to more than one iterator. Upon iterator detroy, we |
| 160 | * iterate on all the gc ptrarray and decrement the refcounts, freeing |
| 161 | * if we reach 0.) |
| 162 | * (note to implementor: we calculate the dependency graph when |
| 163 | * babeltrace_iter_read_event() is executed after a |
| 164 | * babeltrace_iter_add_callback(). Beware that it is valid to create/add |
| 165 | * callbacks/read/add more callbacks/read some more.) |
| 166 | */ |
| 167 | int babeltrace_iter_add_callback(struct babeltrace_iter *iter, |
| 168 | bt_event_name event, void *private_data, int flags, |
| 169 | enum bt_cb_ret (*callback)(struct bt_ctf_data *ctf_data, |
| 170 | void *caller_data), |
| 171 | struct bt_dependencies *depends, |
| 172 | struct bt_dependencies *weak_depends, |
| 173 | struct bt_dependencies *provides); |
| 174 | |
| 175 | /* |
| 176 | * For flags parameter above. |
| 177 | */ |
| 178 | enum { |
| 179 | BT_FLAGS_FREE_PRIVATE_DATA = (1 << 0), |
| 180 | }; |
| 181 | |
| 182 | #endif /* _BABELTRACE_H */ |