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