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. | |
24 | */ | |
25 | ||
26 | #include <stdint.h> | |
e003ab50 | 27 | #include <babeltrace/context.h> |
03798a93 | 28 | #include <babeltrace/clock-types.h> |
9843982d | 29 | |
9843982d | 30 | struct definition; |
c50d2a7a | 31 | struct bt_ctf_event; |
e003ab50 | 32 | struct bt_ctf_event_decl; |
64c2c249 | 33 | struct bt_ctf_field_decl; |
9843982d JD |
34 | |
35 | /* | |
36 | * the top-level scopes in CTF | |
37 | */ | |
38 | enum bt_ctf_scope { | |
39 | BT_TRACE_PACKET_HEADER = 0, | |
40 | BT_STREAM_PACKET_CONTEXT = 1, | |
41 | BT_STREAM_EVENT_HEADER = 2, | |
42 | BT_STREAM_EVENT_CONTEXT = 3, | |
43 | BT_EVENT_CONTEXT = 4, | |
44 | BT_EVENT_FIELDS = 5, | |
45 | }; | |
46 | ||
47 | /* | |
48 | * the supported CTF types | |
49 | */ | |
50 | enum ctf_type_id { | |
51 | CTF_TYPE_UNKNOWN = 0, | |
52 | CTF_TYPE_INTEGER, | |
53 | CTF_TYPE_FLOAT, | |
54 | CTF_TYPE_ENUM, | |
55 | CTF_TYPE_STRING, | |
56 | CTF_TYPE_STRUCT, | |
57 | CTF_TYPE_UNTAGGED_VARIANT, | |
58 | CTF_TYPE_VARIANT, | |
59 | CTF_TYPE_ARRAY, | |
60 | CTF_TYPE_SEQUENCE, | |
61 | NR_CTF_TYPES, | |
62 | }; | |
63 | ||
8673030f JD |
64 | /* |
65 | * the supported CTF string encodings | |
66 | */ | |
67 | enum ctf_string_encoding { | |
68 | CTF_STRING_NONE = 0, | |
69 | CTF_STRING_UTF8, | |
70 | CTF_STRING_ASCII, | |
71 | CTF_STRING_UNKNOWN, | |
72 | }; | |
73 | ||
9843982d JD |
74 | /* |
75 | * bt_ctf_get_top_level_scope: return a definition of the top-level scope | |
76 | * | |
77 | * Top-level scopes are defined in the bt_ctf_scope enum. | |
78 | * In order to get a field or a field list, the user needs to pass a | |
79 | * scope as argument, this scope can be a top-level scope or a scope | |
80 | * relative to an arbitrary field. This function provides the mapping | |
81 | * between the enum and the actual definition of top-level scopes. | |
82 | * On error return NULL. | |
83 | */ | |
c50d2a7a | 84 | const struct definition *bt_ctf_get_top_level_scope(const struct bt_ctf_event *event, |
9843982d JD |
85 | enum bt_ctf_scope scope); |
86 | ||
87 | /* | |
88 | * bt_ctf_event_get_name: returns the name of the event or NULL on error | |
89 | */ | |
c50d2a7a | 90 | const char *bt_ctf_event_name(const struct bt_ctf_event *event); |
9843982d JD |
91 | |
92 | /* | |
d40ee8ec | 93 | * bt_ctf_get_cycles: returns the timestamp of the event as written |
03798a93 | 94 | * in the packet (in cycles) or -1ULL on error. |
57f3005e | 95 | */ |
d40ee8ec | 96 | uint64_t bt_ctf_get_cycles(const struct bt_ctf_event *event); |
57f3005e SJD |
97 | |
98 | /* | |
d40ee8ec | 99 | * bt_ctf_get_timestamp: returns the timestamp of the event offsetted |
03798a93 | 100 | * with the system clock source (in ns) or -1ULL on error |
9843982d | 101 | */ |
d40ee8ec | 102 | uint64_t bt_ctf_get_timestamp(const struct bt_ctf_event *event); |
9843982d JD |
103 | |
104 | /* | |
aacd0c69 JD |
105 | * bt_ctf_get_field_list: set list pointer to an array of definition |
106 | * pointers and set count to the number of elements in the array. | |
107 | * Return 0 on success and a negative value on error. | |
9843982d | 108 | */ |
c50d2a7a | 109 | int bt_ctf_get_field_list(const struct bt_ctf_event *event, |
04ae3991 | 110 | const struct definition *scope, |
9843982d JD |
111 | struct definition const * const **list, |
112 | unsigned int *count); | |
113 | ||
114 | /* | |
115 | * bt_ctf_get_field: returns the definition of a specific field | |
116 | */ | |
c50d2a7a | 117 | const struct definition *bt_ctf_get_field(const struct bt_ctf_event *event, |
04ae3991 | 118 | const struct definition *scope, |
9843982d JD |
119 | const char *field); |
120 | ||
121 | /* | |
122 | * bt_ctf_get_index: if the field is an array or a sequence, return the element | |
123 | * at position index, otherwise return NULL; | |
124 | */ | |
c50d2a7a | 125 | const struct definition *bt_ctf_get_index(const struct bt_ctf_event *event, |
04ae3991 | 126 | const struct definition *field, |
9843982d JD |
127 | unsigned int index); |
128 | ||
129 | /* | |
130 | * bt_ctf_field_name: returns the name of a field or NULL on error | |
131 | */ | |
132 | const char *bt_ctf_field_name(const struct definition *def); | |
133 | ||
134 | /* | |
135 | * bt_ctf_field_type: returns the type of a field or -1 if unknown | |
136 | */ | |
da320b83 | 137 | enum ctf_type_id bt_ctf_field_type(const struct definition *def); |
9843982d | 138 | |
8673030f JD |
139 | /* |
140 | * bt_ctf_get_int_signedness: return the signedness of an integer | |
141 | * | |
142 | * return 0 if unsigned | |
143 | * return 1 if signed | |
144 | * return -1 on error | |
145 | */ | |
146 | int bt_ctf_get_int_signedness(const struct definition *field); | |
147 | ||
148 | /* | |
149 | * bt_ctf_get_int_base: return the base of an int or a negative value on error | |
150 | */ | |
151 | int bt_ctf_get_int_base(const struct definition *field); | |
152 | ||
153 | /* | |
154 | * bt_ctf_get_int_byte_order: return the byte order of an int or a negative | |
155 | * value on error | |
156 | */ | |
157 | int bt_ctf_get_int_byte_order(const struct definition *field); | |
158 | ||
fef0e521 MD |
159 | /* |
160 | * bt_ctf_get_int_len: return the size, in bits, of an int or a negative | |
161 | * value on error | |
162 | */ | |
163 | ssize_t bt_ctf_get_int_len(const struct definition *field); | |
164 | ||
8673030f JD |
165 | /* |
166 | * bt_ctf_get_encoding: return the encoding of an int or a string. | |
167 | * return a negative value on error | |
168 | */ | |
169 | enum ctf_string_encoding bt_ctf_get_encoding(const struct definition *field); | |
170 | ||
171 | /* | |
172 | * bt_ctf_get_array_len: return the len of an array or a negative | |
173 | * value on error | |
174 | */ | |
175 | int bt_ctf_get_array_len(const struct definition *field); | |
176 | ||
9843982d JD |
177 | /* |
178 | * Field access functions | |
179 | * | |
180 | * These functions return the value associated with the field passed in | |
181 | * parameter. | |
182 | * | |
183 | * If the field does not exist or is not of the type requested, the value | |
184 | * returned is undefined. To check if an error occured, use the | |
b330165c | 185 | * bt_ctf_field_get_error() function after accessing a field. |
9843982d | 186 | */ |
da320b83 JD |
187 | uint64_t bt_ctf_get_uint64(const struct definition *field); |
188 | int64_t bt_ctf_get_int64(const struct definition *field); | |
189 | char *bt_ctf_get_char_array(const struct definition *field); | |
190 | char *bt_ctf_get_string(const struct definition *field); | |
9843982d JD |
191 | |
192 | /* | |
b330165c | 193 | * bt_ctf_field_get_error: returns the last error code encountered while |
9843982d JD |
194 | * accessing a field and reset the error flag. |
195 | * Return 0 if no error, a negative value otherwise. | |
196 | */ | |
197 | int bt_ctf_field_get_error(void); | |
198 | ||
e003ab50 JD |
199 | /* |
200 | * bt_ctf_get_event_decl_list: set list pointer to an array of bt_ctf_event_decl | |
201 | * pointers and set count to the number of elements in the array. | |
202 | * | |
203 | * Return 0 on success and a negative value on error. | |
204 | */ | |
205 | int bt_ctf_get_event_decl_list(int handle_id, struct bt_context *ctx, | |
64c2c249 | 206 | struct bt_ctf_event_decl * const **list, |
e003ab50 JD |
207 | unsigned int *count); |
208 | ||
209 | /* | |
210 | * bt_ctf_get_decl_event_name: return the name of the event or NULL on error | |
211 | */ | |
212 | const char *bt_ctf_get_decl_event_name(const struct bt_ctf_event_decl *event); | |
213 | ||
64c2c249 JD |
214 | /* |
215 | * bt_ctf_get_decl_fields: set list pointer to an array of bt_ctf_field_decl | |
216 | * pointers and set count to the number of elements in the array. | |
217 | * | |
218 | * Returns 0 on success and a negative value on error | |
219 | */ | |
220 | int bt_ctf_get_decl_fields(struct bt_ctf_event_decl *event_decl, | |
221 | enum bt_ctf_scope scope, | |
222 | struct bt_ctf_field_decl const * const **list, | |
223 | unsigned int *count); | |
224 | ||
225 | /* | |
226 | * bt_ctf_get_decl_field_name: return the name of a field decl or NULL on error | |
227 | */ | |
228 | const char *bt_ctf_get_decl_field_name(const struct bt_ctf_field_decl *field); | |
229 | ||
9843982d | 230 | #endif /* _BABELTRACE_CTF_EVENTS_H */ |