Commit | Line | Data |
---|---|---|
c054553d MD |
1 | #ifndef _BABELTRACE_CTF_METADATA_H |
2 | #define _BABELTRACE_CTF_METADATA_H | |
3 | ||
4 | /* | |
5 | * BabelTrace | |
6 | * | |
7 | * CTF 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> | |
46322b33 | 23 | #include <babeltrace/format.h> |
dd2544fd | 24 | #include <babeltrace/ctf/types.h> |
bbefb8dd MD |
25 | #include <sys/types.h> |
26 | #include <dirent.h> | |
96513a7f MD |
27 | #include <uuid/uuid.h> |
28 | #include <assert.h> | |
c054553d MD |
29 | #include <glib.h> |
30 | ||
0f980a35 MD |
31 | #define CTF_MAGIC 0xC1FC1FC1 |
32 | ||
c054553d MD |
33 | struct ctf_trace; |
34 | struct ctf_stream; | |
35 | struct ctf_event; | |
36 | ||
0f980a35 MD |
37 | struct ctf_file_stream { |
38 | uint64_t stream_id; | |
39 | struct ctf_stream *stream; | |
46322b33 | 40 | struct ctf_stream_pos pos; /* current stream position */ |
65102a8c MD |
41 | }; |
42 | ||
a0720417 | 43 | #define CTF_TRACE_SET_FIELD(ctf_trace, field) \ |
96513a7f | 44 | do { \ |
96513a7f MD |
45 | (ctf_trace)->field_mask |= CTF_TRACE_ ## field; \ |
46 | } while (0) | |
47 | ||
48 | #define CTF_TRACE_FIELD_IS_SET(ctf_trace, field) \ | |
49 | ((ctf_trace)->field_mask & CTF_TRACE_ ## field) | |
50 | ||
51 | #define CTF_TRACE_GET_FIELD(ctf_trace, field) \ | |
52 | ({ \ | |
53 | assert(CTF_TRACE_FIELD_IS_SET(ctf_trace, field)); \ | |
54 | (ctf_trace)->(field); \ | |
55 | }) | |
56 | ||
05628561 | 57 | |
c054553d | 58 | struct ctf_trace { |
46322b33 | 59 | struct trace_descriptor parent; |
05628561 | 60 | /* root scope */ |
f6625916 | 61 | struct declaration_scope *root_declaration_scope; |
05628561 | 62 | |
f6625916 | 63 | struct declaration_scope *declaration_scope; |
0f980a35 MD |
64 | /* innermost definition scope. to be used as parent of stream. */ |
65 | struct definition_scope *definition_scope; | |
66 | GPtrArray *streams; /* Array of struct ctf_stream pointers */ | |
67 | struct ctf_file_stream metadata; | |
68 | ||
69 | /* Declarations only used when parsing */ | |
70 | struct declaration_struct *packet_header_decl; | |
71 | ||
72 | /* Definitions used afterward */ | |
73 | struct definition_struct *packet_header; | |
fe21b943 MD |
74 | |
75 | uint64_t major; | |
76 | uint64_t minor; | |
96513a7f | 77 | uuid_t uuid; |
0f980a35 | 78 | int byte_order; /* trace BYTE_ORDER. 0 if unset. */ |
96513a7f MD |
79 | |
80 | enum { /* Fields populated mask */ | |
0f980a35 MD |
81 | CTF_TRACE_major = (1U << 0), |
82 | CTF_TRACE_minor = (1U << 1), | |
83 | CTF_TRACE_uuid = (1U << 2), | |
84 | CTF_TRACE_byte_order = (1U << 3), | |
85 | CTF_TRACE_packet_header = (1U << 4), | |
96513a7f | 86 | } field_mask; |
bbefb8dd MD |
87 | |
88 | /* Information about trace backing directory and files */ | |
89 | DIR *dir; | |
65102a8c | 90 | int dirfd; |
bbefb8dd | 91 | int flags; /* open flags */ |
c054553d MD |
92 | }; |
93 | ||
a0720417 | 94 | #define CTF_STREAM_SET_FIELD(ctf_stream, field) \ |
96513a7f | 95 | do { \ |
96513a7f MD |
96 | (ctf_stream)->field_mask |= CTF_STREAM_ ## field; \ |
97 | } while (0) | |
98 | ||
99 | #define CTF_STREAM_FIELD_IS_SET(ctf_stream, field) \ | |
100 | ((ctf_stream)->field_mask & CTF_STREAM_ ## field) | |
101 | ||
102 | #define CTF_STREAM_GET_FIELD(ctf_stream, field) \ | |
103 | ({ \ | |
104 | assert(CTF_STREAM_FIELD_IS_SET(ctf_stream, field)); \ | |
105 | (ctf_stream)->(field); \ | |
106 | }) | |
107 | ||
c054553d | 108 | struct ctf_stream { |
96513a7f | 109 | struct ctf_trace *trace; |
05628561 | 110 | /* parent is lexical scope conaining the stream scope */ |
f6625916 | 111 | struct declaration_scope *declaration_scope; |
41253107 | 112 | /* innermost definition scope. to be used as parent of event. */ |
e1151715 | 113 | struct definition_scope *definition_scope; |
05628561 | 114 | GPtrArray *events_by_id; /* Array of struct ctf_event pointers indexed by id */ |
96513a7f | 115 | GHashTable *event_quark_to_id; /* GQuark to numeric id */ |
fe21b943 | 116 | |
9e29e16e MD |
117 | /* Declarations only used when parsing */ |
118 | struct declaration_struct *packet_context_decl; | |
119 | struct declaration_struct *event_header_decl; | |
120 | struct declaration_struct *event_context_decl; | |
121 | ||
122 | /* Definitions used afterward */ | |
123 | struct definition_struct *packet_context; | |
e1151715 MD |
124 | struct definition_struct *event_header; |
125 | struct definition_struct *event_context; | |
96513a7f MD |
126 | |
127 | uint64_t stream_id; | |
128 | ||
129 | enum { /* Fields populated mask */ | |
130 | CTF_STREAM_stream_id = (1 << 0), | |
131 | } field_mask; | |
bbefb8dd | 132 | |
0f980a35 | 133 | GPtrArray *files; /* Array of struct ctf_file_stream pointers */ |
c054553d MD |
134 | }; |
135 | ||
05628561 | 136 | #define CTF_EVENT_SET_FIELD(ctf_event, field) \ |
96513a7f | 137 | do { \ |
96513a7f MD |
138 | (ctf_event)->field_mask |= CTF_EVENT_ ## field; \ |
139 | } while (0) | |
140 | ||
141 | #define CTF_EVENT_FIELD_IS_SET(ctf_event, field) \ | |
142 | ((ctf_event)->field_mask & CTF_EVENT_ ## field) | |
143 | ||
144 | #define CTF_EVENT_GET_FIELD(ctf_event, field) \ | |
145 | ({ \ | |
146 | assert(CTF_EVENT_FIELD_IS_SET(ctf_event, field)); \ | |
147 | (ctf_event)->(field); \ | |
148 | }) | |
149 | ||
c054553d | 150 | struct ctf_event { |
05628561 MD |
151 | /* stream mapped by stream_id */ |
152 | struct ctf_stream *stream; | |
153 | /* parent is lexical scope conaining the event scope */ | |
f6625916 | 154 | struct declaration_scope *declaration_scope; |
9e29e16e MD |
155 | |
156 | /* Declarations only used when parsing */ | |
157 | struct declaration_struct *context_decl; | |
158 | struct declaration_struct *fields_decl; | |
159 | ||
160 | /* Definitions used afterward */ | |
e1151715 MD |
161 | struct definition_struct *context; |
162 | struct definition_struct *fields; | |
96513a7f MD |
163 | |
164 | GQuark name; | |
165 | uint64_t id; /* Numeric identifier within the stream */ | |
166 | uint64_t stream_id; | |
167 | ||
168 | enum { /* Fields populated mask */ | |
169 | CTF_EVENT_name = (1 << 0), | |
170 | CTF_EVENT_id = (1 << 1), | |
171 | CTF_EVENT_stream_id = (1 << 2), | |
172 | } field_mask; | |
c054553d MD |
173 | }; |
174 | ||
175 | #endif /* _BABELTRACE_CTF_METADATA_H */ |