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 "LIB/MSG-STREAM-ACTIVITY"
24 #include "lib/logging.h"
26 #include "lib/assert-pre.h"
27 #include "lib/object.h"
28 #include "compat/compiler.h"
29 #include <babeltrace2/trace-ir/clock-class.h>
30 #include "lib/trace-ir/clock-snapshot.h"
31 #include "lib/trace-ir/stream-class.h"
32 #include "lib/trace-ir/stream.h"
33 #include "lib/graph/message/message.h"
34 #include <babeltrace2/graph/message-stream-activity-beginning-const.h>
35 #include <babeltrace2/graph/message-stream-activity-end-const.h>
36 #include <babeltrace2/graph/message-stream-activity-beginning.h>
37 #include <babeltrace2/graph/message-stream-activity-end.h>
39 #include "stream-activity.h"
42 void destroy_stream_activity_message(struct bt_object
*obj
)
44 struct bt_message_stream_activity
*message
= (void *) obj
;
46 BT_LIB_LOGD("Destroying stream activity 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_cs
) {
51 bt_clock_snapshot_recycle(message
->default_cs
);
52 message
->default_cs
= NULL
;
59 struct bt_message
*create_stream_activity_message(
60 struct bt_self_message_iterator
*self_msg_iter
,
61 struct bt_stream
*stream
, enum bt_message_type type
)
63 struct bt_message_stream_activity
*message
;
64 struct bt_stream_class
*stream_class
;
66 BT_ASSERT_PRE_NON_NULL(self_msg_iter
, "Message iterator");
67 BT_ASSERT_PRE_NON_NULL(stream
, "Stream");
68 stream_class
= bt_stream_borrow_class(stream
);
69 BT_ASSERT(stream_class
);
70 BT_LIB_LOGD("Creating stream activity message object: "
71 "type=%s, %![stream-]+s, %![sc-]+S",
72 bt_message_type_string(type
), stream
, stream_class
);
73 message
= g_new0(struct bt_message_stream_activity
, 1);
75 BT_LOGE_STR("Failed to allocate one stream activity message.");
79 bt_message_init(&message
->parent
, type
,
80 destroy_stream_activity_message
, NULL
);
81 message
->stream
= stream
;
82 bt_object_get_no_null_check(message
->stream
);
84 if (stream_class
->default_clock_class
) {
85 message
->default_cs
= bt_clock_snapshot_create(
86 stream_class
->default_clock_class
);
87 if (!message
->default_cs
) {
92 message
->default_cs_state
=
93 BT_MESSAGE_STREAM_ACTIVITY_CLOCK_SNAPSHOT_STATE_UNKNOWN
;
94 BT_LIB_LOGD("Created stream activity message object: "
95 "%![msg-]+n, %![stream-]+s, %![sc-]+S", message
,
96 stream
, stream_class
);
98 return (void *) &message
->parent
;
104 struct bt_message
*bt_message_stream_activity_beginning_create(
105 struct bt_self_message_iterator
*self_msg_iter
,
106 const struct bt_stream
*stream
)
108 return create_stream_activity_message(self_msg_iter
, (void *) stream
,
109 BT_MESSAGE_TYPE_STREAM_ACTIVITY_BEGINNING
);
112 struct bt_message
*bt_message_stream_activity_end_create(
113 struct bt_self_message_iterator
*self_msg_iter
,
114 const struct bt_stream
*stream
)
116 return create_stream_activity_message(self_msg_iter
, (void *) stream
,
117 BT_MESSAGE_TYPE_STREAM_ACTIVITY_END
);
121 struct bt_stream
*borrow_stream_activity_message_stream(
122 struct bt_message
*message
)
124 struct bt_message_stream_activity
*stream_act_msg
= (void *) message
;
127 return stream_act_msg
->stream
;
130 struct bt_stream
*bt_message_stream_activity_beginning_borrow_stream(
131 struct bt_message
*message
)
133 BT_ASSERT_PRE_NON_NULL(message
, "Message");
134 BT_ASSERT_PRE_MSG_IS_TYPE(message
,
135 BT_MESSAGE_TYPE_STREAM_ACTIVITY_BEGINNING
);
136 return borrow_stream_activity_message_stream(message
);
139 struct bt_stream
*bt_message_stream_activity_end_borrow_stream(
140 struct bt_message
*message
)
142 BT_ASSERT_PRE_NON_NULL(message
, "Message");
143 BT_ASSERT_PRE_MSG_IS_TYPE(message
,
144 BT_MESSAGE_TYPE_STREAM_ACTIVITY_END
);
145 return borrow_stream_activity_message_stream(message
);
148 const struct bt_stream
*bt_message_stream_activity_beginning_borrow_stream_const(
149 const struct bt_message
*message
)
151 return bt_message_stream_activity_beginning_borrow_stream(
155 const struct bt_stream
*bt_message_stream_activity_end_borrow_stream_const(
156 const struct bt_message
*message
)
158 return bt_message_stream_activity_end_borrow_stream((void *) message
);
162 void set_stream_activity_message_default_clock_snapshot(
163 struct bt_message
*msg
, uint64_t value_cycles
)
165 struct bt_message_stream_activity
*stream_act_msg
= (void *) msg
;
166 struct bt_stream_class
*sc
;
169 BT_ASSERT_PRE_HOT(msg
, "Message", ": %!+n", msg
);
170 sc
= stream_act_msg
->stream
->class;
172 BT_ASSERT_PRE(sc
->default_clock_class
,
173 "Message's stream's class has no default clock class: "
174 "%![msg-]+n, %![sc-]+S", msg
, sc
);
175 bt_clock_snapshot_set_raw_value(stream_act_msg
->default_cs
,
177 stream_act_msg
->default_cs_state
=
178 BT_MESSAGE_STREAM_ACTIVITY_CLOCK_SNAPSHOT_STATE_KNOWN
;
179 BT_LIB_LOGD("Set stream activity message's default clock snapshot: "
180 "%![msg-]+n, value=%" PRIu64
, msg
, value_cycles
);
183 void bt_message_stream_activity_beginning_set_default_clock_snapshot(
184 struct bt_message
*msg
, uint64_t raw_value
)
186 BT_ASSERT_PRE_NON_NULL(msg
, "Message");
187 BT_ASSERT_PRE_MSG_IS_TYPE(msg
,
188 BT_MESSAGE_TYPE_STREAM_ACTIVITY_BEGINNING
);
189 set_stream_activity_message_default_clock_snapshot(msg
, raw_value
);
192 void bt_message_stream_activity_end_set_default_clock_snapshot(
193 struct bt_message
*msg
, uint64_t raw_value
)
195 BT_ASSERT_PRE_NON_NULL(msg
, "Message");
196 BT_ASSERT_PRE_MSG_IS_TYPE(msg
,
197 BT_MESSAGE_TYPE_STREAM_ACTIVITY_END
);
198 set_stream_activity_message_default_clock_snapshot(msg
, raw_value
);
202 enum bt_message_stream_activity_clock_snapshot_state
203 borrow_stream_activity_message_default_clock_snapshot_const(
204 const bt_message
*msg
, const bt_clock_snapshot
**snapshot
)
206 const struct bt_message_stream_activity
*stream_act_msg
=
209 BT_ASSERT_PRE_NON_NULL(snapshot
, "Clock snapshot (output)");
210 *snapshot
= stream_act_msg
->default_cs
;
211 return stream_act_msg
->default_cs_state
;
214 enum bt_message_stream_activity_clock_snapshot_state
215 bt_message_stream_activity_beginning_borrow_default_clock_snapshot_const(
216 const bt_message
*msg
, const bt_clock_snapshot
**snapshot
)
218 BT_ASSERT_PRE_NON_NULL(msg
, "Message");
219 BT_ASSERT_PRE_MSG_IS_TYPE(msg
,
220 BT_MESSAGE_TYPE_STREAM_ACTIVITY_BEGINNING
);
221 return borrow_stream_activity_message_default_clock_snapshot_const(msg
,
225 enum bt_message_stream_activity_clock_snapshot_state
226 bt_message_stream_activity_end_borrow_default_clock_snapshot_const(
227 const bt_message
*msg
, const bt_clock_snapshot
**snapshot
)
229 BT_ASSERT_PRE_NON_NULL(msg
, "Message");
230 BT_ASSERT_PRE_MSG_IS_TYPE(msg
, BT_MESSAGE_TYPE_STREAM_ACTIVITY_END
);
231 return borrow_stream_activity_message_default_clock_snapshot_const(msg
,
236 void set_stream_activity_message_default_clock_snapshot_state(
237 struct bt_message
*msg
,
238 enum bt_message_stream_activity_clock_snapshot_state state
)
240 struct bt_message_stream_activity
*stream_act_msg
= (void *) msg
;
243 BT_ASSERT_PRE_HOT(msg
, "Message", ": %!+n", msg
);
244 BT_ASSERT_PRE(state
!= BT_MESSAGE_STREAM_ACTIVITY_CLOCK_SNAPSHOT_STATE_KNOWN
,
245 "Invalid clock snapshot state: %![msg-]+n, state=%s",
247 bt_message_stream_activity_clock_snapshot_state_string(state
));
248 stream_act_msg
->default_cs_state
= state
;
249 BT_LIB_LOGD("Set stream activity message's default clock snapshot state: "
250 "%![msg-]+n, state=%s", msg
,
251 bt_message_stream_activity_clock_snapshot_state_string(state
));
254 void bt_message_stream_activity_beginning_set_default_clock_snapshot_state(
255 struct bt_message
*msg
,
256 enum bt_message_stream_activity_clock_snapshot_state state
)
258 BT_ASSERT_PRE_NON_NULL(msg
, "Message");
259 BT_ASSERT_PRE_MSG_IS_TYPE(msg
,
260 BT_MESSAGE_TYPE_STREAM_ACTIVITY_BEGINNING
);
261 set_stream_activity_message_default_clock_snapshot_state(msg
, state
);
264 void bt_message_stream_activity_end_set_default_clock_snapshot_state(
265 struct bt_message
*msg
,
266 enum bt_message_stream_activity_clock_snapshot_state state
)
268 BT_ASSERT_PRE_NON_NULL(msg
, "Message");
269 BT_ASSERT_PRE_MSG_IS_TYPE(msg
,
270 BT_MESSAGE_TYPE_STREAM_ACTIVITY_END
);
271 set_stream_activity_message_default_clock_snapshot_state(msg
, state
);
275 const struct bt_clock_class
*
276 borrow_stream_activity_message_stream_class_default_clock_class(
277 const struct bt_message
*msg
)
279 struct bt_message_stream_activity
*stream_act_msg
= (void *) msg
;
282 return stream_act_msg
->stream
->class->default_clock_class
;
285 const struct bt_clock_class
*
286 bt_message_stream_activity_beginning_borrow_stream_class_default_clock_class_const(
287 const struct bt_message
*msg
)
289 BT_ASSERT_PRE_NON_NULL(msg
, "Message");
290 BT_ASSERT_PRE_MSG_IS_TYPE(msg
,
291 BT_MESSAGE_TYPE_STREAM_ACTIVITY_BEGINNING
);
292 return borrow_stream_activity_message_stream_class_default_clock_class(
296 const struct bt_clock_class
*
297 bt_message_stream_activity_end_borrow_stream_class_default_clock_class_const(
298 const struct bt_message
*msg
)
300 BT_ASSERT_PRE_NON_NULL(msg
, "Message");
301 BT_ASSERT_PRE_MSG_IS_TYPE(msg
, BT_MESSAGE_TYPE_STREAM_ACTIVITY_END
);
302 return borrow_stream_activity_message_stream_class_default_clock_class(