1 #ifndef BABELTRACE_PLUGIN_CTF_LTTNG_LIVE_H
2 #define BABELTRACE_PLUGIN_CTF_LTTNG_LIVE_H
5 * BabelTrace - LTTng-live client Component
7 * Copyright 2019 Francis Deslauriers <francis.deslauriers@efficios.com>
8 * Copyright 2016 Jérémie Galarneau <jeremie.galarneau@efficios.com>
9 * Copyright 2016 Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
11 * Author: Jérémie Galarneau <jeremie.galarneau@efficios.com>
13 * Permission is hereby granted, free of charge, to any person obtaining a copy
14 * of this software and associated documentation files (the "Software"), to deal
15 * in the Software without restriction, including without limitation the rights
16 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
17 * copies of the Software, and to permit persons to whom the Software is
18 * furnished to do so, subject to the following conditions:
20 * The above copyright notice and this permission notice shall be included in
21 * all copies or substantial portions of the Software.
23 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
24 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
25 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
26 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
27 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
28 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
34 #include "common/macros.h"
35 #include <babeltrace2/babeltrace.h>
37 #include "../common/metadata/decoder.h"
38 #include "../common/msg-iter/msg-iter.h"
40 #include "viewer-connection.h"
42 struct lttng_live_component
;
43 struct lttng_live_session
;
44 struct lttng_live_msg_iter
;
46 enum lttng_live_stream_state
{
47 /* This stream won't have data until some known time in the future. */
48 LTTNG_LIVE_STREAM_QUIESCENT
,
50 * This stream won't have data until some known time in the future and
51 * the message iterator inactivity message was already sent downstream.
53 LTTNG_LIVE_STREAM_QUIESCENT_NO_DATA
, /* */
54 /* This stream has data ready to be consumed. */
55 LTTNG_LIVE_STREAM_ACTIVE_DATA
,
57 * This stream has no data left to consume. We should asked the relay
60 LTTNG_LIVE_STREAM_ACTIVE_NO_DATA
,
61 /* This stream won't have anymore data, ever. */
62 LTTNG_LIVE_STREAM_EOF
,
65 /* Iterator over a live stream. */
66 struct lttng_live_stream_iterator
{
67 bt_logging_level log_level
;
68 bt_self_component
*self_comp
;
74 struct lttng_live_trace
*trace
;
77 * Since only a single iterator per viewer connection, we have
78 * only a single message iterator per stream.
80 struct bt_msg_iter
*msg_iter
;
82 uint64_t viewer_stream_id
;
84 uint64_t ctf_stream_class_id
;
86 /* base offset in current index. */
88 /* len to read in current index. */
90 /* offset in current index. */
94 * Clock Snapshot value of the last message iterator inactivity message
97 uint64_t last_inactivity_ts
;
100 * Clock Snapshot value of the current message iterator inactivity
101 * message we might want to send downstream.
103 uint64_t current_inactivity_ts
;
105 enum lttng_live_stream_state state
;
108 * The current message produced by this live stream iterator. Owned by
111 bt_message
*current_msg
;
113 /* Timestamp in nanoseconds of the current message (current_msg). */
114 int64_t current_msg_ts_ns
;
124 struct lttng_live_metadata
{
125 bt_logging_level log_level
;
126 bt_self_component
*self_comp
;
128 /* Weak reference. */
129 struct lttng_live_trace
*trace
;
132 /* Weak reference. */
133 struct ctf_metadata_decoder
*decoder
;
138 struct lttng_live_trace
{
139 bt_logging_level log_level
;
140 bt_self_component
*self_comp
;
142 /* Back reference to session. */
143 struct lttng_live_session
*session
;
145 /* ctf trace ID within the session. */
151 /* Weak reference. */
152 bt_trace_class
*trace_class
;
154 struct lttng_live_metadata
*metadata
;
156 const bt_clock_class
*clock_class
;
158 /* Array of pointers to struct lttng_live_stream_iterator. */
160 GPtrArray
*stream_iterators
;
162 bool new_metadata_needed
;
165 struct lttng_live_session
{
166 bt_logging_level log_level
;
167 bt_self_component
*self_comp
;
169 /* Weak reference. */
170 struct lttng_live_msg_iter
*lttng_live_msg_iter
;
176 GString
*session_name
;
180 /* Array of pointers to struct lttng_live_trace. */
184 bool new_streams_needed
;
185 bool lazy_stream_msg_init
;
189 enum session_not_found_action
{
190 SESSION_NOT_FOUND_ACTION_CONTINUE
,
191 SESSION_NOT_FOUND_ACTION_FAIL
,
192 SESSION_NOT_FOUND_ACTION_END
,
196 * A component instance is an iterator on a single session.
198 struct lttng_live_component
{
199 bt_logging_level log_level
;
201 /* Weak reference. */
202 bt_self_component
*self_comp
;
206 enum session_not_found_action sess_not_found_act
;
209 size_t max_query_size
;
212 * Keeps track of whether the downstream component already has a
213 * message iterator on this component.
218 struct lttng_live_msg_iter
{
219 bt_logging_level log_level
;
220 bt_self_component
*self_comp
;
222 /* Weak reference. */
223 struct lttng_live_component
*lttng_live_comp
;
225 /* Weak reference. */
226 bt_self_message_iterator
*self_msg_iter
;
229 struct live_viewer_connection
*viewer_connection
;
231 /* Array of pointers to struct lttng_live_session. */
234 /* Number of live stream iterator this message iterator has.*/
235 uint64_t active_stream_iter
;
237 /* Timestamp in nanosecond of the last message sent downstream. */
238 int64_t last_msg_ts_ns
;
241 enum lttng_live_iterator_status
{
242 /** Iterator state has progressed. Continue iteration immediately. */
243 LTTNG_LIVE_ITERATOR_STATUS_CONTINUE
= 3,
244 /** No message available for now. Try again later. */
245 LTTNG_LIVE_ITERATOR_STATUS_AGAIN
= 2,
246 /** No more CTF_LTTNG_LIVEs to be delivered. */
247 LTTNG_LIVE_ITERATOR_STATUS_END
= 1,
248 /** No error, okay. */
249 LTTNG_LIVE_ITERATOR_STATUS_OK
= 0,
250 /** Invalid arguments. */
251 LTTNG_LIVE_ITERATOR_STATUS_INVAL
= -1,
252 /** General error. */
253 LTTNG_LIVE_ITERATOR_STATUS_ERROR
= -2,
254 /** Out of memory. */
255 LTTNG_LIVE_ITERATOR_STATUS_NOMEM
= -3,
256 /** Unsupported iterator feature. */
257 LTTNG_LIVE_ITERATOR_STATUS_UNSUPPORTED
= -4,
260 bt_component_class_init_method_status
lttng_live_component_init(
261 bt_self_component_source
*self_comp
,
262 const bt_value
*params
, void *init_method_data
);
264 bt_component_class_query_method_status
lttng_live_query(
265 bt_self_component_class_source
*comp_class
,
266 const bt_query_executor
*query_exec
,
267 const char *object
, const bt_value
*params
,
268 bt_logging_level log_level
,
269 const bt_value
**result
);
271 void lttng_live_component_finalize(bt_self_component_source
*component
);
273 bt_component_class_message_iterator_next_method_status
lttng_live_msg_iter_next(
274 bt_self_message_iterator
*iterator
,
275 bt_message_array_const msgs
, uint64_t capacity
,
278 bt_component_class_message_iterator_init_method_status
lttng_live_msg_iter_init(
279 bt_self_message_iterator
*self_msg_it
,
280 bt_self_component_source
*self_comp
,
281 bt_self_component_port_output
*self_port
);
283 void lttng_live_msg_iter_finalize(bt_self_message_iterator
*it
);
285 int lttng_live_create_viewer_session(struct lttng_live_msg_iter
*lttng_live_msg_iter
);
286 int lttng_live_attach_session(struct lttng_live_session
*session
);
287 int lttng_live_detach_session(struct lttng_live_session
*session
);
288 enum lttng_live_iterator_status
lttng_live_get_new_streams(
289 struct lttng_live_session
*session
);
291 int lttng_live_add_session(struct lttng_live_msg_iter
*lttng_live_msg_iter
,
293 const char *hostname
,
294 const char *session_name
);
296 ssize_t
lttng_live_get_one_metadata_packet(struct lttng_live_trace
*trace
,
298 enum lttng_live_iterator_status
lttng_live_get_next_index(
299 struct lttng_live_msg_iter
*lttng_live_msg_iter
,
300 struct lttng_live_stream_iterator
*stream
,
301 struct packet_index
*index
);
303 enum bt_msg_iter_medium_status
lttng_live_get_stream_bytes(
304 struct lttng_live_msg_iter
*lttng_live_msg_iter
,
305 struct lttng_live_stream_iterator
*stream
, uint8_t *buf
,
306 uint64_t offset
, uint64_t req_len
, uint64_t *recv_len
);
307 void lttng_live_add_stream_iterator(struct lttng_live_msg_iter
*lttng_live_msg_iter
,
308 struct lttng_live_stream_iterator
*stream_iter
);
309 void lttng_live_remove_stream_iterator(struct lttng_live_msg_iter
*lttng_live_msg_iter
,
310 struct lttng_live_stream_iterator
*stream_iter
);
312 struct lttng_live_trace
*lttng_live_borrow_trace(
313 struct lttng_live_session
*session
, uint64_t trace_id
);
314 void lttng_live_need_new_streams(struct lttng_live_msg_iter
*lttng_live_msg_iter
);
316 bool lttng_live_graph_is_canceled(struct lttng_live_msg_iter
*msg_iter
);
318 #endif /* BABELTRACE_PLUGIN_CTF_LTTNG_LIVE_H */