Signed-off-by: Julien Desfossez <julien.desfossez@efficios.com>
Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
static
struct trace_descriptor *bt_dummy_open_trace(const char *path, int flags,
static
struct trace_descriptor *bt_dummy_open_trace(const char *path, int flags,
- void (*packet_seek)(struct stream_pos *pos, size_t offset,
+ void (*packet_seek)(struct stream_pos *pos, size_t index,
int whence), FILE *metadata_fp)
{
struct ctf_text_stream_pos *pos;
int whence), FILE *metadata_fp)
{
struct ctf_text_stream_pos *pos;
struct trace_descriptor *ctf_text_open_trace(const char *path, int flags,
struct trace_descriptor *ctf_text_open_trace(const char *path, int flags,
- void (*packet_seek)(struct stream_pos *pos, size_t offset,
+ void (*packet_seek)(struct stream_pos *pos, size_t index,
int whence), FILE *metadata_fp);
void ctf_text_close_trace(struct trace_descriptor *descriptor);
int whence), FILE *metadata_fp);
void ctf_text_close_trace(struct trace_descriptor *descriptor);
struct trace_descriptor *ctf_text_open_trace(const char *path, int flags,
struct trace_descriptor *ctf_text_open_trace(const char *path, int flags,
- void (*packet_seek)(struct stream_pos *pos, size_t offset,
+ void (*packet_seek)(struct stream_pos *pos, size_t index,
int whence), FILE *metadata_fp)
{
struct ctf_text_stream_pos *pos;
int whence), FILE *metadata_fp)
{
struct ctf_text_stream_pos *pos;
static
struct trace_descriptor *ctf_open_trace(const char *path, int flags,
static
struct trace_descriptor *ctf_open_trace(const char *path, int flags,
- void (*packet_seek)(struct stream_pos *pos, size_t offset,
- int whence), FILE *metadata_fp);
+ void (*packet_seek)(struct stream_pos *pos, size_t index,
+ int whence),
+ FILE *metadata_fp);
static
struct trace_descriptor *ctf_open_mmap_trace(
struct mmap_stream_list *mmap_list,
static
struct trace_descriptor *ctf_open_mmap_trace(
struct mmap_stream_list *mmap_list,
- void (*packet_seek)(struct stream_pos *pos, size_t offset, int whence),
+ void (*packet_seek)(struct stream_pos *pos, size_t index,
+ int whence),
FILE *metadata_fp);
static
FILE *metadata_fp);
static
(void) g_array_free(pos->packet_index, TRUE);
}
(void) g_array_free(pos->packet_index, TRUE);
}
-void ctf_packet_seek(struct stream_pos *stream_pos, size_t offset, int whence)
+/*
+ * for SEEK_CUR: go to next packet.
+ * for SEEK_POS: go to packet numer (index).
+ */
+void ctf_packet_seek(struct stream_pos *stream_pos, size_t index, int whence)
{
struct ctf_stream_pos *pos =
container_of(stream_pos, struct ctf_stream_pos, parent);
{
struct ctf_stream_pos *pos =
container_of(stream_pos, struct ctf_stream_pos, parent);
container_of(pos, struct ctf_file_stream, pos);
int ret;
off_t off;
container_of(pos, struct ctf_file_stream, pos);
int ret;
off_t off;
- struct packet_index *index;
+ struct packet_index *packet_index;
if (pos->prot == PROT_WRITE && pos->content_size_loc)
*pos->content_size_loc = pos->offset;
if (pos->prot == PROT_WRITE && pos->content_size_loc)
*pos->content_size_loc = pos->offset;
switch (whence) {
case SEEK_CUR:
/* The writer will add padding */
switch (whence) {
case SEEK_CUR:
/* The writer will add padding */
- assert(pos->offset + offset == pos->packet_size);
pos->mmap_offset += WRITE_PACKET_LEN / CHAR_BIT;
break;
case SEEK_SET:
pos->mmap_offset += WRITE_PACKET_LEN / CHAR_BIT;
break;
case SEEK_SET:
- assert(offset == 0); /* only seek supported for now */
+ assert(index == 0); /* only seek supported for now */
pos->cur_index = 0;
break;
default:
pos->cur_index = 0;
break;
default:
return;
}
/* For printing discarded event count */
return;
}
/* For printing discarded event count */
- index = &g_array_index(pos->packet_index,
+ packet_index = &g_array_index(pos->packet_index,
struct packet_index, pos->cur_index);
struct packet_index, pos->cur_index);
- events_discarded_diff = index->events_discarded;
+ events_discarded_diff = packet_index->events_discarded;
file_stream->parent.prev_timestamp_end =
file_stream->parent.prev_timestamp_end =
+ packet_index->timestamp_end;
if (pos->cur_index > 0) {
if (pos->cur_index > 0) {
- index = &g_array_index(pos->packet_index,
+ packet_index = &g_array_index(pos->packet_index,
struct packet_index,
pos->cur_index - 1);
struct packet_index,
pos->cur_index - 1);
- events_discarded_diff -= index->events_discarded;
+ events_discarded_diff -= packet_index->events_discarded;
}
file_stream->parent.events_discarded = events_discarded_diff;
file_stream->parent.prev_timestamp = file_stream->parent.timestamp;
/* The reader will expect us to skip padding */
}
file_stream->parent.events_discarded = events_discarded_diff;
file_stream->parent.prev_timestamp = file_stream->parent.timestamp;
/* The reader will expect us to skip padding */
- assert(pos->offset + offset == pos->content_size);
++pos->cur_index;
break;
}
case SEEK_SET:
++pos->cur_index;
break;
}
case SEEK_SET:
- if (offset == 0)
- pos->cur_index = 0;
+ pos->cur_index = index;
file_stream->parent.prev_timestamp = 0;
file_stream->parent.prev_timestamp_end = 0;
break;
file_stream->parent.prev_timestamp = 0;
file_stream->parent.prev_timestamp_end = 0;
break;
pos->offset = EOF;
return;
}
pos->offset = EOF;
return;
}
- index = &g_array_index(pos->packet_index, struct packet_index,
+ packet_index = &g_array_index(pos->packet_index, struct packet_index,
- pos->mmap_offset = index->offset;
+ pos->mmap_offset = packet_index->offset;
/* Lookup context/packet size in index */
/* Lookup context/packet size in index */
- file_stream->parent.timestamp = index->timestamp_begin;
- pos->content_size = index->content_size;
- pos->packet_size = index->packet_size;
- if (index->data_offset < index->content_size) {
+ file_stream->parent.timestamp = packet_index->timestamp_begin;
+ pos->content_size = packet_index->content_size;
+ pos->packet_size = packet_index->packet_size;
+ if (packet_index->data_offset < packet_index->content_size) {
pos->offset = 0; /* will read headers */
pos->offset = 0; /* will read headers */
- } else if (index->data_offset == index->content_size) {
+ } else if (packet_index->data_offset == packet_index->content_size) {
- pos->offset = index->data_offset;
- offset = 0;
+ pos->offset = packet_index->data_offset;
whence = SEEK_CUR;
goto read_next_packet;
} else {
whence = SEEK_CUR;
goto read_next_packet;
} else {
static
int ctf_open_trace_metadata_read(struct ctf_trace *td,
static
int ctf_open_trace_metadata_read(struct ctf_trace *td,
- void (*packet_seek)(struct stream_pos *pos, size_t offset,
+ void (*packet_seek)(struct stream_pos *pos, size_t index,
int whence), FILE *metadata_fp)
{
struct ctf_scanner *scanner;
int whence), FILE *metadata_fp)
{
struct ctf_scanner *scanner;
*/
static
int ctf_open_file_stream_read(struct ctf_trace *td, const char *path, int flags,
*/
static
int ctf_open_file_stream_read(struct ctf_trace *td, const char *path, int flags,
- void (*packet_seek)(struct stream_pos *pos, size_t offset,
+ void (*packet_seek)(struct stream_pos *pos, size_t index,
static
int ctf_open_trace_read(struct ctf_trace *td,
const char *path, int flags,
static
int ctf_open_trace_read(struct ctf_trace *td,
const char *path, int flags,
- void (*packet_seek)(struct stream_pos *pos, size_t offset,
+ void (*packet_seek)(struct stream_pos *pos, size_t index,
int whence), FILE *metadata_fp)
{
int ret;
int whence), FILE *metadata_fp)
{
int ret;
static
struct trace_descriptor *ctf_open_trace(const char *path, int flags,
static
struct trace_descriptor *ctf_open_trace(const char *path, int flags,
- void (*packet_seek)(struct stream_pos *pos, size_t offset,
+ void (*packet_seek)(struct stream_pos *pos, size_t index,
int whence), FILE *metadata_fp)
{
struct ctf_trace *td;
int whence), FILE *metadata_fp)
{
struct ctf_trace *td;
static
int ctf_open_mmap_stream_read(struct ctf_trace *td,
struct mmap_stream *mmap_info,
static
int ctf_open_mmap_stream_read(struct ctf_trace *td,
struct mmap_stream *mmap_info,
- void (*packet_seek)(struct stream_pos *pos, size_t offset,
+ void (*packet_seek)(struct stream_pos *pos, size_t index,
int ctf_open_mmap_trace_read(struct ctf_trace *td,
struct mmap_stream_list *mmap_list,
int ctf_open_mmap_trace_read(struct ctf_trace *td,
struct mmap_stream_list *mmap_list,
- void (*packet_seek)(struct stream_pos *pos, size_t offset,
+ void (*packet_seek)(struct stream_pos *pos, size_t index,
int whence),
FILE *metadata_fp)
{
int whence),
FILE *metadata_fp)
{
static
struct trace_descriptor *ctf_open_mmap_trace(
struct mmap_stream_list *mmap_list,
static
struct trace_descriptor *ctf_open_mmap_trace(
struct mmap_stream_list *mmap_list,
- void (*packet_seek)(struct stream_pos *pos, size_t offset, int whence),
+ void (*packet_seek)(struct stream_pos *pos, size_t index,
+ int whence),
FILE *metadata_fp)
{
struct ctf_trace *td;
FILE *metadata_fp)
{
struct ctf_trace *td;
int bt_context_add_trace(struct bt_context *ctx, const char *path,
const char *format,
void (*packet_seek)(struct stream_pos *pos,
int bt_context_add_trace(struct bt_context *ctx, const char *path,
const char *format,
void (*packet_seek)(struct stream_pos *pos,
- size_t offset, int whence));
+ size_t index, int whence));
/*
* bt_context_remove_trace: Remove a trace from the context.
/*
* bt_context_remove_trace: Remove a trace from the context.
ssize_t offset; /* offset from base, in bits. EOF for end of file. */
ssize_t last_offset; /* offset before the last read_event */
size_t cur_index; /* current index in packet index */
ssize_t offset; /* offset from base, in bits. EOF for end of file. */
ssize_t last_offset; /* offset before the last read_event */
size_t cur_index; /* current index in packet index */
- void (*packet_seek)(struct stream_pos *pos, size_t offset,
+ void (*packet_seek)(struct stream_pos *pos, size_t index,
int whence); /* function called to switch packet */
int dummy; /* dummy position, for length calculation */
int whence); /* function called to switch packet */
int dummy; /* dummy position, for length calculation */
int ctf_sequence_read(struct stream_pos *pos, struct definition *definition);
int ctf_sequence_write(struct stream_pos *pos, struct definition *definition);
int ctf_sequence_read(struct stream_pos *pos, struct definition *definition);
int ctf_sequence_write(struct stream_pos *pos, struct definition *definition);
-void ctf_packet_seek(struct stream_pos *pos, size_t offset, int whence);
+void ctf_packet_seek(struct stream_pos *pos, size_t index, int whence);
void ctf_init_pos(struct ctf_stream_pos *pos, int fd, int open_flags);
void ctf_fini_pos(struct ctf_stream_pos *pos);
void ctf_init_pos(struct ctf_stream_pos *pos, int fd, int open_flags);
void ctf_fini_pos(struct ctf_stream_pos *pos);
&& (unlikely(pos->offset + bit_offset >= pos->packet_size))) {
printf_debug("ctf_packet_seek (before call): %zd\n",
pos->offset);
&& (unlikely(pos->offset + bit_offset >= pos->packet_size))) {
printf_debug("ctf_packet_seek (before call): %zd\n",
pos->offset);
- ctf_packet_seek(&pos->parent, bit_offset, SEEK_CUR);
+ ctf_packet_seek(&pos->parent, 0, SEEK_CUR);
printf_debug("ctf_packet_seek (after call): %zd\n",
pos->offset);
return;
printf_debug("ctf_packet_seek (after call): %zd\n",
pos->offset);
return;
struct trace_descriptor *(*open_trace)(const char *path, int flags,
void (*packet_seek)(struct stream_pos *pos,
struct trace_descriptor *(*open_trace)(const char *path, int flags,
void (*packet_seek)(struct stream_pos *pos,
- size_t offset, int whence),
+ size_t index, int whence),
FILE *metadata_fp);
struct trace_descriptor *(*open_mmap_trace)(
struct mmap_stream_list *mmap_list,
void (*packet_seek)(struct stream_pos *pos,
FILE *metadata_fp);
struct trace_descriptor *(*open_mmap_trace)(
struct mmap_stream_list *mmap_list,
void (*packet_seek)(struct stream_pos *pos,
- size_t offset, int whence),
+ size_t index, int whence),
FILE *metadata_fp);
void (*close_trace)(struct trace_descriptor *descriptor);
};
FILE *metadata_fp);
void (*close_trace)(struct trace_descriptor *descriptor);
};
int bt_context_add_trace(struct bt_context *ctx, const char *path,
const char *format_name,
int bt_context_add_trace(struct bt_context *ctx, const char *path,
const char *format_name,
- void (*packet_seek)(struct stream_pos *pos,
- size_t offset, int whence))
+ void (*packet_seek)(struct stream_pos *pos, size_t index,
+ int whence))
{
struct trace_descriptor *td;
struct format *fmt;
{
struct trace_descriptor *td;
struct format *fmt;
index->timestamp_end <= timestamp)
continue;
index->timestamp_end <= timestamp)
continue;
- stream_pos->cur_index = i;
- stream_pos->packet_seek(&stream_pos->parent,
- index->offset, SEEK_SET);
+ stream_pos->packet_seek(&stream_pos->parent, i, SEEK_SET);
while (cfs->parent.timestamp < timestamp) {
ret = stream_read_event(cfs);
if (ret < 0)
while (cfs->parent.timestamp < timestamp) {
ret = stream_read_event(cfs);
if (ret < 0)
i++) {
struct stream_saved_pos *saved_pos;
struct ctf_stream_pos *stream_pos;
i++) {
struct stream_saved_pos *saved_pos;
struct ctf_stream_pos *stream_pos;
- struct packet_index *index;
struct ctf_stream *stream;
saved_pos = &g_array_index(
struct ctf_stream *stream;
saved_pos = &g_array_index(
struct stream_saved_pos, i);
stream = &saved_pos->file_stream->parent;
stream_pos = &saved_pos->file_stream->pos;
struct stream_saved_pos, i);
stream = &saved_pos->file_stream->parent;
stream_pos = &saved_pos->file_stream->pos;
- index = &g_array_index(stream_pos->packet_index,
- struct packet_index,
- saved_pos->cur_index);
- stream_pos->cur_index = saved_pos->cur_index;
stream_pos->packet_seek(&stream_pos->parent,
stream_pos->packet_seek(&stream_pos->parent,
- index->offset, SEEK_SET);
+ saved_pos->cur_index, SEEK_SET);
/*
* the timestamp needs to be restored after
/*
* the timestamp needs to be restored after