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