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>
37 #include <babeltrace/ctf/ctf-index.h>
39 #include <babeltrace/babeltrace.h>
40 #include <babeltrace/endian.h>
41 #include <babeltrace/ctf/events.h>
42 #include <babeltrace/ctf/callbacks.h>
43 #include <babeltrace/ctf/iterator.h>
45 /* for packet_index */
46 #include <babeltrace/ctf/types.h>
48 #include <babeltrace/ctf/metadata.h>
49 #include <babeltrace/ctf-text/types.h>
50 #include <babeltrace/ctf/events-internal.h>
51 #include <formats/ctf/events-private.h>
53 #include <babeltrace/compat/memstream.h>
54 #include <babeltrace/compat/send.h>
55 #include <babeltrace/compat/string.h>
57 #include "lttng-live.h"
58 #include "lttng-viewer-abi.h"
60 #define ACTIVE_POLL_DELAY 100 /* ms */
63 * Memory allocation zeroed
65 #define zmalloc(x) calloc(1, x)
68 #define max_t(type, a, b) \
69 ((type) (a) > (type) (b) ? (type) (a) : (type) (b))
72 static void ctf_live_packet_seek(struct bt_stream_pos
*stream_pos
,
73 size_t index
, int whence
);
74 static int add_traces(struct lttng_live_ctx
*ctx
);
75 static int del_traces(gpointer key
, gpointer value
, gpointer user_data
);
76 static int get_new_metadata(struct lttng_live_ctx
*ctx
,
77 struct lttng_live_viewer_stream
*viewer_stream
,
81 ssize_t
lttng_live_recv(int fd
, void *buf
, size_t len
)
84 size_t copied
= 0, to_copy
= len
;
87 ret
= recv(fd
, buf
+ copied
, to_copy
, 0);
89 assert(ret
<= to_copy
);
93 } while ((ret
> 0 && to_copy
> 0)
94 || (ret
< 0 && errno
== EINTR
));
97 /* ret = 0 means orderly shutdown, ret < 0 is error. */
102 ssize_t
lttng_live_send(int fd
, const void *buf
, size_t len
)
107 ret
= bt_send_nosigpipe(fd
, buf
, len
);
108 } while (ret
< 0 && errno
== EINTR
);
112 int lttng_live_connect_viewer(struct lttng_live_ctx
*ctx
)
114 struct hostent
*host
;
115 struct sockaddr_in server_addr
;
118 if (lttng_live_should_quit()) {
123 host
= gethostbyname(ctx
->relay_hostname
);
125 fprintf(stderr
, "[error] Cannot lookup hostname %s\n",
126 ctx
->relay_hostname
);
130 if ((ctx
->control_sock
= socket(AF_INET
, SOCK_STREAM
, 0)) == -1) {
135 server_addr
.sin_family
= AF_INET
;
136 server_addr
.sin_port
= htons(ctx
->port
);
137 server_addr
.sin_addr
= *((struct in_addr
*) host
->h_addr
);
138 memset(&(server_addr
.sin_zero
), 0, 8);
140 if (connect(ctx
->control_sock
, (struct sockaddr
*) &server_addr
,
141 sizeof(struct sockaddr
)) == -1) {
152 fprintf(stderr
, "[error] Connection failed\n");
156 int lttng_live_establish_connection(struct lttng_live_ctx
*ctx
)
158 struct lttng_viewer_cmd cmd
;
159 struct lttng_viewer_connect connect
;
163 if (lttng_live_should_quit()) {
168 cmd
.cmd
= htobe32(LTTNG_VIEWER_CONNECT
);
169 cmd
.data_size
= htobe64(sizeof(connect
));
170 cmd
.cmd_version
= htobe32(0);
172 connect
.viewer_session_id
= -1ULL; /* will be set on recv */
173 connect
.major
= htobe32(LTTNG_LIVE_MAJOR
);
174 connect
.minor
= htobe32(LTTNG_LIVE_MINOR
);
175 connect
.type
= htobe32(LTTNG_VIEWER_CLIENT_COMMAND
);
177 ret_len
= lttng_live_send(ctx
->control_sock
, &cmd
, sizeof(cmd
));
179 perror("[error] Error sending cmd");
182 assert(ret_len
== sizeof(cmd
));
184 ret_len
= lttng_live_send(ctx
->control_sock
, &connect
, sizeof(connect
));
186 perror("[error] Error sending version");
189 assert(ret_len
== sizeof(connect
));
191 ret_len
= lttng_live_recv(ctx
->control_sock
, &connect
, sizeof(connect
));
193 fprintf(stderr
, "[error] Remote side has closed connection\n");
197 perror("[error] Error receiving version");
200 assert(ret_len
== sizeof(connect
));
202 printf_verbose("Received viewer session ID : %" PRIu64
"\n",
203 be64toh(connect
.viewer_session_id
));
204 printf_verbose("Relayd version : %u.%u\n", be32toh(connect
.major
),
205 be32toh(connect
.minor
));
207 if (LTTNG_LIVE_MAJOR
!= be32toh(connect
.major
)) {
208 fprintf(stderr
, "[error] Incompatible lttng-relayd protocol\n");
211 /* Use the smallest protocol version implemented. */
212 if (LTTNG_LIVE_MINOR
> be32toh(connect
.minor
)) {
213 ctx
->minor
= be32toh(connect
.minor
);
215 ctx
->minor
= LTTNG_LIVE_MINOR
;
217 ctx
->major
= LTTNG_LIVE_MAJOR
;
223 fprintf(stderr
, "[error] Unable to establish connection\n");
228 void free_session_list(GPtrArray
*session_list
)
231 struct lttng_live_relay_session
*relay_session
;
233 for (i
= 0; i
< session_list
->len
; i
++) {
234 relay_session
= g_ptr_array_index(session_list
, i
);
235 free(relay_session
->name
);
236 free(relay_session
->hostname
);
238 g_ptr_array_free(session_list
, TRUE
);
242 void print_session_list(GPtrArray
*session_list
, const char *path
)
245 struct lttng_live_relay_session
*relay_session
;
247 for (i
= 0; i
< session_list
->len
; i
++) {
248 relay_session
= g_ptr_array_index(session_list
, i
);
249 fprintf(LTTNG_LIVE_OUTPUT_FP
, "%s/host/%s/%s (timer = %u, "
250 "%u stream(s), %u client(s) connected)\n",
251 path
, relay_session
->hostname
,
252 relay_session
->name
, relay_session
->timer
,
253 relay_session
->streams
, relay_session
->clients
);
258 void update_session_list(GPtrArray
*session_list
, char *hostname
,
259 char *session_name
, uint32_t streams
, uint32_t clients
,
263 struct lttng_live_relay_session
*relay_session
;
265 for (i
= 0; i
< session_list
->len
; i
++) {
266 relay_session
= g_ptr_array_index(session_list
, i
);
267 if ((strncmp(relay_session
->hostname
, hostname
, MAXNAMLEN
) == 0) &&
268 strncmp(relay_session
->name
,
269 session_name
, MAXNAMLEN
) == 0) {
270 relay_session
->streams
+= streams
;
271 if (relay_session
->clients
< clients
)
272 relay_session
->clients
= clients
;
280 relay_session
= g_new0(struct lttng_live_relay_session
, 1);
281 relay_session
->hostname
= bt_strndup(hostname
, MAXNAMLEN
);
282 relay_session
->name
= bt_strndup(session_name
, MAXNAMLEN
);
283 relay_session
->clients
= clients
;
284 relay_session
->streams
= streams
;
285 relay_session
->timer
= timer
;
286 g_ptr_array_add(session_list
, relay_session
);
289 int lttng_live_list_sessions(struct lttng_live_ctx
*ctx
, const char *path
)
291 struct lttng_viewer_cmd cmd
;
292 struct lttng_viewer_list_sessions list
;
293 struct lttng_viewer_session lsession
;
294 int i
, ret
, sessions_count
, print_list
= 0;
297 GPtrArray
*session_list
= NULL
;
299 if (lttng_live_should_quit()) {
304 if (strlen(ctx
->session_name
) == 0) {
306 session_list
= g_ptr_array_new();
309 cmd
.cmd
= htobe32(LTTNG_VIEWER_LIST_SESSIONS
);
310 cmd
.data_size
= htobe64(0);
311 cmd
.cmd_version
= htobe32(0);
313 ret_len
= lttng_live_send(ctx
->control_sock
, &cmd
, sizeof(cmd
));
315 perror("[error] Error sending cmd");
318 assert(ret_len
== sizeof(cmd
));
320 ret_len
= lttng_live_recv(ctx
->control_sock
, &list
, sizeof(list
));
322 fprintf(stderr
, "[error] Remote side has closed connection\n");
326 perror("[error] Error receiving session list");
329 assert(ret_len
== sizeof(list
));
331 sessions_count
= be32toh(list
.sessions_count
);
332 for (i
= 0; i
< sessions_count
; i
++) {
333 ret_len
= lttng_live_recv(ctx
->control_sock
, &lsession
, sizeof(lsession
));
335 fprintf(stderr
, "[error] Remote side has closed connection\n");
339 perror("[error] Error receiving session");
342 assert(ret_len
== sizeof(lsession
));
343 lsession
.hostname
[LTTNG_VIEWER_HOST_NAME_MAX
- 1] = '\0';
344 lsession
.session_name
[LTTNG_VIEWER_NAME_MAX
- 1] = '\0';
345 session_id
= be64toh(lsession
.id
);
348 update_session_list(session_list
,
350 lsession
.session_name
,
351 be32toh(lsession
.streams
),
352 be32toh(lsession
.clients
),
353 be32toh(lsession
.live_timer
));
355 if ((strncmp(lsession
.session_name
, ctx
->session_name
,
356 MAXNAMLEN
) == 0) && (strncmp(lsession
.hostname
,
357 ctx
->traced_hostname
, MAXNAMLEN
) == 0)) {
358 printf_verbose("Reading from session %" PRIu64
"\n",
360 g_array_append_val(ctx
->session_ids
,
367 print_session_list(session_list
, path
);
368 free_session_list(session_list
);
375 fprintf(stderr
, "[error] Unable to list sessions\n");
379 int lttng_live_ctf_trace_assign(struct lttng_live_viewer_stream
*stream
,
380 uint64_t ctf_trace_id
)
382 struct lttng_live_ctf_trace
*trace
;
385 trace
= g_hash_table_lookup(stream
->session
->ctf_traces
,
388 trace
= g_new0(struct lttng_live_ctf_trace
, 1);
389 trace
->ctf_trace_id
= ctf_trace_id
;
390 trace
->streams
= g_ptr_array_new();
391 g_hash_table_insert(stream
->session
->ctf_traces
,
392 &trace
->ctf_trace_id
,
395 if (stream
->metadata_flag
)
396 trace
->metadata_stream
= stream
;
398 stream
->ctf_trace
= trace
;
399 g_ptr_array_add(trace
->streams
, stream
);
405 int open_metadata_fp_write(struct lttng_live_viewer_stream
*stream
,
406 char **metadata_buf
, size_t *size
)
410 stream
->metadata_fp_write
=
411 babeltrace_open_memstream(metadata_buf
, size
);
412 if (!stream
->metadata_fp_write
) {
413 perror("Metadata open_memstream");
420 int lttng_live_attach_session(struct lttng_live_ctx
*ctx
, uint64_t id
)
422 struct lttng_viewer_cmd cmd
;
423 struct lttng_viewer_attach_session_request rq
;
424 struct lttng_viewer_attach_session_response rp
;
425 struct lttng_viewer_stream stream
;
429 if (lttng_live_should_quit()) {
434 cmd
.cmd
= htobe32(LTTNG_VIEWER_ATTACH_SESSION
);
435 cmd
.data_size
= htobe64(sizeof(rq
));
436 cmd
.cmd_version
= htobe32(0);
438 memset(&rq
, 0, sizeof(rq
));
439 rq
.session_id
= htobe64(id
);
440 // TODO: add cmd line parameter to select seek beginning
441 // rq.seek = htobe32(LTTNG_VIEWER_SEEK_BEGINNING);
442 rq
.seek
= htobe32(LTTNG_VIEWER_SEEK_LAST
);
444 ret_len
= lttng_live_send(ctx
->control_sock
, &cmd
, sizeof(cmd
));
446 perror("[error] Error sending cmd");
449 assert(ret_len
== sizeof(cmd
));
451 ret_len
= lttng_live_send(ctx
->control_sock
, &rq
, sizeof(rq
));
453 perror("[error] Error sending attach request");
456 assert(ret_len
== sizeof(rq
));
458 ret_len
= lttng_live_recv(ctx
->control_sock
, &rp
, sizeof(rp
));
460 fprintf(stderr
, "[error] Remote side has closed connection\n");
464 perror("[error] Error receiving attach response");
467 assert(ret_len
== sizeof(rp
));
469 switch(be32toh(rp
.status
)) {
470 case LTTNG_VIEWER_ATTACH_OK
:
472 case LTTNG_VIEWER_ATTACH_UNK
:
473 ret
= -LTTNG_VIEWER_ATTACH_UNK
;
475 case LTTNG_VIEWER_ATTACH_ALREADY
:
476 fprintf(stderr
, "[error] There is already a viewer attached to this session\n");
478 case LTTNG_VIEWER_ATTACH_NOT_LIVE
:
479 fprintf(stderr
, "[error] Not a live session\n");
481 case LTTNG_VIEWER_ATTACH_SEEK_ERR
:
482 fprintf(stderr
, "[error] Wrong seek parameter\n");
485 fprintf(stderr
, "[error] Unknown attach return code %u\n",
489 if (be32toh(rp
.status
) != LTTNG_VIEWER_ATTACH_OK
) {
493 ctx
->session
->stream_count
+= be32toh(rp
.streams_count
);
495 * When the session is created but not started, we do an active wait
496 * until it starts. It allows the viewer to start processing the trace
497 * as soon as the session starts.
499 if (ctx
->session
->stream_count
== 0) {
503 printf_verbose("Waiting for %" PRIu64
" streams:\n",
504 ctx
->session
->stream_count
);
505 ctx
->session
->streams
= g_new0(struct lttng_live_viewer_stream
,
506 ctx
->session
->stream_count
);
507 for (i
= 0; i
< be32toh(rp
.streams_count
); i
++) {
508 ret_len
= lttng_live_recv(ctx
->control_sock
, &stream
, sizeof(stream
));
510 fprintf(stderr
, "[error] Remote side has closed connection\n");
514 perror("[error] Error receiving stream");
517 assert(ret_len
== sizeof(stream
));
518 stream
.path_name
[LTTNG_VIEWER_PATH_MAX
- 1] = '\0';
519 stream
.channel_name
[LTTNG_VIEWER_NAME_MAX
- 1] = '\0';
521 printf_verbose(" stream %" PRIu64
" : %s/%s\n",
522 be64toh(stream
.id
), stream
.path_name
,
523 stream
.channel_name
);
524 ctx
->session
->streams
[i
].id
= be64toh(stream
.id
);
525 ctx
->session
->streams
[i
].session
= ctx
->session
;
527 ctx
->session
->streams
[i
].mmap_size
= 0;
528 ctx
->session
->streams
[i
].ctf_stream_id
= -1ULL;
530 if (be32toh(stream
.metadata_flag
)) {
531 ctx
->session
->streams
[i
].metadata_flag
= 1;
533 ret
= lttng_live_ctf_trace_assign(&ctx
->session
->streams
[i
],
534 be64toh(stream
.ctf_trace_id
));
549 * Ask the relay for new streams.
551 * Returns the number of new streams received or a negative value on error.
554 int ask_new_streams(struct lttng_live_ctx
*ctx
)
556 int i
, ret
= 0, nb_streams
= 0;
560 for (i
= 0; i
< ctx
->session_ids
->len
; i
++) {
561 id
= g_array_index(ctx
->session_ids
, uint64_t, i
);
562 ret
= lttng_live_get_new_streams(ctx
, id
);
563 printf_verbose("Asking for new streams returns %d\n", ret
);
565 if (lttng_live_should_quit()) {
568 if (ret
== -LTTNG_VIEWER_NEW_STREAMS_HUP
) {
569 printf_verbose("Session %" PRIu64
" closed\n",
572 * The streams have already been closed during
573 * the reading, so we only need to get rid of
574 * the trace in our internal table of sessions.
576 g_array_remove_index(ctx
->session_ids
, i
);
578 * We can't continue iterating on the g_array
579 * after a remove, we have to start again.
597 int append_metadata(struct lttng_live_ctx
*ctx
,
598 struct lttng_live_viewer_stream
*viewer_stream
)
601 struct lttng_live_viewer_stream
*metadata
;
602 char *metadata_buf
= NULL
;
604 printf_verbose("get_next_index: new metadata needed\n");
605 ret
= get_new_metadata(ctx
, viewer_stream
, &metadata_buf
);
611 metadata
= viewer_stream
->ctf_trace
->metadata_stream
;
612 metadata
->ctf_trace
->metadata_fp
=
613 babeltrace_fmemopen(metadata_buf
,
614 metadata
->metadata_len
, "rb");
615 if (!metadata
->ctf_trace
->metadata_fp
) {
616 perror("Metadata fmemopen");
621 ret
= ctf_append_trace_metadata(
622 viewer_stream
->ctf_trace
->handle
->td
,
623 metadata
->ctf_trace
->metadata_fp
);
624 /* We accept empty metadata packets */
625 if (ret
!= 0 && ret
!= -ENOENT
) {
626 fprintf(stderr
, "[error] Appending metadata\n");
636 int get_data_packet(struct lttng_live_ctx
*ctx
,
637 struct ctf_stream_pos
*pos
,
638 struct lttng_live_viewer_stream
*stream
, uint64_t offset
,
641 struct lttng_viewer_cmd cmd
;
642 struct lttng_viewer_get_packet rq
;
643 struct lttng_viewer_trace_packet rp
;
648 if (lttng_live_should_quit()) {
654 * Flush the output between attempts to grab a packet, thus
655 * ensuring we flush at least at the periodical timer period.
656 * This ensures the output remains reactive for interactive users and
657 * that the output is flushed when redirected to a file by the shell.
659 if (fflush(LTTNG_LIVE_OUTPUT_FP
) < 0) {
664 cmd
.cmd
= htobe32(LTTNG_VIEWER_GET_PACKET
);
665 cmd
.data_size
= htobe64(sizeof(rq
));
666 cmd
.cmd_version
= htobe32(0);
668 memset(&rq
, 0, sizeof(rq
));
669 rq
.stream_id
= htobe64(stream
->id
);
670 rq
.offset
= htobe64(offset
);
671 rq
.len
= htobe32(len
);
673 ret_len
= lttng_live_send(ctx
->control_sock
, &cmd
, sizeof(cmd
));
675 perror("[error] Error sending cmd");
678 assert(ret_len
== sizeof(cmd
));
680 ret_len
= lttng_live_send(ctx
->control_sock
, &rq
, sizeof(rq
));
682 perror("[error] Error sending get_data_packet request");
685 assert(ret_len
== sizeof(rq
));
687 ret_len
= lttng_live_recv(ctx
->control_sock
, &rp
, sizeof(rp
));
689 fprintf(stderr
, "[error] Remote side has closed connection\n");
693 perror("[error] Error receiving data response");
696 if (ret_len
!= sizeof(rp
)) {
697 fprintf(stderr
, "[error] get_data_packet: expected %zu"
698 ", received %zd\n", sizeof(rp
),
703 rp
.flags
= be32toh(rp
.flags
);
705 switch (be32toh(rp
.status
)) {
706 case LTTNG_VIEWER_GET_PACKET_OK
:
707 len
= be32toh(rp
.len
);
708 printf_verbose("get_data_packet: Ok, packet size : %" PRIu64
711 case LTTNG_VIEWER_GET_PACKET_RETRY
:
712 /* Unimplemented by relay daemon */
713 printf_verbose("get_data_packet: retry\n");
715 case LTTNG_VIEWER_GET_PACKET_ERR
:
716 if (rp
.flags
& LTTNG_VIEWER_FLAG_NEW_METADATA
) {
717 printf_verbose("get_data_packet: new metadata needed\n");
718 ret
= append_metadata(ctx
, stream
);
722 if (rp
.flags
& LTTNG_VIEWER_FLAG_NEW_STREAM
) {
723 printf_verbose("get_data_packet: new streams needed\n");
724 ret
= ask_new_streams(ctx
);
727 } else if (ret
> 0) {
728 ret
= add_traces(ctx
);
734 if (rp
.flags
& (LTTNG_VIEWER_FLAG_NEW_METADATA
735 | LTTNG_VIEWER_FLAG_NEW_STREAM
)) {
738 fprintf(stderr
, "[error] get_data_packet: error\n");
740 case LTTNG_VIEWER_GET_PACKET_EOF
:
744 printf_verbose("get_data_packet: unknown\n");
752 if (len
> stream
->mmap_size
) {
755 new_size
= max_t(uint64_t, len
, stream
->mmap_size
<< 1);
758 ret
= munmap_align(pos
->base_mma
);
760 perror("[error] Unable to unmap old base");
763 pos
->base_mma
= NULL
;
765 pos
->base_mma
= mmap_align(new_size
,
766 PROT_READ
| PROT_WRITE
,
767 MAP_PRIVATE
| MAP_ANONYMOUS
, -1, 0);
768 if (pos
->base_mma
== MAP_FAILED
) {
769 perror("[error] mmap error");
770 pos
->base_mma
= NULL
;
774 stream
->mmap_size
= new_size
;
775 printf_verbose("Expanding stream mmap size to %" PRIu64
" bytes\n",
779 ret_len
= lttng_live_recv(ctx
->control_sock
,
780 mmap_align_addr(pos
->base_mma
), len
);
782 fprintf(stderr
, "[error] Remote side has closed connection\n");
786 perror("[error] Error receiving trace packet");
789 assert(ret_len
== len
);
799 int get_one_metadata_packet(struct lttng_live_ctx
*ctx
,
800 struct lttng_live_viewer_stream
*metadata_stream
)
804 struct lttng_viewer_cmd cmd
;
805 struct lttng_viewer_get_metadata rq
;
806 struct lttng_viewer_metadata_packet rp
;
810 if (lttng_live_should_quit()) {
815 rq
.stream_id
= htobe64(metadata_stream
->id
);
816 cmd
.cmd
= htobe32(LTTNG_VIEWER_GET_METADATA
);
817 cmd
.data_size
= htobe64(sizeof(rq
));
818 cmd
.cmd_version
= htobe32(0);
820 ret_len
= lttng_live_send(ctx
->control_sock
, &cmd
, sizeof(cmd
));
822 perror("[error] Error sending cmd");
825 assert(ret_len
== sizeof(cmd
));
827 ret_len
= lttng_live_send(ctx
->control_sock
, &rq
, sizeof(rq
));
829 perror("[error] Error sending get_metadata request");
832 assert(ret_len
== sizeof(rq
));
834 ret_len
= lttng_live_recv(ctx
->control_sock
, &rp
, sizeof(rp
));
836 fprintf(stderr
, "[error] Remote side has closed connection\n");
840 perror("[error] Error receiving metadata response");
843 assert(ret_len
== sizeof(rp
));
845 switch (be32toh(rp
.status
)) {
846 case LTTNG_VIEWER_METADATA_OK
:
847 printf_verbose("get_metadata : OK\n");
849 case LTTNG_VIEWER_NO_NEW_METADATA
:
850 printf_verbose("get_metadata : NO NEW\n");
853 case LTTNG_VIEWER_METADATA_ERR
:
854 printf_verbose("get_metadata : ERR\n");
857 printf_verbose("get_metadata : UNKNOWN\n");
861 len
= be64toh(rp
.len
);
862 printf_verbose("Writing %" PRIu64
" bytes to metadata\n", len
);
869 perror("relay data zmalloc");
872 ret_len
= lttng_live_recv(ctx
->control_sock
, data
, len
);
874 fprintf(stderr
, "[error] Remote side has closed connection\n");
875 goto error_free_data
;
878 perror("[error] Error receiving trace packet");
879 goto error_free_data
;
881 assert(ret_len
== len
);
884 ret_len
= fwrite(data
, 1, len
,
885 metadata_stream
->metadata_fp_write
);
886 } while (ret_len
< 0 && errno
== EINTR
);
888 fprintf(stderr
, "[error] Writing in the metadata fp\n");
889 goto error_free_data
;
891 assert(ret_len
== len
);
892 metadata_stream
->metadata_len
+= len
;
905 * Return 0 on success, a negative value on error.
908 int get_new_metadata(struct lttng_live_ctx
*ctx
,
909 struct lttng_live_viewer_stream
*viewer_stream
,
913 struct lttng_live_viewer_stream
*metadata_stream
;
914 size_t size
, len_read
= 0;
916 metadata_stream
= viewer_stream
->ctf_trace
->metadata_stream
;
917 if (!metadata_stream
) {
918 fprintf(stderr
, "[error] No metadata stream\n");
922 metadata_stream
->metadata_len
= 0;
923 ret
= open_metadata_fp_write(metadata_stream
, metadata_buf
, &size
);
929 if (lttng_live_should_quit()) {
934 * get_one_metadata_packet returns the number of bytes
935 * received, 0 when we have received everything, a
936 * negative value on error.
938 ret
= get_one_metadata_packet(ctx
, metadata_stream
);
943 (void) poll(NULL
, 0, ACTIVE_POLL_DELAY
);
945 } while (ret
> 0 || !len_read
);
947 if (babeltrace_close_memstream(metadata_buf
, &size
,
948 metadata_stream
->metadata_fp_write
)) {
949 perror("babeltrace_close_memstream");
951 metadata_stream
->metadata_fp_write
= NULL
;
958 * Assign the fields from a lttng_viewer_index to a packet_index.
961 void lttng_index_to_packet_index(struct lttng_viewer_index
*lindex
,
962 struct packet_index
*pindex
)
967 pindex
->offset
= be64toh(lindex
->offset
);
968 pindex
->packet_size
= be64toh(lindex
->packet_size
);
969 pindex
->content_size
= be64toh(lindex
->content_size
);
970 pindex
->ts_cycles
.timestamp_begin
= be64toh(lindex
->timestamp_begin
);
971 pindex
->ts_cycles
.timestamp_end
= be64toh(lindex
->timestamp_end
);
972 pindex
->events_discarded
= be64toh(lindex
->events_discarded
);
976 * Get one index for a stream.
978 * Returns 0 on success or a negative value on error.
981 int get_next_index(struct lttng_live_ctx
*ctx
,
982 struct lttng_live_viewer_stream
*viewer_stream
,
983 struct packet_index
*index
, uint64_t *stream_id
)
985 struct lttng_viewer_cmd cmd
;
986 struct lttng_viewer_get_next_index rq
;
989 struct lttng_viewer_index
*rp
= &viewer_stream
->current_index
;
991 cmd
.cmd
= htobe32(LTTNG_VIEWER_GET_NEXT_INDEX
);
992 cmd
.data_size
= htobe64(sizeof(rq
));
993 cmd
.cmd_version
= htobe32(0);
995 memset(&rq
, 0, sizeof(rq
));
996 rq
.stream_id
= htobe64(viewer_stream
->id
);
999 if (lttng_live_should_quit()) {
1003 ret_len
= lttng_live_send(ctx
->control_sock
, &cmd
, sizeof(cmd
));
1005 perror("[error] Error sending cmd");
1008 assert(ret_len
== sizeof(cmd
));
1010 ret_len
= lttng_live_send(ctx
->control_sock
, &rq
, sizeof(rq
));
1012 perror("[error] Error sending get_next_index request");
1015 assert(ret_len
== sizeof(rq
));
1017 ret_len
= lttng_live_recv(ctx
->control_sock
, rp
, sizeof(*rp
));
1019 fprintf(stderr
, "[error] Remote side has closed connection\n");
1023 perror("[error] Error receiving index response");
1026 assert(ret_len
== sizeof(*rp
));
1028 rp
->flags
= be32toh(rp
->flags
);
1030 switch (be32toh(rp
->status
)) {
1031 case LTTNG_VIEWER_INDEX_INACTIVE
:
1032 printf_verbose("get_next_index: inactive\n");
1033 memset(index
, 0, sizeof(struct packet_index
));
1034 index
->ts_cycles
.timestamp_end
= be64toh(rp
->timestamp_end
);
1035 *stream_id
= be64toh(rp
->stream_id
);
1037 case LTTNG_VIEWER_INDEX_OK
:
1038 printf_verbose("get_next_index: Ok, need metadata update : %u\n",
1039 rp
->flags
& LTTNG_VIEWER_FLAG_NEW_METADATA
);
1040 lttng_index_to_packet_index(rp
, index
);
1041 *stream_id
= be64toh(rp
->stream_id
);
1042 viewer_stream
->data_pending
= 1;
1044 if (rp
->flags
& LTTNG_VIEWER_FLAG_NEW_METADATA
) {
1045 ret
= append_metadata(ctx
, viewer_stream
);
1049 if (rp
->flags
& LTTNG_VIEWER_FLAG_NEW_STREAM
) {
1050 printf_verbose("get_next_index: need new streams\n");
1051 ret
= ask_new_streams(ctx
);
1054 } else if (ret
> 0) {
1055 ret
= add_traces(ctx
);
1062 case LTTNG_VIEWER_INDEX_RETRY
:
1063 printf_verbose("get_next_index: retry\n");
1064 (void) poll(NULL
, 0, ACTIVE_POLL_DELAY
);
1066 case LTTNG_VIEWER_INDEX_HUP
:
1067 printf_verbose("get_next_index: stream hung up\n");
1068 viewer_stream
->id
= -1ULL;
1069 index
->offset
= EOF
;
1070 ctx
->session
->stream_count
--;
1072 case LTTNG_VIEWER_INDEX_ERR
:
1073 fprintf(stderr
, "[error] get_next_index: error\n");
1076 fprintf(stderr
, "[error] get_next_index: unkwown value\n");
1088 void read_packet_header(struct ctf_stream_pos
*pos
,
1089 struct ctf_file_stream
*file_stream
)
1093 /* update trace_packet_header and stream_packet_context */
1094 if (!(pos
->prot
& PROT_WRITE
) &&
1095 file_stream
->parent
.trace_packet_header
) {
1096 /* Read packet header */
1097 ret
= generic_rw(&pos
->parent
,
1098 &file_stream
->parent
.trace_packet_header
->p
);
1101 fprintf(stderr
, "[error] trace packet "
1102 "header read failed\n");
1106 if (!(pos
->prot
& PROT_WRITE
) &&
1107 file_stream
->parent
.stream_packet_context
) {
1108 /* Read packet context */
1109 ret
= generic_rw(&pos
->parent
,
1110 &file_stream
->parent
.stream_packet_context
->p
);
1113 fprintf(stderr
, "[error] stream packet "
1114 "context read failed\n");
1118 pos
->data_offset
= pos
->offset
;
1125 * Handle the seek parameters.
1126 * Returns 0 if the packet_seek can continue, a positive value to
1127 * cleanly exit the packet_seek, a negative value on error.
1130 int handle_seek_position(size_t index
, int whence
,
1131 struct lttng_live_viewer_stream
*viewer_stream
,
1132 struct ctf_stream_pos
*pos
,
1133 struct ctf_file_stream
*file_stream
)
1143 * We only allow to seek to 0.
1146 fprintf(stderr
, "[error] Arbitrary seek in lttng-live "
1147 "trace not supported\n");
1157 fprintf(stderr
, "[error] Invalid seek parameter\n");
1166 void ctf_live_packet_seek(struct bt_stream_pos
*stream_pos
, size_t index
,
1169 struct ctf_stream_pos
*pos
;
1170 struct ctf_file_stream
*file_stream
;
1171 struct packet_index
*prev_index
= NULL
, *cur_index
;
1172 struct lttng_live_viewer_stream
*viewer_stream
;
1173 struct lttng_live_session
*session
;
1174 uint64_t stream_id
= -1ULL;
1177 pos
= ctf_pos(stream_pos
);
1178 file_stream
= container_of(pos
, struct ctf_file_stream
, pos
);
1179 viewer_stream
= (struct lttng_live_viewer_stream
*) pos
->priv
;
1180 session
= viewer_stream
->session
;
1182 ret
= handle_seek_position(index
, whence
, viewer_stream
, pos
,
1189 switch (pos
->packet_index
->len
) {
1191 g_array_set_size(pos
->packet_index
, 1);
1192 cur_index
= &g_array_index(pos
->packet_index
,
1193 struct packet_index
, 0);
1196 g_array_set_size(pos
->packet_index
, 2);
1197 prev_index
= &g_array_index(pos
->packet_index
,
1198 struct packet_index
, 0);
1199 cur_index
= &g_array_index(pos
->packet_index
,
1200 struct packet_index
, 1);
1203 g_array_index(pos
->packet_index
,
1204 struct packet_index
, 0) =
1205 g_array_index(pos
->packet_index
,
1206 struct packet_index
, 1);
1207 prev_index
= &g_array_index(pos
->packet_index
,
1208 struct packet_index
, 0);
1209 cur_index
= &g_array_index(pos
->packet_index
,
1210 struct packet_index
, 1);
1217 if (viewer_stream
->data_pending
) {
1218 lttng_index_to_packet_index(&viewer_stream
->current_index
, cur_index
);
1220 printf_verbose("get_next_index for stream %" PRIu64
"\n", viewer_stream
->id
);
1221 ret
= get_next_index(session
->ctx
, viewer_stream
, cur_index
, &stream_id
);
1224 if (!lttng_live_should_quit()) {
1225 fprintf(stderr
, "[error] get_next_index failed\n");
1229 printf_verbose("Index received : packet_size : %" PRIu64
1230 ", offset %" PRIu64
", content_size %" PRIu64
1231 ", timestamp_end : %" PRIu64
"\n",
1232 cur_index
->packet_size
, cur_index
->offset
,
1233 cur_index
->content_size
,
1234 cur_index
->ts_cycles
.timestamp_end
);
1239 * On the first time we receive an index, the stream_id needs to
1240 * be set for the stream in order to use it, we don't want any
1241 * data at this stage.
1243 if (file_stream
->parent
.stream_id
== -1ULL) {
1245 * Warning: with lttng-tools < 2.4.2, the beacon does not
1246 * contain the real stream ID, it is memset to 0, so this
1247 * might create a problem when a session has multiple
1248 * channels. We can't detect it at this stage, lttng-tools
1249 * has to be upgraded to fix this problem.
1251 printf_verbose("Assigning stream_id %" PRIu64
"\n",
1253 file_stream
->parent
.stream_id
= stream_id
;
1254 viewer_stream
->ctf_stream_id
= stream_id
;
1259 pos
->packet_size
= cur_index
->packet_size
;
1260 pos
->content_size
= cur_index
->content_size
;
1261 pos
->mmap_base_offset
= 0;
1262 if (cur_index
->offset
== EOF
) {
1268 if (cur_index
->content_size
== 0) {
1269 if (file_stream
->parent
.stream_class
) {
1270 file_stream
->parent
.cycles_timestamp
=
1271 cur_index
->ts_cycles
.timestamp_end
;
1272 file_stream
->parent
.real_timestamp
= ctf_get_real_timestamp(
1273 &file_stream
->parent
,
1274 cur_index
->ts_cycles
.timestamp_end
);
1277 if (file_stream
->parent
.stream_class
) {
1278 /* Convert the timestamps and append to the real_index. */
1279 cur_index
->ts_real
.timestamp_begin
= ctf_get_real_timestamp(
1280 &file_stream
->parent
,
1281 cur_index
->ts_cycles
.timestamp_begin
);
1282 cur_index
->ts_real
.timestamp_end
= ctf_get_real_timestamp(
1283 &file_stream
->parent
,
1284 cur_index
->ts_cycles
.timestamp_end
);
1287 ctf_update_current_packet_index(&file_stream
->parent
,
1288 prev_index
, cur_index
);
1290 file_stream
->parent
.cycles_timestamp
=
1291 cur_index
->ts_cycles
.timestamp_begin
;
1292 file_stream
->parent
.real_timestamp
=
1293 cur_index
->ts_real
.timestamp_begin
;
1296 if (pos
->packet_size
== 0 || pos
->offset
== EOF
) {
1300 printf_verbose("get_data_packet for stream %" PRIu64
"\n",
1302 ret
= get_data_packet(session
->ctx
, pos
, viewer_stream
,
1304 cur_index
->packet_size
/ CHAR_BIT
);
1307 } else if (ret
< 0) {
1309 if (!lttng_live_should_quit()) {
1310 fprintf(stderr
, "[error] get_data_packet failed\n");
1314 viewer_stream
->data_pending
= 0;
1316 read_packet_header(pos
, file_stream
);
1322 int lttng_live_create_viewer_session(struct lttng_live_ctx
*ctx
)
1324 struct lttng_viewer_cmd cmd
;
1325 struct lttng_viewer_create_session_response resp
;
1329 if (lttng_live_should_quit()) {
1334 cmd
.cmd
= htobe32(LTTNG_VIEWER_CREATE_SESSION
);
1335 cmd
.data_size
= htobe64(0);
1336 cmd
.cmd_version
= htobe32(0);
1338 ret_len
= lttng_live_send(ctx
->control_sock
, &cmd
, sizeof(cmd
));
1340 perror("[error] Error sending cmd");
1343 assert(ret_len
== sizeof(cmd
));
1345 ret_len
= lttng_live_recv(ctx
->control_sock
, &resp
, sizeof(resp
));
1347 fprintf(stderr
, "[error] Remote side has closed connection\n");
1351 perror("[error] Error receiving create session reply");
1354 assert(ret_len
== sizeof(resp
));
1356 if (be32toh(resp
.status
) != LTTNG_VIEWER_CREATE_SESSION_OK
) {
1357 fprintf(stderr
, "[error] Error creating viewer session\n");
1369 int del_traces(gpointer key
, gpointer value
, gpointer user_data
)
1371 struct bt_context
*bt_ctx
= user_data
;
1372 struct lttng_live_ctf_trace
*trace
= value
;
1375 ret
= bt_context_remove_trace(bt_ctx
, trace
->trace_id
);
1377 fprintf(stderr
, "[error] removing trace from context\n");
1379 /* remove the key/value pair from the HT. */
1384 int add_one_trace(struct lttng_live_ctx
*ctx
,
1385 struct lttng_live_ctf_trace
*trace
)
1388 struct bt_context
*bt_ctx
= ctx
->bt_ctx
;
1389 struct lttng_live_viewer_stream
*stream
;
1390 struct bt_mmap_stream
*new_mmap_stream
;
1391 struct bt_mmap_stream_list mmap_list
;
1392 struct bt_trace_descriptor
*td
;
1393 struct bt_trace_handle
*handle
;
1396 * We don't know how many streams we will receive for a trace, so
1397 * once we are done receiving the traces, we add all the traces
1398 * received to the bt_context.
1399 * We can receive streams during the attach command or the
1400 * get_new_streams, so we have to make sure not to add multiple
1401 * times the same traces.
1402 * If a trace is already in the context, we just skip this function.
1404 if (trace
->in_use
) {
1409 BT_INIT_LIST_HEAD(&mmap_list
.head
);
1411 for (i
= 0; i
< trace
->streams
->len
; i
++) {
1412 stream
= g_ptr_array_index(trace
->streams
, i
);
1414 if (!stream
->metadata_flag
) {
1415 new_mmap_stream
= zmalloc(sizeof(struct bt_mmap_stream
));
1416 new_mmap_stream
->priv
= (void *) stream
;
1417 new_mmap_stream
->fd
= -1;
1418 bt_list_add(&new_mmap_stream
->list
, &mmap_list
.head
);
1420 char *metadata_buf
= NULL
;
1422 /* Get all possible metadata before starting */
1423 ret
= get_new_metadata(ctx
, stream
, &metadata_buf
);
1428 if (!stream
->metadata_len
) {
1429 fprintf(stderr
, "[error] empty metadata\n");
1435 trace
->metadata_fp
= babeltrace_fmemopen(metadata_buf
,
1436 stream
->metadata_len
, "rb");
1437 if (!trace
->metadata_fp
) {
1438 perror("Metadata fmemopen");
1446 if (!trace
->metadata_fp
) {
1447 fprintf(stderr
, "[error] No metadata stream opened\n");
1452 ret
= bt_context_add_trace(bt_ctx
, NULL
, "ctf",
1453 ctf_live_packet_seek
, &mmap_list
, trace
->metadata_fp
);
1455 fprintf(stderr
, "[error] Error adding trace\n");
1459 trace
->metadata_stream
->metadata_len
= 0;
1461 handle
= (struct bt_trace_handle
*) g_hash_table_lookup(
1462 bt_ctx
->trace_handles
,
1463 (gpointer
) (unsigned long) ret
);
1465 trace
->handle
= handle
;
1466 if (bt_ctx
->current_iterator
) {
1467 bt_iter_add_trace(bt_ctx
->current_iterator
, td
);
1470 trace
->trace_id
= ret
;
1476 bt_context_put(bt_ctx
);
1482 int add_traces(struct lttng_live_ctx
*ctx
)
1485 struct lttng_live_ctf_trace
*trace
;
1490 g_hash_table_iter_init(&it
, ctx
->session
->ctf_traces
);
1491 while (g_hash_table_iter_next(&it
, &key
, &value
)) {
1492 trace
= (struct lttng_live_ctf_trace
*) value
;
1493 ret
= add_one_trace(ctx
, trace
);
1506 * Request new streams for a session.
1507 * Returns the number of streams received or a negative value on error.
1509 int lttng_live_get_new_streams(struct lttng_live_ctx
*ctx
, uint64_t id
)
1511 struct lttng_viewer_cmd cmd
;
1512 struct lttng_viewer_new_streams_request rq
;
1513 struct lttng_viewer_new_streams_response rp
;
1514 struct lttng_viewer_stream stream
;
1515 int ret
, i
, nb_streams
= 0;
1517 uint32_t stream_count
;
1519 if (lttng_live_should_quit()) {
1524 cmd
.cmd
= htobe32(LTTNG_VIEWER_GET_NEW_STREAMS
);
1525 cmd
.data_size
= htobe64(sizeof(rq
));
1526 cmd
.cmd_version
= htobe32(0);
1528 memset(&rq
, 0, sizeof(rq
));
1529 rq
.session_id
= htobe64(id
);
1531 ret_len
= lttng_live_send(ctx
->control_sock
, &cmd
, sizeof(cmd
));
1533 perror("[error] Error sending cmd");
1536 assert(ret_len
== sizeof(cmd
));
1538 ret_len
= lttng_live_send(ctx
->control_sock
, &rq
, sizeof(rq
));
1540 perror("[error] Error sending get_new_streams request");
1543 assert(ret_len
== sizeof(rq
));
1545 ret_len
= lttng_live_recv(ctx
->control_sock
, &rp
, sizeof(rp
));
1547 fprintf(stderr
, "[error] Remote side has closed connection\n");
1551 perror("[error] Error receiving get_new_streams response");
1554 assert(ret_len
== sizeof(rp
));
1556 switch(be32toh(rp
.status
)) {
1557 case LTTNG_VIEWER_NEW_STREAMS_OK
:
1559 case LTTNG_VIEWER_NEW_STREAMS_NO_NEW
:
1562 case LTTNG_VIEWER_NEW_STREAMS_HUP
:
1563 ret
= -LTTNG_VIEWER_NEW_STREAMS_HUP
;
1565 case LTTNG_VIEWER_NEW_STREAMS_ERR
:
1566 fprintf(stderr
, "[error] get_new_streams error\n");
1569 fprintf(stderr
, "[error] Unknown return code %u\n",
1570 be32toh(rp
.status
));
1574 stream_count
= be32toh(rp
.streams_count
);
1575 ctx
->session
->stream_count
+= stream_count
;
1577 * When the session is created but not started, we do an active wait
1578 * until it starts. It allows the viewer to start processing the trace
1579 * as soon as the session starts.
1581 if (ctx
->session
->stream_count
== 0) {
1585 printf_verbose("Waiting for %" PRIu64
" streams:\n",
1586 ctx
->session
->stream_count
);
1587 ctx
->session
->streams
= g_new0(struct lttng_live_viewer_stream
,
1588 ctx
->session
->stream_count
);
1589 for (i
= 0; i
< stream_count
; i
++) {
1590 ret_len
= lttng_live_recv(ctx
->control_sock
, &stream
, sizeof(stream
));
1592 fprintf(stderr
, "[error] Remote side has closed connection\n");
1596 perror("[error] Error receiving stream");
1599 assert(ret_len
== sizeof(stream
));
1600 stream
.path_name
[LTTNG_VIEWER_PATH_MAX
- 1] = '\0';
1601 stream
.channel_name
[LTTNG_VIEWER_NAME_MAX
- 1] = '\0';
1603 printf_verbose(" stream %" PRIu64
" : %s/%s\n",
1604 be64toh(stream
.id
), stream
.path_name
,
1605 stream
.channel_name
);
1606 ctx
->session
->streams
[i
].id
= be64toh(stream
.id
);
1607 ctx
->session
->streams
[i
].session
= ctx
->session
;
1609 ctx
->session
->streams
[i
].mmap_size
= 0;
1610 ctx
->session
->streams
[i
].ctf_stream_id
= -1ULL;
1612 if (be32toh(stream
.metadata_flag
)) {
1613 ctx
->session
->streams
[i
].metadata_flag
= 1;
1615 ret
= lttng_live_ctf_trace_assign(&ctx
->session
->streams
[i
],
1616 be64toh(stream
.ctf_trace_id
));
1631 int lttng_live_read(struct lttng_live_ctx
*ctx
)
1635 struct bt_ctf_iter
*iter
;
1636 const struct bt_ctf_event
*event
;
1637 struct bt_iter_pos begin_pos
;
1638 struct bt_trace_descriptor
*td_write
;
1639 struct bt_format
*fmt_write
;
1640 struct ctf_text_stream_pos
*sout
;
1643 ctx
->bt_ctx
= bt_context_create();
1645 fprintf(stderr
, "[error] bt_context_create allocation\n");
1649 fmt_write
= bt_lookup_format(g_quark_from_static_string("text"));
1651 fprintf(stderr
, "[error] ctf-text error\n");
1655 td_write
= fmt_write
->open_trace(NULL
, O_RDWR
, NULL
, NULL
);
1657 fprintf(stderr
, "[error] Error opening output trace\n");
1661 sout
= container_of(td_write
, struct ctf_text_stream_pos
,
1663 if (!sout
->parent
.event_cb
) {
1667 ret
= lttng_live_create_viewer_session(ctx
);
1672 for (i
= 0; i
< ctx
->session_ids
->len
; i
++) {
1673 id
= g_array_index(ctx
->session_ids
, uint64_t, i
);
1674 printf_verbose("Attaching to session %" PRIu64
"\n", id
);
1675 ret
= lttng_live_attach_session(ctx
, id
);
1676 printf_verbose("Attaching session returns %d\n", ret
);
1678 if (ret
== -LTTNG_VIEWER_ATTACH_UNK
) {
1679 fprintf(stderr
, "[error] Unknown session ID\n");
1686 * As long as the session is active, we try to get new streams.
1691 if (lttng_live_should_quit()) {
1696 while (!ctx
->session
->stream_count
) {
1697 if (lttng_live_should_quit()
1698 || ctx
->session_ids
->len
== 0) {
1702 ret
= ask_new_streams(ctx
);
1706 if (!ctx
->session
->stream_count
) {
1707 (void) poll(NULL
, 0, ACTIVE_POLL_DELAY
);
1711 ret
= add_traces(ctx
);
1716 begin_pos
.type
= BT_SEEK_BEGIN
;
1717 iter
= bt_ctf_iter_create(ctx
->bt_ctx
, &begin_pos
, NULL
);
1719 if (lttng_live_should_quit()) {
1723 fprintf(stderr
, "[error] Iterator creation error\n");
1727 if (lttng_live_should_quit()) {
1731 event
= bt_ctf_iter_read_event_flags(iter
, &flags
);
1732 if (!(flags
& BT_ITER_FLAG_RETRY
)) {
1737 ret
= sout
->parent
.event_cb(&sout
->parent
,
1738 event
->parent
->stream
);
1740 fprintf(stderr
, "[error] Writing "
1745 ret
= bt_iter_next(bt_ctf_get_iter(iter
));
1750 bt_ctf_iter_destroy(iter
);
1751 g_hash_table_foreach_remove(ctx
->session
->ctf_traces
,
1752 del_traces
, ctx
->bt_ctx
);
1753 ctx
->session
->stream_count
= 0;
1757 bt_context_put(ctx
->bt_ctx
);
1759 if (lttng_live_should_quit()) {