X-Git-Url: http://git.efficios.com/?a=blobdiff_plain;f=plugins%2Fctf%2Ffs-src%2Fquery.c;h=e2018b157a0aef746e6d1c7ea85781bd992dd8a0;hb=68b66a256a54d32992dfefeaad11eea88b7df234;hp=c185307caa3f6b2ef8d1dcd90b0704ec81876117;hpb=07330b50b347dcb93ea10d564bed354a02d11a66;p=babeltrace.git diff --git a/plugins/ctf/fs-src/query.c b/plugins/ctf/fs-src/query.c index c185307c..e2018b15 100644 --- a/plugins/ctf/fs-src/query.c +++ b/plugins/ctf/fs-src/query.c @@ -26,12 +26,12 @@ #include "query.h" #include -#include +#include #include "metadata.h" #include "../common/metadata/decoder.h" -#include -#include -#include +#include +#include +#include #include "fs.h" #define BT_LOG_TAG "PLUGIN-CTF-FS-QUERY-SRC" @@ -211,14 +211,14 @@ int add_range(bt_value *info, struct range *range, goto end; } - status = bt_value_map_insert_integer_entry(range_map, "begin", + status = bt_value_map_insert_signed_integer_entry(range_map, "begin", range->begin_ns); if (status != BT_VALUE_STATUS_OK) { ret = -1; goto end; } - status = bt_value_map_insert_integer_entry(range_map, "end", + status = bt_value_map_insert_signed_integer_entry(range_map, "end", range->end_ns); if (status != BT_VALUE_STATUS_OK) { ret = -1; @@ -244,16 +244,16 @@ int add_stream_ids(bt_value *info, struct ctf_fs_ds_file_group *ds_file_group) bt_value_status status; if (ds_file_group->stream_id != UINT64_C(-1)) { - status = bt_value_map_insert_integer_entry(info, "id", - (int64_t) ds_file_group->stream_id); + status = bt_value_map_insert_unsigned_integer_entry(info, "id", + ds_file_group->stream_id); if (status != BT_VALUE_STATUS_OK) { ret = -1; goto end; } } - status = bt_value_map_insert_integer_entry(info, "class-id", - (int64_t) ds_file_group->sc->id); + status = bt_value_map_insert_unsigned_integer_entry(info, "class-id", + ds_file_group->sc->id); if (status != BT_VALUE_STATUS_OK) { ret = -1; goto end; @@ -271,9 +271,8 @@ int populate_stream_info(struct ctf_fs_ds_file_group *group, size_t file_idx; bt_value_status status; bt_value *file_paths; - - stream_range->begin_ns = INT64_MAX; - stream_range->end_ns = 0; + struct ctf_fs_ds_index_entry *first_ds_index_entry, *last_ds_index_entry; + gchar *port_name = NULL; file_paths = bt_value_array_create(); if (!file_paths) { @@ -282,44 +281,50 @@ int populate_stream_info(struct ctf_fs_ds_file_group *group, } for (file_idx = 0; file_idx < group->ds_file_infos->len; file_idx++) { - int64_t file_begin_epoch, file_end_epoch; struct ctf_fs_ds_file_info *info = g_ptr_array_index(group->ds_file_infos, file_idx); - if (!info->index || info->index->entries->len == 0) { - BT_LOGW("Cannot determine range of unindexed stream file \'%s\'", - info->path->str); - ret = -1; - goto end; - } - status = bt_value_array_append_string_element(file_paths, info->path->str); if (status != BT_VALUE_STATUS_OK) { ret = -1; goto end; } - - /* - * file range is from timestamp_begin of the first entry to the - * timestamp_end of the last entry. - */ - file_begin_epoch = ((struct ctf_fs_ds_index_entry *) &g_array_index(info->index->entries, - struct ctf_fs_ds_index_entry, 0))->timestamp_begin_ns; - file_end_epoch = ((struct ctf_fs_ds_index_entry *) &g_array_index(info->index->entries, - struct ctf_fs_ds_index_entry, info->index->entries->len - 1))->timestamp_end_ns; - - stream_range->begin_ns = min(stream_range->begin_ns, file_begin_epoch); - stream_range->end_ns = max(stream_range->end_ns, file_end_epoch); - stream_range->set = true; } - if (stream_range->set) { - ret = add_range(group_info, stream_range, "range-ns"); - if (ret) { - goto end; - } + /* + * Since each `struct ctf_fs_ds_file_group` has a sorted array of + * `struct ctf_fs_ds_index_entry`, we can compute the stream range from + * the timestamp_begin of the first index entry and the timestamp_end + * of the last index entry. + */ + BT_ASSERT(group->index); + BT_ASSERT(group->index->entries); + BT_ASSERT(group->index->entries->len > 0); + + /* First entry. */ + first_ds_index_entry = (struct ctf_fs_ds_index_entry *) g_ptr_array_index( + group->index->entries, 0); + + /* Last entry. */ + last_ds_index_entry = (struct ctf_fs_ds_index_entry *) g_ptr_array_index( + group->index->entries, group->index->entries->len - 1); + + stream_range->begin_ns = first_ds_index_entry->timestamp_begin_ns; + stream_range->end_ns = last_ds_index_entry->timestamp_end_ns; + + /* + * If any of the begin and end timestamps is not set it means that + * packets don't include `timestamp_begin` _and_ `timestamp_end` fields + * in their packet context so we can't set the range. + */ + stream_range->set = stream_range->begin_ns != UINT64_C(-1) && + stream_range->end_ns != UINT64_C(-1); + + ret = add_range(group_info, stream_range, "range-ns"); + if (ret) { + goto end; } status = bt_value_map_insert_entry(group_info, "paths", @@ -333,6 +338,20 @@ int populate_stream_info(struct ctf_fs_ds_file_group *group, if (ret) { goto end; } + + port_name = ctf_fs_make_port_name(group); + if (!port_name) { + ret = -1; + goto end; + } + + status = bt_value_map_insert_string_entry(group_info, "port-name", + port_name); + if (status != BT_VALUE_STATUS_OK) { + ret = -1; + goto end; + } + end: bt_value_put_ref(file_paths); return ret; @@ -401,6 +420,12 @@ int populate_trace_info(const struct ctf_fs_trace *trace, bt_value *trace_info) goto end; } + status = bt_value_array_append_element(file_groups, group_info); + bt_value_put_ref(group_info); + if (status != BT_VALUE_STATUS_OK) { + goto end; + } + if (group_range.set) { trace_range.begin_ns = min(trace_range.begin_ns, group_range.begin_ns); @@ -413,13 +438,6 @@ int populate_trace_info(const struct ctf_fs_trace *trace, bt_value *trace_info) trace_intersection.end_ns = min(trace_intersection.end_ns, group_range.end_ns); trace_intersection.set = true; - status = bt_value_array_append_element( - file_groups, - group_info); - bt_value_put_ref(group_info); - if (status != BT_VALUE_STATUS_OK) { - goto end; - } } } @@ -470,13 +488,13 @@ bt_query_status trace_info_query( goto error; } - paths_value = bt_value_map_borrow_entry_value_const(params, "paths"); - if (!validate_paths_parameter(paths_value)) { + ctf_fs = ctf_fs_component_create(); + if (!ctf_fs) { goto error; } - ctf_fs = ctf_fs_component_create(); - if (!ctf_fs) { + if (!read_src_fs_parameters(params, &paths_value, ctf_fs)) { + status = BT_QUERY_STATUS_INVALID_PARAMS; goto error; }