Add -t option
[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
33 struct ctf_trace;
34 struct ctf_stream;
35 struct ctf_event;
36
37 struct ctf_file_stream {
38 uint64_t stream_id;
39 struct ctf_stream *stream;
40 struct ctf_stream_pos pos; /* current stream position */
41 };
42
43 #define CTF_TRACE_SET_FIELD(ctf_trace, field) \
44 do { \
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
57
58 struct ctf_trace {
59 struct trace_descriptor parent;
60 /* root scope */
61 struct declaration_scope *root_declaration_scope;
62
63 struct declaration_scope *declaration_scope;
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;
74
75 uint64_t major;
76 uint64_t minor;
77 uuid_t uuid;
78 int byte_order; /* trace BYTE_ORDER. 0 if unset. */
79
80 enum { /* Fields populated mask */
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),
86 } field_mask;
87
88 /* Information about trace backing directory and files */
89 DIR *dir;
90 int dirfd;
91 int flags; /* open flags */
92 };
93
94 #define CTF_STREAM_SET_FIELD(ctf_stream, field) \
95 do { \
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
108 struct ctf_stream {
109 struct ctf_trace *trace;
110 /* parent is lexical scope conaining the stream scope */
111 struct declaration_scope *declaration_scope;
112 /* innermost definition scope. to be used as parent of event. */
113 struct definition_scope *definition_scope;
114 GPtrArray *events_by_id; /* Array of struct ctf_event pointers indexed by id */
115 GHashTable *event_quark_to_id; /* GQuark to numeric id */
116
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;
124 struct definition_struct *event_header;
125 struct definition_struct *event_context;
126
127 uint64_t stream_id;
128
129 enum { /* Fields populated mask */
130 CTF_STREAM_stream_id = (1 << 0),
131 } field_mask;
132
133 GPtrArray *files; /* Array of struct ctf_file_stream pointers */
134 };
135
136 #define CTF_EVENT_SET_FIELD(ctf_event, field) \
137 do { \
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
150 struct ctf_event {
151 /* stream mapped by stream_id */
152 struct ctf_stream *stream;
153 /* parent is lexical scope conaining the event scope */
154 struct declaration_scope *declaration_scope;
155
156 /* Declarations only used when parsing */
157 struct declaration_struct *context_decl;
158 struct declaration_struct *fields_decl;
159
160 /* Definitions used afterward */
161 struct definition_struct *context;
162 struct definition_struct *fields;
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;
173 };
174
175 #endif /* _BABELTRACE_CTF_METADATA_H */
This page took 0.034478 seconds and 4 git commands to generate.