return 0;
}
+void ctf_update_current_packet_index(struct ctf_stream_definition *stream,
+ struct packet_index *prev_index,
+ struct packet_index *cur_index)
+{
+ uint64_t events_discarded_diff;
+
+ /* Update packet index time information */
+ stream->prev_cycles_timestamp_end =
+ cur_index->ts_cycles.timestamp_end;
+ stream->prev_cycles_timestamp =
+ cur_index->ts_cycles.timestamp_begin;
+ stream->prev_real_timestamp_end =
+ cur_index->ts_real.timestamp_end;
+ stream->prev_real_timestamp =
+ cur_index->ts_real.timestamp_begin;
+
+ stream->prev_real_timestamp =
+ stream->real_timestamp;
+ stream->prev_cycles_timestamp =
+ stream->cycles_timestamp;
+
+ /* Update packet index discarded event information */
+ events_discarded_diff = cur_index->events_discarded;
+ if (prev_index) {
+ events_discarded_diff -= prev_index->events_discarded;
+ /*
+ * Deal with 32-bit wrap-around if the tracer provided a
+ * 32-bit field.
+ */
+ if (prev_index->events_discarded_len == 32) {
+ events_discarded_diff = (uint32_t) events_discarded_diff;
+ }
+ }
+ stream->events_discarded = events_discarded_diff;
+}
+
/*
* for SEEK_CUR: go to next packet.
* for SEEK_SET: go to packet numer (index).
switch (whence) {
case SEEK_CUR:
{
- uint64_t events_discarded_diff;
+ struct packet_index *prev_index = NULL;
if (pos->offset == EOF) {
return;
}
assert(pos->cur_index < pos->packet_index->len);
-
- /* For printing discarded event count */
packet_index = &g_array_index(pos->packet_index,
struct packet_index, pos->cur_index);
- file_stream->parent.prev_cycles_timestamp_end =
- packet_index->ts_cycles.timestamp_end;
- file_stream->parent.prev_cycles_timestamp =
- packet_index->ts_cycles.timestamp_begin;
- file_stream->parent.prev_real_timestamp_end =
- packet_index->ts_real.timestamp_end;
- file_stream->parent.prev_real_timestamp =
- packet_index->ts_real.timestamp_begin;
-
- events_discarded_diff = packet_index->events_discarded;
if (pos->cur_index > 0) {
- packet_index = &g_array_index(pos->packet_index,
+ prev_index = &g_array_index(pos->packet_index,
struct packet_index,
pos->cur_index - 1);
- events_discarded_diff -= packet_index->events_discarded;
- /*
- * Deal with 32-bit wrap-around if the
- * tracer provided a 32-bit field.
- */
- if (packet_index->events_discarded_len == 32) {
- events_discarded_diff = (uint32_t) events_discarded_diff;
- }
}
- file_stream->parent.events_discarded = events_discarded_diff;
- file_stream->parent.prev_real_timestamp = file_stream->parent.real_timestamp;
- file_stream->parent.prev_cycles_timestamp = file_stream->parent.cycles_timestamp;
+ ctf_update_current_packet_index(&file_stream->parent,
+ prev_index, packet_index);
+
/* The reader will expect us to skip padding */
++pos->cur_index;
break;
static
int ctf_open_trace_metadata_read(struct ctf_trace *td,
void (*packet_seek)(struct bt_stream_pos *pos, size_t index,
- int whence), FILE *metadata_fp)
+ int whence), FILE *metadata_fp,
+ struct ctf_scanner *scanner)
{
- struct ctf_scanner *scanner;
struct ctf_file_stream *metadata_stream;
FILE *fp;
char *buf = NULL;
if (ret) {
/* Warn about empty metadata */
fprintf(stderr, "[warning] Empty metadata.\n");
- goto end_packet_read;
+ goto end;
}
td->metadata_string = buf;
td->metadata_packetized = 1;
td->byte_order = BYTE_ORDER;
/* Check text-only metadata header and version */
- nr_items = fscanf(fp, "/* CTF %u.%u", &major, &minor);
+ nr_items = fscanf(fp, "/* CTF %10u.%10u", &major, &minor);
if (nr_items < 2)
fprintf(stderr, "[warning] Ill-shapen or missing \"/* CTF x.y\" header for text-only metadata.\n");
if (check_version(major, minor) < 0) {
ret = -EINVAL;
- goto end_packet_read;
+ goto end;
}
rewind(fp);
}
- scanner = ctf_scanner_alloc(fp);
- if (!scanner) {
- fprintf(stderr, "[error] Error allocating scanner\n");
- ret = -ENOMEM;
- goto end_scanner_alloc;
- }
- ret = ctf_scanner_append_ast(scanner);
+ ret = ctf_scanner_append_ast(scanner, fp);
if (ret) {
fprintf(stderr, "[error] Error creating AST\n");
goto end;
goto end;
}
end:
- ctf_scanner_free(scanner);
-end_scanner_alloc:
-end_packet_read:
if (fp) {
closeret = fclose(fp);
if (closeret) {
int import_stream_packet_index(struct ctf_trace *td,
struct ctf_file_stream *file_stream)
{
- struct ctf_stream_declaration *stream;
struct ctf_stream_pos *pos;
struct ctf_packet_index ctf_index;
struct ctf_packet_index_file_hdr index_hdr;
while (fread(&ctf_index, index_hdr.packet_index_len, 1,
pos->index_fp) == 1) {
uint64_t stream_id;
+ struct ctf_stream_declaration *stream = NULL;
memset(&index, 0, sizeof(index));
index.offset = be64toh(ctf_index.offset);
}
file_stream->parent.stream_id = stream_id;
- stream = g_ptr_array_index(td->streams, stream_id);
+ if (stream_id < td->streams->len) {
+ stream = g_ptr_array_index(td->streams, stream_id);
+ }
if (!stream) {
fprintf(stderr, "[error] Stream %" PRIu64
" is not declared in metadata.\n",
void (*packet_seek)(struct bt_stream_pos *pos, size_t index,
int whence), FILE *metadata_fp)
{
+ struct ctf_scanner *scanner;
int ret, closeret;
struct dirent *dirent;
struct dirent *diriter;
/*
* Keep the metadata file separate.
*/
-
- ret = ctf_open_trace_metadata_read(td, packet_seek, metadata_fp);
+ scanner = ctf_scanner_alloc();
+ if (!scanner) {
+ fprintf(stderr, "[error] Error allocating scanner\n");
+ ret = -ENOMEM;
+ goto error_metadata;
+ }
+ ret = ctf_open_trace_metadata_read(td, packet_seek, metadata_fp,
+ scanner);
+ ctf_scanner_free(scanner);
if (ret) {
fprintf(stderr, "[warning] Unable to open trace metadata for path \"%s\".\n", path);
goto error_metadata;
pos->offset = 0;
pos->dummy = false;
pos->cur_index = 0;
- pos->packet_index = NULL;
pos->prot = PROT_READ;
pos->flags = MAP_PRIVATE;
pos->parent.rw_table = read_dispatch_table;
pos->parent.event_cb = ctf_read_event;
pos->priv = mmap_info->priv;
+ pos->packet_index = g_array_new(FALSE, TRUE,
+ sizeof(struct packet_index));
}
static
{
int ret;
struct bt_mmap_stream *mmap_info;
+ struct ctf_scanner *scanner;
- ret = ctf_open_trace_metadata_read(td, ctf_packet_seek, metadata_fp);
+ scanner = ctf_scanner_alloc();
+ if (!scanner) {
+ fprintf(stderr, "[error] Error allocating scanner\n");
+ ret = -ENOMEM;
+ goto error_scanner_alloc;
+ }
+ ret = ctf_open_trace_metadata_read(td, ctf_packet_seek, metadata_fp,
+ scanner);
if (ret) {
goto error;
}
goto error;
}
}
-
+ ctf_scanner_free(scanner);
return 0;
error:
+ ctf_scanner_free(scanner);
+error_scanner_alloc:
return ret;
}
goto error;
}
td = g_new0(struct ctf_trace, 1);
+ td->dirfd = -1;
ret = ctf_open_mmap_trace_read(td, mmap_list, packet_seek, metadata_fp);
if (ret)
goto error_free;