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