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_OK
:
499 case LTTNG_LIVE_ITERATOR_STATUS_END
:
501 * The trace has ended. Remove it of the array an
502 * continue the iteration.
503 * We can remove the trace safely when using the
504 * g_ptr_array_remove_index_fast because it replaces
505 * the element at trace_idx with the array's last
506 * element. trace_idx is not incremented because of
509 (void) g_ptr_array_remove_index_fast(session
->traces
,
513 BT_COMP_LOGE_APPEND_CAUSE(self_comp
,
514 "Error updating trace metadata: "
515 "stream-iter-status=%s, trace-id=%"PRIu64
,
516 lttng_live_iterator_status_string(status
),
521 status
= lttng_live_lazy_msg_init(session
,
522 lttng_live_msg_iter
->self_msg_iter
);
529 void lttng_live_need_new_streams(struct lttng_live_msg_iter
*lttng_live_msg_iter
)
531 uint64_t session_idx
;
533 for (session_idx
= 0; session_idx
< lttng_live_msg_iter
->sessions
->len
;
535 struct lttng_live_session
*session
=
536 g_ptr_array_index(lttng_live_msg_iter
->sessions
, session_idx
);
537 session
->new_streams_needed
= true;
542 void lttng_live_force_new_streams_and_metadata(struct lttng_live_msg_iter
*lttng_live_msg_iter
)
544 uint64_t session_idx
, trace_idx
;
546 for (session_idx
= 0; session_idx
< lttng_live_msg_iter
->sessions
->len
;
548 struct lttng_live_session
*session
=
549 g_ptr_array_index(lttng_live_msg_iter
->sessions
, session_idx
);
550 session
->new_streams_needed
= true;
551 for (trace_idx
= 0; trace_idx
< session
->traces
->len
;
553 struct lttng_live_trace
*trace
=
554 g_ptr_array_index(session
->traces
, trace_idx
);
555 trace
->new_metadata_needed
= true;
561 enum lttng_live_iterator_status
562 lttng_live_iterator_handle_new_streams_and_metadata(
563 struct lttng_live_msg_iter
*lttng_live_msg_iter
)
565 enum lttng_live_iterator_status status
;
566 enum lttng_live_viewer_status viewer_status
;
567 bt_logging_level log_level
= lttng_live_msg_iter
->log_level
;
568 bt_self_component
*self_comp
= lttng_live_msg_iter
->self_comp
;
569 uint64_t session_idx
= 0, nr_sessions_opened
= 0;
570 struct lttng_live_session
*session
;
571 enum session_not_found_action sess_not_found_act
=
572 lttng_live_msg_iter
->lttng_live_comp
->params
.sess_not_found_act
;
574 BT_COMP_LOGD("Update data and metadata of all sessions"
575 "live-msg-iter-addr=%p", lttng_live_msg_iter
);
577 * In a remotely distant future, we could add a "new
578 * session" flag to the protocol, which would tell us that we
579 * need to query for new sessions even though we have sessions
582 if (lttng_live_msg_iter
->sessions
->len
== 0) {
583 if (sess_not_found_act
!= SESSION_NOT_FOUND_ACTION_CONTINUE
) {
584 BT_COMP_LOGD("No session found. Exiting in accordance with the `session-not-found-action` parameter");
585 status
= LTTNG_LIVE_ITERATOR_STATUS_END
;
588 BT_COMP_LOGD("No session found. Try creating a new one in accordance with the `session-not-found-action` parameter");
590 * Retry to create a viewer session for the requested
593 viewer_status
= lttng_live_create_viewer_session(lttng_live_msg_iter
);
594 if (viewer_status
!= LTTNG_LIVE_VIEWER_STATUS_OK
) {
595 if (viewer_status
== LTTNG_LIVE_VIEWER_STATUS_ERROR
) {
596 status
= LTTNG_LIVE_ITERATOR_STATUS_ERROR
;
597 BT_COMP_LOGE_APPEND_CAUSE(self_comp
,
598 "Error creating LTTng live viewer session");
599 } else if (viewer_status
== LTTNG_LIVE_VIEWER_STATUS_INTERRUPTED
) {
600 status
= LTTNG_LIVE_ITERATOR_STATUS_AGAIN
;
609 for (session_idx
= 0; session_idx
< lttng_live_msg_iter
->sessions
->len
;
611 session
= g_ptr_array_index(lttng_live_msg_iter
->sessions
,
613 status
= lttng_live_get_session(lttng_live_msg_iter
, session
);
615 case LTTNG_LIVE_ITERATOR_STATUS_OK
:
617 case LTTNG_LIVE_ITERATOR_STATUS_END
:
618 status
= LTTNG_LIVE_ITERATOR_STATUS_OK
;
623 if (!session
->closed
) {
624 nr_sessions_opened
++;
628 if (sess_not_found_act
!= SESSION_NOT_FOUND_ACTION_CONTINUE
&&
629 nr_sessions_opened
== 0) {
630 status
= LTTNG_LIVE_ITERATOR_STATUS_END
;
632 status
= LTTNG_LIVE_ITERATOR_STATUS_OK
;
640 enum lttng_live_iterator_status
emit_inactivity_message(
641 struct lttng_live_msg_iter
*lttng_live_msg_iter
,
642 struct lttng_live_stream_iterator
*stream_iter
,
643 bt_message
**message
, uint64_t timestamp
)
645 enum lttng_live_iterator_status ret
= LTTNG_LIVE_ITERATOR_STATUS_OK
;
646 bt_logging_level log_level
= lttng_live_msg_iter
->log_level
;
647 bt_self_component
*self_comp
= lttng_live_msg_iter
->self_comp
;
648 bt_message
*msg
= NULL
;
650 BT_ASSERT(stream_iter
->trace
->clock_class
);
652 msg
= bt_message_message_iterator_inactivity_create(
653 lttng_live_msg_iter
->self_msg_iter
,
654 stream_iter
->trace
->clock_class
, timestamp
);
656 BT_COMP_LOGE_APPEND_CAUSE(self_comp
,
657 "Error emitting message iterator inactivity message");
666 ret
= LTTNG_LIVE_ITERATOR_STATUS_ERROR
;
667 bt_message_put_ref(msg
);
672 enum lttng_live_iterator_status
lttng_live_iterator_next_handle_one_quiescent_stream(
673 struct lttng_live_msg_iter
*lttng_live_msg_iter
,
674 struct lttng_live_stream_iterator
*lttng_live_stream
,
675 bt_message
**message
)
677 enum lttng_live_iterator_status ret
= LTTNG_LIVE_ITERATOR_STATUS_OK
;
679 if (lttng_live_stream
->state
!= LTTNG_LIVE_STREAM_QUIESCENT
) {
680 return LTTNG_LIVE_ITERATOR_STATUS_OK
;
683 if (lttng_live_stream
->current_inactivity_ts
==
684 lttng_live_stream
->last_inactivity_ts
) {
685 lttng_live_stream
->state
= LTTNG_LIVE_STREAM_QUIESCENT_NO_DATA
;
686 ret
= LTTNG_LIVE_ITERATOR_STATUS_CONTINUE
;
690 ret
= emit_inactivity_message(lttng_live_msg_iter
, lttng_live_stream
,
691 message
, lttng_live_stream
->current_inactivity_ts
);
693 lttng_live_stream
->last_inactivity_ts
=
694 lttng_live_stream
->current_inactivity_ts
;
700 int live_get_msg_ts_ns(struct lttng_live_stream_iterator
*stream_iter
,
701 struct lttng_live_msg_iter
*lttng_live_msg_iter
,
702 const bt_message
*msg
, int64_t last_msg_ts_ns
,
705 const bt_clock_class
*clock_class
= NULL
;
706 const bt_clock_snapshot
*clock_snapshot
= NULL
;
708 bt_logging_level log_level
= lttng_live_msg_iter
->log_level
;
709 bt_self_component
*self_comp
= lttng_live_msg_iter
->self_comp
;
712 BT_ASSERT_DBG(ts_ns
);
714 BT_COMP_LOGD("Getting message's timestamp: iter-data-addr=%p, msg-addr=%p, "
715 "last-msg-ts=%" PRId64
, lttng_live_msg_iter
, msg
,
718 switch (bt_message_get_type(msg
)) {
719 case BT_MESSAGE_TYPE_EVENT
:
720 clock_class
= bt_message_event_borrow_stream_class_default_clock_class_const(
722 BT_ASSERT_DBG(clock_class
);
724 clock_snapshot
= bt_message_event_borrow_default_clock_snapshot_const(
727 case BT_MESSAGE_TYPE_PACKET_BEGINNING
:
728 clock_class
= bt_message_packet_beginning_borrow_stream_class_default_clock_class_const(
730 BT_ASSERT(clock_class
);
732 clock_snapshot
= bt_message_packet_beginning_borrow_default_clock_snapshot_const(
735 case BT_MESSAGE_TYPE_PACKET_END
:
736 clock_class
= bt_message_packet_end_borrow_stream_class_default_clock_class_const(
738 BT_ASSERT(clock_class
);
740 clock_snapshot
= bt_message_packet_end_borrow_default_clock_snapshot_const(
743 case BT_MESSAGE_TYPE_DISCARDED_EVENTS
:
744 clock_class
= bt_message_discarded_events_borrow_stream_class_default_clock_class_const(
746 BT_ASSERT(clock_class
);
748 clock_snapshot
= bt_message_discarded_events_borrow_beginning_default_clock_snapshot_const(
751 case BT_MESSAGE_TYPE_DISCARDED_PACKETS
:
752 clock_class
= bt_message_discarded_packets_borrow_stream_class_default_clock_class_const(
754 BT_ASSERT(clock_class
);
756 clock_snapshot
= bt_message_discarded_packets_borrow_beginning_default_clock_snapshot_const(
759 case BT_MESSAGE_TYPE_MESSAGE_ITERATOR_INACTIVITY
:
760 clock_snapshot
= bt_message_message_iterator_inactivity_borrow_default_clock_snapshot_const(
764 /* All the other messages have a higher priority */
765 BT_COMP_LOGD_STR("Message has no timestamp: using the last message timestamp.");
766 *ts_ns
= last_msg_ts_ns
;
770 clock_class
= bt_clock_snapshot_borrow_clock_class_const(clock_snapshot
);
771 BT_ASSERT_DBG(clock_class
);
773 ret
= bt_clock_snapshot_get_ns_from_origin(clock_snapshot
, ts_ns
);
775 BT_COMP_LOGE_APPEND_CAUSE(self_comp
,
776 "Cannot get nanoseconds from Epoch of clock snapshot: "
777 "clock-snapshot-addr=%p", clock_snapshot
);
788 BT_COMP_LOGD("Found message's timestamp: "
789 "iter-data-addr=%p, msg-addr=%p, "
790 "last-msg-ts=%" PRId64
", ts=%" PRId64
,
791 lttng_live_msg_iter
, msg
, last_msg_ts_ns
, *ts_ns
);
798 enum lttng_live_iterator_status
lttng_live_iterator_next_handle_one_active_data_stream(
799 struct lttng_live_msg_iter
*lttng_live_msg_iter
,
800 struct lttng_live_stream_iterator
*lttng_live_stream
,
801 bt_message
**message
)
803 enum lttng_live_iterator_status ret
= LTTNG_LIVE_ITERATOR_STATUS_OK
;
804 bt_logging_level log_level
= lttng_live_msg_iter
->log_level
;
805 bt_self_component
*self_comp
= lttng_live_msg_iter
->self_comp
;
806 enum ctf_msg_iter_status status
;
807 uint64_t session_idx
, trace_idx
;
809 for (session_idx
= 0; session_idx
< lttng_live_msg_iter
->sessions
->len
;
811 struct lttng_live_session
*session
=
812 g_ptr_array_index(lttng_live_msg_iter
->sessions
, session_idx
);
814 if (session
->new_streams_needed
) {
815 ret
= LTTNG_LIVE_ITERATOR_STATUS_CONTINUE
;
818 for (trace_idx
= 0; trace_idx
< session
->traces
->len
;
820 struct lttng_live_trace
*trace
=
821 g_ptr_array_index(session
->traces
, trace_idx
);
822 if (trace
->new_metadata_needed
) {
823 ret
= LTTNG_LIVE_ITERATOR_STATUS_CONTINUE
;
829 if (lttng_live_stream
->state
!= LTTNG_LIVE_STREAM_ACTIVE_DATA
) {
830 ret
= LTTNG_LIVE_ITERATOR_STATUS_ERROR
;
831 BT_COMP_LOGE_APPEND_CAUSE(self_comp
,
832 "Invalid state of live stream iterator"
833 "stream-iter-status=%s",
834 lttng_live_stream_state_string(lttng_live_stream
->state
));
838 status
= ctf_msg_iter_get_next_message(
839 lttng_live_stream
->msg_iter
, message
);
841 case CTF_MSG_ITER_STATUS_EOF
:
842 ret
= LTTNG_LIVE_ITERATOR_STATUS_END
;
844 case CTF_MSG_ITER_STATUS_OK
:
845 ret
= LTTNG_LIVE_ITERATOR_STATUS_OK
;
847 case CTF_MSG_ITER_STATUS_AGAIN
:
849 * Continue immediately (end of packet). The next
850 * get_index may return AGAIN to delay the following
853 ret
= LTTNG_LIVE_ITERATOR_STATUS_CONTINUE
;
855 case CTF_MSG_ITER_STATUS_INVAL
:
856 /* No argument provided by the user, so don't return INVAL. */
857 case CTF_MSG_ITER_STATUS_ERROR
:
859 ret
= LTTNG_LIVE_ITERATOR_STATUS_ERROR
;
860 BT_COMP_LOGE_APPEND_CAUSE(self_comp
,
861 "CTF message iterator failed to get next message: "
862 "msg-iter=%p, msg-iter-status=%s",
863 lttng_live_stream
->msg_iter
,
864 ctf_msg_iter_status_string(status
));
873 enum lttng_live_iterator_status
lttng_live_iterator_close_stream(
874 struct lttng_live_msg_iter
*lttng_live_msg_iter
,
875 struct lttng_live_stream_iterator
*stream_iter
,
876 bt_message
**curr_msg
)
878 enum lttng_live_iterator_status live_status
=
879 LTTNG_LIVE_ITERATOR_STATUS_OK
;
880 bt_logging_level log_level
= lttng_live_msg_iter
->log_level
;
881 bt_self_component
*self_comp
= lttng_live_msg_iter
->self_comp
;
883 * The viewer has hung up on us so we are closing the stream. The
884 * `ctf_msg_iter` should simply realize that it needs to close the
885 * stream properly by emitting the necessary stream end message.
887 enum ctf_msg_iter_status status
= ctf_msg_iter_get_next_message(
888 stream_iter
->msg_iter
, curr_msg
);
890 if (status
== CTF_MSG_ITER_STATUS_ERROR
) {
891 BT_COMP_LOGE_APPEND_CAUSE(self_comp
,
892 "Error getting the next message from CTF message iterator");
893 live_status
= LTTNG_LIVE_ITERATOR_STATUS_ERROR
;
897 BT_ASSERT(status
== CTF_MSG_ITER_STATUS_OK
);
905 * handle_no_data_streams()
907 * - for each ACTIVE_NO_DATA stream:
908 * - query relayd for stream data, or quiescence info.
909 * - if need metadata, get metadata, goto retry.
910 * - if new stream, get new stream as ACTIVE_NO_DATA, goto retry
911 * - if quiescent, move to QUIESCENT streams
912 * - if fetched data, move to ACTIVE_DATA streams
913 * (at this point each stream either has data, or is quiescent)
917 * handle_new_streams_and_metadata()
918 * - query relayd for known streams, add them as ACTIVE_NO_DATA
919 * - query relayd for metadata
921 * call handle_active_no_data_streams()
923 * handle_quiescent_streams()
924 * - if at least one stream is ACTIVE_DATA:
925 * - peek stream event with lowest timestamp -> next_ts
926 * - for each quiescent stream
927 * - if next_ts >= quiescent end
928 * - set state to ACTIVE_NO_DATA
930 * - for each quiescent stream
931 * - set state to ACTIVE_NO_DATA
933 * call handle_active_no_data_streams()
935 * handle_active_data_streams()
936 * - if at least one stream is ACTIVE_DATA:
937 * - get stream event with lowest timestamp from heap
938 * - make that stream event the current message.
939 * - move this stream heap position to its next event
940 * - if we need to fetch data from relayd, move
941 * stream to ACTIVE_NO_DATA.
945 * end criterion: ctrl-c on client. If relayd exits or the session
946 * closes on the relay daemon side, we keep on waiting for streams.
947 * Eventually handle --end timestamp (also an end criterion).
949 * When disconnected from relayd: try to re-connect endlessly.
952 enum lttng_live_iterator_status
lttng_live_iterator_next_msg_on_stream(
953 struct lttng_live_msg_iter
*lttng_live_msg_iter
,
954 struct lttng_live_stream_iterator
*stream_iter
,
955 bt_message
**curr_msg
)
957 bt_logging_level log_level
= lttng_live_msg_iter
->log_level
;
958 bt_self_component
*self_comp
= lttng_live_msg_iter
->self_comp
;
959 enum lttng_live_iterator_status live_status
;
961 BT_COMP_LOGD("Finding the next message for stream iterator: "
962 "stream-name=\"%s\"", stream_iter
->name
->str
);
964 if (stream_iter
->has_stream_hung_up
) {
966 * The stream has hung up and the stream was properly closed
967 * during the last call to the current function. Return _END
968 * status now so that this stream iterator is removed for the
969 * stream iterator list.
971 live_status
= LTTNG_LIVE_ITERATOR_STATUS_END
;
976 LTTNG_LIVE_LOGD_STREAM_ITER(stream_iter
);
977 live_status
= lttng_live_iterator_handle_new_streams_and_metadata(
978 lttng_live_msg_iter
);
979 if (live_status
!= LTTNG_LIVE_ITERATOR_STATUS_OK
) {
982 live_status
= lttng_live_iterator_next_handle_one_no_data_stream(
983 lttng_live_msg_iter
, stream_iter
);
985 if (live_status
!= LTTNG_LIVE_ITERATOR_STATUS_OK
) {
986 if (live_status
== LTTNG_LIVE_ITERATOR_STATUS_END
) {
988 * We overwrite `live_status` since `curr_msg` is
989 * likely set to a valid message in this function.
991 live_status
= lttng_live_iterator_close_stream(
992 lttng_live_msg_iter
, stream_iter
, curr_msg
);
996 live_status
= lttng_live_iterator_next_handle_one_quiescent_stream(
997 lttng_live_msg_iter
, stream_iter
, curr_msg
);
998 if (live_status
!= LTTNG_LIVE_ITERATOR_STATUS_OK
) {
999 BT_ASSERT(!*curr_msg
);
1005 live_status
= lttng_live_iterator_next_handle_one_active_data_stream(
1006 lttng_live_msg_iter
, stream_iter
, curr_msg
);
1007 if (live_status
!= LTTNG_LIVE_ITERATOR_STATUS_OK
) {
1008 BT_ASSERT(!*curr_msg
);
1012 if (live_status
== LTTNG_LIVE_ITERATOR_STATUS_CONTINUE
) {
1020 enum lttng_live_iterator_status
next_stream_iterator_for_trace(
1021 struct lttng_live_msg_iter
*lttng_live_msg_iter
,
1022 struct lttng_live_trace
*live_trace
,
1023 struct lttng_live_stream_iterator
**youngest_trace_stream_iter
)
1025 struct lttng_live_stream_iterator
*youngest_candidate_stream_iter
= NULL
;
1026 bt_logging_level log_level
= lttng_live_msg_iter
->log_level
;
1027 bt_self_component
*self_comp
= lttng_live_msg_iter
->self_comp
;
1028 enum lttng_live_iterator_status stream_iter_status
;;
1029 int64_t youngest_candidate_msg_ts
= INT64_MAX
;
1030 uint64_t stream_iter_idx
;
1032 BT_ASSERT_DBG(live_trace
);
1033 BT_ASSERT_DBG(live_trace
->stream_iterators
);
1035 BT_COMP_LOGD("Finding the next stream iterator for trace: "
1036 "trace-id=%"PRIu64
, live_trace
->id
);
1038 * Update the current message of every stream iterators of this trace.
1039 * The current msg of every stream must have a timestamp equal or
1040 * larger than the last message returned by this iterator. We must
1041 * ensure monotonicity.
1043 stream_iter_idx
= 0;
1044 while (stream_iter_idx
< live_trace
->stream_iterators
->len
) {
1045 bool stream_iter_is_ended
= false;
1046 struct lttng_live_stream_iterator
*stream_iter
=
1047 g_ptr_array_index(live_trace
->stream_iterators
,
1051 * Find if there is are now current message for this stream
1054 while (!stream_iter
->current_msg
) {
1055 bt_message
*msg
= NULL
;
1056 int64_t curr_msg_ts_ns
= INT64_MAX
;
1057 stream_iter_status
= lttng_live_iterator_next_msg_on_stream(
1058 lttng_live_msg_iter
, stream_iter
, &msg
);
1060 BT_COMP_LOGD("live stream iterator returned status :%s",
1061 lttng_live_iterator_status_string(stream_iter_status
));
1062 if (stream_iter_status
== LTTNG_LIVE_ITERATOR_STATUS_END
) {
1063 stream_iter_is_ended
= true;
1067 if (stream_iter_status
!= LTTNG_LIVE_ITERATOR_STATUS_OK
) {
1074 * Get the timestamp in nanoseconds from origin of this
1077 live_get_msg_ts_ns(stream_iter
, lttng_live_msg_iter
,
1078 msg
, lttng_live_msg_iter
->last_msg_ts_ns
,
1082 * Check if the message of the current live stream
1083 * iterator occured at the exact same time or after the
1084 * last message returned by this component's message
1085 * iterator. If not, we return an error.
1087 if (curr_msg_ts_ns
>= lttng_live_msg_iter
->last_msg_ts_ns
) {
1088 stream_iter
->current_msg
= msg
;
1089 stream_iter
->current_msg_ts_ns
= curr_msg_ts_ns
;
1092 * We received a message in the past. To ensure
1093 * monotonicity, we can't send it forward.
1095 BT_COMP_LOGE_APPEND_CAUSE(self_comp
,
1096 "Message's timestamp is less than "
1097 "lttng-live's message iterator's last "
1098 "returned timestamp: "
1099 "lttng-live-msg-iter-addr=%p, ts=%" PRId64
", "
1100 "last-msg-ts=%" PRId64
,
1101 lttng_live_msg_iter
, curr_msg_ts_ns
,
1102 lttng_live_msg_iter
->last_msg_ts_ns
);
1103 stream_iter_status
= LTTNG_LIVE_ITERATOR_STATUS_ERROR
;
1108 BT_ASSERT_DBG(stream_iter
!= youngest_candidate_stream_iter
);
1110 if (!stream_iter_is_ended
) {
1111 if (G_UNLIKELY(youngest_candidate_stream_iter
== NULL
) ||
1112 stream_iter
->current_msg_ts_ns
< youngest_candidate_msg_ts
) {
1114 * Update the current best candidate message
1115 * for the stream iterator of this live trace
1116 * to be forwarded downstream.
1118 youngest_candidate_msg_ts
= stream_iter
->current_msg_ts_ns
;
1119 youngest_candidate_stream_iter
= stream_iter
;
1120 } else if (stream_iter
->current_msg_ts_ns
== youngest_candidate_msg_ts
) {
1122 * Order the messages in an arbitrary but
1123 * deterministic way.
1125 BT_ASSERT_DBG(stream_iter
!= youngest_candidate_stream_iter
);
1126 int ret
= common_muxing_compare_messages(
1127 stream_iter
->current_msg
,
1128 youngest_candidate_stream_iter
->current_msg
);
1131 * The `youngest_candidate_stream_iter->current_msg`
1132 * should go first. Update the next
1133 * iterator and the current timestamp.
1135 youngest_candidate_msg_ts
= stream_iter
->current_msg_ts_ns
;
1136 youngest_candidate_stream_iter
= stream_iter
;
1137 } else if (ret
== 0) {
1139 * Unable to pick which one should go
1142 BT_COMP_LOGW("Cannot deterministically pick next live stream message iterator because they have identical next messages: "
1143 "stream-iter-addr=%p"
1144 "stream-iter-addr=%p",
1146 youngest_candidate_stream_iter
);
1153 * The live stream iterator has ended. That
1154 * iterator is removed from the array, but
1155 * there is no need to increment
1156 * stream_iter_idx as
1157 * g_ptr_array_remove_index_fast replaces the
1158 * removed element with the array's last
1161 g_ptr_array_remove_index_fast(
1162 live_trace
->stream_iterators
,
1167 if (youngest_candidate_stream_iter
) {
1168 *youngest_trace_stream_iter
= youngest_candidate_stream_iter
;
1169 stream_iter_status
= LTTNG_LIVE_ITERATOR_STATUS_OK
;
1172 * The only case where we don't have a candidate for this trace
1173 * is if we reached the end of all the iterators.
1175 BT_ASSERT(live_trace
->stream_iterators
->len
== 0);
1176 stream_iter_status
= LTTNG_LIVE_ITERATOR_STATUS_END
;
1180 return stream_iter_status
;
1184 enum lttng_live_iterator_status
next_stream_iterator_for_session(
1185 struct lttng_live_msg_iter
*lttng_live_msg_iter
,
1186 struct lttng_live_session
*session
,
1187 struct lttng_live_stream_iterator
**youngest_session_stream_iter
)
1189 bt_self_component
*self_comp
= lttng_live_msg_iter
->self_comp
;
1190 bt_logging_level log_level
= lttng_live_msg_iter
->log_level
;
1191 enum lttng_live_iterator_status stream_iter_status
;
1192 uint64_t trace_idx
= 0;
1193 int64_t youngest_candidate_msg_ts
= INT64_MAX
;
1194 struct lttng_live_stream_iterator
*youngest_candidate_stream_iter
= NULL
;
1196 BT_COMP_LOGD("Finding the next stream iterator for session: "
1197 "session-id=%"PRIu64
, session
->id
);
1199 * Make sure we are attached to the session and look for new streams
1202 stream_iter_status
= lttng_live_get_session(lttng_live_msg_iter
, session
);
1203 if (stream_iter_status
!= LTTNG_LIVE_ITERATOR_STATUS_OK
&&
1204 stream_iter_status
!= LTTNG_LIVE_ITERATOR_STATUS_CONTINUE
&&
1205 stream_iter_status
!= LTTNG_LIVE_ITERATOR_STATUS_END
) {
1209 BT_ASSERT_DBG(session
->traces
);
1211 while (trace_idx
< session
->traces
->len
) {
1212 bool trace_is_ended
= false;
1213 struct lttng_live_stream_iterator
*stream_iter
;
1214 struct lttng_live_trace
*trace
=
1215 g_ptr_array_index(session
->traces
, trace_idx
);
1217 stream_iter_status
= next_stream_iterator_for_trace(
1218 lttng_live_msg_iter
, trace
, &stream_iter
);
1219 if (stream_iter_status
== LTTNG_LIVE_ITERATOR_STATUS_END
) {
1221 * All the live stream iterators for this trace are
1222 * ENDed. Remove the trace from this session.
1224 trace_is_ended
= true;
1225 } else if (stream_iter_status
!= LTTNG_LIVE_ITERATOR_STATUS_OK
) {
1229 if (!trace_is_ended
) {
1230 BT_ASSERT_DBG(stream_iter
);
1232 if (G_UNLIKELY(youngest_candidate_stream_iter
== NULL
) ||
1233 stream_iter
->current_msg_ts_ns
< youngest_candidate_msg_ts
) {
1234 youngest_candidate_msg_ts
= stream_iter
->current_msg_ts_ns
;
1235 youngest_candidate_stream_iter
= stream_iter
;
1236 } else if (stream_iter
->current_msg_ts_ns
== youngest_candidate_msg_ts
) {
1238 * Order the messages in an arbitrary but
1239 * deterministic way.
1241 int ret
= common_muxing_compare_messages(
1242 stream_iter
->current_msg
,
1243 youngest_candidate_stream_iter
->current_msg
);
1246 * The `youngest_candidate_stream_iter->current_msg`
1247 * should go first. Update the next iterator
1248 * and the current timestamp.
1250 youngest_candidate_msg_ts
= stream_iter
->current_msg_ts_ns
;
1251 youngest_candidate_stream_iter
= stream_iter
;
1252 } else if (ret
== 0) {
1253 /* Unable to pick which one should go first. */
1254 BT_COMP_LOGW("Cannot deterministically pick next live stream message iterator because they have identical next messages: "
1255 "stream-iter-addr=%p" "stream-iter-addr=%p",
1256 stream_iter
, youngest_candidate_stream_iter
);
1262 * trace_idx is not incremented since
1263 * g_ptr_array_remove_index_fast replaces the
1264 * element at trace_idx with the array's last element.
1266 g_ptr_array_remove_index_fast(session
->traces
,
1270 if (youngest_candidate_stream_iter
) {
1271 *youngest_session_stream_iter
= youngest_candidate_stream_iter
;
1272 stream_iter_status
= LTTNG_LIVE_ITERATOR_STATUS_OK
;
1275 * The only cases where we don't have a candidate for this
1277 * 1. if we reached the end of all the iterators of all the
1278 * traces of this session,
1279 * 2. if we never had live stream iterator in the first place.
1281 * In either cases, we return END.
1283 BT_ASSERT(session
->traces
->len
== 0);
1284 stream_iter_status
= LTTNG_LIVE_ITERATOR_STATUS_END
;
1287 return stream_iter_status
;
1291 void put_messages(bt_message_array_const msgs
, uint64_t count
)
1295 for (i
= 0; i
< count
; i
++) {
1296 BT_MESSAGE_PUT_REF_AND_RESET(msgs
[i
]);
1301 bt_component_class_message_iterator_next_method_status
lttng_live_msg_iter_next(
1302 bt_self_message_iterator
*self_msg_it
,
1303 bt_message_array_const msgs
, uint64_t capacity
,
1306 bt_component_class_message_iterator_next_method_status status
;
1307 enum lttng_live_viewer_status viewer_status
;
1308 struct lttng_live_msg_iter
*lttng_live_msg_iter
=
1309 bt_self_message_iterator_get_data(self_msg_it
);
1310 struct lttng_live_component
*lttng_live
=
1311 lttng_live_msg_iter
->lttng_live_comp
;
1312 bt_self_component
*self_comp
= lttng_live_msg_iter
->self_comp
;
1313 bt_logging_level log_level
= lttng_live_msg_iter
->log_level
;
1314 enum lttng_live_iterator_status stream_iter_status
;
1315 uint64_t session_idx
;
1319 BT_ASSERT_DBG(lttng_live_msg_iter
);
1321 if (G_UNLIKELY(lttng_live_msg_iter
->was_interrupted
)) {
1323 * The iterator was interrupted in a previous call to the
1324 * `_next()` method. We currently do not support generating
1325 * messages after such event. The babeltrace2 CLI should never
1326 * be running the graph after being interrupted. So this check
1327 * is to prevent other graph users from using this live
1328 * iterator in an messed up internal state.
1330 status
= BT_COMPONENT_CLASS_MESSAGE_ITERATOR_NEXT_METHOD_STATUS_ERROR
;
1331 BT_COMP_LOGE_APPEND_CAUSE(self_comp
,
1332 "Message iterator was interrupted during a previous call to the `next()` and currently does not support continuing after such event.");
1337 * Clear all the invalid message reference that might be left over in
1340 memset(msgs
, 0, capacity
* sizeof(*msgs
));
1343 * If no session are exposed on the relay found at the url provided by
1344 * the user, session count will be 0. In this case, we return status
1345 * end to return gracefully.
1347 if (lttng_live_msg_iter
->sessions
->len
== 0) {
1348 if (lttng_live
->params
.sess_not_found_act
!=
1349 SESSION_NOT_FOUND_ACTION_CONTINUE
) {
1350 status
= BT_COMPONENT_CLASS_MESSAGE_ITERATOR_NEXT_METHOD_STATUS_END
;
1354 * The are no more active session for this session
1355 * name. Retry to create a viewer session for the
1356 * requested session name.
1358 viewer_status
= lttng_live_create_viewer_session(lttng_live_msg_iter
);
1359 if (viewer_status
!= LTTNG_LIVE_VIEWER_STATUS_OK
) {
1360 if (viewer_status
== LTTNG_LIVE_VIEWER_STATUS_ERROR
) {
1361 status
= BT_COMPONENT_CLASS_MESSAGE_ITERATOR_NEXT_METHOD_STATUS_ERROR
;
1362 BT_COMP_LOGE_APPEND_CAUSE(self_comp
,
1363 "Error creating LTTng live viewer session");
1364 } else if (viewer_status
== LTTNG_LIVE_VIEWER_STATUS_INTERRUPTED
) {
1365 status
= BT_COMPONENT_CLASS_MESSAGE_ITERATOR_NEXT_METHOD_STATUS_AGAIN
;
1374 if (lttng_live_msg_iter
->active_stream_iter
== 0) {
1375 lttng_live_force_new_streams_and_metadata(lttng_live_msg_iter
);
1379 * Here the muxing of message is done.
1381 * We need to iterate over all the streams of all the traces of all the
1382 * viewer sessions in order to get the message with the smallest
1383 * timestamp. In this case, a session is a viewer session and there is
1384 * one viewer session per consumer daemon. (UST 32bit, UST 64bit and/or
1385 * kernel). Each viewer session can have multiple traces, for example,
1386 * 64bit UST viewer sessions could have multiple per-pid traces.
1388 * We iterate over the streams of each traces to update and see what is
1389 * their next message's timestamp. From those timestamps, we select the
1390 * message with the smallest timestamp as the best candidate message
1391 * for that trace and do the same thing across all the sessions.
1393 * We then compare the timestamp of best candidate message of all the
1394 * sessions to pick the message with the smallest timestamp and we
1397 while (*count
< capacity
) {
1398 struct lttng_live_stream_iterator
*youngest_stream_iter
= NULL
,
1399 *candidate_stream_iter
= NULL
;
1400 int64_t youngest_msg_ts_ns
= INT64_MAX
;
1402 BT_ASSERT_DBG(lttng_live_msg_iter
->sessions
);
1404 while (session_idx
< lttng_live_msg_iter
->sessions
->len
) {
1405 struct lttng_live_session
*session
=
1406 g_ptr_array_index(lttng_live_msg_iter
->sessions
,
1409 /* Find the best candidate message to send downstream. */
1410 stream_iter_status
= next_stream_iterator_for_session(
1411 lttng_live_msg_iter
, session
,
1412 &candidate_stream_iter
);
1414 /* If we receive an END status, it means that either:
1415 * - Those traces never had active streams (UST with no
1416 * data produced yet),
1417 * - All live stream iterators have ENDed.*/
1418 if (stream_iter_status
== LTTNG_LIVE_ITERATOR_STATUS_END
) {
1419 if (session
->closed
&& session
->traces
->len
== 0) {
1421 * Remove the session from the list.
1422 * session_idx is not modified since
1423 * g_ptr_array_remove_index_fast
1424 * replaces the the removed element with
1425 * the array's last element.
1427 g_ptr_array_remove_index_fast(
1428 lttng_live_msg_iter
->sessions
,
1436 if (stream_iter_status
!= LTTNG_LIVE_ITERATOR_STATUS_OK
) {
1440 if (G_UNLIKELY(youngest_stream_iter
== NULL
) ||
1441 candidate_stream_iter
->current_msg_ts_ns
< youngest_msg_ts_ns
) {
1442 youngest_msg_ts_ns
= candidate_stream_iter
->current_msg_ts_ns
;
1443 youngest_stream_iter
= candidate_stream_iter
;
1444 } else if (candidate_stream_iter
->current_msg_ts_ns
== youngest_msg_ts_ns
) {
1446 * The currently selected message to be sent
1447 * downstream next has the exact same timestamp
1448 * that of the current candidate message. We
1449 * must break the tie in a predictable manner.
1451 BT_COMP_LOGD_STR("Two of the next message candidates have the same timestamps, pick one deterministically.");
1453 * Order the messages in an arbitrary but
1454 * deterministic way.
1456 int ret
= common_muxing_compare_messages(
1457 candidate_stream_iter
->current_msg
,
1458 youngest_stream_iter
->current_msg
);
1461 * The `candidate_stream_iter->current_msg`
1462 * should go first. Update the next
1463 * iterator and the current timestamp.
1465 youngest_msg_ts_ns
= candidate_stream_iter
->current_msg_ts_ns
;
1466 youngest_stream_iter
= candidate_stream_iter
;
1467 } else if (ret
== 0) {
1468 /* Unable to pick which one should go first. */
1469 BT_COMP_LOGW("Cannot deterministically pick next live stream message iterator because they have identical next messages: "
1470 "next-stream-iter-addr=%p" "candidate-stream-iter-addr=%p",
1471 youngest_stream_iter
, candidate_stream_iter
);
1478 if (!youngest_stream_iter
) {
1479 stream_iter_status
= LTTNG_LIVE_ITERATOR_STATUS_AGAIN
;
1483 BT_ASSERT_DBG(youngest_stream_iter
->current_msg
);
1484 /* Ensure monotonicity. */
1485 BT_ASSERT_DBG(lttng_live_msg_iter
->last_msg_ts_ns
<=
1486 youngest_stream_iter
->current_msg_ts_ns
);
1489 * Insert the next message to the message batch. This will set
1490 * stream iterator current messsage to NULL so that next time
1491 * we fetch the next message of that stream iterator
1493 BT_MESSAGE_MOVE_REF(msgs
[*count
], youngest_stream_iter
->current_msg
);
1496 /* Update the last timestamp in nanoseconds sent downstream. */
1497 lttng_live_msg_iter
->last_msg_ts_ns
= youngest_msg_ts_ns
;
1498 youngest_stream_iter
->current_msg_ts_ns
= INT64_MAX
;
1500 stream_iter_status
= LTTNG_LIVE_ITERATOR_STATUS_OK
;
1504 switch (stream_iter_status
) {
1505 case LTTNG_LIVE_ITERATOR_STATUS_OK
:
1506 case LTTNG_LIVE_ITERATOR_STATUS_AGAIN
:
1508 * If we gathered messages, return _OK even if the graph was
1509 * interrupted. This allows for the components downstream to at
1510 * least get the thoses messages. If the graph was indeed
1511 * interrupted there should not be another _next() call as the
1512 * application will tear down the graph. This component class
1513 * doesn't support restarting after an interruption.
1516 status
= BT_COMPONENT_CLASS_MESSAGE_ITERATOR_NEXT_METHOD_STATUS_OK
;
1518 status
= BT_COMPONENT_CLASS_MESSAGE_ITERATOR_NEXT_METHOD_STATUS_AGAIN
;
1521 case LTTNG_LIVE_ITERATOR_STATUS_END
:
1522 status
= BT_COMPONENT_CLASS_MESSAGE_ITERATOR_NEXT_METHOD_STATUS_END
;
1524 case LTTNG_LIVE_ITERATOR_STATUS_NOMEM
:
1525 BT_COMP_LOGE_APPEND_CAUSE(self_comp
,
1526 "Memory error preparing the next batch of messages: "
1527 "live-iter-status=%s",
1528 lttng_live_iterator_status_string(stream_iter_status
));
1529 status
= BT_COMPONENT_CLASS_MESSAGE_ITERATOR_NEXT_METHOD_STATUS_MEMORY_ERROR
;
1531 case LTTNG_LIVE_ITERATOR_STATUS_ERROR
:
1532 case LTTNG_LIVE_ITERATOR_STATUS_INVAL
:
1533 case LTTNG_LIVE_ITERATOR_STATUS_UNSUPPORTED
:
1534 BT_COMP_LOGE_APPEND_CAUSE(self_comp
,
1535 "Error preparing the next batch of messages: "
1536 "live-iter-status=%s",
1537 lttng_live_iterator_status_string(stream_iter_status
));
1539 status
= BT_COMPONENT_CLASS_MESSAGE_ITERATOR_NEXT_METHOD_STATUS_ERROR
;
1540 /* Put all existing messages on error. */
1541 put_messages(msgs
, *count
);
1552 struct lttng_live_msg_iter
*lttng_live_msg_iter_create(
1553 struct lttng_live_component
*lttng_live_comp
,
1554 bt_self_message_iterator
*self_msg_it
)
1556 bt_self_component
*self_comp
= lttng_live_comp
->self_comp
;
1557 bt_logging_level log_level
= lttng_live_comp
->log_level
;
1559 struct lttng_live_msg_iter
*lttng_live_msg_iter
=
1560 g_new0(struct lttng_live_msg_iter
, 1);
1561 if (!lttng_live_msg_iter
) {
1562 BT_COMP_LOGE_APPEND_CAUSE(self_comp
,
1563 "Failed to allocate lttng_live_msg_iter");
1567 lttng_live_msg_iter
->log_level
= lttng_live_comp
->log_level
;
1568 lttng_live_msg_iter
->self_comp
= lttng_live_comp
->self_comp
;
1569 lttng_live_msg_iter
->lttng_live_comp
= lttng_live_comp
;
1570 lttng_live_msg_iter
->self_msg_iter
= self_msg_it
;
1572 lttng_live_msg_iter
->active_stream_iter
= 0;
1573 lttng_live_msg_iter
->last_msg_ts_ns
= INT64_MIN
;
1574 lttng_live_msg_iter
->was_interrupted
= false;
1576 lttng_live_msg_iter
->sessions
= g_ptr_array_new_with_free_func(
1577 (GDestroyNotify
) lttng_live_destroy_session
);
1578 BT_ASSERT(lttng_live_msg_iter
->sessions
);
1581 return lttng_live_msg_iter
;
1586 bt_component_class_message_iterator_initialize_method_status
lttng_live_msg_iter_init(
1587 bt_self_message_iterator
*self_msg_it
,
1588 bt_self_message_iterator_configuration
*config
,
1589 bt_self_component_source
*self_comp_src
,
1590 bt_self_component_port_output
*self_port
)
1592 bt_component_class_message_iterator_initialize_method_status status
;
1593 bt_self_component
*self_comp
=
1594 bt_self_component_source_as_self_component(self_comp_src
);
1595 struct lttng_live_component
*lttng_live
;
1596 struct lttng_live_msg_iter
*lttng_live_msg_iter
;
1597 enum lttng_live_viewer_status viewer_status
;
1598 bt_logging_level log_level
;
1600 BT_ASSERT(self_msg_it
);
1602 lttng_live
= bt_self_component_get_data(self_comp
);
1603 log_level
= lttng_live
->log_level
;
1604 self_comp
= lttng_live
->self_comp
;
1607 /* There can be only one downstream iterator at the same time. */
1608 BT_ASSERT(!lttng_live
->has_msg_iter
);
1609 lttng_live
->has_msg_iter
= true;
1611 lttng_live_msg_iter
= lttng_live_msg_iter_create(lttng_live
,
1613 if (!lttng_live_msg_iter
) {
1614 status
= BT_COMPONENT_CLASS_MESSAGE_ITERATOR_INITIALIZE_METHOD_STATUS_MEMORY_ERROR
;
1615 BT_COMP_LOGE_APPEND_CAUSE(self_comp
,
1616 "Failed to create lttng_live_msg_iter");
1620 viewer_status
= live_viewer_connection_create(self_comp
, NULL
,
1621 log_level
, lttng_live
->params
.url
->str
, false,
1622 lttng_live_msg_iter
, <tng_live_msg_iter
->viewer_connection
);
1623 if (viewer_status
!= LTTNG_LIVE_VIEWER_STATUS_OK
) {
1624 if (viewer_status
== LTTNG_LIVE_VIEWER_STATUS_ERROR
) {
1625 BT_COMP_LOGE_APPEND_CAUSE(self_comp
,
1626 "Failed to create viewer connection");
1627 } else if (viewer_status
== LTTNG_LIVE_VIEWER_STATUS_INTERRUPTED
) {
1629 * Interruption in the _iter_init() method is not
1630 * supported. Return an error.
1632 BT_COMP_LOGE_APPEND_CAUSE(self_comp
,
1633 "Interrupted while creating viewer connection");
1638 viewer_status
= lttng_live_create_viewer_session(lttng_live_msg_iter
);
1639 if (viewer_status
!= LTTNG_LIVE_VIEWER_STATUS_OK
) {
1640 if (viewer_status
== LTTNG_LIVE_VIEWER_STATUS_ERROR
) {
1641 BT_COMP_LOGE_APPEND_CAUSE(self_comp
,
1642 "Failed to create viewer session");
1643 } else if (viewer_status
== LTTNG_LIVE_VIEWER_STATUS_INTERRUPTED
) {
1645 * Interruption in the _iter_init() method is not
1646 * supported. Return an error.
1648 BT_COMP_LOGE_APPEND_CAUSE(self_comp
,
1649 "Interrupted when creating viewer session");
1654 if (lttng_live_msg_iter
->sessions
->len
== 0) {
1655 switch (lttng_live
->params
.sess_not_found_act
) {
1656 case SESSION_NOT_FOUND_ACTION_CONTINUE
:
1657 BT_COMP_LOGI("Unable to connect to the requested live viewer session. Keep trying to connect because of "
1658 "%s=\"%s\" component parameter: url=\"%s\"",
1659 SESS_NOT_FOUND_ACTION_PARAM
,
1660 SESS_NOT_FOUND_ACTION_CONTINUE_STR
,
1661 lttng_live
->params
.url
->str
);
1663 case SESSION_NOT_FOUND_ACTION_FAIL
:
1664 BT_COMP_LOGE_APPEND_CAUSE(self_comp
,
1665 "Unable to connect to the requested live viewer session. Fail the message iterator initialization because of %s=\"%s\" "
1666 "component parameter: url =\"%s\"",
1667 SESS_NOT_FOUND_ACTION_PARAM
,
1668 SESS_NOT_FOUND_ACTION_FAIL_STR
,
1669 lttng_live
->params
.url
->str
);
1671 case SESSION_NOT_FOUND_ACTION_END
:
1672 BT_COMP_LOGI("Unable to connect to the requested live viewer session. End gracefully at the first _next() "
1673 "call because of %s=\"%s\" component parameter: "
1674 "url=\"%s\"", SESS_NOT_FOUND_ACTION_PARAM
,
1675 SESS_NOT_FOUND_ACTION_END_STR
,
1676 lttng_live
->params
.url
->str
);
1683 bt_self_message_iterator_set_data(self_msg_it
, lttng_live_msg_iter
);
1684 status
= BT_COMPONENT_CLASS_MESSAGE_ITERATOR_INITIALIZE_METHOD_STATUS_OK
;
1688 status
= BT_COMPONENT_CLASS_MESSAGE_ITERATOR_INITIALIZE_METHOD_STATUS_ERROR
;
1689 lttng_live_msg_iter_destroy(lttng_live_msg_iter
);
1694 static struct bt_param_validation_map_value_entry_descr list_sessions_params
[] = {
1695 { URL_PARAM
, BT_PARAM_VALIDATION_MAP_VALUE_ENTRY_MANDATORY
, { .type
= BT_VALUE_TYPE_STRING
} },
1696 BT_PARAM_VALIDATION_MAP_VALUE_ENTRY_END
1700 bt_component_class_query_method_status
lttng_live_query_list_sessions(
1701 const bt_value
*params
, const bt_value
**result
,
1702 bt_self_component_class
*self_comp_class
,
1703 bt_logging_level log_level
)
1705 bt_component_class_query_method_status status
;
1706 const bt_value
*url_value
= NULL
;
1708 struct live_viewer_connection
*viewer_connection
= NULL
;
1709 enum lttng_live_viewer_status viewer_status
;
1710 enum bt_param_validation_status validation_status
;
1711 gchar
*validate_error
= NULL
;
1713 validation_status
= bt_param_validation_validate(params
,
1714 list_sessions_params
, &validate_error
);
1715 if (validation_status
== BT_PARAM_VALIDATION_STATUS_MEMORY_ERROR
) {
1716 status
= BT_COMPONENT_CLASS_QUERY_METHOD_STATUS_MEMORY_ERROR
;
1718 } else if (validation_status
== BT_PARAM_VALIDATION_STATUS_VALIDATION_ERROR
) {
1719 status
= BT_COMPONENT_CLASS_QUERY_METHOD_STATUS_ERROR
;
1720 BT_COMP_CLASS_LOGE_APPEND_CAUSE(self_comp_class
, "%s",
1725 url_value
= bt_value_map_borrow_entry_value_const(params
, URL_PARAM
);
1726 url
= bt_value_string_get(url_value
);
1728 viewer_status
= live_viewer_connection_create(NULL
, self_comp_class
,
1729 log_level
, url
, true, NULL
, &viewer_connection
);
1730 if (viewer_status
!= LTTNG_LIVE_VIEWER_STATUS_OK
) {
1731 if (viewer_status
== LTTNG_LIVE_VIEWER_STATUS_ERROR
) {
1732 BT_COMP_CLASS_LOGE_APPEND_CAUSE(self_comp_class
,
1733 "Failed to create viewer connection");
1734 status
= BT_COMPONENT_CLASS_QUERY_METHOD_STATUS_ERROR
;
1735 } else if (viewer_status
== LTTNG_LIVE_VIEWER_STATUS_INTERRUPTED
) {
1736 status
= BT_COMPONENT_CLASS_QUERY_METHOD_STATUS_AGAIN
;
1743 status
= live_viewer_connection_list_sessions(viewer_connection
,
1745 if (status
!= BT_COMPONENT_CLASS_QUERY_METHOD_STATUS_OK
) {
1746 BT_COMP_CLASS_LOGE_APPEND_CAUSE(self_comp_class
,
1747 "Failed to list viewer sessions");
1754 BT_VALUE_PUT_REF_AND_RESET(*result
);
1757 status
= BT_COMPONENT_CLASS_QUERY_METHOD_STATUS_ERROR
;
1761 if (viewer_connection
) {
1762 live_viewer_connection_destroy(viewer_connection
);
1765 g_free(validate_error
);
1771 bt_component_class_query_method_status
lttng_live_query_support_info(
1772 const bt_value
*params
, const bt_value
**result
,
1773 bt_self_component_class
*self_comp_class
,
1774 bt_logging_level log_level
)
1776 bt_component_class_query_method_status status
=
1777 BT_COMPONENT_CLASS_QUERY_METHOD_STATUS_OK
;
1778 const bt_value
*input_type_value
;
1779 const bt_value
*input_value
;
1781 struct bt_common_lttng_live_url_parts parts
= { 0 };
1783 /* Used by the logging macros */
1784 __attribute__((unused
)) bt_self_component
*self_comp
= NULL
;
1787 input_type_value
= bt_value_map_borrow_entry_value_const(params
,
1789 if (!input_type_value
) {
1790 BT_COMP_CLASS_LOGE_APPEND_CAUSE(self_comp_class
,
1791 "Missing expected `type` parameter.");
1795 if (!bt_value_is_string(input_type_value
)) {
1796 BT_COMP_CLASS_LOGE_APPEND_CAUSE(self_comp_class
,
1797 "`type` parameter is not a string value.");
1801 if (strcmp(bt_value_string_get(input_type_value
), "string") != 0) {
1802 /* We don't handle file system paths */
1806 input_value
= bt_value_map_borrow_entry_value_const(params
, "input");
1808 BT_COMP_CLASS_LOGE_APPEND_CAUSE(self_comp_class
,
1809 "Missing expected `input` parameter.");
1813 if (!bt_value_is_string(input_value
)) {
1814 BT_COMP_CLASS_LOGE_APPEND_CAUSE(self_comp_class
,
1815 "`input` parameter is not a string value.");
1819 parts
= bt_common_parse_lttng_live_url(bt_value_string_get(input_value
),
1821 if (parts
.session_name
) {
1823 * Looks pretty much like an LTTng live URL: we got the
1824 * session name part, which forms a complete URL.
1830 *result
= bt_value_real_create_init(weight
);
1832 status
= BT_COMPONENT_CLASS_QUERY_METHOD_STATUS_MEMORY_ERROR
;
1840 status
= BT_COMPONENT_CLASS_QUERY_METHOD_STATUS_ERROR
;
1843 BT_ASSERT(!*result
);
1846 bt_common_destroy_lttng_live_url_parts(&parts
);
1851 bt_component_class_query_method_status
lttng_live_query(
1852 bt_self_component_class_source
*comp_class
,
1853 bt_private_query_executor
*priv_query_exec
,
1854 const char *object
, const bt_value
*params
,
1855 __attribute__((unused
)) void *method_data
,
1856 const bt_value
**result
)
1858 bt_component_class_query_method_status status
=
1859 BT_COMPONENT_CLASS_QUERY_METHOD_STATUS_OK
;
1860 bt_self_component
*self_comp
= NULL
;
1861 bt_self_component_class
*self_comp_class
=
1862 bt_self_component_class_source_as_self_component_class(comp_class
);
1863 bt_logging_level log_level
= bt_query_executor_get_logging_level(
1864 bt_private_query_executor_as_query_executor_const(
1867 if (strcmp(object
, "sessions") == 0) {
1868 status
= lttng_live_query_list_sessions(params
, result
,
1869 self_comp_class
, log_level
);
1870 } else if (strcmp(object
, "babeltrace.support-info") == 0) {
1871 status
= lttng_live_query_support_info(params
, result
,
1872 self_comp_class
, log_level
);
1874 BT_COMP_LOGI("Unknown query object `%s`", object
);
1875 status
= BT_COMPONENT_CLASS_QUERY_METHOD_STATUS_UNKNOWN_OBJECT
;
1884 void lttng_live_component_destroy_data(struct lttng_live_component
*lttng_live
)
1889 if (lttng_live
->params
.url
) {
1890 g_string_free(lttng_live
->params
.url
, TRUE
);
1896 void lttng_live_component_finalize(bt_self_component_source
*component
)
1898 void *data
= bt_self_component_get_data(
1899 bt_self_component_source_as_self_component(component
));
1904 lttng_live_component_destroy_data(data
);
1908 enum session_not_found_action
parse_session_not_found_action_param(
1909 const bt_value
*no_session_param
)
1911 enum session_not_found_action action
;
1912 const char *no_session_act_str
= bt_value_string_get(no_session_param
);
1914 if (strcmp(no_session_act_str
, SESS_NOT_FOUND_ACTION_CONTINUE_STR
) == 0) {
1915 action
= SESSION_NOT_FOUND_ACTION_CONTINUE
;
1916 } else if (strcmp(no_session_act_str
, SESS_NOT_FOUND_ACTION_FAIL_STR
) == 0) {
1917 action
= SESSION_NOT_FOUND_ACTION_FAIL
;
1919 BT_ASSERT(strcmp(no_session_act_str
, SESS_NOT_FOUND_ACTION_END_STR
) == 0);
1920 action
= SESSION_NOT_FOUND_ACTION_END
;
1926 static struct bt_param_validation_value_descr inputs_elem_descr
= {
1927 .type
= BT_VALUE_TYPE_STRING
,
1930 static const char *sess_not_found_action_choices
[] = {
1931 SESS_NOT_FOUND_ACTION_CONTINUE_STR
,
1932 SESS_NOT_FOUND_ACTION_FAIL_STR
,
1933 SESS_NOT_FOUND_ACTION_END_STR
,
1936 static struct bt_param_validation_map_value_entry_descr params_descr
[] = {
1937 { INPUTS_PARAM
, BT_PARAM_VALIDATION_MAP_VALUE_ENTRY_MANDATORY
, { BT_VALUE_TYPE_ARRAY
, .array
= {
1940 .element_type
= &inputs_elem_descr
,
1942 { SESS_NOT_FOUND_ACTION_PARAM
, BT_PARAM_VALIDATION_MAP_VALUE_ENTRY_OPTIONAL
, { BT_VALUE_TYPE_STRING
, .string
= {
1943 .choices
= sess_not_found_action_choices
,
1945 BT_PARAM_VALIDATION_MAP_VALUE_ENTRY_END
1949 bt_component_class_initialize_method_status
lttng_live_component_create(
1950 const bt_value
*params
,
1951 bt_logging_level log_level
,
1952 bt_self_component
*self_comp
,
1953 struct lttng_live_component
**component
)
1955 struct lttng_live_component
*lttng_live
= NULL
;
1956 const bt_value
*inputs_value
;
1957 const bt_value
*url_value
;
1958 const bt_value
*value
;
1960 enum bt_param_validation_status validation_status
;
1961 gchar
*validation_error
= NULL
;
1962 bt_component_class_initialize_method_status status
;
1964 validation_status
= bt_param_validation_validate(params
, params_descr
,
1966 if (validation_status
== BT_PARAM_VALIDATION_STATUS_MEMORY_ERROR
) {
1967 status
= BT_COMPONENT_CLASS_INITIALIZE_METHOD_STATUS_MEMORY_ERROR
;
1969 } else if (validation_status
== BT_PARAM_VALIDATION_STATUS_VALIDATION_ERROR
) {
1970 BT_COMP_LOGE_APPEND_CAUSE(self_comp
, "%s", validation_error
);
1971 status
= BT_COMPONENT_CLASS_INITIALIZE_METHOD_STATUS_ERROR
;
1975 lttng_live
= g_new0(struct lttng_live_component
, 1);
1977 status
= BT_COMPONENT_CLASS_INITIALIZE_METHOD_STATUS_MEMORY_ERROR
;
1980 lttng_live
->log_level
= log_level
;
1981 lttng_live
->self_comp
= self_comp
;
1982 lttng_live
->max_query_size
= MAX_QUERY_SIZE
;
1983 lttng_live
->has_msg_iter
= false;
1986 bt_value_map_borrow_entry_value_const(params
, INPUTS_PARAM
);
1988 bt_value_array_borrow_element_by_index_const(inputs_value
, 0);
1989 url
= bt_value_string_get(url_value
);
1991 lttng_live
->params
.url
= g_string_new(url
);
1992 if (!lttng_live
->params
.url
) {
1993 status
= BT_COMPONENT_CLASS_INITIALIZE_METHOD_STATUS_MEMORY_ERROR
;
1997 value
= bt_value_map_borrow_entry_value_const(params
,
1998 SESS_NOT_FOUND_ACTION_PARAM
);
2000 lttng_live
->params
.sess_not_found_act
=
2001 parse_session_not_found_action_param(value
);
2003 BT_COMP_LOGI("Optional `%s` parameter is missing: "
2004 "defaulting to `%s`.",
2005 SESS_NOT_FOUND_ACTION_PARAM
,
2006 SESS_NOT_FOUND_ACTION_CONTINUE_STR
);
2007 lttng_live
->params
.sess_not_found_act
=
2008 SESSION_NOT_FOUND_ACTION_CONTINUE
;
2011 status
= BT_COMPONENT_CLASS_INITIALIZE_METHOD_STATUS_OK
;
2015 lttng_live_component_destroy_data(lttng_live
);
2018 g_free(validation_error
);
2020 *component
= lttng_live
;
2025 bt_component_class_initialize_method_status
lttng_live_component_init(
2026 bt_self_component_source
*self_comp_src
,
2027 bt_self_component_source_configuration
*config
,
2028 const bt_value
*params
,
2029 __attribute__((unused
)) void *init_method_data
)
2031 struct lttng_live_component
*lttng_live
;
2032 bt_component_class_initialize_method_status ret
;
2033 bt_self_component
*self_comp
=
2034 bt_self_component_source_as_self_component(self_comp_src
);
2035 bt_logging_level log_level
= bt_component_get_logging_level(
2036 bt_self_component_as_component(self_comp
));
2037 bt_self_component_add_port_status add_port_status
;
2039 ret
= lttng_live_component_create(params
, log_level
, self_comp
, <tng_live
);
2040 if (ret
!= BT_COMPONENT_CLASS_INITIALIZE_METHOD_STATUS_OK
) {
2044 add_port_status
= bt_self_component_source_add_output_port(
2045 self_comp_src
, "out", NULL
, NULL
);
2046 if (add_port_status
!= BT_SELF_COMPONENT_ADD_PORT_STATUS_OK
) {
2047 ret
= (int) add_port_status
;
2051 bt_self_component_set_data(self_comp
, lttng_live
);
2055 lttng_live_component_destroy_data(lttng_live
);