X-Git-Url: https://git.lttng.org/?p=lttngtop.git;a=blobdiff_plain;f=src%2Flttngtop.c;h=26faf1de7d0344db0717e371f82b5bcd152fb1a4;hp=7c0ec53b71c34f280bde95b8698bff32c5763fff;hb=33572a17ebf19098e1f1d3f1088e000e276eec60;hpb=6777529d08ef971ec423bf62b69fab662fe4040a diff --git a/src/lttngtop.c b/src/lttngtop.c index 7c0ec53..26faf1d 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; @@ -88,9 +89,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 +123,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 +149,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); @@ -355,6 +365,8 @@ void init_lttngtop() lttngtop.nbthreads = 0; lttngtop.nbfiles = 0; + lttngtop.process_hash_table = g_hash_table_new(g_direct_hash, + g_direct_equal); lttngtop.process_table = g_ptr_array_new(); lttngtop.files_table = g_ptr_array_new(); lttngtop.cpu_table = g_ptr_array_new(); @@ -463,7 +475,9 @@ void iter_trace(struct bt_context *bt_ctx) NULL, NULL, NULL); } - while ((event = bt_ctf_iter_read_event(iter)) != NULL) { + while (((event = bt_ctf_iter_read_event(iter)) != NULL)) { + if (quit) + goto end_iter; ret = bt_iter_next(bt_ctf_get_iter(iter)); if (ret < 0) goto end_iter; @@ -763,34 +777,33 @@ end: return ret; } -void *live_consume() +void live_consume(struct bt_context **bt_ctx) { - struct bt_context *bt_ctx = NULL; int ret; if (!metadata_ready) { sem_wait(&metadata_available); if (access("/tmp/livesession/kernel/metadata", F_OK) != 0) { fprintf(stderr,"no metadata\n"); - return NULL; + goto end; } metadata_ready = 1; 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", + *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; + goto end; } trace_opened = 1; } - iter_trace(bt_ctx); - return NULL; +end: + return; } int setup_consumer(char *command_sock_path, pthread_t *threads, @@ -853,7 +866,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) { @@ -949,9 +962,13 @@ 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(); + live_consume(&bt_ctx); + iter_trace(bt_ctx); + + pthread_join(timer_thread, NULL); + quit = 1; + pthread_join(display_thread, NULL); - sleep(2000); lttng_stop_tracing("test"); lttng_destroy_session("test"); @@ -976,8 +993,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); }