2 * Copyright 2019 Philippe Proulx <pproulx@efficios.com>
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:
11 * The above copyright notice and this permission notice shall be included in
12 * all copies or substantial portions of the Software.
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
23 #define BT_LOG_TAG "MSG-DISCARDED-ITEMS"
24 #include <babeltrace/lib-logging-internal.h>
26 #include <babeltrace/assert-pre-internal.h>
27 #include <babeltrace/object-internal.h>
28 #include <babeltrace/compiler-internal.h>
29 #include <babeltrace/trace-ir/clock-class.h>
30 #include <babeltrace/trace-ir/clock-snapshot-internal.h>
31 #include <babeltrace/trace-ir/stream-class-internal.h>
32 #include <babeltrace/trace-ir/stream-internal.h>
33 #include <babeltrace/property-internal.h>
34 #include <babeltrace/graph/message-internal.h>
35 #include <babeltrace/graph/message-discarded-items-internal.h>
36 #include <babeltrace/graph/message-discarded-events.h>
37 #include <babeltrace/graph/message-discarded-events-const.h>
38 #include <babeltrace/graph/message-discarded-packets.h>
39 #include <babeltrace/graph/message-discarded-packets-const.h>
42 void destroy_discarded_items_message(struct bt_object
*obj
)
44 struct bt_message_discarded_items
*message
= (void *) obj
;
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
);
50 if (message
->default_begin_cs
) {
51 bt_clock_snapshot_recycle(message
->default_begin_cs
);
52 message
->default_begin_cs
= NULL
;
55 if (message
->default_end_cs
) {
56 bt_clock_snapshot_recycle(message
->default_end_cs
);
57 message
->default_end_cs
= NULL
;
64 struct 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
,
68 uint64_t beginning_raw_value
, uint64_t end_raw_value
)
70 struct bt_message_discarded_items
*message
;
71 struct bt_stream_class
*stream_class
;
73 bool has_default_clock_snapshots
;
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
);
80 if (type
== BT_MESSAGE_TYPE_DISCARDED_EVENTS
) {
81 has_support
= stream_class
->supports_discarded_events
;
82 has_default_clock_snapshots
=
83 stream_class
->discarded_events_have_default_clock_snapshots
;
85 has_support
= stream_class
->supports_discarded_packets
;
86 has_default_clock_snapshots
=
87 stream_class
->discarded_packets_have_default_clock_snapshots
;
90 BT_ASSERT_PRE(has_support
,
91 "Stream class does not support discarded events or packets: "
92 "type=%s, %![stream-]+s, %![sc-]+S",
93 bt_message_type_string(type
), stream
, stream_class
);
94 BT_ASSERT_PRE((with_cs
&& has_default_clock_snapshots
) ||
95 (!with_cs
&& !has_default_clock_snapshots
),
96 "Unexpected stream class configuration when creating "
97 "a discarded events or packets message: "
98 "type=%s, %![stream-]+s, %![sc-]+S, with-cs=%d, "
99 "cs-begin-val=%" PRIu64
", cs-end-val=%" PRIu64
,
100 bt_message_type_string(type
), stream
, stream_class
,
101 with_cs
, beginning_raw_value
, end_raw_value
);
102 BT_LIB_LOGD("Creating discarded items message object: "
103 "type=%s, %![stream-]+s, %![sc-]+S, with-cs=%d, "
104 "cs-begin-val=%" PRIu64
", cs-end-val=%" PRIu64
,
105 bt_message_type_string(type
), stream
, stream_class
,
106 with_cs
, beginning_raw_value
, end_raw_value
);
107 message
= g_new0(struct bt_message_discarded_items
, 1);
109 BT_LOGE_STR("Failed to allocate one discarded items message.");
113 bt_message_init(&message
->parent
, type
,
114 destroy_discarded_items_message
, NULL
);
115 message
->stream
= stream
;
116 bt_object_get_no_null_check(message
->stream
);
119 BT_ASSERT(stream_class
->default_clock_class
);
120 message
->default_begin_cs
= bt_clock_snapshot_create(
121 stream_class
->default_clock_class
);
122 if (!message
->default_begin_cs
) {
126 bt_clock_snapshot_set_raw_value(message
->default_begin_cs
,
127 beginning_raw_value
);
129 message
->default_end_cs
= bt_clock_snapshot_create(
130 stream_class
->default_clock_class
);
131 if (!message
->default_end_cs
) {
135 bt_clock_snapshot_set_raw_value(message
->default_end_cs
,
139 bt_property_uint_init(&message
->count
,
140 BT_PROPERTY_AVAILABILITY_NOT_AVAILABLE
, 0);
141 BT_LIB_LOGD("Created discarded items message object: "
142 "%![msg-]+n, %![stream-]+s, %![sc-]+S", message
,
143 stream
, stream_class
);
145 return (void *) &message
->parent
;
152 struct bt_stream
*borrow_discarded_items_message_stream(
153 struct bt_message
*message
)
155 struct bt_message_discarded_items
*disc_items_msg
= (void *) message
;
158 return disc_items_msg
->stream
;
162 void set_discarded_items_message_count(struct bt_message
*message
,
165 struct bt_message_discarded_items
*disc_items_msg
= (void *) message
;
168 BT_ASSERT_PRE_HOT(message
, "Message", ": %!+n", message
);
169 bt_property_uint_set(&disc_items_msg
->count
, count
);
173 enum bt_property_availability
get_discarded_items_message_count(
174 const struct bt_message
*message
, uint64_t *count
)
176 struct bt_message_discarded_items
*disc_items_msg
= (void *) message
;
178 BT_ASSERT_PRE_NON_NULL(count
, "Count (output)");
180 *count
= disc_items_msg
->count
.value
;
181 return disc_items_msg
->count
.base
.avail
;
185 const struct bt_clock_snapshot
*
186 borrow_discarded_items_message_default_beginning_clock_snapshot_const(
187 const struct bt_message
*message
)
189 struct bt_message_discarded_items
*disc_items_msg
= (void *) message
;
192 BT_ASSERT_PRE(disc_items_msg
->stream
->class->default_clock_class
,
193 "Message's stream's class has no default clock class: "
194 "%![msg-]+n, %![sc-]+S",
195 message
, disc_items_msg
->stream
->class);
196 return disc_items_msg
->default_begin_cs
;
200 const struct bt_clock_snapshot
*
201 borrow_discarded_items_message_default_end_clock_snapshot_const(
202 const struct bt_message
*message
)
204 struct bt_message_discarded_items
*disc_items_msg
= (void *) message
;
207 BT_ASSERT_PRE(disc_items_msg
->stream
->class->default_clock_class
,
208 "Message's stream's class has no default clock class: "
209 "%![msg-]+n, %![sc-]+S",
210 message
, disc_items_msg
->stream
->class);
211 return disc_items_msg
->default_end_cs
;
214 struct bt_message
*bt_message_discarded_events_create(
215 struct bt_self_message_iterator
*message_iterator
,
216 const struct bt_stream
*stream
)
218 return create_discarded_items_message(message_iterator
,
219 BT_MESSAGE_TYPE_DISCARDED_EVENTS
, (void *) stream
,
223 struct bt_message
*bt_message_discarded_events_create_with_default_clock_snapshots(
224 struct bt_self_message_iterator
*message_iterator
,
225 const struct bt_stream
*stream
, uint64_t beginning_raw_value
,
226 uint64_t end_raw_value
)
228 return create_discarded_items_message(message_iterator
,
229 BT_MESSAGE_TYPE_DISCARDED_EVENTS
, (void *) stream
,
230 true, beginning_raw_value
, end_raw_value
);
233 struct bt_stream
*bt_message_discarded_events_borrow_stream(
234 struct bt_message
*message
)
236 BT_ASSERT_PRE_NON_NULL(message
, "Message");
237 BT_ASSERT_PRE_MSG_IS_TYPE(message
, BT_MESSAGE_TYPE_DISCARDED_EVENTS
);
238 return borrow_discarded_items_message_stream(message
);
241 void bt_message_discarded_events_set_count(struct bt_message
*message
,
244 BT_ASSERT_PRE_NON_NULL(message
, "Message");
245 BT_ASSERT_PRE_MSG_IS_TYPE(message
, BT_MESSAGE_TYPE_DISCARDED_EVENTS
);
246 set_discarded_items_message_count(message
, count
);
249 const struct bt_clock_snapshot
*
250 bt_message_discarded_events_borrow_default_beginning_clock_snapshot_const(
251 const struct bt_message
*msg
)
253 BT_ASSERT_PRE_NON_NULL(msg
, "Message");
254 BT_ASSERT_PRE_MSG_IS_TYPE(msg
, BT_MESSAGE_TYPE_DISCARDED_EVENTS
);
255 return borrow_discarded_items_message_default_beginning_clock_snapshot_const(
259 const struct bt_clock_snapshot
*
260 bt_message_discarded_events_borrow_default_end_clock_snapshot_const(
261 const struct bt_message
*msg
)
263 BT_ASSERT_PRE_NON_NULL(msg
, "Message");
264 BT_ASSERT_PRE_MSG_IS_TYPE(msg
, BT_MESSAGE_TYPE_DISCARDED_EVENTS
);
265 return borrow_discarded_items_message_default_end_clock_snapshot_const(
269 const struct bt_stream
*
270 bt_message_discarded_events_borrow_stream_const(const struct bt_message
*message
)
272 return (void *) bt_message_discarded_events_borrow_stream(
276 enum bt_property_availability
bt_message_discarded_events_get_count(
277 const struct bt_message
*message
, uint64_t *count
)
279 BT_ASSERT_PRE_NON_NULL(message
, "Message");
280 BT_ASSERT_PRE_MSG_IS_TYPE(message
, BT_MESSAGE_TYPE_DISCARDED_EVENTS
);
281 return get_discarded_items_message_count(message
, count
);
284 struct bt_message
*bt_message_discarded_packets_create(
285 struct bt_self_message_iterator
*message_iterator
,
286 const struct bt_stream
*stream
)
288 return create_discarded_items_message(message_iterator
,
289 BT_MESSAGE_TYPE_DISCARDED_PACKETS
, (void *) stream
,
293 struct bt_message
*bt_message_discarded_packets_create_with_default_clock_snapshots(
294 struct bt_self_message_iterator
*message_iterator
,
295 const struct bt_stream
*stream
, uint64_t beginning_raw_value
,
296 uint64_t end_raw_value
)
298 return create_discarded_items_message(message_iterator
,
299 BT_MESSAGE_TYPE_DISCARDED_PACKETS
, (void *) stream
,
300 true, beginning_raw_value
, end_raw_value
);
303 struct bt_stream
*bt_message_discarded_packets_borrow_stream(
304 struct bt_message
*message
)
306 BT_ASSERT_PRE_NON_NULL(message
, "Message");
307 BT_ASSERT_PRE_MSG_IS_TYPE(message
, BT_MESSAGE_TYPE_DISCARDED_PACKETS
);
308 return borrow_discarded_items_message_stream(message
);
311 void bt_message_discarded_packets_set_count(struct bt_message
*message
,
314 BT_ASSERT_PRE_NON_NULL(message
, "Message");
315 BT_ASSERT_PRE_MSG_IS_TYPE(message
, BT_MESSAGE_TYPE_DISCARDED_PACKETS
);
316 set_discarded_items_message_count(message
, count
);
319 const struct bt_clock_snapshot
*
320 bt_message_discarded_packets_borrow_default_beginning_clock_snapshot_const(
321 const struct bt_message
*msg
)
323 BT_ASSERT_PRE_NON_NULL(msg
, "Message");
324 BT_ASSERT_PRE_MSG_IS_TYPE(msg
, BT_MESSAGE_TYPE_DISCARDED_PACKETS
);
325 return borrow_discarded_items_message_default_beginning_clock_snapshot_const(
329 const struct bt_clock_snapshot
*
330 bt_message_discarded_packets_borrow_default_end_clock_snapshot_const(
331 const struct bt_message
*msg
)
333 BT_ASSERT_PRE_NON_NULL(msg
, "Message");
334 BT_ASSERT_PRE_MSG_IS_TYPE(msg
, BT_MESSAGE_TYPE_DISCARDED_PACKETS
);
335 return borrow_discarded_items_message_default_end_clock_snapshot_const(
339 const struct bt_stream
*
340 bt_message_discarded_packets_borrow_stream_const(const struct bt_message
*message
)
342 return (void *) bt_message_discarded_packets_borrow_stream(
346 enum bt_property_availability
bt_message_discarded_packets_get_count(
347 const struct bt_message
*message
, uint64_t *count
)
349 BT_ASSERT_PRE_NON_NULL(message
, "Message");
350 BT_ASSERT_PRE_MSG_IS_TYPE(message
, BT_MESSAGE_TYPE_DISCARDED_PACKETS
);
351 return get_discarded_items_message_count(message
, count
);
355 const struct bt_clock_class
*
356 borrow_discarded_items_message_stream_class_default_clock_class(
357 const struct bt_message
*msg
)
359 struct bt_message_discarded_items
*disc_items_msg
= (void *) msg
;
362 return disc_items_msg
->stream
->class->default_clock_class
;
365 const struct bt_clock_class
*
366 bt_message_discarded_events_borrow_stream_class_default_clock_class_const(
367 const struct bt_message
*msg
)
369 BT_ASSERT_PRE_NON_NULL(msg
, "Message");
370 BT_ASSERT_PRE_MSG_IS_TYPE(msg
, BT_MESSAGE_TYPE_DISCARDED_EVENTS
);
371 return borrow_discarded_items_message_stream_class_default_clock_class(
375 const struct bt_clock_class
*
376 bt_message_discarded_packets_borrow_stream_class_default_clock_class_const(
377 const struct bt_message
*msg
)
379 BT_ASSERT_PRE_NON_NULL(msg
, "Message");
380 BT_ASSERT_PRE_MSG_IS_TYPE(msg
, BT_MESSAGE_TYPE_DISCARDED_PACKETS
);
381 return borrow_discarded_items_message_stream_class_default_clock_class(