X-Git-Url: https://git.lttng.org/?p=lttngtop.git;a=blobdiff_plain;f=src%2Flttngtop.c;h=9b650f4bddc5b43926bf318ba6961d1b591caf7c;hp=9ac8d39c1c9f8c262a9fea039de0c7c9b663e339;hb=050f9cf91c01ff380df000bd0daa559285b7e787;hpb=30b646c4e7aab1e1bee8fef60619a61bd80bedad diff --git a/src/lttngtop.c b/src/lttngtop.c index 9ac8d39..9b650f4 100644 --- a/src/lttngtop.c +++ b/src/lttngtop.c @@ -53,13 +53,14 @@ const char *opt_input_path; int opt_textdump; +int quit = 0; + struct lttngtop *copy; pthread_t display_thread; pthread_t timer_thread; unsigned long refresh_display = 1 * NSEC_PER_SEC; unsigned long last_display_update = 0; -int quit = 0; /* list of FDs available for being read with snapshots */ struct mmap_stream_list mmap_list; @@ -69,9 +70,7 @@ struct lttng_consumer_local_data *ctx = NULL; /* list of snapshots currently not consumed */ GPtrArray *available_snapshots; sem_t metadata_available; -FILE *metadata_fp; -int trace_opened = 0; -int metadata_ready = 0; +int reload_trace = 0; enum { OPT_NONE = 0, @@ -88,9 +87,17 @@ static struct poptOption long_options[] = { void *refresh_thread(void *p) { + struct mmap_stream *mmap_info; + while (1) { - if (quit) - return NULL; + if (quit) { + sem_post(&pause_sem); + sem_post(&timer); + sem_post(&goodtodisplay); + pthread_exit(0); + } + bt_list_for_each_entry(mmap_info, &mmap_list.head, list) + helper_kernctl_buffer_flush(mmap_info->fd); sem_wait(&pause_sem); sem_post(&pause_sem); sem_post(&timer); @@ -114,17 +121,19 @@ void *ncurses_display(void *p) sem_wait(&goodtodisplay); sem_wait(&pause_sem); + if (quit) { + sem_post(&pause_sem); + sem_post(&timer); + reset_ncurses(); + pthread_exit(0); + } + copy = g_ptr_array_index(copies, current_display_index); assert(copy); display(current_display_index++); sem_post(&goodtoupdate); sem_post(&pause_sem); - - if (quit) { - reset_ncurses(); - pthread_exit(0); - } } } @@ -138,7 +147,6 @@ enum bt_cb_ret print_timestamp(struct bt_ctf_event *call_data, void *private_dat struct tm start; uint64_t ts_nsec_start; - timestamp = bt_ctf_get_timestamp(call_data); start = format_timestamp(timestamp); @@ -343,7 +351,6 @@ void init_lttngtop() copies = g_ptr_array_new(); global_perf_liszt = g_hash_table_new(g_str_hash, g_str_equal); - sem_init(&goodtodisplay, 0, 0); sem_init(&goodtoupdate, 0, 1); sem_init(&timer, 0, 1); @@ -467,6 +474,8 @@ void iter_trace(struct bt_context *bt_ctx) } while ((event = bt_ctf_iter_read_event(iter)) != NULL) { + if (quit || reload_trace) + goto end_iter; ret = bt_iter_next(bt_ctf_get_iter(iter)); if (ret < 0) goto end_iter; @@ -762,38 +771,34 @@ int on_recv_fd(struct lttng_consumer_stream *kconsumerd_fd) ret = 0; } + reload_trace = 1; + end: return ret; } -void *live_consume() +void live_consume(struct bt_context **bt_ctx) { - struct bt_context *bt_ctx = NULL; int ret; + FILE *metadata_fp; - if (!metadata_ready) { - sem_wait(&metadata_available); - if (access("/tmp/livesession/metadata", F_OK) != 0) { - fprintf(stderr,"no metadata\n"); - return NULL; - } - metadata_ready = 1; - metadata_fp = fopen("/tmp/livesession/metadata", "r"); + sem_wait(&metadata_available); + if (access("/tmp/livesession/kernel/metadata", F_OK) != 0) { + fprintf(stderr,"no metadata\n"); + goto end; } + metadata_fp = fopen("/tmp/livesession/kernel/metadata", "r"); - if (!trace_opened) { - bt_ctx = bt_context_create(); - ret = bt_context_add_trace(bt_ctx, NULL, "ctf", - lttngtop_ctf_packet_seek, &mmap_list, metadata_fp); - if (ret < 0) { - printf("Error adding trace\n"); - return NULL; - } - trace_opened = 1; + *bt_ctx = bt_context_create(); + ret = bt_context_add_trace(*bt_ctx, NULL, "ctf", + lttngtop_ctf_packet_seek, &mmap_list, metadata_fp); + if (ret < 0) { + printf("Error adding trace\n"); + goto end; } - iter_trace(bt_ctx); - return NULL; +end: + return; } int setup_consumer(char *command_sock_path, pthread_t *threads, @@ -856,7 +861,7 @@ void *setup_live_tracing() /* setup the session */ dom.type = LTTNG_DOMAIN_KERNEL; - ret = system("rm -rf /tmp/livesession"); + ret = unlink("/tmp/livesession"); lttng_destroy_session("test"); if ((ret = lttng_create_session("test", "/tmp/livesession")) < 0) { @@ -870,6 +875,16 @@ void *setup_live_tracing() goto end; } + /* + * FIXME : need to let the + * helper_lttng_consumer_thread_receive_fds create the + * socket. + * Cleaner solution ? + */ + while (access(command_sock_path, F_OK)) { + sleep(0.1); + } + if ((ret = lttng_register_consumer(handle, command_sock_path)) < 0) { fprintf(stderr,"error registering consumer : %s\n", helper_lttcomm_get_readable_code(ret)); @@ -935,6 +950,8 @@ int main(int argc, char **argv) { int ret; struct bt_context *bt_ctx = NULL; + struct mmap_stream *mmap_info; + unsigned long mmap_len; ret = parse_options(argc, argv); if (ret < 0) { @@ -952,9 +969,38 @@ int main(int argc, char **argv) pthread_create(&display_thread, NULL, ncurses_display, (void *) NULL); pthread_create(&timer_thread, NULL, refresh_thread, (void *) NULL); } - live_consume(); + while (!quit) { + reload_trace = 0; + live_consume(&bt_ctx); + iter_trace(bt_ctx); + ret = bt_context_remove_trace(bt_ctx, 0); + if (ret != 0) + fprintf(stderr, "error removing trace\n"); + if (bt_ctx) { + bt_context_put(bt_ctx); + } + + /* + * since we receive all FDs every time there is an + * update and the FD number is different every time, + * we don't know which one are valid. + * so we check if all FDs are usable with a simple + * ioctl call. + */ + bt_list_for_each_entry(mmap_info, &mmap_list.head, list) { + ret = helper_kernctl_get_mmap_len(mmap_info->fd, &mmap_len); + if (ret != 0) { + ret = errno; + bt_list_del(&mmap_info->list); + } + } + sem_post(&metadata_available); + } + + pthread_join(timer_thread, NULL); + quit = 1; + pthread_join(display_thread, NULL); - sleep(2000); lttng_stop_tracing("test"); lttng_destroy_session("test"); @@ -979,8 +1025,8 @@ int main(int argc, char **argv) iter_trace(bt_ctx); - quit = 1; pthread_join(display_thread, NULL); + quit = 1; pthread_join(timer_thread, NULL); }