From 75cc2c3593a5cec870fb530ed4712b5c13d9f0db Mon Sep 17 00:00:00 2001 From: Mathieu Desnoyers Date: Mon, 23 May 2011 19:43:34 -0400 Subject: [PATCH] Keep packet header and context current Signed-off-by: Mathieu Desnoyers --- formats/ctf/ctf.c | 45 +++++++++++++++++++++++++++++++++- include/babeltrace/ctf/types.h | 2 ++ 2 files changed, 46 insertions(+), 1 deletion(-) diff --git a/formats/ctf/ctf.c b/formats/ctf/ctf.c index a85a5f36..2048d6a0 100644 --- a/formats/ctf/ctf.c +++ b/formats/ctf/ctf.c @@ -340,6 +340,8 @@ void ctf_fini_pos(struct ctf_stream_pos *pos) void ctf_move_pos_slow(struct ctf_stream_pos *pos, size_t offset, int whence) { + struct ctf_file_stream *file_stream = + container_of(pos, struct ctf_file_stream, pos); int ret; off_t off; struct packet_index *index; @@ -405,10 +407,11 @@ void ctf_move_pos_slow(struct ctf_stream_pos *pos, size_t offset, int whence) pos->mmap_offset = index->offset; /* Lookup context/packet size in index */ + file_stream->stream.timestamp = index->timestamp_begin; pos->content_size = index->content_size; pos->packet_size = index->packet_size; if (index->data_offset < index->content_size) - pos->offset = index->data_offset; + pos->offset = 0; /* will read headers */ else { pos->offset = EOF; return; @@ -422,6 +425,18 @@ void ctf_move_pos_slow(struct ctf_stream_pos *pos, size_t offset, int whence) strerror(errno)); assert(0); } + + /* update trace_packet_header and stream_packet_context */ + if (file_stream->stream.trace_packet_header) { + /* Read packet header */ + ret = generic_rw(&pos->parent, &file_stream->stream.trace_packet_header->p); + assert(!ret); + } + if (file_stream->stream.stream_packet_context) { + /* Read packet context */ + ret = generic_rw(&pos->parent, &file_stream->stream.stream_packet_context->p); + assert(!ret); + } } static @@ -792,6 +807,8 @@ int create_stream_packet_index(struct ctf_trace *td, packet_index.offset = pos->mmap_offset; packet_index.content_size = 0; packet_index.packet_size = 0; + packet_index.timestamp_begin = 0; + packet_index.timestamp_end = 0; /* read and check header, set stream id (and check) */ if (file_stream->stream.trace_packet_header) { @@ -920,6 +937,32 @@ int create_stream_packet_index(struct ctf_trace *td, /* Use content size if non-zero, else file size */ packet_index.packet_size = packet_index.content_size ? : filestats.st_size * CHAR_BIT; } + + /* read timestamp begin from header */ + len_index = struct_declaration_lookup_field_index(file_stream->stream.stream_packet_context->declaration, g_quark_from_static_string("timestamp_begin")); + if (len_index >= 0) { + struct definition_integer *defint; + struct definition *field; + + field = struct_definition_get_field_from_index(file_stream->stream.stream_packet_context, len_index); + assert(field->declaration->id == CTF_TYPE_INTEGER); + defint = container_of(field, struct definition_integer, p); + assert(defint->declaration->signedness == FALSE); + packet_index.timestamp_begin = defint->value._unsigned; + } + + /* read timestamp end from header */ + len_index = struct_declaration_lookup_field_index(file_stream->stream.stream_packet_context->declaration, g_quark_from_static_string("timestamp_end")); + if (len_index >= 0) { + struct definition_integer *defint; + struct definition *field; + + field = struct_definition_get_field_from_index(file_stream->stream.stream_packet_context, len_index); + assert(field->declaration->id == CTF_TYPE_INTEGER); + defint = container_of(field, struct definition_integer, p); + assert(defint->declaration->signedness == FALSE); + packet_index.timestamp_end = defint->value._unsigned; + } } else { /* Use file size for packet size */ packet_index.content_size = filestats.st_size * CHAR_BIT; diff --git a/include/babeltrace/ctf/types.h b/include/babeltrace/ctf/types.h index 14da1d91..c5912714 100644 --- a/include/babeltrace/ctf/types.h +++ b/include/babeltrace/ctf/types.h @@ -36,6 +36,8 @@ struct packet_index { off_t data_offset; /* offset of data within the packet, in bits */ size_t packet_size; /* packet size, in bits */ size_t content_size; /* content size, in bits */ + uint64_t timestamp_begin; + uint64_t timestamp_end; }; /* -- 2.34.1