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