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_add_clock: add a clock to the trace.
117 * Add a clock to the trace. Clocks assigned to stream classes must be
118 * added to the trace beforehand.
120 * @param trace Trace instance.
121 * @param clock Clock to add to the trace.
123 * Returns 0 on success, a negative value on error.
125 extern int bt_ctf_trace_add_clock(struct bt_ctf_trace
*trace
,
126 struct bt_ctf_clock
*clock
);
129 * bt_ctf_trace_get_clock_count: get the number of clocks
130 * associated to the trace.
132 * @param trace Trace instance.
134 * Returns the clock count on success, a negative value on error.
136 extern int bt_ctf_trace_get_clock_count(struct bt_ctf_trace
*trace
);
139 * bt_ctf_trace_get_clock: get a trace's clock at index.
141 * @param trace Trace instance.
142 * @param index Index of the clock in the given trace.
144 * Return a clock instance on success, NULL on error.
146 extern struct bt_ctf_clock
*bt_ctf_trace_get_clock(
147 struct bt_ctf_trace
*trace
, int index
);
150 * bt_ctf_trace_get_metadata_string: get metadata string.
152 * Get the trace's TSDL metadata. The caller assumes the ownership of the
155 * @param trace Trace instance.
157 * Returns the metadata string on success, NULL on error.
159 extern char *bt_ctf_trace_get_metadata_string(struct bt_ctf_trace
*trace
);
162 * bt_ctf_trace_set_byte_order: set a field type's byte order.
164 * Set the trace's byte order. Defaults to the current host's endianness.
166 * @param trace Trace instance.
167 * @param byte_order Trace's byte order.
169 * Returns 0 on success, a negative value on error.
171 * Note: byte_order must not be BT_CTF_BYTE_ORDER_NATIVE since, according
172 * to the CTF specification, is defined as "the byte order described in the
173 * trace description".
175 extern int bt_ctf_trace_set_byte_order(struct bt_ctf_trace
*trace
,
176 enum bt_ctf_byte_order byte_order
);
179 * bt_ctf_trace_get_packet_header_type: get a trace's packet header type.
181 * Get the trace's packet header type.
183 * @param trace Trace instance.
185 * Returns the trace's packet header type (a structure) on success, NULL on
188 extern struct bt_ctf_field_type
*bt_ctf_trace_get_packet_header_type(
189 struct bt_ctf_trace
*trace
);
192 * bt_ctf_trace_set_packet_header_type: set a trace's packet header type.
194 * Set the trace's packet header type.
196 * @param trace Trace instance.
197 * @param packet_header_type Packet header field type (must be a structure).
199 * Returns 0 on success, a negative value on error.
201 extern int bt_ctf_trace_set_packet_header_type(struct bt_ctf_trace
*trace
,
202 struct bt_ctf_field_type
*packet_header_type
);
205 * bt_ctf_trace_get and bt_ctf_trace_put: increment and decrement the
206 * trace's reference count.
208 * These functions ensure that the trace won't be destroyed while it
209 * is in use. The same number of get and put (plus one extra put to
210 * release the initial reference done at creation) have to be done to
213 * When the trace's reference count is decremented to 0 by a
214 * bt_ctf_trace_put, the trace is freed.
216 * @param trace Trace instance.
218 extern void bt_ctf_trace_get(struct bt_ctf_trace
*trace
);
219 extern void bt_ctf_trace_put(struct bt_ctf_trace
*trace
);
225 #endif /* BABELTRACE_CTF_IR_TRACE_H */