struct ctf_stream_pos *pos =
container_of(ppos, struct ctf_stream_pos, parent);
struct ctf_stream_class *stream_class = stream->stream_class;
- struct ctf_file_event *event;
+ struct ctf_stream_event *event;
uint64_t id = 0;
int ret;
int ctf_write_event(struct stream_pos *pos, struct ctf_stream *stream)
{
struct ctf_stream_class *stream_class = stream->stream_class;
- struct ctf_file_event *event;
+ struct ctf_stream_event *event;
uint64_t id = 0;
int ret;
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;
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;
strerror(errno));
assert(0);
}
+
+ /* update trace_packet_header and stream_packet_context */
+ if (pos->prot != PROT_WRITE && file_stream->stream.trace_packet_header) {
+ /* Read packet header */
+ ret = generic_rw(&pos->parent, &file_stream->stream.trace_packet_header->p);
+ assert(!ret);
+ }
+ if (pos->prot != PROT_WRITE && file_stream->stream.stream_packet_context) {
+ /* Read packet context */
+ ret = generic_rw(&pos->parent, &file_stream->stream.stream_packet_context->p);
+ assert(!ret);
+ }
}
static
return -EINVAL;
}
- toread = header.content_size / CHAR_BIT;
+ toread = (header.content_size / CHAR_BIT) - header_sizeof(header);
for (;;) {
readlen = fread(buf, sizeof(char), min(sizeof(buf), toread), in);
}
static
-struct ctf_file_event *create_event_definitions(struct ctf_trace *td,
- struct ctf_stream *stream,
- struct ctf_event *event)
+struct ctf_stream_event *create_event_definitions(struct ctf_trace *td,
+ struct ctf_stream *stream,
+ struct ctf_event *event)
{
- struct ctf_file_event *file_event = g_new0(struct ctf_file_event, 1);
+ struct ctf_stream_event *stream_event = g_new0(struct ctf_stream_event, 1);
if (event->context_decl) {
struct definition *definition =
if (!definition) {
goto error;
}
- file_event->event_context = container_of(definition,
+ stream_event->event_context = container_of(definition,
struct definition_struct, p);
- stream->parent_def_scope = file_event->event_context->p.scope;
+ stream->parent_def_scope = stream_event->event_context->p.scope;
}
if (event->fields_decl) {
struct definition *definition =
if (!definition) {
goto error;
}
- file_event->event_fields = container_of(definition,
+ stream_event->event_fields = container_of(definition,
struct definition_struct, p);
- stream->parent_def_scope = file_event->event_fields->p.scope;
+ stream->parent_def_scope = stream_event->event_fields->p.scope;
}
- return file_event;
+ return stream_event;
error:
- if (file_event->event_fields)
- definition_unref(&file_event->event_fields->p);
- if (file_event->event_context)
- definition_unref(&file_event->event_context->p);
+ if (stream_event->event_fields)
+ definition_unref(&stream_event->event_fields->p);
+ if (stream_event->event_context)
+ definition_unref(&stream_event->event_context->p);
return NULL;
}
g_ptr_array_set_size(stream->events_by_id, stream_class->events_by_id->len);
for (i = 0; i < stream->events_by_id->len; i++) {
struct ctf_event *event = g_ptr_array_index(stream_class->events_by_id, i);
- struct ctf_file_event *file_event;
+ struct ctf_stream_event *stream_event;
if (!event)
continue;
- file_event = create_event_definitions(td, stream, event);
- if (!file_event)
+ stream_event = create_event_definitions(td, stream, event);
+ if (!stream_event)
goto error_event;
- g_ptr_array_index(stream->events_by_id, i) = file_event;
+ g_ptr_array_index(stream->events_by_id, i) = stream_event;
}
return 0;
error_event:
for (i = 0; i < stream->events_by_id->len; i++) {
- struct ctf_file_event *file_event = g_ptr_array_index(stream->events_by_id, i);
- if (file_event)
- g_free(file_event);
+ struct ctf_stream_event *stream_event = g_ptr_array_index(stream->events_by_id, i);
+ if (stream_event)
+ g_free(stream_event);
}
g_ptr_array_free(stream->events_by_id, TRUE);
error:
if (ret < 0)
return ret;
+ if (filestats.st_size < MAX_PACKET_HEADER_LEN / CHAR_BIT)
+ return -EINVAL;
+
for (pos->mmap_offset = 0; pos->mmap_offset < filestats.st_size; ) {
uint64_t stream_id = 0;
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) {
/* 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;