Commit | Line | Data |
---|---|---|
145b8090 MD |
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 | ||
22 | #include <babeltrace/types.h> | |
23 | #include <babeltrace/format.h> | |
24 | #include <babeltrace/ctf/types.h> | |
25 | #include <sys/types.h> | |
26 | #include <dirent.h> | |
1b1d76c0 | 27 | #include <babeltrace/uuid.h> |
145b8090 MD |
28 | #include <assert.h> |
29 | #include <glib.h> | |
30 | ||
31 | struct ctf_trace; | |
f380e105 | 32 | struct ctf_stream_declaration; |
4716614a | 33 | struct ctf_event_declaration; |
25ccc85b | 34 | struct ctf_clock; |
f133896d | 35 | struct ctf_callsite; |
145b8090 | 36 | |
9e88d150 | 37 | struct ctf_stream_definition { |
f380e105 | 38 | struct ctf_stream_declaration *stream_class; |
03798a93 JD |
39 | uint64_t real_timestamp; /* Current timestamp, in ns */ |
40 | uint64_t cycles_timestamp; /* Current timestamp, in cycles */ | |
c87a8eb2 | 41 | uint64_t event_id; /* Current event ID */ |
5e2eb0ae | 42 | int has_timestamp; |
661c4ce8 | 43 | uint64_t stream_id; |
145b8090 MD |
44 | |
45 | struct definition_struct *trace_packet_header; | |
46 | struct definition_struct *stream_packet_context; | |
47 | struct definition_struct *stream_event_header; | |
48 | struct definition_struct *stream_event_context; | |
c716f83b | 49 | GPtrArray *events_by_id; /* Array of struct ctf_event_definition pointers indexed by id */ |
145b8090 MD |
50 | struct definition_scope *parent_def_scope; /* for initialization */ |
51 | int stream_definitions_created; | |
fca04958 | 52 | |
25ccc85b MD |
53 | struct ctf_clock *current_clock; |
54 | ||
fca04958 | 55 | /* Event discarded information */ |
4c4ba021 | 56 | uint64_t events_discarded; |
03798a93 JD |
57 | uint64_t prev_real_timestamp; /* Start-of-last-packet timestamp in ns */ |
58 | uint64_t prev_real_timestamp_end; /* End-of-last-packet timestamp in ns */ | |
59 | uint64_t prev_cycles_timestamp; /* Start-of-last-packet timestamp in cycles */ | |
60 | uint64_t prev_cycles_timestamp_end; /* End-of-last-packet timestamp in cycles */ | |
145b8090 MD |
61 | }; |
62 | ||
c716f83b | 63 | struct ctf_event_definition { |
d3ded99d | 64 | struct ctf_stream_definition *stream; |
145b8090 MD |
65 | struct definition_struct *event_context; |
66 | struct definition_struct *event_fields; | |
67 | }; | |
68 | ||
50cb9c56 MD |
69 | #define CTF_CLOCK_SET_FIELD(ctf_clock, field) \ |
70 | do { \ | |
71 | (ctf_clock)->field_mask |= CTF_CLOCK_ ## field; \ | |
72 | } while (0) | |
73 | ||
74 | #define CTF_CLOCK_FIELD_IS_SET(ctf_clock, field) \ | |
75 | ((ctf_clock)->field_mask & CTF_CLOCK_ ## field) | |
76 | ||
77 | #define CTF_CLOCK_GET_FIELD(ctf_clock, field) \ | |
78 | ({ \ | |
79 | assert(CTF_CLOCK_FIELD_IS_SET(ctf_clock, field)); \ | |
80 | (ctf_clock)->(field); \ | |
81 | }) | |
82 | ||
83 | struct ctf_clock { | |
84 | GQuark name; | |
85 | GQuark uuid; | |
86 | char *description; | |
87 | uint64_t freq; /* frequency, in HZ */ | |
88 | /* precision in seconds is: precision * (1/freq) */ | |
89 | uint64_t precision; | |
90 | /* | |
91 | * The offset from Epoch is: offset_s + (offset * (1/freq)) | |
92 | * Coarse clock offset from Epoch (in seconds). | |
93 | */ | |
94 | uint64_t offset_s; | |
95 | /* Fine clock offset from Epoch, in (1/freq) units. */ | |
96 | uint64_t offset; | |
11ac6674 | 97 | int absolute; |
50cb9c56 MD |
98 | |
99 | enum { /* Fields populated mask */ | |
100 | CTF_CLOCK_name = (1U << 0), | |
bf94ab2b | 101 | CTF_CLOCK_freq = (1U << 1), |
50cb9c56 MD |
102 | } field_mask; |
103 | }; | |
104 | ||
f133896d MD |
105 | #define CTF_CALLSITE_SET_FIELD(ctf_callsite, field) \ |
106 | do { \ | |
107 | (ctf_callsite)->field_mask |= CTF_CALLSITE_ ## field; \ | |
108 | } while (0) | |
109 | ||
110 | #define CTF_CALLSITE_FIELD_IS_SET(ctf_callsite, field) \ | |
111 | ((ctf_callsite)->field_mask & CTF_CALLSITE_ ## field) | |
112 | ||
113 | #define CTF_CALLSITE_GET_FIELD(ctf_callsite, field) \ | |
114 | ({ \ | |
115 | assert(CTF_CALLSITE_FIELD_IS_SET(ctf_callsite, field)); \ | |
116 | (ctf_callsite)->(field); \ | |
117 | }) | |
118 | ||
119 | struct ctf_callsite { | |
120 | GQuark name; /* event name associated with callsite */ | |
121 | char *func; | |
122 | char *file; | |
123 | uint64_t line; | |
b448902b | 124 | uint64_t ip; |
c5ff71a3 | 125 | struct bt_list_head node; |
f133896d MD |
126 | enum { /* Fields populated mask */ |
127 | CTF_CALLSITE_name = (1U << 0), | |
128 | CTF_CALLSITE_func = (1U << 1), | |
129 | CTF_CALLSITE_file = (1U << 2), | |
130 | CTF_CALLSITE_line = (1U << 3), | |
b448902b | 131 | CTF_CALLSITE_ip = (1U << 4), |
f133896d MD |
132 | } field_mask; |
133 | }; | |
134 | ||
c5ff71a3 MD |
135 | struct ctf_callsite_dups { |
136 | struct bt_list_head head; | |
137 | }; | |
138 | ||
145b8090 MD |
139 | #define CTF_TRACE_SET_FIELD(ctf_trace, field) \ |
140 | do { \ | |
141 | (ctf_trace)->field_mask |= CTF_TRACE_ ## field; \ | |
142 | } while (0) | |
143 | ||
144 | #define CTF_TRACE_FIELD_IS_SET(ctf_trace, field) \ | |
145 | ((ctf_trace)->field_mask & CTF_TRACE_ ## field) | |
146 | ||
147 | #define CTF_TRACE_GET_FIELD(ctf_trace, field) \ | |
148 | ({ \ | |
149 | assert(CTF_TRACE_FIELD_IS_SET(ctf_trace, field)); \ | |
150 | (ctf_trace)->(field); \ | |
151 | }) | |
152 | ||
cadd09e9 MD |
153 | #define TRACER_ENV_LEN 128 |
154 | ||
155 | /* tracer-specific environment */ | |
156 | struct ctf_tracer_env { | |
157 | int vpid; /* negative if unset */ | |
158 | ||
159 | /* All strings below: "" if unset. */ | |
160 | char procname[TRACER_ENV_LEN]; | |
32cfb8ad | 161 | char hostname[TRACER_ENV_LEN]; |
cadd09e9 MD |
162 | char domain[TRACER_ENV_LEN]; |
163 | char sysname[TRACER_ENV_LEN]; | |
164 | char release[TRACER_ENV_LEN]; | |
165 | char version[TRACER_ENV_LEN]; | |
166 | }; | |
167 | ||
145b8090 MD |
168 | struct ctf_trace { |
169 | struct trace_descriptor parent; | |
170 | /* root scope */ | |
171 | struct declaration_scope *root_declaration_scope; | |
172 | ||
173 | struct declaration_scope *declaration_scope; | |
174 | /* innermost definition scope. to be used as parent of stream. */ | |
175 | struct definition_scope *definition_scope; | |
f380e105 | 176 | GPtrArray *streams; /* Array of struct ctf_stream_declaration pointers */ |
9e88d150 | 177 | struct ctf_stream_definition *metadata; |
50cb9c56 | 178 | GHashTable *clocks; |
f133896d | 179 | GHashTable *callsites; |
25ccc85b | 180 | struct ctf_clock *single_clock; /* currently supports only one clock */ |
fa709ab2 | 181 | struct trace_collection *collection; /* Container of this trace */ |
e003ab50 | 182 | GPtrArray *event_declarations; /* Array of all the struct bt_ctf_event_decl */ |
145b8090 | 183 | |
145b8090 MD |
184 | struct declaration_struct *packet_header_decl; |
185 | ||
186 | uint64_t major; | |
187 | uint64_t minor; | |
ce9cc1bc | 188 | unsigned char uuid[BABELTRACE_UUID_LEN]; |
145b8090 | 189 | int byte_order; /* trace BYTE_ORDER. 0 if unset. */ |
cadd09e9 | 190 | struct ctf_tracer_env env; |
145b8090 MD |
191 | |
192 | enum { /* Fields populated mask */ | |
193 | CTF_TRACE_major = (1U << 0), | |
194 | CTF_TRACE_minor = (1U << 1), | |
195 | CTF_TRACE_uuid = (1U << 2), | |
196 | CTF_TRACE_byte_order = (1U << 3), | |
197 | CTF_TRACE_packet_header = (1U << 4), | |
198 | } field_mask; | |
199 | ||
200 | /* Information about trace backing directory and files */ | |
201 | DIR *dir; | |
202 | int dirfd; | |
203 | int flags; /* open flags */ | |
204 | ||
205 | /* Heap of streams, ordered to always get the lowest timestam */ | |
206 | struct ptr_heap *stream_heap; | |
82662ad4 | 207 | char path[PATH_MAX]; |
98a04903 JD |
208 | |
209 | struct bt_context *ctx; | |
210 | struct bt_trace_handle *handle; | |
145b8090 MD |
211 | }; |
212 | ||
213 | #define CTF_STREAM_SET_FIELD(ctf_stream, field) \ | |
214 | do { \ | |
215 | (ctf_stream)->field_mask |= CTF_STREAM_ ## field; \ | |
216 | } while (0) | |
217 | ||
218 | #define CTF_STREAM_FIELD_IS_SET(ctf_stream, field) \ | |
219 | ((ctf_stream)->field_mask & CTF_STREAM_ ## field) | |
220 | ||
221 | #define CTF_STREAM_GET_FIELD(ctf_stream, field) \ | |
222 | ({ \ | |
223 | assert(CTF_STREAM_FIELD_IS_SET(ctf_stream, field)); \ | |
224 | (ctf_stream)->(field); \ | |
225 | }) | |
226 | ||
f380e105 | 227 | struct ctf_stream_declaration { |
145b8090 MD |
228 | struct ctf_trace *trace; |
229 | /* parent is lexical scope conaining the stream scope */ | |
230 | struct declaration_scope *declaration_scope; | |
231 | /* innermost definition scope. to be used as parent of event. */ | |
232 | struct definition_scope *definition_scope; | |
4716614a | 233 | GPtrArray *events_by_id; /* Array of struct ctf_event_declaration pointers indexed by id */ |
145b8090 MD |
234 | GHashTable *event_quark_to_id; /* GQuark to numeric id */ |
235 | ||
145b8090 MD |
236 | struct declaration_struct *packet_context_decl; |
237 | struct declaration_struct *event_header_decl; | |
238 | struct declaration_struct *event_context_decl; | |
239 | ||
240 | uint64_t stream_id; | |
241 | ||
242 | enum { /* Fields populated mask */ | |
243 | CTF_STREAM_stream_id = (1 << 0), | |
244 | } field_mask; | |
245 | ||
9e88d150 | 246 | GPtrArray *streams; /* Array of struct ctf_stream_definition pointers */ |
145b8090 MD |
247 | }; |
248 | ||
249 | #define CTF_EVENT_SET_FIELD(ctf_event, field) \ | |
250 | do { \ | |
251 | (ctf_event)->field_mask |= CTF_EVENT_ ## field; \ | |
252 | } while (0) | |
253 | ||
254 | #define CTF_EVENT_FIELD_IS_SET(ctf_event, field) \ | |
255 | ((ctf_event)->field_mask & CTF_EVENT_ ## field) | |
256 | ||
257 | #define CTF_EVENT_GET_FIELD(ctf_event, field) \ | |
258 | ({ \ | |
259 | assert(CTF_EVENT_FIELD_IS_SET(ctf_event, field)); \ | |
260 | (ctf_event)->(field); \ | |
261 | }) | |
262 | ||
4716614a | 263 | struct ctf_event_declaration { |
145b8090 | 264 | /* stream mapped by stream_id */ |
f380e105 | 265 | struct ctf_stream_declaration *stream; |
145b8090 MD |
266 | /* parent is lexical scope conaining the event scope */ |
267 | struct declaration_scope *declaration_scope; | |
268 | ||
145b8090 MD |
269 | struct declaration_struct *context_decl; |
270 | struct declaration_struct *fields_decl; | |
271 | ||
272 | GQuark name; | |
273 | uint64_t id; /* Numeric identifier within the stream */ | |
274 | uint64_t stream_id; | |
306eeaa6 | 275 | int loglevel; |
f6714e20 | 276 | GQuark model_emf_uri; |
145b8090 MD |
277 | |
278 | enum { /* Fields populated mask */ | |
d86d62f8 MD |
279 | CTF_EVENT_name = (1 << 0), |
280 | CTF_EVENT_id = (1 << 1), | |
281 | CTF_EVENT_stream_id = (1 << 2), | |
306eeaa6 | 282 | CTF_EVENT_loglevel = (1 << 4), |
f6714e20 | 283 | CTF_EVENT_model_emf_uri = (1 << 5), |
145b8090 MD |
284 | } field_mask; |
285 | }; | |
286 | ||
287 | #endif /* _BABELTRACE_CTF_IR_METADATA_H */ |