X-Git-Url: http://git.efficios.com/?p=babeltrace.git;a=blobdiff_plain;f=formats%2Fctf%2Fctf.c;h=5e43d2fa867cce377f14cf9869929ef20afd79bd;hp=41aa35d60fd6a67e23b128a60a258ed03215bab2;hb=e9378815b6be9213062f4097247bade3642ad479;hpb=4152822bf555f86a1dce28cb6755ff0849c3a75a diff --git a/formats/ctf/ctf.c b/formats/ctf/ctf.c index 41aa35d6..5e43d2fa 100644 --- a/formats/ctf/ctf.c +++ b/formats/ctf/ctf.c @@ -52,7 +52,9 @@ extern int yydebug; +static struct trace_descriptor *ctf_open_trace(const char *path, int flags); +static void ctf_close_trace(struct trace_descriptor *descriptor); static @@ -101,6 +103,7 @@ int ctf_read_event(struct stream_pos *ppos, struct ctf_stream *stream) /* Read event header */ if (stream_class->event_header) { struct definition_integer *integer_definition; + struct definition *variant; ret = generic_rw(ppos, &stream_class->event_header->p); if (ret) @@ -118,20 +121,21 @@ int ctf_read_event(struct stream_pos *ppos, struct ctf_stream *stream) } } + variant = lookup_variant(&stream_class->event_header->p, "v"); + if (variant) { + integer_definition = lookup_integer(variant, "id", FALSE); + if (integer_definition) { + id = integer_definition->value._unsigned; + } + } + /* lookup timestamp */ integer_definition = lookup_integer(&stream_class->event_header->p, "timestamp", FALSE); if (integer_definition) { stream->timestamp = integer_definition->value._unsigned; } else { - struct definition *definition; - - definition = lookup_variant(&stream_class->event_header->p, "v"); - if (definition) { - integer_definition = lookup_integer(definition, "id", FALSE); - if (integer_definition) { - id = integer_definition->value._unsigned; - } - integer_definition = lookup_integer(definition, "timestamp", FALSE); + if (variant) { + integer_definition = lookup_integer(variant, "timestamp", FALSE); if (integer_definition) { stream->timestamp = integer_definition->value._unsigned; } @@ -183,23 +187,32 @@ 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; int ret; /* print event header */ if (stream_class->event_header) { + struct definition_integer *integer_definition; + struct definition *variant; + /* lookup event id */ - len_index = struct_declaration_lookup_field_index(stream_class->event_header_decl, - g_quark_from_static_string("id")); - 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); - id = defint->value._unsigned; /* set id */ + integer_definition = lookup_integer(&stream_class->event_header->p, "id", FALSE); + if (integer_definition) { + id = integer_definition->value._unsigned; + } else { + struct definition_enum *enum_definition; + + enum_definition = lookup_enum(&stream_class->event_header->p, "id", FALSE); + if (enum_definition) { + id = enum_definition->integer->value._unsigned; + } + } + + variant = lookup_variant(&stream_class->event_header->p, "v"); + if (variant) { + integer_definition = lookup_integer(variant, "id", FALSE); + if (integer_definition) { + id = integer_definition->value._unsigned; + } } ret = generic_rw(pos, &stream_class->event_header->p); @@ -489,6 +502,11 @@ int ctf_open_trace_metadata_stream_read(struct ctf_trace *td, FILE **fp, int ret; in = *fp; + /* + * Using strlen on *buf instead of size of open_memstream + * because its size includes garbage at the end (after final + * \0). This is the allocated size, not the actual string size. + */ out = open_memstream(buf, &size); if (out == NULL) return -errno; @@ -506,7 +524,7 @@ int ctf_open_trace_metadata_stream_read(struct ctf_trace *td, FILE **fp, fclose(out); /* flush the buffer */ fclose(in); /* open for reading */ - *fp = fmemopen(*buf, size, "rb"); + *fp = fmemopen(*buf, strlen(*buf), "rb"); return 0; } @@ -891,6 +909,7 @@ error: return ret; } +static struct trace_descriptor *ctf_open_trace(const char *path, int flags) { struct ctf_trace *td; @@ -929,6 +948,7 @@ void ctf_close_file_stream(struct ctf_file_stream *file_stream) close(file_stream->pos.fd); } +static void ctf_close_trace(struct trace_descriptor *tdp) { struct ctf_trace *td = container_of(tdp, struct ctf_trace, parent); @@ -938,7 +958,10 @@ void ctf_close_trace(struct trace_descriptor *tdp) for (i = 0; i < td->streams->len; i++) { struct ctf_stream_class *stream; int j; + stream = g_ptr_array_index(td->streams, i); + if (!stream) + continue; for (j = 0; j < stream->files->len; j++) { struct ctf_file_stream *file_stream; file_stream = g_ptr_array_index(stream->files, j);