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/event-types.h>
41 struct bt_ctf_stream_class
;
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,
51 * bt_ctf_trace_create: create a trace instance.
53 * Allocate a new trace.
55 * A trace's default packet header is a structure initialized with the following
59 * - uint32_t stream_id
61 * Returns a new trace on success, NULL on error.
63 extern struct bt_ctf_trace
*bt_ctf_trace_create(void);
66 * bt_ctf_trace_create_stream: create a stream instance.
68 * Allocate a new stream instance and register it to the trace. The creation of
69 * a stream sets its reference count to 1.
71 * @param trace Trace instance.
72 * @param stream_class Stream class to instantiate.
74 * Returns a new stream on success, NULL on error.
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
);
81 * bt_ctf_trace_add_environment_field: add a string environment field to the
84 * Add a string environment field to the trace. The name and value parameters
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).
91 * Returns 0 on success, a negative value on error.
93 extern int bt_ctf_trace_add_environment_field(struct bt_ctf_trace
*trace
,
98 * bt_ctf_trace_add_environment_field_integer: add an integer environment
101 * Add an integer environment field to the trace. The name parameter is
104 * @param trace Trace instance.
105 * @param name Name of the environment field (will be copied).
106 * @param value Value of the environment field.
108 * Returns 0 on success, a negative value on error.
110 extern int bt_ctf_trace_add_environment_field_integer(
111 struct bt_ctf_trace
*trace
, const char *name
,
115 * bt_ctf_trace_get_environment_field_count: get environment field count.
117 * Get the trace's environment field count.
119 * @param trace Trace instance.
121 * Returns the environment field count, a negative value on error.
123 extern int bt_ctf_trace_get_environment_field_count(
124 struct bt_ctf_trace
*trace
);
127 * bt_ctf_trace_get_environment_field_type: get environment field type.
129 * Get an environment field's type.
131 * @param trace Trace instance.
132 * @param index Index of the environment field.
134 * Returns the environment field count, a negative value on error.
136 extern enum bt_environment_field_type
137 bt_ctf_trace_get_environment_field_type(struct bt_ctf_trace
*trace
,
141 * bt_ctf_trace_get_environment_field_name: get environment field name.
143 * Get an environment field's name. The string's ownership is not
144 * transferred to the caller.
146 * @param trace Trace instance.
147 * @param index Index of the environment field.
149 * Returns the environment field's name, NULL on error.
152 bt_ctf_trace_get_environment_field_name(struct bt_ctf_trace
*trace
,
156 * bt_ctf_trace_get_environment_field_value_string: get environment field
159 * Get an environment field's string value. The string's ownership is not
160 * transferred to the caller.
162 * @param trace Trace instance.
163 * @param index Index of the environment field.
165 * Returns the environment field's string value, NULL on error.
168 bt_ctf_trace_get_environment_field_value_string(struct bt_ctf_trace
*trace
,
172 * bt_ctf_trace_get_environment_field_value_integer: get environment field
175 * Get an environment field's integer value.
177 * @param trace Trace instance.
178 * @param index Index of the environment field.
180 * Returns the environment field's integer value, a negative value on error.
183 bt_ctf_trace_get_environment_field_value_integer(struct bt_ctf_trace
*trace
,
184 int index
, int64_t *value
);
187 * bt_ctf_trace_add_clock: add a clock to the trace.
189 * Add a clock to the trace. Clocks assigned to stream classes must be
190 * added to the trace beforehand.
192 * @param trace Trace instance.
193 * @param clock Clock to add to the trace.
195 * Returns 0 on success, a negative value on error.
197 extern int bt_ctf_trace_add_clock(struct bt_ctf_trace
*trace
,
198 struct bt_ctf_clock
*clock
);
201 * bt_ctf_trace_get_clock_count: get the number of clocks
202 * associated to the trace.
204 * @param trace Trace instance.
206 * Returns the clock count on success, a negative value on error.
208 extern int bt_ctf_trace_get_clock_count(struct bt_ctf_trace
*trace
);
211 * bt_ctf_trace_get_clock: get a trace's clock at index.
213 * @param trace Trace instance.
214 * @param index Index of the clock in the given trace.
216 * Return a clock instance on success, NULL on error.
218 extern struct bt_ctf_clock
*bt_ctf_trace_get_clock(
219 struct bt_ctf_trace
*trace
, int index
);
222 * bt_ctf_trace_get_metadata_string: get metadata string.
224 * Get the trace's TSDL metadata. The caller assumes the ownership of the
227 * @param trace Trace instance.
229 * Returns the metadata string on success, NULL on error.
231 extern char *bt_ctf_trace_get_metadata_string(struct bt_ctf_trace
*trace
);
234 * bt_ctf_trace_set_byte_order: set a field type's byte order.
236 * Set the trace's byte order. Defaults to the current host's endianness.
238 * @param trace Trace instance.
239 * @param byte_order Trace's byte order.
241 * Returns 0 on success, a negative value on error.
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".
247 extern int bt_ctf_trace_set_byte_order(struct bt_ctf_trace
*trace
,
248 enum bt_ctf_byte_order byte_order
);
251 * bt_ctf_trace_get_packet_header_type: get a trace's packet header type.
253 * Get the trace's packet header type.
255 * @param trace Trace instance.
257 * Returns the trace's packet header type (a structure) on success, NULL on
260 extern struct bt_ctf_field_type
*bt_ctf_trace_get_packet_header_type(
261 struct bt_ctf_trace
*trace
);
264 * bt_ctf_trace_set_packet_header_type: set a trace's packet header type.
266 * Set the trace's packet header type.
268 * @param trace Trace instance.
269 * @param packet_header_type Packet header field type (must be a structure).
271 * Returns 0 on success, a negative value on error.
273 extern int bt_ctf_trace_set_packet_header_type(struct bt_ctf_trace
*trace
,
274 struct bt_ctf_field_type
*packet_header_type
);
277 * bt_ctf_trace_get and bt_ctf_trace_put: increment and decrement the
278 * trace's reference count.
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
285 * When the trace's reference count is decremented to 0 by a
286 * bt_ctf_trace_put, the trace is freed.
288 * @param trace Trace instance.
290 extern void bt_ctf_trace_get(struct bt_ctf_trace
*trace
);
291 extern void bt_ctf_trace_put(struct bt_ctf_trace
*trace
);
297 #endif /* BABELTRACE_CTF_IR_TRACE_H */