1 #ifndef _BABELTRACE_CTF_IR_METADATA_H
2 #define _BABELTRACE_CTF_IR_METADATA_H
7 * CTF Intermediate Representation Metadata Header
9 * Copyright 2011 - Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
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:
18 * The above copyright notice and this permission notice shall be included in
19 * all copies or substantial portions of the Software.
21 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
22 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
23 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
24 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
25 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
26 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
30 #include <babeltrace/types.h>
31 #include <babeltrace/format.h>
32 #include <babeltrace/format-internal.h>
33 #include <babeltrace/ctf/types.h>
34 #include <sys/types.h>
36 #include <babeltrace/compat/uuid.h>
41 struct ctf_stream_declaration
;
42 struct ctf_event_declaration
;
47 struct ctf_stream_packet_limits
{
52 struct ctf_stream_packet_timestamp
{
53 struct ctf_stream_packet_limits cycles
;
54 struct ctf_stream_packet_limits real
;
57 struct ctf_stream_definition
{
58 struct ctf_stream_declaration
*stream_class
;
59 uint64_t real_timestamp
; /* Current timestamp, in ns */
60 uint64_t cycles_timestamp
; /* Current timestamp, in cycles */
61 uint64_t event_id
; /* Current event ID */
65 struct definition_struct
*trace_packet_header
;
66 struct definition_struct
*stream_packet_context
;
67 struct definition_struct
*stream_event_header
;
68 struct definition_struct
*stream_event_context
;
69 GPtrArray
*events_by_id
; /* Array of struct ctf_event_definition pointers indexed by id */
70 struct definition_scope
*parent_def_scope
; /* for initialization */
71 int stream_definitions_created
;
73 struct ctf_clock
*current_clock
;
75 /* Event discarded information */
76 uint64_t events_discarded
;
77 /* Trace packets lost */
78 uint64_t packets_lost
;
79 struct ctf_stream_packet_timestamp prev
;
80 struct ctf_stream_packet_timestamp current
;
81 char path
[PATH_MAX
]; /* Path to stream. '\0' for mmap traces */
84 struct ctf_event_definition
{
85 struct ctf_stream_definition
*stream
;
86 struct definition_struct
*event_context
;
87 struct definition_struct
*event_fields
;
90 #define CTF_CLOCK_SET_FIELD(ctf_clock, field) \
92 (ctf_clock)->field_mask |= CTF_CLOCK_ ## field; \
95 #define CTF_CLOCK_FIELD_IS_SET(ctf_clock, field) \
96 ((ctf_clock)->field_mask & CTF_CLOCK_ ## field)
98 #define CTF_CLOCK_GET_FIELD(ctf_clock, field) \
100 assert(CTF_CLOCK_FIELD_IS_SET(ctf_clock, field)); \
101 (ctf_clock)->(field); \
108 uint64_t freq
; /* frequency, in HZ */
109 /* precision in seconds is: precision * (1/freq) */
112 * The offset from Epoch is: offset_s + (offset * (1/freq))
113 * Coarse clock offset from Epoch (in seconds).
116 /* Fine clock offset from Epoch, in (1/freq) units. */
120 enum { /* Fields populated mask */
121 CTF_CLOCK_name
= (1U << 0),
122 CTF_CLOCK_freq
= (1U << 1),
126 #define CTF_CALLSITE_SET_FIELD(ctf_callsite, field) \
128 (ctf_callsite)->field_mask |= CTF_CALLSITE_ ## field; \
131 #define CTF_CALLSITE_FIELD_IS_SET(ctf_callsite, field) \
132 ((ctf_callsite)->field_mask & CTF_CALLSITE_ ## field)
134 #define CTF_CALLSITE_GET_FIELD(ctf_callsite, field) \
136 assert(CTF_CALLSITE_FIELD_IS_SET(ctf_callsite, field)); \
137 (ctf_callsite)->(field); \
140 struct ctf_callsite
{
141 GQuark name
; /* event name associated with callsite */
146 struct bt_list_head node
;
147 enum { /* Fields populated mask */
148 CTF_CALLSITE_name
= (1U << 0),
149 CTF_CALLSITE_func
= (1U << 1),
150 CTF_CALLSITE_file
= (1U << 2),
151 CTF_CALLSITE_line
= (1U << 3),
152 CTF_CALLSITE_ip
= (1U << 4),
156 struct ctf_callsite_dups
{
157 struct bt_list_head head
;
160 #define CTF_TRACE_SET_FIELD(ctf_trace, field) \
162 (ctf_trace)->field_mask |= CTF_TRACE_ ## field; \
165 #define CTF_TRACE_FIELD_IS_SET(ctf_trace, field) \
166 ((ctf_trace)->field_mask & CTF_TRACE_ ## field)
168 #define CTF_TRACE_GET_FIELD(ctf_trace, field) \
170 assert(CTF_TRACE_FIELD_IS_SET(ctf_trace, field)); \
171 (ctf_trace)->(field); \
174 #define TRACER_ENV_LEN 128
176 /* tracer-specific environment */
177 struct ctf_tracer_env
{
178 int vpid
; /* negative if unset */
180 /* All strings below: "" if unset. */
181 char procname
[TRACER_ENV_LEN
];
182 char hostname
[TRACER_ENV_LEN
];
183 char domain
[TRACER_ENV_LEN
];
184 char sysname
[TRACER_ENV_LEN
];
185 char release
[TRACER_ENV_LEN
];
186 char version
[TRACER_ENV_LEN
];
187 char tracer_name
[TRACER_ENV_LEN
];
190 #ifdef ENABLE_DEBUGINFO
195 struct bt_trace_descriptor parent
;
198 struct declaration_scope
*root_declaration_scope
;
200 struct declaration_scope
*declaration_scope
;
201 /* innermost definition scope. to be used as parent of stream. */
202 struct definition_scope
*definition_scope
;
203 GPtrArray
*streams
; /* Array of struct ctf_stream_declaration pointers */
204 struct ctf_stream_definition
*metadata
;
205 char *metadata_string
;
206 int metadata_packetized
;
207 GHashTable
*callsites
;
208 GPtrArray
*event_declarations
; /* Array of all the struct bt_ctf_event_decl */
210 struct declaration_struct
*packet_header_decl
;
211 struct ctf_scanner
*scanner
;
212 int restart_root_decl
;
216 unsigned char uuid
[BABELTRACE_UUID_LEN
];
217 int byte_order
; /* trace BYTE_ORDER. 0 if unset. */
218 struct ctf_tracer_env env
;
220 enum { /* Fields populated mask */
221 CTF_TRACE_major
= (1U << 0),
222 CTF_TRACE_minor
= (1U << 1),
223 CTF_TRACE_uuid
= (1U << 2),
224 CTF_TRACE_byte_order
= (1U << 3),
225 CTF_TRACE_packet_header
= (1U << 4),
228 /* Information about trace backing directory and files */
231 int flags
; /* open flags */
233 #ifdef ENABLE_DEBUGINFO
234 /* Debug information for this trace */
235 struct debug_info
*debug_info
;
239 #define CTF_STREAM_SET_FIELD(ctf_stream, field) \
241 (ctf_stream)->field_mask |= CTF_STREAM_ ## field; \
244 #define CTF_STREAM_FIELD_IS_SET(ctf_stream, field) \
245 ((ctf_stream)->field_mask & CTF_STREAM_ ## field)
247 #define CTF_STREAM_GET_FIELD(ctf_stream, field) \
249 assert(CTF_STREAM_FIELD_IS_SET(ctf_stream, field)); \
250 (ctf_stream)->(field); \
253 struct ctf_stream_declaration
{
254 struct ctf_trace
*trace
;
255 /* parent is lexical scope containing the stream scope */
256 struct declaration_scope
*declaration_scope
;
257 /* innermost definition scope. to be used as parent of event. */
258 struct definition_scope
*definition_scope
;
259 GPtrArray
*events_by_id
; /* Array of struct ctf_event_declaration pointers indexed by id */
260 GHashTable
*event_quark_to_id
; /* GQuark to numeric id */
262 struct declaration_struct
*packet_context_decl
;
263 struct declaration_struct
*event_header_decl
;
264 struct declaration_struct
*event_context_decl
;
268 enum { /* Fields populated mask */
269 CTF_STREAM_stream_id
= (1 << 0),
272 GPtrArray
*streams
; /* Array of struct ctf_stream_definition pointers */
275 #define CTF_EVENT_SET_FIELD(ctf_event, field) \
277 (ctf_event)->field_mask |= CTF_EVENT_ ## field; \
280 #define CTF_EVENT_FIELD_IS_SET(ctf_event, field) \
281 ((ctf_event)->field_mask & CTF_EVENT_ ## field)
283 #define CTF_EVENT_GET_FIELD(ctf_event, field) \
285 assert(CTF_EVENT_FIELD_IS_SET(ctf_event, field)); \
286 (ctf_event)->(field); \
289 struct ctf_event_declaration
{
290 /* stream mapped by stream_id */
291 struct ctf_stream_declaration
*stream
;
292 /* parent is lexical scope containing the event scope */
293 struct declaration_scope
*declaration_scope
;
295 struct declaration_struct
*context_decl
;
296 struct declaration_struct
*fields_decl
;
299 uint64_t id
; /* Numeric identifier within the stream */
302 GQuark model_emf_uri
;
304 enum { /* Fields populated mask */
305 CTF_EVENT_name
= (1 << 0),
306 CTF_EVENT_id
= (1 << 1),
307 CTF_EVENT_stream_id
= (1 << 2),
308 CTF_EVENT_loglevel
= (1 << 4),
309 CTF_EVENT_model_emf_uri
= (1 << 5),
313 #endif /* _BABELTRACE_CTF_IR_METADATA_H */