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>
40 void destroy_discarded_items_message(struct bt_object
*obj
)
42 struct bt_message_discarded_items
*message
= (void *) obj
;
44 BT_LIB_LOGD("Destroying discarded items message: %!+n", message
);
45 BT_LIB_LOGD("Putting stream: %!+s", message
->stream
);
46 BT_OBJECT_PUT_REF_AND_RESET(message
->stream
);
48 if (message
->default_begin_cs
) {
49 bt_clock_snapshot_recycle(message
->default_begin_cs
);
50 message
->default_begin_cs
= NULL
;
53 if (message
->default_end_cs
) {
54 bt_clock_snapshot_recycle(message
->default_end_cs
);
55 message
->default_end_cs
= NULL
;
62 struct bt_message
*create_discarded_items_message(
63 struct bt_self_message_iterator
*self_msg_iter
,
64 enum bt_message_type type
, struct bt_stream
*stream
,
66 uint64_t beginning_raw_value
, uint64_t end_raw_value
)
68 struct bt_message_discarded_items
*message
;
69 struct bt_stream_class
*stream_class
;
71 BT_ASSERT_PRE_NON_NULL(self_msg_iter
, "Message iterator");
72 BT_ASSERT_PRE_NON_NULL(stream
, "Stream");
73 stream_class
= bt_stream_borrow_class(stream
);
74 BT_ASSERT(stream_class
);
75 BT_LIB_LOGD("Creating discarded items message object: "
76 "type=%s, %![stream-]+s, %![sc-]+S, with-cs=%d, "
77 "cs-begin-val=%" PRIu64
", cs-end-val=%" PRIu64
,
78 bt_message_type_string(type
), stream
, stream_class
,
79 with_cs
, beginning_raw_value
, end_raw_value
);
80 message
= g_new0(struct bt_message_discarded_items
, 1);
82 BT_LOGE_STR("Failed to allocate one discarded items message.");
86 bt_message_init(&message
->parent
, type
,
87 destroy_discarded_items_message
, NULL
);
88 message
->stream
= stream
;
89 bt_object_get_no_null_check(message
->stream
);
92 message
->default_begin_cs
= bt_clock_snapshot_create(
93 stream_class
->default_clock_class
);
94 if (!message
->default_begin_cs
) {
98 bt_clock_snapshot_set_raw_value(message
->default_begin_cs
,
101 message
->default_end_cs
= bt_clock_snapshot_create(
102 stream_class
->default_clock_class
);
103 if (!message
->default_end_cs
) {
107 bt_clock_snapshot_set_raw_value(message
->default_end_cs
,
111 bt_property_uint_init(&message
->count
,
112 BT_PROPERTY_AVAILABILITY_NOT_AVAILABLE
, 0);
113 BT_LIB_LOGD("Created discarded items message object: "
114 "%![msg-]+n, %![stream-]+s, %![sc-]+S", message
,
115 stream
, stream_class
);
117 return (void *) &message
->parent
;
124 struct bt_stream
*borrow_discarded_items_message_stream(
125 struct bt_message
*message
)
127 struct bt_message_discarded_items
*disc_items_msg
= (void *) message
;
130 return disc_items_msg
->stream
;
134 void set_discarded_items_message_count(struct bt_message
*message
,
137 struct bt_message_discarded_items
*disc_items_msg
= (void *) message
;
140 BT_ASSERT_PRE_HOT(message
, "Message", ": %!+n", message
);
141 bt_property_uint_set(&disc_items_msg
->count
, count
);
145 enum bt_property_availability
get_discarded_items_message_count(
146 const struct bt_message
*message
, uint64_t *count
)
148 struct bt_message_discarded_items
*disc_items_msg
= (void *) message
;
150 BT_ASSERT_PRE_NON_NULL(count
, "Count (output)");
152 *count
= disc_items_msg
->count
.value
;
153 return disc_items_msg
->count
.base
.avail
;
157 enum bt_clock_snapshot_state
158 borrow_discarded_items_message_default_beginning_clock_snapshot_const(
159 const struct bt_message
*message
,
160 const struct bt_clock_snapshot
**snapshot
)
162 struct bt_message_discarded_items
*disc_items_msg
= (void *) message
;
165 BT_ASSERT_PRE(disc_items_msg
->stream
->class->default_clock_class
,
166 "Message's stream's class has no default clock class: "
167 "%![msg-]+n, %![sc-]+S",
168 message
, disc_items_msg
->stream
->class);
169 BT_ASSERT_PRE_NON_NULL(snapshot
, "Clock snapshot (output)");
170 *snapshot
= disc_items_msg
->default_begin_cs
;
171 return BT_CLOCK_SNAPSHOT_STATE_KNOWN
;
175 enum bt_clock_snapshot_state
176 borrow_discarded_items_message_default_end_clock_snapshot_const(
177 const struct bt_message
*message
,
178 const struct bt_clock_snapshot
**snapshot
)
180 struct bt_message_discarded_items
*disc_items_msg
= (void *) message
;
183 BT_ASSERT_PRE(disc_items_msg
->stream
->class->default_clock_class
,
184 "Message's stream's class has no default clock class: "
185 "%![msg-]+n, %![sc-]+S",
186 message
, disc_items_msg
->stream
->class);
187 BT_ASSERT_PRE_NON_NULL(snapshot
, "Clock snapshot (output)");
188 *snapshot
= disc_items_msg
->default_end_cs
;
189 return BT_CLOCK_SNAPSHOT_STATE_KNOWN
;
192 struct bt_message
*bt_message_discarded_events_create(
193 struct bt_self_message_iterator
*message_iterator
,
194 struct bt_stream
*stream
)
196 return create_discarded_items_message(message_iterator
,
197 BT_MESSAGE_TYPE_DISCARDED_EVENTS
, stream
,
201 struct bt_message
*bt_message_discarded_events_create_with_default_clock_snapshots(
202 struct bt_self_message_iterator
*message_iterator
,
203 struct bt_stream
*stream
, uint64_t beginning_raw_value
,
204 uint64_t end_raw_value
)
206 return create_discarded_items_message(message_iterator
,
207 BT_MESSAGE_TYPE_DISCARDED_EVENTS
, stream
,
208 true, beginning_raw_value
, end_raw_value
);
211 struct bt_stream
*bt_message_discarded_events_borrow_stream(
212 struct bt_message
*message
)
214 BT_ASSERT_PRE_NON_NULL(message
, "Message");
215 BT_ASSERT_PRE_MSG_IS_TYPE(message
, BT_MESSAGE_TYPE_DISCARDED_EVENTS
);
216 return borrow_discarded_items_message_stream(message
);
219 void bt_message_discarded_events_set_count(struct bt_message
*message
,
222 BT_ASSERT_PRE_NON_NULL(message
, "Message");
223 BT_ASSERT_PRE_MSG_IS_TYPE(message
, BT_MESSAGE_TYPE_DISCARDED_EVENTS
);
224 set_discarded_items_message_count(message
, count
);
227 enum bt_clock_snapshot_state
228 bt_message_discarded_events_borrow_default_beginning_clock_snapshot_const(
229 const struct bt_message
*msg
,
230 const struct bt_clock_snapshot
**snapshot
)
232 BT_ASSERT_PRE_NON_NULL(msg
, "Message");
233 BT_ASSERT_PRE_MSG_IS_TYPE(msg
, BT_MESSAGE_TYPE_DISCARDED_EVENTS
);
234 return borrow_discarded_items_message_default_beginning_clock_snapshot_const(
238 enum bt_clock_snapshot_state
239 bt_message_discarded_events_borrow_default_end_clock_snapshot_const(
240 const struct bt_message
*msg
,
241 const struct bt_clock_snapshot
**snapshot
)
243 BT_ASSERT_PRE_NON_NULL(msg
, "Message");
244 BT_ASSERT_PRE_MSG_IS_TYPE(msg
, BT_MESSAGE_TYPE_DISCARDED_EVENTS
);
245 return borrow_discarded_items_message_default_end_clock_snapshot_const(
249 const struct bt_stream
*
250 bt_message_discarded_events_borrow_stream_const(const struct bt_message
*message
)
252 return (void *) bt_message_discarded_events_borrow_stream(
256 enum bt_property_availability
bt_message_discarded_events_get_count(
257 const struct bt_message
*message
, uint64_t *count
)
259 BT_ASSERT_PRE_NON_NULL(message
, "Message");
260 BT_ASSERT_PRE_MSG_IS_TYPE(message
, BT_MESSAGE_TYPE_DISCARDED_EVENTS
);
261 return get_discarded_items_message_count(message
, count
);