From aa6bffaea450106c60fc1292152bd94a270fd243 Mon Sep 17 00:00:00 2001 From: Mathieu Desnoyers Date: Mon, 9 May 2011 11:28:56 -0400 Subject: [PATCH 1/1] move struct ctf_stream -> struct ctf_stream_class Signed-off-by: Mathieu Desnoyers --- converter/babeltrace-lib.c | 2 +- formats/ctf-text/ctf-text.c | 42 ++++++++++++------- formats/ctf/ctf.c | 8 ++-- .../metadata/ctf-visitor-generate-io-struct.c | 8 ++-- include/babeltrace/ctf/metadata.h | 12 +++--- include/babeltrace/types.h | 4 +- 6 files changed, 44 insertions(+), 32 deletions(-) diff --git a/converter/babeltrace-lib.c b/converter/babeltrace-lib.c index 8f29c5a8..cc3d8d3b 100644 --- a/converter/babeltrace-lib.c +++ b/converter/babeltrace-lib.c @@ -66,7 +66,7 @@ int convert_trace(struct trace_descriptor *td_write, /* For each stream (TODO: order events by timestamp) */ for (stream_id = 0; stream_id < tin->streams->len; stream_id++) { - struct ctf_stream *stream = g_ptr_array_index(tin->streams, stream_id); + struct ctf_stream_class *stream = g_ptr_array_index(tin->streams, stream_id); if (!stream) continue; diff --git a/formats/ctf-text/ctf-text.c b/formats/ctf-text/ctf-text.c index 423cb10f..2ec71c56 100644 --- a/formats/ctf-text/ctf-text.c +++ b/formats/ctf-text/ctf-text.c @@ -55,7 +55,7 @@ struct format ctf_text_format = { static int ctf_text_write_event(struct stream_pos *ppos, - struct ctf_stream *stream_class) + struct ctf_stream_class *stream_class) { struct ctf_text_stream_pos *pos = container_of(ppos, struct ctf_text_stream_pos, parent); @@ -63,6 +63,7 @@ int ctf_text_write_event(struct stream_pos *ppos, uint64_t id = 0; int len_index; int ret; + int field_nr = 0; /* print event header */ if (stream_class->event_header) { @@ -91,16 +92,27 @@ int ctf_text_write_event(struct stream_pos *ppos, return -EINVAL; } + if (field_nr++ != 0) + fprintf(pos->fp, ", "); + if (pos->print_names) + fprintf(pos->fp, "timestamp = "); + else + fprintf(pos->fp, "["); + fprintf(pos->fp, "%" PRIu64, (uint64_t) 0); /* TODO */ + if (!pos->print_names) + fprintf(pos->fp, "]"); + + if (field_nr++ != 0) + fprintf(pos->fp, ", "); if (pos->print_names) fprintf(pos->fp, "name = "); - fprintf(pos->fp, "%s", g_quark_to_string(event_class->name)); + fprintf(pos->fp, "%s: ", g_quark_to_string(event_class->name)); if (stream_class->event_header) { + if (field_nr++ != 0) + fprintf(pos->fp, ", "); if (pos->print_names) - fprintf(pos->fp, ", stream.event.header ="); - else - fprintf(pos->fp, ","); - fprintf(pos->fp, " "); + fprintf(pos->fp, "stream.event.header = "); ret = generic_rw(ppos, &stream_class->event_header->p); if (ret) goto error; @@ -108,10 +120,10 @@ int ctf_text_write_event(struct stream_pos *ppos, /* print stream-declared event context */ if (stream_class->event_context) { + if (field_nr++ != 0) + fprintf(pos->fp, ", "); if (pos->print_names) - fprintf(pos->fp, ", stream.event.context ="); - else - fprintf(pos->fp, ","); + fprintf(pos->fp, "stream.event.context = "); fprintf(pos->fp, " "); ret = generic_rw(ppos, &stream_class->event_context->p); if (ret) @@ -120,10 +132,10 @@ int ctf_text_write_event(struct stream_pos *ppos, /* print event-declared event context */ if (event_class->context) { + if (field_nr++ != 0) + fprintf(pos->fp, ", "); if (pos->print_names) - fprintf(pos->fp, ", event.context ="); - else - fprintf(pos->fp, ","); + fprintf(pos->fp, "event.context = "); fprintf(pos->fp, " "); ret = generic_rw(ppos, &event_class->context->p); if (ret) @@ -132,10 +144,10 @@ int ctf_text_write_event(struct stream_pos *ppos, /* Read and print event payload */ if (event_class->fields) { + if (field_nr++ != 0) + fprintf(pos->fp, ", "); if (pos->print_names) - fprintf(pos->fp, ", event.fields ="); - else - fprintf(pos->fp, ","); + fprintf(pos->fp, "event.fields = "); fprintf(pos->fp, " "); ret = generic_rw(ppos, &event_class->fields->p); if (ret) diff --git a/formats/ctf/ctf.c b/formats/ctf/ctf.c index 50cc93de..441d2bb4 100644 --- a/formats/ctf/ctf.c +++ b/formats/ctf/ctf.c @@ -80,7 +80,7 @@ struct format ctf_format = { }; static -int ctf_read_event(struct stream_pos *ppos, struct ctf_stream *stream_class) +int ctf_read_event(struct stream_pos *ppos, struct ctf_stream_class *stream_class) { struct ctf_stream_pos *pos = container_of(ppos, struct ctf_stream_pos, parent); @@ -151,7 +151,7 @@ error: } static -int ctf_write_event(struct stream_pos *pos, struct ctf_stream *stream_class) +int ctf_write_event(struct stream_pos *pos, struct ctf_stream_class *stream_class) { struct ctf_event *event_class; uint64_t id = 0; @@ -424,7 +424,7 @@ static int create_stream_packet_index(struct ctf_trace *td, struct ctf_file_stream *file_stream) { - struct ctf_stream *stream; + struct ctf_stream_class *stream; int len_index; struct ctf_stream_pos *pos; struct stat filestats; @@ -776,7 +776,7 @@ void ctf_close_trace(struct trace_descriptor *tdp) if (td->streams) { for (i = 0; i < td->streams->len; i++) { - struct ctf_stream *stream; + struct ctf_stream_class *stream; int j; stream = g_ptr_array_index(td->streams, i); for (j = 0; j < stream->files->len; j++) { diff --git a/formats/ctf/metadata/ctf-visitor-generate-io-struct.c b/formats/ctf/metadata/ctf-visitor-generate-io-struct.c index 033537e6..9da7d0d8 100644 --- a/formats/ctf/metadata/ctf-visitor-generate-io-struct.c +++ b/formats/ctf/metadata/ctf-visitor-generate-io-struct.c @@ -125,7 +125,7 @@ int get_unary_uuid(struct cds_list_head *head, uuid_t *uuid) } static -struct ctf_stream *trace_stream_lookup(struct ctf_trace *trace, uint64_t stream_id) +struct ctf_stream_class *trace_stream_lookup(struct ctf_trace *trace, uint64_t stream_id) { if (trace->streams->len <= stream_id) return NULL; @@ -1515,7 +1515,7 @@ error: static -int ctf_stream_declaration_visit(FILE *fd, int depth, struct ctf_node *node, struct ctf_stream *stream, struct ctf_trace *trace) +int ctf_stream_declaration_visit(FILE *fd, int depth, struct ctf_node *node, struct ctf_stream_class *stream, struct ctf_trace *trace) { int ret = 0; @@ -1637,10 +1637,10 @@ int ctf_stream_visit(FILE *fd, int depth, struct ctf_node *node, { int ret = 0; struct ctf_node *iter; - struct ctf_stream *stream; + struct ctf_stream_class *stream; struct definition_scope *parent_def_scope; - stream = g_new0(struct ctf_stream, 1); + stream = g_new0(struct ctf_stream_class, 1); stream->declaration_scope = new_declaration_scope(parent_declaration_scope); stream->events_by_id = g_ptr_array_new(); stream->event_quark_to_id = g_hash_table_new(g_direct_hash, g_direct_equal); diff --git a/include/babeltrace/ctf/metadata.h b/include/babeltrace/ctf/metadata.h index 5e7fd30e..de1a70d1 100644 --- a/include/babeltrace/ctf/metadata.h +++ b/include/babeltrace/ctf/metadata.h @@ -31,13 +31,13 @@ #define CTF_MAGIC 0xC1FC1FC1 struct ctf_trace; -struct ctf_stream; +struct ctf_stream_class; struct ctf_event; struct ctf_file_stream { uint64_t stream_id; - struct ctf_stream *stream; - struct ctf_stream_pos pos; /* current stream position */ + struct ctf_stream_class *stream; + struct ctf_stream_pos pos; /* current stream position */ }; #define CTF_TRACE_SET_FIELD(ctf_trace, field) \ @@ -63,7 +63,7 @@ struct ctf_trace { struct declaration_scope *declaration_scope; /* innermost definition scope. to be used as parent of stream. */ struct definition_scope *definition_scope; - GPtrArray *streams; /* Array of struct ctf_stream pointers */ + GPtrArray *streams; /* Array of struct ctf_stream_class pointers */ struct ctf_file_stream metadata; /* Declarations only used when parsing */ @@ -105,7 +105,7 @@ struct ctf_trace { (ctf_stream)->(field); \ }) -struct ctf_stream { +struct ctf_stream_class { struct ctf_trace *trace; /* parent is lexical scope conaining the stream scope */ struct declaration_scope *declaration_scope; @@ -149,7 +149,7 @@ struct ctf_stream { struct ctf_event { /* stream mapped by stream_id */ - struct ctf_stream *stream; + struct ctf_stream_class *stream; /* parent is lexical scope conaining the event scope */ struct declaration_scope *declaration_scope; diff --git a/include/babeltrace/types.h b/include/babeltrace/types.h index 6bfd703d..fa543bf2 100644 --- a/include/babeltrace/types.h +++ b/include/babeltrace/types.h @@ -31,7 +31,7 @@ /* Preallocate this many fields for structures */ #define DEFAULT_NR_STRUCT_FIELDS 8 -struct ctf_stream; +struct ctf_stream_class; 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 *stream_class); + struct ctf_stream_class *stream_class); }; static inline -- 2.34.1