struct ctf_stream_declaration *stream_class;
stream_class = g_ptr_array_index(tin->streams, i);
+ if (!stream_class)
+ continue;
/* for each file_stream */
for (j = 0; j < stream_class->streams->len; j++) {
struct ctf_stream_definition *stream;
struct ctf_stream_declaration *stream_class;
stream_class = g_ptr_array_index(tin->streams, i);
+ if (!stream_class)
+ continue;
/* for each file_stream */
for (j = 0; j < stream_class->streams->len; j++) {
struct ctf_stream_definition *stream;
/* save the current position as a restore point */
pos->last_offset = pos->offset;
- /* we just read the event, it is consumed when used by the caller */
- stream->consumed = 0;
/*
* This is the EOF check after we've advanced the position in
pos->packet_size = 0;
pos->content_size = 0;
pos->content_size_loc = NULL;
- pos->base = NULL;
+ pos->base_mma = NULL;
pos->offset = 0;
pos->dummy = false;
pos->cur_index = 0;
if (pos->prot == PROT_WRITE && pos->content_size_loc)
*pos->content_size_loc = pos->offset;
- if (pos->base) {
+ if (pos->base_mma) {
/* unmap old base */
- ret = munmap(pos->base, pos->packet_size / CHAR_BIT);
+ ret = munmap_align(pos->base_mma);
if (ret) {
fprintf(stderr, "[error] Unable to unmap old base: %s.\n",
strerror(errno));
if (pos->prot == PROT_WRITE && pos->content_size_loc)
*pos->content_size_loc = pos->offset;
- if (pos->base) {
+ if (pos->base_mma) {
/* unmap old base */
- ret = munmap(pos->base, pos->packet_size / CHAR_BIT);
+ ret = munmap_align(pos->base_mma);
if (ret) {
fprintf(stderr, "[error] Unable to unmap old base: %s.\n",
strerror(errno));
assert(0);
}
- pos->base = NULL;
+ pos->base_mma = NULL;
}
/*
switch (whence) {
case SEEK_CUR:
{
- uint32_t events_discarded_diff;
+ uint64_t events_discarded_diff;
if (pos->offset == EOF) {
return;
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_timestamp = file_stream->parent.timestamp;
*/
if ((&file_stream->parent)->stream_class->trace->collection) {
fflush(stdout);
- fprintf(stderr, "[warning] Tracer discarded %d events at end of stream between [",
+ fprintf(stderr, "[warning] Tracer discarded %" PRIu64 " events at end of stream between [",
file_stream->parent.events_discarded);
ctf_print_timestamp(stderr, &file_stream->parent,
file_stream->parent.prev_timestamp);
fprintf(stderr, "] and [");
ctf_print_timestamp(stderr, &file_stream->parent,
file_stream->parent.prev_timestamp_end);
- fprintf(stderr, "]. You should consider increasing the buffer size.\n");
+ fprintf(stderr, "]. You should consider recording a new trace with larger buffers or with fewer events enabled.\n");
fflush(stderr);
}
file_stream->parent.events_discarded = 0;
}
}
/* map new base. Need mapping length from header. */
- pos->base = mmap(NULL, pos->packet_size / CHAR_BIT, pos->prot,
- pos->flags, pos->fd, pos->mmap_offset);
- if (pos->base == MAP_FAILED) {
+ pos->base_mma = mmap_align(pos->packet_size / CHAR_BIT, pos->prot,
+ pos->flags, pos->fd, pos->mmap_offset);
+ if (pos->base_mma == MAP_FAILED) {
fprintf(stderr, "[error] mmap error %s.\n",
strerror(errno));
assert(0);
int ret = 0;
metadata_stream = g_new0(struct ctf_file_stream, 1);
+ metadata_stream->pos.last_offset = LAST_OFFSET_POISON;
if (packet_seek) {
metadata_stream->pos.packet_seek = packet_seek;
ctf_scanner_free(scanner);
end_scanner_alloc:
end_packet_read:
- fclose(fp);
+ if (fp)
+ fclose(fp);
free(buf);
end_stream:
close(metadata_stream->pos.fd);
for (pos->mmap_offset = 0; pos->mmap_offset < filestats.st_size; ) {
uint64_t stream_id = 0;
- if (pos->base) {
+ if (pos->base_mma) {
/* unmap old base */
- ret = munmap(pos->base, pos->packet_size / CHAR_BIT);
+ ret = munmap_align(pos->base_mma);
if (ret) {
fprintf(stderr, "[error] Unable to unmap old base: %s.\n",
strerror(errno));
return ret;
}
- pos->base = NULL;
+ pos->base_mma = NULL;
}
/* map new base. Need mapping length from header. */
- pos->base = mmap(NULL, MAX_PACKET_HEADER_LEN / CHAR_BIT, PROT_READ,
+ pos->base_mma = mmap_align(MAX_PACKET_HEADER_LEN / CHAR_BIT, PROT_READ,
MAP_PRIVATE, pos->fd, pos->mmap_offset);
+ assert(pos->base_mma != MAP_FAILED);
pos->content_size = MAX_PACKET_HEADER_LEN; /* Unknown at this point */
pos->packet_size = MAX_PACKET_HEADER_LEN; /* Unknown at this point */
pos->offset = 0; /* Position of the packet header */
field = struct_definition_get_field_from_index(file_stream->parent.stream_packet_context, len_index);
packet_index.events_discarded = get_unsigned_int(field);
+ packet_index.events_discarded_len = get_int_len(field);
}
} else {
/* Use file size for packet size */
if (packet_index.packet_size > ((uint64_t)filestats.st_size - packet_index.offset) * CHAR_BIT) {
fprintf(stderr, "[error] Packet size (%" PRIu64 " bits) is larger than remaining file size (%" PRIu64 " bits).\n",
- packet_index.content_size, ((uint64_t)filestats.st_size - packet_index.offset) * CHAR_BIT);
+ packet_index.packet_size, ((uint64_t)filestats.st_size - packet_index.offset) * CHAR_BIT);
return -EINVAL;
}
void (*packet_seek)(struct stream_pos *pos, size_t index,
int whence))
{
- int ret;
+ int ret, fd;
struct ctf_file_stream *file_stream;
+ struct stat statbuf;
- ret = openat(td->dirfd, path, flags);
- if (ret < 0) {
+ fd = openat(td->dirfd, path, flags);
+ if (fd < 0) {
perror("File stream openat()");
+ ret = fd;
goto error;
}
+
+ /* Don't try to mmap subdirectories. Skip them, return success. */
+ ret = fstat(fd, &statbuf);
+ if (ret) {
+ perror("File stream fstat()");
+ goto fstat_error;
+ }
+ if (S_ISDIR(statbuf.st_mode)) {
+ fprintf(stderr, "[warning] Skipping directory '%s' found in trace\n", path);
+ ret = 0;
+ goto fd_is_dir_ok;
+ }
+
file_stream = g_new0(struct ctf_file_stream, 1);
+ file_stream->pos.last_offset = LAST_OFFSET_POISON;
if (packet_seek) {
file_stream->pos.packet_seek = packet_seek;
goto error_def;
}
- ctf_init_pos(&file_stream->pos, ret, flags);
+ ctf_init_pos(&file_stream->pos, fd, flags);
ret = create_trace_definitions(td, &file_stream->parent);
if (ret)
goto error_def;
definition_unref(&file_stream->parent.trace_packet_header->p);
error_def:
ctf_fini_pos(&file_stream->pos);
- close(file_stream->pos.fd);
g_free(file_stream);
+fd_is_dir_ok:
+fstat_error:
+ close(fd);
error:
return ret;
}
/* Open trace directory */
td->dir = opendir(path);
if (!td->dir) {
- fprintf(stderr, "[error] Unable to open trace directory.\n");
+ fprintf(stderr, "[error] Unable to open trace directory \"%s\".\n", path);
ret = -ENOENT;
goto error;
}
td->dirfd = open(path, 0);
if (td->dirfd < 0) {
- fprintf(stderr, "[error] Unable to open trace directory file descriptor.\n");
+ fprintf(stderr, "[error] Unable to open trace directory file descriptor for path \"%s\".\n", path);
perror("Trace directory open");
ret = -errno;
goto error_dirfd;
ret = ctf_open_trace_metadata_read(td, packet_seek, metadata_fp);
if (ret) {
+ fprintf(stderr, "[warning] Unable to open trace metadata for path \"%s\".\n", path);
goto error_metadata;
}
pos->content_size = 0;
pos->content_size_loc = NULL;
pos->fd = mmap_info->fd;
- pos->base = 0;
+ pos->base_mma = NULL;
pos->offset = 0;
pos->dummy = false;
pos->cur_index = 0;
struct ctf_file_stream *file_stream;
file_stream = g_new0(struct ctf_file_stream, 1);
+ file_stream->pos.last_offset = LAST_OFFSET_POISON;
ctf_init_mmap_pos(&file_stream->pos, mmap_info);
file_stream->pos.packet_seek = packet_seek;
struct bt_ctf_event_decl *event;
event = g_ptr_array_index(td->event_declarations, i);
+ if (event->context_decl)
+ g_ptr_array_free(event->context_decl, TRUE);
+ if (event->fields_decl)
+ g_ptr_array_free(event->fields_decl, TRUE);
+ if (event->packet_header_decl)
+ g_ptr_array_free(event->packet_header_decl, TRUE);
+ if (event->event_context_decl)
+ g_ptr_array_free(event->event_context_decl, TRUE);
+ if (event->event_header_decl)
+ g_ptr_array_free(event->event_header_decl, TRUE);
+ if (event->packet_context_decl)
+ g_ptr_array_free(event->packet_context_decl, TRUE);
g_free(event);
}
g_ptr_array_free(td->event_declarations, TRUE);