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/iterator.h>
30 struct ctf_stream_event
;
35 * the top-level scopes in CTF
38 BT_TRACE_PACKET_HEADER
= 0,
39 BT_STREAM_PACKET_CONTEXT
= 1,
40 BT_STREAM_EVENT_HEADER
= 2,
41 BT_STREAM_EVENT_CONTEXT
= 3,
47 * the supported CTF types
56 CTF_TYPE_UNTAGGED_VARIANT
,
64 * the supported CTF string encodings
66 enum ctf_string_encoding
{
74 * the structure to manipulate events
77 struct ctf_stream
*stream
;
78 struct ctf_stream_event
*event
;
82 * bt_ctf_iter_read_event: Read the iterator's current event data.
84 * @iter: trace collection iterator (input)
85 * @stream: stream containing event at current position (output)
86 * @event: current event (output)
87 * Return 0 on success, negative error value on error.
89 struct bt_ctf_event
*bt_ctf_iter_read_event(struct bt_ctf_iter
*iter
);
92 * bt_ctf_iter_create - Allocate a CTF trace collection iterator.
94 * begin_pos and end_pos are optional parameters to specify the position
95 * at which the trace collection should be seeked upon iterator
96 * creation, and the position at which iteration will start returning
99 * By default, if begin_pos is NULL, a BT_SEEK_CUR is performed at
100 * creation. By default, if end_pos is NULL, a BT_SEEK_END (end of
101 * trace) is the EOF criterion.
103 struct bt_ctf_iter
*bt_ctf_iter_create(struct bt_context
*ctx
,
104 struct bt_iter_pos
*begin_pos
,
105 struct bt_iter_pos
*end_pos
);
108 * bt_ctf_get_iter - get iterator from ctf iterator.
110 struct bt_iter
*bt_ctf_get_iter(struct bt_ctf_iter
*iter
);
113 * bt_ctf_iter_destroy - Free a CTF trace collection iterator.
115 void bt_ctf_iter_destroy(struct bt_ctf_iter
*iter
);
118 * bt_ctf_get_top_level_scope: return a definition of the top-level scope
120 * Top-level scopes are defined in the bt_ctf_scope enum.
121 * In order to get a field or a field list, the user needs to pass a
122 * scope as argument, this scope can be a top-level scope or a scope
123 * relative to an arbitrary field. This function provides the mapping
124 * between the enum and the actual definition of top-level scopes.
125 * On error return NULL.
127 struct definition
*bt_ctf_get_top_level_scope(struct bt_ctf_event
*event
,
128 enum bt_ctf_scope scope
);
131 * bt_ctf_event_get_name: returns the name of the event or NULL on error
133 const char *bt_ctf_event_name(struct bt_ctf_event
*event
);
136 * bt_ctf_get_timestamp_raw: returns the timestamp of the event as written in
137 * the packet or -1ULL on error
139 uint64_t bt_ctf_get_timestamp_raw(struct bt_ctf_event
*event
);
142 * bt_ctf_get_timestamp: returns the timestamp of the event offsetted with the
143 * system clock source or -1ULL on error
145 uint64_t bt_ctf_get_timestamp(struct bt_ctf_event
*event
);
148 * bt_ctf_get_field_list: set list pointer to an array of definition
149 * pointers and set count to the number of elements in the array.
150 * Return 0 on success and a negative value on error.
152 int bt_ctf_get_field_list(struct bt_ctf_event
*event
,
153 struct definition
*scope
,
154 struct definition
const * const **list
,
155 unsigned int *count
);
158 * bt_ctf_get_field: returns the definition of a specific field
160 struct definition
*bt_ctf_get_field(struct bt_ctf_event
*event
,
161 struct 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 struct definition
*bt_ctf_get_index(struct bt_ctf_event
*event
,
169 struct 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 definition
*def
);
178 * bt_ctf_field_type: returns the type of a field or -1 if unknown
180 enum ctf_type_id
bt_ctf_field_type(const struct definition
*def
);
183 * bt_ctf_get_int_signedness: return the signedness of an integer
185 * return 0 if unsigned
189 int bt_ctf_get_int_signedness(const struct definition
*field
);
192 * bt_ctf_get_int_base: return the base of an int or a negative value on error
194 int bt_ctf_get_int_base(const struct definition
*field
);
197 * bt_ctf_get_int_byte_order: return the byte order of an int or a negative
200 int bt_ctf_get_int_byte_order(const struct definition
*field
);
203 * bt_ctf_get_encoding: return the encoding of an int or a string.
204 * return a negative value on error
206 enum ctf_string_encoding
bt_ctf_get_encoding(const struct definition
*field
);
209 * bt_ctf_get_array_len: return the len of an array or a negative
212 int bt_ctf_get_array_len(const struct definition
*field
);
215 * Field access functions
217 * These functions return the value associated with the field passed in
220 * If the field does not exist or is not of the type requested, the value
221 * returned is undefined. To check if an error occured, use the
222 * bt_ctf_field_error() function after accessing a field.
224 uint64_t bt_ctf_get_uint64(const struct definition
*field
);
225 int64_t bt_ctf_get_int64(const struct definition
*field
);
226 char *bt_ctf_get_char_array(const struct definition
*field
);
227 char *bt_ctf_get_string(const struct definition
*field
);
230 * bt_ctf_field_error: returns the last error code encountered while
231 * accessing a field and reset the error flag.
232 * Return 0 if no error, a negative value otherwise.
234 int bt_ctf_field_get_error(void);
236 #endif /* _BABELTRACE_CTF_EVENTS_H */