src.ctf.fs: trace-info: omit stream `range-ns` field when no TS
[babeltrace.git] / lib / graph / message / stream-activity.c
1 /*
2 * Copyright 2019 Philippe Proulx <pproulx@efficios.com>
3 *
4 * Permission is hereby granted, free of charge, to any person obtaining a copy
5 * of this software and associated documentation files (the "Software"), to deal
6 * in the Software without restriction, including without limitation the rights
7 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8 * copies of the Software, and to permit persons to whom the Software is
9 * furnished to do so, subject to the following conditions:
10 *
11 * The above copyright notice and this permission notice shall be included in
12 * all copies or substantial portions of the Software.
13 *
14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20 * SOFTWARE.
21 */
22
23 #define BT_LOG_TAG "MSG-STREAM-ACTIVITY"
24 #include <babeltrace2/lib-logging-internal.h>
25
26 #include <babeltrace2/assert-pre-internal.h>
27 #include <babeltrace2/object-internal.h>
28 #include <babeltrace2/compiler-internal.h>
29 #include <babeltrace2/trace-ir/clock-class.h>
30 #include <babeltrace2/trace-ir/clock-snapshot-internal.h>
31 #include <babeltrace2/trace-ir/stream-class-internal.h>
32 #include <babeltrace2/trace-ir/stream-internal.h>
33 #include <babeltrace2/graph/message-internal.h>
34 #include <babeltrace2/graph/message-stream-activity-beginning-const.h>
35 #include <babeltrace2/graph/message-stream-activity-end-const.h>
36 #include <babeltrace2/graph/message-stream-activity-beginning.h>
37 #include <babeltrace2/graph/message-stream-activity-end.h>
38 #include <babeltrace2/graph/message-stream-activity-internal.h>
39
40 static
41 void destroy_stream_activity_message(struct bt_object *obj)
42 {
43 struct bt_message_stream_activity *message = (void *) obj;
44
45 BT_LIB_LOGD("Destroying stream activity message: %!+n", message);
46 BT_LIB_LOGD("Putting stream: %!+s", message->stream);
47 BT_OBJECT_PUT_REF_AND_RESET(message->stream);
48
49 if (message->default_cs) {
50 bt_clock_snapshot_recycle(message->default_cs);
51 message->default_cs = NULL;
52 }
53
54 g_free(message);
55 }
56
57 static inline
58 struct bt_message *create_stream_activity_message(
59 struct bt_self_message_iterator *self_msg_iter,
60 struct bt_stream *stream, enum bt_message_type type)
61 {
62 struct bt_message_stream_activity *message;
63 struct bt_stream_class *stream_class;
64
65 BT_ASSERT_PRE_NON_NULL(self_msg_iter, "Message iterator");
66 BT_ASSERT_PRE_NON_NULL(stream, "Stream");
67 stream_class = bt_stream_borrow_class(stream);
68 BT_ASSERT(stream_class);
69 BT_LIB_LOGD("Creating stream activity message object: "
70 "type=%s, %![stream-]+s, %![sc-]+S",
71 bt_message_type_string(type), stream, stream_class);
72 message = g_new0(struct bt_message_stream_activity, 1);
73 if (!message) {
74 BT_LOGE_STR("Failed to allocate one stream activity message.");
75 goto error;
76 }
77
78 bt_message_init(&message->parent, type,
79 destroy_stream_activity_message, NULL);
80 message->stream = stream;
81 bt_object_get_no_null_check(message->stream);
82
83 if (stream_class->default_clock_class) {
84 message->default_cs = bt_clock_snapshot_create(
85 stream_class->default_clock_class);
86 if (!message->default_cs) {
87 goto error;
88 }
89 }
90
91 message->default_cs_state =
92 BT_MESSAGE_STREAM_ACTIVITY_CLOCK_SNAPSHOT_STATE_UNKNOWN;
93 BT_LIB_LOGD("Created stream activity message object: "
94 "%![msg-]+n, %![stream-]+s, %![sc-]+S", message,
95 stream, stream_class);
96
97 return (void *) &message->parent;
98
99 error:
100 return NULL;
101 }
102
103 struct bt_message *bt_message_stream_activity_beginning_create(
104 struct bt_self_message_iterator *self_msg_iter,
105 const struct bt_stream *stream)
106 {
107 return create_stream_activity_message(self_msg_iter, (void *) stream,
108 BT_MESSAGE_TYPE_STREAM_ACTIVITY_BEGINNING);
109 }
110
111 struct bt_message *bt_message_stream_activity_end_create(
112 struct bt_self_message_iterator *self_msg_iter,
113 const struct bt_stream *stream)
114 {
115 return create_stream_activity_message(self_msg_iter, (void *) stream,
116 BT_MESSAGE_TYPE_STREAM_ACTIVITY_END);
117 }
118
119 static inline
120 struct bt_stream *borrow_stream_activity_message_stream(
121 struct bt_message *message)
122 {
123 struct bt_message_stream_activity *stream_act_msg = (void *) message;
124
125 BT_ASSERT(message);
126 return stream_act_msg->stream;
127 }
128
129 struct bt_stream *bt_message_stream_activity_beginning_borrow_stream(
130 struct bt_message *message)
131 {
132 BT_ASSERT_PRE_NON_NULL(message, "Message");
133 BT_ASSERT_PRE_MSG_IS_TYPE(message,
134 BT_MESSAGE_TYPE_STREAM_ACTIVITY_BEGINNING);
135 return borrow_stream_activity_message_stream(message);
136 }
137
138 struct bt_stream *bt_message_stream_activity_end_borrow_stream(
139 struct bt_message *message)
140 {
141 BT_ASSERT_PRE_NON_NULL(message, "Message");
142 BT_ASSERT_PRE_MSG_IS_TYPE(message,
143 BT_MESSAGE_TYPE_STREAM_ACTIVITY_END);
144 return borrow_stream_activity_message_stream(message);
145 }
146
147 const struct bt_stream *bt_message_stream_activity_beginning_borrow_stream_const(
148 const struct bt_message *message)
149 {
150 return bt_message_stream_activity_beginning_borrow_stream(
151 (void *) message);
152 }
153
154 const struct bt_stream *bt_message_stream_activity_end_borrow_stream_const(
155 const struct bt_message *message)
156 {
157 return bt_message_stream_activity_end_borrow_stream((void *) message);
158 }
159
160 static inline
161 void set_stream_activity_message_default_clock_snapshot(
162 struct bt_message *msg, uint64_t value_cycles)
163 {
164 struct bt_message_stream_activity *stream_act_msg = (void *) msg;
165 struct bt_stream_class *sc;
166
167 BT_ASSERT(msg);
168 BT_ASSERT_PRE_HOT(msg, "Message", ": %!+n", msg);
169 sc = stream_act_msg->stream->class;
170 BT_ASSERT(sc);
171 BT_ASSERT_PRE(sc->default_clock_class,
172 "Message's stream's class has no default clock class: "
173 "%![msg-]+n, %![sc-]+S", msg, sc);
174 bt_clock_snapshot_set_raw_value(stream_act_msg->default_cs,
175 value_cycles);
176 stream_act_msg->default_cs_state =
177 BT_MESSAGE_STREAM_ACTIVITY_CLOCK_SNAPSHOT_STATE_KNOWN;
178 BT_LIB_LOGV("Set stream activity message's default clock snapshot: "
179 "%![msg-]+n, value=%" PRIu64, msg, value_cycles);
180 }
181
182 void bt_message_stream_activity_beginning_set_default_clock_snapshot(
183 struct bt_message *msg, uint64_t raw_value)
184 {
185 BT_ASSERT_PRE_NON_NULL(msg, "Message");
186 BT_ASSERT_PRE_MSG_IS_TYPE(msg,
187 BT_MESSAGE_TYPE_STREAM_ACTIVITY_BEGINNING);
188 set_stream_activity_message_default_clock_snapshot(msg, raw_value);
189 }
190
191 void bt_message_stream_activity_end_set_default_clock_snapshot(
192 struct bt_message *msg, uint64_t raw_value)
193 {
194 BT_ASSERT_PRE_NON_NULL(msg, "Message");
195 BT_ASSERT_PRE_MSG_IS_TYPE(msg,
196 BT_MESSAGE_TYPE_STREAM_ACTIVITY_END);
197 set_stream_activity_message_default_clock_snapshot(msg, raw_value);
198 }
199
200 static inline
201 enum bt_message_stream_activity_clock_snapshot_state
202 borrow_stream_activity_message_default_clock_snapshot_const(
203 const bt_message *msg, const bt_clock_snapshot **snapshot)
204 {
205 const struct bt_message_stream_activity *stream_act_msg =
206 (const void *) msg;
207
208 BT_ASSERT_PRE_NON_NULL(snapshot, "Clock snapshot (output)");
209 *snapshot = stream_act_msg->default_cs;
210 return stream_act_msg->default_cs_state;
211 }
212
213 enum bt_message_stream_activity_clock_snapshot_state
214 bt_message_stream_activity_beginning_borrow_default_clock_snapshot_const(
215 const bt_message *msg, const bt_clock_snapshot **snapshot)
216 {
217 BT_ASSERT_PRE_NON_NULL(msg, "Message");
218 BT_ASSERT_PRE_MSG_IS_TYPE(msg,
219 BT_MESSAGE_TYPE_STREAM_ACTIVITY_BEGINNING);
220 return borrow_stream_activity_message_default_clock_snapshot_const(msg,
221 snapshot);
222 }
223
224 enum bt_message_stream_activity_clock_snapshot_state
225 bt_message_stream_activity_end_borrow_default_clock_snapshot_const(
226 const bt_message *msg, const bt_clock_snapshot **snapshot)
227 {
228 BT_ASSERT_PRE_NON_NULL(msg, "Message");
229 BT_ASSERT_PRE_MSG_IS_TYPE(msg, BT_MESSAGE_TYPE_STREAM_ACTIVITY_END);
230 return borrow_stream_activity_message_default_clock_snapshot_const(msg,
231 snapshot);
232 }
233
234 static inline
235 void set_stream_activity_message_default_clock_snapshot_state(
236 struct bt_message *msg,
237 enum bt_message_stream_activity_clock_snapshot_state state)
238 {
239 struct bt_message_stream_activity *stream_act_msg = (void *) msg;
240
241 BT_ASSERT(msg);
242 BT_ASSERT_PRE_HOT(msg, "Message", ": %!+n", msg);
243 BT_ASSERT_PRE(state != BT_MESSAGE_STREAM_ACTIVITY_CLOCK_SNAPSHOT_STATE_KNOWN,
244 "Invalid clock snapshot state: %![msg-]+n, state=%s",
245 msg,
246 bt_message_stream_activity_clock_snapshot_state_string(state));
247 stream_act_msg->default_cs_state = state;
248 BT_LIB_LOGV("Set stream activity message's default clock snapshot state: "
249 "%![msg-]+n, state=%s", msg,
250 bt_message_stream_activity_clock_snapshot_state_string(state));
251 }
252
253 void bt_message_stream_activity_beginning_set_default_clock_snapshot_state(
254 struct bt_message *msg,
255 enum bt_message_stream_activity_clock_snapshot_state state)
256 {
257 BT_ASSERT_PRE_NON_NULL(msg, "Message");
258 BT_ASSERT_PRE_MSG_IS_TYPE(msg,
259 BT_MESSAGE_TYPE_STREAM_ACTIVITY_BEGINNING);
260 set_stream_activity_message_default_clock_snapshot_state(msg, state);
261 }
262
263 void bt_message_stream_activity_end_set_default_clock_snapshot_state(
264 struct bt_message *msg,
265 enum bt_message_stream_activity_clock_snapshot_state state)
266 {
267 BT_ASSERT_PRE_NON_NULL(msg, "Message");
268 BT_ASSERT_PRE_MSG_IS_TYPE(msg,
269 BT_MESSAGE_TYPE_STREAM_ACTIVITY_END);
270 set_stream_activity_message_default_clock_snapshot_state(msg, state);
271 }
272
273 static inline
274 const struct bt_clock_class *
275 borrow_stream_activity_message_stream_class_default_clock_class(
276 const struct bt_message *msg)
277 {
278 struct bt_message_stream_activity *stream_act_msg = (void *) msg;
279
280 BT_ASSERT(msg);
281 return stream_act_msg->stream->class->default_clock_class;
282 }
283
284 const struct bt_clock_class *
285 bt_message_stream_activity_beginning_borrow_stream_class_default_clock_class_const(
286 const struct bt_message *msg)
287 {
288 BT_ASSERT_PRE_NON_NULL(msg, "Message");
289 BT_ASSERT_PRE_MSG_IS_TYPE(msg,
290 BT_MESSAGE_TYPE_STREAM_ACTIVITY_BEGINNING);
291 return borrow_stream_activity_message_stream_class_default_clock_class(
292 msg);
293 }
294
295 const struct bt_clock_class *
296 bt_message_stream_activity_end_borrow_stream_class_default_clock_class_const(
297 const struct bt_message *msg)
298 {
299 BT_ASSERT_PRE_NON_NULL(msg, "Message");
300 BT_ASSERT_PRE_MSG_IS_TYPE(msg, BT_MESSAGE_TYPE_STREAM_ACTIVITY_END);
301 return borrow_stream_activity_message_stream_class_default_clock_class(
302 msg);
303 }
This page took 0.036178 seconds and 4 git commands to generate.