4 * Babeltrace CTF LTTng-live Client Component
6 * Copyright 2019 Francis Deslauriers <francis.deslauriers@efficios.com>
7 * Copyright 2016 Jérémie Galarneau <jeremie.galarneau@efficios.com>
8 * Copyright 2016 Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
10 * Author: Jérémie Galarneau <jeremie.galarneau@efficios.com>
12 * Permission is hereby granted, free of charge, to any person obtaining a copy
13 * of this software and associated documentation files (the "Software"), to deal
14 * in the Software without restriction, including without limitation the rights
15 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
16 * copies of the Software, and to permit persons to whom the Software is
17 * furnished to do so, subject to the following conditions:
19 * The above copyright notice and this permission notice shall be included in
20 * all copies or substantial portions of the Software.
22 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
23 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
24 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
25 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
26 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
27 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
31 #define BT_COMP_LOG_SELF_COMP self_comp
32 #define BT_LOG_OUTPUT_LEVEL log_level
33 #define BT_LOG_TAG "PLUGIN/SRC.CTF.LTTNG-LIVE"
34 #include "logging/comp-logging.h"
42 #include "common/assert.h"
43 #include <babeltrace2/babeltrace.h>
44 #include "compat/compiler.h"
45 #include <babeltrace2/types.h>
47 #include "plugins/common/muxing/muxing.h"
48 #include "plugins/common/param-validation/param-validation.h"
50 #include "data-stream.h"
52 #include "lttng-live.h"
54 #define MAX_QUERY_SIZE (256*1024)
55 #define URL_PARAM "url"
56 #define INPUTS_PARAM "inputs"
57 #define SESS_NOT_FOUND_ACTION_PARAM "session-not-found-action"
58 #define SESS_NOT_FOUND_ACTION_CONTINUE_STR "continue"
59 #define SESS_NOT_FOUND_ACTION_FAIL_STR "fail"
60 #define SESS_NOT_FOUND_ACTION_END_STR "end"
62 #define print_dbg(fmt, ...) BT_COMP_LOGD(fmt, ## __VA_ARGS__)
65 const char *lttng_live_iterator_status_string(
66 enum lttng_live_iterator_status status
)
69 case LTTNG_LIVE_ITERATOR_STATUS_CONTINUE
:
70 return "LTTNG_LIVE_ITERATOR_STATUS_CONTINUE";
71 case LTTNG_LIVE_ITERATOR_STATUS_AGAIN
:
72 return "LTTNG_LIVE_ITERATOR_STATUS_AGAIN";
73 case LTTNG_LIVE_ITERATOR_STATUS_END
:
74 return "LTTNG_LIVE_ITERATOR_STATUS_END";
75 case LTTNG_LIVE_ITERATOR_STATUS_OK
:
76 return "LTTNG_LIVE_ITERATOR_STATUS_OK";
77 case LTTNG_LIVE_ITERATOR_STATUS_INVAL
:
78 return "LTTNG_LIVE_ITERATOR_STATUS_INVAL";
79 case LTTNG_LIVE_ITERATOR_STATUS_ERROR
:
80 return "LTTNG_LIVE_ITERATOR_STATUS_ERROR";
81 case LTTNG_LIVE_ITERATOR_STATUS_NOMEM
:
82 return "LTTNG_LIVE_ITERATOR_STATUS_NOMEM";
83 case LTTNG_LIVE_ITERATOR_STATUS_UNSUPPORTED
:
84 return "LTTNG_LIVE_ITERATOR_STATUS_UNSUPPORTED";
91 const char *lttng_live_stream_state_string(enum lttng_live_stream_state state
)
94 case LTTNG_LIVE_STREAM_ACTIVE_NO_DATA
:
95 return "ACTIVE_NO_DATA";
96 case LTTNG_LIVE_STREAM_QUIESCENT_NO_DATA
:
97 return "QUIESCENT_NO_DATA";
98 case LTTNG_LIVE_STREAM_QUIESCENT
:
100 case LTTNG_LIVE_STREAM_ACTIVE_DATA
:
101 return "ACTIVE_DATA";
102 case LTTNG_LIVE_STREAM_EOF
:
109 #define LTTNG_LIVE_LOGD_STREAM_ITER(live_stream_iter) \
111 BT_COMP_LOGD("Live stream iterator state=%s, last-inact-ts=%" PRId64 \
112 ", curr-inact-ts %" PRId64, \
113 lttng_live_stream_state_string(live_stream_iter->state), \
114 live_stream_iter->last_inactivity_ts, \
115 live_stream_iter->current_inactivity_ts); \
119 bool lttng_live_graph_is_canceled(struct lttng_live_msg_iter
*msg_iter
)
128 ret
= bt_self_message_iterator_is_interrupted(
129 msg_iter
->self_msg_iter
);
136 struct lttng_live_trace
*lttng_live_find_trace(struct lttng_live_session
*session
,
140 struct lttng_live_trace
*ret_trace
= NULL
;
142 for (trace_idx
= 0; trace_idx
< session
->traces
->len
; trace_idx
++) {
143 struct lttng_live_trace
*trace
=
144 g_ptr_array_index(session
->traces
, trace_idx
);
145 if (trace
->id
== trace_id
) {
156 void lttng_live_destroy_trace(struct lttng_live_trace
*trace
)
158 bt_logging_level log_level
= trace
->log_level
;
159 bt_self_component
*self_comp
= trace
->self_comp
;
161 BT_COMP_LOGD("Destroying live trace: trace-id=%"PRIu64
, trace
->id
);
163 BT_ASSERT(trace
->stream_iterators
);
164 g_ptr_array_free(trace
->stream_iterators
, TRUE
);
166 BT_TRACE_PUT_REF_AND_RESET(trace
->trace
);
167 BT_TRACE_CLASS_PUT_REF_AND_RESET(trace
->trace_class
);
169 lttng_live_metadata_fini(trace
);
174 struct lttng_live_trace
*lttng_live_create_trace(struct lttng_live_session
*session
,
177 struct lttng_live_trace
*trace
= NULL
;
178 bt_logging_level log_level
= session
->log_level
;
179 bt_self_component
*self_comp
= session
->self_comp
;
181 BT_COMP_LOGD("Creating live trace: "
182 "session-id=%"PRIu64
", trace-id=%"PRIu64
,
183 session
->id
, trace_id
);
184 trace
= g_new0(struct lttng_live_trace
, 1);
186 BT_COMP_LOGE_APPEND_CAUSE(self_comp
,
187 "Failed to allocate live trace");
190 trace
->log_level
= session
->log_level
;
191 trace
->self_comp
= session
->self_comp
;
192 trace
->session
= session
;
193 trace
->id
= trace_id
;
194 trace
->trace_class
= NULL
;
196 trace
->stream_iterators
= g_ptr_array_new_with_free_func(
197 (GDestroyNotify
) lttng_live_stream_iterator_destroy
);
198 BT_ASSERT(trace
->stream_iterators
);
199 trace
->new_metadata_needed
= true;
200 g_ptr_array_add(session
->traces
, trace
);
211 struct lttng_live_trace
*lttng_live_borrow_trace(
212 struct lttng_live_session
*session
, uint64_t trace_id
)
214 struct lttng_live_trace
*trace
;
216 trace
= lttng_live_find_trace(session
, trace_id
);
221 /* The session is the owner of the newly created trace. */
222 trace
= lttng_live_create_trace(session
, trace_id
);
229 int lttng_live_add_session(struct lttng_live_msg_iter
*lttng_live_msg_iter
,
230 uint64_t session_id
, const char *hostname
,
231 const char *session_name
)
234 struct lttng_live_session
*session
;
235 bt_logging_level log_level
= lttng_live_msg_iter
->log_level
;
236 bt_self_component
*self_comp
= lttng_live_msg_iter
->self_comp
;
238 BT_COMP_LOGD("Adding live session: "
239 "session-id=%" PRIu64
", hostname=\"%s\" session-name=\"%s\"",
240 session_id
, hostname
, session_name
);
242 session
= g_new0(struct lttng_live_session
, 1);
244 BT_COMP_LOGE_APPEND_CAUSE(self_comp
,
245 "Failed to allocate live session");
249 session
->log_level
= lttng_live_msg_iter
->log_level
;
250 session
->self_comp
= lttng_live_msg_iter
->self_comp
;
251 session
->id
= session_id
;
252 session
->traces
= g_ptr_array_new_with_free_func(
253 (GDestroyNotify
) lttng_live_destroy_trace
);
254 BT_ASSERT(session
->traces
);
255 session
->lttng_live_msg_iter
= lttng_live_msg_iter
;
256 session
->new_streams_needed
= true;
257 session
->hostname
= g_string_new(hostname
);
258 BT_ASSERT(session
->hostname
);
260 session
->session_name
= g_string_new(session_name
);
261 BT_ASSERT(session
->session_name
);
263 g_ptr_array_add(lttng_live_msg_iter
->sessions
, session
);
273 void lttng_live_destroy_session(struct lttng_live_session
*session
)
275 bt_logging_level log_level
;
276 bt_self_component
*self_comp
;
282 log_level
= session
->log_level
;
283 self_comp
= session
->self_comp
;
284 BT_COMP_LOGD("Destroying live session: "
285 "session-id=%"PRIu64
", session-name=\"%s\"",
286 session
->id
, session
->session_name
->str
);
287 if (session
->id
!= -1ULL) {
288 if (lttng_live_detach_session(session
)) {
289 if (!lttng_live_graph_is_canceled(
290 session
->lttng_live_msg_iter
)) {
291 /* Old relayd cannot detach sessions. */
292 BT_COMP_LOGD("Unable to detach lttng live session %" PRIu64
,
299 if (session
->traces
) {
300 g_ptr_array_free(session
->traces
, TRUE
);
303 if (session
->hostname
) {
304 g_string_free(session
->hostname
, TRUE
);
306 if (session
->session_name
) {
307 g_string_free(session
->session_name
, TRUE
);
316 void lttng_live_msg_iter_destroy(struct lttng_live_msg_iter
*lttng_live_msg_iter
)
318 if (!lttng_live_msg_iter
) {
322 if (lttng_live_msg_iter
->sessions
) {
323 g_ptr_array_free(lttng_live_msg_iter
->sessions
, TRUE
);
326 if (lttng_live_msg_iter
->viewer_connection
) {
327 live_viewer_connection_destroy(lttng_live_msg_iter
->viewer_connection
);
329 BT_ASSERT(lttng_live_msg_iter
->lttng_live_comp
);
330 BT_ASSERT(lttng_live_msg_iter
->lttng_live_comp
->has_msg_iter
);
332 /* All stream iterators must be destroyed at this point. */
333 BT_ASSERT(lttng_live_msg_iter
->active_stream_iter
== 0);
334 lttng_live_msg_iter
->lttng_live_comp
->has_msg_iter
= false;
336 g_free(lttng_live_msg_iter
);
343 void lttng_live_msg_iter_finalize(bt_self_message_iterator
*self_msg_iter
)
345 struct lttng_live_msg_iter
*lttng_live_msg_iter
;
347 BT_ASSERT(self_msg_iter
);
349 lttng_live_msg_iter
= bt_self_message_iterator_get_data(self_msg_iter
);
350 BT_ASSERT(lttng_live_msg_iter
);
351 lttng_live_msg_iter_destroy(lttng_live_msg_iter
);
355 enum lttng_live_iterator_status
lttng_live_iterator_next_check_stream_state(
356 struct lttng_live_stream_iterator
*lttng_live_stream
)
358 bt_logging_level log_level
= lttng_live_stream
->log_level
;
359 bt_self_component
*self_comp
= lttng_live_stream
->self_comp
;
361 switch (lttng_live_stream
->state
) {
362 case LTTNG_LIVE_STREAM_QUIESCENT
:
363 case LTTNG_LIVE_STREAM_ACTIVE_DATA
:
365 case LTTNG_LIVE_STREAM_ACTIVE_NO_DATA
:
367 BT_COMP_LOGF("Unexpected stream state \"ACTIVE_NO_DATA\"");
369 case LTTNG_LIVE_STREAM_QUIESCENT_NO_DATA
:
371 BT_COMP_LOGF("Unexpected stream state \"QUIESCENT_NO_DATA\"");
373 case LTTNG_LIVE_STREAM_EOF
:
376 return LTTNG_LIVE_ITERATOR_STATUS_OK
;
380 * For active no data stream, fetch next data. It can be either:
381 * - quiescent: need to put it in the prio heap at quiescent end
383 * - have data: need to wire up first event into the prio heap,
384 * - have no data on this stream at this point: need to retry (AGAIN) or
388 enum lttng_live_iterator_status
lttng_live_iterator_next_handle_one_no_data_stream(
389 struct lttng_live_msg_iter
*lttng_live_msg_iter
,
390 struct lttng_live_stream_iterator
*lttng_live_stream
)
392 bt_logging_level log_level
= lttng_live_msg_iter
->log_level
;
393 bt_self_component
*self_comp
= lttng_live_msg_iter
->self_comp
;
394 enum lttng_live_iterator_status ret
= LTTNG_LIVE_ITERATOR_STATUS_OK
;
395 enum lttng_live_stream_state orig_state
= lttng_live_stream
->state
;
396 struct packet_index index
;
398 if (lttng_live_stream
->trace
->new_metadata_needed
) {
399 ret
= LTTNG_LIVE_ITERATOR_STATUS_CONTINUE
;
402 if (lttng_live_stream
->trace
->session
->new_streams_needed
) {
403 ret
= LTTNG_LIVE_ITERATOR_STATUS_CONTINUE
;
406 if (lttng_live_stream
->state
!= LTTNG_LIVE_STREAM_ACTIVE_NO_DATA
&&
407 lttng_live_stream
->state
!= LTTNG_LIVE_STREAM_QUIESCENT_NO_DATA
) {
410 ret
= lttng_live_get_next_index(lttng_live_msg_iter
, lttng_live_stream
,
412 if (ret
!= LTTNG_LIVE_ITERATOR_STATUS_OK
) {
415 BT_ASSERT_DBG(lttng_live_stream
->state
!= LTTNG_LIVE_STREAM_EOF
);
416 if (lttng_live_stream
->state
== LTTNG_LIVE_STREAM_QUIESCENT
) {
417 uint64_t last_inact_ts
= lttng_live_stream
->last_inactivity_ts
,
418 curr_inact_ts
= lttng_live_stream
->current_inactivity_ts
;
420 if (orig_state
== LTTNG_LIVE_STREAM_QUIESCENT_NO_DATA
&&
421 last_inact_ts
== curr_inact_ts
) {
422 ret
= LTTNG_LIVE_ITERATOR_STATUS_AGAIN
;
423 LTTNG_LIVE_LOGD_STREAM_ITER(lttng_live_stream
);
425 ret
= LTTNG_LIVE_ITERATOR_STATUS_CONTINUE
;
429 lttng_live_stream
->base_offset
= index
.offset
;
430 lttng_live_stream
->offset
= index
.offset
;
431 lttng_live_stream
->len
= index
.packet_size
/ CHAR_BIT
;
433 if (ret
== LTTNG_LIVE_ITERATOR_STATUS_OK
) {
434 ret
= lttng_live_iterator_next_check_stream_state(lttng_live_stream
);
440 * Creation of the message requires the ctf trace class to be created
441 * beforehand, but the live protocol gives us all streams (including metadata)
442 * at once. So we split it in three steps: getting streams, getting metadata
443 * (which creates the ctf trace class), and then creating the per-stream
447 enum lttng_live_iterator_status
lttng_live_get_session(
448 struct lttng_live_msg_iter
*lttng_live_msg_iter
,
449 struct lttng_live_session
*session
)
451 bt_logging_level log_level
= lttng_live_msg_iter
->log_level
;
452 bt_self_component
*self_comp
= lttng_live_msg_iter
->self_comp
;
453 enum lttng_live_iterator_status status
;
456 BT_COMP_LOGD("Updating all streams for session: "
457 "session-id=%"PRIu64
", session-name=\"%s\"",
458 session
->id
, session
->session_name
->str
);
460 if (!session
->attached
) {
461 enum lttng_live_viewer_status attach_status
=
462 lttng_live_attach_session(session
,
463 lttng_live_msg_iter
->self_msg_iter
);
464 if (attach_status
!= LTTNG_LIVE_VIEWER_STATUS_OK
) {
465 if (lttng_live_graph_is_canceled(lttng_live_msg_iter
)) {
467 * Clear any causes appended in
468 * `lttng_live_attach_session()` as we want to
469 * return gracefully since the graph was
472 bt_current_thread_clear_error();
473 status
= LTTNG_LIVE_ITERATOR_STATUS_AGAIN
;
475 status
= LTTNG_LIVE_ITERATOR_STATUS_ERROR
;
476 BT_COMP_LOGE_APPEND_CAUSE(self_comp
,
477 "Error attaching to LTTng live session");
483 status
= lttng_live_get_new_streams(session
,
484 lttng_live_msg_iter
->self_msg_iter
);
485 if (status
!= LTTNG_LIVE_ITERATOR_STATUS_OK
&&
486 status
!= LTTNG_LIVE_ITERATOR_STATUS_END
) {
490 while (trace_idx
< session
->traces
->len
) {
491 struct lttng_live_trace
*trace
=
492 g_ptr_array_index(session
->traces
, trace_idx
);
494 status
= lttng_live_metadata_update(trace
);
496 case LTTNG_LIVE_ITERATOR_STATUS_END
:
497 case LTTNG_LIVE_ITERATOR_STATUS_OK
:
500 case LTTNG_LIVE_ITERATOR_STATUS_CONTINUE
:
501 case LTTNG_LIVE_ITERATOR_STATUS_AGAIN
:
504 BT_COMP_LOGE_APPEND_CAUSE(self_comp
,
505 "Error updating trace metadata: "
506 "stream-iter-status=%s, trace-id=%"PRIu64
,
507 lttng_live_iterator_status_string(status
),
512 status
= lttng_live_lazy_msg_init(session
,
513 lttng_live_msg_iter
->self_msg_iter
);
520 void lttng_live_need_new_streams(struct lttng_live_msg_iter
*lttng_live_msg_iter
)
522 uint64_t session_idx
;
524 for (session_idx
= 0; session_idx
< lttng_live_msg_iter
->sessions
->len
;
526 struct lttng_live_session
*session
=
527 g_ptr_array_index(lttng_live_msg_iter
->sessions
, session_idx
);
528 session
->new_streams_needed
= true;
533 void lttng_live_force_new_streams_and_metadata(struct lttng_live_msg_iter
*lttng_live_msg_iter
)
535 uint64_t session_idx
, trace_idx
;
537 for (session_idx
= 0; session_idx
< lttng_live_msg_iter
->sessions
->len
;
539 struct lttng_live_session
*session
=
540 g_ptr_array_index(lttng_live_msg_iter
->sessions
, session_idx
);
541 session
->new_streams_needed
= true;
542 for (trace_idx
= 0; trace_idx
< session
->traces
->len
;
544 struct lttng_live_trace
*trace
=
545 g_ptr_array_index(session
->traces
, trace_idx
);
546 trace
->new_metadata_needed
= true;
552 enum lttng_live_iterator_status
553 lttng_live_iterator_handle_new_streams_and_metadata(
554 struct lttng_live_msg_iter
*lttng_live_msg_iter
)
556 enum lttng_live_iterator_status status
;
557 enum lttng_live_viewer_status viewer_status
;
558 bt_logging_level log_level
= lttng_live_msg_iter
->log_level
;
559 bt_self_component
*self_comp
= lttng_live_msg_iter
->self_comp
;
560 uint64_t session_idx
= 0, nr_sessions_opened
= 0;
561 struct lttng_live_session
*session
;
562 enum session_not_found_action sess_not_found_act
=
563 lttng_live_msg_iter
->lttng_live_comp
->params
.sess_not_found_act
;
565 BT_COMP_LOGD("Update data and metadata of all sessions"
566 "live-msg-iter-addr=%p", lttng_live_msg_iter
);
568 * In a remotely distant future, we could add a "new
569 * session" flag to the protocol, which would tell us that we
570 * need to query for new sessions even though we have sessions
573 if (lttng_live_msg_iter
->sessions
->len
== 0) {
574 if (sess_not_found_act
!= SESSION_NOT_FOUND_ACTION_CONTINUE
) {
575 BT_COMP_LOGD("No session found. Exiting in accordance with the `session-not-found-action` parameter");
576 status
= LTTNG_LIVE_ITERATOR_STATUS_END
;
579 BT_COMP_LOGD("No session found. Try creating a new one in accordance with the `session-not-found-action` parameter");
581 * Retry to create a viewer session for the requested
584 viewer_status
= lttng_live_create_viewer_session(lttng_live_msg_iter
);
585 if (viewer_status
!= LTTNG_LIVE_VIEWER_STATUS_OK
) {
586 if (viewer_status
== LTTNG_LIVE_VIEWER_STATUS_ERROR
) {
587 status
= LTTNG_LIVE_ITERATOR_STATUS_ERROR
;
588 BT_COMP_LOGE_APPEND_CAUSE(self_comp
,
589 "Error creating LTTng live viewer session");
590 } else if (viewer_status
== LTTNG_LIVE_VIEWER_STATUS_INTERRUPTED
) {
591 status
= LTTNG_LIVE_ITERATOR_STATUS_AGAIN
;
600 for (session_idx
= 0; session_idx
< lttng_live_msg_iter
->sessions
->len
;
602 session
= g_ptr_array_index(lttng_live_msg_iter
->sessions
,
604 status
= lttng_live_get_session(lttng_live_msg_iter
, session
);
606 case LTTNG_LIVE_ITERATOR_STATUS_OK
:
608 case LTTNG_LIVE_ITERATOR_STATUS_END
:
609 status
= LTTNG_LIVE_ITERATOR_STATUS_OK
;
614 if (!session
->closed
) {
615 nr_sessions_opened
++;
619 if (sess_not_found_act
!= SESSION_NOT_FOUND_ACTION_CONTINUE
&&
620 nr_sessions_opened
== 0) {
621 status
= LTTNG_LIVE_ITERATOR_STATUS_END
;
623 status
= LTTNG_LIVE_ITERATOR_STATUS_OK
;
631 enum lttng_live_iterator_status
emit_inactivity_message(
632 struct lttng_live_msg_iter
*lttng_live_msg_iter
,
633 struct lttng_live_stream_iterator
*stream_iter
,
634 bt_message
**message
, uint64_t timestamp
)
636 enum lttng_live_iterator_status ret
= LTTNG_LIVE_ITERATOR_STATUS_OK
;
637 bt_logging_level log_level
= lttng_live_msg_iter
->log_level
;
638 bt_self_component
*self_comp
= lttng_live_msg_iter
->self_comp
;
639 bt_message
*msg
= NULL
;
641 BT_ASSERT(stream_iter
->trace
->clock_class
);
643 msg
= bt_message_message_iterator_inactivity_create(
644 lttng_live_msg_iter
->self_msg_iter
,
645 stream_iter
->trace
->clock_class
, timestamp
);
647 BT_COMP_LOGE_APPEND_CAUSE(self_comp
,
648 "Error emitting message iterator inactivity message");
657 ret
= LTTNG_LIVE_ITERATOR_STATUS_ERROR
;
658 bt_message_put_ref(msg
);
663 enum lttng_live_iterator_status
lttng_live_iterator_next_handle_one_quiescent_stream(
664 struct lttng_live_msg_iter
*lttng_live_msg_iter
,
665 struct lttng_live_stream_iterator
*lttng_live_stream
,
666 bt_message
**message
)
668 enum lttng_live_iterator_status ret
= LTTNG_LIVE_ITERATOR_STATUS_OK
;
670 if (lttng_live_stream
->state
!= LTTNG_LIVE_STREAM_QUIESCENT
) {
671 return LTTNG_LIVE_ITERATOR_STATUS_OK
;
674 if (lttng_live_stream
->current_inactivity_ts
==
675 lttng_live_stream
->last_inactivity_ts
) {
676 lttng_live_stream
->state
= LTTNG_LIVE_STREAM_QUIESCENT_NO_DATA
;
677 ret
= LTTNG_LIVE_ITERATOR_STATUS_CONTINUE
;
681 ret
= emit_inactivity_message(lttng_live_msg_iter
, lttng_live_stream
,
682 message
, lttng_live_stream
->current_inactivity_ts
);
684 lttng_live_stream
->last_inactivity_ts
=
685 lttng_live_stream
->current_inactivity_ts
;
691 int live_get_msg_ts_ns(struct lttng_live_stream_iterator
*stream_iter
,
692 struct lttng_live_msg_iter
*lttng_live_msg_iter
,
693 const bt_message
*msg
, int64_t last_msg_ts_ns
,
696 const bt_clock_class
*clock_class
= NULL
;
697 const bt_clock_snapshot
*clock_snapshot
= NULL
;
699 bt_logging_level log_level
= lttng_live_msg_iter
->log_level
;
700 bt_self_component
*self_comp
= lttng_live_msg_iter
->self_comp
;
703 BT_ASSERT_DBG(ts_ns
);
705 BT_COMP_LOGD("Getting message's timestamp: iter-data-addr=%p, msg-addr=%p, "
706 "last-msg-ts=%" PRId64
, lttng_live_msg_iter
, msg
,
709 switch (bt_message_get_type(msg
)) {
710 case BT_MESSAGE_TYPE_EVENT
:
711 clock_class
= bt_message_event_borrow_stream_class_default_clock_class_const(
713 BT_ASSERT_DBG(clock_class
);
715 clock_snapshot
= bt_message_event_borrow_default_clock_snapshot_const(
718 case BT_MESSAGE_TYPE_PACKET_BEGINNING
:
719 clock_class
= bt_message_packet_beginning_borrow_stream_class_default_clock_class_const(
721 BT_ASSERT(clock_class
);
723 clock_snapshot
= bt_message_packet_beginning_borrow_default_clock_snapshot_const(
726 case BT_MESSAGE_TYPE_PACKET_END
:
727 clock_class
= bt_message_packet_end_borrow_stream_class_default_clock_class_const(
729 BT_ASSERT(clock_class
);
731 clock_snapshot
= bt_message_packet_end_borrow_default_clock_snapshot_const(
734 case BT_MESSAGE_TYPE_DISCARDED_EVENTS
:
735 clock_class
= bt_message_discarded_events_borrow_stream_class_default_clock_class_const(
737 BT_ASSERT(clock_class
);
739 clock_snapshot
= bt_message_discarded_events_borrow_beginning_default_clock_snapshot_const(
742 case BT_MESSAGE_TYPE_DISCARDED_PACKETS
:
743 clock_class
= bt_message_discarded_packets_borrow_stream_class_default_clock_class_const(
745 BT_ASSERT(clock_class
);
747 clock_snapshot
= bt_message_discarded_packets_borrow_beginning_default_clock_snapshot_const(
750 case BT_MESSAGE_TYPE_MESSAGE_ITERATOR_INACTIVITY
:
751 clock_snapshot
= bt_message_message_iterator_inactivity_borrow_default_clock_snapshot_const(
755 /* All the other messages have a higher priority */
756 BT_COMP_LOGD_STR("Message has no timestamp: using the last message timestamp.");
757 *ts_ns
= last_msg_ts_ns
;
761 clock_class
= bt_clock_snapshot_borrow_clock_class_const(clock_snapshot
);
762 BT_ASSERT_DBG(clock_class
);
764 ret
= bt_clock_snapshot_get_ns_from_origin(clock_snapshot
, ts_ns
);
766 BT_COMP_LOGE_APPEND_CAUSE(self_comp
,
767 "Cannot get nanoseconds from Epoch of clock snapshot: "
768 "clock-snapshot-addr=%p", clock_snapshot
);
779 BT_COMP_LOGD("Found message's timestamp: "
780 "iter-data-addr=%p, msg-addr=%p, "
781 "last-msg-ts=%" PRId64
", ts=%" PRId64
,
782 lttng_live_msg_iter
, msg
, last_msg_ts_ns
, *ts_ns
);
789 enum lttng_live_iterator_status
lttng_live_iterator_next_handle_one_active_data_stream(
790 struct lttng_live_msg_iter
*lttng_live_msg_iter
,
791 struct lttng_live_stream_iterator
*lttng_live_stream
,
792 bt_message
**message
)
794 enum lttng_live_iterator_status ret
= LTTNG_LIVE_ITERATOR_STATUS_OK
;
795 bt_logging_level log_level
= lttng_live_msg_iter
->log_level
;
796 bt_self_component
*self_comp
= lttng_live_msg_iter
->self_comp
;
797 enum ctf_msg_iter_status status
;
798 uint64_t session_idx
, trace_idx
;
800 for (session_idx
= 0; session_idx
< lttng_live_msg_iter
->sessions
->len
;
802 struct lttng_live_session
*session
=
803 g_ptr_array_index(lttng_live_msg_iter
->sessions
, session_idx
);
805 if (session
->new_streams_needed
) {
806 ret
= LTTNG_LIVE_ITERATOR_STATUS_CONTINUE
;
809 for (trace_idx
= 0; trace_idx
< session
->traces
->len
;
811 struct lttng_live_trace
*trace
=
812 g_ptr_array_index(session
->traces
, trace_idx
);
813 if (trace
->new_metadata_needed
) {
814 ret
= LTTNG_LIVE_ITERATOR_STATUS_CONTINUE
;
820 if (lttng_live_stream
->state
!= LTTNG_LIVE_STREAM_ACTIVE_DATA
) {
821 ret
= LTTNG_LIVE_ITERATOR_STATUS_ERROR
;
822 BT_COMP_LOGE_APPEND_CAUSE(self_comp
,
823 "Invalid state of live stream iterator"
824 "stream-iter-status=%s",
825 lttng_live_stream_state_string(lttng_live_stream
->state
));
829 status
= ctf_msg_iter_get_next_message(
830 lttng_live_stream
->msg_iter
, message
);
832 case CTF_MSG_ITER_STATUS_EOF
:
833 ret
= LTTNG_LIVE_ITERATOR_STATUS_END
;
835 case CTF_MSG_ITER_STATUS_OK
:
836 ret
= LTTNG_LIVE_ITERATOR_STATUS_OK
;
838 case CTF_MSG_ITER_STATUS_AGAIN
:
840 * Continue immediately (end of packet). The next
841 * get_index may return AGAIN to delay the following
844 ret
= LTTNG_LIVE_ITERATOR_STATUS_CONTINUE
;
846 case CTF_MSG_ITER_STATUS_INVAL
:
847 /* No argument provided by the user, so don't return INVAL. */
848 case CTF_MSG_ITER_STATUS_ERROR
:
850 ret
= LTTNG_LIVE_ITERATOR_STATUS_ERROR
;
851 BT_COMP_LOGE_APPEND_CAUSE(self_comp
,
852 "CTF message iterator failed to get next message: "
853 "msg-iter=%p, msg-iter-status=%s",
854 lttng_live_stream
->msg_iter
,
855 ctf_msg_iter_status_string(status
));
864 enum lttng_live_iterator_status
lttng_live_iterator_close_stream(
865 struct lttng_live_msg_iter
*lttng_live_msg_iter
,
866 struct lttng_live_stream_iterator
*stream_iter
,
867 bt_message
**curr_msg
)
869 enum lttng_live_iterator_status live_status
=
870 LTTNG_LIVE_ITERATOR_STATUS_OK
;
871 bt_logging_level log_level
= lttng_live_msg_iter
->log_level
;
872 bt_self_component
*self_comp
= lttng_live_msg_iter
->self_comp
;
874 * The viewer has hung up on us so we are closing the stream. The
875 * `ctf_msg_iter` should simply realize that it needs to close the
876 * stream properly by emitting the necessary stream end message.
878 enum ctf_msg_iter_status status
= ctf_msg_iter_get_next_message(
879 stream_iter
->msg_iter
, curr_msg
);
881 if (status
== CTF_MSG_ITER_STATUS_ERROR
) {
882 BT_COMP_LOGE_APPEND_CAUSE(self_comp
,
883 "Error getting the next message from CTF message iterator");
884 live_status
= LTTNG_LIVE_ITERATOR_STATUS_ERROR
;
888 BT_ASSERT(status
== CTF_MSG_ITER_STATUS_OK
);
896 * handle_no_data_streams()
898 * - for each ACTIVE_NO_DATA stream:
899 * - query relayd for stream data, or quiescence info.
900 * - if need metadata, get metadata, goto retry.
901 * - if new stream, get new stream as ACTIVE_NO_DATA, goto retry
902 * - if quiescent, move to QUIESCENT streams
903 * - if fetched data, move to ACTIVE_DATA streams
904 * (at this point each stream either has data, or is quiescent)
908 * handle_new_streams_and_metadata()
909 * - query relayd for known streams, add them as ACTIVE_NO_DATA
910 * - query relayd for metadata
912 * call handle_active_no_data_streams()
914 * handle_quiescent_streams()
915 * - if at least one stream is ACTIVE_DATA:
916 * - peek stream event with lowest timestamp -> next_ts
917 * - for each quiescent stream
918 * - if next_ts >= quiescent end
919 * - set state to ACTIVE_NO_DATA
921 * - for each quiescent stream
922 * - set state to ACTIVE_NO_DATA
924 * call handle_active_no_data_streams()
926 * handle_active_data_streams()
927 * - if at least one stream is ACTIVE_DATA:
928 * - get stream event with lowest timestamp from heap
929 * - make that stream event the current message.
930 * - move this stream heap position to its next event
931 * - if we need to fetch data from relayd, move
932 * stream to ACTIVE_NO_DATA.
936 * end criterion: ctrl-c on client. If relayd exits or the session
937 * closes on the relay daemon side, we keep on waiting for streams.
938 * Eventually handle --end timestamp (also an end criterion).
940 * When disconnected from relayd: try to re-connect endlessly.
943 enum lttng_live_iterator_status
lttng_live_iterator_next_msg_on_stream(
944 struct lttng_live_msg_iter
*lttng_live_msg_iter
,
945 struct lttng_live_stream_iterator
*stream_iter
,
946 bt_message
**curr_msg
)
948 bt_logging_level log_level
= lttng_live_msg_iter
->log_level
;
949 bt_self_component
*self_comp
= lttng_live_msg_iter
->self_comp
;
950 enum lttng_live_iterator_status live_status
;
952 BT_COMP_LOGD("Finding the next message for stream iterator: "
953 "stream-name=\"%s\"", stream_iter
->name
->str
);
955 if (stream_iter
->has_stream_hung_up
) {
957 * The stream has hung up and the stream was properly closed
958 * during the last call to the current function. Return _END
959 * status now so that this stream iterator is removed for the
960 * stream iterator list.
962 live_status
= LTTNG_LIVE_ITERATOR_STATUS_END
;
967 LTTNG_LIVE_LOGD_STREAM_ITER(stream_iter
);
968 live_status
= lttng_live_iterator_handle_new_streams_and_metadata(
969 lttng_live_msg_iter
);
970 if (live_status
!= LTTNG_LIVE_ITERATOR_STATUS_OK
) {
973 live_status
= lttng_live_iterator_next_handle_one_no_data_stream(
974 lttng_live_msg_iter
, stream_iter
);
976 if (live_status
!= LTTNG_LIVE_ITERATOR_STATUS_OK
) {
977 if (live_status
== LTTNG_LIVE_ITERATOR_STATUS_END
) {
979 * We overwrite `live_status` since `curr_msg` is
980 * likely set to a valid message in this function.
982 live_status
= lttng_live_iterator_close_stream(
983 lttng_live_msg_iter
, stream_iter
, curr_msg
);
987 live_status
= lttng_live_iterator_next_handle_one_quiescent_stream(
988 lttng_live_msg_iter
, stream_iter
, curr_msg
);
989 if (live_status
!= LTTNG_LIVE_ITERATOR_STATUS_OK
) {
990 BT_ASSERT(!*curr_msg
);
996 live_status
= lttng_live_iterator_next_handle_one_active_data_stream(
997 lttng_live_msg_iter
, stream_iter
, curr_msg
);
998 if (live_status
!= LTTNG_LIVE_ITERATOR_STATUS_OK
) {
999 BT_ASSERT(!*curr_msg
);
1003 if (live_status
== LTTNG_LIVE_ITERATOR_STATUS_CONTINUE
) {
1011 enum lttng_live_iterator_status
next_stream_iterator_for_trace(
1012 struct lttng_live_msg_iter
*lttng_live_msg_iter
,
1013 struct lttng_live_trace
*live_trace
,
1014 struct lttng_live_stream_iterator
**youngest_trace_stream_iter
)
1016 struct lttng_live_stream_iterator
*youngest_candidate_stream_iter
= NULL
;
1017 bt_logging_level log_level
= lttng_live_msg_iter
->log_level
;
1018 bt_self_component
*self_comp
= lttng_live_msg_iter
->self_comp
;
1019 enum lttng_live_iterator_status stream_iter_status
;;
1020 int64_t youngest_candidate_msg_ts
= INT64_MAX
;
1021 uint64_t stream_iter_idx
;
1023 BT_ASSERT_DBG(live_trace
);
1024 BT_ASSERT_DBG(live_trace
->stream_iterators
);
1026 BT_COMP_LOGD("Finding the next stream iterator for trace: "
1027 "trace-id=%"PRIu64
, live_trace
->id
);
1029 * Update the current message of every stream iterators of this trace.
1030 * The current msg of every stream must have a timestamp equal or
1031 * larger than the last message returned by this iterator. We must
1032 * ensure monotonicity.
1034 stream_iter_idx
= 0;
1035 while (stream_iter_idx
< live_trace
->stream_iterators
->len
) {
1036 bool stream_iter_is_ended
= false;
1037 struct lttng_live_stream_iterator
*stream_iter
=
1038 g_ptr_array_index(live_trace
->stream_iterators
,
1042 * Find if there is are now current message for this stream
1045 while (!stream_iter
->current_msg
) {
1046 bt_message
*msg
= NULL
;
1047 int64_t curr_msg_ts_ns
= INT64_MAX
;
1048 stream_iter_status
= lttng_live_iterator_next_msg_on_stream(
1049 lttng_live_msg_iter
, stream_iter
, &msg
);
1051 BT_COMP_LOGD("live stream iterator returned status :%s",
1052 lttng_live_iterator_status_string(stream_iter_status
));
1053 if (stream_iter_status
== LTTNG_LIVE_ITERATOR_STATUS_END
) {
1054 stream_iter_is_ended
= true;
1058 if (stream_iter_status
!= LTTNG_LIVE_ITERATOR_STATUS_OK
) {
1065 * Get the timestamp in nanoseconds from origin of this
1068 live_get_msg_ts_ns(stream_iter
, lttng_live_msg_iter
,
1069 msg
, lttng_live_msg_iter
->last_msg_ts_ns
,
1073 * Check if the message of the current live stream
1074 * iterator occured at the exact same time or after the
1075 * last message returned by this component's message
1076 * iterator. If not, we return an error.
1078 if (curr_msg_ts_ns
>= lttng_live_msg_iter
->last_msg_ts_ns
) {
1079 stream_iter
->current_msg
= msg
;
1080 stream_iter
->current_msg_ts_ns
= curr_msg_ts_ns
;
1083 * We received a message in the past. To ensure
1084 * monotonicity, we can't send it forward.
1086 BT_COMP_LOGE_APPEND_CAUSE(self_comp
,
1087 "Message's timestamp is less than "
1088 "lttng-live's message iterator's last "
1089 "returned timestamp: "
1090 "lttng-live-msg-iter-addr=%p, ts=%" PRId64
", "
1091 "last-msg-ts=%" PRId64
,
1092 lttng_live_msg_iter
, curr_msg_ts_ns
,
1093 lttng_live_msg_iter
->last_msg_ts_ns
);
1094 stream_iter_status
= LTTNG_LIVE_ITERATOR_STATUS_ERROR
;
1099 BT_ASSERT_DBG(stream_iter
!= youngest_candidate_stream_iter
);
1101 if (!stream_iter_is_ended
) {
1102 if (G_UNLIKELY(youngest_candidate_stream_iter
== NULL
) ||
1103 stream_iter
->current_msg_ts_ns
< youngest_candidate_msg_ts
) {
1105 * Update the current best candidate message
1106 * for the stream iterator of this live trace
1107 * to be forwarded downstream.
1109 youngest_candidate_msg_ts
= stream_iter
->current_msg_ts_ns
;
1110 youngest_candidate_stream_iter
= stream_iter
;
1111 } else if (stream_iter
->current_msg_ts_ns
== youngest_candidate_msg_ts
) {
1113 * Order the messages in an arbitrary but
1114 * deterministic way.
1116 BT_ASSERT_DBG(stream_iter
!= youngest_candidate_stream_iter
);
1117 int ret
= common_muxing_compare_messages(
1118 stream_iter
->current_msg
,
1119 youngest_candidate_stream_iter
->current_msg
);
1122 * The `youngest_candidate_stream_iter->current_msg`
1123 * should go first. Update the next
1124 * iterator and the current timestamp.
1126 youngest_candidate_msg_ts
= stream_iter
->current_msg_ts_ns
;
1127 youngest_candidate_stream_iter
= stream_iter
;
1128 } else if (ret
== 0) {
1130 * Unable to pick which one should go
1133 BT_COMP_LOGW("Cannot deterministically pick next live stream message iterator because they have identical next messages: "
1134 "stream-iter-addr=%p"
1135 "stream-iter-addr=%p",
1137 youngest_candidate_stream_iter
);
1144 * The live stream iterator has ended. That
1145 * iterator is removed from the array, but
1146 * there is no need to increment
1147 * stream_iter_idx as
1148 * g_ptr_array_remove_index_fast replaces the
1149 * removed element with the array's last
1152 g_ptr_array_remove_index_fast(
1153 live_trace
->stream_iterators
,
1158 if (youngest_candidate_stream_iter
) {
1159 *youngest_trace_stream_iter
= youngest_candidate_stream_iter
;
1160 stream_iter_status
= LTTNG_LIVE_ITERATOR_STATUS_OK
;
1163 * The only case where we don't have a candidate for this trace
1164 * is if we reached the end of all the iterators.
1166 BT_ASSERT(live_trace
->stream_iterators
->len
== 0);
1167 stream_iter_status
= LTTNG_LIVE_ITERATOR_STATUS_END
;
1171 return stream_iter_status
;
1175 enum lttng_live_iterator_status
next_stream_iterator_for_session(
1176 struct lttng_live_msg_iter
*lttng_live_msg_iter
,
1177 struct lttng_live_session
*session
,
1178 struct lttng_live_stream_iterator
**youngest_session_stream_iter
)
1180 bt_self_component
*self_comp
= lttng_live_msg_iter
->self_comp
;
1181 bt_logging_level log_level
= lttng_live_msg_iter
->log_level
;
1182 enum lttng_live_iterator_status stream_iter_status
;
1183 uint64_t trace_idx
= 0;
1184 int64_t youngest_candidate_msg_ts
= INT64_MAX
;
1185 struct lttng_live_stream_iterator
*youngest_candidate_stream_iter
= NULL
;
1187 BT_COMP_LOGD("Finding the next stream iterator for session: "
1188 "session-id=%"PRIu64
, session
->id
);
1190 * Make sure we are attached to the session and look for new streams
1193 stream_iter_status
= lttng_live_get_session(lttng_live_msg_iter
, session
);
1194 if (stream_iter_status
!= LTTNG_LIVE_ITERATOR_STATUS_OK
&&
1195 stream_iter_status
!= LTTNG_LIVE_ITERATOR_STATUS_CONTINUE
&&
1196 stream_iter_status
!= LTTNG_LIVE_ITERATOR_STATUS_END
) {
1200 BT_ASSERT_DBG(session
->traces
);
1202 while (trace_idx
< session
->traces
->len
) {
1203 bool trace_is_ended
= false;
1204 struct lttng_live_stream_iterator
*stream_iter
;
1205 struct lttng_live_trace
*trace
=
1206 g_ptr_array_index(session
->traces
, trace_idx
);
1208 stream_iter_status
= next_stream_iterator_for_trace(
1209 lttng_live_msg_iter
, trace
, &stream_iter
);
1210 if (stream_iter_status
== LTTNG_LIVE_ITERATOR_STATUS_END
) {
1212 * All the live stream iterators for this trace are
1213 * ENDed. Remove the trace from this session.
1215 trace_is_ended
= true;
1216 } else if (stream_iter_status
!= LTTNG_LIVE_ITERATOR_STATUS_OK
) {
1220 if (!trace_is_ended
) {
1221 BT_ASSERT_DBG(stream_iter
);
1223 if (G_UNLIKELY(youngest_candidate_stream_iter
== NULL
) ||
1224 stream_iter
->current_msg_ts_ns
< youngest_candidate_msg_ts
) {
1225 youngest_candidate_msg_ts
= stream_iter
->current_msg_ts_ns
;
1226 youngest_candidate_stream_iter
= stream_iter
;
1227 } else if (stream_iter
->current_msg_ts_ns
== youngest_candidate_msg_ts
) {
1229 * Order the messages in an arbitrary but
1230 * deterministic way.
1232 int ret
= common_muxing_compare_messages(
1233 stream_iter
->current_msg
,
1234 youngest_candidate_stream_iter
->current_msg
);
1237 * The `youngest_candidate_stream_iter->current_msg`
1238 * should go first. Update the next iterator
1239 * and the current timestamp.
1241 youngest_candidate_msg_ts
= stream_iter
->current_msg_ts_ns
;
1242 youngest_candidate_stream_iter
= stream_iter
;
1243 } else if (ret
== 0) {
1244 /* Unable to pick which one should go first. */
1245 BT_COMP_LOGW("Cannot deterministically pick next live stream message iterator because they have identical next messages: "
1246 "stream-iter-addr=%p" "stream-iter-addr=%p",
1247 stream_iter
, youngest_candidate_stream_iter
);
1253 * trace_idx is not incremented since
1254 * g_ptr_array_remove_index_fast replaces the
1255 * element at trace_idx with the array's last element.
1257 g_ptr_array_remove_index_fast(session
->traces
,
1261 if (youngest_candidate_stream_iter
) {
1262 *youngest_session_stream_iter
= youngest_candidate_stream_iter
;
1263 stream_iter_status
= LTTNG_LIVE_ITERATOR_STATUS_OK
;
1266 * The only cases where we don't have a candidate for this
1268 * 1. if we reached the end of all the iterators of all the
1269 * traces of this session,
1270 * 2. if we never had live stream iterator in the first place.
1272 * In either cases, we return END.
1274 BT_ASSERT(session
->traces
->len
== 0);
1275 stream_iter_status
= LTTNG_LIVE_ITERATOR_STATUS_END
;
1278 return stream_iter_status
;
1282 void put_messages(bt_message_array_const msgs
, uint64_t count
)
1286 for (i
= 0; i
< count
; i
++) {
1287 BT_MESSAGE_PUT_REF_AND_RESET(msgs
[i
]);
1292 bt_component_class_message_iterator_next_method_status
lttng_live_msg_iter_next(
1293 bt_self_message_iterator
*self_msg_it
,
1294 bt_message_array_const msgs
, uint64_t capacity
,
1297 bt_component_class_message_iterator_next_method_status status
;
1298 enum lttng_live_viewer_status viewer_status
;
1299 struct lttng_live_msg_iter
*lttng_live_msg_iter
=
1300 bt_self_message_iterator_get_data(self_msg_it
);
1301 struct lttng_live_component
*lttng_live
=
1302 lttng_live_msg_iter
->lttng_live_comp
;
1303 bt_self_component
*self_comp
= lttng_live_msg_iter
->self_comp
;
1304 bt_logging_level log_level
= lttng_live_msg_iter
->log_level
;
1305 enum lttng_live_iterator_status stream_iter_status
;
1306 uint64_t session_idx
;
1310 BT_ASSERT_DBG(lttng_live_msg_iter
);
1312 if (G_UNLIKELY(lttng_live_msg_iter
->was_interrupted
)) {
1314 * The iterator was interrupted in a previous call to the
1315 * `_next()` method. We currently do not support generating
1316 * messages after such event. The babeltrace2 CLI should never
1317 * be running the graph after being interrupted. So this check
1318 * is to prevent other graph users from using this live
1319 * iterator in an messed up internal state.
1321 status
= BT_COMPONENT_CLASS_MESSAGE_ITERATOR_NEXT_METHOD_STATUS_ERROR
;
1322 BT_COMP_LOGE_APPEND_CAUSE(self_comp
,
1323 "Message iterator was interrupted during a previous call to the `next()` and currently does not support continuing after such event.");
1328 * Clear all the invalid message reference that might be left over in
1331 memset(msgs
, 0, capacity
* sizeof(*msgs
));
1334 * If no session are exposed on the relay found at the url provided by
1335 * the user, session count will be 0. In this case, we return status
1336 * end to return gracefully.
1338 if (lttng_live_msg_iter
->sessions
->len
== 0) {
1339 if (lttng_live
->params
.sess_not_found_act
!=
1340 SESSION_NOT_FOUND_ACTION_CONTINUE
) {
1341 status
= BT_COMPONENT_CLASS_MESSAGE_ITERATOR_NEXT_METHOD_STATUS_END
;
1345 * The are no more active session for this session
1346 * name. Retry to create a viewer session for the
1347 * requested session name.
1349 viewer_status
= lttng_live_create_viewer_session(lttng_live_msg_iter
);
1350 if (viewer_status
!= LTTNG_LIVE_VIEWER_STATUS_OK
) {
1351 if (viewer_status
== LTTNG_LIVE_VIEWER_STATUS_ERROR
) {
1352 status
= BT_COMPONENT_CLASS_MESSAGE_ITERATOR_NEXT_METHOD_STATUS_ERROR
;
1353 BT_COMP_LOGE_APPEND_CAUSE(self_comp
,
1354 "Error creating LTTng live viewer session");
1355 } else if (viewer_status
== LTTNG_LIVE_VIEWER_STATUS_INTERRUPTED
) {
1356 status
= BT_COMPONENT_CLASS_MESSAGE_ITERATOR_NEXT_METHOD_STATUS_AGAIN
;
1365 if (lttng_live_msg_iter
->active_stream_iter
== 0) {
1366 lttng_live_force_new_streams_and_metadata(lttng_live_msg_iter
);
1370 * Here the muxing of message is done.
1372 * We need to iterate over all the streams of all the traces of all the
1373 * viewer sessions in order to get the message with the smallest
1374 * timestamp. In this case, a session is a viewer session and there is
1375 * one viewer session per consumer daemon. (UST 32bit, UST 64bit and/or
1376 * kernel). Each viewer session can have multiple traces, for example,
1377 * 64bit UST viewer sessions could have multiple per-pid traces.
1379 * We iterate over the streams of each traces to update and see what is
1380 * their next message's timestamp. From those timestamps, we select the
1381 * message with the smallest timestamp as the best candidate message
1382 * for that trace and do the same thing across all the sessions.
1384 * We then compare the timestamp of best candidate message of all the
1385 * sessions to pick the message with the smallest timestamp and we
1388 while (*count
< capacity
) {
1389 struct lttng_live_stream_iterator
*youngest_stream_iter
= NULL
,
1390 *candidate_stream_iter
= NULL
;
1391 int64_t youngest_msg_ts_ns
= INT64_MAX
;
1393 BT_ASSERT_DBG(lttng_live_msg_iter
->sessions
);
1395 while (session_idx
< lttng_live_msg_iter
->sessions
->len
) {
1396 struct lttng_live_session
*session
=
1397 g_ptr_array_index(lttng_live_msg_iter
->sessions
,
1400 /* Find the best candidate message to send downstream. */
1401 stream_iter_status
= next_stream_iterator_for_session(
1402 lttng_live_msg_iter
, session
,
1403 &candidate_stream_iter
);
1405 /* If we receive an END status, it means that either:
1406 * - Those traces never had active streams (UST with no
1407 * data produced yet),
1408 * - All live stream iterators have ENDed.*/
1409 if (stream_iter_status
== LTTNG_LIVE_ITERATOR_STATUS_END
) {
1410 if (session
->closed
&& session
->traces
->len
== 0) {
1412 * Remove the session from the list.
1413 * session_idx is not modified since
1414 * g_ptr_array_remove_index_fast
1415 * replaces the the removed element with
1416 * the array's last element.
1418 g_ptr_array_remove_index_fast(
1419 lttng_live_msg_iter
->sessions
,
1427 if (stream_iter_status
!= LTTNG_LIVE_ITERATOR_STATUS_OK
) {
1431 if (G_UNLIKELY(youngest_stream_iter
== NULL
) ||
1432 candidate_stream_iter
->current_msg_ts_ns
< youngest_msg_ts_ns
) {
1433 youngest_msg_ts_ns
= candidate_stream_iter
->current_msg_ts_ns
;
1434 youngest_stream_iter
= candidate_stream_iter
;
1435 } else if (candidate_stream_iter
->current_msg_ts_ns
== youngest_msg_ts_ns
) {
1437 * The currently selected message to be sent
1438 * downstream next has the exact same timestamp
1439 * that of the current candidate message. We
1440 * must break the tie in a predictable manner.
1442 BT_COMP_LOGD_STR("Two of the next message candidates have the same timestamps, pick one deterministically.");
1444 * Order the messages in an arbitrary but
1445 * deterministic way.
1447 int ret
= common_muxing_compare_messages(
1448 candidate_stream_iter
->current_msg
,
1449 youngest_stream_iter
->current_msg
);
1452 * The `candidate_stream_iter->current_msg`
1453 * should go first. Update the next
1454 * iterator and the current timestamp.
1456 youngest_msg_ts_ns
= candidate_stream_iter
->current_msg_ts_ns
;
1457 youngest_stream_iter
= candidate_stream_iter
;
1458 } else if (ret
== 0) {
1459 /* Unable to pick which one should go first. */
1460 BT_COMP_LOGW("Cannot deterministically pick next live stream message iterator because they have identical next messages: "
1461 "next-stream-iter-addr=%p" "candidate-stream-iter-addr=%p",
1462 youngest_stream_iter
, candidate_stream_iter
);
1469 if (!youngest_stream_iter
) {
1470 stream_iter_status
= LTTNG_LIVE_ITERATOR_STATUS_AGAIN
;
1474 BT_ASSERT_DBG(youngest_stream_iter
->current_msg
);
1475 /* Ensure monotonicity. */
1476 BT_ASSERT_DBG(lttng_live_msg_iter
->last_msg_ts_ns
<=
1477 youngest_stream_iter
->current_msg_ts_ns
);
1480 * Insert the next message to the message batch. This will set
1481 * stream iterator current messsage to NULL so that next time
1482 * we fetch the next message of that stream iterator
1484 BT_MESSAGE_MOVE_REF(msgs
[*count
], youngest_stream_iter
->current_msg
);
1487 /* Update the last timestamp in nanoseconds sent downstream. */
1488 lttng_live_msg_iter
->last_msg_ts_ns
= youngest_msg_ts_ns
;
1489 youngest_stream_iter
->current_msg_ts_ns
= INT64_MAX
;
1491 stream_iter_status
= LTTNG_LIVE_ITERATOR_STATUS_OK
;
1495 switch (stream_iter_status
) {
1496 case LTTNG_LIVE_ITERATOR_STATUS_OK
:
1497 case LTTNG_LIVE_ITERATOR_STATUS_AGAIN
:
1499 * If we gathered messages, return _OK even if the graph was
1500 * interrupted. This allows for the components downstream to at
1501 * least get the thoses messages. If the graph was indeed
1502 * interrupted there should not be another _next() call as the
1503 * application will tear down the graph. This component class
1504 * doesn't support restarting after an interruption.
1507 status
= BT_COMPONENT_CLASS_MESSAGE_ITERATOR_NEXT_METHOD_STATUS_OK
;
1509 status
= BT_COMPONENT_CLASS_MESSAGE_ITERATOR_NEXT_METHOD_STATUS_AGAIN
;
1512 case LTTNG_LIVE_ITERATOR_STATUS_END
:
1513 status
= BT_COMPONENT_CLASS_MESSAGE_ITERATOR_NEXT_METHOD_STATUS_END
;
1515 case LTTNG_LIVE_ITERATOR_STATUS_NOMEM
:
1516 BT_COMP_LOGE_APPEND_CAUSE(self_comp
,
1517 "Memory error preparing the next batch of messages: "
1518 "live-iter-status=%s",
1519 lttng_live_iterator_status_string(stream_iter_status
));
1520 status
= BT_COMPONENT_CLASS_MESSAGE_ITERATOR_NEXT_METHOD_STATUS_MEMORY_ERROR
;
1522 case LTTNG_LIVE_ITERATOR_STATUS_ERROR
:
1523 case LTTNG_LIVE_ITERATOR_STATUS_INVAL
:
1524 case LTTNG_LIVE_ITERATOR_STATUS_UNSUPPORTED
:
1525 BT_COMP_LOGE_APPEND_CAUSE(self_comp
,
1526 "Error preparing the next batch of messages: "
1527 "live-iter-status=%s",
1528 lttng_live_iterator_status_string(stream_iter_status
));
1530 status
= BT_COMPONENT_CLASS_MESSAGE_ITERATOR_NEXT_METHOD_STATUS_ERROR
;
1531 /* Put all existing messages on error. */
1532 put_messages(msgs
, *count
);
1543 struct lttng_live_msg_iter
*lttng_live_msg_iter_create(
1544 struct lttng_live_component
*lttng_live_comp
,
1545 bt_self_message_iterator
*self_msg_it
)
1547 bt_self_component
*self_comp
= lttng_live_comp
->self_comp
;
1548 bt_logging_level log_level
= lttng_live_comp
->log_level
;
1550 struct lttng_live_msg_iter
*lttng_live_msg_iter
=
1551 g_new0(struct lttng_live_msg_iter
, 1);
1552 if (!lttng_live_msg_iter
) {
1553 BT_COMP_LOGE_APPEND_CAUSE(self_comp
,
1554 "Failed to allocate lttng_live_msg_iter");
1558 lttng_live_msg_iter
->log_level
= lttng_live_comp
->log_level
;
1559 lttng_live_msg_iter
->self_comp
= lttng_live_comp
->self_comp
;
1560 lttng_live_msg_iter
->lttng_live_comp
= lttng_live_comp
;
1561 lttng_live_msg_iter
->self_msg_iter
= self_msg_it
;
1563 lttng_live_msg_iter
->active_stream_iter
= 0;
1564 lttng_live_msg_iter
->last_msg_ts_ns
= INT64_MIN
;
1565 lttng_live_msg_iter
->was_interrupted
= false;
1567 lttng_live_msg_iter
->sessions
= g_ptr_array_new_with_free_func(
1568 (GDestroyNotify
) lttng_live_destroy_session
);
1569 BT_ASSERT(lttng_live_msg_iter
->sessions
);
1572 return lttng_live_msg_iter
;
1577 bt_component_class_message_iterator_initialize_method_status
lttng_live_msg_iter_init(
1578 bt_self_message_iterator
*self_msg_it
,
1579 bt_self_message_iterator_configuration
*config
,
1580 bt_self_component_source
*self_comp_src
,
1581 bt_self_component_port_output
*self_port
)
1583 bt_component_class_message_iterator_initialize_method_status status
;
1584 bt_self_component
*self_comp
=
1585 bt_self_component_source_as_self_component(self_comp_src
);
1586 struct lttng_live_component
*lttng_live
;
1587 struct lttng_live_msg_iter
*lttng_live_msg_iter
;
1588 enum lttng_live_viewer_status viewer_status
;
1589 bt_logging_level log_level
;
1591 BT_ASSERT(self_msg_it
);
1593 lttng_live
= bt_self_component_get_data(self_comp
);
1594 log_level
= lttng_live
->log_level
;
1595 self_comp
= lttng_live
->self_comp
;
1598 /* There can be only one downstream iterator at the same time. */
1599 BT_ASSERT(!lttng_live
->has_msg_iter
);
1600 lttng_live
->has_msg_iter
= true;
1602 lttng_live_msg_iter
= lttng_live_msg_iter_create(lttng_live
,
1604 if (!lttng_live_msg_iter
) {
1605 status
= BT_COMPONENT_CLASS_MESSAGE_ITERATOR_INITIALIZE_METHOD_STATUS_MEMORY_ERROR
;
1606 BT_COMP_LOGE_APPEND_CAUSE(self_comp
,
1607 "Failed to create lttng_live_msg_iter");
1611 viewer_status
= live_viewer_connection_create(self_comp
, NULL
,
1612 log_level
, lttng_live
->params
.url
->str
, false,
1613 lttng_live_msg_iter
, <tng_live_msg_iter
->viewer_connection
);
1614 if (viewer_status
!= LTTNG_LIVE_VIEWER_STATUS_OK
) {
1615 if (viewer_status
== LTTNG_LIVE_VIEWER_STATUS_ERROR
) {
1616 BT_COMP_LOGE_APPEND_CAUSE(self_comp
,
1617 "Failed to create viewer connection");
1618 } else if (viewer_status
== LTTNG_LIVE_VIEWER_STATUS_INTERRUPTED
) {
1620 * Interruption in the _iter_init() method is not
1621 * supported. Return an error.
1623 BT_COMP_LOGE_APPEND_CAUSE(self_comp
,
1624 "Interrupted while creating viewer connection");
1629 viewer_status
= lttng_live_create_viewer_session(lttng_live_msg_iter
);
1630 if (viewer_status
!= LTTNG_LIVE_VIEWER_STATUS_OK
) {
1631 if (viewer_status
== LTTNG_LIVE_VIEWER_STATUS_ERROR
) {
1632 BT_COMP_LOGE_APPEND_CAUSE(self_comp
,
1633 "Failed to create viewer session");
1634 } else if (viewer_status
== LTTNG_LIVE_VIEWER_STATUS_INTERRUPTED
) {
1636 * Interruption in the _iter_init() method is not
1637 * supported. Return an error.
1639 BT_COMP_LOGE_APPEND_CAUSE(self_comp
,
1640 "Interrupted when creating viewer session");
1645 if (lttng_live_msg_iter
->sessions
->len
== 0) {
1646 switch (lttng_live
->params
.sess_not_found_act
) {
1647 case SESSION_NOT_FOUND_ACTION_CONTINUE
:
1648 BT_COMP_LOGI("Unable to connect to the requested live viewer session. Keep trying to connect because of "
1649 "%s=\"%s\" component parameter: url=\"%s\"",
1650 SESS_NOT_FOUND_ACTION_PARAM
,
1651 SESS_NOT_FOUND_ACTION_CONTINUE_STR
,
1652 lttng_live
->params
.url
->str
);
1654 case SESSION_NOT_FOUND_ACTION_FAIL
:
1655 BT_COMP_LOGE_APPEND_CAUSE(self_comp
,
1656 "Unable to connect to the requested live viewer session. Fail the message iterator initialization because of %s=\"%s\" "
1657 "component parameter: url =\"%s\"",
1658 SESS_NOT_FOUND_ACTION_PARAM
,
1659 SESS_NOT_FOUND_ACTION_FAIL_STR
,
1660 lttng_live
->params
.url
->str
);
1662 case SESSION_NOT_FOUND_ACTION_END
:
1663 BT_COMP_LOGI("Unable to connect to the requested live viewer session. End gracefully at the first _next() "
1664 "call because of %s=\"%s\" component parameter: "
1665 "url=\"%s\"", SESS_NOT_FOUND_ACTION_PARAM
,
1666 SESS_NOT_FOUND_ACTION_END_STR
,
1667 lttng_live
->params
.url
->str
);
1674 bt_self_message_iterator_set_data(self_msg_it
, lttng_live_msg_iter
);
1675 status
= BT_COMPONENT_CLASS_MESSAGE_ITERATOR_INITIALIZE_METHOD_STATUS_OK
;
1679 status
= BT_COMPONENT_CLASS_MESSAGE_ITERATOR_INITIALIZE_METHOD_STATUS_ERROR
;
1680 lttng_live_msg_iter_destroy(lttng_live_msg_iter
);
1685 static struct bt_param_validation_map_value_entry_descr list_sessions_params
[] = {
1686 { URL_PARAM
, BT_PARAM_VALIDATION_MAP_VALUE_ENTRY_MANDATORY
, { .type
= BT_VALUE_TYPE_STRING
} },
1687 BT_PARAM_VALIDATION_MAP_VALUE_ENTRY_END
1691 bt_component_class_query_method_status
lttng_live_query_list_sessions(
1692 const bt_value
*params
, const bt_value
**result
,
1693 bt_self_component_class
*self_comp_class
,
1694 bt_logging_level log_level
)
1696 bt_component_class_query_method_status status
;
1697 const bt_value
*url_value
= NULL
;
1699 struct live_viewer_connection
*viewer_connection
= NULL
;
1700 enum lttng_live_viewer_status viewer_status
;
1701 enum bt_param_validation_status validation_status
;
1702 gchar
*validate_error
= NULL
;
1704 validation_status
= bt_param_validation_validate(params
,
1705 list_sessions_params
, &validate_error
);
1706 if (validation_status
== BT_PARAM_VALIDATION_STATUS_MEMORY_ERROR
) {
1707 status
= BT_COMPONENT_CLASS_QUERY_METHOD_STATUS_MEMORY_ERROR
;
1709 } else if (validation_status
== BT_PARAM_VALIDATION_STATUS_VALIDATION_ERROR
) {
1710 status
= BT_COMPONENT_CLASS_QUERY_METHOD_STATUS_ERROR
;
1711 BT_COMP_CLASS_LOGE_APPEND_CAUSE(self_comp_class
, "%s",
1716 url_value
= bt_value_map_borrow_entry_value_const(params
, URL_PARAM
);
1717 url
= bt_value_string_get(url_value
);
1719 viewer_status
= live_viewer_connection_create(NULL
, self_comp_class
,
1720 log_level
, url
, true, NULL
, &viewer_connection
);
1721 if (viewer_status
!= LTTNG_LIVE_VIEWER_STATUS_OK
) {
1722 if (viewer_status
== LTTNG_LIVE_VIEWER_STATUS_ERROR
) {
1723 BT_COMP_CLASS_LOGE_APPEND_CAUSE(self_comp_class
,
1724 "Failed to create viewer connection");
1725 status
= BT_COMPONENT_CLASS_QUERY_METHOD_STATUS_ERROR
;
1726 } else if (viewer_status
== LTTNG_LIVE_VIEWER_STATUS_INTERRUPTED
) {
1727 status
= BT_COMPONENT_CLASS_QUERY_METHOD_STATUS_AGAIN
;
1734 status
= live_viewer_connection_list_sessions(viewer_connection
,
1736 if (status
!= BT_COMPONENT_CLASS_QUERY_METHOD_STATUS_OK
) {
1737 BT_COMP_CLASS_LOGE_APPEND_CAUSE(self_comp_class
,
1738 "Failed to list viewer sessions");
1745 BT_VALUE_PUT_REF_AND_RESET(*result
);
1748 status
= BT_COMPONENT_CLASS_QUERY_METHOD_STATUS_ERROR
;
1752 if (viewer_connection
) {
1753 live_viewer_connection_destroy(viewer_connection
);
1756 g_free(validate_error
);
1762 bt_component_class_query_method_status
lttng_live_query_support_info(
1763 const bt_value
*params
, const bt_value
**result
,
1764 bt_self_component_class
*self_comp_class
,
1765 bt_logging_level log_level
)
1767 bt_component_class_query_method_status status
=
1768 BT_COMPONENT_CLASS_QUERY_METHOD_STATUS_OK
;
1769 const bt_value
*input_type_value
;
1770 const bt_value
*input_value
;
1772 struct bt_common_lttng_live_url_parts parts
= { 0 };
1774 /* Used by the logging macros */
1775 __attribute__((unused
)) bt_self_component
*self_comp
= NULL
;
1778 input_type_value
= bt_value_map_borrow_entry_value_const(params
,
1780 if (!input_type_value
) {
1781 BT_COMP_CLASS_LOGE_APPEND_CAUSE(self_comp_class
,
1782 "Missing expected `type` parameter.");
1786 if (!bt_value_is_string(input_type_value
)) {
1787 BT_COMP_CLASS_LOGE_APPEND_CAUSE(self_comp_class
,
1788 "`type` parameter is not a string value.");
1792 if (strcmp(bt_value_string_get(input_type_value
), "string") != 0) {
1793 /* We don't handle file system paths */
1797 input_value
= bt_value_map_borrow_entry_value_const(params
, "input");
1799 BT_COMP_CLASS_LOGE_APPEND_CAUSE(self_comp_class
,
1800 "Missing expected `input` parameter.");
1804 if (!bt_value_is_string(input_value
)) {
1805 BT_COMP_CLASS_LOGE_APPEND_CAUSE(self_comp_class
,
1806 "`input` parameter is not a string value.");
1810 parts
= bt_common_parse_lttng_live_url(bt_value_string_get(input_value
),
1812 if (parts
.session_name
) {
1814 * Looks pretty much like an LTTng live URL: we got the
1815 * session name part, which forms a complete URL.
1821 *result
= bt_value_real_create_init(weight
);
1823 status
= BT_COMPONENT_CLASS_QUERY_METHOD_STATUS_MEMORY_ERROR
;
1831 status
= BT_COMPONENT_CLASS_QUERY_METHOD_STATUS_ERROR
;
1834 BT_ASSERT(!*result
);
1837 bt_common_destroy_lttng_live_url_parts(&parts
);
1842 bt_component_class_query_method_status
lttng_live_query(
1843 bt_self_component_class_source
*comp_class
,
1844 bt_private_query_executor
*priv_query_exec
,
1845 const char *object
, const bt_value
*params
,
1846 __attribute__((unused
)) void *method_data
,
1847 const bt_value
**result
)
1849 bt_component_class_query_method_status status
=
1850 BT_COMPONENT_CLASS_QUERY_METHOD_STATUS_OK
;
1851 bt_self_component
*self_comp
= NULL
;
1852 bt_self_component_class
*self_comp_class
=
1853 bt_self_component_class_source_as_self_component_class(comp_class
);
1854 bt_logging_level log_level
= bt_query_executor_get_logging_level(
1855 bt_private_query_executor_as_query_executor_const(
1858 if (strcmp(object
, "sessions") == 0) {
1859 status
= lttng_live_query_list_sessions(params
, result
,
1860 self_comp_class
, log_level
);
1861 } else if (strcmp(object
, "babeltrace.support-info") == 0) {
1862 status
= lttng_live_query_support_info(params
, result
,
1863 self_comp_class
, log_level
);
1865 BT_COMP_LOGI("Unknown query object `%s`", object
);
1866 status
= BT_COMPONENT_CLASS_QUERY_METHOD_STATUS_UNKNOWN_OBJECT
;
1875 void lttng_live_component_destroy_data(struct lttng_live_component
*lttng_live
)
1880 if (lttng_live
->params
.url
) {
1881 g_string_free(lttng_live
->params
.url
, TRUE
);
1887 void lttng_live_component_finalize(bt_self_component_source
*component
)
1889 void *data
= bt_self_component_get_data(
1890 bt_self_component_source_as_self_component(component
));
1895 lttng_live_component_destroy_data(data
);
1899 enum session_not_found_action
parse_session_not_found_action_param(
1900 const bt_value
*no_session_param
)
1902 enum session_not_found_action action
;
1903 const char *no_session_act_str
= bt_value_string_get(no_session_param
);
1905 if (strcmp(no_session_act_str
, SESS_NOT_FOUND_ACTION_CONTINUE_STR
) == 0) {
1906 action
= SESSION_NOT_FOUND_ACTION_CONTINUE
;
1907 } else if (strcmp(no_session_act_str
, SESS_NOT_FOUND_ACTION_FAIL_STR
) == 0) {
1908 action
= SESSION_NOT_FOUND_ACTION_FAIL
;
1910 BT_ASSERT(strcmp(no_session_act_str
, SESS_NOT_FOUND_ACTION_END_STR
) == 0);
1911 action
= SESSION_NOT_FOUND_ACTION_END
;
1917 static struct bt_param_validation_value_descr inputs_elem_descr
= {
1918 .type
= BT_VALUE_TYPE_STRING
,
1921 static const char *sess_not_found_action_choices
[] = {
1922 SESS_NOT_FOUND_ACTION_CONTINUE_STR
,
1923 SESS_NOT_FOUND_ACTION_FAIL_STR
,
1924 SESS_NOT_FOUND_ACTION_END_STR
,
1927 static struct bt_param_validation_map_value_entry_descr params_descr
[] = {
1928 { INPUTS_PARAM
, BT_PARAM_VALIDATION_MAP_VALUE_ENTRY_MANDATORY
, { BT_VALUE_TYPE_ARRAY
, .array
= {
1931 .element_type
= &inputs_elem_descr
,
1933 { SESS_NOT_FOUND_ACTION_PARAM
, BT_PARAM_VALIDATION_MAP_VALUE_ENTRY_OPTIONAL
, { BT_VALUE_TYPE_STRING
, .string
= {
1934 .choices
= sess_not_found_action_choices
,
1936 BT_PARAM_VALIDATION_MAP_VALUE_ENTRY_END
1940 bt_component_class_initialize_method_status
lttng_live_component_create(
1941 const bt_value
*params
,
1942 bt_logging_level log_level
,
1943 bt_self_component
*self_comp
,
1944 struct lttng_live_component
**component
)
1946 struct lttng_live_component
*lttng_live
= NULL
;
1947 const bt_value
*inputs_value
;
1948 const bt_value
*url_value
;
1949 const bt_value
*value
;
1951 enum bt_param_validation_status validation_status
;
1952 gchar
*validation_error
= NULL
;
1953 bt_component_class_initialize_method_status status
;
1955 validation_status
= bt_param_validation_validate(params
, params_descr
,
1957 if (validation_status
== BT_PARAM_VALIDATION_STATUS_MEMORY_ERROR
) {
1958 status
= BT_COMPONENT_CLASS_INITIALIZE_METHOD_STATUS_MEMORY_ERROR
;
1960 } else if (validation_status
== BT_PARAM_VALIDATION_STATUS_VALIDATION_ERROR
) {
1961 BT_COMP_LOGE_APPEND_CAUSE(self_comp
, "%s", validation_error
);
1962 status
= BT_COMPONENT_CLASS_INITIALIZE_METHOD_STATUS_ERROR
;
1966 lttng_live
= g_new0(struct lttng_live_component
, 1);
1968 status
= BT_COMPONENT_CLASS_INITIALIZE_METHOD_STATUS_MEMORY_ERROR
;
1971 lttng_live
->log_level
= log_level
;
1972 lttng_live
->self_comp
= self_comp
;
1973 lttng_live
->max_query_size
= MAX_QUERY_SIZE
;
1974 lttng_live
->has_msg_iter
= false;
1977 bt_value_map_borrow_entry_value_const(params
, INPUTS_PARAM
);
1979 bt_value_array_borrow_element_by_index_const(inputs_value
, 0);
1980 url
= bt_value_string_get(url_value
);
1982 lttng_live
->params
.url
= g_string_new(url
);
1983 if (!lttng_live
->params
.url
) {
1984 status
= BT_COMPONENT_CLASS_INITIALIZE_METHOD_STATUS_MEMORY_ERROR
;
1988 value
= bt_value_map_borrow_entry_value_const(params
,
1989 SESS_NOT_FOUND_ACTION_PARAM
);
1991 lttng_live
->params
.sess_not_found_act
=
1992 parse_session_not_found_action_param(value
);
1994 BT_COMP_LOGI("Optional `%s` parameter is missing: "
1995 "defaulting to `%s`.",
1996 SESS_NOT_FOUND_ACTION_PARAM
,
1997 SESS_NOT_FOUND_ACTION_CONTINUE_STR
);
1998 lttng_live
->params
.sess_not_found_act
=
1999 SESSION_NOT_FOUND_ACTION_CONTINUE
;
2002 status
= BT_COMPONENT_CLASS_INITIALIZE_METHOD_STATUS_OK
;
2006 lttng_live_component_destroy_data(lttng_live
);
2009 g_free(validation_error
);
2011 *component
= lttng_live
;
2016 bt_component_class_initialize_method_status
lttng_live_component_init(
2017 bt_self_component_source
*self_comp_src
,
2018 bt_self_component_source_configuration
*config
,
2019 const bt_value
*params
,
2020 __attribute__((unused
)) void *init_method_data
)
2022 struct lttng_live_component
*lttng_live
;
2023 bt_component_class_initialize_method_status ret
;
2024 bt_self_component
*self_comp
=
2025 bt_self_component_source_as_self_component(self_comp_src
);
2026 bt_logging_level log_level
= bt_component_get_logging_level(
2027 bt_self_component_as_component(self_comp
));
2028 bt_self_component_add_port_status add_port_status
;
2030 ret
= lttng_live_component_create(params
, log_level
, self_comp
, <tng_live
);
2031 if (ret
!= BT_COMPONENT_CLASS_INITIALIZE_METHOD_STATUS_OK
) {
2035 add_port_status
= bt_self_component_source_add_output_port(
2036 self_comp_src
, "out", NULL
, NULL
);
2037 if (add_port_status
!= BT_SELF_COMPONENT_ADD_PORT_STATUS_OK
) {
2038 ret
= (int) add_port_status
;
2042 bt_self_component_set_data(self_comp
, lttng_live
);
2046 lttng_live_component_destroy_data(lttng_live
);