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