1 #ifndef BABELTRACE_CTF_IR_TRACE_H
2 #define BABELTRACE_CTF_IR_TRACE_H
5 * BabelTrace - CTF IR: Trace
7 * Copyright 2014 Jérémie Galarneau <jeremie.galarneau@efficios.com>
9 * Author: Jérémie Galarneau <jeremie.galarneau@efficios.com>
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:
18 * The above copyright notice and this permission notice shall be included in
19 * all copies or substantial portions of the Software.
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
29 * The Common Trace Format (CTF) Specification is available at
30 * http://www.efficios.com/ctf
33 #include <babeltrace/ctf-ir/field-types.h>
34 #include <babeltrace/values.h>
35 #include <babeltrace/babeltrace-internal.h>
44 struct bt_ctf_stream_class
;
48 * bt_ctf_trace_create: create a trace instance.
50 * Allocate a new trace.
52 * A trace's default packet header is a structure initialized with the following
56 * - uint32_t stream_id
58 * Returns a new trace on success, NULL on error.
61 struct bt_ctf_trace
*bt_ctf_trace_create(void);
64 * bt_ctf_trace_set_environment_field: sets an environment field to the
67 * Sets an environment field to the trace. The name parameter is
68 * copied, whereas the value parameter's reference count is incremented
69 * (if the function succeeds).
71 * If a value exists in the environment for the specified name, it is
72 * replaced by the new value.
74 * The value parameter _must_ be either an integer value object or a
75 * string value object. Other object types are not supported.
77 * @param trace Trace instance.
78 * @param name Name of the environment field (will be copied).
79 * @param value Value of the environment field.
81 * Returns 0 on success, a negative value on error.
84 int bt_ctf_trace_set_environment_field(
85 struct bt_ctf_trace
*trace
, const char *name
,
86 struct bt_value
*value
);
89 * bt_ctf_trace_set_environment_field_string: sets a string environment
92 * Sets a string environment field to the trace. This is a helper
93 * function which corresponds to calling
94 * bt_ctf_trace_set_environment_field() with a string object.
96 * @param trace Trace instance.
97 * @param name Name of the environment field (will be copied).
98 * @param value Value of the environment field (will be copied).
100 * Returns 0 on success, a negative value on error.
103 int bt_ctf_trace_set_environment_field_string(
104 struct bt_ctf_trace
*trace
, const char *name
,
108 * bt_ctf_trace_set_environment_field_integer: sets an integer environment
109 * field to the trace.
111 * Sets an integer environment field to the trace. This is a helper
112 * function which corresponds to calling
113 * bt_ctf_trace_set_environment_field() with an integer object.
115 * @param trace Trace instance.
116 * @param name Name of the environment field (will be copied).
117 * @param value Value of the environment field.
119 * Returns 0 on success, a negative value on error.
122 int bt_ctf_trace_set_environment_field_integer(
123 struct bt_ctf_trace
*trace
, const char *name
,
127 * bt_ctf_trace_get_environment_field_count: get environment field count.
129 * Get the trace's environment field count.
131 * @param trace Trace instance.
133 * Returns the environment field count, a negative value on error.
136 int bt_ctf_trace_get_environment_field_count(
137 struct bt_ctf_trace
*trace
);
140 * bt_ctf_trace_get_environment_field_name: get environment field name.
142 * Get an environment field's name. The string's ownership is not
143 * transferred to the caller. The string data is valid as long as
144 * this trace's environment is not modified.
146 * @param trace Trace instance.
147 * @param index Index of the environment field.
149 * Returns the environment field's name, NULL on error.
153 bt_ctf_trace_get_environment_field_name(struct bt_ctf_trace
*trace
,
157 * bt_ctf_trace_get_environment_field_value: get environment
158 * field value (an object).
160 * Get an environment field's value (an object). The returned object's
161 * reference count is incremented. When done with the object, the caller
162 * must call bt_value_put() on it.
164 * @param trace Trace instance.
165 * @param index Index of the environment field.
167 * Returns the environment field's object value, NULL on error.
171 bt_ctf_trace_get_environment_field_value(struct bt_ctf_trace
*trace
,
175 * bt_ctf_trace_get_environment_field_value_by_name: get environment
176 * field value (an object) by name.
178 * Get an environment field's value (an object) by its field name. The
179 * returned object's reference count is incremented. When done with the
180 * object, the caller must call bt_value_put() on it.
182 * @param trace Trace instance.
183 * @param name Environment field's name
185 * Returns the environment field's object value, NULL on error.
189 bt_ctf_trace_get_environment_field_value_by_name(struct bt_ctf_trace
*trace
,
193 * bt_ctf_trace_add_clock: add a clock to the trace.
195 * Add a clock to the trace. Clocks assigned to stream classes must be
196 * added to the trace beforehand.
198 * @param trace Trace instance.
199 * @param clock Clock to add to the trace.
201 * Returns 0 on success, a negative value on error.
204 int bt_ctf_trace_add_clock(struct bt_ctf_trace
*trace
,
205 struct bt_ctf_clock
*clock
);
208 * bt_ctf_trace_get_clock_count: get the number of clocks
209 * associated with the trace.
211 * @param trace Trace instance.
213 * Returns the clock count on success, a negative value on error.
216 int bt_ctf_trace_get_clock_count(struct bt_ctf_trace
*trace
);
219 * bt_ctf_trace_get_clock: get a trace's clock at index.
221 * @param trace Trace instance.
222 * @param index Index of the clock in the given trace.
224 * Return a clock instance on success, NULL on error.
227 struct bt_ctf_clock
*bt_ctf_trace_get_clock(
228 struct bt_ctf_trace
*trace
, int index
);
231 * bt_ctf_trace_add_stream_class: add a stream_class to the trace.
233 * Add a stream class to the trace.
235 * @param trace Trace instance.
236 * @param stream_class Stream class to add to the trace.
238 * Returns 0 on success, a negative value on error.
241 int bt_ctf_trace_add_stream_class(struct bt_ctf_trace
*trace
,
242 struct bt_ctf_stream_class
*stream_class
);
245 * bt_ctf_trace_get_stream_class_count: get the number of stream classes
246 * associated with the trace.
248 * @param trace Trace instance.
250 * Returns the stream class count on success, a negative value on error.
253 int bt_ctf_trace_get_stream_class_count(struct bt_ctf_trace
*trace
);
256 * bt_ctf_trace_get_stream_class: get a trace's stream class at index.
258 * @param trace Trace instance.
259 * @param index Index of the stream class in the given trace.
261 * Return a stream class on success, NULL on error.
264 struct bt_ctf_stream_class
*bt_ctf_trace_get_stream_class(
265 struct bt_ctf_trace
*trace
, int index
);
268 * bt_ctf_trace_get_stream_class_by_id: get a trace's stream class by ID.
270 * @param trace Trace instance.
271 * @param index ID of the stream class in the given trace.
273 * Return a stream class on success, NULL on error.
276 struct bt_ctf_stream_class
*bt_ctf_trace_get_stream_class_by_id(
277 struct bt_ctf_trace
*trace
, uint32_t id
);
280 * bt_ctf_trace_get_clock_by_name: get a trace's clock by name
282 * @param trace Trace instance.
283 * @param name Name of the clock in the given trace.
285 * Return a clock instance on success, NULL on error.
288 struct bt_ctf_clock
*bt_ctf_trace_get_clock_by_name(
289 struct bt_ctf_trace
*trace
, const char *name
);
292 * bt_ctf_trace_get_metadata_string: get metadata string.
294 * Get the trace's TSDL metadata. The caller assumes the ownership of the
297 * @param trace Trace instance.
299 * Returns the metadata string on success, NULL on error.
302 char *bt_ctf_trace_get_metadata_string(struct bt_ctf_trace
*trace
);
305 * bt_ctf_trace_get_byte_order: get a trace's byte order.
307 * Get the trace's byte order.
309 * @param trace Trace instance.
311 * Returns the trace's endianness, BT_CTF_BYTE_ORDER_UNKNOWN on error.
314 enum bt_ctf_byte_order
bt_ctf_trace_get_byte_order(
315 struct bt_ctf_trace
*trace
);
318 * bt_ctf_trace_set_byte_order: set a trace's byte order.
320 * Set the trace's byte order. Defaults to the current host's endianness.
322 * @param trace Trace instance.
323 * @param byte_order Trace's byte order.
325 * Returns 0 on success, a negative value on error.
327 * Note: byte_order must not be BT_CTF_BYTE_ORDER_NATIVE since, according
328 * to the CTF specification, is defined as "the byte order described in the
329 * trace description".
332 int bt_ctf_trace_set_byte_order(struct bt_ctf_trace
*trace
,
333 enum bt_ctf_byte_order byte_order
);
336 * bt_ctf_trace_get_packet_header_type: get a trace's packet header type.
338 * Get the trace's packet header type.
340 * @param trace Trace instance.
342 * Returns the trace's packet header type (a structure) on success, NULL on
346 struct bt_ctf_field_type
*bt_ctf_trace_get_packet_header_type(
347 struct bt_ctf_trace
*trace
);
350 * bt_ctf_trace_set_packet_header_type: set a trace's packet header type.
352 * Set the trace's packet header type.
354 * @param trace Trace instance.
355 * @param packet_header_type Packet header field type (must be a structure).
357 * Returns 0 on success, a negative value on error.
360 int bt_ctf_trace_set_packet_header_type(struct bt_ctf_trace
*trace
,
361 struct bt_ctf_field_type
*packet_header_type
);
367 #endif /* BABELTRACE_CTF_IR_TRACE_H */