Commit | Line | Data |
---|---|---|
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 | |
41 | static | |
42 | void 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 | ||
63 | static inline | |
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, | |
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 PP |
72 | bool has_support; |
73 | bool has_default_clock_snapshots; | |
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; | |
82 | has_default_clock_snapshots = | |
83 | stream_class->discarded_events_have_default_clock_snapshots; | |
84 | } else { | |
85 | has_support = stream_class->supports_discarded_packets; | |
86 | has_default_clock_snapshots = | |
87 | stream_class->discarded_packets_have_default_clock_snapshots; | |
88 | } | |
89 | ||
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: " | |
aa12059b PP |
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); | |
4c833281 PP |
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); | |
108 | if (!message) { | |
109 | BT_LOGE_STR("Failed to allocate one discarded items message."); | |
110 | goto error; | |
111 | } | |
112 | ||
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); | |
117 | ||
118 | if (with_cs) { | |
aa12059b | 119 | BT_ASSERT(stream_class->default_clock_class); |
4c833281 PP |
120 | message->default_begin_cs = bt_clock_snapshot_create( |
121 | stream_class->default_clock_class); | |
122 | if (!message->default_begin_cs) { | |
123 | goto error; | |
124 | } | |
125 | ||
126 | bt_clock_snapshot_set_raw_value(message->default_begin_cs, | |
127 | beginning_raw_value); | |
128 | ||
129 | message->default_end_cs = bt_clock_snapshot_create( | |
130 | stream_class->default_clock_class); | |
131 | if (!message->default_end_cs) { | |
132 | goto error; | |
133 | } | |
134 | ||
135 | bt_clock_snapshot_set_raw_value(message->default_end_cs, | |
136 | end_raw_value); | |
137 | } | |
138 | ||
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); | |
144 | ||
145 | return (void *) &message->parent; | |
146 | ||
147 | error: | |
148 | return NULL; | |
149 | } | |
150 | ||
151 | static inline | |
152 | struct bt_stream *borrow_discarded_items_message_stream( | |
153 | struct bt_message *message) | |
154 | { | |
155 | struct bt_message_discarded_items *disc_items_msg = (void *) message; | |
156 | ||
157 | BT_ASSERT(message); | |
158 | return disc_items_msg->stream; | |
159 | } | |
160 | ||
161 | static inline | |
162 | void set_discarded_items_message_count(struct bt_message *message, | |
163 | uint64_t count) | |
164 | { | |
165 | struct bt_message_discarded_items *disc_items_msg = (void *) message; | |
166 | ||
167 | BT_ASSERT(message); | |
168 | BT_ASSERT_PRE_HOT(message, "Message", ": %!+n", message); | |
169 | bt_property_uint_set(&disc_items_msg->count, count); | |
170 | } | |
171 | ||
172 | static inline | |
173 | enum bt_property_availability get_discarded_items_message_count( | |
174 | const struct bt_message *message, uint64_t *count) | |
175 | { | |
176 | struct bt_message_discarded_items *disc_items_msg = (void *) message; | |
177 | ||
178 | BT_ASSERT_PRE_NON_NULL(count, "Count (output)"); | |
179 | BT_ASSERT(message); | |
180 | *count = disc_items_msg->count.value; | |
181 | return disc_items_msg->count.base.avail; | |
182 | } | |
183 | ||
184 | static inline | |
0cbc2c33 | 185 | const struct bt_clock_snapshot * |
9b24b6aa | 186 | borrow_discarded_items_message_beginning_default_clock_snapshot_const( |
0cbc2c33 | 187 | const struct bt_message *message) |
4c833281 PP |
188 | { |
189 | struct bt_message_discarded_items *disc_items_msg = (void *) message; | |
190 | ||
191 | BT_ASSERT(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); | |
0cbc2c33 | 196 | return disc_items_msg->default_begin_cs; |
4c833281 PP |
197 | } |
198 | ||
199 | static inline | |
0cbc2c33 | 200 | const struct bt_clock_snapshot * |
9b24b6aa | 201 | borrow_discarded_items_message_end_default_clock_snapshot_const( |
0cbc2c33 | 202 | const struct bt_message *message) |
4c833281 PP |
203 | { |
204 | struct bt_message_discarded_items *disc_items_msg = (void *) message; | |
205 | ||
206 | BT_ASSERT(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); | |
0cbc2c33 | 211 | return disc_items_msg->default_end_cs; |
4c833281 PP |
212 | } |
213 | ||
214 | struct bt_message *bt_message_discarded_events_create( | |
215 | struct bt_self_message_iterator *message_iterator, | |
58085ca4 | 216 | const struct bt_stream *stream) |
4c833281 PP |
217 | { |
218 | return create_discarded_items_message(message_iterator, | |
58085ca4 | 219 | BT_MESSAGE_TYPE_DISCARDED_EVENTS, (void *) stream, |
4c833281 PP |
220 | false, 0, 0); |
221 | } | |
222 | ||
223 | struct bt_message *bt_message_discarded_events_create_with_default_clock_snapshots( | |
224 | struct bt_self_message_iterator *message_iterator, | |
58085ca4 | 225 | const struct bt_stream *stream, uint64_t beginning_raw_value, |
4c833281 PP |
226 | uint64_t end_raw_value) |
227 | { | |
228 | return create_discarded_items_message(message_iterator, | |
58085ca4 | 229 | BT_MESSAGE_TYPE_DISCARDED_EVENTS, (void *) stream, |
4c833281 PP |
230 | true, beginning_raw_value, end_raw_value); |
231 | } | |
232 | ||
233 | struct bt_stream *bt_message_discarded_events_borrow_stream( | |
234 | struct bt_message *message) | |
235 | { | |
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); | |
239 | } | |
240 | ||
241 | void bt_message_discarded_events_set_count(struct bt_message *message, | |
242 | uint64_t count) | |
243 | { | |
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); | |
247 | } | |
248 | ||
0cbc2c33 | 249 | const struct bt_clock_snapshot * |
9b24b6aa | 250 | bt_message_discarded_events_borrow_beginning_default_clock_snapshot_const( |
0cbc2c33 | 251 | const struct bt_message *msg) |
4c833281 PP |
252 | { |
253 | BT_ASSERT_PRE_NON_NULL(msg, "Message"); | |
254 | BT_ASSERT_PRE_MSG_IS_TYPE(msg, BT_MESSAGE_TYPE_DISCARDED_EVENTS); | |
9b24b6aa | 255 | return borrow_discarded_items_message_beginning_default_clock_snapshot_const( |
0cbc2c33 | 256 | msg); |
4c833281 PP |
257 | } |
258 | ||
0cbc2c33 | 259 | const struct bt_clock_snapshot * |
9b24b6aa | 260 | bt_message_discarded_events_borrow_end_default_clock_snapshot_const( |
0cbc2c33 | 261 | const struct bt_message *msg) |
4c833281 PP |
262 | { |
263 | BT_ASSERT_PRE_NON_NULL(msg, "Message"); | |
264 | BT_ASSERT_PRE_MSG_IS_TYPE(msg, BT_MESSAGE_TYPE_DISCARDED_EVENTS); | |
9b24b6aa | 265 | return borrow_discarded_items_message_end_default_clock_snapshot_const( |
0cbc2c33 | 266 | msg); |
4c833281 PP |
267 | } |
268 | ||
269 | const struct bt_stream * | |
270 | bt_message_discarded_events_borrow_stream_const(const struct bt_message *message) | |
271 | { | |
272 | return (void *) bt_message_discarded_events_borrow_stream( | |
273 | (void *) message); | |
274 | } | |
275 | ||
276 | enum bt_property_availability bt_message_discarded_events_get_count( | |
277 | const struct bt_message *message, uint64_t *count) | |
278 | { | |
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); | |
282 | } | |
4237f1f2 PP |
283 | |
284 | struct bt_message *bt_message_discarded_packets_create( | |
285 | struct bt_self_message_iterator *message_iterator, | |
58085ca4 | 286 | const struct bt_stream *stream) |
4237f1f2 PP |
287 | { |
288 | return create_discarded_items_message(message_iterator, | |
58085ca4 | 289 | BT_MESSAGE_TYPE_DISCARDED_PACKETS, (void *) stream, |
4237f1f2 PP |
290 | false, 0, 0); |
291 | } | |
292 | ||
293 | struct bt_message *bt_message_discarded_packets_create_with_default_clock_snapshots( | |
294 | struct bt_self_message_iterator *message_iterator, | |
58085ca4 | 295 | const struct bt_stream *stream, uint64_t beginning_raw_value, |
4237f1f2 PP |
296 | uint64_t end_raw_value) |
297 | { | |
298 | return create_discarded_items_message(message_iterator, | |
58085ca4 | 299 | BT_MESSAGE_TYPE_DISCARDED_PACKETS, (void *) stream, |
4237f1f2 PP |
300 | true, beginning_raw_value, end_raw_value); |
301 | } | |
302 | ||
303 | struct bt_stream *bt_message_discarded_packets_borrow_stream( | |
304 | struct bt_message *message) | |
305 | { | |
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); | |
309 | } | |
310 | ||
311 | void bt_message_discarded_packets_set_count(struct bt_message *message, | |
312 | uint64_t count) | |
313 | { | |
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); | |
317 | } | |
318 | ||
0cbc2c33 | 319 | const struct bt_clock_snapshot * |
9b24b6aa | 320 | bt_message_discarded_packets_borrow_beginning_default_clock_snapshot_const( |
0cbc2c33 | 321 | const struct bt_message *msg) |
4237f1f2 PP |
322 | { |
323 | BT_ASSERT_PRE_NON_NULL(msg, "Message"); | |
324 | BT_ASSERT_PRE_MSG_IS_TYPE(msg, BT_MESSAGE_TYPE_DISCARDED_PACKETS); | |
9b24b6aa | 325 | return borrow_discarded_items_message_beginning_default_clock_snapshot_const( |
0cbc2c33 | 326 | msg); |
4237f1f2 PP |
327 | } |
328 | ||
0cbc2c33 | 329 | const struct bt_clock_snapshot * |
9b24b6aa | 330 | bt_message_discarded_packets_borrow_end_default_clock_snapshot_const( |
0cbc2c33 | 331 | const struct bt_message *msg) |
4237f1f2 PP |
332 | { |
333 | BT_ASSERT_PRE_NON_NULL(msg, "Message"); | |
334 | BT_ASSERT_PRE_MSG_IS_TYPE(msg, BT_MESSAGE_TYPE_DISCARDED_PACKETS); | |
9b24b6aa | 335 | return borrow_discarded_items_message_end_default_clock_snapshot_const( |
0cbc2c33 | 336 | msg); |
4237f1f2 PP |
337 | } |
338 | ||
339 | const struct bt_stream * | |
340 | bt_message_discarded_packets_borrow_stream_const(const struct bt_message *message) | |
341 | { | |
342 | return (void *) bt_message_discarded_packets_borrow_stream( | |
343 | (void *) message); | |
344 | } | |
345 | ||
346 | enum bt_property_availability bt_message_discarded_packets_get_count( | |
347 | const struct bt_message *message, uint64_t *count) | |
348 | { | |
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); | |
352 | } | |
33931ab8 PP |
353 | |
354 | static inline | |
355 | const struct bt_clock_class * | |
356 | borrow_discarded_items_message_stream_class_default_clock_class( | |
357 | const struct bt_message *msg) | |
358 | { | |
359 | struct bt_message_discarded_items *disc_items_msg = (void *) msg; | |
360 | ||
361 | BT_ASSERT(msg); | |
362 | return disc_items_msg->stream->class->default_clock_class; | |
363 | } | |
364 | ||
365 | const struct bt_clock_class * | |
366 | bt_message_discarded_events_borrow_stream_class_default_clock_class_const( | |
367 | const struct bt_message *msg) | |
368 | { | |
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( | |
372 | msg); | |
373 | } | |
374 | ||
375 | const struct bt_clock_class * | |
376 | bt_message_discarded_packets_borrow_stream_class_default_clock_class_const( | |
377 | const struct bt_message *msg) | |
378 | { | |
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( | |
382 | msg); | |
383 | } |