From 6834784db7638d11ca5b1f7f6e6a26c19e2ad75a Mon Sep 17 00:00:00 2001 From: Simon Marchi Date: Fri, 1 Nov 2019 15:17:46 -0400 Subject: [PATCH] ctf: read packet sequence number from index Starting with version 1.1, the CTF index format includes a packet sequence number. Read it, if the index minor version is >=1. The index major version is already checked to always be 1 above in the code. If the version is lower than that, store UINT64_MAX in the packet_seq_num field of the ctf_fs_ds_index_entry structure. This information will be used in a subsequent patch. Change-Id: I7b94a94344b26638ae4b7cfc4659067bebc7e195 Signed-off-by: Simon Marchi --- src/plugins/ctf/fs-src/data-stream-file.c | 33 ++++++++++++++++++++--- src/plugins/ctf/fs-src/fs.h | 5 ++++ 2 files changed, 35 insertions(+), 3 deletions(-) diff --git a/src/plugins/ctf/fs-src/data-stream-file.c b/src/plugins/ctf/fs-src/data-stream-file.c index b62ad693..99ff70b1 100644 --- a/src/plugins/ctf/fs-src/data-stream-file.c +++ b/src/plugins/ctf/fs-src/data-stream-file.c @@ -280,6 +280,24 @@ struct ctf_msg_iter_medium_ops ctf_fs_ds_file_medops = { .seek = medop_seek, }; +static +struct ctf_fs_ds_index_entry *ctf_fs_ds_index_entry_create( + bt_self_component *self_comp, bt_logging_level log_level) +{ + struct ctf_fs_ds_index_entry *entry; + + entry = g_new0(struct ctf_fs_ds_index_entry, 1); + if (!entry) { + BT_COMP_LOGE_APPEND_CAUSE(self_comp, "Failed to allocate a ctf_fs_ds_index_entry."); + goto end; + } + + entry->packet_seq_num = UINT64_MAX; + +end: + return entry; +} + static int convert_cycles_to_ns(struct ctf_clock_class *clock_class, uint64_t cycles, int64_t *ns) @@ -419,8 +437,11 @@ struct ctf_fs_ds_index *build_index_from_idx_file( goto error; } - index_entry = g_new0(struct ctf_fs_ds_index_entry, 1); + index_entry = ctf_fs_ds_index_entry_create( + ds_file->self_comp, ds_file->log_level); if (!index_entry) { + BT_COMP_LOGE_APPEND_CAUSE(ds_file->self_comp, + "Failed to create a ctf_fs_ds_index_entry."); goto error; } @@ -465,6 +486,10 @@ struct ctf_fs_ds_index *build_index_from_idx_file( goto error; } + if (version_minor >= 1) { + index_entry->packet_seq_num = be64toh(file_index->packet_seq_num); + } + total_packets_size += packet_size; file_pos += file_index_entry_size; @@ -621,9 +646,11 @@ struct ctf_fs_ds_index *build_index_from_stream_file( goto error; } - index_entry = g_new0(struct ctf_fs_ds_index_entry, 1); + index_entry = ctf_fs_ds_index_entry_create( + ds_file->self_comp, ds_file->log_level); if (!index_entry) { - BT_COMP_LOGE_STR("Failed to allocate a new index entry."); + BT_COMP_LOGE_APPEND_CAUSE(ds_file->self_comp, + "Failed to create a ctf_fs_ds_index_entry."); goto error; } diff --git a/src/plugins/ctf/fs-src/fs.h b/src/plugins/ctf/fs-src/fs.h index a6594b1c..78faded2 100644 --- a/src/plugins/ctf/fs-src/fs.h +++ b/src/plugins/ctf/fs-src/fs.h @@ -129,6 +129,11 @@ struct ctf_fs_ds_index_entry { * (in ns since EPOCH). */ int64_t timestamp_begin_ns, timestamp_end_ns; + + /* + * Packet sequence number, or UINT64_MAX if not present in the index. + */ + uint64_t packet_seq_num; }; struct ctf_fs_ds_index { -- 2.34.1