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