Commit | Line | Data |
---|---|---|
bc37ae52 JG |
1 | #ifndef BABELTRACE_CTF_IR_TRACE_H |
2 | #define BABELTRACE_CTF_IR_TRACE_H | |
3 | ||
4 | /* | |
5 | * BabelTrace - CTF IR: Trace | |
6 | * | |
7 | * Copyright 2014 Jérémie Galarneau <jeremie.galarneau@efficios.com> | |
8 | * | |
9 | * Author: Jérémie Galarneau <jeremie.galarneau@efficios.com> | |
10 | * | |
11 | * Permission is hereby granted, free of charge, to any person obtaining a copy | |
12 | * of this software and associated documentation files (the "Software"), to deal | |
13 | * in the Software without restriction, including without limitation the rights | |
14 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | |
15 | * copies of the Software, and to permit persons to whom the Software is | |
16 | * furnished to do so, subject to the following conditions: | |
17 | * | |
18 | * The above copyright notice and this permission notice shall be included in | |
19 | * all copies or substantial portions of the Software. | |
20 | * | |
21 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | |
22 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | |
23 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | |
24 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | |
25 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | |
26 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | |
27 | * SOFTWARE. | |
28 | * | |
29 | * The Common Trace Format (CTF) Specification is available at | |
30 | * http://www.efficios.com/ctf | |
31 | */ | |
32 | ||
33 | #include <babeltrace/ctf-ir/event-types.h> | |
410d0373 | 34 | #include <stdint.h> |
bc37ae52 JG |
35 | |
36 | #ifdef __cplusplus | |
37 | extern "C" { | |
38 | #endif | |
39 | ||
40 | struct bt_ctf_trace; | |
41 | struct bt_ctf_stream; | |
42 | struct bt_ctf_stream_class; | |
43 | struct bt_ctf_clock; | |
44 | ||
3487c9f3 JG |
45 | enum bt_environment_field_type { |
46 | BT_ENVIRONMENT_FIELD_TYPE_UNKNOWN = -1, | |
47 | BT_ENVIRONMENT_FIELD_TYPE_STRING = 0, | |
48 | BT_ENVIRONMENT_FIELD_TYPE_INTEGER = 1, | |
49 | }; | |
50 | ||
bc37ae52 JG |
51 | /* |
52 | * bt_ctf_trace_create: create a trace instance. | |
53 | * | |
d246b111 JG |
54 | * Allocate a new trace. |
55 | * | |
56 | * A trace's default packet header is a structure initialized with the following | |
57 | * fields: | |
58 | * - uint32_t magic | |
59 | * - uint8_t uuid[16] | |
60 | * - uint32_t stream_id | |
bc37ae52 JG |
61 | * |
62 | * Returns a new trace on success, NULL on error. | |
63 | */ | |
64 | extern struct bt_ctf_trace *bt_ctf_trace_create(void); | |
65 | ||
66 | /* | |
67 | * bt_ctf_trace_create_stream: create a stream instance. | |
68 | * | |
69 | * Allocate a new stream instance and register it to the trace. The creation of | |
70 | * a stream sets its reference count to 1. | |
71 | * | |
72 | * @param trace Trace instance. | |
73 | * @param stream_class Stream class to instantiate. | |
74 | * | |
75 | * Returns a new stream on success, NULL on error. | |
76 | */ | |
77 | extern struct bt_ctf_stream *bt_ctf_trace_create_stream( | |
78 | struct bt_ctf_trace *trace, | |
79 | struct bt_ctf_stream_class *stream_class); | |
80 | ||
81 | /* | |
3487c9f3 JG |
82 | * bt_ctf_trace_add_environment_field: add a string environment field to the |
83 | * trace. | |
bc37ae52 | 84 | * |
3487c9f3 JG |
85 | * Add a string environment field to the trace. The name and value parameters |
86 | * are copied. | |
bc37ae52 JG |
87 | * |
88 | * @param trace Trace instance. | |
89 | * @param name Name of the environment field (will be copied). | |
90 | * @param value Value of the environment field (will be copied). | |
91 | * | |
92 | * Returns 0 on success, a negative value on error. | |
93 | */ | |
94 | extern int bt_ctf_trace_add_environment_field(struct bt_ctf_trace *trace, | |
95 | const char *name, | |
96 | const char *value); | |
97 | ||
3487c9f3 JG |
98 | /* |
99 | * bt_ctf_trace_add_environment_field_integer: add an integer environment | |
100 | * field to the trace. | |
101 | * | |
102 | * Add an integer environment field to the trace. The name parameter is | |
103 | * copied. | |
104 | * | |
105 | * @param trace Trace instance. | |
106 | * @param name Name of the environment field (will be copied). | |
107 | * @param value Value of the environment field. | |
108 | * | |
109 | * Returns 0 on success, a negative value on error. | |
110 | */ | |
111 | extern int bt_ctf_trace_add_environment_field_integer( | |
112 | struct bt_ctf_trace *trace, const char *name, | |
113 | int64_t value); | |
114 | ||
e6fa2160 JG |
115 | /* |
116 | * bt_ctf_trace_get_environment_field_count: get environment field count. | |
117 | * | |
118 | * Get the trace's environment field count. | |
119 | * | |
120 | * @param trace Trace instance. | |
121 | * | |
122 | * Returns the environment field count, a negative value on error. | |
123 | */ | |
124 | extern int bt_ctf_trace_get_environment_field_count( | |
125 | struct bt_ctf_trace *trace); | |
126 | ||
127 | /* | |
128 | * bt_ctf_trace_get_environment_field_type: get environment field type. | |
129 | * | |
130 | * Get an environment field's type. | |
131 | * | |
132 | * @param trace Trace instance. | |
133 | * @param index Index of the environment field. | |
134 | * | |
135 | * Returns the environment field count, a negative value on error. | |
136 | */ | |
137 | extern enum bt_environment_field_type | |
138 | bt_ctf_trace_get_environment_field_type(struct bt_ctf_trace *trace, | |
139 | int index); | |
140 | ||
141 | /* | |
142 | * bt_ctf_trace_get_environment_field_name: get environment field name. | |
143 | * | |
144 | * Get an environment field's name. The string's ownership is not | |
145 | * transferred to the caller. | |
146 | * | |
147 | * @param trace Trace instance. | |
148 | * @param index Index of the environment field. | |
149 | * | |
150 | * Returns the environment field's name, NULL on error. | |
151 | */ | |
152 | extern const char * | |
153 | bt_ctf_trace_get_environment_field_name(struct bt_ctf_trace *trace, | |
154 | int index); | |
155 | ||
156 | /* | |
157 | * bt_ctf_trace_get_environment_field_value_string: get environment field | |
158 | * string value. | |
159 | * | |
160 | * Get an environment field's string value. The string's ownership is not | |
161 | * transferred to the caller. | |
162 | * | |
163 | * @param trace Trace instance. | |
164 | * @param index Index of the environment field. | |
165 | * | |
166 | * Returns the environment field's string value, NULL on error. | |
167 | */ | |
168 | extern const char * | |
169 | bt_ctf_trace_get_environment_field_value_string(struct bt_ctf_trace *trace, | |
170 | int index); | |
171 | ||
172 | /* | |
173 | * bt_ctf_trace_get_environment_field_value_integer: get environment field | |
174 | * integer value. | |
175 | * | |
176 | * Get an environment field's integer value. | |
177 | * | |
178 | * @param trace Trace instance. | |
179 | * @param index Index of the environment field. | |
180 | * | |
181 | * Returns the environment field's integer value, a negative value on error. | |
182 | */ | |
183 | extern int | |
184 | bt_ctf_trace_get_environment_field_value_integer(struct bt_ctf_trace *trace, | |
185 | int index, int64_t *value); | |
186 | ||
bc37ae52 JG |
187 | /* |
188 | * bt_ctf_trace_add_clock: add a clock to the trace. | |
189 | * | |
190 | * Add a clock to the trace. Clocks assigned to stream classes must be | |
191 | * added to the trace beforehand. | |
192 | * | |
193 | * @param trace Trace instance. | |
194 | * @param clock Clock to add to the trace. | |
195 | * | |
196 | * Returns 0 on success, a negative value on error. | |
197 | */ | |
198 | extern int bt_ctf_trace_add_clock(struct bt_ctf_trace *trace, | |
199 | struct bt_ctf_clock *clock); | |
200 | ||
884cd6c3 JG |
201 | /* |
202 | * bt_ctf_trace_get_clock_count: get the number of clocks | |
ef0c4a15 | 203 | * associated with the trace. |
884cd6c3 JG |
204 | * |
205 | * @param trace Trace instance. | |
206 | * | |
207 | * Returns the clock count on success, a negative value on error. | |
208 | */ | |
209 | extern int bt_ctf_trace_get_clock_count(struct bt_ctf_trace *trace); | |
210 | ||
211 | /* | |
212 | * bt_ctf_trace_get_clock: get a trace's clock at index. | |
213 | * | |
214 | * @param trace Trace instance. | |
215 | * @param index Index of the clock in the given trace. | |
216 | * | |
217 | * Return a clock instance on success, NULL on error. | |
218 | */ | |
219 | extern struct bt_ctf_clock *bt_ctf_trace_get_clock( | |
220 | struct bt_ctf_trace *trace, int index); | |
221 | ||
ef0c4a15 JG |
222 | /* |
223 | * bt_ctf_trace_add_stream_class: add a stream_class to the trace. | |
224 | * | |
225 | * Add a stream class to the trace. | |
226 | * | |
227 | * @param trace Trace instance. | |
228 | * @param stream_class Stream class to add to the trace. | |
229 | * | |
230 | * Returns 0 on success, a negative value on error. | |
231 | */ | |
232 | extern int bt_ctf_trace_add_stream_class(struct bt_ctf_trace *trace, | |
233 | struct bt_ctf_stream_class *stream_class); | |
234 | ||
235 | /* | |
236 | * bt_ctf_trace_get_stream_class_count: get the number of stream classes | |
237 | * associated with the trace. | |
238 | * | |
239 | * @param trace Trace instance. | |
240 | * | |
241 | * Returns the stream class count on success, a negative value on error. | |
242 | */ | |
243 | extern int bt_ctf_trace_get_stream_class_count(struct bt_ctf_trace *trace); | |
244 | ||
245 | /* | |
246 | * bt_ctf_trace_get_stream_class: get a trace's stream class at index. | |
247 | * | |
248 | * @param trace Trace instance. | |
249 | * @param index Index of the stream class in the given trace. | |
250 | * | |
251 | * Return a stream class on success, NULL on error. | |
252 | */ | |
253 | extern struct bt_ctf_stream_class *bt_ctf_trace_get_stream_class( | |
254 | struct bt_ctf_trace *trace, int index); | |
255 | ||
bc37ae52 JG |
256 | /* |
257 | * bt_ctf_trace_get_metadata_string: get metadata string. | |
258 | * | |
259 | * Get the trace's TSDL metadata. The caller assumes the ownership of the | |
260 | * returned string. | |
261 | * | |
262 | * @param trace Trace instance. | |
263 | * | |
264 | * Returns the metadata string on success, NULL on error. | |
265 | */ | |
266 | extern char *bt_ctf_trace_get_metadata_string(struct bt_ctf_trace *trace); | |
267 | ||
268 | /* | |
4ed90fb3 JG |
269 | * bt_ctf_trace_get_byte_order: get a trace's byte order. |
270 | * | |
271 | * Get the trace's byte order. | |
272 | * | |
273 | * @param trace Trace instance. | |
274 | * | |
275 | * Returns the trace's endianness, BT_CTF_BYTE_ORDER_UNKNOWN on error. | |
276 | */ | |
277 | extern enum bt_ctf_byte_order bt_ctf_trace_get_byte_order( | |
278 | struct bt_ctf_trace *trace); | |
279 | ||
280 | /* | |
281 | * bt_ctf_trace_set_byte_order: set a trace's byte order. | |
bc37ae52 | 282 | * |
c35a1669 | 283 | * Set the trace's byte order. Defaults to the current host's endianness. |
bc37ae52 JG |
284 | * |
285 | * @param trace Trace instance. | |
286 | * @param byte_order Trace's byte order. | |
287 | * | |
288 | * Returns 0 on success, a negative value on error. | |
c35a1669 JG |
289 | * |
290 | * Note: byte_order must not be BT_CTF_BYTE_ORDER_NATIVE since, according | |
291 | * to the CTF specification, is defined as "the byte order described in the | |
292 | * trace description". | |
bc37ae52 JG |
293 | */ |
294 | extern int bt_ctf_trace_set_byte_order(struct bt_ctf_trace *trace, | |
295 | enum bt_ctf_byte_order byte_order); | |
296 | ||
d246b111 JG |
297 | /* |
298 | * bt_ctf_trace_get_packet_header_type: get a trace's packet header type. | |
299 | * | |
300 | * Get the trace's packet header type. | |
301 | * | |
302 | * @param trace Trace instance. | |
303 | * | |
304 | * Returns the trace's packet header type (a structure) on success, NULL on | |
305 | * error. | |
306 | */ | |
307 | extern struct bt_ctf_field_type *bt_ctf_trace_get_packet_header_type( | |
308 | struct bt_ctf_trace *trace); | |
309 | ||
310 | /* | |
311 | * bt_ctf_trace_set_packet_header_type: set a trace's packet header type. | |
312 | * | |
313 | * Set the trace's packet header type. | |
314 | * | |
315 | * @param trace Trace instance. | |
316 | * @param packet_header_type Packet header field type (must be a structure). | |
317 | * | |
318 | * Returns 0 on success, a negative value on error. | |
319 | */ | |
320 | extern int bt_ctf_trace_set_packet_header_type(struct bt_ctf_trace *trace, | |
321 | struct bt_ctf_field_type *packet_header_type); | |
322 | ||
bc37ae52 JG |
323 | /* |
324 | * bt_ctf_trace_get and bt_ctf_trace_put: increment and decrement the | |
325 | * trace's reference count. | |
326 | * | |
327 | * These functions ensure that the trace won't be destroyed while it | |
328 | * is in use. The same number of get and put (plus one extra put to | |
329 | * release the initial reference done at creation) have to be done to | |
330 | * destroy a trace. | |
331 | * | |
332 | * When the trace's reference count is decremented to 0 by a | |
333 | * bt_ctf_trace_put, the trace is freed. | |
334 | * | |
335 | * @param trace Trace instance. | |
336 | */ | |
337 | extern void bt_ctf_trace_get(struct bt_ctf_trace *trace); | |
338 | extern void bt_ctf_trace_put(struct bt_ctf_trace *trace); | |
339 | ||
340 | #ifdef __cplusplus | |
341 | } | |
342 | #endif | |
343 | ||
344 | #endif /* BABELTRACE_CTF_IR_TRACE_H */ |