Update pretty-printing output
authorMathieu Desnoyers <mathieu.desnoyers@efficios.com>
Mon, 9 May 2011 17:23:40 +0000 (13:23 -0400)
committerMathieu Desnoyers <mathieu.desnoyers@efficios.com>
Mon, 9 May 2011 17:23:40 +0000 (13:23 -0400)
Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
converter/babeltrace-lib.c
formats/ctf-text/ctf-text.c
formats/ctf/ctf.c
include/babeltrace/ctf/metadata.h
include/babeltrace/types.h

index cc3d8d3b922235c31184951e41fa347feb86cc6f..aba421999f31b1b061a598083cf750e4e1dcf13e 100644 (file)
@@ -35,14 +35,14 @@ int convert_stream(struct ctf_text_stream_pos *sout,
        /* For each event, print header, context, payload */
        /* TODO: order events by timestamps across streams */
        for (;;) {
-               ret = sin->pos.parent.event_cb(&sin->pos.parent, sin->stream);
+               ret = sin->pos.parent.event_cb(&sin->pos.parent, &sin->stream);
                if (ret == EOF)
                        break;
                else if (ret) {
                        fprintf(stdout, "[error] Reading event failed.\n");
                        goto error;
                }
-               ret = sout->parent.event_cb(&sout->parent, sin->stream);
+               ret = sout->parent.event_cb(&sout->parent, &sin->stream);
                if (ret) {
                        fprintf(stdout, "[error] Writing event failed.\n");
                        goto error;
index c355f0a6e34b6d5c0fafb2aeb3a1bc496e3bff03..882e0620eed83159510f844d9c1d5ed4e34fccff 100644 (file)
@@ -55,10 +55,11 @@ struct format ctf_text_format = {
 
 static
 int ctf_text_write_event(struct stream_pos *ppos,
-                        struct ctf_stream_class *stream_class)
+                        struct ctf_stream *stream)
 {
        struct ctf_text_stream_pos *pos =
                container_of(ppos, struct ctf_text_stream_pos, parent);
+       struct ctf_stream_class *stream_class = stream->stream_class;
        struct ctf_event *event_class;
        uint64_t id = 0;
        int len_index;
@@ -96,7 +97,7 @@ int ctf_text_write_event(struct stream_pos *ppos,
                fprintf(pos->fp, "timestamp = ");
        else
                fprintf(pos->fp, "[");
-       fprintf(pos->fp, "%" PRIu64, (uint64_t) 0);     /* TODO */
+       fprintf(pos->fp, "%12" PRIu64, stream->timestamp);
        if (!pos->print_names)
                fprintf(pos->fp, "]");
 
@@ -112,7 +113,8 @@ int ctf_text_write_event(struct stream_pos *ppos,
        else
                fprintf(pos->fp, ": ");
 
-       if (stream_class->event_header) {
+       /* Only show the event header in verbose mode */
+       if (babeltrace_verbose && stream_class->event_header) {
                if (field_nr++ != 0)
                        fprintf(pos->fp, ", ");
                if (pos->print_names)
index 441d2bb491d2567e6eb2a54d5e9d394fa89d469c..f4432a89d167c0fe01e181232f246ad4cf5b73e0 100644 (file)
@@ -80,10 +80,11 @@ struct format ctf_format = {
 };
 
 static
-int ctf_read_event(struct stream_pos *ppos, struct ctf_stream_class *stream_class)
+int ctf_read_event(struct stream_pos *ppos, struct ctf_stream *stream)
 {
        struct ctf_stream_pos *pos =
                container_of(ppos, struct ctf_stream_pos, parent);
+       struct ctf_stream_class *stream_class = stream->stream_class;
        struct ctf_event *event_class;
        uint64_t id = 0;
        int len_index;
@@ -110,6 +111,22 @@ int ctf_read_event(struct stream_pos *ppos, struct ctf_stream_class *stream_clas
                        assert(defint->declaration->signedness == FALSE);
                        id = defint->value._unsigned;   /* set id */
                }
+
+               /* lookup timestamp */
+               len_index = struct_declaration_lookup_field_index(stream_class->event_header_decl,
+                               g_quark_from_static_string("timestamp"));
+               if (len_index >= 0) {
+                       struct definition_integer *defint;
+                       struct definition *field;
+
+                       field = struct_definition_get_field_from_index(stream_class->event_header, len_index);
+                       assert(field->declaration->id == CTF_TYPE_INTEGER);
+                       defint = container_of(field, struct definition_integer, p);
+                       assert(defint->declaration->signedness == FALSE);
+                       /* update timestamp */
+                       stream->timestamp = defint->value._unsigned;
+               }
+
        }
 
        /* Read stream-declared event context */
@@ -151,8 +168,9 @@ error:
 }
 
 static
-int ctf_write_event(struct stream_pos *pos, struct ctf_stream_class *stream_class)
+int ctf_write_event(struct stream_pos *pos, struct ctf_stream *stream)
 {
+       struct ctf_stream_class *stream_class = stream->stream_class;
        struct ctf_event *event_class;
        uint64_t id = 0;
        int len_index;
@@ -545,7 +563,7 @@ int create_stream_packet_index(struct ctf_trace *td,
                                fprintf(stdout, "[error] Stream %" PRIu64 " is not declared in metadata.\n", stream_id);
                                return -EINVAL;
                        }
-                       file_stream->stream = stream;
+                       file_stream->stream.stream_class = stream;
                }
                first_packet = 0;
 
@@ -639,7 +657,7 @@ int ctf_open_file_stream_read(struct ctf_trace *td, const char *path, int flags)
        if (ret)
                goto error_index;
        /* Add stream file to stream class */
-       g_ptr_array_add(file_stream->stream->files, file_stream);
+       g_ptr_array_add(file_stream->stream.stream_class->files, file_stream);
        return 0;
 
 error_index:
index de1a70d101b921975a5f10fb23b183ff9e558adb..903d018dd9cb7c6811fcb9ce42712a29864c88f3 100644 (file)
 
 struct ctf_trace;
 struct ctf_stream_class;
+struct ctf_stream;
 struct ctf_event;
 
+struct ctf_stream {
+       struct ctf_stream_class *stream_class;
+       uint64_t timestamp;                     /* Current timestamp, in ns */
+};
+
 struct ctf_file_stream {
        uint64_t stream_id;
-       struct ctf_stream_class *stream;
+       struct ctf_stream stream;
        struct ctf_stream_pos pos;      /* current stream position */
 };
 
index fa543bf2ddaed57323aea6d4331ce2ce7586e477..b7e84da2ee22cf6bc488c27d76af2acf4ea76eab 100644 (file)
@@ -31,7 +31,7 @@
 /* Preallocate this many fields for structures */
 #define DEFAULT_NR_STRUCT_FIELDS 8
 
-struct ctf_stream_class;
+struct ctf_stream;
 struct stream_pos;
 struct format;
 struct definition;
@@ -114,7 +114,7 @@ struct stream_pos {
        /* read/write dispatch table. Specific to plugin used for stream. */
        rw_dispatch *rw_table;  /* rw dispatch table */
        int (*event_cb)(struct stream_pos *pos,
-                       struct ctf_stream_class *stream_class);
+                       struct ctf_stream *stream);
 };
 
 static inline
This page took 0.039914 seconds and 4 git commands to generate.