Add bt_common_abort() and use it instead of abort() directly
[babeltrace.git] / src / plugins / common / muxing / muxing.c
1 /*
2 * Copyright 2019 Francis Deslauriers <francis.deslauriers@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 #include <babeltrace2/babeltrace.h>
24
25 #include <inttypes.h>
26 #include <stdlib.h>
27 #include <string.h>
28
29 #include "common/assert.h"
30 #include "common/common.h"
31 #include "common/macros.h"
32 #include "common/uuid.h"
33
34 #include "muxing.h"
35
36 struct message_to_compare {
37 const bt_message *msg;
38 const bt_trace *trace;
39 const bt_stream *stream;
40 };
41
42 struct messages_to_compare {
43 struct message_to_compare left;
44 struct message_to_compare right;
45 };
46
47 static
48 int message_type_weight(const bt_message_type msg_type)
49 {
50 int weight;
51
52 switch (msg_type) {
53 case BT_MESSAGE_TYPE_STREAM_BEGINNING:
54 weight = 7;
55 break;
56 case BT_MESSAGE_TYPE_PACKET_BEGINNING:
57 weight = 6;
58 break;
59 case BT_MESSAGE_TYPE_EVENT:
60 weight = 5;
61 break;
62 case BT_MESSAGE_TYPE_DISCARDED_EVENTS:
63 weight = 4;
64 break;
65 case BT_MESSAGE_TYPE_PACKET_END:
66 weight = 3;
67 break;
68 case BT_MESSAGE_TYPE_MESSAGE_ITERATOR_INACTIVITY:
69 weight = 2;
70 break;
71 case BT_MESSAGE_TYPE_DISCARDED_PACKETS:
72 weight = 1;
73 break;
74 case BT_MESSAGE_TYPE_STREAM_END:
75 weight = 0;
76 break;
77 default:
78 bt_common_abort();
79 }
80
81 return weight;
82 }
83
84 /*
85 * Compare 2 messages to order them in a determinitic way based on their
86 * types.
87 * Returns -1 is left mesage must go first
88 * Returns 1 is right mesage must go first
89 */
90 static
91 int compare_messages_by_type(struct messages_to_compare *msgs)
92 {
93 bt_message_type left_msg_type = bt_message_get_type(msgs->left.msg);
94 bt_message_type right_msg_type = bt_message_get_type(msgs->right.msg);
95
96 return message_type_weight(right_msg_type) -
97 message_type_weight(left_msg_type);
98 }
99
100 static
101 int compare_events(const bt_event *left_event, const bt_event *right_event)
102 {
103 int ret = 0;
104 const bt_event_class *left_event_class, *right_event_class;
105 uint64_t left_event_class_id, right_event_class_id;
106 const char *left_event_class_name, *right_event_class_name,
107 *left_event_class_emf_uri, *right_event_class_emf_uri;
108 bt_event_class_log_level left_event_class_log_level, right_event_class_log_level;
109 bt_property_availability left_log_level_avail, right_log_level_avail;
110
111 left_event_class = bt_event_borrow_class_const(left_event);
112 right_event_class = bt_event_borrow_class_const(right_event);
113
114 left_event_class_id = bt_event_class_get_id(left_event_class);
115 right_event_class_id = bt_event_class_get_id(right_event_class);
116
117 if (left_event_class_id > right_event_class_id) {
118 ret = 1;
119 goto end;
120 } else if (left_event_class_id < right_event_class_id) {
121 ret = -1;
122 goto end;
123 }
124
125 left_event_class_name = bt_event_class_get_name(left_event_class);
126 right_event_class_name = bt_event_class_get_name(right_event_class);
127 if (left_event_class_name && right_event_class_name) {
128 ret = strcmp(left_event_class_name, right_event_class_name);
129 if (ret != 0) {
130 goto end;
131 }
132 } else if (!left_event_class_name && right_event_class_name) {
133 ret = -1;
134 goto end;
135 } else if (left_event_class_name && !right_event_class_name) {
136 ret = 1;
137 goto end;
138 }
139
140 left_log_level_avail = bt_event_class_get_log_level(left_event_class,
141 &left_event_class_log_level);
142 right_log_level_avail = bt_event_class_get_log_level(right_event_class,
143 &right_event_class_log_level);
144
145 if (left_log_level_avail == BT_PROPERTY_AVAILABILITY_AVAILABLE &&
146 right_log_level_avail == BT_PROPERTY_AVAILABILITY_AVAILABLE) {
147 ret = left_event_class_log_level - right_event_class_log_level;
148 if (ret) {
149 goto end;
150 }
151 } else if (left_log_level_avail == BT_PROPERTY_AVAILABILITY_AVAILABLE &&
152 right_log_level_avail == BT_PROPERTY_AVAILABILITY_NOT_AVAILABLE) {
153 ret = -1;
154 goto end;
155 } else if (left_log_level_avail == BT_PROPERTY_AVAILABILITY_NOT_AVAILABLE &&
156 right_log_level_avail == BT_PROPERTY_AVAILABILITY_AVAILABLE) {
157 ret = 1;
158 goto end;
159 }
160
161 left_event_class_emf_uri = bt_event_class_get_emf_uri(left_event_class);
162 right_event_class_emf_uri = bt_event_class_get_emf_uri(right_event_class);
163 if (left_event_class_emf_uri && right_event_class_emf_uri) {
164 ret = strcmp(left_event_class_emf_uri, right_event_class_emf_uri);
165 if (ret != 0) {
166 goto end;
167 }
168 } else if (!left_event_class_emf_uri && right_event_class_emf_uri) {
169 ret = -1;
170 goto end;
171 } else if (left_event_class_emf_uri && !right_event_class_emf_uri) {
172 ret = 1;
173 goto end;
174 }
175
176 end:
177 return ret;
178 }
179
180 static
181 int compare_streams(const bt_stream *left_stream, const bt_stream *right_stream)
182 {
183 int ret = 0;
184 const char *left_stream_name, *right_stream_name,
185 *left_stream_class_name, *right_stream_class_name;
186 const bt_stream_class *left_stream_class, *right_stream_class;
187
188 /*
189 * No need to compare stream id as it was checked earlier and if we are
190 * here it means they are identical or both absent.
191 */
192 BT_ASSERT(bt_stream_get_id(left_stream) ==
193 bt_stream_get_id(right_stream));
194
195 /* Compare stream name. */
196 left_stream_name = bt_stream_get_name(left_stream);
197 right_stream_name = bt_stream_get_name(right_stream);
198
199 if (left_stream_name && right_stream_name) {
200 ret = strcmp(left_stream_name, right_stream_name);
201 if (ret != 0) {
202 goto end;
203 }
204 } else if (!left_stream_name && right_stream_name) {
205 ret = -1;
206 goto end;
207 } else if (left_stream_name && !right_stream_name) {
208 ret = 1;
209 goto end;
210 }
211
212 left_stream_class = bt_stream_borrow_class_const(left_stream);
213 right_stream_class = bt_stream_borrow_class_const(right_stream);
214
215 /*
216 * No need to compare stream class id as it was checked earlier and if
217 * we are here it means they are identical.
218 */
219 BT_ASSERT(bt_stream_class_get_id(left_stream_class) ==
220 bt_stream_class_get_id(right_stream_class));
221
222 /* Compare stream class name. */
223 left_stream_class_name = bt_stream_class_get_name(left_stream_class);
224 right_stream_class_name = bt_stream_class_get_name(right_stream_class);
225
226 if (left_stream_class_name && right_stream_class_name) {
227 ret = strcmp(left_stream_class_name, right_stream_class_name);
228 if (ret != 0) {
229 goto end;
230 }
231 } else if (!left_stream_class_name && right_stream_class_name) {
232 ret = -1;
233 goto end;
234 } else if (left_stream_class_name && !right_stream_class_name) {
235 ret = 1;
236 goto end;
237 }
238
239 /* Compare stream class automatic event class id assignment. */
240 if (bt_stream_class_assigns_automatic_event_class_id(left_stream_class) &&
241 !bt_stream_class_assigns_automatic_event_class_id(right_stream_class)) {
242 ret = 1;
243 goto end;
244 } else if (!bt_stream_class_assigns_automatic_event_class_id(left_stream_class) &&
245 bt_stream_class_assigns_automatic_event_class_id(right_stream_class)) {
246 ret = -1;
247 goto end;
248 }
249
250 /* Compare stream class automatic stream id assignment. */
251 if (bt_stream_class_assigns_automatic_stream_id(left_stream_class) &&
252 !bt_stream_class_assigns_automatic_stream_id(right_stream_class)) {
253 ret = 1;
254 goto end;
255 } else if (!bt_stream_class_assigns_automatic_stream_id(left_stream_class) &&
256 bt_stream_class_assigns_automatic_stream_id(right_stream_class)) {
257 ret = -1;
258 goto end;
259 }
260
261 /* Compare stream class support of discarded events. */
262 if (bt_stream_class_supports_discarded_events(left_stream_class) &&
263 !bt_stream_class_supports_discarded_events(right_stream_class)) {
264 ret = 1;
265 goto end;
266 } else if (!bt_stream_class_supports_discarded_events(left_stream_class) &&
267 bt_stream_class_supports_discarded_events(right_stream_class)) {
268 ret = -1;
269 goto end;
270 }
271
272 /* Compare stream class discarded events default clock snapshot. */
273 if (bt_stream_class_discarded_events_have_default_clock_snapshots(left_stream_class) &&
274 !bt_stream_class_discarded_events_have_default_clock_snapshots(right_stream_class)) {
275 ret = 1;
276 goto end;
277 } else if (!bt_stream_class_discarded_events_have_default_clock_snapshots(left_stream_class) &&
278 bt_stream_class_discarded_events_have_default_clock_snapshots(right_stream_class)) {
279 ret = -1;
280 goto end;
281 }
282
283 /* Compare stream class support of packets. */
284 if (bt_stream_class_supports_packets(left_stream_class) &&
285 !bt_stream_class_supports_packets(right_stream_class)) {
286 ret = 1;
287 goto end;
288 } else if (!bt_stream_class_supports_packets(left_stream_class) &&
289 bt_stream_class_supports_packets(right_stream_class)) {
290 ret = -1;
291 goto end;
292 }
293
294 if (!bt_stream_class_supports_packets(left_stream_class)) {
295 /* Skip all packet related checks. */
296 goto end;
297 }
298
299 /*
300 * Compare stream class presence of discarded packets beginning default
301 * clock snapshot.
302 */
303 if (bt_stream_class_packets_have_beginning_default_clock_snapshot(left_stream_class) &&
304 !bt_stream_class_packets_have_beginning_default_clock_snapshot(right_stream_class)) {
305 ret = 1;
306 goto end;
307 } else if (!bt_stream_class_packets_have_beginning_default_clock_snapshot(left_stream_class) &&
308 bt_stream_class_packets_have_beginning_default_clock_snapshot(right_stream_class)) {
309 ret = -1;
310 goto end;
311 }
312
313 /*
314 * Compare stream class presence of discarded packets end default clock
315 * snapshot.
316 */
317 if (bt_stream_class_packets_have_end_default_clock_snapshot(left_stream_class) &&
318 !bt_stream_class_packets_have_end_default_clock_snapshot(right_stream_class)) {
319 ret = 1;
320 goto end;
321 } else if (!bt_stream_class_packets_have_end_default_clock_snapshot(left_stream_class) &&
322 bt_stream_class_packets_have_end_default_clock_snapshot(right_stream_class)) {
323 ret = -1;
324 goto end;
325 }
326
327 /* Compare stream class support of discarded packets. */
328 if (bt_stream_class_supports_discarded_packets(left_stream_class) &&
329 !bt_stream_class_supports_discarded_packets(right_stream_class)) {
330 ret = 1;
331 goto end;
332 } else if (!bt_stream_class_supports_discarded_packets(left_stream_class) &&
333 bt_stream_class_supports_discarded_packets(right_stream_class)) {
334 ret = -1;
335 goto end;
336 }
337
338 /* Compare stream class discarded packets default clock snapshot. */
339 if (bt_stream_class_discarded_packets_have_default_clock_snapshots(left_stream_class) &&
340 !bt_stream_class_discarded_packets_have_default_clock_snapshots(right_stream_class)) {
341 ret = 1;
342 goto end;
343 } else if (!bt_stream_class_discarded_packets_have_default_clock_snapshots(left_stream_class) &&
344 bt_stream_class_discarded_packets_have_default_clock_snapshots(right_stream_class)) {
345 ret = -1;
346 goto end;
347 }
348
349 end:
350 return ret;
351 }
352
353 static
354 int compare_clock_snapshots_and_clock_classes(const bt_clock_snapshot *left_cs,
355 const bt_clock_snapshot *right_cs)
356 {
357 int ret;
358 uint64_t left_freq, right_freq, left_prec, right_prec;
359 uint64_t left_cs_value, right_cs_value;
360 const bt_clock_class *left_clock_class, *right_clock_class;
361 const char *left_clock_class_name, *right_clock_class_name;
362 left_cs_value = bt_clock_snapshot_get_value(left_cs);
363 right_cs_value = bt_clock_snapshot_get_value(right_cs);
364 bt_uuid left_clock_class_uuid, right_clock_class_uuid;
365
366 ret = left_cs_value - right_cs_value;
367 if (ret != 0) {
368 goto end;
369 }
370
371 left_clock_class = bt_clock_snapshot_borrow_clock_class_const(left_cs);
372 right_clock_class = bt_clock_snapshot_borrow_clock_class_const(right_cs);
373
374 left_clock_class_uuid = bt_clock_class_get_uuid(left_clock_class);
375 right_clock_class_uuid = bt_clock_class_get_uuid(right_clock_class);
376
377 if (left_clock_class_uuid && !right_clock_class_uuid) {
378 ret = -1;
379 goto end;
380 } else if (!left_clock_class_uuid && right_clock_class_uuid) {
381 ret = 1;
382 goto end;
383 } else if (left_clock_class_uuid && right_clock_class_uuid) {
384 ret = bt_uuid_compare(left_clock_class_uuid,
385 right_clock_class_uuid);
386 if (ret != 0) {
387 goto end;
388 }
389 }
390
391
392 left_clock_class_name = bt_clock_class_get_name(left_clock_class);
393 right_clock_class_name = bt_clock_class_get_name(right_clock_class);
394
395 if (left_clock_class_name && !right_clock_class_name) {
396 ret = -1;
397 goto end;
398 } else if (!left_clock_class_name && right_clock_class_name) {
399 ret = 1;
400 goto end;
401 } else if (left_clock_class_name && right_clock_class_name) {
402 ret = strcmp(left_clock_class_name, right_clock_class_name);
403 if (ret != 0) {
404 goto end;
405 }
406 }
407
408 left_freq = bt_clock_class_get_frequency(left_clock_class);
409 right_freq = bt_clock_class_get_frequency(right_clock_class);
410
411 ret = right_freq - left_freq;
412 if (ret != 0) {
413 goto end;
414 }
415
416 left_prec = bt_clock_class_get_precision(left_clock_class);
417 right_prec = bt_clock_class_get_precision(right_clock_class);
418
419 ret = right_prec - left_prec;
420 if (ret != 0) {
421 goto end;
422 }
423
424 end:
425 return ret;
426 }
427
428 static
429 const bt_stream *borrow_stream(const bt_message *msg)
430 {
431 bt_message_type msg_type = bt_message_get_type(msg);
432 const bt_stream *stream = NULL;
433 const bt_packet *packet = NULL;
434 const bt_event *event = NULL;
435
436 switch (msg_type) {
437 case BT_MESSAGE_TYPE_STREAM_BEGINNING:
438 stream = bt_message_stream_beginning_borrow_stream_const(msg);
439 break;
440 case BT_MESSAGE_TYPE_STREAM_END:
441 stream = bt_message_stream_end_borrow_stream_const(msg);
442 break;
443 case BT_MESSAGE_TYPE_PACKET_BEGINNING:
444 packet = bt_message_packet_beginning_borrow_packet_const(msg);
445 stream = bt_packet_borrow_stream_const(packet);
446 break;
447 case BT_MESSAGE_TYPE_PACKET_END:
448 packet = bt_message_packet_end_borrow_packet_const(msg);
449 stream = bt_packet_borrow_stream_const(packet);
450 break;
451 case BT_MESSAGE_TYPE_EVENT:
452 event = bt_message_event_borrow_event_const(msg);
453 stream = bt_event_borrow_stream_const(event);
454 break;
455 case BT_MESSAGE_TYPE_DISCARDED_EVENTS:
456 stream = bt_message_discarded_events_borrow_stream_const(msg);
457 break;
458 case BT_MESSAGE_TYPE_DISCARDED_PACKETS:
459 stream = bt_message_discarded_packets_borrow_stream_const(msg);
460 break;
461 case BT_MESSAGE_TYPE_MESSAGE_ITERATOR_INACTIVITY:
462 goto end;
463 default:
464 bt_common_abort();
465 }
466
467 end:
468 return stream;
469 }
470
471 static
472 const bt_trace *borrow_trace(const bt_message *msg)
473 {
474 const bt_trace *trace = NULL;
475 const bt_stream *stream = NULL;
476
477 stream = borrow_stream(msg);
478 if (stream) {
479 trace = bt_stream_borrow_trace_const(stream);
480 }
481
482 return trace;
483 }
484
485 static
486 int compare_messages_by_trace_name(struct messages_to_compare *msgs)
487 {
488 int ret = 0;
489 const char *left_trace_name = NULL, *right_trace_name = NULL;
490
491 if (msgs->left.trace && !msgs->right.trace) {
492 ret = -1;
493 goto end;
494 }
495
496 if (!msgs->left.trace && msgs->right.trace) {
497 ret = 1;
498 goto end;
499 }
500
501 if (!msgs->left.trace && !msgs->right.trace) {
502 ret = 0;
503 goto end;
504 }
505
506 left_trace_name = bt_trace_get_name(msgs->left.trace);
507 right_trace_name = bt_trace_get_name(msgs->right.trace);
508
509 if (left_trace_name && !right_trace_name) {
510 ret = -1;
511 goto end;
512 }
513
514 if (!left_trace_name && right_trace_name) {
515 ret = 1;
516 goto end;
517 }
518
519 if (!left_trace_name && !right_trace_name) {
520 ret = 0;
521 goto end;
522 }
523
524 ret = strcmp(left_trace_name, right_trace_name);
525 end:
526 return ret;
527 }
528
529 static
530 int compare_messages_by_trace_uuid(struct messages_to_compare *msgs)
531 {
532 int ret = 0;
533 bt_uuid left_trace_uuid = NULL, right_trace_uuid = NULL;
534
535 if (msgs->left.trace && !msgs->right.trace) {
536 ret = -1;
537 goto end;
538 }
539
540 if (!msgs->left.trace && msgs->right.trace) {
541 ret = 1;
542 goto end;
543 }
544
545 if (!msgs->left.trace && !msgs->right.trace) {
546 ret = 0;
547 goto end;
548 }
549
550 left_trace_uuid = bt_trace_get_uuid(msgs->left.trace);
551 right_trace_uuid = bt_trace_get_uuid(msgs->right.trace);
552
553 if (left_trace_uuid && !right_trace_uuid) {
554 ret = -1;
555 goto end;
556 }
557
558 if (!left_trace_uuid && right_trace_uuid) {
559 ret = 1;
560 goto end;
561 }
562
563 if (!left_trace_uuid && !right_trace_uuid) {
564 ret = 0;
565 goto end;
566 }
567
568 ret = bt_uuid_compare(left_trace_uuid, right_trace_uuid);
569 end:
570 return ret;
571 }
572
573 static
574 int compare_messages_by_stream_class_id(struct messages_to_compare *msgs)
575 {
576 int ret = 0;
577 uint64_t left_stream_class_id = 0, right_stream_class_id = 0;
578
579 if (msgs->left.stream && !msgs->right.stream) {
580 ret = -1;
581 goto end;
582 }
583
584 if (!msgs->left.stream && msgs->right.stream) {
585 ret = 1;
586 goto end;
587 }
588
589 if (!msgs->left.stream && !msgs->right.stream) {
590 ret = 0;
591 goto end;
592 }
593
594 left_stream_class_id = bt_stream_class_get_id(
595 bt_stream_borrow_class_const(msgs->left.stream));
596
597 right_stream_class_id = bt_stream_class_get_id(
598 bt_stream_borrow_class_const(msgs->right.stream));
599
600 if (left_stream_class_id == right_stream_class_id) {
601 ret = 0;
602 goto end;
603 }
604
605 ret = (left_stream_class_id < right_stream_class_id) ? -1 : 1;
606
607 end:
608 return ret;
609 }
610
611 static
612 int compare_messages_by_stream_id(struct messages_to_compare *msgs)
613 {
614 int ret = 0;
615 uint64_t left_stream_id = 0, right_stream_id = 0;
616
617 if (msgs->left.stream && !msgs->right.stream) {
618 ret = -1;
619 goto end;
620 }
621
622 if (!msgs->left.stream && msgs->right.stream) {
623 ret = 1;
624 goto end;
625 }
626
627 if (!msgs->left.stream && !msgs->right.stream) {
628 ret = 0;
629 goto end;
630 }
631
632 left_stream_id = bt_stream_get_id(msgs->left.stream);
633 right_stream_id = bt_stream_get_id(msgs->right.stream);
634
635 if (left_stream_id == right_stream_id) {
636 ret = 0;
637 goto end;
638 }
639
640 ret = (left_stream_id < right_stream_id) ? -1 : 1;
641
642 end:
643 return ret;
644 }
645
646 static
647 int compare_messages_same_type(struct messages_to_compare *msgs)
648 {
649 int ret = 0;
650
651 /*
652 * Both messages are of the same type, we must compare characterics of
653 * the messages such as the attributes of the event in a event message.
654 */
655 BT_ASSERT(bt_message_get_type(msgs->left.msg) ==
656 bt_message_get_type(msgs->right.msg));
657
658 switch (bt_message_get_type(msgs->left.msg)) {
659 case BT_MESSAGE_TYPE_STREAM_BEGINNING:
660 /* Fall-through */
661 case BT_MESSAGE_TYPE_STREAM_END:
662 /* Fall-through */
663 case BT_MESSAGE_TYPE_PACKET_BEGINNING:
664 /* Fall-through */
665 case BT_MESSAGE_TYPE_PACKET_END:
666 ret = compare_streams(msgs->left.stream, msgs->right.stream);
667 if (ret) {
668 goto end;
669 }
670
671 break;
672 case BT_MESSAGE_TYPE_EVENT:
673 {
674 const bt_event *left_event, *right_event;
675 left_event = bt_message_event_borrow_event_const(msgs->left.msg);
676 right_event = bt_message_event_borrow_event_const(msgs->right.msg);
677
678 ret = compare_events(left_event, right_event);
679 if (ret) {
680 goto end;
681 }
682
683 ret = compare_streams(msgs->left.stream, msgs->right.stream);
684 if (ret) {
685 goto end;
686 }
687 break;
688 }
689 case BT_MESSAGE_TYPE_DISCARDED_EVENTS:
690 {
691 const bt_stream_class *left_stream_class;
692 bt_property_availability left_event_count_avail,
693 right_event_count_avail;
694 uint64_t left_event_count, right_event_count;
695
696 /*
697 * Compare streams first to check if there is a
698 * mismatch about discarded event related configuration
699 * in the stream class.
700 */
701 ret = compare_streams(msgs->left.stream, msgs->right.stream);
702 if (ret) {
703 goto end;
704 }
705
706 left_stream_class = bt_stream_borrow_class_const(msgs->left.stream);
707 if (bt_stream_class_discarded_events_have_default_clock_snapshots(
708 left_stream_class)) {
709 const bt_clock_snapshot *left_beg_cs =
710 bt_message_discarded_events_borrow_beginning_default_clock_snapshot_const(msgs->left.msg);
711 const bt_clock_snapshot *right_beg_cs =
712 bt_message_discarded_events_borrow_beginning_default_clock_snapshot_const(msgs->right.msg);
713 const bt_clock_snapshot *left_end_cs =
714 bt_message_discarded_events_borrow_end_default_clock_snapshot_const(msgs->left.msg);
715 const bt_clock_snapshot *right_end_cs =
716 bt_message_discarded_events_borrow_end_default_clock_snapshot_const(msgs->right.msg);
717
718 ret = compare_clock_snapshots_and_clock_classes(
719 left_beg_cs, right_beg_cs);
720 if (ret) {
721 goto end;
722 }
723
724 ret = compare_clock_snapshots_and_clock_classes(
725 left_end_cs, right_end_cs);
726 if (ret) {
727 goto end;
728 }
729 }
730
731 left_event_count_avail =
732 bt_message_discarded_events_get_count(
733 msgs->left.msg, &left_event_count);
734 right_event_count_avail =
735 bt_message_discarded_events_get_count(
736 msgs->right.msg, &right_event_count);
737 if (left_event_count_avail == BT_PROPERTY_AVAILABILITY_AVAILABLE &&
738 right_event_count_avail == BT_PROPERTY_AVAILABILITY_AVAILABLE) {
739 ret = left_event_count - right_event_count;
740 if (ret != 0) {
741 goto end;
742 }
743 } else if (left_event_count_avail == BT_PROPERTY_AVAILABILITY_AVAILABLE &&
744 right_event_count_avail == BT_PROPERTY_AVAILABILITY_NOT_AVAILABLE) {
745 ret = -1;
746 goto end;
747 } else if (left_event_count_avail == BT_PROPERTY_AVAILABILITY_NOT_AVAILABLE &&
748 right_event_count_avail == BT_PROPERTY_AVAILABILITY_AVAILABLE) {
749 ret = 1;
750 goto end;
751 }
752
753 break;
754 }
755 case BT_MESSAGE_TYPE_DISCARDED_PACKETS:
756 {
757 const bt_stream_class *left_stream_class;
758 bt_property_availability left_packet_count_avail,
759 right_packet_count_avail;
760 uint64_t left_packet_count, right_packet_count;
761
762 /*
763 * Compare streams first to check if there is a
764 * mismatch about discarded packets related
765 * configuration in the stream class.
766 */
767 ret = compare_streams(msgs->left.stream, msgs->right.stream);
768 if (ret) {
769 goto end;
770 }
771
772 left_stream_class = bt_stream_borrow_class_const(msgs->left.stream);
773
774 if (bt_stream_class_discarded_packets_have_default_clock_snapshots(
775 left_stream_class)) {
776 const bt_clock_snapshot *left_beg_cs =
777 bt_message_discarded_packets_borrow_beginning_default_clock_snapshot_const(msgs->left.msg);
778 const bt_clock_snapshot *right_beg_cs =
779 bt_message_discarded_packets_borrow_beginning_default_clock_snapshot_const(msgs->right.msg);
780 const bt_clock_snapshot *left_end_cs =
781 bt_message_discarded_packets_borrow_end_default_clock_snapshot_const(msgs->left.msg);
782 const bt_clock_snapshot *right_end_cs =
783 bt_message_discarded_packets_borrow_end_default_clock_snapshot_const(msgs->right.msg);
784
785 ret = compare_clock_snapshots_and_clock_classes(
786 left_beg_cs, right_beg_cs);
787 if (ret) {
788 goto end;
789 }
790
791 ret = compare_clock_snapshots_and_clock_classes(
792 left_end_cs, right_end_cs);
793 if (ret) {
794 goto end;
795 }
796 }
797
798 left_packet_count_avail = bt_message_discarded_packets_get_count(
799 msgs->left.msg, &left_packet_count);
800 right_packet_count_avail = bt_message_discarded_packets_get_count(
801 msgs->right.msg, &right_packet_count);
802 if (left_packet_count_avail == BT_PROPERTY_AVAILABILITY_AVAILABLE &&
803 right_packet_count_avail == BT_PROPERTY_AVAILABILITY_AVAILABLE) {
804 ret = left_packet_count - right_packet_count;
805 if (ret != 0) {
806 goto end;
807 }
808 } else if (left_packet_count_avail == BT_PROPERTY_AVAILABILITY_AVAILABLE &&
809 right_packet_count_avail == BT_PROPERTY_AVAILABILITY_NOT_AVAILABLE) {
810 ret = -1;
811 goto end;
812 } else if (left_packet_count_avail == BT_PROPERTY_AVAILABILITY_NOT_AVAILABLE &&
813 right_packet_count_avail == BT_PROPERTY_AVAILABILITY_AVAILABLE) {
814 ret = 1;
815 goto end;
816 }
817
818 break;
819 }
820 case BT_MESSAGE_TYPE_MESSAGE_ITERATOR_INACTIVITY:
821 {
822 const bt_clock_snapshot *left_cs =
823 bt_message_message_iterator_inactivity_borrow_default_clock_snapshot_const(msgs->left.msg);
824 const bt_clock_snapshot *right_cs =
825 bt_message_message_iterator_inactivity_borrow_default_clock_snapshot_const(msgs->right.msg);
826
827 ret = compare_clock_snapshots_and_clock_classes(
828 left_cs, right_cs);
829 if (ret != 0) {
830 goto end;
831 }
832
833 break;
834 }
835 default:
836 bt_common_abort();
837 }
838
839 end:
840 return ret;
841 }
842
843 BT_HIDDEN
844 int common_muxing_compare_messages(const bt_message *left_msg,
845 const bt_message *right_msg)
846 {
847 int ret = 0;
848 struct messages_to_compare msgs;
849
850 BT_ASSERT(left_msg != right_msg);
851
852 msgs.left.msg = left_msg;
853 msgs.left.trace = borrow_trace(left_msg);
854 msgs.left.stream = borrow_stream(left_msg);
855
856 msgs.right.msg = right_msg;
857 msgs.right.trace = borrow_trace(right_msg);
858 msgs.right.stream = borrow_stream(right_msg);
859
860 /* Same timestamp: compare trace UUIDs. */
861 ret = compare_messages_by_trace_uuid(&msgs);
862 if (ret) {
863 goto end;
864 }
865
866 /* Same timestamp and trace UUID: compare trace names. */
867 ret = compare_messages_by_trace_name(&msgs);
868 if (ret) {
869 goto end;
870 }
871
872 /*
873 * Same timestamp, trace name, and trace UUID: compare stream class
874 * IDs.
875 */
876 ret = compare_messages_by_stream_class_id(&msgs);
877 if (ret) {
878 goto end;
879 }
880
881 /*
882 * Same timestamp, trace name, trace UUID, and stream class ID: compare
883 * stream IDs.
884 */
885 ret = compare_messages_by_stream_id(&msgs);
886 if (ret) {
887 goto end;
888 }
889
890 if (bt_message_get_type(msgs.left.msg) !=
891 bt_message_get_type(msgs.right.msg)) {
892 /*
893 * The messages are of different type, we order (arbitrarily)
894 * in the following way:
895 * SB < PB < EV < DE < MI < PE < DP < SE
896 */
897 ret = compare_messages_by_type(&msgs);
898 if (ret) {
899 goto end;
900 }
901 } else {
902 /* The messages are of the same type. */
903 ret = compare_messages_same_type(&msgs);
904 if (ret) {
905 goto end;
906 }
907 }
908
909 end:
910 return ret;
911 }
This page took 0.048725 seconds and 5 git commands to generate.