1 #ifndef _BABELTRACE_CTF_EVENTS_H
2 #define _BABELTRACE_CTF_EVENTS_H
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.
27 #include <babeltrace/context.h>
28 #include <babeltrace/clock-types.h>
37 struct bt_ctf_event_decl
;
38 struct bt_ctf_field_decl
;
41 * the top-level scopes in CTF
44 BT_TRACE_PACKET_HEADER
= 0,
45 BT_STREAM_PACKET_CONTEXT
= 1,
46 BT_STREAM_EVENT_HEADER
= 2,
47 BT_STREAM_EVENT_CONTEXT
= 3,
53 * the supported CTF types
62 CTF_TYPE_UNTAGGED_VARIANT
,
70 * the supported CTF string encodings
72 enum ctf_string_encoding
{
80 * bt_ctf_get_top_level_scope: return a definition of the top-level scope
82 * Top-level scopes are defined in the bt_ctf_scope enum.
83 * In order to get a field or a field list, the user needs to pass a
84 * scope as argument, this scope can be a top-level scope or a scope
85 * relative to an arbitrary field. This function provides the mapping
86 * between the enum and the actual definition of top-level scopes.
87 * On error return NULL.
89 const struct definition
*bt_ctf_get_top_level_scope(const struct bt_ctf_event
*event
,
90 enum bt_ctf_scope scope
);
93 * bt_ctf_event_get_name: returns the name of the event or NULL on error
95 const char *bt_ctf_event_name(const struct bt_ctf_event
*event
);
98 * bt_ctf_get_cycles: returns the timestamp of the event as written
99 * in the packet (in cycles) or -1ULL on error.
101 uint64_t bt_ctf_get_cycles(const struct bt_ctf_event
*event
);
104 * bt_ctf_get_timestamp: returns the timestamp of the event offsetted
105 * with the system clock source (in ns) or -1ULL on error
107 uint64_t bt_ctf_get_timestamp(const struct bt_ctf_event
*event
);
110 * bt_ctf_get_field_list: obtain the list of fields for compound type
112 * This function can be used to obtain the list of fields
113 * contained within a compound type: array, sequence,
114 * structure, or variant.
116 * This function sets the "list" pointer to an array of definition
117 * pointers and set count to the number of elements in the array.
118 * Return 0 on success and a negative value on error.
120 * The content pointed to by "list" should *not* be freed. It stays
121 * valid as long as the event is unchanged (as long as the iterator
122 * from which the event is extracted is unchanged).
124 int bt_ctf_get_field_list(const struct bt_ctf_event
*event
,
125 const struct definition
*scope
,
126 struct definition
const * const **list
,
127 unsigned int *count
);
130 * bt_ctf_get_field: returns the definition of a specific field
132 const struct definition
*bt_ctf_get_field(const struct bt_ctf_event
*event
,
133 const struct definition
*scope
,
137 * bt_ctf_get_index: if the field is an array or a sequence, return the element
138 * at position index, otherwise return NULL;
140 const struct definition
*bt_ctf_get_index(const struct bt_ctf_event
*event
,
141 const struct definition
*field
,
145 * bt_ctf_field_name: returns the name of a field or NULL on error
147 const char *bt_ctf_field_name(const struct definition
*def
);
150 * bt_ctf_get_decl_from_def: return the declaration of a field from
151 * its definition or NULL on error
153 const struct declaration
*bt_ctf_get_decl_from_def(const struct definition
*def
);
156 * bt_ctf_get_decl_from_field_decl: return the declaration of a field from
157 * a field_decl or NULL on error
159 const struct declaration
*bt_ctf_get_decl_from_field_decl(
160 const struct bt_ctf_field_decl
*field
);
163 * bt_ctf_field_type: returns the type of a field or -1 if unknown
165 enum ctf_type_id
bt_ctf_field_type(const struct declaration
*decl
);
168 * bt_ctf_get_int_signedness: return the signedness of an integer
170 * return 0 if unsigned
174 int bt_ctf_get_int_signedness(const struct declaration
*decl
);
177 * bt_ctf_get_int_base: return the base of an int or a negative value on error
179 int bt_ctf_get_int_base(const struct declaration
*decl
);
182 * bt_ctf_get_int_byte_order: return the byte order of an int or a negative
185 int bt_ctf_get_int_byte_order(const struct declaration
*decl
);
188 * bt_ctf_get_int_len: return the size, in bits, of an int or a negative
191 ssize_t
bt_ctf_get_int_len(const struct declaration
*decl
);
194 * bt_ctf_get_encoding: return the encoding of an int, a string, or of
195 * the integer contained in a char array or a sequence.
196 * return a negative value on error
198 enum ctf_string_encoding
bt_ctf_get_encoding(const struct declaration
*decl
);
201 * bt_ctf_get_array_len: return the len of an array or a negative
204 int bt_ctf_get_array_len(const struct declaration
*decl
);
207 * Field access functions
209 * These functions return the value associated with the field passed in
212 * If the field does not exist or is not of the type requested, the value
213 * returned is undefined. To check if an error occured, use the
214 * bt_ctf_field_get_error() function after accessing a field.
216 * bt_ctf_get_enum_int gets the integer field of an enumeration.
217 * bt_ctf_get_enum_str gets the string matching the current enumeration
218 * value, or NULL if the current value does not match any string.
220 uint64_t bt_ctf_get_uint64(const struct definition
*field
);
221 int64_t bt_ctf_get_int64(const struct definition
*field
);
222 const struct definition
*bt_ctf_get_enum_int(const struct definition
*field
);
223 const char *bt_ctf_get_enum_str(const struct definition
*field
);
224 char *bt_ctf_get_char_array(const struct definition
*field
);
225 char *bt_ctf_get_string(const struct definition
*field
);
228 * bt_ctf_field_get_error: returns the last error code encountered while
229 * accessing a field and reset the error flag.
230 * Return 0 if no error, a negative value otherwise.
232 int bt_ctf_field_get_error(void);
235 * bt_ctf_get_event_decl_list: set list pointer to an array of bt_ctf_event_decl
236 * pointers and set count to the number of elements in the array.
238 * Return 0 on success and a negative value on error.
240 int bt_ctf_get_event_decl_list(int handle_id
, struct bt_context
*ctx
,
241 struct bt_ctf_event_decl
* const **list
,
242 unsigned int *count
);
245 * bt_ctf_get_decl_event_name: return the name of the event or NULL on error
247 const char *bt_ctf_get_decl_event_name(const struct bt_ctf_event_decl
*event
);
250 * bt_ctf_get_decl_fields: set list pointer to an array of bt_ctf_field_decl
251 * pointers and set count to the number of elements in the array.
253 * Returns 0 on success and a negative value on error
255 int bt_ctf_get_decl_fields(struct bt_ctf_event_decl
*event_decl
,
256 enum bt_ctf_scope scope
,
257 struct bt_ctf_field_decl
const * const **list
,
258 unsigned int *count
);
261 * bt_ctf_get_decl_field_name: return the name of a field decl or NULL on error
263 const char *bt_ctf_get_decl_field_name(const struct bt_ctf_field_decl
*field
);
269 #endif /* _BABELTRACE_CTF_EVENTS_H */