working textdump
[lttngtop.git] / src / lttngtop.c
index fd23e74da416c746cf437586ecb275d3c0628a2d..a042ceb98a92275b41f18d270b159d97e655c746 100644 (file)
@@ -132,6 +132,47 @@ void *ncurses_display(void *p)
        }
 }
 
+/* FIXME : TMP */
+struct tm ts_format_timestamp(uint64_t timestamp)
+{
+       struct tm tm;
+       uint64_t ts_sec = 0, ts_nsec;
+       time_t time_s;
+
+       ts_nsec = timestamp;
+       ts_sec += ts_nsec / NSEC_PER_SEC;
+       ts_nsec = ts_nsec % NSEC_PER_SEC;
+
+       time_s = (time_t) ts_sec;
+
+       localtime_r(&time_s, &tm);
+
+       return tm;
+}
+
+/*
+ * hook on each event to check the timestamp and refresh the display if
+ * necessary
+ */
+enum bt_cb_ret print_timestamp(struct bt_ctf_event *call_data, void *private_data)
+{
+       unsigned long timestamp;
+       struct tm start;
+       uint64_t ts_nsec_start, ts_nsec_end;
+
+
+       timestamp = bt_ctf_get_timestamp(call_data);
+
+       start = ts_format_timestamp(timestamp);
+       ts_nsec_start = timestamp % NSEC_PER_SEC;
+
+       printf("%02d:%02d:%02d.%09" PRIu64 " %s\n", start.tm_hour,
+                       start.tm_min, start.tm_sec, ts_nsec_start,
+                       bt_ctf_event_name(call_data));
+
+       return BT_CB_OK;
+}
+
 /*
  * hook on each event to check the timestamp and refresh the display if
  * necessary
@@ -390,6 +431,11 @@ void iter_trace(struct bt_context *bt_ctx)
        begin_pos.type = BT_SEEK_BEGIN;
        iter = bt_ctf_iter_create(bt_ctx, &begin_pos, NULL);
 
+       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,
@@ -434,7 +480,7 @@ void iter_trace(struct bt_context *bt_ctx)
                                        "lttng_statedump_file_descriptor"),
                        NULL, 0, handle_statedump_file_descriptor,
                        NULL, NULL, NULL);
-
+#endif
        while ((event = bt_ctf_iter_read_event(iter)) != NULL) {
                ret = bt_iter_next(bt_ctf_get_iter(iter));
                if (ret < 0)
@@ -824,7 +870,8 @@ int on_recv_fd(struct lttng_consumer_stream *kconsumerd_fd)
                }
 
                g_ptr_array_add(lttng_consumer_stream_array, kconsumerd_fd);
-               ret = 0;
+               /* keep mmap FDs internally */
+               ret = 1;
        } else {
                consumerd_metadata = helper_get_lttng_consumer_stream_wait_fd(kconsumerd_fd);
                sessiond_metadata = helper_get_lttng_consumer_stream_key(kconsumerd_fd);
@@ -840,30 +887,30 @@ void *live_consume()
        struct bt_context *bt_ctx = NULL;
        int ret;
 
-       while (1) {
-//             dump_snapshot();
-
-               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");
+       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 NULL;
                }
+               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",
-                                       lttngtop_ctf_packet_seek, &mmap_list, metadata_fp);
-                       trace_opened = 1;
+       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;
                }
-               iter_trace(bt_ctx);
-               sleep(1);
+               trace_opened = 1;
        }
+       iter_trace(bt_ctx);
+       sleep(1);
 }
 
 int setup_consumer(char *command_sock_path, pthread_t *threads,
@@ -928,6 +975,7 @@ void *setup_live_tracing()
 
        ret = system("rm -rf /tmp/livesession");
 
+       lttng_destroy_session("test");
        if ((ret = lttng_create_session("test", "/tmp/livesession")) < 0) {
                fprintf(stderr,"error creating the session : %s\n",
                                helper_lttcomm_get_readable_code(ret));
@@ -999,7 +1047,7 @@ void *setup_live_tracing()
        //init_lttngtop();
 
 end:
-       return ret;
+       return NULL;
 }
 
 int main(int argc, char **argv)
@@ -1019,7 +1067,7 @@ int main(int argc, char **argv)
        if (!opt_input_path) {
                printf("live tracing enabled\n");
                pthread_create(&live_trace_thread, NULL, setup_live_tracing, (void *) NULL);
-               sleep(20);
+               sleep(2000);
                printf("STOPPING\n");
                lttng_stop_tracing("test");
                printf("DESTROYING\n");
This page took 0.029994 seconds and 4 git commands to generate.