Print event discarded at end of stream
authorMathieu Desnoyers <mathieu.desnoyers@efficios.com>
Mon, 30 Jan 2012 21:41:39 +0000 (16:41 -0500)
committerMathieu Desnoyers <mathieu.desnoyers@efficios.com>
Mon, 30 Jan 2012 21:41:39 +0000 (16:41 -0500)
Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
formats/ctf-text/ctf-text.c
formats/ctf/ctf.c
include/babeltrace/ctf/types.h

index f8507e6256093eba7c67fa7083fb1624b03b637e..83f0cf9c9ac1e8385e2ed29c2574ba0ab60a2e7e 100644 (file)
@@ -47,13 +47,7 @@ int opt_all_field_names,
        opt_trace_procname_field,
        opt_trace_vpid_field,
        opt_loglevel_field,
-       opt_delta_field = 1,
-       opt_clock_raw,
-       opt_clock_seconds,
-       opt_clock_date,
-       opt_clock_gmt;
-
-uint64_t opt_clock_offset;
+       opt_delta_field = 1;
 
 enum field_item {
        ITEM_SCOPE,
@@ -157,75 +151,6 @@ void set_field_names_print(struct ctf_text_stream_pos *pos, enum field_item item
        }
 }
 
-static
-void ctf_text_print_timestamp(FILE *fp, struct ctf_text_stream_pos *pos,
-                       struct ctf_stream *stream,
-                       uint64_t timestamp)
-{
-       uint64_t ts_sec = 0, ts_nsec;
-       struct ctf_trace *trace = stream->stream_class->trace;
-       struct trace_collection *tc = trace->collection;
-       struct ctf_clock *clock = tc->single_clock;
-
-       ts_nsec = timestamp;
-
-       /* Add offsets */
-       if (!opt_clock_raw && clock) {
-               ts_sec += clock->offset_s;
-               ts_nsec += clock->offset;
-       }
-       ts_sec += opt_clock_offset;
-
-       ts_sec += ts_nsec / NSEC_PER_SEC;
-       ts_nsec = ts_nsec % NSEC_PER_SEC;
-
-       if (!opt_clock_seconds) {
-               struct tm tm;
-               time_t time_s = (time_t) ts_sec;
-
-               if (!opt_clock_gmt) {
-                       struct tm *res;
-
-                       res = localtime_r(&time_s, &tm);
-                       if (!res) {
-                               fprintf(stderr, "[warning] Unable to get localtime.\n");
-                               goto seconds;
-                       }
-               } else {
-                       struct tm *res;
-
-                       res = gmtime_r(&time_s, &tm);
-                       if (!res) {
-                               fprintf(stderr, "[warning] Unable to get gmtime.\n");
-                               goto seconds;
-                       }
-               }
-               if (opt_clock_date) {
-                       char timestr[26];
-                       size_t res;
-
-                       /* Print date and time */
-                       res = strftime(timestr, sizeof(timestr),
-                               "%F ", &tm);
-                       if (!res) {
-                               fprintf(stderr, "[warning] Unable to print ascii time.\n");
-                               goto seconds;
-                       }
-                       fprintf(fp, "%s", timestr);
-               }
-               /* Print time in HH:MM:SS.ns */
-               fprintf(fp, "%02d:%02d:%02d.%09" PRIu64,
-                       tm.tm_hour, tm.tm_min, tm.tm_sec, ts_nsec);
-               goto end;
-       }
-seconds:
-       fprintf(fp, "%3" PRIu64 ".%09" PRIu64,
-               ts_sec, ts_nsec);
-
-end:
-       return;
-}
-
 static
 int ctf_text_write_event(struct stream_pos *ppos,
                         struct ctf_stream *stream)
@@ -259,12 +184,12 @@ int ctf_text_write_event(struct stream_pos *ppos,
 
        /* Print events discarded */
        if (stream->events_discarded) {
-               fflush(stdout);
+               fflush(pos->fp);
                fprintf(stderr, "[warning] Tracer discarded %d events between [",
                        stream->events_discarded);
-               ctf_text_print_timestamp(stderr, pos, stream, stream->prev_timestamp);
+               ctf_print_timestamp(stderr, stream, stream->prev_timestamp);
                fprintf(stderr, "] and [");
-               ctf_text_print_timestamp(stderr, pos, stream, stream->prev_timestamp_end);
+               ctf_print_timestamp(stderr, stream, stream->prev_timestamp_end);
                fprintf(stderr, "]. You should consider increasing the buffer size.\n");
                fflush(stderr);
                stream->events_discarded = 0;
@@ -276,7 +201,7 @@ int ctf_text_write_event(struct stream_pos *ppos,
                        fprintf(pos->fp, "timestamp = ");
                else
                        fprintf(pos->fp, "[");
-               ctf_text_print_timestamp(pos->fp, pos, stream, stream->timestamp);
+               ctf_print_timestamp(pos->fp, stream, stream->timestamp);
                if (!pos->print_names)
                        fprintf(pos->fp, "]");
 
index 0e425bbb0b4d2abacc4a9d5c0297ebfb7278ab0e..62cc2e3939e2f8506d779aada3c02b215a6623d0 100644 (file)
 #define min(a, b)      (((a) < (b)) ? (a) : (b))
 #endif
 
+#define NSEC_PER_SEC 1000000000ULL
+
+int opt_clock_raw,
+       opt_clock_seconds,
+       opt_clock_date,
+       opt_clock_gmt;
+
+uint64_t opt_clock_offset;
+
 extern int yydebug;
 
 static
@@ -125,6 +134,74 @@ void ctf_update_timestamp(struct ctf_stream *stream,
        stream->timestamp = updateval;
 }
 
+void ctf_print_timestamp(FILE *fp,
+                       struct ctf_stream *stream,
+                       uint64_t timestamp)
+{
+       uint64_t ts_sec = 0, ts_nsec;
+       struct ctf_trace *trace = stream->stream_class->trace;
+       struct trace_collection *tc = trace->collection;
+       struct ctf_clock *clock = tc->single_clock;
+
+       ts_nsec = timestamp;
+
+       /* Add offsets */
+       if (!opt_clock_raw && clock) {
+               ts_sec += clock->offset_s;
+               ts_nsec += clock->offset;
+       }
+       ts_sec += opt_clock_offset;
+
+       ts_sec += ts_nsec / NSEC_PER_SEC;
+       ts_nsec = ts_nsec % NSEC_PER_SEC;
+
+       if (!opt_clock_seconds) {
+               struct tm tm;
+               time_t time_s = (time_t) ts_sec;
+
+               if (!opt_clock_gmt) {
+                       struct tm *res;
+
+                       res = localtime_r(&time_s, &tm);
+                       if (!res) {
+                               fprintf(stderr, "[warning] Unable to get localtime.\n");
+                               goto seconds;
+                       }
+               } else {
+                       struct tm *res;
+
+                       res = gmtime_r(&time_s, &tm);
+                       if (!res) {
+                               fprintf(stderr, "[warning] Unable to get gmtime.\n");
+                               goto seconds;
+                       }
+               }
+               if (opt_clock_date) {
+                       char timestr[26];
+                       size_t res;
+
+                       /* Print date and time */
+                       res = strftime(timestr, sizeof(timestr),
+                               "%F ", &tm);
+                       if (!res) {
+                               fprintf(stderr, "[warning] Unable to print ascii time.\n");
+                               goto seconds;
+                       }
+                       fprintf(fp, "%s", timestr);
+               }
+               /* Print time in HH:MM:SS.ns */
+               fprintf(fp, "%02d:%02d:%02d.%09" PRIu64,
+                       tm.tm_hour, tm.tm_min, tm.tm_sec, ts_nsec);
+               goto end;
+       }
+seconds:
+       fprintf(fp, "%3" PRIu64 ".%09" PRIu64,
+               ts_sec, ts_nsec);
+
+end:
+       return;
+}
+
 static
 int ctf_read_event(struct stream_pos *ppos, struct ctf_stream *stream)
 {
@@ -396,6 +473,9 @@ void ctf_move_pos_slow(struct ctf_stream_pos *pos, size_t offset, int whence)
                {
                        uint32_t events_discarded_diff;
 
+                       if (pos->offset == EOF) {
+                               return;
+                       }
                        /* For printing discarded event count */
                        index = &g_array_index(pos->packet_index,
                                        struct packet_index, pos->cur_index);
@@ -409,12 +489,10 @@ void ctf_move_pos_slow(struct ctf_stream_pos *pos, size_t offset, int whence)
                                events_discarded_diff -= index->events_discarded;
                        }
                        file_stream->parent.events_discarded = events_discarded_diff;
-                       if (pos->offset == EOF)
-                               return;
+                       file_stream->parent.prev_timestamp = file_stream->parent.timestamp;
                        /* The reader will expect us to skip padding */
                        assert(pos->offset + offset == pos->content_size);
                        ++pos->cur_index;
-                       file_stream->parent.prev_timestamp = file_stream->parent.timestamp;
                        break;
                }
                case SEEK_SET:
@@ -427,6 +505,26 @@ void ctf_move_pos_slow(struct ctf_stream_pos *pos, size_t offset, int whence)
                        assert(0);
                }
                if (pos->cur_index >= pos->packet_index->len) {
+                       /*
+                        * When a stream reaches the end of the
+                        * file, we need to show the number of
+                        * events discarded ourselves, because
+                        * there is no next event scheduled to
+                        * be printed in the output.
+                        */
+                       if (file_stream->parent.events_discarded) {
+                               fflush(stdout);
+                               fprintf(stderr, "[warning] Tracer discarded %d events at end of stream between [",
+                                       file_stream->parent.events_discarded);
+                               ctf_print_timestamp(stderr, &file_stream->parent,
+                                       file_stream->parent.prev_timestamp);
+                               fprintf(stderr, "] and [");
+                               ctf_print_timestamp(stderr, &file_stream->parent,
+                                       file_stream->parent.prev_timestamp_end);
+                               fprintf(stderr, "]. You should consider increasing the buffer size.\n");
+                               fflush(stderr);
+                               file_stream->parent.events_discarded = 0;
+                       }
                        pos->offset = EOF;
                        return;
                }
index 0b045448908e3db9afba22ae165751776722f7ec..c5c824fdb8bab26f3d6808ec9562a6f70a807fa9 100644 (file)
@@ -199,4 +199,7 @@ void ctf_pos_get_event(struct ctf_stream_pos *pos)
        }
 }
 
+void ctf_print_timestamp(FILE *fp, struct ctf_stream *stream,
+                       uint64_t timestamp);
+
 #endif /* _BABELTRACE_CTF_TYPES_H */
This page took 0.028308 seconds and 4 git commands to generate.