tap-driver.sh: flush stdout after each test result
[babeltrace.git] / lib / graph / message / discarded-items.c
CommitLineData
4c833281
PP
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-DISCARDED-ITEMS"
3fadfbc0 24#include <babeltrace2/lib-logging-internal.h>
4c833281 25
3fadfbc0
MJ
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/property-internal.h>
34#include <babeltrace2/graph/message-internal.h>
35#include <babeltrace2/graph/message-discarded-items-internal.h>
36#include <babeltrace2/graph/message-discarded-events.h>
37#include <babeltrace2/graph/message-discarded-events-const.h>
38#include <babeltrace2/graph/message-discarded-packets.h>
39#include <babeltrace2/graph/message-discarded-packets-const.h>
4c833281
PP
40
41static
42void destroy_discarded_items_message(struct bt_object *obj)
43{
44 struct bt_message_discarded_items *message = (void *) obj;
45
46 BT_LIB_LOGD("Destroying discarded items message: %!+n", message);
47 BT_LIB_LOGD("Putting stream: %!+s", message->stream);
48 BT_OBJECT_PUT_REF_AND_RESET(message->stream);
49
50 if (message->default_begin_cs) {
51 bt_clock_snapshot_recycle(message->default_begin_cs);
52 message->default_begin_cs = NULL;
53 }
54
55 if (message->default_end_cs) {
56 bt_clock_snapshot_recycle(message->default_end_cs);
57 message->default_end_cs = NULL;
58 }
59
60 g_free(message);
61}
62
63static inline
64struct bt_message *create_discarded_items_message(
65 struct bt_self_message_iterator *self_msg_iter,
66 enum bt_message_type type, struct bt_stream *stream,
67 bool with_cs,
68 uint64_t beginning_raw_value, uint64_t end_raw_value)
69{
70 struct bt_message_discarded_items *message;
71 struct bt_stream_class *stream_class;
2e90378a 72 bool has_support;
8cc5f12b 73 bool need_cs;
4c833281
PP
74
75 BT_ASSERT_PRE_NON_NULL(self_msg_iter, "Message iterator");
76 BT_ASSERT_PRE_NON_NULL(stream, "Stream");
77 stream_class = bt_stream_borrow_class(stream);
78 BT_ASSERT(stream_class);
2e90378a
PP
79
80 if (type == BT_MESSAGE_TYPE_DISCARDED_EVENTS) {
81 has_support = stream_class->supports_discarded_events;
8cc5f12b 82 need_cs = stream_class->discarded_events_have_default_clock_snapshots;
2e90378a
PP
83 } else {
84 has_support = stream_class->supports_discarded_packets;
8cc5f12b 85 need_cs = stream_class->discarded_packets_have_default_clock_snapshots;
2e90378a
PP
86 }
87
88 BT_ASSERT_PRE(has_support,
89 "Stream class does not support discarded events or packets: "
90 "type=%s, %![stream-]+s, %![sc-]+S",
91 bt_message_type_string(type), stream, stream_class);
8cc5f12b 92 BT_ASSERT_PRE(need_cs ? with_cs : true,
2e90378a 93 "Unexpected stream class configuration when creating "
8cc5f12b
PP
94 "a discarded events or discarded packets message: "
95 "default clock snapshots are needed, but none was provided: "
96 "type=%s, %![stream-]+s, %![sc-]+S, with-cs=%d, "
97 "cs-begin-val=%" PRIu64 ", cs-end-val=%" PRIu64,
98 bt_message_type_string(type), stream, stream_class,
99 with_cs, beginning_raw_value, end_raw_value);
100 BT_ASSERT_PRE(!need_cs ? !with_cs : true,
101 "Unexpected stream class configuration when creating "
102 "a discarded events or discarded packets message: "
103 "no default clock snapshots are needed, but two were provided: "
aa12059b
PP
104 "type=%s, %![stream-]+s, %![sc-]+S, with-cs=%d, "
105 "cs-begin-val=%" PRIu64 ", cs-end-val=%" PRIu64,
106 bt_message_type_string(type), stream, stream_class,
107 with_cs, beginning_raw_value, end_raw_value);
4c833281
PP
108 BT_LIB_LOGD("Creating discarded items message object: "
109 "type=%s, %![stream-]+s, %![sc-]+S, with-cs=%d, "
110 "cs-begin-val=%" PRIu64 ", cs-end-val=%" PRIu64,
111 bt_message_type_string(type), stream, stream_class,
112 with_cs, beginning_raw_value, end_raw_value);
113 message = g_new0(struct bt_message_discarded_items, 1);
114 if (!message) {
115 BT_LOGE_STR("Failed to allocate one discarded items message.");
116 goto error;
117 }
118
119 bt_message_init(&message->parent, type,
120 destroy_discarded_items_message, NULL);
121 message->stream = stream;
122 bt_object_get_no_null_check(message->stream);
123
124 if (with_cs) {
aa12059b 125 BT_ASSERT(stream_class->default_clock_class);
4c833281
PP
126 message->default_begin_cs = bt_clock_snapshot_create(
127 stream_class->default_clock_class);
128 if (!message->default_begin_cs) {
129 goto error;
130 }
131
132 bt_clock_snapshot_set_raw_value(message->default_begin_cs,
133 beginning_raw_value);
134
135 message->default_end_cs = bt_clock_snapshot_create(
136 stream_class->default_clock_class);
137 if (!message->default_end_cs) {
138 goto error;
139 }
140
141 bt_clock_snapshot_set_raw_value(message->default_end_cs,
142 end_raw_value);
143 }
144
145 bt_property_uint_init(&message->count,
146 BT_PROPERTY_AVAILABILITY_NOT_AVAILABLE, 0);
147 BT_LIB_LOGD("Created discarded items message object: "
148 "%![msg-]+n, %![stream-]+s, %![sc-]+S", message,
149 stream, stream_class);
150
151 return (void *) &message->parent;
152
153error:
154 return NULL;
155}
156
157static inline
158struct bt_stream *borrow_discarded_items_message_stream(
159 struct bt_message *message)
160{
161 struct bt_message_discarded_items *disc_items_msg = (void *) message;
162
163 BT_ASSERT(message);
164 return disc_items_msg->stream;
165}
166
167static inline
168void set_discarded_items_message_count(struct bt_message *message,
169 uint64_t count)
170{
171 struct bt_message_discarded_items *disc_items_msg = (void *) message;
172
173 BT_ASSERT(message);
174 BT_ASSERT_PRE_HOT(message, "Message", ": %!+n", message);
175 bt_property_uint_set(&disc_items_msg->count, count);
176}
177
178static inline
179enum bt_property_availability get_discarded_items_message_count(
180 const struct bt_message *message, uint64_t *count)
181{
182 struct bt_message_discarded_items *disc_items_msg = (void *) message;
183
184 BT_ASSERT_PRE_NON_NULL(count, "Count (output)");
185 BT_ASSERT(message);
186 *count = disc_items_msg->count.value;
187 return disc_items_msg->count.base.avail;
188}
189
190static inline
0cbc2c33 191const struct bt_clock_snapshot *
9b24b6aa 192borrow_discarded_items_message_beginning_default_clock_snapshot_const(
0cbc2c33 193 const struct bt_message *message)
4c833281
PP
194{
195 struct bt_message_discarded_items *disc_items_msg = (void *) message;
196
197 BT_ASSERT(message);
198 BT_ASSERT_PRE(disc_items_msg->stream->class->default_clock_class,
199 "Message's stream's class has no default clock class: "
200 "%![msg-]+n, %![sc-]+S",
201 message, disc_items_msg->stream->class);
0cbc2c33 202 return disc_items_msg->default_begin_cs;
4c833281
PP
203}
204
205static inline
0cbc2c33 206const struct bt_clock_snapshot *
9b24b6aa 207borrow_discarded_items_message_end_default_clock_snapshot_const(
0cbc2c33 208 const struct bt_message *message)
4c833281
PP
209{
210 struct bt_message_discarded_items *disc_items_msg = (void *) message;
211
212 BT_ASSERT(message);
213 BT_ASSERT_PRE(disc_items_msg->stream->class->default_clock_class,
214 "Message's stream's class has no default clock class: "
215 "%![msg-]+n, %![sc-]+S",
216 message, disc_items_msg->stream->class);
0cbc2c33 217 return disc_items_msg->default_end_cs;
4c833281
PP
218}
219
220struct bt_message *bt_message_discarded_events_create(
221 struct bt_self_message_iterator *message_iterator,
58085ca4 222 const struct bt_stream *stream)
4c833281
PP
223{
224 return create_discarded_items_message(message_iterator,
58085ca4 225 BT_MESSAGE_TYPE_DISCARDED_EVENTS, (void *) stream,
4c833281
PP
226 false, 0, 0);
227}
228
229struct bt_message *bt_message_discarded_events_create_with_default_clock_snapshots(
230 struct bt_self_message_iterator *message_iterator,
58085ca4 231 const struct bt_stream *stream, uint64_t beginning_raw_value,
4c833281
PP
232 uint64_t end_raw_value)
233{
234 return create_discarded_items_message(message_iterator,
58085ca4 235 BT_MESSAGE_TYPE_DISCARDED_EVENTS, (void *) stream,
4c833281
PP
236 true, beginning_raw_value, end_raw_value);
237}
238
239struct bt_stream *bt_message_discarded_events_borrow_stream(
240 struct bt_message *message)
241{
242 BT_ASSERT_PRE_NON_NULL(message, "Message");
243 BT_ASSERT_PRE_MSG_IS_TYPE(message, BT_MESSAGE_TYPE_DISCARDED_EVENTS);
244 return borrow_discarded_items_message_stream(message);
245}
246
247void bt_message_discarded_events_set_count(struct bt_message *message,
248 uint64_t count)
249{
250 BT_ASSERT_PRE_NON_NULL(message, "Message");
251 BT_ASSERT_PRE_MSG_IS_TYPE(message, BT_MESSAGE_TYPE_DISCARDED_EVENTS);
252 set_discarded_items_message_count(message, count);
253}
254
0cbc2c33 255const struct bt_clock_snapshot *
9b24b6aa 256bt_message_discarded_events_borrow_beginning_default_clock_snapshot_const(
0cbc2c33 257 const struct bt_message *msg)
4c833281
PP
258{
259 BT_ASSERT_PRE_NON_NULL(msg, "Message");
260 BT_ASSERT_PRE_MSG_IS_TYPE(msg, BT_MESSAGE_TYPE_DISCARDED_EVENTS);
9b24b6aa 261 return borrow_discarded_items_message_beginning_default_clock_snapshot_const(
0cbc2c33 262 msg);
4c833281
PP
263}
264
0cbc2c33 265const struct bt_clock_snapshot *
9b24b6aa 266bt_message_discarded_events_borrow_end_default_clock_snapshot_const(
0cbc2c33 267 const struct bt_message *msg)
4c833281
PP
268{
269 BT_ASSERT_PRE_NON_NULL(msg, "Message");
270 BT_ASSERT_PRE_MSG_IS_TYPE(msg, BT_MESSAGE_TYPE_DISCARDED_EVENTS);
9b24b6aa 271 return borrow_discarded_items_message_end_default_clock_snapshot_const(
0cbc2c33 272 msg);
4c833281
PP
273}
274
275const struct bt_stream *
276bt_message_discarded_events_borrow_stream_const(const struct bt_message *message)
277{
278 return (void *) bt_message_discarded_events_borrow_stream(
279 (void *) message);
280}
281
282enum bt_property_availability bt_message_discarded_events_get_count(
283 const struct bt_message *message, uint64_t *count)
284{
285 BT_ASSERT_PRE_NON_NULL(message, "Message");
286 BT_ASSERT_PRE_MSG_IS_TYPE(message, BT_MESSAGE_TYPE_DISCARDED_EVENTS);
287 return get_discarded_items_message_count(message, count);
288}
4237f1f2
PP
289
290struct bt_message *bt_message_discarded_packets_create(
291 struct bt_self_message_iterator *message_iterator,
58085ca4 292 const struct bt_stream *stream)
4237f1f2
PP
293{
294 return create_discarded_items_message(message_iterator,
58085ca4 295 BT_MESSAGE_TYPE_DISCARDED_PACKETS, (void *) stream,
4237f1f2
PP
296 false, 0, 0);
297}
298
299struct bt_message *bt_message_discarded_packets_create_with_default_clock_snapshots(
300 struct bt_self_message_iterator *message_iterator,
58085ca4 301 const struct bt_stream *stream, uint64_t beginning_raw_value,
4237f1f2
PP
302 uint64_t end_raw_value)
303{
304 return create_discarded_items_message(message_iterator,
58085ca4 305 BT_MESSAGE_TYPE_DISCARDED_PACKETS, (void *) stream,
4237f1f2
PP
306 true, beginning_raw_value, end_raw_value);
307}
308
309struct bt_stream *bt_message_discarded_packets_borrow_stream(
310 struct bt_message *message)
311{
312 BT_ASSERT_PRE_NON_NULL(message, "Message");
313 BT_ASSERT_PRE_MSG_IS_TYPE(message, BT_MESSAGE_TYPE_DISCARDED_PACKETS);
314 return borrow_discarded_items_message_stream(message);
315}
316
317void bt_message_discarded_packets_set_count(struct bt_message *message,
318 uint64_t count)
319{
320 BT_ASSERT_PRE_NON_NULL(message, "Message");
321 BT_ASSERT_PRE_MSG_IS_TYPE(message, BT_MESSAGE_TYPE_DISCARDED_PACKETS);
322 set_discarded_items_message_count(message, count);
323}
324
0cbc2c33 325const struct bt_clock_snapshot *
9b24b6aa 326bt_message_discarded_packets_borrow_beginning_default_clock_snapshot_const(
0cbc2c33 327 const struct bt_message *msg)
4237f1f2
PP
328{
329 BT_ASSERT_PRE_NON_NULL(msg, "Message");
330 BT_ASSERT_PRE_MSG_IS_TYPE(msg, BT_MESSAGE_TYPE_DISCARDED_PACKETS);
9b24b6aa 331 return borrow_discarded_items_message_beginning_default_clock_snapshot_const(
0cbc2c33 332 msg);
4237f1f2
PP
333}
334
0cbc2c33 335const struct bt_clock_snapshot *
9b24b6aa 336bt_message_discarded_packets_borrow_end_default_clock_snapshot_const(
0cbc2c33 337 const struct bt_message *msg)
4237f1f2
PP
338{
339 BT_ASSERT_PRE_NON_NULL(msg, "Message");
340 BT_ASSERT_PRE_MSG_IS_TYPE(msg, BT_MESSAGE_TYPE_DISCARDED_PACKETS);
9b24b6aa 341 return borrow_discarded_items_message_end_default_clock_snapshot_const(
0cbc2c33 342 msg);
4237f1f2
PP
343}
344
345const struct bt_stream *
346bt_message_discarded_packets_borrow_stream_const(const struct bt_message *message)
347{
348 return (void *) bt_message_discarded_packets_borrow_stream(
349 (void *) message);
350}
351
352enum bt_property_availability bt_message_discarded_packets_get_count(
353 const struct bt_message *message, uint64_t *count)
354{
355 BT_ASSERT_PRE_NON_NULL(message, "Message");
356 BT_ASSERT_PRE_MSG_IS_TYPE(message, BT_MESSAGE_TYPE_DISCARDED_PACKETS);
357 return get_discarded_items_message_count(message, count);
358}
33931ab8
PP
359
360static inline
361const struct bt_clock_class *
362borrow_discarded_items_message_stream_class_default_clock_class(
363 const struct bt_message *msg)
364{
365 struct bt_message_discarded_items *disc_items_msg = (void *) msg;
366
367 BT_ASSERT(msg);
368 return disc_items_msg->stream->class->default_clock_class;
369}
370
371const struct bt_clock_class *
372bt_message_discarded_events_borrow_stream_class_default_clock_class_const(
373 const struct bt_message *msg)
374{
375 BT_ASSERT_PRE_NON_NULL(msg, "Message");
376 BT_ASSERT_PRE_MSG_IS_TYPE(msg, BT_MESSAGE_TYPE_DISCARDED_EVENTS);
377 return borrow_discarded_items_message_stream_class_default_clock_class(
378 msg);
379}
380
381const struct bt_clock_class *
382bt_message_discarded_packets_borrow_stream_class_default_clock_class_const(
383 const struct bt_message *msg)
384{
385 BT_ASSERT_PRE_NON_NULL(msg, "Message");
386 BT_ASSERT_PRE_MSG_IS_TYPE(msg, BT_MESSAGE_TYPE_DISCARDED_PACKETS);
387 return borrow_discarded_items_message_stream_class_default_clock_class(
388 msg);
389}
This page took 0.041791 seconds and 4 git commands to generate.