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 *print_state(struct lttng_live_stream_iterator
*s
)
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 print_stream_state(live_stream_iter) \
111 BT_COMP_LOGD("stream state %s last_inact_ts %" PRId64 \
112 ", curr_inact_ts %" PRId64, \
113 print_state(live_stream_iter), \
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("Destroy lttng_live_trace");
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 trace
= g_new0(struct lttng_live_trace
, 1);
183 BT_COMP_LOGE_APPEND_CAUSE(self_comp
,
184 "Failed to allocate live trace");
187 trace
->log_level
= session
->log_level
;
188 trace
->self_comp
= session
->self_comp
;
189 trace
->session
= session
;
190 trace
->id
= trace_id
;
191 trace
->trace_class
= NULL
;
193 trace
->stream_iterators
= g_ptr_array_new_with_free_func(
194 (GDestroyNotify
) lttng_live_stream_iterator_destroy
);
195 BT_ASSERT(trace
->stream_iterators
);
196 trace
->new_metadata_needed
= true;
197 g_ptr_array_add(session
->traces
, trace
);
199 BT_COMP_LOGI("Create trace");
209 struct lttng_live_trace
*lttng_live_borrow_trace(
210 struct lttng_live_session
*session
, uint64_t trace_id
)
212 struct lttng_live_trace
*trace
;
214 trace
= lttng_live_find_trace(session
, trace_id
);
219 /* The session is the owner of the newly created trace. */
220 trace
= lttng_live_create_trace(session
, trace_id
);
227 int lttng_live_add_session(struct lttng_live_msg_iter
*lttng_live_msg_iter
,
228 uint64_t session_id
, const char *hostname
,
229 const char *session_name
)
232 struct lttng_live_session
*session
;
233 bt_logging_level log_level
= lttng_live_msg_iter
->log_level
;
234 bt_self_component
*self_comp
= lttng_live_msg_iter
->self_comp
;
236 session
= g_new0(struct lttng_live_session
, 1);
238 BT_COMP_LOGE_APPEND_CAUSE(self_comp
,
239 "Failed to allocate live session");
243 session
->log_level
= lttng_live_msg_iter
->log_level
;
244 session
->self_comp
= lttng_live_msg_iter
->self_comp
;
245 session
->id
= session_id
;
246 session
->traces
= g_ptr_array_new_with_free_func(
247 (GDestroyNotify
) lttng_live_destroy_trace
);
248 BT_ASSERT(session
->traces
);
249 session
->lttng_live_msg_iter
= lttng_live_msg_iter
;
250 session
->new_streams_needed
= true;
251 session
->hostname
= g_string_new(hostname
);
252 BT_ASSERT(session
->hostname
);
254 session
->session_name
= g_string_new(session_name
);
255 BT_ASSERT(session
->session_name
);
257 BT_COMP_LOGI("Reading from session: %" PRIu64
" hostname: %s session_name: %s",
258 session
->id
, hostname
, session_name
);
259 g_ptr_array_add(lttng_live_msg_iter
->sessions
, session
);
269 void lttng_live_destroy_session(struct lttng_live_session
*session
)
271 bt_logging_level log_level
;
272 bt_self_component
*self_comp
;
278 log_level
= session
->log_level
;
279 self_comp
= session
->self_comp
;
280 BT_COMP_LOGD("Destroy lttng live session");
281 if (session
->id
!= -1ULL) {
282 if (lttng_live_detach_session(session
)) {
283 if (!lttng_live_graph_is_canceled(
284 session
->lttng_live_msg_iter
)) {
285 /* Old relayd cannot detach sessions. */
286 BT_COMP_LOGD("Unable to detach lttng live session %" PRIu64
,
293 if (session
->traces
) {
294 g_ptr_array_free(session
->traces
, TRUE
);
297 if (session
->hostname
) {
298 g_string_free(session
->hostname
, TRUE
);
300 if (session
->session_name
) {
301 g_string_free(session
->session_name
, TRUE
);
310 void lttng_live_msg_iter_destroy(struct lttng_live_msg_iter
*lttng_live_msg_iter
)
312 if (!lttng_live_msg_iter
) {
316 if (lttng_live_msg_iter
->sessions
) {
317 g_ptr_array_free(lttng_live_msg_iter
->sessions
, TRUE
);
320 if (lttng_live_msg_iter
->viewer_connection
) {
321 live_viewer_connection_destroy(lttng_live_msg_iter
->viewer_connection
);
323 BT_ASSERT(lttng_live_msg_iter
->lttng_live_comp
);
324 BT_ASSERT(lttng_live_msg_iter
->lttng_live_comp
->has_msg_iter
);
326 /* All stream iterators must be destroyed at this point. */
327 BT_ASSERT(lttng_live_msg_iter
->active_stream_iter
== 0);
328 lttng_live_msg_iter
->lttng_live_comp
->has_msg_iter
= false;
330 g_free(lttng_live_msg_iter
);
337 void lttng_live_msg_iter_finalize(bt_self_message_iterator
*self_msg_iter
)
339 struct lttng_live_msg_iter
*lttng_live_msg_iter
;
341 BT_ASSERT(self_msg_iter
);
343 lttng_live_msg_iter
= bt_self_message_iterator_get_data(self_msg_iter
);
344 BT_ASSERT(lttng_live_msg_iter
);
345 lttng_live_msg_iter_destroy(lttng_live_msg_iter
);
349 enum lttng_live_iterator_status
lttng_live_iterator_next_check_stream_state(
350 struct lttng_live_stream_iterator
*lttng_live_stream
)
352 bt_logging_level log_level
= lttng_live_stream
->log_level
;
353 bt_self_component
*self_comp
= lttng_live_stream
->self_comp
;
355 switch (lttng_live_stream
->state
) {
356 case LTTNG_LIVE_STREAM_QUIESCENT
:
357 case LTTNG_LIVE_STREAM_ACTIVE_DATA
:
359 case LTTNG_LIVE_STREAM_ACTIVE_NO_DATA
:
361 BT_COMP_LOGF("Unexpected stream state \"ACTIVE_NO_DATA\"");
363 case LTTNG_LIVE_STREAM_QUIESCENT_NO_DATA
:
365 BT_COMP_LOGF("Unexpected stream state \"QUIESCENT_NO_DATA\"");
367 case LTTNG_LIVE_STREAM_EOF
:
370 return LTTNG_LIVE_ITERATOR_STATUS_OK
;
374 * For active no data stream, fetch next data. It can be either:
375 * - quiescent: need to put it in the prio heap at quiescent end
377 * - have data: need to wire up first event into the prio heap,
378 * - have no data on this stream at this point: need to retry (AGAIN) or
382 enum lttng_live_iterator_status
lttng_live_iterator_next_handle_one_no_data_stream(
383 struct lttng_live_msg_iter
*lttng_live_msg_iter
,
384 struct lttng_live_stream_iterator
*lttng_live_stream
)
386 bt_logging_level log_level
= lttng_live_msg_iter
->log_level
;
387 bt_self_component
*self_comp
= lttng_live_msg_iter
->self_comp
;
388 enum lttng_live_iterator_status ret
= LTTNG_LIVE_ITERATOR_STATUS_OK
;
389 enum lttng_live_stream_state orig_state
= lttng_live_stream
->state
;
390 struct packet_index index
;
392 if (lttng_live_stream
->trace
->new_metadata_needed
) {
393 ret
= LTTNG_LIVE_ITERATOR_STATUS_CONTINUE
;
396 if (lttng_live_stream
->trace
->session
->new_streams_needed
) {
397 ret
= LTTNG_LIVE_ITERATOR_STATUS_CONTINUE
;
400 if (lttng_live_stream
->state
!= LTTNG_LIVE_STREAM_ACTIVE_NO_DATA
&&
401 lttng_live_stream
->state
!= LTTNG_LIVE_STREAM_QUIESCENT_NO_DATA
) {
404 ret
= lttng_live_get_next_index(lttng_live_msg_iter
, lttng_live_stream
,
406 if (ret
!= LTTNG_LIVE_ITERATOR_STATUS_OK
) {
409 BT_ASSERT_DBG(lttng_live_stream
->state
!= LTTNG_LIVE_STREAM_EOF
);
410 if (lttng_live_stream
->state
== LTTNG_LIVE_STREAM_QUIESCENT
) {
411 uint64_t last_inact_ts
= lttng_live_stream
->last_inactivity_ts
,
412 curr_inact_ts
= lttng_live_stream
->current_inactivity_ts
;
414 if (orig_state
== LTTNG_LIVE_STREAM_QUIESCENT_NO_DATA
&&
415 last_inact_ts
== curr_inact_ts
) {
416 ret
= LTTNG_LIVE_ITERATOR_STATUS_AGAIN
;
417 print_stream_state(lttng_live_stream
);
419 ret
= LTTNG_LIVE_ITERATOR_STATUS_CONTINUE
;
423 lttng_live_stream
->base_offset
= index
.offset
;
424 lttng_live_stream
->offset
= index
.offset
;
425 lttng_live_stream
->len
= index
.packet_size
/ CHAR_BIT
;
427 if (ret
== LTTNG_LIVE_ITERATOR_STATUS_OK
) {
428 ret
= lttng_live_iterator_next_check_stream_state(lttng_live_stream
);
434 * Creation of the message requires the ctf trace class to be created
435 * beforehand, but the live protocol gives us all streams (including metadata)
436 * at once. So we split it in three steps: getting streams, getting metadata
437 * (which creates the ctf trace class), and then creating the per-stream
441 enum lttng_live_iterator_status
lttng_live_get_session(
442 struct lttng_live_msg_iter
*lttng_live_msg_iter
,
443 struct lttng_live_session
*session
)
445 bt_logging_level log_level
= lttng_live_msg_iter
->log_level
;
446 bt_self_component
*self_comp
= lttng_live_msg_iter
->self_comp
;
447 enum lttng_live_iterator_status status
;
450 if (!session
->attached
) {
451 enum lttng_live_viewer_status attach_status
=
452 lttng_live_attach_session(session
,
453 lttng_live_msg_iter
->self_msg_iter
);
454 if (attach_status
!= LTTNG_LIVE_VIEWER_STATUS_OK
) {
455 if (lttng_live_graph_is_canceled(lttng_live_msg_iter
)) {
457 * Clear any causes appended in
458 * `lttng_live_attach_session()` as we want to
459 * return gracefully since the graph was
462 bt_current_thread_clear_error();
463 status
= LTTNG_LIVE_ITERATOR_STATUS_AGAIN
;
465 status
= LTTNG_LIVE_ITERATOR_STATUS_ERROR
;
466 BT_COMP_LOGE_APPEND_CAUSE(self_comp
,
467 "Error attaching to LTTng live session");
473 status
= lttng_live_get_new_streams(session
,
474 lttng_live_msg_iter
->self_msg_iter
);
475 if (status
!= LTTNG_LIVE_ITERATOR_STATUS_OK
&&
476 status
!= LTTNG_LIVE_ITERATOR_STATUS_END
) {
480 while (trace_idx
< session
->traces
->len
) {
481 struct lttng_live_trace
*trace
=
482 g_ptr_array_index(session
->traces
, trace_idx
);
484 status
= lttng_live_metadata_update(trace
);
486 case LTTNG_LIVE_ITERATOR_STATUS_OK
:
489 case LTTNG_LIVE_ITERATOR_STATUS_END
:
491 * The trace has ended. Remove it of the array an
492 * continue the iteration.
493 * We can remove the trace safely when using the
494 * g_ptr_array_remove_index_fast because it replaces
495 * the element at trace_idx with the array's last
496 * element. trace_idx is not incremented because of
499 (void) g_ptr_array_remove_index_fast(session
->traces
,
506 status
= lttng_live_lazy_msg_init(session
,
507 lttng_live_msg_iter
->self_msg_iter
);
514 void lttng_live_need_new_streams(struct lttng_live_msg_iter
*lttng_live_msg_iter
)
516 uint64_t session_idx
;
518 for (session_idx
= 0; session_idx
< lttng_live_msg_iter
->sessions
->len
;
520 struct lttng_live_session
*session
=
521 g_ptr_array_index(lttng_live_msg_iter
->sessions
, session_idx
);
522 session
->new_streams_needed
= true;
527 void lttng_live_force_new_streams_and_metadata(struct lttng_live_msg_iter
*lttng_live_msg_iter
)
529 uint64_t session_idx
, trace_idx
;
531 for (session_idx
= 0; session_idx
< lttng_live_msg_iter
->sessions
->len
;
533 struct lttng_live_session
*session
=
534 g_ptr_array_index(lttng_live_msg_iter
->sessions
, session_idx
);
535 session
->new_streams_needed
= true;
536 for (trace_idx
= 0; trace_idx
< session
->traces
->len
;
538 struct lttng_live_trace
*trace
=
539 g_ptr_array_index(session
->traces
, trace_idx
);
540 trace
->new_metadata_needed
= true;
546 enum lttng_live_iterator_status
547 lttng_live_iterator_handle_new_streams_and_metadata(
548 struct lttng_live_msg_iter
*lttng_live_msg_iter
)
550 enum lttng_live_iterator_status status
;
551 enum lttng_live_viewer_status viewer_status
;
552 bt_logging_level log_level
= lttng_live_msg_iter
->log_level
;
553 bt_self_component
*self_comp
= lttng_live_msg_iter
->self_comp
;
554 uint64_t session_idx
= 0, nr_sessions_opened
= 0;
555 struct lttng_live_session
*session
;
556 enum session_not_found_action sess_not_found_act
=
557 lttng_live_msg_iter
->lttng_live_comp
->params
.sess_not_found_act
;
560 * In a remotely distant future, we could add a "new
561 * session" flag to the protocol, which would tell us that we
562 * need to query for new sessions even though we have sessions
565 if (lttng_live_msg_iter
->sessions
->len
== 0) {
566 if (sess_not_found_act
!= SESSION_NOT_FOUND_ACTION_CONTINUE
) {
567 status
= LTTNG_LIVE_ITERATOR_STATUS_END
;
571 * Retry to create a viewer session for the requested
574 viewer_status
= lttng_live_create_viewer_session(lttng_live_msg_iter
);
575 if (viewer_status
!= LTTNG_LIVE_VIEWER_STATUS_OK
) {
576 if (viewer_status
== LTTNG_LIVE_VIEWER_STATUS_ERROR
) {
577 status
= LTTNG_LIVE_ITERATOR_STATUS_ERROR
;
578 BT_COMP_LOGE_APPEND_CAUSE(self_comp
,
579 "Error creating LTTng live viewer session");
580 } else if (viewer_status
== LTTNG_LIVE_VIEWER_STATUS_INTERRUPTED
) {
581 status
= LTTNG_LIVE_ITERATOR_STATUS_AGAIN
;
590 for (session_idx
= 0; session_idx
< lttng_live_msg_iter
->sessions
->len
;
592 session
= g_ptr_array_index(lttng_live_msg_iter
->sessions
,
594 status
= lttng_live_get_session(lttng_live_msg_iter
, session
);
596 case LTTNG_LIVE_ITERATOR_STATUS_OK
:
598 case LTTNG_LIVE_ITERATOR_STATUS_END
:
599 status
= LTTNG_LIVE_ITERATOR_STATUS_OK
;
604 if (!session
->closed
) {
605 nr_sessions_opened
++;
609 if (sess_not_found_act
!= SESSION_NOT_FOUND_ACTION_CONTINUE
&&
610 nr_sessions_opened
== 0) {
611 status
= LTTNG_LIVE_ITERATOR_STATUS_END
;
613 status
= LTTNG_LIVE_ITERATOR_STATUS_OK
;
621 enum lttng_live_iterator_status
emit_inactivity_message(
622 struct lttng_live_msg_iter
*lttng_live_msg_iter
,
623 struct lttng_live_stream_iterator
*stream_iter
,
624 bt_message
**message
, uint64_t timestamp
)
626 enum lttng_live_iterator_status ret
= LTTNG_LIVE_ITERATOR_STATUS_OK
;
627 bt_logging_level log_level
= lttng_live_msg_iter
->log_level
;
628 bt_self_component
*self_comp
= lttng_live_msg_iter
->self_comp
;
629 bt_message
*msg
= NULL
;
631 BT_ASSERT(stream_iter
->trace
->clock_class
);
633 msg
= bt_message_message_iterator_inactivity_create(
634 lttng_live_msg_iter
->self_msg_iter
,
635 stream_iter
->trace
->clock_class
, timestamp
);
637 BT_COMP_LOGE_APPEND_CAUSE(self_comp
,
638 "Error emitting message iterator inactivity message");
647 ret
= LTTNG_LIVE_ITERATOR_STATUS_ERROR
;
648 bt_message_put_ref(msg
);
653 enum lttng_live_iterator_status
lttng_live_iterator_next_handle_one_quiescent_stream(
654 struct lttng_live_msg_iter
*lttng_live_msg_iter
,
655 struct lttng_live_stream_iterator
*lttng_live_stream
,
656 bt_message
**message
)
658 enum lttng_live_iterator_status ret
= LTTNG_LIVE_ITERATOR_STATUS_OK
;
660 if (lttng_live_stream
->state
!= LTTNG_LIVE_STREAM_QUIESCENT
) {
661 return LTTNG_LIVE_ITERATOR_STATUS_OK
;
664 if (lttng_live_stream
->current_inactivity_ts
==
665 lttng_live_stream
->last_inactivity_ts
) {
666 lttng_live_stream
->state
= LTTNG_LIVE_STREAM_QUIESCENT_NO_DATA
;
667 ret
= LTTNG_LIVE_ITERATOR_STATUS_CONTINUE
;
671 ret
= emit_inactivity_message(lttng_live_msg_iter
, lttng_live_stream
,
672 message
, lttng_live_stream
->current_inactivity_ts
);
674 lttng_live_stream
->last_inactivity_ts
=
675 lttng_live_stream
->current_inactivity_ts
;
681 int live_get_msg_ts_ns(struct lttng_live_stream_iterator
*stream_iter
,
682 struct lttng_live_msg_iter
*lttng_live_msg_iter
,
683 const bt_message
*msg
, int64_t last_msg_ts_ns
,
686 const bt_clock_class
*clock_class
= NULL
;
687 const bt_clock_snapshot
*clock_snapshot
= NULL
;
689 bt_logging_level log_level
= lttng_live_msg_iter
->log_level
;
690 bt_self_component
*self_comp
= lttng_live_msg_iter
->self_comp
;
693 BT_ASSERT_DBG(ts_ns
);
695 BT_COMP_LOGD("Getting message's timestamp: iter-data-addr=%p, msg-addr=%p, "
696 "last-msg-ts=%" PRId64
, lttng_live_msg_iter
, msg
,
699 switch (bt_message_get_type(msg
)) {
700 case BT_MESSAGE_TYPE_EVENT
:
701 clock_class
= bt_message_event_borrow_stream_class_default_clock_class_const(
703 BT_ASSERT_DBG(clock_class
);
705 clock_snapshot
= bt_message_event_borrow_default_clock_snapshot_const(
708 case BT_MESSAGE_TYPE_PACKET_BEGINNING
:
709 clock_class
= bt_message_packet_beginning_borrow_stream_class_default_clock_class_const(
711 BT_ASSERT(clock_class
);
713 clock_snapshot
= bt_message_packet_beginning_borrow_default_clock_snapshot_const(
716 case BT_MESSAGE_TYPE_PACKET_END
:
717 clock_class
= bt_message_packet_end_borrow_stream_class_default_clock_class_const(
719 BT_ASSERT(clock_class
);
721 clock_snapshot
= bt_message_packet_end_borrow_default_clock_snapshot_const(
724 case BT_MESSAGE_TYPE_DISCARDED_EVENTS
:
725 clock_class
= bt_message_discarded_events_borrow_stream_class_default_clock_class_const(
727 BT_ASSERT(clock_class
);
729 clock_snapshot
= bt_message_discarded_events_borrow_beginning_default_clock_snapshot_const(
732 case BT_MESSAGE_TYPE_DISCARDED_PACKETS
:
733 clock_class
= bt_message_discarded_packets_borrow_stream_class_default_clock_class_const(
735 BT_ASSERT(clock_class
);
737 clock_snapshot
= bt_message_discarded_packets_borrow_beginning_default_clock_snapshot_const(
740 case BT_MESSAGE_TYPE_MESSAGE_ITERATOR_INACTIVITY
:
741 clock_snapshot
= bt_message_message_iterator_inactivity_borrow_default_clock_snapshot_const(
745 /* All the other messages have a higher priority */
746 BT_COMP_LOGD_STR("Message has no timestamp: using the last message timestamp.");
747 *ts_ns
= last_msg_ts_ns
;
751 clock_class
= bt_clock_snapshot_borrow_clock_class_const(clock_snapshot
);
752 BT_ASSERT_DBG(clock_class
);
754 ret
= bt_clock_snapshot_get_ns_from_origin(clock_snapshot
, ts_ns
);
756 BT_COMP_LOGE_APPEND_CAUSE(self_comp
,
757 "Cannot get nanoseconds from Epoch of clock snapshot: "
758 "clock-snapshot-addr=%p", clock_snapshot
);
769 BT_COMP_LOGD("Found message's timestamp: "
770 "iter-data-addr=%p, msg-addr=%p, "
771 "last-msg-ts=%" PRId64
", ts=%" PRId64
,
772 lttng_live_msg_iter
, msg
, last_msg_ts_ns
, *ts_ns
);
779 enum lttng_live_iterator_status
lttng_live_iterator_next_handle_one_active_data_stream(
780 struct lttng_live_msg_iter
*lttng_live_msg_iter
,
781 struct lttng_live_stream_iterator
*lttng_live_stream
,
782 bt_message
**message
)
784 enum lttng_live_iterator_status ret
= LTTNG_LIVE_ITERATOR_STATUS_OK
;
785 bt_logging_level log_level
= lttng_live_msg_iter
->log_level
;
786 bt_self_component
*self_comp
= lttng_live_msg_iter
->self_comp
;
787 enum ctf_msg_iter_status status
;
788 uint64_t session_idx
, trace_idx
;
790 for (session_idx
= 0; session_idx
< lttng_live_msg_iter
->sessions
->len
;
792 struct lttng_live_session
*session
=
793 g_ptr_array_index(lttng_live_msg_iter
->sessions
, session_idx
);
795 if (session
->new_streams_needed
) {
796 ret
= LTTNG_LIVE_ITERATOR_STATUS_CONTINUE
;
799 for (trace_idx
= 0; trace_idx
< session
->traces
->len
;
801 struct lttng_live_trace
*trace
=
802 g_ptr_array_index(session
->traces
, trace_idx
);
803 if (trace
->new_metadata_needed
) {
804 ret
= LTTNG_LIVE_ITERATOR_STATUS_CONTINUE
;
810 if (lttng_live_stream
->state
!= LTTNG_LIVE_STREAM_ACTIVE_DATA
) {
811 ret
= LTTNG_LIVE_ITERATOR_STATUS_ERROR
;
815 status
= ctf_msg_iter_get_next_message(
816 lttng_live_stream
->msg_iter
, message
);
818 case CTF_MSG_ITER_STATUS_EOF
:
819 ret
= LTTNG_LIVE_ITERATOR_STATUS_END
;
821 case CTF_MSG_ITER_STATUS_OK
:
822 ret
= LTTNG_LIVE_ITERATOR_STATUS_OK
;
824 case CTF_MSG_ITER_STATUS_AGAIN
:
826 * Continue immediately (end of packet). The next
827 * get_index may return AGAIN to delay the following
830 ret
= LTTNG_LIVE_ITERATOR_STATUS_CONTINUE
;
832 case CTF_MSG_ITER_STATUS_INVAL
:
833 /* No argument provided by the user, so don't return INVAL. */
834 case CTF_MSG_ITER_STATUS_ERROR
:
836 ret
= LTTNG_LIVE_ITERATOR_STATUS_ERROR
;
837 BT_COMP_LOGE_APPEND_CAUSE(self_comp
,
838 "CTF message iterator return an error or failed: "
839 "msg_iter=%p", lttng_live_stream
->msg_iter
);
848 enum lttng_live_iterator_status
lttng_live_iterator_close_stream(
849 struct lttng_live_msg_iter
*lttng_live_msg_iter
,
850 struct lttng_live_stream_iterator
*stream_iter
,
851 bt_message
**curr_msg
)
853 enum lttng_live_iterator_status live_status
=
854 LTTNG_LIVE_ITERATOR_STATUS_OK
;
855 bt_logging_level log_level
= lttng_live_msg_iter
->log_level
;
856 bt_self_component
*self_comp
= lttng_live_msg_iter
->self_comp
;
858 * The viewer has hung up on us so we are closing the stream. The
859 * `ctf_msg_iter` should simply realize that it needs to close the
860 * stream properly by emitting the necessary stream end message.
862 enum ctf_msg_iter_status status
= ctf_msg_iter_get_next_message(
863 stream_iter
->msg_iter
, curr_msg
);
865 if (status
== CTF_MSG_ITER_STATUS_ERROR
) {
866 BT_COMP_LOGE_APPEND_CAUSE(self_comp
,
867 "Error getting the next message from CTF message iterator");
868 live_status
= LTTNG_LIVE_ITERATOR_STATUS_ERROR
;
872 BT_ASSERT(status
== CTF_MSG_ITER_STATUS_OK
);
880 * handle_no_data_streams()
882 * - for each ACTIVE_NO_DATA stream:
883 * - query relayd for stream data, or quiescence info.
884 * - if need metadata, get metadata, goto retry.
885 * - if new stream, get new stream as ACTIVE_NO_DATA, goto retry
886 * - if quiescent, move to QUIESCENT streams
887 * - if fetched data, move to ACTIVE_DATA streams
888 * (at this point each stream either has data, or is quiescent)
892 * handle_new_streams_and_metadata()
893 * - query relayd for known streams, add them as ACTIVE_NO_DATA
894 * - query relayd for metadata
896 * call handle_active_no_data_streams()
898 * handle_quiescent_streams()
899 * - if at least one stream is ACTIVE_DATA:
900 * - peek stream event with lowest timestamp -> next_ts
901 * - for each quiescent stream
902 * - if next_ts >= quiescent end
903 * - set state to ACTIVE_NO_DATA
905 * - for each quiescent stream
906 * - set state to ACTIVE_NO_DATA
908 * call handle_active_no_data_streams()
910 * handle_active_data_streams()
911 * - if at least one stream is ACTIVE_DATA:
912 * - get stream event with lowest timestamp from heap
913 * - make that stream event the current message.
914 * - move this stream heap position to its next event
915 * - if we need to fetch data from relayd, move
916 * stream to ACTIVE_NO_DATA.
920 * end criterion: ctrl-c on client. If relayd exits or the session
921 * closes on the relay daemon side, we keep on waiting for streams.
922 * Eventually handle --end timestamp (also an end criterion).
924 * When disconnected from relayd: try to re-connect endlessly.
927 enum lttng_live_iterator_status
lttng_live_iterator_next_msg_on_stream(
928 struct lttng_live_msg_iter
*lttng_live_msg_iter
,
929 struct lttng_live_stream_iterator
*stream_iter
,
930 bt_message
**curr_msg
)
932 bt_logging_level log_level
= lttng_live_msg_iter
->log_level
;
933 bt_self_component
*self_comp
= lttng_live_msg_iter
->self_comp
;
934 enum lttng_live_iterator_status live_status
;
936 if (stream_iter
->has_stream_hung_up
) {
938 * The stream has hung up and the stream was properly closed
939 * during the last call to the current function. Return _END
940 * status now so that this stream iterator is removed for the
941 * stream iterator list.
943 live_status
= LTTNG_LIVE_ITERATOR_STATUS_END
;
948 print_stream_state(stream_iter
);
949 live_status
= lttng_live_iterator_handle_new_streams_and_metadata(
950 lttng_live_msg_iter
);
951 if (live_status
!= LTTNG_LIVE_ITERATOR_STATUS_OK
) {
954 live_status
= lttng_live_iterator_next_handle_one_no_data_stream(
955 lttng_live_msg_iter
, stream_iter
);
957 if (live_status
!= LTTNG_LIVE_ITERATOR_STATUS_OK
) {
958 if (live_status
== LTTNG_LIVE_ITERATOR_STATUS_END
) {
960 * We overwrite `live_status` since `curr_msg` is
961 * likely set to a valid message in this function.
963 live_status
= lttng_live_iterator_close_stream(
964 lttng_live_msg_iter
, stream_iter
, curr_msg
);
968 live_status
= lttng_live_iterator_next_handle_one_quiescent_stream(
969 lttng_live_msg_iter
, stream_iter
, curr_msg
);
970 if (live_status
!= LTTNG_LIVE_ITERATOR_STATUS_OK
) {
971 BT_ASSERT(!*curr_msg
);
977 live_status
= lttng_live_iterator_next_handle_one_active_data_stream(
978 lttng_live_msg_iter
, stream_iter
, curr_msg
);
979 if (live_status
!= LTTNG_LIVE_ITERATOR_STATUS_OK
) {
980 BT_ASSERT(!*curr_msg
);
984 if (live_status
== LTTNG_LIVE_ITERATOR_STATUS_CONTINUE
) {
992 enum lttng_live_iterator_status
next_stream_iterator_for_trace(
993 struct lttng_live_msg_iter
*lttng_live_msg_iter
,
994 struct lttng_live_trace
*live_trace
,
995 struct lttng_live_stream_iterator
**youngest_trace_stream_iter
)
997 struct lttng_live_stream_iterator
*youngest_candidate_stream_iter
= NULL
;
998 bt_logging_level log_level
= lttng_live_msg_iter
->log_level
;
999 bt_self_component
*self_comp
= lttng_live_msg_iter
->self_comp
;
1000 enum lttng_live_iterator_status stream_iter_status
;;
1001 int64_t youngest_candidate_msg_ts
= INT64_MAX
;
1002 uint64_t stream_iter_idx
;
1004 BT_ASSERT_DBG(live_trace
);
1005 BT_ASSERT_DBG(live_trace
->stream_iterators
);
1007 * Update the current message of every stream iterators of this trace.
1008 * The current msg of every stream must have a timestamp equal or
1009 * larger than the last message returned by this iterator. We must
1010 * ensure monotonicity.
1012 stream_iter_idx
= 0;
1013 while (stream_iter_idx
< live_trace
->stream_iterators
->len
) {
1014 bool stream_iter_is_ended
= false;
1015 struct lttng_live_stream_iterator
*stream_iter
=
1016 g_ptr_array_index(live_trace
->stream_iterators
,
1020 * Find if there is are now current message for this stream
1023 while (!stream_iter
->current_msg
) {
1024 bt_message
*msg
= NULL
;
1025 int64_t curr_msg_ts_ns
= INT64_MAX
;
1026 stream_iter_status
= lttng_live_iterator_next_msg_on_stream(
1027 lttng_live_msg_iter
, stream_iter
, &msg
);
1029 BT_COMP_LOGD("live stream iterator returned status :%s",
1030 lttng_live_iterator_status_string(stream_iter_status
));
1031 if (stream_iter_status
== LTTNG_LIVE_ITERATOR_STATUS_END
) {
1032 stream_iter_is_ended
= true;
1036 if (stream_iter_status
!= LTTNG_LIVE_ITERATOR_STATUS_OK
) {
1043 * Get the timestamp in nanoseconds from origin of this
1046 live_get_msg_ts_ns(stream_iter
, lttng_live_msg_iter
,
1047 msg
, lttng_live_msg_iter
->last_msg_ts_ns
,
1051 * Check if the message of the current live stream
1052 * iterator occured at the exact same time or after the
1053 * last message returned by this component's message
1054 * iterator. If not, we return an error.
1056 if (curr_msg_ts_ns
>= lttng_live_msg_iter
->last_msg_ts_ns
) {
1057 stream_iter
->current_msg
= msg
;
1058 stream_iter
->current_msg_ts_ns
= curr_msg_ts_ns
;
1061 * We received a message in the past. To ensure
1062 * monotonicity, we can't send it forward.
1064 BT_COMP_LOGE_APPEND_CAUSE(self_comp
,
1065 "Message's timestamp is less than "
1066 "lttng-live's message iterator's last "
1067 "returned timestamp: "
1068 "lttng-live-msg-iter-addr=%p, ts=%" PRId64
", "
1069 "last-msg-ts=%" PRId64
,
1070 lttng_live_msg_iter
, curr_msg_ts_ns
,
1071 lttng_live_msg_iter
->last_msg_ts_ns
);
1072 stream_iter_status
= LTTNG_LIVE_ITERATOR_STATUS_ERROR
;
1077 BT_ASSERT_DBG(stream_iter
!= youngest_candidate_stream_iter
);
1079 if (!stream_iter_is_ended
) {
1080 if (G_UNLIKELY(youngest_candidate_stream_iter
== NULL
) ||
1081 stream_iter
->current_msg_ts_ns
< youngest_candidate_msg_ts
) {
1083 * Update the current best candidate message
1084 * for the stream iterator of this live trace
1085 * to be forwarded downstream.
1087 youngest_candidate_msg_ts
= stream_iter
->current_msg_ts_ns
;
1088 youngest_candidate_stream_iter
= stream_iter
;
1089 } else if (stream_iter
->current_msg_ts_ns
== youngest_candidate_msg_ts
) {
1091 * Order the messages in an arbitrary but
1092 * deterministic way.
1094 BT_ASSERT_DBG(stream_iter
!= youngest_candidate_stream_iter
);
1095 int ret
= common_muxing_compare_messages(
1096 stream_iter
->current_msg
,
1097 youngest_candidate_stream_iter
->current_msg
);
1100 * The `youngest_candidate_stream_iter->current_msg`
1101 * should go first. Update the next
1102 * iterator and the current timestamp.
1104 youngest_candidate_msg_ts
= stream_iter
->current_msg_ts_ns
;
1105 youngest_candidate_stream_iter
= stream_iter
;
1106 } else if (ret
== 0) {
1108 * Unable to pick which one should go
1111 BT_COMP_LOGW("Cannot deterministically pick next live stream message iterator because they have identical next messages: "
1112 "stream-iter-addr=%p"
1113 "stream-iter-addr=%p",
1115 youngest_candidate_stream_iter
);
1122 * The live stream iterator has ended. That
1123 * iterator is removed from the array, but
1124 * there is no need to increment
1125 * stream_iter_idx as
1126 * g_ptr_array_remove_index_fast replaces the
1127 * removed element with the array's last
1130 g_ptr_array_remove_index_fast(
1131 live_trace
->stream_iterators
,
1136 if (youngest_candidate_stream_iter
) {
1137 *youngest_trace_stream_iter
= youngest_candidate_stream_iter
;
1138 stream_iter_status
= LTTNG_LIVE_ITERATOR_STATUS_OK
;
1141 * The only case where we don't have a candidate for this trace
1142 * is if we reached the end of all the iterators.
1144 BT_ASSERT(live_trace
->stream_iterators
->len
== 0);
1145 stream_iter_status
= LTTNG_LIVE_ITERATOR_STATUS_END
;
1149 return stream_iter_status
;
1153 enum lttng_live_iterator_status
next_stream_iterator_for_session(
1154 struct lttng_live_msg_iter
*lttng_live_msg_iter
,
1155 struct lttng_live_session
*session
,
1156 struct lttng_live_stream_iterator
**youngest_session_stream_iter
)
1158 bt_self_component
*self_comp
= lttng_live_msg_iter
->self_comp
;
1159 bt_logging_level log_level
= lttng_live_msg_iter
->log_level
;
1160 enum lttng_live_iterator_status stream_iter_status
;
1161 uint64_t trace_idx
= 0;
1162 int64_t youngest_candidate_msg_ts
= INT64_MAX
;
1163 struct lttng_live_stream_iterator
*youngest_candidate_stream_iter
= NULL
;
1166 * Make sure we are attached to the session and look for new streams
1169 stream_iter_status
= lttng_live_get_session(lttng_live_msg_iter
, session
);
1170 if (stream_iter_status
!= LTTNG_LIVE_ITERATOR_STATUS_OK
&&
1171 stream_iter_status
!= LTTNG_LIVE_ITERATOR_STATUS_CONTINUE
&&
1172 stream_iter_status
!= LTTNG_LIVE_ITERATOR_STATUS_END
) {
1176 BT_ASSERT_DBG(session
->traces
);
1178 while (trace_idx
< session
->traces
->len
) {
1179 bool trace_is_ended
= false;
1180 struct lttng_live_stream_iterator
*stream_iter
;
1181 struct lttng_live_trace
*trace
=
1182 g_ptr_array_index(session
->traces
, trace_idx
);
1184 stream_iter_status
= next_stream_iterator_for_trace(
1185 lttng_live_msg_iter
, trace
, &stream_iter
);
1186 if (stream_iter_status
== LTTNG_LIVE_ITERATOR_STATUS_END
) {
1188 * All the live stream iterators for this trace are
1189 * ENDed. Remove the trace from this session.
1191 trace_is_ended
= true;
1192 } else if (stream_iter_status
!= LTTNG_LIVE_ITERATOR_STATUS_OK
) {
1196 if (!trace_is_ended
) {
1197 BT_ASSERT_DBG(stream_iter
);
1199 if (G_UNLIKELY(youngest_candidate_stream_iter
== NULL
) ||
1200 stream_iter
->current_msg_ts_ns
< youngest_candidate_msg_ts
) {
1201 youngest_candidate_msg_ts
= stream_iter
->current_msg_ts_ns
;
1202 youngest_candidate_stream_iter
= stream_iter
;
1203 } else if (stream_iter
->current_msg_ts_ns
== youngest_candidate_msg_ts
) {
1205 * Order the messages in an arbitrary but
1206 * deterministic way.
1208 int ret
= common_muxing_compare_messages(
1209 stream_iter
->current_msg
,
1210 youngest_candidate_stream_iter
->current_msg
);
1213 * The `youngest_candidate_stream_iter->current_msg`
1214 * should go first. Update the next iterator
1215 * and the current timestamp.
1217 youngest_candidate_msg_ts
= stream_iter
->current_msg_ts_ns
;
1218 youngest_candidate_stream_iter
= stream_iter
;
1219 } else if (ret
== 0) {
1220 /* Unable to pick which one should go first. */
1221 BT_COMP_LOGW("Cannot deterministically pick next live stream message iterator because they have identical next messages: "
1222 "stream-iter-addr=%p" "stream-iter-addr=%p",
1223 stream_iter
, youngest_candidate_stream_iter
);
1229 * trace_idx is not incremented since
1230 * g_ptr_array_remove_index_fast replaces the
1231 * element at trace_idx with the array's last element.
1233 g_ptr_array_remove_index_fast(session
->traces
,
1237 if (youngest_candidate_stream_iter
) {
1238 *youngest_session_stream_iter
= youngest_candidate_stream_iter
;
1239 stream_iter_status
= LTTNG_LIVE_ITERATOR_STATUS_OK
;
1242 * The only cases where we don't have a candidate for this
1244 * 1. if we reached the end of all the iterators of all the
1245 * traces of this session,
1246 * 2. if we never had live stream iterator in the first place.
1248 * In either cases, we return END.
1250 BT_ASSERT(session
->traces
->len
== 0);
1251 stream_iter_status
= LTTNG_LIVE_ITERATOR_STATUS_END
;
1254 return stream_iter_status
;
1258 void put_messages(bt_message_array_const msgs
, uint64_t count
)
1262 for (i
= 0; i
< count
; i
++) {
1263 BT_MESSAGE_PUT_REF_AND_RESET(msgs
[i
]);
1268 bt_component_class_message_iterator_next_method_status
lttng_live_msg_iter_next(
1269 bt_self_message_iterator
*self_msg_it
,
1270 bt_message_array_const msgs
, uint64_t capacity
,
1273 bt_component_class_message_iterator_next_method_status status
;
1274 enum lttng_live_viewer_status viewer_status
;
1275 struct lttng_live_msg_iter
*lttng_live_msg_iter
=
1276 bt_self_message_iterator_get_data(self_msg_it
);
1277 struct lttng_live_component
*lttng_live
=
1278 lttng_live_msg_iter
->lttng_live_comp
;
1279 bt_self_component
*self_comp
= lttng_live_msg_iter
->self_comp
;
1280 bt_logging_level log_level
= lttng_live_msg_iter
->log_level
;
1281 enum lttng_live_iterator_status stream_iter_status
;
1282 uint64_t session_idx
;
1286 BT_ASSERT_DBG(lttng_live_msg_iter
);
1288 if (G_UNLIKELY(lttng_live_msg_iter
->was_interrupted
)) {
1290 * The iterator was interrupted in a previous call to the
1291 * `_next()` method. We currently do not support generating
1292 * messages after such event. The babeltrace2 CLI should never
1293 * be running the graph after being interrupted. So this check
1294 * is to prevent other graph users from using this live
1295 * iterator in an messed up internal state.
1297 status
= BT_COMPONENT_CLASS_MESSAGE_ITERATOR_NEXT_METHOD_STATUS_ERROR
;
1298 BT_COMP_LOGE_APPEND_CAUSE(self_comp
,
1299 "Message iterator was interrupted during a previous call to the `next()` and currently does not support continuing after such event.");
1304 * Clear all the invalid message reference that might be left over in
1307 memset(msgs
, 0, capacity
* sizeof(*msgs
));
1310 * If no session are exposed on the relay found at the url provided by
1311 * the user, session count will be 0. In this case, we return status
1312 * end to return gracefully.
1314 if (lttng_live_msg_iter
->sessions
->len
== 0) {
1315 if (lttng_live
->params
.sess_not_found_act
!=
1316 SESSION_NOT_FOUND_ACTION_CONTINUE
) {
1317 status
= BT_COMPONENT_CLASS_MESSAGE_ITERATOR_NEXT_METHOD_STATUS_END
;
1321 * The are no more active session for this session
1322 * name. Retry to create a viewer session for the
1323 * requested session name.
1325 viewer_status
= lttng_live_create_viewer_session(lttng_live_msg_iter
);
1326 if (viewer_status
!= LTTNG_LIVE_VIEWER_STATUS_OK
) {
1327 if (viewer_status
== LTTNG_LIVE_VIEWER_STATUS_ERROR
) {
1328 status
= BT_COMPONENT_CLASS_MESSAGE_ITERATOR_NEXT_METHOD_STATUS_ERROR
;
1329 BT_COMP_LOGE_APPEND_CAUSE(self_comp
,
1330 "Error creating LTTng live viewer session");
1331 } else if (viewer_status
== LTTNG_LIVE_VIEWER_STATUS_INTERRUPTED
) {
1332 status
= BT_COMPONENT_CLASS_MESSAGE_ITERATOR_NEXT_METHOD_STATUS_AGAIN
;
1341 if (lttng_live_msg_iter
->active_stream_iter
== 0) {
1342 lttng_live_force_new_streams_and_metadata(lttng_live_msg_iter
);
1346 * Here the muxing of message is done.
1348 * We need to iterate over all the streams of all the traces of all the
1349 * viewer sessions in order to get the message with the smallest
1350 * timestamp. In this case, a session is a viewer session and there is
1351 * one viewer session per consumer daemon. (UST 32bit, UST 64bit and/or
1352 * kernel). Each viewer session can have multiple traces, for example,
1353 * 64bit UST viewer sessions could have multiple per-pid traces.
1355 * We iterate over the streams of each traces to update and see what is
1356 * their next message's timestamp. From those timestamps, we select the
1357 * message with the smallest timestamp as the best candidate message
1358 * for that trace and do the same thing across all the sessions.
1360 * We then compare the timestamp of best candidate message of all the
1361 * sessions to pick the message with the smallest timestamp and we
1364 while (*count
< capacity
) {
1365 struct lttng_live_stream_iterator
*youngest_stream_iter
= NULL
,
1366 *candidate_stream_iter
= NULL
;
1367 int64_t youngest_msg_ts_ns
= INT64_MAX
;
1369 BT_ASSERT_DBG(lttng_live_msg_iter
->sessions
);
1371 while (session_idx
< lttng_live_msg_iter
->sessions
->len
) {
1372 struct lttng_live_session
*session
=
1373 g_ptr_array_index(lttng_live_msg_iter
->sessions
,
1376 /* Find the best candidate message to send downstream. */
1377 stream_iter_status
= next_stream_iterator_for_session(
1378 lttng_live_msg_iter
, session
,
1379 &candidate_stream_iter
);
1381 /* If we receive an END status, it means that either:
1382 * - Those traces never had active streams (UST with no
1383 * data produced yet),
1384 * - All live stream iterators have ENDed.*/
1385 if (stream_iter_status
== LTTNG_LIVE_ITERATOR_STATUS_END
) {
1386 if (session
->closed
&& session
->traces
->len
== 0) {
1388 * Remove the session from the list.
1389 * session_idx is not modified since
1390 * g_ptr_array_remove_index_fast
1391 * replaces the the removed element with
1392 * the array's last element.
1394 g_ptr_array_remove_index_fast(
1395 lttng_live_msg_iter
->sessions
,
1403 if (stream_iter_status
!= LTTNG_LIVE_ITERATOR_STATUS_OK
) {
1407 if (G_UNLIKELY(youngest_stream_iter
== NULL
) ||
1408 candidate_stream_iter
->current_msg_ts_ns
< youngest_msg_ts_ns
) {
1409 youngest_msg_ts_ns
= candidate_stream_iter
->current_msg_ts_ns
;
1410 youngest_stream_iter
= candidate_stream_iter
;
1411 } else if (candidate_stream_iter
->current_msg_ts_ns
== youngest_msg_ts_ns
) {
1413 * The currently selected message to be sent
1414 * downstream next has the exact same timestamp
1415 * that of the current candidate message. We
1416 * must break the tie in a predictable manner.
1418 BT_COMP_LOGD_STR("Two of the next message candidates have the same timestamps, pick one deterministically.");
1420 * Order the messages in an arbitrary but
1421 * deterministic way.
1423 int ret
= common_muxing_compare_messages(
1424 candidate_stream_iter
->current_msg
,
1425 youngest_stream_iter
->current_msg
);
1428 * The `candidate_stream_iter->current_msg`
1429 * should go first. Update the next
1430 * iterator and the current timestamp.
1432 youngest_msg_ts_ns
= candidate_stream_iter
->current_msg_ts_ns
;
1433 youngest_stream_iter
= candidate_stream_iter
;
1434 } else if (ret
== 0) {
1435 /* Unable to pick which one should go first. */
1436 BT_COMP_LOGW("Cannot deterministically pick next live stream message iterator because they have identical next messages: "
1437 "next-stream-iter-addr=%p" "candidate-stream-iter-addr=%p",
1438 youngest_stream_iter
, candidate_stream_iter
);
1445 if (!youngest_stream_iter
) {
1446 stream_iter_status
= LTTNG_LIVE_ITERATOR_STATUS_AGAIN
;
1450 BT_ASSERT_DBG(youngest_stream_iter
->current_msg
);
1451 /* Ensure monotonicity. */
1452 BT_ASSERT_DBG(lttng_live_msg_iter
->last_msg_ts_ns
<=
1453 youngest_stream_iter
->current_msg_ts_ns
);
1456 * Insert the next message to the message batch. This will set
1457 * stream iterator current messsage to NULL so that next time
1458 * we fetch the next message of that stream iterator
1460 BT_MESSAGE_MOVE_REF(msgs
[*count
], youngest_stream_iter
->current_msg
);
1463 /* Update the last timestamp in nanoseconds sent downstream. */
1464 lttng_live_msg_iter
->last_msg_ts_ns
= youngest_msg_ts_ns
;
1465 youngest_stream_iter
->current_msg_ts_ns
= INT64_MAX
;
1467 stream_iter_status
= LTTNG_LIVE_ITERATOR_STATUS_OK
;
1471 switch (stream_iter_status
) {
1472 case LTTNG_LIVE_ITERATOR_STATUS_OK
:
1473 case LTTNG_LIVE_ITERATOR_STATUS_AGAIN
:
1475 * If we gathered messages, return _OK even if the graph was
1476 * interrupted. This allows for the components downstream to at
1477 * least get the thoses messages. If the graph was indeed
1478 * interrupted there should not be another _next() call as the
1479 * application will tear down the graph. This component class
1480 * doesn't support restarting after an interruption.
1483 status
= BT_COMPONENT_CLASS_MESSAGE_ITERATOR_NEXT_METHOD_STATUS_OK
;
1485 status
= BT_COMPONENT_CLASS_MESSAGE_ITERATOR_NEXT_METHOD_STATUS_AGAIN
;
1488 case LTTNG_LIVE_ITERATOR_STATUS_END
:
1489 status
= BT_COMPONENT_CLASS_MESSAGE_ITERATOR_NEXT_METHOD_STATUS_END
;
1491 case LTTNG_LIVE_ITERATOR_STATUS_NOMEM
:
1492 BT_COMP_LOGE_APPEND_CAUSE(self_comp
,
1493 "Memory error preparing the next batch of messages: "
1494 "live-iter-status=%s",
1495 lttng_live_iterator_status_string(stream_iter_status
));
1496 status
= BT_COMPONENT_CLASS_MESSAGE_ITERATOR_NEXT_METHOD_STATUS_MEMORY_ERROR
;
1498 case LTTNG_LIVE_ITERATOR_STATUS_ERROR
:
1499 case LTTNG_LIVE_ITERATOR_STATUS_INVAL
:
1500 case LTTNG_LIVE_ITERATOR_STATUS_UNSUPPORTED
:
1501 BT_COMP_LOGE_APPEND_CAUSE(self_comp
,
1502 "Error preparing the next batch of messages: "
1503 "live-iter-status=%s",
1504 lttng_live_iterator_status_string(stream_iter_status
));
1506 status
= BT_COMPONENT_CLASS_MESSAGE_ITERATOR_NEXT_METHOD_STATUS_ERROR
;
1507 /* Put all existing messages on error. */
1508 put_messages(msgs
, *count
);
1519 struct lttng_live_msg_iter
*lttng_live_msg_iter_create(
1520 struct lttng_live_component
*lttng_live_comp
,
1521 bt_self_message_iterator
*self_msg_it
)
1523 bt_self_component
*self_comp
= lttng_live_comp
->self_comp
;
1524 bt_logging_level log_level
= lttng_live_comp
->log_level
;
1526 struct lttng_live_msg_iter
*lttng_live_msg_iter
=
1527 g_new0(struct lttng_live_msg_iter
, 1);
1528 if (!lttng_live_msg_iter
) {
1529 BT_COMP_LOGE_APPEND_CAUSE(self_comp
,
1530 "Failed to allocate lttng_live_msg_iter");
1534 lttng_live_msg_iter
->log_level
= lttng_live_comp
->log_level
;
1535 lttng_live_msg_iter
->self_comp
= lttng_live_comp
->self_comp
;
1536 lttng_live_msg_iter
->lttng_live_comp
= lttng_live_comp
;
1537 lttng_live_msg_iter
->self_msg_iter
= self_msg_it
;
1539 lttng_live_msg_iter
->active_stream_iter
= 0;
1540 lttng_live_msg_iter
->last_msg_ts_ns
= INT64_MIN
;
1541 lttng_live_msg_iter
->was_interrupted
= false;
1543 lttng_live_msg_iter
->sessions
= g_ptr_array_new_with_free_func(
1544 (GDestroyNotify
) lttng_live_destroy_session
);
1545 BT_ASSERT(lttng_live_msg_iter
->sessions
);
1548 return lttng_live_msg_iter
;
1553 bt_component_class_message_iterator_initialize_method_status
lttng_live_msg_iter_init(
1554 bt_self_message_iterator
*self_msg_it
,
1555 bt_self_message_iterator_configuration
*config
,
1556 bt_self_component_source
*self_comp_src
,
1557 bt_self_component_port_output
*self_port
)
1559 bt_component_class_message_iterator_initialize_method_status status
;
1560 bt_self_component
*self_comp
=
1561 bt_self_component_source_as_self_component(self_comp_src
);
1562 struct lttng_live_component
*lttng_live
;
1563 struct lttng_live_msg_iter
*lttng_live_msg_iter
;
1564 enum lttng_live_viewer_status viewer_status
;
1565 bt_logging_level log_level
;
1567 BT_ASSERT(self_msg_it
);
1569 lttng_live
= bt_self_component_get_data(self_comp
);
1570 log_level
= lttng_live
->log_level
;
1571 self_comp
= lttng_live
->self_comp
;
1574 /* There can be only one downstream iterator at the same time. */
1575 BT_ASSERT(!lttng_live
->has_msg_iter
);
1576 lttng_live
->has_msg_iter
= true;
1578 lttng_live_msg_iter
= lttng_live_msg_iter_create(lttng_live
,
1580 if (!lttng_live_msg_iter
) {
1581 status
= BT_COMPONENT_CLASS_MESSAGE_ITERATOR_INITIALIZE_METHOD_STATUS_MEMORY_ERROR
;
1582 BT_COMP_LOGE_APPEND_CAUSE(self_comp
,
1583 "Failed to create lttng_live_msg_iter");
1587 viewer_status
= live_viewer_connection_create(self_comp
, NULL
,
1588 log_level
, lttng_live
->params
.url
->str
, false,
1589 lttng_live_msg_iter
, <tng_live_msg_iter
->viewer_connection
);
1590 if (viewer_status
!= LTTNG_LIVE_VIEWER_STATUS_OK
) {
1591 if (viewer_status
== LTTNG_LIVE_VIEWER_STATUS_ERROR
) {
1592 BT_COMP_LOGE_APPEND_CAUSE(self_comp
,
1593 "Failed to create viewer connection");
1594 } else if (viewer_status
== LTTNG_LIVE_VIEWER_STATUS_INTERRUPTED
) {
1596 * Interruption in the _iter_init() method is not
1597 * supported. Return an error.
1599 BT_COMP_LOGE_APPEND_CAUSE(self_comp
,
1600 "Interrupted while creating viewer connection");
1605 viewer_status
= lttng_live_create_viewer_session(lttng_live_msg_iter
);
1606 if (viewer_status
!= LTTNG_LIVE_VIEWER_STATUS_OK
) {
1607 if (viewer_status
== LTTNG_LIVE_VIEWER_STATUS_ERROR
) {
1608 BT_COMP_LOGE_APPEND_CAUSE(self_comp
,
1609 "Failed to create viewer session");
1610 } else if (viewer_status
== LTTNG_LIVE_VIEWER_STATUS_INTERRUPTED
) {
1612 * Interruption in the _iter_init() method is not
1613 * supported. Return an error.
1615 BT_COMP_LOGE_APPEND_CAUSE(self_comp
,
1616 "Interrupted when creating viewer session");
1621 if (lttng_live_msg_iter
->sessions
->len
== 0) {
1622 switch (lttng_live
->params
.sess_not_found_act
) {
1623 case SESSION_NOT_FOUND_ACTION_CONTINUE
:
1624 BT_COMP_LOGI("Unable to connect to the requested live viewer session. Keep trying to connect because of "
1625 "%s=\"%s\" component parameter: url=\"%s\"",
1626 SESS_NOT_FOUND_ACTION_PARAM
,
1627 SESS_NOT_FOUND_ACTION_CONTINUE_STR
,
1628 lttng_live
->params
.url
->str
);
1630 case SESSION_NOT_FOUND_ACTION_FAIL
:
1631 BT_COMP_LOGE_APPEND_CAUSE(self_comp
,
1632 "Unable to connect to the requested live viewer session. Fail the message iterator initialization because of %s=\"%s\" "
1633 "component parameter: url =\"%s\"",
1634 SESS_NOT_FOUND_ACTION_PARAM
,
1635 SESS_NOT_FOUND_ACTION_FAIL_STR
,
1636 lttng_live
->params
.url
->str
);
1638 case SESSION_NOT_FOUND_ACTION_END
:
1639 BT_COMP_LOGI("Unable to connect to the requested live viewer session. End gracefully at the first _next() "
1640 "call because of %s=\"%s\" component parameter: "
1641 "url=\"%s\"", SESS_NOT_FOUND_ACTION_PARAM
,
1642 SESS_NOT_FOUND_ACTION_END_STR
,
1643 lttng_live
->params
.url
->str
);
1650 bt_self_message_iterator_set_data(self_msg_it
, lttng_live_msg_iter
);
1651 status
= BT_COMPONENT_CLASS_MESSAGE_ITERATOR_INITIALIZE_METHOD_STATUS_OK
;
1655 status
= BT_COMPONENT_CLASS_MESSAGE_ITERATOR_INITIALIZE_METHOD_STATUS_ERROR
;
1656 lttng_live_msg_iter_destroy(lttng_live_msg_iter
);
1661 static struct bt_param_validation_map_value_entry_descr list_sessions_params
[] = {
1662 { URL_PARAM
, BT_PARAM_VALIDATION_MAP_VALUE_ENTRY_MANDATORY
, { .type
= BT_VALUE_TYPE_STRING
} },
1663 BT_PARAM_VALIDATION_MAP_VALUE_ENTRY_END
1667 bt_component_class_query_method_status
lttng_live_query_list_sessions(
1668 const bt_value
*params
, const bt_value
**result
,
1669 bt_self_component_class
*self_comp_class
,
1670 bt_logging_level log_level
)
1672 bt_component_class_query_method_status status
;
1673 const bt_value
*url_value
= NULL
;
1675 struct live_viewer_connection
*viewer_connection
= NULL
;
1676 enum lttng_live_viewer_status viewer_status
;
1677 enum bt_param_validation_status validation_status
;
1678 gchar
*validate_error
= NULL
;
1680 validation_status
= bt_param_validation_validate(params
,
1681 list_sessions_params
, &validate_error
);
1682 if (validation_status
== BT_PARAM_VALIDATION_STATUS_MEMORY_ERROR
) {
1683 status
= BT_COMPONENT_CLASS_QUERY_METHOD_STATUS_MEMORY_ERROR
;
1685 } else if (validation_status
== BT_PARAM_VALIDATION_STATUS_VALIDATION_ERROR
) {
1686 status
= BT_COMPONENT_CLASS_QUERY_METHOD_STATUS_ERROR
;
1687 BT_COMP_CLASS_LOGE_APPEND_CAUSE(self_comp_class
, "%s",
1692 url_value
= bt_value_map_borrow_entry_value_const(params
, URL_PARAM
);
1693 url
= bt_value_string_get(url_value
);
1695 viewer_status
= live_viewer_connection_create(NULL
, self_comp_class
,
1696 log_level
, url
, true, NULL
, &viewer_connection
);
1697 if (viewer_status
!= LTTNG_LIVE_VIEWER_STATUS_OK
) {
1698 if (viewer_status
== LTTNG_LIVE_VIEWER_STATUS_ERROR
) {
1699 BT_COMP_CLASS_LOGE_APPEND_CAUSE(self_comp_class
,
1700 "Failed to create viewer connection");
1701 status
= BT_COMPONENT_CLASS_QUERY_METHOD_STATUS_ERROR
;
1702 } else if (viewer_status
== LTTNG_LIVE_VIEWER_STATUS_INTERRUPTED
) {
1703 status
= BT_COMPONENT_CLASS_QUERY_METHOD_STATUS_AGAIN
;
1710 status
= live_viewer_connection_list_sessions(viewer_connection
,
1712 if (status
!= BT_COMPONENT_CLASS_QUERY_METHOD_STATUS_OK
) {
1713 BT_COMP_CLASS_LOGE_APPEND_CAUSE(self_comp_class
,
1714 "Failed to list viewer sessions");
1721 BT_VALUE_PUT_REF_AND_RESET(*result
);
1724 status
= BT_COMPONENT_CLASS_QUERY_METHOD_STATUS_ERROR
;
1728 if (viewer_connection
) {
1729 live_viewer_connection_destroy(viewer_connection
);
1732 g_free(validate_error
);
1738 bt_component_class_query_method_status
lttng_live_query_support_info(
1739 const bt_value
*params
, const bt_value
**result
,
1740 bt_self_component_class
*self_comp_class
,
1741 bt_logging_level log_level
)
1743 bt_component_class_query_method_status status
=
1744 BT_COMPONENT_CLASS_QUERY_METHOD_STATUS_OK
;
1745 const bt_value
*input_type_value
;
1746 const bt_value
*input_value
;
1748 struct bt_common_lttng_live_url_parts parts
= { 0 };
1750 /* Used by the logging macros */
1751 __attribute__((unused
)) bt_self_component
*self_comp
= NULL
;
1754 input_type_value
= bt_value_map_borrow_entry_value_const(params
,
1756 if (!input_type_value
) {
1757 BT_COMP_CLASS_LOGE_APPEND_CAUSE(self_comp_class
,
1758 "Missing expected `type` parameter.");
1762 if (!bt_value_is_string(input_type_value
)) {
1763 BT_COMP_CLASS_LOGE_APPEND_CAUSE(self_comp_class
,
1764 "`type` parameter is not a string value.");
1768 if (strcmp(bt_value_string_get(input_type_value
), "string") != 0) {
1769 /* We don't handle file system paths */
1773 input_value
= bt_value_map_borrow_entry_value_const(params
, "input");
1775 BT_COMP_CLASS_LOGE_APPEND_CAUSE(self_comp_class
,
1776 "Missing expected `input` parameter.");
1780 if (!bt_value_is_string(input_value
)) {
1781 BT_COMP_CLASS_LOGE_APPEND_CAUSE(self_comp_class
,
1782 "`input` parameter is not a string value.");
1786 parts
= bt_common_parse_lttng_live_url(bt_value_string_get(input_value
),
1788 if (parts
.session_name
) {
1790 * Looks pretty much like an LTTng live URL: we got the
1791 * session name part, which forms a complete URL.
1797 *result
= bt_value_real_create_init(weight
);
1799 status
= BT_COMPONENT_CLASS_QUERY_METHOD_STATUS_MEMORY_ERROR
;
1807 status
= BT_COMPONENT_CLASS_QUERY_METHOD_STATUS_ERROR
;
1810 BT_ASSERT(!*result
);
1813 bt_common_destroy_lttng_live_url_parts(&parts
);
1818 bt_component_class_query_method_status
lttng_live_query(
1819 bt_self_component_class_source
*comp_class
,
1820 bt_private_query_executor
*priv_query_exec
,
1821 const char *object
, const bt_value
*params
,
1822 __attribute__((unused
)) void *method_data
,
1823 const bt_value
**result
)
1825 bt_component_class_query_method_status status
=
1826 BT_COMPONENT_CLASS_QUERY_METHOD_STATUS_OK
;
1827 bt_self_component
*self_comp
= NULL
;
1828 bt_self_component_class
*self_comp_class
=
1829 bt_self_component_class_source_as_self_component_class(comp_class
);
1830 bt_logging_level log_level
= bt_query_executor_get_logging_level(
1831 bt_private_query_executor_as_query_executor_const(
1834 if (strcmp(object
, "sessions") == 0) {
1835 status
= lttng_live_query_list_sessions(params
, result
,
1836 self_comp_class
, log_level
);
1837 } else if (strcmp(object
, "babeltrace.support-info") == 0) {
1838 status
= lttng_live_query_support_info(params
, result
,
1839 self_comp_class
, log_level
);
1841 BT_COMP_LOGI("Unknown query object `%s`", object
);
1842 status
= BT_COMPONENT_CLASS_QUERY_METHOD_STATUS_UNKNOWN_OBJECT
;
1851 void lttng_live_component_destroy_data(struct lttng_live_component
*lttng_live
)
1856 if (lttng_live
->params
.url
) {
1857 g_string_free(lttng_live
->params
.url
, TRUE
);
1863 void lttng_live_component_finalize(bt_self_component_source
*component
)
1865 void *data
= bt_self_component_get_data(
1866 bt_self_component_source_as_self_component(component
));
1871 lttng_live_component_destroy_data(data
);
1875 enum session_not_found_action
parse_session_not_found_action_param(
1876 const bt_value
*no_session_param
)
1878 enum session_not_found_action action
;
1879 const char *no_session_act_str
= bt_value_string_get(no_session_param
);
1881 if (strcmp(no_session_act_str
, SESS_NOT_FOUND_ACTION_CONTINUE_STR
) == 0) {
1882 action
= SESSION_NOT_FOUND_ACTION_CONTINUE
;
1883 } else if (strcmp(no_session_act_str
, SESS_NOT_FOUND_ACTION_FAIL_STR
) == 0) {
1884 action
= SESSION_NOT_FOUND_ACTION_FAIL
;
1886 BT_ASSERT(strcmp(no_session_act_str
, SESS_NOT_FOUND_ACTION_END_STR
) == 0);
1887 action
= SESSION_NOT_FOUND_ACTION_END
;
1893 static struct bt_param_validation_value_descr inputs_elem_descr
= {
1894 .type
= BT_VALUE_TYPE_STRING
,
1897 static const char *sess_not_found_action_choices
[] = {
1898 SESS_NOT_FOUND_ACTION_CONTINUE_STR
,
1899 SESS_NOT_FOUND_ACTION_FAIL_STR
,
1900 SESS_NOT_FOUND_ACTION_END_STR
,
1903 static struct bt_param_validation_map_value_entry_descr params_descr
[] = {
1904 { INPUTS_PARAM
, BT_PARAM_VALIDATION_MAP_VALUE_ENTRY_MANDATORY
, { BT_VALUE_TYPE_ARRAY
, .array
= {
1907 .element_type
= &inputs_elem_descr
,
1909 { SESS_NOT_FOUND_ACTION_PARAM
, BT_PARAM_VALIDATION_MAP_VALUE_ENTRY_OPTIONAL
, { BT_VALUE_TYPE_STRING
, .string
= {
1910 .choices
= sess_not_found_action_choices
,
1912 BT_PARAM_VALIDATION_MAP_VALUE_ENTRY_END
1916 bt_component_class_initialize_method_status
lttng_live_component_create(
1917 const bt_value
*params
,
1918 bt_logging_level log_level
,
1919 bt_self_component
*self_comp
,
1920 struct lttng_live_component
**component
)
1922 struct lttng_live_component
*lttng_live
= NULL
;
1923 const bt_value
*inputs_value
;
1924 const bt_value
*url_value
;
1925 const bt_value
*value
;
1927 enum bt_param_validation_status validation_status
;
1928 gchar
*validation_error
= NULL
;
1929 bt_component_class_initialize_method_status status
;
1931 validation_status
= bt_param_validation_validate(params
, params_descr
,
1933 if (validation_status
== BT_PARAM_VALIDATION_STATUS_MEMORY_ERROR
) {
1934 status
= BT_COMPONENT_CLASS_INITIALIZE_METHOD_STATUS_MEMORY_ERROR
;
1936 } else if (validation_status
== BT_PARAM_VALIDATION_STATUS_VALIDATION_ERROR
) {
1937 BT_COMP_LOGE_APPEND_CAUSE(self_comp
, "%s", validation_error
);
1938 status
= BT_COMPONENT_CLASS_INITIALIZE_METHOD_STATUS_ERROR
;
1942 lttng_live
= g_new0(struct lttng_live_component
, 1);
1944 status
= BT_COMPONENT_CLASS_INITIALIZE_METHOD_STATUS_MEMORY_ERROR
;
1947 lttng_live
->log_level
= log_level
;
1948 lttng_live
->self_comp
= self_comp
;
1949 lttng_live
->max_query_size
= MAX_QUERY_SIZE
;
1950 lttng_live
->has_msg_iter
= false;
1953 bt_value_map_borrow_entry_value_const(params
, INPUTS_PARAM
);
1955 bt_value_array_borrow_element_by_index_const(inputs_value
, 0);
1956 url
= bt_value_string_get(url_value
);
1958 lttng_live
->params
.url
= g_string_new(url
);
1959 if (!lttng_live
->params
.url
) {
1960 status
= BT_COMPONENT_CLASS_INITIALIZE_METHOD_STATUS_MEMORY_ERROR
;
1964 value
= bt_value_map_borrow_entry_value_const(params
,
1965 SESS_NOT_FOUND_ACTION_PARAM
);
1967 lttng_live
->params
.sess_not_found_act
=
1968 parse_session_not_found_action_param(value
);
1970 BT_COMP_LOGI("Optional `%s` parameter is missing: "
1971 "defaulting to `%s`.",
1972 SESS_NOT_FOUND_ACTION_PARAM
,
1973 SESS_NOT_FOUND_ACTION_CONTINUE_STR
);
1974 lttng_live
->params
.sess_not_found_act
=
1975 SESSION_NOT_FOUND_ACTION_CONTINUE
;
1978 status
= BT_COMPONENT_CLASS_INITIALIZE_METHOD_STATUS_OK
;
1982 lttng_live_component_destroy_data(lttng_live
);
1985 g_free(validation_error
);
1987 *component
= lttng_live
;
1992 bt_component_class_initialize_method_status
lttng_live_component_init(
1993 bt_self_component_source
*self_comp_src
,
1994 bt_self_component_source_configuration
*config
,
1995 const bt_value
*params
,
1996 __attribute__((unused
)) void *init_method_data
)
1998 struct lttng_live_component
*lttng_live
;
1999 bt_component_class_initialize_method_status ret
;
2000 bt_self_component
*self_comp
=
2001 bt_self_component_source_as_self_component(self_comp_src
);
2002 bt_logging_level log_level
= bt_component_get_logging_level(
2003 bt_self_component_as_component(self_comp
));
2004 bt_self_component_add_port_status add_port_status
;
2006 ret
= lttng_live_component_create(params
, log_level
, self_comp
, <tng_live
);
2007 if (ret
!= BT_COMPONENT_CLASS_INITIALIZE_METHOD_STATUS_OK
) {
2011 add_port_status
= bt_self_component_source_add_output_port(
2012 self_comp_src
, "out", NULL
, NULL
);
2013 if (add_port_status
!= BT_SELF_COMPONENT_ADD_PORT_STATUS_OK
) {
2014 ret
= (int) add_port_status
;
2018 bt_self_component_set_data(self_comp
, lttng_live
);
2022 lttng_live_component_destroy_data(lttng_live
);