1 #ifndef _BABELTRACE_CTF_EVENTS_INTERNAL_H
2 #define _BABELTRACE_CTF_EVENTS_INTERNAL_H
7 * CTF events API (internal)
9 * Copyright 2011-2012 EfficiOS Inc. and Linux Foundation
11 * Author: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
12 * Julien Desfossez <julien.desfossez@efficios.com>
14 * Permission is hereby granted, free of charge, to any person obtaining
15 * a copy of this software and associated documentation files (the
16 * "Software"), to deal in the Software without restriction, including
17 * without limitation the rights to use, copy, modify, merge, publish,
18 * distribute, sublicense, and/or sell copies of the Software, and to
19 * permit persons to whom the Software is furnished to do so, subject to
20 * the following conditions:
22 * The above copyright notice and this permission notice shall be
23 * included in all copies or substantial portions of the Software.
25 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
26 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
27 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
28 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
29 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
30 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
34 #include <babeltrace/iterator-internal.h>
35 #include <babeltrace/ctf/callbacks.h>
36 #include <babeltrace/ctf/callbacks-internal.h>
37 #include <babeltrace/ctf-ir/metadata.h>
38 #include <babeltrace/ctf-ir/field-types.h>
41 struct ctf_stream_definition
;
44 * These structures are public mappings to internal ctf_event structures.
47 struct ctf_event_definition
*parent
;
50 struct bt_ctf_event_decl
{
51 struct ctf_event_declaration parent
;
52 GPtrArray
*context_decl
;
53 GPtrArray
*fields_decl
;
54 GPtrArray
*packet_header_decl
;
55 GPtrArray
*event_context_decl
;
56 GPtrArray
*event_header_decl
;
57 GPtrArray
*packet_context_decl
;
61 struct bt_iter parent
;
62 struct bt_ctf_event current_ctf_event
; /* last read event */
63 GArray
*callbacks
; /* Array of struct bt_stream_callbacks */
64 struct bt_callback_chain main_callbacks
; /* For all events */
66 * Flag indicating if dependency graph needs to be recalculated.
67 * Set by bt_iter_add_callback(), and checked (and
68 * cleared) by upon entry into bt_iter_read_event().
69 * bt_iter_read_event() is responsible for calling dep
70 * graph calculation if it sees this flag set.
72 int recalculate_dep_graph
;
74 * Array of pointers to struct bt_dependencies, for garbage
75 * collection. We're not using a linked list here because each
76 * struct bt_dependencies can belong to more than one
83 void ctf_update_current_packet_index(struct ctf_stream_definition
*stream
,
84 struct packet_index
*prev_index
,
85 struct packet_index
*cur_index
);
88 struct bt_declaration
;
90 struct bt_ctf_event_decl
;
91 struct bt_ctf_field_decl
;
94 * the top-level scopes in CTF
97 BT_TRACE_PACKET_HEADER
= 0,
98 BT_STREAM_PACKET_CONTEXT
= 1,
99 BT_STREAM_EVENT_HEADER
= 2,
100 BT_STREAM_EVENT_CONTEXT
= 3,
101 BT_EVENT_CONTEXT
= 4,
106 * bt_ctf_get_top_level_scope: return a definition of the top-level scope
108 * Top-level scopes are defined in the ctf_scope enum.
109 * In order to get a field or a field list, the user needs to pass a
110 * scope as argument, this scope can be a top-level scope or a scope
111 * relative to an arbitrary field. This function provides the mapping
112 * between the enum and the actual definition of top-level scopes.
113 * On error return NULL.
115 const struct bt_definition
*bt_ctf_get_top_level_scope(const struct bt_ctf_event
*event
,
116 enum ctf_scope scope
);
119 * bt_ctf_event_get_name: returns the name of the event or NULL on error
121 const char *bt_ctf_event_name(const struct bt_ctf_event
*event
);
124 * bt_ctf_get_cycles: returns the timestamp of the event as written
125 * in the packet (in cycles) or -1ULL on error.
127 uint64_t bt_ctf_get_cycles(const struct bt_ctf_event
*event
);
130 * bt_ctf_get_timestamp: get the timestamp of the event offsetted
131 * with the system clock source (in ns) in *timestamp.
133 * Return 0 on success, or -1ULL on error.
135 int bt_ctf_get_timestamp(const struct bt_ctf_event
*event
, int64_t *timestamp
);
138 * bt_ctf_get_field_list: obtain the list of fields for compound type
140 * This function can be used to obtain the list of fields contained
141 * within a top-level scope of an event or a compound type: array,
142 * sequence, structure, or variant.
144 * This function sets the "list" pointer to an array of definition
145 * pointers and set count to the number of elements in the array.
146 * Return 0 on success and a negative value on error.
148 * The content pointed to by "list" should *not* be freed. It stays
149 * valid as long as the event is unchanged (as long as the iterator
150 * from which the event is extracted is unchanged).
152 int bt_ctf_get_field_list(const struct bt_ctf_event
*event
,
153 const struct bt_definition
*scope
,
154 struct bt_definition
const * const **list
,
155 unsigned int *count
);
158 * bt_ctf_get_field: returns the definition of a specific field
160 const struct bt_definition
*bt_ctf_get_field(const struct bt_ctf_event
*event
,
161 const struct bt_definition
*scope
,
165 * bt_ctf_get_index: if the field is an array or a sequence, return the element
166 * at position index, otherwise return NULL;
168 const struct bt_definition
*bt_ctf_get_index(const struct bt_ctf_event
*event
,
169 const struct bt_definition
*field
,
173 * bt_ctf_field_name: returns the name of a field or NULL on error
175 const char *bt_ctf_field_name(const struct bt_definition
*def
);
178 * bt_ctf_get_decl_from_def: return the declaration of a field from
179 * its definition or NULL on error
181 const struct bt_declaration
*bt_ctf_get_decl_from_def(const struct bt_definition
*def
);
184 * bt_ctf_get_decl_from_field_decl: return the declaration of a field from
185 * a field_decl or NULL on error
187 const struct bt_declaration
*bt_ctf_get_decl_from_field_decl(
188 const struct bt_ctf_field_decl
*field
);
191 * bt_ctf_field_type: returns the type of a field or -1 if unknown
193 enum ctf_type_id
bt_ctf_field_type(const struct bt_declaration
*decl
);
196 * bt_ctf_get_int_signedness: return the signedness of an integer
198 * return 0 if unsigned
202 int bt_ctf_get_int_signedness(const struct bt_declaration
*decl
);
205 * bt_ctf_get_int_base: return the base of an int or a negative value on error
207 int bt_ctf_get_int_base(const struct bt_declaration
*decl
);
210 * bt_ctf_get_int_byte_order: return the byte order of an int or a negative
213 int bt_ctf_get_int_byte_order(const struct bt_declaration
*decl
);
216 * bt_ctf_get_int_len: return the size, in bits, of an int or a negative
219 ssize_t
bt_ctf_get_int_len(const struct bt_declaration
*decl
);
222 * bt_ctf_get_encoding: return the encoding of an int, a string, or of
223 * the integer contained in a char array or a sequence.
224 * return a negative value on error
226 enum ctf_string_encoding
bt_ctf_get_encoding(const struct bt_declaration
*decl
);
229 * bt_ctf_get_array_len: return the len of an array or a negative
232 int bt_ctf_get_array_len(const struct bt_declaration
*decl
);
235 * bt_ctf_get_struct_field_count: return the number of fields in a structure.
236 * Returns a negative value on error.
238 uint64_t bt_ctf_get_struct_field_count(const struct bt_definition
*field
);
241 * Field access functions
243 * These functions return the value associated with the field passed in
246 * If the field does not exist or is not of the type requested, the value
247 * returned is undefined. To check if an error occured, use the
248 * bt_ctf_field_get_error() function after accessing a field.
250 * bt_ctf_get_enum_int gets the integer field of an enumeration.
251 * bt_ctf_get_enum_str gets the string matching the current enumeration
252 * value, or NULL if the current value does not match any string.
254 uint64_t bt_ctf_get_uint64(const struct bt_definition
*field
);
255 int64_t bt_ctf_get_int64(const struct bt_definition
*field
);
256 const struct bt_definition
*bt_ctf_get_enum_int(const struct bt_definition
*field
);
257 const char *bt_ctf_get_enum_str(const struct bt_definition
*field
);
258 char *bt_ctf_get_char_array(const struct bt_definition
*field
);
259 char *bt_ctf_get_string(const struct bt_definition
*field
);
260 double bt_ctf_get_float(const struct bt_definition
*field
);
261 const struct bt_definition
*bt_ctf_get_variant(const struct bt_definition
*field
);
262 const struct bt_definition
*bt_ctf_get_struct_field_index(
263 const struct bt_definition
*field
, uint64_t i
);
266 * bt_ctf_field_get_error: returns the last error code encountered while
267 * accessing a field and reset the error flag.
268 * Return 0 if no error, a negative value otherwise.
270 int bt_ctf_field_get_error(void);
273 * bt_ctf_get_event_decl_list: get a list of all the event declarations in
276 * The list array is pointed to the array of event declarations.
277 * The number of events in the array is written in count.
279 * Return 0 on success and a negative value on error.
281 * The content pointed to by "list" should *not* be freed. It stays
282 * valid as long as the trace is opened.
284 int bt_ctf_get_event_decl_list(int handle_id
, struct bt_context
*ctx
,
285 struct bt_ctf_event_decl
* const **list
,
286 unsigned int *count
);
289 * bt_ctf_get_decl_event_name: return the name of the event or NULL on error
291 const char *bt_ctf_get_decl_event_name(const struct bt_ctf_event_decl
*event
);
294 * bt_ctf_get_decl_event_id: return the event-ID of the event or -1ULL on error
296 uint64_t bt_ctf_get_decl_event_id(const struct bt_ctf_event_decl
*event
);
299 * bt_ctf_get_decl_fields: get all field declarations in a scope of an event
301 * The list array is pointed to the array of field declaration.
302 * The number of field declaration in the array is written in count.
304 * Returns 0 on success and a negative value on error
306 * The content pointed to by "list" should *not* be freed. It stays
307 * valid as long as the trace is opened.
309 int bt_ctf_get_decl_fields(struct bt_ctf_event_decl
*event_decl
,
310 enum ctf_scope scope
,
311 struct bt_ctf_field_decl
const * const **list
,
312 unsigned int *count
);
315 * bt_ctf_get_decl_field_name: return the name of a field decl or NULL on error
317 const char *bt_ctf_get_decl_field_name(const struct bt_ctf_field_decl
*field
);
319 #endif /*_BABELTRACE_CTF_EVENTS_INTERNAL_H */