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.
22 #include <babeltrace/types.h>
23 #include <babeltrace/format.h>
24 #include <babeltrace/ctf/types.h>
25 #include <sys/types.h>
27 #include <babeltrace/uuid.h>
32 struct ctf_stream_declaration
;
33 struct ctf_event_declaration
;
37 struct ctf_stream_definition
{
38 struct ctf_stream_declaration
*stream_class
;
39 uint64_t real_timestamp
; /* Current timestamp, in ns */
40 uint64_t cycles_timestamp
; /* Current timestamp, in cycles */
41 uint64_t event_id
; /* Current event ID */
45 struct definition_struct
*trace_packet_header
;
46 struct definition_struct
*stream_packet_context
;
47 struct definition_struct
*stream_event_header
;
48 struct definition_struct
*stream_event_context
;
49 GPtrArray
*events_by_id
; /* Array of struct ctf_event_definition pointers indexed by id */
50 struct definition_scope
*parent_def_scope
; /* for initialization */
51 int stream_definitions_created
;
53 struct ctf_clock
*current_clock
;
55 /* Event discarded information */
56 uint64_t events_discarded
;
57 uint64_t prev_real_timestamp
; /* Start-of-last-packet timestamp in ns */
58 uint64_t prev_real_timestamp_end
; /* End-of-last-packet timestamp in ns */
59 uint64_t prev_cycles_timestamp
; /* Start-of-last-packet timestamp in cycles */
60 uint64_t prev_cycles_timestamp_end
; /* End-of-last-packet timestamp in cycles */
63 struct ctf_event_definition
{
64 struct ctf_stream_definition
*stream
;
65 struct definition_struct
*event_context
;
66 struct definition_struct
*event_fields
;
69 #define CTF_CLOCK_SET_FIELD(ctf_clock, field) \
71 (ctf_clock)->field_mask |= CTF_CLOCK_ ## field; \
74 #define CTF_CLOCK_FIELD_IS_SET(ctf_clock, field) \
75 ((ctf_clock)->field_mask & CTF_CLOCK_ ## field)
77 #define CTF_CLOCK_GET_FIELD(ctf_clock, field) \
79 assert(CTF_CLOCK_FIELD_IS_SET(ctf_clock, field)); \
80 (ctf_clock)->(field); \
87 uint64_t freq
; /* frequency, in HZ */
88 /* precision in seconds is: precision * (1/freq) */
91 * The offset from Epoch is: offset_s + (offset * (1/freq))
92 * Coarse clock offset from Epoch (in seconds).
95 /* Fine clock offset from Epoch, in (1/freq) units. */
99 enum { /* Fields populated mask */
100 CTF_CLOCK_name
= (1U << 0),
101 CTF_CLOCK_freq
= (1U << 1),
105 #define CTF_CALLSITE_SET_FIELD(ctf_callsite, field) \
107 (ctf_callsite)->field_mask |= CTF_CALLSITE_ ## field; \
110 #define CTF_CALLSITE_FIELD_IS_SET(ctf_callsite, field) \
111 ((ctf_callsite)->field_mask & CTF_CALLSITE_ ## field)
113 #define CTF_CALLSITE_GET_FIELD(ctf_callsite, field) \
115 assert(CTF_CALLSITE_FIELD_IS_SET(ctf_callsite, field)); \
116 (ctf_callsite)->(field); \
119 struct ctf_callsite
{
120 GQuark name
; /* event name associated with callsite */
124 struct bt_list_head node
;
125 enum { /* Fields populated mask */
126 CTF_CALLSITE_name
= (1U << 0),
127 CTF_CALLSITE_func
= (1U << 1),
128 CTF_CALLSITE_file
= (1U << 2),
129 CTF_CALLSITE_line
= (1U << 3),
133 struct ctf_callsite_dups
{
134 struct bt_list_head head
;
137 #define CTF_TRACE_SET_FIELD(ctf_trace, field) \
139 (ctf_trace)->field_mask |= CTF_TRACE_ ## field; \
142 #define CTF_TRACE_FIELD_IS_SET(ctf_trace, field) \
143 ((ctf_trace)->field_mask & CTF_TRACE_ ## field)
145 #define CTF_TRACE_GET_FIELD(ctf_trace, field) \
147 assert(CTF_TRACE_FIELD_IS_SET(ctf_trace, field)); \
148 (ctf_trace)->(field); \
151 #define TRACER_ENV_LEN 128
153 /* tracer-specific environment */
154 struct ctf_tracer_env
{
155 int vpid
; /* negative if unset */
157 /* All strings below: "" if unset. */
158 char procname
[TRACER_ENV_LEN
];
159 char hostname
[TRACER_ENV_LEN
];
160 char domain
[TRACER_ENV_LEN
];
161 char sysname
[TRACER_ENV_LEN
];
162 char release
[TRACER_ENV_LEN
];
163 char version
[TRACER_ENV_LEN
];
167 struct trace_descriptor parent
;
169 struct declaration_scope
*root_declaration_scope
;
171 struct declaration_scope
*declaration_scope
;
172 /* innermost definition scope. to be used as parent of stream. */
173 struct definition_scope
*definition_scope
;
174 GPtrArray
*streams
; /* Array of struct ctf_stream_declaration pointers */
175 struct ctf_stream_definition
*metadata
;
177 GHashTable
*callsites
;
178 struct ctf_clock
*single_clock
; /* currently supports only one clock */
179 struct trace_collection
*collection
; /* Container of this trace */
180 GPtrArray
*event_declarations
; /* Array of all the struct bt_ctf_event_decl */
182 struct declaration_struct
*packet_header_decl
;
186 unsigned char uuid
[BABELTRACE_UUID_LEN
];
187 int byte_order
; /* trace BYTE_ORDER. 0 if unset. */
188 struct ctf_tracer_env env
;
190 enum { /* Fields populated mask */
191 CTF_TRACE_major
= (1U << 0),
192 CTF_TRACE_minor
= (1U << 1),
193 CTF_TRACE_uuid
= (1U << 2),
194 CTF_TRACE_byte_order
= (1U << 3),
195 CTF_TRACE_packet_header
= (1U << 4),
198 /* Information about trace backing directory and files */
201 int flags
; /* open flags */
203 /* Heap of streams, ordered to always get the lowest timestam */
204 struct ptr_heap
*stream_heap
;
207 struct bt_context
*ctx
;
208 struct bt_trace_handle
*handle
;
211 #define CTF_STREAM_SET_FIELD(ctf_stream, field) \
213 (ctf_stream)->field_mask |= CTF_STREAM_ ## field; \
216 #define CTF_STREAM_FIELD_IS_SET(ctf_stream, field) \
217 ((ctf_stream)->field_mask & CTF_STREAM_ ## field)
219 #define CTF_STREAM_GET_FIELD(ctf_stream, field) \
221 assert(CTF_STREAM_FIELD_IS_SET(ctf_stream, field)); \
222 (ctf_stream)->(field); \
225 struct ctf_stream_declaration
{
226 struct ctf_trace
*trace
;
227 /* parent is lexical scope conaining the stream scope */
228 struct declaration_scope
*declaration_scope
;
229 /* innermost definition scope. to be used as parent of event. */
230 struct definition_scope
*definition_scope
;
231 GPtrArray
*events_by_id
; /* Array of struct ctf_event_declaration pointers indexed by id */
232 GHashTable
*event_quark_to_id
; /* GQuark to numeric id */
234 struct declaration_struct
*packet_context_decl
;
235 struct declaration_struct
*event_header_decl
;
236 struct declaration_struct
*event_context_decl
;
240 enum { /* Fields populated mask */
241 CTF_STREAM_stream_id
= (1 << 0),
244 GPtrArray
*streams
; /* Array of struct ctf_stream_definition pointers */
247 #define CTF_EVENT_SET_FIELD(ctf_event, field) \
249 (ctf_event)->field_mask |= CTF_EVENT_ ## field; \
252 #define CTF_EVENT_FIELD_IS_SET(ctf_event, field) \
253 ((ctf_event)->field_mask & CTF_EVENT_ ## field)
255 #define CTF_EVENT_GET_FIELD(ctf_event, field) \
257 assert(CTF_EVENT_FIELD_IS_SET(ctf_event, field)); \
258 (ctf_event)->(field); \
261 struct ctf_event_declaration
{
262 /* stream mapped by stream_id */
263 struct ctf_stream_declaration
*stream
;
264 /* parent is lexical scope conaining the event scope */
265 struct declaration_scope
*declaration_scope
;
267 struct declaration_struct
*context_decl
;
268 struct declaration_struct
*fields_decl
;
271 uint64_t id
; /* Numeric identifier within the stream */
274 GQuark model_emf_uri
;
276 enum { /* Fields populated mask */
277 CTF_EVENT_name
= (1 << 0),
278 CTF_EVENT_id
= (1 << 1),
279 CTF_EVENT_stream_id
= (1 << 2),
280 CTF_EVENT_loglevel
= (1 << 4),
281 CTF_EVENT_model_emf_uri
= (1 << 5),
285 #endif /* _BABELTRACE_CTF_IR_METADATA_H */