#include "plugins/common/param-validation/param-validation.h"
#include "../common/src/metadata/tsdl/decoder.hpp"
+#include "data-stream-file.hpp"
#include "fs.hpp"
+#include "metadata.hpp"
#include "query.hpp"
#define METADATA_TEXT_SIG "/* CTF 1.8"
ctf_metadata_decoder_up decoder = ctf_metadata_decoder_create(&decoder_cfg);
if (!decoder) {
BT_CPPLOGE_APPEND_CAUSE_AND_THROW_SPEC(
- logger, bt2::Error, "Cannot create metadata decoder: path=\"{}}\".", path);
+ logger, bt2::Error, "Cannot create metadata decoder: path=\"{}\".", path);
}
rewind(metadataFp.get());
return result;
}
-static void add_range(const bt2::MapValue info, struct range *range, const char *range_name)
+static void add_range(const bt2::MapValue info, const range& range, const char *range_name)
{
- if (!range->set) {
+ if (!range.set) {
/* Not an error. */
return;
}
const auto rangeMap = info.insertEmptyMap(range_name);
- rangeMap.insert("begin", range->begin_ns);
- rangeMap.insert("end", range->end_ns);
+ rangeMap.insert("begin", range.begin_ns);
+ rangeMap.insert("end", range.end_ns);
}
-static void populate_stream_info(struct ctf_fs_ds_file_group *group, const bt2::MapValue groupInfo,
- struct range *stream_range, const bt2c::Logger& logger)
+static void populate_stream_info(struct ctf_fs_ds_file_group *group, const bt2::MapValue groupInfo)
{
/*
* Since each `struct ctf_fs_ds_file_group` has a sorted array of
* 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);
+ BT_ASSERT(!group->index.entries.empty());
/* First entry. */
- ctf_fs_ds_index_entry *first_ds_index_entry =
- (struct ctf_fs_ds_index_entry *) g_ptr_array_index(group->index->entries, 0);
+ const auto& first_ds_index_entry = group->index.entries.front();
/* Last entry. */
- ctf_fs_ds_index_entry *last_ds_index_entry = (struct ctf_fs_ds_index_entry *) g_ptr_array_index(
- group->index->entries, group->index->entries->len - 1);
+ const auto& last_ds_index_entry = group->index.entries.back();
- stream_range->begin_ns = first_ds_index_entry->timestamp_begin_ns;
- stream_range->end_ns = last_ds_index_entry->timestamp_end_ns;
+ range stream_range;
+ 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);
+ stream_range.set = stream_range.begin_ns != UINT64_C(-1) && stream_range.end_ns != UINT64_C(-1);
add_range(groupInfo, stream_range, "range-ns");
-
- bt2c::GCharUP portName = ctf_fs_make_port_name(group);
- if (!portName) {
- BT_CPPLOGE_APPEND_CAUSE_AND_THROW_SPEC(logger, bt2::Error, "Failed to make port name");
- }
-
- groupInfo.insert("port-name", portName.get());
+ groupInfo.insert("port-name", ctf_fs_make_port_name(group));
}
static void populate_trace_info(const struct ctf_fs_trace *trace, const bt2::MapValue traceInfo,
const bt2c::Logger& logger)
{
- BT_ASSERT(trace->ds_file_groups);
/* Add trace range info only if it contains streams. */
- if (trace->ds_file_groups->len == 0) {
- BT_CPPLOGE_APPEND_CAUSE_AND_THROW_SPEC(
- logger, bt2::Error, "Trace has no streams: trace-path={}", trace->path->str);
+ if (trace->ds_file_groups.empty()) {
+ BT_CPPLOGE_APPEND_CAUSE_AND_THROW_SPEC(logger, bt2::Error,
+ "Trace has no streams: trace-path={}", trace->path);
}
const auto fileGroups = traceInfo.insertEmptyArray("stream-infos");
/* Find range of all stream groups, and of the trace. */
- for (size_t group_idx = 0; group_idx < trace->ds_file_groups->len; group_idx++) {
- range group_range;
- ctf_fs_ds_file_group *group =
- (ctf_fs_ds_file_group *) g_ptr_array_index(trace->ds_file_groups, group_idx);
-
+ for (const auto& group : trace->ds_file_groups) {
const auto groupInfo = fileGroups.appendEmptyMap();
- populate_stream_info(group, groupInfo, &group_range, logger);
+ populate_stream_info(group.get(), groupInfo);
}
}
bt2::Value::Shared trace_infos_query(const bt2::ConstMapValue params, const bt2c::Logger& logger)
{
- ctf_fs_component::UP ctf_fs = ctf_fs_component_create(logger);
- if (!ctf_fs) {
- BT_CPPLOGE_APPEND_CAUSE_AND_THROW_SPEC(logger, bt2::Error,
- "Cannot create ctf_fs_component");
- }
-
- const bt_value *inputs_value = NULL;
- const bt_value *trace_name_value;
-
- if (!read_src_fs_parameters(params.libObjPtr(), &inputs_value, &trace_name_value,
- ctf_fs.get())) {
- BT_CPPLOGE_APPEND_CAUSE_AND_THROW_SPEC(logger, bt2::Error, "Failed to read parameters");
- }
+ const auto parameters = read_src_fs_parameters(params, logger);
+ ctf_fs_component ctf_fs {parameters.clkClsCfg, logger};
- if (ctf_fs_component_create_ctf_fs_trace(ctf_fs.get(), inputs_value, trace_name_value, NULL)) {
+ if (ctf_fs_component_create_ctf_fs_trace(
+ &ctf_fs, parameters.inputs,
+ parameters.traceName ? parameters.traceName->c_str() : nullptr, nullptr)) {
BT_CPPLOGE_APPEND_CAUSE_AND_THROW_SPEC(logger, bt2::Error, "Failed to create trace");
}
const auto result = bt2::ArrayValue::create();
const auto traceInfo = result->appendEmptyMap();
- populate_trace_info(ctf_fs->trace, traceInfo, logger);
+ populate_trace_info(ctf_fs.trace.get(), traceInfo, logger);
return result;
}