2 * Copyright 2018 - 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.
15 #define BT_LOG_OUTPUT_LEVEL log_level
16 #define BT_LOG_TAG "PLUGIN/CTF/META/UPDATE-DEF-CC"
17 #include "logging/log.h"
19 #include <babeltrace2/babeltrace.h>
20 #include "common/macros.h"
21 #include "common/assert.h"
27 #include "ctf-meta-visitors.h"
30 int find_mapped_clock_class(struct ctf_field_class
*fc
,
31 struct ctf_clock_class
**clock_class
,
32 bt_logging_level log_level
)
42 case CTF_FIELD_CLASS_TYPE_INT
:
43 case CTF_FIELD_CLASS_TYPE_ENUM
:
45 struct ctf_field_class_int
*int_fc
= (void *) fc
;
47 if (int_fc
->mapped_clock_class
) {
48 if (*clock_class
&& *clock_class
!=
49 int_fc
->mapped_clock_class
) {
50 BT_LOGE("Stream class contains more than one "
51 "clock class: expected-cc-name=\"%s\", "
52 "other-cc-name=\"%s\"",
53 (*clock_class
)->name
->str
,
54 int_fc
->mapped_clock_class
->name
->str
);
59 *clock_class
= int_fc
->mapped_clock_class
;
64 case CTF_FIELD_CLASS_TYPE_STRUCT
:
66 struct ctf_field_class_struct
*struct_fc
= (void *) fc
;
68 for (i
= 0; i
< struct_fc
->members
->len
; i
++) {
69 struct ctf_named_field_class
*named_fc
=
70 ctf_field_class_struct_borrow_member_by_index(
73 ret
= find_mapped_clock_class(named_fc
->fc
,
74 clock_class
, log_level
);
82 case CTF_FIELD_CLASS_TYPE_VARIANT
:
84 struct ctf_field_class_variant
*var_fc
= (void *) fc
;
86 for (i
= 0; i
< var_fc
->options
->len
; i
++) {
87 struct ctf_named_field_class
*named_fc
=
88 ctf_field_class_variant_borrow_option_by_index(
91 ret
= find_mapped_clock_class(named_fc
->fc
,
92 clock_class
, log_level
);
100 case CTF_FIELD_CLASS_TYPE_ARRAY
:
101 case CTF_FIELD_CLASS_TYPE_SEQUENCE
:
103 struct ctf_field_class_array_base
*array_fc
= (void *) fc
;
105 ret
= find_mapped_clock_class(array_fc
->elem_fc
, clock_class
,
122 int update_stream_class_default_clock_class(
123 struct ctf_stream_class
*stream_class
,
124 bt_logging_level log_level
)
127 struct ctf_clock_class
*clock_class
=
128 stream_class
->default_clock_class
;
131 ret
= find_mapped_clock_class(stream_class
->packet_context_fc
,
132 &clock_class
, log_level
);
137 ret
= find_mapped_clock_class(stream_class
->event_header_fc
,
138 &clock_class
, log_level
);
143 ret
= find_mapped_clock_class(stream_class
->event_common_context_fc
,
144 &clock_class
, log_level
);
149 for (i
= 0; i
< stream_class
->event_classes
->len
; i
++) {
150 struct ctf_event_class
*event_class
=
151 stream_class
->event_classes
->pdata
[i
];
153 ret
= find_mapped_clock_class(event_class
->spec_context_fc
,
154 &clock_class
, log_level
);
159 ret
= find_mapped_clock_class(event_class
->payload_fc
,
160 &clock_class
, log_level
);
166 if (!stream_class
->default_clock_class
) {
167 stream_class
->default_clock_class
= clock_class
;
175 int ctf_trace_class_update_default_clock_classes(struct ctf_trace_class
*ctf_tc
,
176 bt_logging_level log_level
)
180 struct ctf_clock_class
*clock_class
= NULL
;
182 ret
= find_mapped_clock_class(ctf_tc
->packet_header_fc
, &clock_class
,
193 for (i
= 0; i
< ctf_tc
->stream_classes
->len
; i
++) {
194 struct ctf_stream_class
*sc
=
195 ctf_tc
->stream_classes
->pdata
[i
];
197 ret
= update_stream_class_default_clock_class(
198 ctf_tc
->stream_classes
->pdata
[i
], log_level
);
200 BT_LOGE("Stream class contains more than one "
201 "clock class: stream-class-id=%" PRIu64
,