#include <babeltrace/ctf/events-internal.h>
#include <babeltrace/trace-handle-internal.h>
#include <babeltrace/context-internal.h>
-#include <babeltrace/uuid.h>
+#include <babeltrace/compat/uuid.h>
#include <babeltrace/endian.h>
#include <inttypes.h>
#include <stdio.h>
#include "metadata/ctf-parser.h"
#include "metadata/ctf-ast.h"
#include "events-private.h"
-#include "memstream.h"
+#include <babeltrace/compat/memstream.h>
#define LOG2_CHAR_BIT 3
opt_clock_gmt;
uint64_t opt_clock_offset;
+uint64_t opt_clock_offset_ns;
extern int yydebug;
ts_nsec = timestamp;
+ /* Add command-line offset in ns*/
+ ts_nsec += opt_clock_offset_ns;
+
/* Add command-line offset */
ts_sec += opt_clock_offset;
/*
* for SEEK_CUR: go to next packet.
- * for SEEK_POS: go to packet numer (index).
+ * for SEEK_SET: go to packet numer (index).
*/
void ctf_packet_seek(struct bt_stream_pos *stream_pos, size_t index, int whence)
{
off_t off;
struct packet_index *packet_index;
+ switch (whence) {
+ case SEEK_CUR:
+ case SEEK_SET: /* Fall-through */
+ break; /* OK */
+ default:
+ assert(0);
+ }
+
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 */
- pos->mmap_offset += WRITE_PACKET_LEN / CHAR_BIT;
+ pos->mmap_offset += pos->packet_size / CHAR_BIT;
break;
case SEEK_SET:
assert(index == 0); /* only seek supported for now */
if (pos->offset == EOF) {
return;
}
+ assert(pos->cur_index < pos->packet_cycles_index->len);
+ assert(pos->cur_index < pos->packet_real_index->len);
+
/* For printing discarded event count */
packet_index = &g_array_index(pos->packet_cycles_index,
struct packet_index, pos->cur_index);
break;
}
case SEEK_SET:
+ if (index >= pos->packet_cycles_index->len) {
+ pos->offset = EOF;
+ return;
+ }
packet_index = &g_array_index(pos->packet_cycles_index,
struct packet_index, index);
pos->last_events_discarded = packet_index->events_discarded;
return ret;
}
+static
+int stream_assign_class(struct ctf_trace *td,
+ struct ctf_file_stream *file_stream,
+ uint64_t stream_id)
+{
+ struct ctf_stream_declaration *stream;
+ int ret;
+
+ file_stream->parent.stream_id = stream_id;
+ if (stream_id >= td->streams->len) {
+ fprintf(stderr, "[error] Stream %" PRIu64 " is not declared in metadata.\n", stream_id);
+ return -EINVAL;
+ }
+ stream = g_ptr_array_index(td->streams, stream_id);
+ if (!stream) {
+ fprintf(stderr, "[error] Stream %" PRIu64 " is not declared in metadata.\n", stream_id);
+ return -EINVAL;
+ }
+ file_stream->parent.stream_class = stream;
+ ret = create_stream_definitions(td, &file_stream->parent);
+ if (ret)
+ return ret;
+ return 0;
+}
+
static
int create_stream_one_packet_index(struct ctf_stream_pos *pos,
struct ctf_trace *td,
size_t filesize)
{
struct packet_index packet_index;
- struct ctf_stream_declaration *stream;
uint64_t stream_id = 0;
uint64_t packet_map_len = DEFAULT_HEADER_LEN, tmp_map_len;
int first_packet = 0;
return -EINVAL;
}
if (first_packet) {
- file_stream->parent.stream_id = stream_id;
- if (stream_id >= td->streams->len) {
- fprintf(stderr, "[error] Stream %" PRIu64 " is not declared in metadata.\n", stream_id);
- return -EINVAL;
- }
- stream = g_ptr_array_index(td->streams, stream_id);
- if (!stream) {
- fprintf(stderr, "[error] Stream %" PRIu64 " is not declared in metadata.\n", stream_id);
- return -EINVAL;
- }
- file_stream->parent.stream_class = stream;
- ret = create_stream_definitions(td, &file_stream->parent);
+ ret = stream_assign_class(td, file_stream, stream_id);
if (ret)
return ret;
}
if (ret < 0)
return ret;
+ /* Deal with empty files */
+ if (!filestats.st_size) {
+ if (file_stream->parent.trace_packet_header
+ || file_stream->parent.stream_packet_context) {
+ /*
+ * We expect a trace packet header and/or stream packet
+ * context. Since a trace needs to have at least one
+ * packet, empty files are therefore not accepted.
+ */
+ fprintf(stderr, "[error] Encountered an empty file, but expecting a trace packet header.\n");
+ return -EINVAL;
+ } else {
+ /*
+ * Without trace packet header nor stream packet
+ * context, a one-packet trace can indeed be empty. This
+ * is only valid if there is only one stream class: 0.
+ */
+ ret = stream_assign_class(td, file_stream, 0);
+ if (ret)
+ return ret;
+ return 0;
+ }
+ }
+
for (pos->mmap_offset = 0; pos->mmap_offset < filestats.st_size; ) {
ret = create_stream_one_packet_index(pos, td, file_stream,
filestats.st_size);