Get rid of clock-raw and use real clock
[babeltrace.git] / include / babeltrace / ctf-ir / metadata.h
CommitLineData
145b8090
MD
1#ifndef _BABELTRACE_CTF_IR_METADATA_H
2#define _BABELTRACE_CTF_IR_METADATA_H
3
4/*
5 * BabelTrace
6 *
7 * CTF Intermediate Representation 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>
1b1d76c0 27#include <babeltrace/uuid.h>
145b8090
MD
28#include <assert.h>
29#include <glib.h>
30
31struct ctf_trace;
f380e105 32struct ctf_stream_declaration;
4716614a 33struct ctf_event_declaration;
25ccc85b 34struct ctf_clock;
145b8090 35
9e88d150 36struct ctf_stream_definition {
f380e105 37 struct ctf_stream_declaration *stream_class;
03798a93
JD
38 uint64_t real_timestamp; /* Current timestamp, in ns */
39 uint64_t cycles_timestamp; /* Current timestamp, in cycles */
c87a8eb2 40 uint64_t event_id; /* Current event ID */
5e2eb0ae 41 int has_timestamp;
661c4ce8 42 uint64_t stream_id;
145b8090
MD
43
44 struct definition_struct *trace_packet_header;
45 struct definition_struct *stream_packet_context;
46 struct definition_struct *stream_event_header;
47 struct definition_struct *stream_event_context;
c716f83b 48 GPtrArray *events_by_id; /* Array of struct ctf_event_definition pointers indexed by id */
145b8090
MD
49 struct definition_scope *parent_def_scope; /* for initialization */
50 int stream_definitions_created;
fca04958 51
25ccc85b
MD
52 struct ctf_clock *current_clock;
53
fca04958 54 /* Event discarded information */
4c4ba021 55 uint64_t events_discarded;
03798a93
JD
56 uint64_t prev_real_timestamp; /* Start-of-last-packet timestamp in ns */
57 uint64_t prev_real_timestamp_end; /* End-of-last-packet timestamp in ns */
58 uint64_t prev_cycles_timestamp; /* Start-of-last-packet timestamp in cycles */
59 uint64_t prev_cycles_timestamp_end; /* End-of-last-packet timestamp in cycles */
145b8090
MD
60};
61
c716f83b 62struct ctf_event_definition {
d3ded99d 63 struct ctf_stream_definition *stream;
145b8090
MD
64 struct definition_struct *event_context;
65 struct definition_struct *event_fields;
66};
67
50cb9c56
MD
68#define CTF_CLOCK_SET_FIELD(ctf_clock, field) \
69 do { \
70 (ctf_clock)->field_mask |= CTF_CLOCK_ ## field; \
71 } while (0)
72
73#define CTF_CLOCK_FIELD_IS_SET(ctf_clock, field) \
74 ((ctf_clock)->field_mask & CTF_CLOCK_ ## field)
75
76#define CTF_CLOCK_GET_FIELD(ctf_clock, field) \
77 ({ \
78 assert(CTF_CLOCK_FIELD_IS_SET(ctf_clock, field)); \
79 (ctf_clock)->(field); \
80 })
81
82struct ctf_clock {
83 GQuark name;
84 GQuark uuid;
85 char *description;
86 uint64_t freq; /* frequency, in HZ */
87 /* precision in seconds is: precision * (1/freq) */
88 uint64_t precision;
89 /*
90 * The offset from Epoch is: offset_s + (offset * (1/freq))
91 * Coarse clock offset from Epoch (in seconds).
92 */
93 uint64_t offset_s;
94 /* Fine clock offset from Epoch, in (1/freq) units. */
95 uint64_t offset;
11ac6674 96 int absolute;
50cb9c56
MD
97
98 enum { /* Fields populated mask */
99 CTF_CLOCK_name = (1U << 0),
bf94ab2b 100 CTF_CLOCK_freq = (1U << 1),
50cb9c56
MD
101 } field_mask;
102};
103
145b8090
MD
104#define CTF_TRACE_SET_FIELD(ctf_trace, field) \
105 do { \
106 (ctf_trace)->field_mask |= CTF_TRACE_ ## field; \
107 } while (0)
108
109#define CTF_TRACE_FIELD_IS_SET(ctf_trace, field) \
110 ((ctf_trace)->field_mask & CTF_TRACE_ ## field)
111
112#define CTF_TRACE_GET_FIELD(ctf_trace, field) \
113 ({ \
114 assert(CTF_TRACE_FIELD_IS_SET(ctf_trace, field)); \
115 (ctf_trace)->(field); \
116 })
117
cadd09e9
MD
118#define TRACER_ENV_LEN 128
119
120/* tracer-specific environment */
121struct ctf_tracer_env {
122 int vpid; /* negative if unset */
123
124 /* All strings below: "" if unset. */
125 char procname[TRACER_ENV_LEN];
126 char domain[TRACER_ENV_LEN];
127 char sysname[TRACER_ENV_LEN];
128 char release[TRACER_ENV_LEN];
129 char version[TRACER_ENV_LEN];
130};
131
145b8090
MD
132struct ctf_trace {
133 struct trace_descriptor parent;
134 /* root scope */
135 struct declaration_scope *root_declaration_scope;
136
137 struct declaration_scope *declaration_scope;
138 /* innermost definition scope. to be used as parent of stream. */
139 struct definition_scope *definition_scope;
f380e105 140 GPtrArray *streams; /* Array of struct ctf_stream_declaration pointers */
9e88d150 141 struct ctf_stream_definition *metadata;
50cb9c56 142 GHashTable *clocks;
25ccc85b 143 struct ctf_clock *single_clock; /* currently supports only one clock */
fa709ab2 144 struct trace_collection *collection; /* Container of this trace */
e003ab50 145 GPtrArray *event_declarations; /* Array of all the struct bt_ctf_event_decl */
145b8090 146
145b8090
MD
147 struct declaration_struct *packet_header_decl;
148
149 uint64_t major;
150 uint64_t minor;
ce9cc1bc 151 unsigned char uuid[BABELTRACE_UUID_LEN];
145b8090 152 int byte_order; /* trace BYTE_ORDER. 0 if unset. */
cadd09e9 153 struct ctf_tracer_env env;
145b8090
MD
154
155 enum { /* Fields populated mask */
156 CTF_TRACE_major = (1U << 0),
157 CTF_TRACE_minor = (1U << 1),
158 CTF_TRACE_uuid = (1U << 2),
159 CTF_TRACE_byte_order = (1U << 3),
160 CTF_TRACE_packet_header = (1U << 4),
161 } field_mask;
162
163 /* Information about trace backing directory and files */
164 DIR *dir;
165 int dirfd;
166 int flags; /* open flags */
167
168 /* Heap of streams, ordered to always get the lowest timestam */
169 struct ptr_heap *stream_heap;
82662ad4 170 char path[PATH_MAX];
98a04903
JD
171
172 struct bt_context *ctx;
173 struct bt_trace_handle *handle;
145b8090
MD
174};
175
176#define CTF_STREAM_SET_FIELD(ctf_stream, field) \
177 do { \
178 (ctf_stream)->field_mask |= CTF_STREAM_ ## field; \
179 } while (0)
180
181#define CTF_STREAM_FIELD_IS_SET(ctf_stream, field) \
182 ((ctf_stream)->field_mask & CTF_STREAM_ ## field)
183
184#define CTF_STREAM_GET_FIELD(ctf_stream, field) \
185 ({ \
186 assert(CTF_STREAM_FIELD_IS_SET(ctf_stream, field)); \
187 (ctf_stream)->(field); \
188 })
189
f380e105 190struct ctf_stream_declaration {
145b8090
MD
191 struct ctf_trace *trace;
192 /* parent is lexical scope conaining the stream scope */
193 struct declaration_scope *declaration_scope;
194 /* innermost definition scope. to be used as parent of event. */
195 struct definition_scope *definition_scope;
4716614a 196 GPtrArray *events_by_id; /* Array of struct ctf_event_declaration pointers indexed by id */
145b8090
MD
197 GHashTable *event_quark_to_id; /* GQuark to numeric id */
198
145b8090
MD
199 struct declaration_struct *packet_context_decl;
200 struct declaration_struct *event_header_decl;
201 struct declaration_struct *event_context_decl;
202
203 uint64_t stream_id;
204
205 enum { /* Fields populated mask */
206 CTF_STREAM_stream_id = (1 << 0),
207 } field_mask;
208
9e88d150 209 GPtrArray *streams; /* Array of struct ctf_stream_definition pointers */
145b8090
MD
210};
211
212#define CTF_EVENT_SET_FIELD(ctf_event, field) \
213 do { \
214 (ctf_event)->field_mask |= CTF_EVENT_ ## field; \
215 } while (0)
216
217#define CTF_EVENT_FIELD_IS_SET(ctf_event, field) \
218 ((ctf_event)->field_mask & CTF_EVENT_ ## field)
219
220#define CTF_EVENT_GET_FIELD(ctf_event, field) \
221 ({ \
222 assert(CTF_EVENT_FIELD_IS_SET(ctf_event, field)); \
223 (ctf_event)->(field); \
224 })
225
4716614a 226struct ctf_event_declaration {
145b8090 227 /* stream mapped by stream_id */
f380e105 228 struct ctf_stream_declaration *stream;
145b8090
MD
229 /* parent is lexical scope conaining the event scope */
230 struct declaration_scope *declaration_scope;
231
145b8090
MD
232 struct declaration_struct *context_decl;
233 struct declaration_struct *fields_decl;
234
235 GQuark name;
236 uint64_t id; /* Numeric identifier within the stream */
237 uint64_t stream_id;
306eeaa6 238 int loglevel;
145b8090
MD
239
240 enum { /* Fields populated mask */
d86d62f8
MD
241 CTF_EVENT_name = (1 << 0),
242 CTF_EVENT_id = (1 << 1),
243 CTF_EVENT_stream_id = (1 << 2),
306eeaa6 244 CTF_EVENT_loglevel = (1 << 4),
145b8090
MD
245 } field_mask;
246};
247
248#endif /* _BABELTRACE_CTF_IR_METADATA_H */
This page took 0.034715 seconds and 4 git commands to generate.