CTF: fix packet indexing
[babeltrace.git] / include / babeltrace / ctf / metadata.h
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>
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 #define CTF_MAGIC 0xC1FC1FC1
32 #define TSDL_MAGIC 0x75D11D57
33
34 struct ctf_trace;
35 struct ctf_stream_class;
36 struct ctf_stream;
37 struct ctf_event;
38
39 struct ctf_stream {
40 struct ctf_stream_class *stream_class;
41 uint64_t timestamp; /* Current timestamp, in ns */
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_file_event pointers indexed by id */
48 struct definition_scope *parent_def_scope; /* for initialization */
49 int stream_definitions_created;
50 };
51
52 struct ctf_file_event {
53 struct definition_struct *event_context;
54 struct definition_struct *event_fields;
55 };
56
57 struct ctf_file_stream {
58 uint64_t stream_id;
59 struct ctf_stream stream;
60 struct ctf_stream_pos pos; /* current stream position */
61 };
62
63 #define CTF_TRACE_SET_FIELD(ctf_trace, field) \
64 do { \
65 (ctf_trace)->field_mask |= CTF_TRACE_ ## field; \
66 } while (0)
67
68 #define CTF_TRACE_FIELD_IS_SET(ctf_trace, field) \
69 ((ctf_trace)->field_mask & CTF_TRACE_ ## field)
70
71 #define CTF_TRACE_GET_FIELD(ctf_trace, field) \
72 ({ \
73 assert(CTF_TRACE_FIELD_IS_SET(ctf_trace, field)); \
74 (ctf_trace)->(field); \
75 })
76
77
78 struct ctf_trace {
79 struct trace_descriptor parent;
80 /* root scope */
81 struct declaration_scope *root_declaration_scope;
82
83 struct declaration_scope *declaration_scope;
84 /* innermost definition scope. to be used as parent of stream. */
85 struct definition_scope *definition_scope;
86 GPtrArray *streams; /* Array of struct ctf_stream_class pointers */
87 struct ctf_file_stream metadata;
88
89 /* Declarations only used when parsing */
90 struct declaration_struct *packet_header_decl;
91
92 uint64_t major;
93 uint64_t minor;
94 uuid_t uuid;
95 int byte_order; /* trace BYTE_ORDER. 0 if unset. */
96
97 enum { /* Fields populated mask */
98 CTF_TRACE_major = (1U << 0),
99 CTF_TRACE_minor = (1U << 1),
100 CTF_TRACE_uuid = (1U << 2),
101 CTF_TRACE_byte_order = (1U << 3),
102 CTF_TRACE_packet_header = (1U << 4),
103 } field_mask;
104
105 /* Information about trace backing directory and files */
106 DIR *dir;
107 int dirfd;
108 int flags; /* open flags */
109
110 /* Heap of streams, ordered to always get the lowest timestam */
111 struct ptr_heap *stream_heap;
112 };
113
114 #define CTF_STREAM_SET_FIELD(ctf_stream, field) \
115 do { \
116 (ctf_stream)->field_mask |= CTF_STREAM_ ## field; \
117 } while (0)
118
119 #define CTF_STREAM_FIELD_IS_SET(ctf_stream, field) \
120 ((ctf_stream)->field_mask & CTF_STREAM_ ## field)
121
122 #define CTF_STREAM_GET_FIELD(ctf_stream, field) \
123 ({ \
124 assert(CTF_STREAM_FIELD_IS_SET(ctf_stream, field)); \
125 (ctf_stream)->(field); \
126 })
127
128 struct ctf_stream_class {
129 struct ctf_trace *trace;
130 /* parent is lexical scope conaining the stream scope */
131 struct declaration_scope *declaration_scope;
132 /* innermost definition scope. to be used as parent of event. */
133 struct definition_scope *definition_scope;
134 GPtrArray *events_by_id; /* Array of struct ctf_event pointers indexed by id */
135 GHashTable *event_quark_to_id; /* GQuark to numeric id */
136
137 /* Declarations only used when parsing */
138 struct declaration_struct *packet_context_decl;
139 struct declaration_struct *event_header_decl;
140 struct declaration_struct *event_context_decl;
141
142 uint64_t stream_id;
143
144 enum { /* Fields populated mask */
145 CTF_STREAM_stream_id = (1 << 0),
146 } field_mask;
147
148 GPtrArray *files; /* Array of struct ctf_file_stream pointers */
149 };
150
151 #define CTF_EVENT_SET_FIELD(ctf_event, field) \
152 do { \
153 (ctf_event)->field_mask |= CTF_EVENT_ ## field; \
154 } while (0)
155
156 #define CTF_EVENT_FIELD_IS_SET(ctf_event, field) \
157 ((ctf_event)->field_mask & CTF_EVENT_ ## field)
158
159 #define CTF_EVENT_GET_FIELD(ctf_event, field) \
160 ({ \
161 assert(CTF_EVENT_FIELD_IS_SET(ctf_event, field)); \
162 (ctf_event)->(field); \
163 })
164
165 struct ctf_event {
166 /* stream mapped by stream_id */
167 struct ctf_stream_class *stream;
168 /* parent is lexical scope conaining the event scope */
169 struct declaration_scope *declaration_scope;
170
171 /* Declarations only used when parsing */
172 struct declaration_struct *context_decl;
173 struct declaration_struct *fields_decl;
174
175 GQuark name;
176 uint64_t id; /* Numeric identifier within the stream */
177 uint64_t stream_id;
178
179 enum { /* Fields populated mask */
180 CTF_EVENT_name = (1 << 0),
181 CTF_EVENT_id = (1 << 1),
182 CTF_EVENT_stream_id = (1 << 2),
183 } field_mask;
184 };
185
186 #define HEADER_END char end_field
187 #define header_sizeof(type) offsetof(typeof(type), end_field)
188
189 struct metadata_packet_header {
190 uint32_t magic; /* 0x75D11D57 */
191 uint8_t uuid[16]; /* Unique Universal Identifier */
192 uint32_t checksum; /* 0 if unused */
193 uint32_t content_size; /* in bits */
194 uint32_t packet_size; /* in bits */
195 uint8_t compression_scheme; /* 0 if unused */
196 uint8_t encryption_scheme; /* 0 if unused */
197 uint8_t checksum_scheme; /* 0 if unused */
198 HEADER_END;
199 };
200
201 #endif /* _BABELTRACE_CTF_METADATA_H */
This page took 0.032703 seconds and 4 git commands to generate.