ctf.fs: bt_ctf_notif_iter_create(): assert() that all medops exist
[babeltrace.git] / include / babeltrace / ctf-ir / metadata.h
1 #ifndef _BABELTRACE_CTF_IR_METADATA_H
2 #define _BABELTRACE_CTF_IR_METADATA_H
3
4 /*
5 * BabelTrace
6 *
7 * CTF Intermediate Representation Metadata Header
8 *
9 * Copyright 2011 - Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
10 *
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:
17 *
18 * The above copyright notice and this permission notice shall be included in
19 * all copies or substantial portions of the Software.
20 *
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
27 * SOFTWARE.
28 */
29
30 #include <babeltrace/types.h>
31 #include <babeltrace/format.h>
32 #include <babeltrace/format-internal.h>
33 #include <babeltrace/ctf/types.h>
34 #include <sys/types.h>
35 #include <dirent.h>
36 #include <babeltrace/compat/uuid.h>
37 #include <assert.h>
38 #include <glib.h>
39
40 struct ctf_trace;
41 struct ctf_stream_declaration;
42 struct ctf_event_declaration;
43 struct ctf_clock;
44 struct ctf_callsite;
45 struct ctf_scanner;
46
47 struct ctf_stream_packet_limits {
48 uint64_t begin;
49 uint64_t end;
50 };
51
52 struct ctf_stream_packet_timestamp {
53 struct ctf_stream_packet_limits cycles;
54 struct ctf_stream_packet_limits real;
55 };
56
57 struct ctf_stream_definition {
58 struct ctf_stream_declaration *stream_class;
59 uint64_t real_timestamp; /* Current timestamp, in ns */
60 uint64_t cycles_timestamp; /* Current timestamp, in cycles */
61 uint64_t event_id; /* Current event ID */
62 int has_timestamp;
63 uint64_t stream_id;
64
65 struct definition_struct *trace_packet_header;
66 struct definition_struct *stream_packet_context;
67 struct definition_struct *stream_event_header;
68 struct definition_struct *stream_event_context;
69 GPtrArray *events_by_id; /* Array of struct ctf_event_definition pointers indexed by id */
70 struct definition_scope *parent_def_scope; /* for initialization */
71 int stream_definitions_created;
72
73 struct ctf_clock *current_clock;
74
75 /* Event discarded information */
76 uint64_t events_discarded;
77 /* Trace packets lost */
78 uint64_t packets_lost;
79 struct ctf_stream_packet_timestamp prev;
80 struct ctf_stream_packet_timestamp current;
81 char path[PATH_MAX]; /* Path to stream. '\0' for mmap traces */
82 };
83
84 struct ctf_event_definition {
85 struct ctf_stream_definition *stream;
86 struct definition_struct *event_context;
87 struct definition_struct *event_fields;
88 };
89
90 #define CTF_CLOCK_SET_FIELD(ctf_clock, field) \
91 do { \
92 (ctf_clock)->field_mask |= CTF_CLOCK_ ## field; \
93 } while (0)
94
95 #define CTF_CLOCK_FIELD_IS_SET(ctf_clock, field) \
96 ((ctf_clock)->field_mask & CTF_CLOCK_ ## field)
97
98 #define CTF_CLOCK_GET_FIELD(ctf_clock, field) \
99 ({ \
100 assert(CTF_CLOCK_FIELD_IS_SET(ctf_clock, field)); \
101 (ctf_clock)->(field); \
102 })
103
104 struct ctf_clock {
105 GQuark name;
106 GQuark uuid;
107 char *description;
108 uint64_t freq; /* frequency, in HZ */
109 /* precision in seconds is: precision * (1/freq) */
110 uint64_t precision;
111 /*
112 * The offset from Epoch is: offset_s + (offset * (1/freq))
113 * Coarse clock offset from Epoch (in seconds).
114 * It can be negative.
115 */
116 int64_t offset_s;
117 /*
118 * Fine clock offset from Epoch, in (1/freq) units.
119 * It can be negative.
120 */
121 int64_t offset;
122 int absolute;
123
124 enum { /* Fields populated mask */
125 CTF_CLOCK_name = (1U << 0),
126 CTF_CLOCK_freq = (1U << 1),
127 } field_mask;
128 };
129
130 #define CTF_CALLSITE_SET_FIELD(ctf_callsite, field) \
131 do { \
132 (ctf_callsite)->field_mask |= CTF_CALLSITE_ ## field; \
133 } while (0)
134
135 #define CTF_CALLSITE_FIELD_IS_SET(ctf_callsite, field) \
136 ((ctf_callsite)->field_mask & CTF_CALLSITE_ ## field)
137
138 #define CTF_CALLSITE_GET_FIELD(ctf_callsite, field) \
139 ({ \
140 assert(CTF_CALLSITE_FIELD_IS_SET(ctf_callsite, field)); \
141 (ctf_callsite)->(field); \
142 })
143
144 struct ctf_callsite {
145 GQuark name; /* event name associated with callsite */
146 char *func;
147 char *file;
148 uint64_t line;
149 uint64_t ip;
150 struct bt_list_head node;
151 enum { /* Fields populated mask */
152 CTF_CALLSITE_name = (1U << 0),
153 CTF_CALLSITE_func = (1U << 1),
154 CTF_CALLSITE_file = (1U << 2),
155 CTF_CALLSITE_line = (1U << 3),
156 CTF_CALLSITE_ip = (1U << 4),
157 } field_mask;
158 };
159
160 struct ctf_callsite_dups {
161 struct bt_list_head head;
162 };
163
164 #define CTF_TRACE_SET_FIELD(ctf_trace, field) \
165 do { \
166 (ctf_trace)->field_mask |= CTF_TRACE_ ## field; \
167 } while (0)
168
169 #define CTF_TRACE_FIELD_IS_SET(ctf_trace, field) \
170 ((ctf_trace)->field_mask & CTF_TRACE_ ## field)
171
172 #define CTF_TRACE_GET_FIELD(ctf_trace, field) \
173 ({ \
174 assert(CTF_TRACE_FIELD_IS_SET(ctf_trace, field)); \
175 (ctf_trace)->(field); \
176 })
177
178 #define TRACER_ENV_LEN 128
179
180 /* tracer-specific environment */
181 struct ctf_tracer_env {
182 int vpid; /* negative if unset */
183
184 /* All strings below: "" if unset. */
185 char procname[TRACER_ENV_LEN];
186 char hostname[TRACER_ENV_LEN];
187 char domain[TRACER_ENV_LEN];
188 char sysname[TRACER_ENV_LEN];
189 char release[TRACER_ENV_LEN];
190 char version[TRACER_ENV_LEN];
191 char tracer_name[TRACER_ENV_LEN];
192 };
193
194 #ifdef ENABLE_DEBUG_INFO
195 struct debug_info;
196 #endif
197
198 struct ctf_trace {
199 struct bt_trace_descriptor parent;
200
201 /* root scope */
202 struct declaration_scope *root_declaration_scope;
203
204 struct declaration_scope *declaration_scope;
205 /* innermost definition scope. to be used as parent of stream. */
206 struct definition_scope *definition_scope;
207 GPtrArray *streams; /* Array of struct ctf_stream_declaration pointers */
208 struct ctf_stream_definition *metadata;
209 char *metadata_string;
210 int metadata_packetized;
211 GHashTable *callsites;
212 GPtrArray *event_declarations; /* Array of all the struct bt_ctf_event_decl */
213
214 struct declaration_struct *packet_header_decl;
215 struct ctf_scanner *scanner;
216 int restart_root_decl;
217
218 uint64_t major;
219 uint64_t minor;
220 unsigned char uuid[BABELTRACE_UUID_LEN];
221 int byte_order; /* trace BYTE_ORDER. 0 if unset. */
222 struct ctf_tracer_env env;
223
224 enum { /* Fields populated mask */
225 CTF_TRACE_major = (1U << 0),
226 CTF_TRACE_minor = (1U << 1),
227 CTF_TRACE_uuid = (1U << 2),
228 CTF_TRACE_byte_order = (1U << 3),
229 CTF_TRACE_packet_header = (1U << 4),
230 } field_mask;
231
232 /* Information about trace backing directory and files */
233 DIR *dir;
234 int dirfd;
235 int flags; /* open flags */
236
237 #ifdef ENABLE_DEBUG_INFO
238 /* Debug information for this trace */
239 struct debug_info *debug_info;
240 #endif
241 };
242
243 #define CTF_STREAM_SET_FIELD(ctf_stream, field) \
244 do { \
245 (ctf_stream)->field_mask |= CTF_STREAM_ ## field; \
246 } while (0)
247
248 #define CTF_STREAM_FIELD_IS_SET(ctf_stream, field) \
249 ((ctf_stream)->field_mask & CTF_STREAM_ ## field)
250
251 #define CTF_STREAM_GET_FIELD(ctf_stream, field) \
252 ({ \
253 assert(CTF_STREAM_FIELD_IS_SET(ctf_stream, field)); \
254 (ctf_stream)->(field); \
255 })
256
257 struct ctf_stream_declaration {
258 struct ctf_trace *trace;
259 /* parent is lexical scope containing the stream scope */
260 struct declaration_scope *declaration_scope;
261 /* innermost definition scope. to be used as parent of event. */
262 struct definition_scope *definition_scope;
263 GPtrArray *events_by_id; /* Array of struct ctf_event_declaration pointers indexed by id */
264 GHashTable *event_quark_to_id; /* GQuark to numeric id */
265
266 struct declaration_struct *packet_context_decl;
267 struct declaration_struct *event_header_decl;
268 struct declaration_struct *event_context_decl;
269
270 uint64_t stream_id;
271
272 enum { /* Fields populated mask */
273 CTF_STREAM_stream_id = (1 << 0),
274 } field_mask;
275
276 GPtrArray *streams; /* Array of struct ctf_stream_definition pointers */
277 };
278
279 #define CTF_EVENT_SET_FIELD(ctf_event, field) \
280 do { \
281 (ctf_event)->field_mask |= CTF_EVENT_ ## field; \
282 } while (0)
283
284 #define CTF_EVENT_FIELD_IS_SET(ctf_event, field) \
285 ((ctf_event)->field_mask & CTF_EVENT_ ## field)
286
287 #define CTF_EVENT_GET_FIELD(ctf_event, field) \
288 ({ \
289 assert(CTF_EVENT_FIELD_IS_SET(ctf_event, field)); \
290 (ctf_event)->(field); \
291 })
292
293 struct ctf_event_declaration {
294 /* stream mapped by stream_id */
295 struct ctf_stream_declaration *stream;
296 /* parent is lexical scope containing the event scope */
297 struct declaration_scope *declaration_scope;
298
299 struct declaration_struct *context_decl;
300 struct declaration_struct *fields_decl;
301
302 GQuark name;
303 uint64_t id; /* Numeric identifier within the stream */
304 uint64_t stream_id;
305 int loglevel;
306 GQuark model_emf_uri;
307
308 enum { /* Fields populated mask */
309 CTF_EVENT_name = (1 << 0),
310 CTF_EVENT_id = (1 << 1),
311 CTF_EVENT_stream_id = (1 << 2),
312 CTF_EVENT_loglevel = (1 << 4),
313 CTF_EVENT_model_emf_uri = (1 << 5),
314 } field_mask;
315 };
316
317 #endif /* _BABELTRACE_CTF_IR_METADATA_H */
This page took 0.037354 seconds and 4 git commands to generate.