- bt_ctf_iter_add_callback(iter, 0, NULL, 0,
- print_timestamp,
- NULL, NULL, NULL);
-
-#if 0
- /* at each event check if we need to refresh */
- bt_ctf_iter_add_callback(iter, 0, NULL, 0,
- check_timestamp,
- NULL, NULL, NULL);
- /* at each event, verify the status of the process table */
- bt_ctf_iter_add_callback(iter, 0, NULL, 0,
- fix_process_table,
- NULL, NULL, NULL);
- /* to handle the scheduling events */
- bt_ctf_iter_add_callback(iter,
- g_quark_from_static_string("sched_switch"),
- NULL, 0, handle_sched_switch, NULL, NULL, NULL);
- /* to clean up the process table */
- bt_ctf_iter_add_callback(iter,
- g_quark_from_static_string("sched_process_free"),
- NULL, 0, handle_sched_process_free, NULL, NULL, NULL);
- /* to get all the process from the statedumps */
- bt_ctf_iter_add_callback(iter,
- g_quark_from_static_string(
- "lttng_statedump_process_state"),
- NULL, 0, handle_statedump_process_state,
- NULL, NULL, NULL);
-
- /* for IO top */
- bt_ctf_iter_add_callback(iter,
- g_quark_from_static_string("exit_syscall"),
- NULL, 0, handle_exit_syscall, NULL, NULL, NULL);
- bt_ctf_iter_add_callback(iter,
- g_quark_from_static_string("sys_write"),
- NULL, 0, handle_sys_write, NULL, NULL, NULL);
- bt_ctf_iter_add_callback(iter,
- g_quark_from_static_string("sys_read"),
- NULL, 0, handle_sys_read, NULL, NULL, NULL);
- bt_ctf_iter_add_callback(iter,
- g_quark_from_static_string("sys_open"),
- NULL, 0, handle_sys_open, NULL, NULL, NULL);
- bt_ctf_iter_add_callback(iter,
- g_quark_from_static_string("sys_close"),
- NULL, 0, handle_sys_close, NULL, NULL, NULL);
- bt_ctf_iter_add_callback(iter,
- g_quark_from_static_string(
+ if (opt_textdump) {
+ bt_ctf_iter_add_callback(iter, 0, NULL, 0,
+ print_timestamp,
+ NULL, NULL, NULL);
+ } else {
+ /* at each event check if we need to refresh */
+ bt_ctf_iter_add_callback(iter, 0, NULL, 0,
+ check_timestamp,
+ NULL, NULL, NULL);
+ /* at each event, verify the status of the process table */
+ bt_ctf_iter_add_callback(iter, 0, NULL, 0,
+ fix_process_table,
+ NULL, NULL, NULL);
+ /* to handle the scheduling events */
+ bt_ctf_iter_add_callback(iter,
+ g_quark_from_static_string("sched_switch"),
+ NULL, 0, handle_sched_switch, NULL, NULL, NULL);
+ /* to clean up the process table */
+ bt_ctf_iter_add_callback(iter,
+ g_quark_from_static_string("sched_process_free"),
+ NULL, 0, handle_sched_process_free, NULL, NULL, NULL);
+ /* to get all the process from the statedumps */
+ bt_ctf_iter_add_callback(iter,
+ g_quark_from_static_string(
+ "lttng_statedump_process_state"),
+ NULL, 0, handle_statedump_process_state,
+ NULL, NULL, NULL);
+
+ /* for IO top */
+ bt_ctf_iter_add_callback(iter,
+ g_quark_from_static_string("exit_syscall"),
+ NULL, 0, handle_exit_syscall, NULL, NULL, NULL);
+ bt_ctf_iter_add_callback(iter,
+ g_quark_from_static_string("sys_write"),
+ NULL, 0, handle_sys_write, NULL, NULL, NULL);
+ bt_ctf_iter_add_callback(iter,
+ g_quark_from_static_string("sys_read"),
+ NULL, 0, handle_sys_read, NULL, NULL, NULL);
+ bt_ctf_iter_add_callback(iter,
+ g_quark_from_static_string("sys_open"),
+ NULL, 0, handle_sys_open, NULL, NULL, NULL);
+ bt_ctf_iter_add_callback(iter,
+ g_quark_from_static_string("sys_close"),
+ NULL, 0, handle_sys_close, NULL, NULL, NULL);
+ bt_ctf_iter_add_callback(iter,
+ g_quark_from_static_string(
-void dump_snapshot()
-{
-#if 0
- struct lttng_consumer_stream *iter;
- unsigned long spos;
- struct mmap_stream *new_snapshot;
-
- int ret = 0;
- int i;
- /*
- * try lock mutex ressource courante (overrun)
- * if fail : overrun
- * stop trace (flush implicite avant stop)
- * lttng_consumer_take_snapshot
- * read timestamp packet end (use time as end pos)
- * - stream_packet_context
- * - reculer de 1 subbuf : pos - max_subbuff_size
- *
- * - position de fin (take_snapshot)
- * - mov_pos_slow ( fin - max_subbuff_size) lire timestamp packet end
- * - prend min(end) (activité sur tous les streams)
- *
- * start trace
- * unlock mutex
- */
-
- helper_kernctl_buffer_flush(consumerd_metadata);
- for (i = 0; i < lttng_consumer_stream_array->len; i++) {
- iter = g_ptr_array_index(lttng_consumer_stream_array, i);
- helper_kernctl_buffer_flush(helper_get_lttng_consumer_stream_wait_fd(iter));
- printf("Taking snapshot of fd : %d\n", helper_get_lttng_consumer_stream_wait_fd(iter));
- ret = helper_lttng_consumer_take_snapshot(ctx, iter);
- if (ret != 0) {
- ret = errno;
- perror("lttng_consumer_take_snapshots");
- goto end;
- }
- }
- for (i = 0; i < lttng_consumer_stream_array->len; i++) {
- iter = g_ptr_array_index(lttng_consumer_stream_array, i);
- ret = helper_lttng_consumer_get_produced_snapshot(ctx, iter, &spos);
- if (ret != 0) {
- ret = errno;
- perror("helper_lttng_consumer_get_produced_snapshot");
- goto end;
- }
- while (helper_get_lttng_consumer_stream_wait_last_pos(iter) < spos) {
- new_snapshot = g_new0(struct mmap_stream, 1);
- new_snapshot->fd = helper_get_lttng_consumer_stream_wait_fd(iter);
- new_snapshot->last_pos = helper_get_lttng_consumer_stream_wait_last_pos(iter);
- fprintf(stderr,"ADDING AVAILABLE SNAPSHOT ON FD %d AT POSITION %lu\n",
- new_snapshot->fd,
- new_snapshot->last_pos);
- g_ptr_array_add(available_snapshots, new_snapshot);
- helper_set_lttng_consumer_stream_wait_last_pos(iter,
- helper_get_lttng_consumer_stream_wait_last_pos(iter) +
- helper_get_lttng_consumer_stream_chan_max_sb_size(iter));
- }
- }
-
- if (!metadata_ready) {
- fprintf(stderr, "BLOCKING BEFORE METADATA\n");
- sem_wait(&metadata_available);
- fprintf(stderr,"OPENING TRACE\n");
- if (access("/tmp/livesession/kernel/metadata", F_OK) != 0) {
- fprintf(stderr,"NO METADATA FILE, SKIPPING\n");
- return;
- }
- metadata_ready = 1;
- metadata_fp = fopen("/tmp/livesession/kernel/metadata", "r");
- }
-
-
-end:
- return;
-#endif
-}
-
- printf("live tracing enabled\n");
- pthread_create(&live_trace_thread, NULL, setup_live_tracing, (void *) NULL);
- sleep(20);
- printf("STOPPING\n");
+ ret = setup_live_tracing();
+ if (ret < 0) {
+ goto end;
+ }
+ init_lttngtop();
+ if (!opt_textdump) {
+ pthread_create(&display_thread, NULL, ncurses_display, (void *) NULL);
+ pthread_create(&timer_thread, NULL, refresh_thread, (void *) NULL);
+ }
+ 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) {
+ bt_list_del(&mmap_info->list);
+ }
+ }
+ sem_post(&metadata_available);
+ }
+
+ pthread_join(timer_thread, NULL);
+ quit = 1;
+ pthread_join(display_thread, NULL);
+