Commit | Line | Data |
---|---|---|
9843982d JD |
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. | |
c462e188 MD |
24 | * |
25 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | |
26 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | |
27 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | |
28 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | |
29 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | |
30 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | |
31 | * SOFTWARE. | |
9843982d JD |
32 | */ |
33 | ||
34 | #include <stdint.h> | |
e003ab50 | 35 | #include <babeltrace/context.h> |
03798a93 | 36 | #include <babeltrace/clock-types.h> |
9843982d | 37 | |
6946751f JD |
38 | #ifdef __cplusplus |
39 | extern "C" { | |
40 | #endif | |
41 | ||
0d69b916 | 42 | struct bt_definition; |
ecc54f11 | 43 | struct bt_declaration; |
c50d2a7a | 44 | struct bt_ctf_event; |
e003ab50 | 45 | struct bt_ctf_event_decl; |
64c2c249 | 46 | struct bt_ctf_field_decl; |
9843982d JD |
47 | |
48 | /* | |
49 | * the top-level scopes in CTF | |
50 | */ | |
51 | enum bt_ctf_scope { | |
52 | BT_TRACE_PACKET_HEADER = 0, | |
53 | BT_STREAM_PACKET_CONTEXT = 1, | |
54 | BT_STREAM_EVENT_HEADER = 2, | |
55 | BT_STREAM_EVENT_CONTEXT = 3, | |
56 | BT_EVENT_CONTEXT = 4, | |
57 | BT_EVENT_FIELDS = 5, | |
58 | }; | |
59 | ||
60 | /* | |
61 | * the supported CTF types | |
62 | */ | |
63 | enum ctf_type_id { | |
64 | CTF_TYPE_UNKNOWN = 0, | |
65 | CTF_TYPE_INTEGER, | |
66 | CTF_TYPE_FLOAT, | |
67 | CTF_TYPE_ENUM, | |
68 | CTF_TYPE_STRING, | |
69 | CTF_TYPE_STRUCT, | |
70 | CTF_TYPE_UNTAGGED_VARIANT, | |
71 | CTF_TYPE_VARIANT, | |
72 | CTF_TYPE_ARRAY, | |
73 | CTF_TYPE_SEQUENCE, | |
74 | NR_CTF_TYPES, | |
75 | }; | |
76 | ||
8673030f JD |
77 | /* |
78 | * the supported CTF string encodings | |
79 | */ | |
80 | enum ctf_string_encoding { | |
81 | CTF_STRING_NONE = 0, | |
82 | CTF_STRING_UTF8, | |
83 | CTF_STRING_ASCII, | |
84 | CTF_STRING_UNKNOWN, | |
85 | }; | |
86 | ||
9843982d JD |
87 | /* |
88 | * bt_ctf_get_top_level_scope: return a definition of the top-level scope | |
89 | * | |
90 | * Top-level scopes are defined in the bt_ctf_scope enum. | |
91 | * In order to get a field or a field list, the user needs to pass a | |
92 | * scope as argument, this scope can be a top-level scope or a scope | |
93 | * relative to an arbitrary field. This function provides the mapping | |
94 | * between the enum and the actual definition of top-level scopes. | |
95 | * On error return NULL. | |
96 | */ | |
0d69b916 | 97 | const struct bt_definition *bt_ctf_get_top_level_scope(const struct bt_ctf_event *event, |
9843982d JD |
98 | enum bt_ctf_scope scope); |
99 | ||
100 | /* | |
101 | * bt_ctf_event_get_name: returns the name of the event or NULL on error | |
102 | */ | |
c50d2a7a | 103 | const char *bt_ctf_event_name(const struct bt_ctf_event *event); |
9843982d JD |
104 | |
105 | /* | |
d40ee8ec | 106 | * bt_ctf_get_cycles: returns the timestamp of the event as written |
03798a93 | 107 | * in the packet (in cycles) or -1ULL on error. |
57f3005e | 108 | */ |
d40ee8ec | 109 | uint64_t bt_ctf_get_cycles(const struct bt_ctf_event *event); |
57f3005e SJD |
110 | |
111 | /* | |
61cf588b MD |
112 | * bt_ctf_get_timestamp: get the timestamp of the event offsetted |
113 | * with the system clock source (in ns) in *timestamp. | |
114 | * | |
115 | * Return 0 on success, or -1ULL on error. | |
9843982d | 116 | */ |
61cf588b | 117 | int bt_ctf_get_timestamp(const struct bt_ctf_event *event, int64_t *timestamp); |
9843982d JD |
118 | |
119 | /* | |
bb337d59 MD |
120 | * bt_ctf_get_field_list: obtain the list of fields for compound type |
121 | * | |
f5464725 JD |
122 | * This function can be used to obtain the list of fields contained |
123 | * within a top-level scope of an event or a compound type: array, | |
124 | * sequence, structure, or variant. | |
bb337d59 MD |
125 | |
126 | * This function sets the "list" pointer to an array of definition | |
aacd0c69 JD |
127 | * pointers and set count to the number of elements in the array. |
128 | * Return 0 on success and a negative value on error. | |
bb337d59 MD |
129 | * |
130 | * The content pointed to by "list" should *not* be freed. It stays | |
131 | * valid as long as the event is unchanged (as long as the iterator | |
132 | * from which the event is extracted is unchanged). | |
9843982d | 133 | */ |
c50d2a7a | 134 | int bt_ctf_get_field_list(const struct bt_ctf_event *event, |
0d69b916 JD |
135 | const struct bt_definition *scope, |
136 | struct bt_definition const * const **list, | |
9843982d JD |
137 | unsigned int *count); |
138 | ||
139 | /* | |
140 | * bt_ctf_get_field: returns the definition of a specific field | |
141 | */ | |
0d69b916 JD |
142 | const struct bt_definition *bt_ctf_get_field(const struct bt_ctf_event *event, |
143 | const struct bt_definition *scope, | |
9843982d JD |
144 | const char *field); |
145 | ||
146 | /* | |
147 | * bt_ctf_get_index: if the field is an array or a sequence, return the element | |
148 | * at position index, otherwise return NULL; | |
149 | */ | |
0d69b916 JD |
150 | const struct bt_definition *bt_ctf_get_index(const struct bt_ctf_event *event, |
151 | const struct bt_definition *field, | |
9843982d JD |
152 | unsigned int index); |
153 | ||
154 | /* | |
155 | * bt_ctf_field_name: returns the name of a field or NULL on error | |
156 | */ | |
0d69b916 | 157 | const char *bt_ctf_field_name(const struct bt_definition *def); |
9843982d | 158 | |
2bdfa4cf | 159 | /* |
b14d90be JD |
160 | * bt_ctf_get_decl_from_def: return the declaration of a field from |
161 | * its definition or NULL on error | |
2bdfa4cf | 162 | */ |
ecc54f11 | 163 | const struct bt_declaration *bt_ctf_get_decl_from_def(const struct bt_definition *def); |
b14d90be JD |
164 | |
165 | /* | |
166 | * bt_ctf_get_decl_from_field_decl: return the declaration of a field from | |
167 | * a field_decl or NULL on error | |
168 | */ | |
ecc54f11 | 169 | const struct bt_declaration *bt_ctf_get_decl_from_field_decl( |
b14d90be | 170 | const struct bt_ctf_field_decl *field); |
2bdfa4cf | 171 | |
9843982d JD |
172 | /* |
173 | * bt_ctf_field_type: returns the type of a field or -1 if unknown | |
174 | */ | |
ecc54f11 | 175 | enum ctf_type_id bt_ctf_field_type(const struct bt_declaration *decl); |
9843982d | 176 | |
8673030f JD |
177 | /* |
178 | * bt_ctf_get_int_signedness: return the signedness of an integer | |
179 | * | |
180 | * return 0 if unsigned | |
181 | * return 1 if signed | |
182 | * return -1 on error | |
183 | */ | |
ecc54f11 | 184 | int bt_ctf_get_int_signedness(const struct bt_declaration *decl); |
8673030f JD |
185 | |
186 | /* | |
187 | * bt_ctf_get_int_base: return the base of an int or a negative value on error | |
188 | */ | |
ecc54f11 | 189 | int bt_ctf_get_int_base(const struct bt_declaration *decl); |
8673030f JD |
190 | |
191 | /* | |
192 | * bt_ctf_get_int_byte_order: return the byte order of an int or a negative | |
193 | * value on error | |
194 | */ | |
ecc54f11 | 195 | int bt_ctf_get_int_byte_order(const struct bt_declaration *decl); |
8673030f | 196 | |
fef0e521 MD |
197 | /* |
198 | * bt_ctf_get_int_len: return the size, in bits, of an int or a negative | |
199 | * value on error | |
200 | */ | |
ecc54f11 | 201 | ssize_t bt_ctf_get_int_len(const struct bt_declaration *decl); |
fef0e521 | 202 | |
8673030f | 203 | /* |
c22b9327 JD |
204 | * bt_ctf_get_encoding: return the encoding of an int, a string, or of |
205 | * the integer contained in a char array or a sequence. | |
8673030f JD |
206 | * return a negative value on error |
207 | */ | |
ecc54f11 | 208 | enum ctf_string_encoding bt_ctf_get_encoding(const struct bt_declaration *decl); |
8673030f JD |
209 | |
210 | /* | |
211 | * bt_ctf_get_array_len: return the len of an array or a negative | |
212 | * value on error | |
213 | */ | |
ecc54f11 | 214 | int bt_ctf_get_array_len(const struct bt_declaration *decl); |
8673030f | 215 | |
3a068915 JG |
216 | /* |
217 | * bt_ctf_get_struct_field_count: return the number of fields in a structure. | |
218 | * Returns a negative value on error. | |
219 | */ | |
220 | uint64_t bt_ctf_get_struct_field_count(const struct bt_definition *field); | |
221 | ||
9843982d JD |
222 | /* |
223 | * Field access functions | |
224 | * | |
225 | * These functions return the value associated with the field passed in | |
226 | * parameter. | |
227 | * | |
228 | * If the field does not exist or is not of the type requested, the value | |
229 | * returned is undefined. To check if an error occured, use the | |
b330165c | 230 | * bt_ctf_field_get_error() function after accessing a field. |
4d25c350 MD |
231 | * |
232 | * bt_ctf_get_enum_int gets the integer field of an enumeration. | |
233 | * bt_ctf_get_enum_str gets the string matching the current enumeration | |
234 | * value, or NULL if the current value does not match any string. | |
9843982d | 235 | */ |
0d69b916 JD |
236 | uint64_t bt_ctf_get_uint64(const struct bt_definition *field); |
237 | int64_t bt_ctf_get_int64(const struct bt_definition *field); | |
238 | const struct bt_definition *bt_ctf_get_enum_int(const struct bt_definition *field); | |
239 | const char *bt_ctf_get_enum_str(const struct bt_definition *field); | |
240 | char *bt_ctf_get_char_array(const struct bt_definition *field); | |
241 | char *bt_ctf_get_string(const struct bt_definition *field); | |
e5a73b90 | 242 | double bt_ctf_get_float(const struct bt_definition *field); |
812e6682 | 243 | const struct bt_definition *bt_ctf_get_variant(const struct bt_definition *field); |
3a068915 JG |
244 | const struct bt_definition *bt_ctf_get_struct_field_index( |
245 | const struct bt_definition *field, uint64_t i); | |
9843982d JD |
246 | |
247 | /* | |
b330165c | 248 | * bt_ctf_field_get_error: returns the last error code encountered while |
9843982d JD |
249 | * accessing a field and reset the error flag. |
250 | * Return 0 if no error, a negative value otherwise. | |
251 | */ | |
252 | int bt_ctf_field_get_error(void); | |
253 | ||
e003ab50 | 254 | /* |
f5464725 JD |
255 | * bt_ctf_get_event_decl_list: get a list of all the event declarations in |
256 | * a trace. | |
257 | * | |
258 | * The list array is pointed to the array of event declarations. | |
259 | * The number of events in the array is written in count. | |
e003ab50 JD |
260 | * |
261 | * Return 0 on success and a negative value on error. | |
f5464725 JD |
262 | * |
263 | * The content pointed to by "list" should *not* be freed. It stays | |
264 | * valid as long as the trace is opened. | |
e003ab50 JD |
265 | */ |
266 | int bt_ctf_get_event_decl_list(int handle_id, struct bt_context *ctx, | |
64c2c249 | 267 | struct bt_ctf_event_decl * const **list, |
e003ab50 JD |
268 | unsigned int *count); |
269 | ||
270 | /* | |
271 | * bt_ctf_get_decl_event_name: return the name of the event or NULL on error | |
272 | */ | |
273 | const char *bt_ctf_get_decl_event_name(const struct bt_ctf_event_decl *event); | |
274 | ||
78564612 AM |
275 | /* |
276 | * bt_ctf_get_decl_event_id: return the event-ID of the event or -1ULL on error | |
277 | */ | |
278 | uint64_t bt_ctf_get_decl_event_id(const struct bt_ctf_event_decl *event); | |
279 | ||
64c2c249 | 280 | /* |
f5464725 JD |
281 | * bt_ctf_get_decl_fields: get all field declarations in a scope of an event |
282 | * | |
283 | * The list array is pointed to the array of field declaration. | |
284 | * The number of field declaration in the array is written in count. | |
64c2c249 JD |
285 | * |
286 | * Returns 0 on success and a negative value on error | |
f5464725 JD |
287 | * |
288 | * The content pointed to by "list" should *not* be freed. It stays | |
289 | * valid as long as the trace is opened. | |
64c2c249 JD |
290 | */ |
291 | int bt_ctf_get_decl_fields(struct bt_ctf_event_decl *event_decl, | |
292 | enum bt_ctf_scope scope, | |
293 | struct bt_ctf_field_decl const * const **list, | |
294 | unsigned int *count); | |
295 | ||
296 | /* | |
297 | * bt_ctf_get_decl_field_name: return the name of a field decl or NULL on error | |
298 | */ | |
299 | const char *bt_ctf_get_decl_field_name(const struct bt_ctf_field_decl *field); | |
300 | ||
6946751f JD |
301 | #ifdef __cplusplus |
302 | } | |
303 | #endif | |
304 | ||
9843982d | 305 | #endif /* _BABELTRACE_CTF_EVENTS_H */ |