Logging: standardize logging tags
[babeltrace.git] / src / lib / graph / message / stream-activity.c
CommitLineData
5df26c89
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
350ad6c1 23#define BT_LOG_TAG "LIB/MSG-STREAM-ACTIVITY"
578e048b 24#include "lib/lib-logging.h"
5df26c89 25
578e048b
MJ
26#include "lib/assert-pre.h"
27#include "lib/object.h"
28#include "compat/compiler.h"
3fadfbc0 29#include <babeltrace2/trace-ir/clock-class.h>
578e048b
MJ
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"
3fadfbc0
MJ
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>
578e048b
MJ
38
39#include "stream-activity.h"
5df26c89
PP
40
41static
42void destroy_stream_activity_message(struct bt_object *obj)
43{
44 struct bt_message_stream_activity *message = (void *) obj;
45
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);
49
50 if (message->default_cs) {
51 bt_clock_snapshot_recycle(message->default_cs);
678aa684 52 message->default_cs = NULL;
5df26c89
PP
53 }
54
55 g_free(message);
56}
57
58static inline
59struct 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)
62{
63 struct bt_message_stream_activity *message;
64 struct bt_stream_class *stream_class;
65
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);
74 if (!message) {
75 BT_LOGE_STR("Failed to allocate one stream activity message.");
76 goto error;
77 }
78
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);
83
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) {
88 goto error;
89 }
90 }
91
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);
97
98 return (void *) &message->parent;
99
100error:
101 return NULL;
102}
103
104struct bt_message *bt_message_stream_activity_beginning_create(
105 struct bt_self_message_iterator *self_msg_iter,
58085ca4 106 const struct bt_stream *stream)
5df26c89 107{
58085ca4 108 return create_stream_activity_message(self_msg_iter, (void *) stream,
5df26c89
PP
109 BT_MESSAGE_TYPE_STREAM_ACTIVITY_BEGINNING);
110}
111
112struct bt_message *bt_message_stream_activity_end_create(
113 struct bt_self_message_iterator *self_msg_iter,
58085ca4 114 const struct bt_stream *stream)
5df26c89 115{
58085ca4 116 return create_stream_activity_message(self_msg_iter, (void *) stream,
5df26c89
PP
117 BT_MESSAGE_TYPE_STREAM_ACTIVITY_END);
118}
119
120static inline
121struct bt_stream *borrow_stream_activity_message_stream(
122 struct bt_message *message)
123{
124 struct bt_message_stream_activity *stream_act_msg = (void *) message;
125
126 BT_ASSERT(message);
127 return stream_act_msg->stream;
128}
129
130struct bt_stream *bt_message_stream_activity_beginning_borrow_stream(
131 struct bt_message *message)
132{
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);
137}
138
139struct bt_stream *bt_message_stream_activity_end_borrow_stream(
140 struct bt_message *message)
141{
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);
146}
147
148const struct bt_stream *bt_message_stream_activity_beginning_borrow_stream_const(
149 const struct bt_message *message)
150{
151 return bt_message_stream_activity_beginning_borrow_stream(
152 (void *) message);
153}
154
155const struct bt_stream *bt_message_stream_activity_end_borrow_stream_const(
156 const struct bt_message *message)
157{
158 return bt_message_stream_activity_end_borrow_stream((void *) message);
159}
160
161static inline
162void set_stream_activity_message_default_clock_snapshot(
163 struct bt_message *msg, uint64_t value_cycles)
164{
165 struct bt_message_stream_activity *stream_act_msg = (void *) msg;
166 struct bt_stream_class *sc;
167
168 BT_ASSERT(msg);
169 BT_ASSERT_PRE_HOT(msg, "Message", ": %!+n", msg);
170 sc = stream_act_msg->stream->class;
171 BT_ASSERT(sc);
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,
176 value_cycles);
177 stream_act_msg->default_cs_state =
178 BT_MESSAGE_STREAM_ACTIVITY_CLOCK_SNAPSHOT_STATE_KNOWN;
3f7d4d90 179 BT_LIB_LOGD("Set stream activity message's default clock snapshot: "
5df26c89
PP
180 "%![msg-]+n, value=%" PRIu64, msg, value_cycles);
181}
182
183void bt_message_stream_activity_beginning_set_default_clock_snapshot(
184 struct bt_message *msg, uint64_t raw_value)
185{
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);
190}
191
192void bt_message_stream_activity_end_set_default_clock_snapshot(
193 struct bt_message *msg, uint64_t raw_value)
194{
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);
199}
200
201static inline
202enum bt_message_stream_activity_clock_snapshot_state
203borrow_stream_activity_message_default_clock_snapshot_const(
204 const bt_message *msg, const bt_clock_snapshot **snapshot)
205{
206 const struct bt_message_stream_activity *stream_act_msg =
207 (const void *) msg;
208
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;
212}
213
214enum bt_message_stream_activity_clock_snapshot_state
215bt_message_stream_activity_beginning_borrow_default_clock_snapshot_const(
216 const bt_message *msg, const bt_clock_snapshot **snapshot)
217{
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,
222 snapshot);
223}
224
225enum bt_message_stream_activity_clock_snapshot_state
226bt_message_stream_activity_end_borrow_default_clock_snapshot_const(
227 const bt_message *msg, const bt_clock_snapshot **snapshot)
228{
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,
232 snapshot);
233}
234
235static inline
236void set_stream_activity_message_default_clock_snapshot_state(
237 struct bt_message *msg,
238 enum bt_message_stream_activity_clock_snapshot_state state)
239{
240 struct bt_message_stream_activity *stream_act_msg = (void *) msg;
241
242 BT_ASSERT(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",
246 msg,
247 bt_message_stream_activity_clock_snapshot_state_string(state));
248 stream_act_msg->default_cs_state = state;
3f7d4d90 249 BT_LIB_LOGD("Set stream activity message's default clock snapshot state: "
5df26c89
PP
250 "%![msg-]+n, state=%s", msg,
251 bt_message_stream_activity_clock_snapshot_state_string(state));
252}
253
254void 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)
257{
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);
262}
263
264void 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)
267{
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);
272}
33931ab8
PP
273
274static inline
275const struct bt_clock_class *
276borrow_stream_activity_message_stream_class_default_clock_class(
277 const struct bt_message *msg)
278{
279 struct bt_message_stream_activity *stream_act_msg = (void *) msg;
280
281 BT_ASSERT(msg);
282 return stream_act_msg->stream->class->default_clock_class;
283}
284
285const struct bt_clock_class *
286bt_message_stream_activity_beginning_borrow_stream_class_default_clock_class_const(
287 const struct bt_message *msg)
288{
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(
293 msg);
294}
295
296const struct bt_clock_class *
297bt_message_stream_activity_end_borrow_stream_class_default_clock_class_const(
298 const struct bt_message *msg)
299{
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(
303 msg);
304}
This page took 0.038216 seconds and 4 git commands to generate.