Format timestamp
authorJulien Desfossez <julien.desfossez@efficios.com>
Tue, 10 Apr 2012 15:26:38 +0000 (11:26 -0400)
committerJulien Desfossez <julien.desfossez@efficios.com>
Tue, 10 Apr 2012 15:26:38 +0000 (11:26 -0400)
Now the timestamp is printed in human-readable format.
It uses the localtime conversion, so it assumes the trace was recorded
on a machine with a similar localtime. GMT clock will also be supported
soon.

Signed-off-by: Julien Desfossez <julien.desfossez@efficios.com>
src/cursesdisplay.c

index acf5753008490925b019c3241838e8c63e2d9d3d..e4565ede33708d4410842062d86c6f0a7fe87d78 100644 (file)
@@ -261,20 +261,42 @@ void basic_header()
        wrefresh(header);
 }
 
+struct tm 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;
+}
+
 void update_header()
 {
+       struct tm start, end;
+       uint64_t ts_nsec_start, ts_nsec_end;
+
+       ts_nsec_start = data->start % NSEC_PER_SEC;
+       start = format_timestamp(data->start);
+
+       ts_nsec_end = data->end % NSEC_PER_SEC;
+       end = format_timestamp(data->end);
+
        werase(header);
        box(header, 0 , 0);
        set_window_title(header, "Statistics for interval ");
        wattron(header, A_BOLD);
-       /*
-       wprintw(header, "[%lu.%lu, %lu.%lu[",
-                       data->start.tv_sec, data->start.tv_nsec,
-                       data->end.tv_sec, data->end.tv_nsec);
-                       */
-       wprintw(header, "[%lu, %lu[",
-            data->start,
-            data->end);
+
+       wprintw(header, "[%02d:%02d:%02d.%09" PRIu64 ", %02d:%02d:%02d.%09" PRIu64 "[",
+               start.tm_hour, start.tm_min, start.tm_sec, ts_nsec_start,
+               end.tm_hour, end.tm_min, end.tm_sec, ts_nsec_end);
        mvwprintw(header, 1, 4, "CPUs");
        wattroff(header, A_BOLD);
        wprintw(header, "\t%d\t(max/cpu : %0.2f%)", data->cpu_table->len,
@@ -505,7 +527,7 @@ void update_perf()
 
        g_ptr_array_sort_with_data(data->process_table, sort_perf, perf_key);
 
-       for (i = 0; i < data->process_table->len && 
+       for (i = 0; i < data->process_table->len &&
                        nblinedisplayed < max_center_lines; i++) {
                tmp = g_ptr_array_index(data->process_table, i);
 
This page took 0.024425 seconds and 4 git commands to generate.