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> | |
34 | ||
35 | #ifdef __cplusplus | |
36 | extern "C" { | |
37 | #endif | |
38 | ||
39 | struct bt_ctf_trace; | |
40 | struct bt_ctf_stream; | |
41 | struct bt_ctf_stream_class; | |
42 | struct bt_ctf_clock; | |
43 | ||
3487c9f3 JG |
44 | enum bt_environment_field_type { |
45 | BT_ENVIRONMENT_FIELD_TYPE_UNKNOWN = -1, | |
46 | BT_ENVIRONMENT_FIELD_TYPE_STRING = 0, | |
47 | BT_ENVIRONMENT_FIELD_TYPE_INTEGER = 1, | |
48 | }; | |
49 | ||
bc37ae52 JG |
50 | /* |
51 | * bt_ctf_trace_create: create a trace instance. | |
52 | * | |
d246b111 JG |
53 | * Allocate a new trace. |
54 | * | |
55 | * A trace's default packet header is a structure initialized with the following | |
56 | * fields: | |
57 | * - uint32_t magic | |
58 | * - uint8_t uuid[16] | |
59 | * - uint32_t stream_id | |
bc37ae52 JG |
60 | * |
61 | * Returns a new trace on success, NULL on error. | |
62 | */ | |
63 | extern struct bt_ctf_trace *bt_ctf_trace_create(void); | |
64 | ||
65 | /* | |
66 | * bt_ctf_trace_create_stream: create a stream instance. | |
67 | * | |
68 | * Allocate a new stream instance and register it to the trace. The creation of | |
69 | * a stream sets its reference count to 1. | |
70 | * | |
71 | * @param trace Trace instance. | |
72 | * @param stream_class Stream class to instantiate. | |
73 | * | |
74 | * Returns a new stream on success, NULL on error. | |
75 | */ | |
76 | extern struct bt_ctf_stream *bt_ctf_trace_create_stream( | |
77 | struct bt_ctf_trace *trace, | |
78 | struct bt_ctf_stream_class *stream_class); | |
79 | ||
80 | /* | |
3487c9f3 JG |
81 | * bt_ctf_trace_add_environment_field: add a string environment field to the |
82 | * trace. | |
bc37ae52 | 83 | * |
3487c9f3 JG |
84 | * Add a string environment field to the trace. The name and value parameters |
85 | * are copied. | |
bc37ae52 JG |
86 | * |
87 | * @param trace Trace instance. | |
88 | * @param name Name of the environment field (will be copied). | |
89 | * @param value Value of the environment field (will be copied). | |
90 | * | |
91 | * Returns 0 on success, a negative value on error. | |
92 | */ | |
93 | extern int bt_ctf_trace_add_environment_field(struct bt_ctf_trace *trace, | |
94 | const char *name, | |
95 | const char *value); | |
96 | ||
3487c9f3 JG |
97 | /* |
98 | * bt_ctf_trace_add_environment_field_integer: add an integer environment | |
99 | * field to the trace. | |
100 | * | |
101 | * Add an integer environment field to the trace. The name parameter is | |
102 | * copied. | |
103 | * | |
104 | * @param trace Trace instance. | |
105 | * @param name Name of the environment field (will be copied). | |
106 | * @param value Value of the environment field. | |
107 | * | |
108 | * Returns 0 on success, a negative value on error. | |
109 | */ | |
110 | extern int bt_ctf_trace_add_environment_field_integer( | |
111 | struct bt_ctf_trace *trace, const char *name, | |
112 | int64_t value); | |
113 | ||
e6fa2160 JG |
114 | /* |
115 | * bt_ctf_trace_get_environment_field_count: get environment field count. | |
116 | * | |
117 | * Get the trace's environment field count. | |
118 | * | |
119 | * @param trace Trace instance. | |
120 | * | |
121 | * Returns the environment field count, a negative value on error. | |
122 | */ | |
123 | extern int bt_ctf_trace_get_environment_field_count( | |
124 | struct bt_ctf_trace *trace); | |
125 | ||
126 | /* | |
127 | * bt_ctf_trace_get_environment_field_type: get environment field type. | |
128 | * | |
129 | * Get an environment field's type. | |
130 | * | |
131 | * @param trace Trace instance. | |
132 | * @param index Index of the environment field. | |
133 | * | |
134 | * Returns the environment field count, a negative value on error. | |
135 | */ | |
136 | extern enum bt_environment_field_type | |
137 | bt_ctf_trace_get_environment_field_type(struct bt_ctf_trace *trace, | |
138 | int index); | |
139 | ||
140 | /* | |
141 | * bt_ctf_trace_get_environment_field_name: get environment field name. | |
142 | * | |
143 | * Get an environment field's name. The string's ownership is not | |
144 | * transferred to the caller. | |
145 | * | |
146 | * @param trace Trace instance. | |
147 | * @param index Index of the environment field. | |
148 | * | |
149 | * Returns the environment field's name, NULL on error. | |
150 | */ | |
151 | extern const char * | |
152 | bt_ctf_trace_get_environment_field_name(struct bt_ctf_trace *trace, | |
153 | int index); | |
154 | ||
155 | /* | |
156 | * bt_ctf_trace_get_environment_field_value_string: get environment field | |
157 | * string value. | |
158 | * | |
159 | * Get an environment field's string value. The string's ownership is not | |
160 | * transferred to the caller. | |
161 | * | |
162 | * @param trace Trace instance. | |
163 | * @param index Index of the environment field. | |
164 | * | |
165 | * Returns the environment field's string value, NULL on error. | |
166 | */ | |
167 | extern const char * | |
168 | bt_ctf_trace_get_environment_field_value_string(struct bt_ctf_trace *trace, | |
169 | int index); | |
170 | ||
171 | /* | |
172 | * bt_ctf_trace_get_environment_field_value_integer: get environment field | |
173 | * integer value. | |
174 | * | |
175 | * Get an environment field's integer value. | |
176 | * | |
177 | * @param trace Trace instance. | |
178 | * @param index Index of the environment field. | |
179 | * | |
180 | * Returns the environment field's integer value, a negative value on error. | |
181 | */ | |
182 | extern int | |
183 | bt_ctf_trace_get_environment_field_value_integer(struct bt_ctf_trace *trace, | |
184 | int index, int64_t *value); | |
185 | ||
bc37ae52 JG |
186 | /* |
187 | * bt_ctf_trace_add_clock: add a clock to the trace. | |
188 | * | |
189 | * Add a clock to the trace. Clocks assigned to stream classes must be | |
190 | * added to the trace beforehand. | |
191 | * | |
192 | * @param trace Trace instance. | |
193 | * @param clock Clock to add to the trace. | |
194 | * | |
195 | * Returns 0 on success, a negative value on error. | |
196 | */ | |
197 | extern int bt_ctf_trace_add_clock(struct bt_ctf_trace *trace, | |
198 | struct bt_ctf_clock *clock); | |
199 | ||
884cd6c3 JG |
200 | /* |
201 | * bt_ctf_trace_get_clock_count: get the number of clocks | |
202 | * associated to the trace. | |
203 | * | |
204 | * @param trace Trace instance. | |
205 | * | |
206 | * Returns the clock count on success, a negative value on error. | |
207 | */ | |
208 | extern int bt_ctf_trace_get_clock_count(struct bt_ctf_trace *trace); | |
209 | ||
210 | /* | |
211 | * bt_ctf_trace_get_clock: get a trace's clock at index. | |
212 | * | |
213 | * @param trace Trace instance. | |
214 | * @param index Index of the clock in the given trace. | |
215 | * | |
216 | * Return a clock instance on success, NULL on error. | |
217 | */ | |
218 | extern struct bt_ctf_clock *bt_ctf_trace_get_clock( | |
219 | struct bt_ctf_trace *trace, int index); | |
220 | ||
bc37ae52 JG |
221 | /* |
222 | * bt_ctf_trace_get_metadata_string: get metadata string. | |
223 | * | |
224 | * Get the trace's TSDL metadata. The caller assumes the ownership of the | |
225 | * returned string. | |
226 | * | |
227 | * @param trace Trace instance. | |
228 | * | |
229 | * Returns the metadata string on success, NULL on error. | |
230 | */ | |
231 | extern char *bt_ctf_trace_get_metadata_string(struct bt_ctf_trace *trace); | |
232 | ||
233 | /* | |
234 | * bt_ctf_trace_set_byte_order: set a field type's byte order. | |
235 | * | |
c35a1669 | 236 | * Set the trace's byte order. Defaults to the current host's endianness. |
bc37ae52 JG |
237 | * |
238 | * @param trace Trace instance. | |
239 | * @param byte_order Trace's byte order. | |
240 | * | |
241 | * Returns 0 on success, a negative value on error. | |
c35a1669 JG |
242 | * |
243 | * Note: byte_order must not be BT_CTF_BYTE_ORDER_NATIVE since, according | |
244 | * to the CTF specification, is defined as "the byte order described in the | |
245 | * trace description". | |
bc37ae52 JG |
246 | */ |
247 | extern int bt_ctf_trace_set_byte_order(struct bt_ctf_trace *trace, | |
248 | enum bt_ctf_byte_order byte_order); | |
249 | ||
d246b111 JG |
250 | /* |
251 | * bt_ctf_trace_get_packet_header_type: get a trace's packet header type. | |
252 | * | |
253 | * Get the trace's packet header type. | |
254 | * | |
255 | * @param trace Trace instance. | |
256 | * | |
257 | * Returns the trace's packet header type (a structure) on success, NULL on | |
258 | * error. | |
259 | */ | |
260 | extern struct bt_ctf_field_type *bt_ctf_trace_get_packet_header_type( | |
261 | struct bt_ctf_trace *trace); | |
262 | ||
263 | /* | |
264 | * bt_ctf_trace_set_packet_header_type: set a trace's packet header type. | |
265 | * | |
266 | * Set the trace's packet header type. | |
267 | * | |
268 | * @param trace Trace instance. | |
269 | * @param packet_header_type Packet header field type (must be a structure). | |
270 | * | |
271 | * Returns 0 on success, a negative value on error. | |
272 | */ | |
273 | extern int bt_ctf_trace_set_packet_header_type(struct bt_ctf_trace *trace, | |
274 | struct bt_ctf_field_type *packet_header_type); | |
275 | ||
bc37ae52 JG |
276 | /* |
277 | * bt_ctf_trace_get and bt_ctf_trace_put: increment and decrement the | |
278 | * trace's reference count. | |
279 | * | |
280 | * These functions ensure that the trace won't be destroyed while it | |
281 | * is in use. The same number of get and put (plus one extra put to | |
282 | * release the initial reference done at creation) have to be done to | |
283 | * destroy a trace. | |
284 | * | |
285 | * When the trace's reference count is decremented to 0 by a | |
286 | * bt_ctf_trace_put, the trace is freed. | |
287 | * | |
288 | * @param trace Trace instance. | |
289 | */ | |
290 | extern void bt_ctf_trace_get(struct bt_ctf_trace *trace); | |
291 | extern void bt_ctf_trace_put(struct bt_ctf_trace *trace); | |
292 | ||
293 | #ifdef __cplusplus | |
294 | } | |
295 | #endif | |
296 | ||
297 | #endif /* BABELTRACE_CTF_IR_TRACE_H */ |