2 * Copyright (C) 2013 - Julien Desfossez <jdesfossez@efficios.com>
3 * Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
5 * Permission is hereby granted, free of charge, to any person obtaining a copy
6 * of this software and associated documentation files (the "Software"), to deal
7 * in the Software without restriction, including without limitation the rights
8 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 * copies of the Software, and to permit persons to whom the Software is
10 * furnished to do so, subject to the following conditions:
12 * The above copyright notice and this permission notice shall be included in
13 * all copies or substantial portions of the Software.
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
24 #include <sys/socket.h>
25 #include <sys/types.h>
26 #include <netinet/in.h>
36 #include <babeltrace/ctf/ctf-index.h>
38 #include <babeltrace/babeltrace.h>
39 #include <babeltrace/ctf/events.h>
40 #include <babeltrace/ctf/callbacks.h>
41 #include <babeltrace/ctf/iterator.h>
43 /* for packet_index */
44 #include <babeltrace/ctf/types.h>
46 #include <babeltrace/ctf/metadata.h>
47 #include <babeltrace/ctf-text/types.h>
48 #include <babeltrace/ctf/events-internal.h>
49 #include <formats/ctf/events-private.h>
51 #include <babeltrace/endian.h>
52 #include <babeltrace/compat/memstream.h>
53 #include <babeltrace/compat/send.h>
54 #include <babeltrace/compat/string.h>
55 #include <babeltrace/compat/mman.h>
56 #include <babeltrace/babeltrace-internal.h>
58 #include "lttng-live.h"
59 #include "lttng-viewer-abi.h"
61 #define ACTIVE_POLL_DELAY 100 /* ms */
63 static void ctf_live_packet_seek(struct bt_stream_pos
*stream_pos
,
64 size_t index
, int whence
);
65 static int add_traces(struct lttng_live_ctx
*ctx
);
66 static int del_traces(gpointer key
, gpointer value
, gpointer user_data
);
67 static int get_new_metadata(struct lttng_live_ctx
*ctx
,
68 struct lttng_live_viewer_stream
*viewer_stream
,
72 ssize_t
lttng_live_recv(int fd
, void *buf
, size_t len
)
75 size_t copied
= 0, to_copy
= len
;
78 ret
= recv(fd
, buf
+ copied
, to_copy
, 0);
80 assert(ret
<= to_copy
);
84 } while ((ret
> 0 && to_copy
> 0)
85 || (ret
< 0 && errno
== EINTR
));
88 /* ret = 0 means orderly shutdown, ret < 0 is error. */
93 ssize_t
lttng_live_send(int fd
, const void *buf
, size_t len
)
98 ret
= bt_send_nosigpipe(fd
, buf
, len
);
99 } while (ret
< 0 && errno
== EINTR
);
103 int lttng_live_connect_viewer(struct lttng_live_ctx
*ctx
)
105 struct hostent
*host
;
106 struct sockaddr_in server_addr
;
109 if (lttng_live_should_quit()) {
114 host
= gethostbyname(ctx
->relay_hostname
);
116 fprintf(stderr
, "[error] Cannot lookup hostname %s\n",
117 ctx
->relay_hostname
);
121 if ((ctx
->control_sock
= socket(AF_INET
, SOCK_STREAM
, 0)) == -1) {
126 server_addr
.sin_family
= AF_INET
;
127 server_addr
.sin_port
= htons(ctx
->port
);
128 server_addr
.sin_addr
= *((struct in_addr
*) host
->h_addr
);
129 memset(&(server_addr
.sin_zero
), 0, 8);
131 if (connect(ctx
->control_sock
, (struct sockaddr
*) &server_addr
,
132 sizeof(struct sockaddr
)) == -1) {
143 fprintf(stderr
, "[error] Connection failed\n");
147 int lttng_live_establish_connection(struct lttng_live_ctx
*ctx
)
149 struct lttng_viewer_cmd cmd
;
150 struct lttng_viewer_connect connect
;
154 if (lttng_live_should_quit()) {
159 cmd
.cmd
= htobe32(LTTNG_VIEWER_CONNECT
);
160 cmd
.data_size
= htobe64((uint64_t) sizeof(connect
));
161 cmd
.cmd_version
= htobe32(0);
163 connect
.viewer_session_id
= -1ULL; /* will be set on recv */
164 connect
.major
= htobe32(LTTNG_LIVE_MAJOR
);
165 connect
.minor
= htobe32(LTTNG_LIVE_MINOR
);
166 connect
.type
= htobe32(LTTNG_VIEWER_CLIENT_COMMAND
);
168 ret_len
= lttng_live_send(ctx
->control_sock
, &cmd
, sizeof(cmd
));
170 perror("[error] Error sending cmd");
173 assert(ret_len
== sizeof(cmd
));
175 ret_len
= lttng_live_send(ctx
->control_sock
, &connect
, sizeof(connect
));
177 perror("[error] Error sending version");
180 assert(ret_len
== sizeof(connect
));
182 ret_len
= lttng_live_recv(ctx
->control_sock
, &connect
, sizeof(connect
));
184 fprintf(stderr
, "[error] Remote side has closed connection\n");
188 perror("[error] Error receiving version");
191 assert(ret_len
== sizeof(connect
));
193 printf_verbose("Received viewer session ID : %" PRIu64
"\n",
194 be64toh(connect
.viewer_session_id
));
195 printf_verbose("Relayd version : %u.%u\n", be32toh(connect
.major
),
196 be32toh(connect
.minor
));
198 if (LTTNG_LIVE_MAJOR
!= be32toh(connect
.major
)) {
199 fprintf(stderr
, "[error] Incompatible lttng-relayd protocol\n");
202 /* Use the smallest protocol version implemented. */
203 if (LTTNG_LIVE_MINOR
> be32toh(connect
.minor
)) {
204 ctx
->minor
= be32toh(connect
.minor
);
206 ctx
->minor
= LTTNG_LIVE_MINOR
;
208 ctx
->major
= LTTNG_LIVE_MAJOR
;
214 fprintf(stderr
, "[error] Unable to establish connection\n");
219 void free_session_list(GPtrArray
*session_list
)
222 struct lttng_live_relay_session
*relay_session
;
224 for (i
= 0; i
< session_list
->len
; i
++) {
225 relay_session
= g_ptr_array_index(session_list
, i
);
226 free(relay_session
->name
);
227 free(relay_session
->hostname
);
229 g_ptr_array_free(session_list
, TRUE
);
233 void print_session_list(GPtrArray
*session_list
, const char *path
)
236 struct lttng_live_relay_session
*relay_session
;
238 for (i
= 0; i
< session_list
->len
; i
++) {
239 relay_session
= g_ptr_array_index(session_list
, i
);
240 fprintf(LTTNG_LIVE_OUTPUT_FP
, "%s/host/%s/%s (timer = %u, "
241 "%u stream(s), %u client(s) connected)\n",
242 path
, relay_session
->hostname
,
243 relay_session
->name
, relay_session
->timer
,
244 relay_session
->streams
, relay_session
->clients
);
249 void update_session_list(GPtrArray
*session_list
, char *hostname
,
250 char *session_name
, uint32_t streams
, uint32_t clients
,
254 struct lttng_live_relay_session
*relay_session
;
256 for (i
= 0; i
< session_list
->len
; i
++) {
257 relay_session
= g_ptr_array_index(session_list
, i
);
258 if ((strncmp(relay_session
->hostname
, hostname
, MAXNAMLEN
) == 0) &&
259 strncmp(relay_session
->name
,
260 session_name
, MAXNAMLEN
) == 0) {
261 relay_session
->streams
+= streams
;
262 if (relay_session
->clients
< clients
)
263 relay_session
->clients
= clients
;
271 relay_session
= g_new0(struct lttng_live_relay_session
, 1);
272 relay_session
->hostname
= bt_strndup(hostname
, MAXNAMLEN
);
273 relay_session
->name
= bt_strndup(session_name
, MAXNAMLEN
);
274 relay_session
->clients
= clients
;
275 relay_session
->streams
= streams
;
276 relay_session
->timer
= timer
;
277 g_ptr_array_add(session_list
, relay_session
);
280 int lttng_live_list_sessions(struct lttng_live_ctx
*ctx
, const char *path
)
282 struct lttng_viewer_cmd cmd
;
283 struct lttng_viewer_list_sessions list
;
284 struct lttng_viewer_session lsession
;
285 int i
, ret
, sessions_count
, print_list
= 0;
288 GPtrArray
*session_list
= NULL
;
290 if (lttng_live_should_quit()) {
295 if (strlen(ctx
->session_name
) == 0) {
297 session_list
= g_ptr_array_new();
300 cmd
.cmd
= htobe32(LTTNG_VIEWER_LIST_SESSIONS
);
301 cmd
.data_size
= htobe64((uint64_t) 0);
302 cmd
.cmd_version
= htobe32(0);
304 ret_len
= lttng_live_send(ctx
->control_sock
, &cmd
, sizeof(cmd
));
306 perror("[error] Error sending cmd");
309 assert(ret_len
== sizeof(cmd
));
311 ret_len
= lttng_live_recv(ctx
->control_sock
, &list
, sizeof(list
));
313 fprintf(stderr
, "[error] Remote side has closed connection\n");
317 perror("[error] Error receiving session list");
320 assert(ret_len
== sizeof(list
));
322 sessions_count
= be32toh(list
.sessions_count
);
323 for (i
= 0; i
< sessions_count
; i
++) {
324 ret_len
= lttng_live_recv(ctx
->control_sock
, &lsession
, sizeof(lsession
));
326 fprintf(stderr
, "[error] Remote side has closed connection\n");
330 perror("[error] Error receiving session");
333 assert(ret_len
== sizeof(lsession
));
334 lsession
.hostname
[LTTNG_VIEWER_HOST_NAME_MAX
- 1] = '\0';
335 lsession
.session_name
[LTTNG_VIEWER_NAME_MAX
- 1] = '\0';
336 session_id
= be64toh(lsession
.id
);
339 update_session_list(session_list
,
341 lsession
.session_name
,
342 be32toh(lsession
.streams
),
343 be32toh(lsession
.clients
),
344 be32toh(lsession
.live_timer
));
346 if ((strncmp(lsession
.session_name
, ctx
->session_name
,
347 MAXNAMLEN
) == 0) && (strncmp(lsession
.hostname
,
348 ctx
->traced_hostname
, MAXNAMLEN
) == 0)) {
349 printf_verbose("Reading from session %" PRIu64
"\n",
351 g_array_append_val(ctx
->session_ids
,
358 print_session_list(session_list
, path
);
359 free_session_list(session_list
);
366 fprintf(stderr
, "[error] Unable to list sessions\n");
370 int lttng_live_ctf_trace_assign(struct lttng_live_viewer_stream
*stream
,
371 uint64_t ctf_trace_id
)
373 struct lttng_live_ctf_trace
*trace
;
376 trace
= g_hash_table_lookup(stream
->session
->ctf_traces
,
379 trace
= g_new0(struct lttng_live_ctf_trace
, 1);
380 trace
->ctf_trace_id
= ctf_trace_id
;
381 trace
->streams
= g_ptr_array_new();
382 g_hash_table_insert(stream
->session
->ctf_traces
,
383 &trace
->ctf_trace_id
,
386 if (stream
->metadata_flag
)
387 trace
->metadata_stream
= stream
;
389 stream
->ctf_trace
= trace
;
390 g_ptr_array_add(trace
->streams
, stream
);
396 int open_metadata_fp_write(struct lttng_live_viewer_stream
*stream
,
397 char **metadata_buf
, size_t *size
)
401 stream
->metadata_fp_write
=
402 bt_open_memstream(metadata_buf
, size
);
403 if (!stream
->metadata_fp_write
) {
404 perror("Metadata open_memstream");
411 int lttng_live_attach_session(struct lttng_live_ctx
*ctx
, uint64_t id
)
413 struct lttng_viewer_cmd cmd
;
414 struct lttng_viewer_attach_session_request rq
;
415 struct lttng_viewer_attach_session_response rp
;
416 struct lttng_viewer_stream stream
;
420 if (lttng_live_should_quit()) {
425 cmd
.cmd
= htobe32(LTTNG_VIEWER_ATTACH_SESSION
);
426 cmd
.data_size
= htobe64((uint64_t) sizeof(rq
));
427 cmd
.cmd_version
= htobe32(0);
429 memset(&rq
, 0, sizeof(rq
));
430 rq
.session_id
= htobe64(id
);
431 // TODO: add cmd line parameter to select seek beginning
432 // rq.seek = htobe32(LTTNG_VIEWER_SEEK_BEGINNING);
433 rq
.seek
= htobe32(LTTNG_VIEWER_SEEK_LAST
);
435 ret_len
= lttng_live_send(ctx
->control_sock
, &cmd
, sizeof(cmd
));
437 perror("[error] Error sending cmd");
440 assert(ret_len
== sizeof(cmd
));
442 ret_len
= lttng_live_send(ctx
->control_sock
, &rq
, sizeof(rq
));
444 perror("[error] Error sending attach request");
447 assert(ret_len
== sizeof(rq
));
449 ret_len
= lttng_live_recv(ctx
->control_sock
, &rp
, sizeof(rp
));
451 fprintf(stderr
, "[error] Remote side has closed connection\n");
455 perror("[error] Error receiving attach response");
458 assert(ret_len
== sizeof(rp
));
460 switch(be32toh(rp
.status
)) {
461 case LTTNG_VIEWER_ATTACH_OK
:
463 case LTTNG_VIEWER_ATTACH_UNK
:
464 ret
= -LTTNG_VIEWER_ATTACH_UNK
;
466 case LTTNG_VIEWER_ATTACH_ALREADY
:
467 fprintf(stderr
, "[error] There is already a viewer attached to this session\n");
469 case LTTNG_VIEWER_ATTACH_NOT_LIVE
:
470 fprintf(stderr
, "[error] Not a live session\n");
472 case LTTNG_VIEWER_ATTACH_SEEK_ERR
:
473 fprintf(stderr
, "[error] Wrong seek parameter\n");
476 fprintf(stderr
, "[error] Unknown attach return code %u\n",
480 if (be32toh(rp
.status
) != LTTNG_VIEWER_ATTACH_OK
) {
484 ctx
->session
->stream_count
+= be32toh(rp
.streams_count
);
486 * When the session is created but not started, we do an active wait
487 * until it starts. It allows the viewer to start processing the trace
488 * as soon as the session starts.
490 if (ctx
->session
->stream_count
== 0) {
494 printf_verbose("Waiting for %" PRIu64
" streams:\n",
495 ctx
->session
->stream_count
);
496 ctx
->session
->streams
= g_new0(struct lttng_live_viewer_stream
,
497 ctx
->session
->stream_count
);
498 for (i
= 0; i
< be32toh(rp
.streams_count
); i
++) {
499 ret_len
= lttng_live_recv(ctx
->control_sock
, &stream
, sizeof(stream
));
501 fprintf(stderr
, "[error] Remote side has closed connection\n");
505 perror("[error] Error receiving stream");
508 assert(ret_len
== sizeof(stream
));
509 stream
.path_name
[LTTNG_VIEWER_PATH_MAX
- 1] = '\0';
510 stream
.channel_name
[LTTNG_VIEWER_NAME_MAX
- 1] = '\0';
512 printf_verbose(" stream %" PRIu64
" : %s/%s\n",
513 be64toh(stream
.id
), stream
.path_name
,
514 stream
.channel_name
);
515 ctx
->session
->streams
[i
].id
= be64toh(stream
.id
);
516 ctx
->session
->streams
[i
].session
= ctx
->session
;
518 ctx
->session
->streams
[i
].mmap_size
= 0;
519 ctx
->session
->streams
[i
].ctf_stream_id
= -1ULL;
521 if (be32toh(stream
.metadata_flag
)) {
522 ctx
->session
->streams
[i
].metadata_flag
= 1;
524 ret
= lttng_live_ctf_trace_assign(&ctx
->session
->streams
[i
],
525 be64toh(stream
.ctf_trace_id
));
540 * Ask the relay for new streams.
542 * Returns the number of new streams received or a negative value on error.
545 int ask_new_streams(struct lttng_live_ctx
*ctx
)
547 int i
, ret
= 0, nb_streams
= 0;
551 for (i
= 0; i
< ctx
->session_ids
->len
; i
++) {
552 id
= g_array_index(ctx
->session_ids
, uint64_t, i
);
553 ret
= lttng_live_get_new_streams(ctx
, id
);
554 printf_verbose("Asking for new streams returns %d\n", ret
);
556 if (lttng_live_should_quit()) {
559 if (ret
== -LTTNG_VIEWER_NEW_STREAMS_HUP
) {
560 printf_verbose("Session %" PRIu64
" closed\n",
563 * The streams have already been closed during
564 * the reading, so we only need to get rid of
565 * the trace in our internal table of sessions.
567 g_array_remove_index(ctx
->session_ids
, i
);
569 * We can't continue iterating on the g_array
570 * after a remove, we have to start again.
588 int append_metadata(struct lttng_live_ctx
*ctx
,
589 struct lttng_live_viewer_stream
*viewer_stream
)
592 struct lttng_live_viewer_stream
*metadata
;
593 char *metadata_buf
= NULL
;
595 printf_verbose("get_next_index: new metadata needed\n");
596 ret
= get_new_metadata(ctx
, viewer_stream
, &metadata_buf
);
602 metadata
= viewer_stream
->ctf_trace
->metadata_stream
;
603 metadata
->ctf_trace
->metadata_fp
=
604 bt_fmemopen(metadata_buf
,
605 metadata
->metadata_len
, "rb");
606 if (!metadata
->ctf_trace
->metadata_fp
) {
607 perror("Metadata fmemopen");
612 ret
= ctf_append_trace_metadata(
613 viewer_stream
->ctf_trace
->handle
->td
,
614 metadata
->ctf_trace
->metadata_fp
);
615 /* We accept empty metadata packets */
616 if (ret
!= 0 && ret
!= -ENOENT
) {
617 fprintf(stderr
, "[error] Appending metadata\n");
627 int get_data_packet(struct lttng_live_ctx
*ctx
,
628 struct ctf_stream_pos
*pos
,
629 struct lttng_live_viewer_stream
*stream
, uint64_t offset
,
632 struct lttng_viewer_cmd cmd
;
633 struct lttng_viewer_get_packet rq
;
634 struct lttng_viewer_trace_packet rp
;
639 if (lttng_live_should_quit()) {
644 cmd
.cmd
= htobe32(LTTNG_VIEWER_GET_PACKET
);
645 cmd
.data_size
= htobe64((uint64_t) sizeof(rq
));
646 cmd
.cmd_version
= htobe32(0);
648 memset(&rq
, 0, sizeof(rq
));
649 rq
.stream_id
= htobe64(stream
->id
);
650 rq
.offset
= htobe64(offset
);
651 rq
.len
= htobe32(len
);
653 ret_len
= lttng_live_send(ctx
->control_sock
, &cmd
, sizeof(cmd
));
655 perror("[error] Error sending cmd");
658 assert(ret_len
== sizeof(cmd
));
660 ret_len
= lttng_live_send(ctx
->control_sock
, &rq
, sizeof(rq
));
662 perror("[error] Error sending get_data_packet request");
665 assert(ret_len
== sizeof(rq
));
667 ret_len
= lttng_live_recv(ctx
->control_sock
, &rp
, sizeof(rp
));
669 fprintf(stderr
, "[error] Remote side has closed connection\n");
673 perror("[error] Error receiving data response");
676 if (ret_len
!= sizeof(rp
)) {
677 fprintf(stderr
, "[error] get_data_packet: expected %zu"
678 ", received %zd\n", sizeof(rp
),
683 rp
.flags
= be32toh(rp
.flags
);
685 switch (be32toh(rp
.status
)) {
686 case LTTNG_VIEWER_GET_PACKET_OK
:
687 len
= be32toh(rp
.len
);
688 printf_verbose("get_data_packet: Ok, packet size : %" PRIu64
691 case LTTNG_VIEWER_GET_PACKET_RETRY
:
692 /* Unimplemented by relay daemon */
693 printf_verbose("get_data_packet: retry\n");
695 case LTTNG_VIEWER_GET_PACKET_ERR
:
696 if (rp
.flags
& LTTNG_VIEWER_FLAG_NEW_METADATA
) {
697 printf_verbose("get_data_packet: new metadata needed\n");
698 ret
= append_metadata(ctx
, stream
);
702 if (rp
.flags
& LTTNG_VIEWER_FLAG_NEW_STREAM
) {
703 printf_verbose("get_data_packet: new streams needed\n");
704 ret
= ask_new_streams(ctx
);
707 } else if (ret
> 0) {
708 ret
= add_traces(ctx
);
714 if (rp
.flags
& (LTTNG_VIEWER_FLAG_NEW_METADATA
715 | LTTNG_VIEWER_FLAG_NEW_STREAM
)) {
718 fprintf(stderr
, "[error] get_data_packet: error\n");
720 case LTTNG_VIEWER_GET_PACKET_EOF
:
724 printf_verbose("get_data_packet: unknown\n");
732 if (len
> stream
->mmap_size
) {
735 new_size
= max_t(uint64_t, len
, stream
->mmap_size
<< 1);
738 ret
= munmap_align(pos
->base_mma
);
740 perror("[error] Unable to unmap old base");
743 pos
->base_mma
= NULL
;
745 pos
->base_mma
= mmap_align(new_size
,
746 PROT_READ
| PROT_WRITE
,
747 MAP_PRIVATE
| MAP_ANONYMOUS
, -1, 0);
748 if (pos
->base_mma
== MAP_FAILED
) {
749 perror("[error] mmap error");
750 pos
->base_mma
= NULL
;
754 stream
->mmap_size
= new_size
;
755 printf_verbose("Expanding stream mmap size to %" PRIu64
" bytes\n",
759 ret_len
= lttng_live_recv(ctx
->control_sock
,
760 mmap_align_addr(pos
->base_mma
), len
);
762 fprintf(stderr
, "[error] Remote side has closed connection\n");
766 perror("[error] Error receiving trace packet");
769 assert(ret_len
== len
);
779 int get_one_metadata_packet(struct lttng_live_ctx
*ctx
,
780 struct lttng_live_viewer_stream
*metadata_stream
)
784 struct lttng_viewer_cmd cmd
;
785 struct lttng_viewer_get_metadata rq
;
786 struct lttng_viewer_metadata_packet rp
;
790 if (lttng_live_should_quit()) {
795 rq
.stream_id
= htobe64(metadata_stream
->id
);
796 cmd
.cmd
= htobe32(LTTNG_VIEWER_GET_METADATA
);
797 cmd
.data_size
= htobe64((uint64_t) sizeof(rq
));
798 cmd
.cmd_version
= htobe32(0);
800 ret_len
= lttng_live_send(ctx
->control_sock
, &cmd
, sizeof(cmd
));
802 perror("[error] Error sending cmd");
805 assert(ret_len
== sizeof(cmd
));
807 ret_len
= lttng_live_send(ctx
->control_sock
, &rq
, sizeof(rq
));
809 perror("[error] Error sending get_metadata request");
812 assert(ret_len
== sizeof(rq
));
814 ret_len
= lttng_live_recv(ctx
->control_sock
, &rp
, sizeof(rp
));
816 fprintf(stderr
, "[error] Remote side has closed connection\n");
820 perror("[error] Error receiving metadata response");
823 assert(ret_len
== sizeof(rp
));
825 switch (be32toh(rp
.status
)) {
826 case LTTNG_VIEWER_METADATA_OK
:
827 printf_verbose("get_metadata : OK\n");
829 case LTTNG_VIEWER_NO_NEW_METADATA
:
830 printf_verbose("get_metadata : NO NEW\n");
833 case LTTNG_VIEWER_METADATA_ERR
:
834 printf_verbose("get_metadata : ERR\n");
837 printf_verbose("get_metadata : UNKNOWN\n");
841 len
= be64toh(rp
.len
);
842 printf_verbose("Writing %" PRIu64
" bytes to metadata\n", len
);
849 perror("relay data zmalloc");
852 ret_len
= lttng_live_recv(ctx
->control_sock
, data
, len
);
854 fprintf(stderr
, "[error] Remote side has closed connection\n");
855 goto error_free_data
;
858 perror("[error] Error receiving trace packet");
859 goto error_free_data
;
861 assert(ret_len
== len
);
864 ret_len
= fwrite(data
, 1, len
,
865 metadata_stream
->metadata_fp_write
);
866 } while (ret_len
< 0 && errno
== EINTR
);
868 fprintf(stderr
, "[error] Writing in the metadata fp\n");
869 goto error_free_data
;
871 assert(ret_len
== len
);
872 metadata_stream
->metadata_len
+= len
;
885 * Return 0 on success, a negative value on error.
888 int get_new_metadata(struct lttng_live_ctx
*ctx
,
889 struct lttng_live_viewer_stream
*viewer_stream
,
893 struct lttng_live_viewer_stream
*metadata_stream
;
894 size_t size
, len_read
= 0;
896 metadata_stream
= viewer_stream
->ctf_trace
->metadata_stream
;
897 if (!metadata_stream
) {
898 fprintf(stderr
, "[error] No metadata stream\n");
902 metadata_stream
->metadata_len
= 0;
903 ret
= open_metadata_fp_write(metadata_stream
, metadata_buf
, &size
);
909 if (lttng_live_should_quit()) {
914 * get_one_metadata_packet returns the number of bytes
915 * received, 0 when we have received everything, a
916 * negative value on error.
918 ret
= get_one_metadata_packet(ctx
, metadata_stream
);
923 (void) poll(NULL
, 0, ACTIVE_POLL_DELAY
);
925 } while (ret
> 0 || !len_read
);
927 if (bt_close_memstream(metadata_buf
, &size
,
928 metadata_stream
->metadata_fp_write
)) {
929 perror("bt_close_memstream");
931 metadata_stream
->metadata_fp_write
= NULL
;
938 * Assign the fields from a lttng_viewer_index to a packet_index.
941 void lttng_index_to_packet_index(struct lttng_viewer_index
*lindex
,
942 struct packet_index
*pindex
)
947 pindex
->offset
= be64toh(lindex
->offset
);
948 pindex
->packet_size
= be64toh(lindex
->packet_size
);
949 pindex
->content_size
= be64toh(lindex
->content_size
);
950 pindex
->ts_cycles
.timestamp_begin
= be64toh(lindex
->timestamp_begin
);
951 pindex
->ts_cycles
.timestamp_end
= be64toh(lindex
->timestamp_end
);
952 pindex
->events_discarded
= be64toh(lindex
->events_discarded
);
956 * Get one index for a stream.
958 * Returns 0 on success or a negative value on error.
961 int get_next_index(struct lttng_live_ctx
*ctx
,
962 struct lttng_live_viewer_stream
*viewer_stream
,
963 struct packet_index
*index
, uint64_t *stream_id
)
965 struct lttng_viewer_cmd cmd
;
966 struct lttng_viewer_get_next_index rq
;
969 struct lttng_viewer_index
*rp
= &viewer_stream
->current_index
;
971 cmd
.cmd
= htobe32(LTTNG_VIEWER_GET_NEXT_INDEX
);
972 cmd
.data_size
= htobe64((uint64_t) sizeof(rq
));
973 cmd
.cmd_version
= htobe32(0);
975 memset(&rq
, 0, sizeof(rq
));
976 rq
.stream_id
= htobe64(viewer_stream
->id
);
979 if (lttng_live_should_quit()) {
983 ret_len
= lttng_live_send(ctx
->control_sock
, &cmd
, sizeof(cmd
));
985 perror("[error] Error sending cmd");
988 assert(ret_len
== sizeof(cmd
));
990 ret_len
= lttng_live_send(ctx
->control_sock
, &rq
, sizeof(rq
));
992 perror("[error] Error sending get_next_index request");
995 assert(ret_len
== sizeof(rq
));
997 ret_len
= lttng_live_recv(ctx
->control_sock
, rp
, sizeof(*rp
));
999 fprintf(stderr
, "[error] Remote side has closed connection\n");
1003 perror("[error] Error receiving index response");
1006 assert(ret_len
== sizeof(*rp
));
1008 rp
->flags
= be32toh(rp
->flags
);
1010 switch (be32toh(rp
->status
)) {
1011 case LTTNG_VIEWER_INDEX_INACTIVE
:
1012 printf_verbose("get_next_index: inactive\n");
1013 memset(index
, 0, sizeof(struct packet_index
));
1014 index
->ts_cycles
.timestamp_end
= be64toh(rp
->timestamp_end
);
1015 *stream_id
= be64toh(rp
->stream_id
);
1017 case LTTNG_VIEWER_INDEX_OK
:
1018 printf_verbose("get_next_index: Ok, need metadata update : %u\n",
1019 rp
->flags
& LTTNG_VIEWER_FLAG_NEW_METADATA
);
1020 lttng_index_to_packet_index(rp
, index
);
1021 *stream_id
= be64toh(rp
->stream_id
);
1022 viewer_stream
->data_pending
= 1;
1024 if (rp
->flags
& LTTNG_VIEWER_FLAG_NEW_METADATA
) {
1025 ret
= append_metadata(ctx
, viewer_stream
);
1029 if (rp
->flags
& LTTNG_VIEWER_FLAG_NEW_STREAM
) {
1030 printf_verbose("get_next_index: need new streams\n");
1031 ret
= ask_new_streams(ctx
);
1034 } else if (ret
> 0) {
1035 ret
= add_traces(ctx
);
1042 case LTTNG_VIEWER_INDEX_RETRY
:
1043 printf_verbose("get_next_index: retry\n");
1044 (void) poll(NULL
, 0, ACTIVE_POLL_DELAY
);
1046 case LTTNG_VIEWER_INDEX_HUP
:
1047 printf_verbose("get_next_index: stream hung up\n");
1048 viewer_stream
->id
= -1ULL;
1049 index
->offset
= EOF
;
1050 ctx
->session
->stream_count
--;
1052 case LTTNG_VIEWER_INDEX_ERR
:
1053 fprintf(stderr
, "[error] get_next_index: error\n");
1056 fprintf(stderr
, "[error] get_next_index: unkwown value\n");
1068 void read_packet_header(struct ctf_stream_pos
*pos
,
1069 struct ctf_file_stream
*file_stream
)
1073 /* update trace_packet_header and stream_packet_context */
1074 if (!(pos
->prot
& PROT_WRITE
) &&
1075 file_stream
->parent
.trace_packet_header
) {
1076 /* Read packet header */
1077 ret
= generic_rw(&pos
->parent
,
1078 &file_stream
->parent
.trace_packet_header
->p
);
1081 fprintf(stderr
, "[error] trace packet "
1082 "header read failed\n");
1086 if (!(pos
->prot
& PROT_WRITE
) &&
1087 file_stream
->parent
.stream_packet_context
) {
1088 /* Read packet context */
1089 ret
= generic_rw(&pos
->parent
,
1090 &file_stream
->parent
.stream_packet_context
->p
);
1093 fprintf(stderr
, "[error] stream packet "
1094 "context read failed\n");
1098 pos
->data_offset
= pos
->offset
;
1105 * Handle the seek parameters.
1106 * Returns 0 if the packet_seek can continue, a positive value to
1107 * cleanly exit the packet_seek, a negative value on error.
1110 int handle_seek_position(size_t index
, int whence
,
1111 struct lttng_live_viewer_stream
*viewer_stream
,
1112 struct ctf_stream_pos
*pos
,
1113 struct ctf_file_stream
*file_stream
)
1123 * We only allow to seek to 0.
1126 fprintf(stderr
, "[error] Arbitrary seek in lttng-live "
1127 "trace not supported\n");
1137 fprintf(stderr
, "[error] Invalid seek parameter\n");
1146 void ctf_live_packet_seek(struct bt_stream_pos
*stream_pos
, size_t index
,
1149 struct ctf_stream_pos
*pos
;
1150 struct ctf_file_stream
*file_stream
;
1151 struct packet_index
*prev_index
= NULL
, *cur_index
;
1152 struct lttng_live_viewer_stream
*viewer_stream
;
1153 struct lttng_live_session
*session
;
1154 uint64_t stream_id
= -1ULL;
1157 pos
= ctf_pos(stream_pos
);
1158 file_stream
= container_of(pos
, struct ctf_file_stream
, pos
);
1159 viewer_stream
= (struct lttng_live_viewer_stream
*) pos
->priv
;
1160 session
= viewer_stream
->session
;
1162 ret
= handle_seek_position(index
, whence
, viewer_stream
, pos
,
1169 switch (pos
->packet_index
->len
) {
1171 g_array_set_size(pos
->packet_index
, 1);
1172 cur_index
= &g_array_index(pos
->packet_index
,
1173 struct packet_index
, 0);
1176 g_array_set_size(pos
->packet_index
, 2);
1177 prev_index
= &g_array_index(pos
->packet_index
,
1178 struct packet_index
, 0);
1179 cur_index
= &g_array_index(pos
->packet_index
,
1180 struct packet_index
, 1);
1183 g_array_index(pos
->packet_index
,
1184 struct packet_index
, 0) =
1185 g_array_index(pos
->packet_index
,
1186 struct packet_index
, 1);
1187 prev_index
= &g_array_index(pos
->packet_index
,
1188 struct packet_index
, 0);
1189 cur_index
= &g_array_index(pos
->packet_index
,
1190 struct packet_index
, 1);
1197 if (viewer_stream
->data_pending
) {
1198 lttng_index_to_packet_index(&viewer_stream
->current_index
, cur_index
);
1200 printf_verbose("get_next_index for stream %" PRIu64
"\n", viewer_stream
->id
);
1201 ret
= get_next_index(session
->ctx
, viewer_stream
, cur_index
, &stream_id
);
1204 if (!lttng_live_should_quit()) {
1205 fprintf(stderr
, "[error] get_next_index failed\n");
1209 printf_verbose("Index received : packet_size : %" PRIu64
1210 ", offset %" PRIu64
", content_size %" PRIu64
1211 ", timestamp_end : %" PRIu64
"\n",
1212 cur_index
->packet_size
, cur_index
->offset
,
1213 cur_index
->content_size
,
1214 cur_index
->ts_cycles
.timestamp_end
);
1219 * On the first time we receive an index, the stream_id needs to
1220 * be set for the stream in order to use it, we don't want any
1221 * data at this stage.
1223 if (file_stream
->parent
.stream_id
== -1ULL) {
1225 * Warning: with lttng-tools < 2.4.2, the beacon does not
1226 * contain the real stream ID, it is memset to 0, so this
1227 * might create a problem when a session has multiple
1228 * channels. We can't detect it at this stage, lttng-tools
1229 * has to be upgraded to fix this problem.
1231 printf_verbose("Assigning stream_id %" PRIu64
"\n",
1233 file_stream
->parent
.stream_id
= stream_id
;
1234 viewer_stream
->ctf_stream_id
= stream_id
;
1239 pos
->packet_size
= cur_index
->packet_size
;
1240 pos
->content_size
= cur_index
->content_size
;
1241 pos
->mmap_base_offset
= 0;
1242 if (cur_index
->offset
== EOF
) {
1248 if (cur_index
->content_size
== 0) {
1249 if (file_stream
->parent
.stream_class
) {
1250 file_stream
->parent
.cycles_timestamp
=
1251 cur_index
->ts_cycles
.timestamp_end
;
1252 file_stream
->parent
.real_timestamp
= ctf_get_real_timestamp(
1253 &file_stream
->parent
,
1254 cur_index
->ts_cycles
.timestamp_end
);
1257 if (file_stream
->parent
.stream_class
) {
1258 /* Convert the timestamps and append to the real_index. */
1259 cur_index
->ts_real
.timestamp_begin
= ctf_get_real_timestamp(
1260 &file_stream
->parent
,
1261 cur_index
->ts_cycles
.timestamp_begin
);
1262 cur_index
->ts_real
.timestamp_end
= ctf_get_real_timestamp(
1263 &file_stream
->parent
,
1264 cur_index
->ts_cycles
.timestamp_end
);
1267 ctf_update_current_packet_index(&file_stream
->parent
,
1268 prev_index
, cur_index
);
1270 file_stream
->parent
.cycles_timestamp
=
1271 cur_index
->ts_cycles
.timestamp_begin
;
1272 file_stream
->parent
.real_timestamp
=
1273 cur_index
->ts_real
.timestamp_begin
;
1277 * Flush the output between attempts to grab a packet, thus
1278 * ensuring we flush at least at the periodical timer period.
1279 * This ensures the output remains reactive for interactive users and
1280 * that the output is flushed when redirected to a file by the shell.
1282 if (fflush(LTTNG_LIVE_OUTPUT_FP
) < 0) {
1287 if (pos
->packet_size
== 0 || pos
->offset
== EOF
) {
1291 printf_verbose("get_data_packet for stream %" PRIu64
"\n",
1293 ret
= get_data_packet(session
->ctx
, pos
, viewer_stream
,
1295 cur_index
->packet_size
/ CHAR_BIT
);
1298 } else if (ret
< 0) {
1300 if (!lttng_live_should_quit()) {
1301 fprintf(stderr
, "[error] get_data_packet failed\n");
1305 viewer_stream
->data_pending
= 0;
1307 read_packet_header(pos
, file_stream
);
1313 int lttng_live_create_viewer_session(struct lttng_live_ctx
*ctx
)
1315 struct lttng_viewer_cmd cmd
;
1316 struct lttng_viewer_create_session_response resp
;
1320 if (lttng_live_should_quit()) {
1325 cmd
.cmd
= htobe32(LTTNG_VIEWER_CREATE_SESSION
);
1326 cmd
.data_size
= htobe64((uint64_t) 0);
1327 cmd
.cmd_version
= htobe32(0);
1329 ret_len
= lttng_live_send(ctx
->control_sock
, &cmd
, sizeof(cmd
));
1331 perror("[error] Error sending cmd");
1334 assert(ret_len
== sizeof(cmd
));
1336 ret_len
= lttng_live_recv(ctx
->control_sock
, &resp
, sizeof(resp
));
1338 fprintf(stderr
, "[error] Remote side has closed connection\n");
1342 perror("[error] Error receiving create session reply");
1345 assert(ret_len
== sizeof(resp
));
1347 if (be32toh(resp
.status
) != LTTNG_VIEWER_CREATE_SESSION_OK
) {
1348 fprintf(stderr
, "[error] Error creating viewer session\n");
1360 int del_traces(gpointer key
, gpointer value
, gpointer user_data
)
1362 struct bt_context
*bt_ctx
= user_data
;
1363 struct lttng_live_ctf_trace
*trace
= value
;
1366 ret
= bt_context_remove_trace(bt_ctx
, trace
->trace_id
);
1368 fprintf(stderr
, "[error] removing trace from context\n");
1370 /* remove the key/value pair from the HT. */
1375 int add_one_trace(struct lttng_live_ctx
*ctx
,
1376 struct lttng_live_ctf_trace
*trace
)
1379 struct bt_context
*bt_ctx
= ctx
->bt_ctx
;
1380 struct lttng_live_viewer_stream
*stream
;
1381 struct bt_mmap_stream
*new_mmap_stream
;
1382 struct bt_mmap_stream_list mmap_list
;
1383 struct bt_trace_descriptor
*td
;
1384 struct bt_trace_handle
*handle
;
1387 * We don't know how many streams we will receive for a trace, so
1388 * once we are done receiving the traces, we add all the traces
1389 * received to the bt_context.
1390 * We can receive streams during the attach command or the
1391 * get_new_streams, so we have to make sure not to add multiple
1392 * times the same traces.
1393 * If a trace is already in the context, we just skip this function.
1395 if (trace
->in_use
) {
1400 BT_INIT_LIST_HEAD(&mmap_list
.head
);
1402 for (i
= 0; i
< trace
->streams
->len
; i
++) {
1403 stream
= g_ptr_array_index(trace
->streams
, i
);
1405 if (!stream
->metadata_flag
) {
1406 new_mmap_stream
= zmalloc(sizeof(struct bt_mmap_stream
));
1407 new_mmap_stream
->priv
= (void *) stream
;
1408 new_mmap_stream
->fd
= -1;
1409 bt_list_add(&new_mmap_stream
->list
, &mmap_list
.head
);
1411 char *metadata_buf
= NULL
;
1413 /* Get all possible metadata before starting */
1414 ret
= get_new_metadata(ctx
, stream
, &metadata_buf
);
1419 if (!stream
->metadata_len
) {
1420 fprintf(stderr
, "[error] empty metadata\n");
1426 trace
->metadata_fp
= bt_fmemopen(metadata_buf
,
1427 stream
->metadata_len
, "rb");
1428 if (!trace
->metadata_fp
) {
1429 perror("Metadata fmemopen");
1437 if (!trace
->metadata_fp
) {
1438 fprintf(stderr
, "[error] No metadata stream opened\n");
1443 ret
= bt_context_add_trace(bt_ctx
, NULL
, "ctf",
1444 ctf_live_packet_seek
, &mmap_list
, trace
->metadata_fp
);
1446 fprintf(stderr
, "[error] Error adding trace\n");
1450 trace
->metadata_stream
->metadata_len
= 0;
1452 handle
= (struct bt_trace_handle
*) g_hash_table_lookup(
1453 bt_ctx
->trace_handles
,
1454 (gpointer
) (unsigned long) ret
);
1456 trace
->handle
= handle
;
1457 if (bt_ctx
->current_iterator
) {
1458 bt_iter_add_trace(bt_ctx
->current_iterator
, td
);
1461 trace
->trace_id
= ret
;
1467 bt_context_put(bt_ctx
);
1473 int add_traces(struct lttng_live_ctx
*ctx
)
1476 struct lttng_live_ctf_trace
*trace
;
1481 g_hash_table_iter_init(&it
, ctx
->session
->ctf_traces
);
1482 while (g_hash_table_iter_next(&it
, &key
, &value
)) {
1483 trace
= (struct lttng_live_ctf_trace
*) value
;
1484 ret
= add_one_trace(ctx
, trace
);
1497 * Request new streams for a session.
1498 * Returns the number of streams received or a negative value on error.
1500 int lttng_live_get_new_streams(struct lttng_live_ctx
*ctx
, uint64_t id
)
1502 struct lttng_viewer_cmd cmd
;
1503 struct lttng_viewer_new_streams_request rq
;
1504 struct lttng_viewer_new_streams_response rp
;
1505 struct lttng_viewer_stream stream
;
1506 int ret
, i
, nb_streams
= 0;
1508 uint32_t stream_count
;
1510 if (lttng_live_should_quit()) {
1515 cmd
.cmd
= htobe32(LTTNG_VIEWER_GET_NEW_STREAMS
);
1516 cmd
.data_size
= htobe64((uint64_t) sizeof(rq
));
1517 cmd
.cmd_version
= htobe32(0);
1519 memset(&rq
, 0, sizeof(rq
));
1520 rq
.session_id
= htobe64(id
);
1522 ret_len
= lttng_live_send(ctx
->control_sock
, &cmd
, sizeof(cmd
));
1524 perror("[error] Error sending cmd");
1527 assert(ret_len
== sizeof(cmd
));
1529 ret_len
= lttng_live_send(ctx
->control_sock
, &rq
, sizeof(rq
));
1531 perror("[error] Error sending get_new_streams request");
1534 assert(ret_len
== sizeof(rq
));
1536 ret_len
= lttng_live_recv(ctx
->control_sock
, &rp
, sizeof(rp
));
1538 fprintf(stderr
, "[error] Remote side has closed connection\n");
1542 perror("[error] Error receiving get_new_streams response");
1545 assert(ret_len
== sizeof(rp
));
1547 switch(be32toh(rp
.status
)) {
1548 case LTTNG_VIEWER_NEW_STREAMS_OK
:
1550 case LTTNG_VIEWER_NEW_STREAMS_NO_NEW
:
1553 case LTTNG_VIEWER_NEW_STREAMS_HUP
:
1554 ret
= -LTTNG_VIEWER_NEW_STREAMS_HUP
;
1556 case LTTNG_VIEWER_NEW_STREAMS_ERR
:
1557 fprintf(stderr
, "[error] get_new_streams error\n");
1560 fprintf(stderr
, "[error] Unknown return code %u\n",
1561 be32toh(rp
.status
));
1565 stream_count
= be32toh(rp
.streams_count
);
1566 ctx
->session
->stream_count
+= stream_count
;
1568 * When the session is created but not started, we do an active wait
1569 * until it starts. It allows the viewer to start processing the trace
1570 * as soon as the session starts.
1572 if (ctx
->session
->stream_count
== 0) {
1576 printf_verbose("Waiting for %" PRIu64
" streams:\n",
1577 ctx
->session
->stream_count
);
1578 ctx
->session
->streams
= g_new0(struct lttng_live_viewer_stream
,
1579 ctx
->session
->stream_count
);
1580 for (i
= 0; i
< stream_count
; i
++) {
1581 ret_len
= lttng_live_recv(ctx
->control_sock
, &stream
, sizeof(stream
));
1583 fprintf(stderr
, "[error] Remote side has closed connection\n");
1587 perror("[error] Error receiving stream");
1590 assert(ret_len
== sizeof(stream
));
1591 stream
.path_name
[LTTNG_VIEWER_PATH_MAX
- 1] = '\0';
1592 stream
.channel_name
[LTTNG_VIEWER_NAME_MAX
- 1] = '\0';
1594 printf_verbose(" stream %" PRIu64
" : %s/%s\n",
1595 be64toh(stream
.id
), stream
.path_name
,
1596 stream
.channel_name
);
1597 ctx
->session
->streams
[i
].id
= be64toh(stream
.id
);
1598 ctx
->session
->streams
[i
].session
= ctx
->session
;
1600 ctx
->session
->streams
[i
].mmap_size
= 0;
1601 ctx
->session
->streams
[i
].ctf_stream_id
= -1ULL;
1603 if (be32toh(stream
.metadata_flag
)) {
1604 ctx
->session
->streams
[i
].metadata_flag
= 1;
1606 ret
= lttng_live_ctf_trace_assign(&ctx
->session
->streams
[i
],
1607 be64toh(stream
.ctf_trace_id
));
1622 int lttng_live_read(struct lttng_live_ctx
*ctx
)
1626 struct bt_ctf_iter
*iter
;
1627 const struct bt_ctf_event
*event
;
1628 struct bt_iter_pos begin_pos
;
1629 struct bt_trace_descriptor
*td_write
;
1630 struct bt_format
*fmt_write
;
1631 struct ctf_text_stream_pos
*sout
;
1634 ctx
->bt_ctx
= bt_context_create();
1636 fprintf(stderr
, "[error] bt_context_create allocation\n");
1640 fmt_write
= bt_lookup_format(g_quark_from_string("text"));
1642 fprintf(stderr
, "[error] ctf-text error\n");
1646 td_write
= fmt_write
->open_trace(NULL
, O_RDWR
, NULL
, NULL
);
1648 fprintf(stderr
, "[error] Error opening output trace\n");
1652 sout
= container_of(td_write
, struct ctf_text_stream_pos
,
1654 if (!sout
->parent
.event_cb
) {
1658 ret
= lttng_live_create_viewer_session(ctx
);
1663 for (i
= 0; i
< ctx
->session_ids
->len
; i
++) {
1664 id
= g_array_index(ctx
->session_ids
, uint64_t, i
);
1665 printf_verbose("Attaching to session %" PRIu64
"\n", id
);
1666 ret
= lttng_live_attach_session(ctx
, id
);
1667 printf_verbose("Attaching session returns %d\n", ret
);
1669 if (ret
== -LTTNG_VIEWER_ATTACH_UNK
) {
1670 fprintf(stderr
, "[error] Unknown session ID\n");
1677 * As long as the session is active, we try to get new streams.
1682 if (lttng_live_should_quit()) {
1687 while (!ctx
->session
->stream_count
) {
1688 if (lttng_live_should_quit()
1689 || ctx
->session_ids
->len
== 0) {
1693 ret
= ask_new_streams(ctx
);
1697 if (!ctx
->session
->stream_count
) {
1698 (void) poll(NULL
, 0, ACTIVE_POLL_DELAY
);
1702 ret
= add_traces(ctx
);
1707 begin_pos
.type
= BT_SEEK_BEGIN
;
1708 iter
= bt_ctf_iter_create(ctx
->bt_ctx
, &begin_pos
, NULL
);
1710 if (lttng_live_should_quit()) {
1714 fprintf(stderr
, "[error] Iterator creation error\n");
1718 if (lttng_live_should_quit()) {
1722 event
= bt_ctf_iter_read_event_flags(iter
, &flags
);
1723 if (!(flags
& BT_ITER_FLAG_RETRY
)) {
1728 ret
= sout
->parent
.event_cb(&sout
->parent
,
1729 event
->parent
->stream
);
1731 fprintf(stderr
, "[error] Writing "
1736 ret
= bt_iter_next(bt_ctf_get_iter(iter
));
1741 bt_ctf_iter_destroy(iter
);
1742 g_hash_table_foreach_remove(ctx
->session
->ctf_traces
,
1743 del_traces
, ctx
->bt_ctx
);
1744 ctx
->session
->stream_count
= 0;
1748 bt_context_put(ctx
->bt_ctx
);
1750 if (lttng_live_should_quit()) {