| 1 | #ifndef _BABELTRACE_CTF_EVENTS_H |
| 2 | #define _BABELTRACE_CTF_EVENTS_H |
| 3 | |
| 4 | /* |
| 5 | * BabelTrace |
| 6 | * |
| 7 | * CTF events API |
| 8 | * |
| 9 | * Copyright 2011-2012 EfficiOS Inc. and Linux Foundation |
| 10 | * |
| 11 | * Author: Mathieu Desnoyers <mathieu.desnoyers@efficios.com> |
| 12 | * Julien Desfossez <julien.desfossez@efficios.com> |
| 13 | * |
| 14 | * Permission is hereby granted, free of charge, to any person obtaining |
| 15 | * a copy of this software and associated documentation files (the |
| 16 | * "Software"), to deal in the Software without restriction, including |
| 17 | * without limitation the rights to use, copy, modify, merge, publish, |
| 18 | * distribute, sublicense, and/or sell copies of the Software, and to |
| 19 | * permit persons to whom the Software is furnished to do so, subject to |
| 20 | * the following conditions: |
| 21 | * |
| 22 | * The above copyright notice and this permission notice shall be |
| 23 | * included in all copies or substantial portions of the Software. |
| 24 | */ |
| 25 | |
| 26 | #include <stdint.h> |
| 27 | #include <babeltrace/iterator.h> |
| 28 | |
| 29 | struct ctf_stream; |
| 30 | struct ctf_stream_event; |
| 31 | struct definition; |
| 32 | struct bt_ctf_iter; |
| 33 | |
| 34 | /* |
| 35 | * the top-level scopes in CTF |
| 36 | */ |
| 37 | enum bt_ctf_scope { |
| 38 | BT_TRACE_PACKET_HEADER = 0, |
| 39 | BT_STREAM_PACKET_CONTEXT = 1, |
| 40 | BT_STREAM_EVENT_HEADER = 2, |
| 41 | BT_STREAM_EVENT_CONTEXT = 3, |
| 42 | BT_EVENT_CONTEXT = 4, |
| 43 | BT_EVENT_FIELDS = 5, |
| 44 | }; |
| 45 | |
| 46 | /* |
| 47 | * the supported CTF types |
| 48 | */ |
| 49 | enum ctf_type_id { |
| 50 | CTF_TYPE_UNKNOWN = 0, |
| 51 | CTF_TYPE_INTEGER, |
| 52 | CTF_TYPE_FLOAT, |
| 53 | CTF_TYPE_ENUM, |
| 54 | CTF_TYPE_STRING, |
| 55 | CTF_TYPE_STRUCT, |
| 56 | CTF_TYPE_UNTAGGED_VARIANT, |
| 57 | CTF_TYPE_VARIANT, |
| 58 | CTF_TYPE_ARRAY, |
| 59 | CTF_TYPE_SEQUENCE, |
| 60 | NR_CTF_TYPES, |
| 61 | }; |
| 62 | |
| 63 | /* |
| 64 | * the structure to manipulate events |
| 65 | */ |
| 66 | struct bt_ctf_event { |
| 67 | struct ctf_stream *stream; |
| 68 | struct ctf_stream_event *event; |
| 69 | }; |
| 70 | |
| 71 | /* |
| 72 | * bt_ctf_iter_read_event: Read the iterator's current event data. |
| 73 | * |
| 74 | * @iter: trace collection iterator (input) |
| 75 | * @stream: stream containing event at current position (output) |
| 76 | * @event: current event (output) |
| 77 | * Return 0 on success, negative error value on error. |
| 78 | */ |
| 79 | struct bt_ctf_event *bt_ctf_iter_read_event(struct bt_ctf_iter *iter); |
| 80 | |
| 81 | /* |
| 82 | * bt_ctf_iter_create - Allocate a CTF trace collection iterator. |
| 83 | * |
| 84 | * begin_pos and end_pos are optional parameters to specify the position |
| 85 | * at which the trace collection should be seeked upon iterator |
| 86 | * creation, and the position at which iteration will start returning |
| 87 | * "EOF". |
| 88 | * |
| 89 | * By default, if begin_pos is NULL, a BT_SEEK_CUR is performed at |
| 90 | * creation. By default, if end_pos is NULL, a BT_SEEK_END (end of |
| 91 | * trace) is the EOF criterion. |
| 92 | */ |
| 93 | struct bt_ctf_iter *bt_ctf_iter_create(struct bt_context *ctx, |
| 94 | struct bt_iter_pos *begin_pos, |
| 95 | struct bt_iter_pos *end_pos); |
| 96 | |
| 97 | /* |
| 98 | * bt_ctf_get_iter - get iterator from ctf iterator. |
| 99 | */ |
| 100 | struct bt_iter *bt_ctf_get_iter(struct bt_ctf_iter *iter); |
| 101 | |
| 102 | /* |
| 103 | * bt_ctf_iter_destroy - Free a CTF trace collection iterator. |
| 104 | */ |
| 105 | void bt_ctf_iter_destroy(struct bt_ctf_iter *iter); |
| 106 | |
| 107 | /* |
| 108 | * bt_ctf_get_top_level_scope: return a definition of the top-level scope |
| 109 | * |
| 110 | * Top-level scopes are defined in the bt_ctf_scope enum. |
| 111 | * In order to get a field or a field list, the user needs to pass a |
| 112 | * scope as argument, this scope can be a top-level scope or a scope |
| 113 | * relative to an arbitrary field. This function provides the mapping |
| 114 | * between the enum and the actual definition of top-level scopes. |
| 115 | * On error return NULL. |
| 116 | */ |
| 117 | struct definition *bt_ctf_get_top_level_scope(struct bt_ctf_event *event, |
| 118 | enum bt_ctf_scope scope); |
| 119 | |
| 120 | /* |
| 121 | * bt_ctf_event_get_name: returns the name of the event or NULL on error |
| 122 | */ |
| 123 | const char *bt_ctf_event_name(struct bt_ctf_event *event); |
| 124 | |
| 125 | /* |
| 126 | * bt_ctf_get_timestamp_raw: returns the timestamp of the event as written in |
| 127 | * the packet or -1ULL on error |
| 128 | */ |
| 129 | uint64_t bt_ctf_get_timestamp_raw(struct bt_ctf_event *event); |
| 130 | |
| 131 | /* |
| 132 | * bt_ctf_get_timestamp: returns the timestamp of the event offsetted with the |
| 133 | * system clock source or -1ULL on error |
| 134 | */ |
| 135 | uint64_t bt_ctf_get_timestamp(struct bt_ctf_event *event); |
| 136 | |
| 137 | /* |
| 138 | * bt_ctf_get_field_list: set list pointer to an array of definition |
| 139 | * pointers and set count to the number of elements in the array. |
| 140 | * Return 0 on success and a negative value on error. |
| 141 | */ |
| 142 | int bt_ctf_get_field_list(struct bt_ctf_event *event, |
| 143 | struct definition *scope, |
| 144 | struct definition const * const **list, |
| 145 | unsigned int *count); |
| 146 | |
| 147 | /* |
| 148 | * bt_ctf_get_field: returns the definition of a specific field |
| 149 | */ |
| 150 | struct definition *bt_ctf_get_field(struct bt_ctf_event *event, |
| 151 | struct definition *scope, |
| 152 | const char *field); |
| 153 | |
| 154 | /* |
| 155 | * bt_ctf_get_index: if the field is an array or a sequence, return the element |
| 156 | * at position index, otherwise return NULL; |
| 157 | */ |
| 158 | struct definition *bt_ctf_get_index(struct bt_ctf_event *event, |
| 159 | struct definition *field, |
| 160 | unsigned int index); |
| 161 | |
| 162 | /* |
| 163 | * bt_ctf_field_name: returns the name of a field or NULL on error |
| 164 | */ |
| 165 | const char *bt_ctf_field_name(const struct definition *def); |
| 166 | |
| 167 | /* |
| 168 | * bt_ctf_field_type: returns the type of a field or -1 if unknown |
| 169 | */ |
| 170 | enum ctf_type_id bt_ctf_field_type(const struct definition *def); |
| 171 | |
| 172 | /* |
| 173 | * Field access functions |
| 174 | * |
| 175 | * These functions return the value associated with the field passed in |
| 176 | * parameter. |
| 177 | * |
| 178 | * If the field does not exist or is not of the type requested, the value |
| 179 | * returned is undefined. To check if an error occured, use the |
| 180 | * bt_ctf_field_error() function after accessing a field. |
| 181 | */ |
| 182 | uint64_t bt_ctf_get_uint64(const struct definition *field); |
| 183 | int64_t bt_ctf_get_int64(const struct definition *field); |
| 184 | char *bt_ctf_get_char_array(const struct definition *field); |
| 185 | char *bt_ctf_get_string(const struct definition *field); |
| 186 | |
| 187 | /* |
| 188 | * bt_ctf_field_error: returns the last error code encountered while |
| 189 | * accessing a field and reset the error flag. |
| 190 | * Return 0 if no error, a negative value otherwise. |
| 191 | */ |
| 192 | int bt_ctf_field_get_error(void); |
| 193 | |
| 194 | #endif /* _BABELTRACE_CTF_EVENTS_H */ |