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