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