[lttng-dev] [RFC babeltrace 1/2] fs-src: add argument for metadata src dir
Philippe Proulx
eeppeliteloop at gmail.com
Tue May 1 10:41:12 EDT 2018
On Mon, Apr 30, 2018 at 6:36 PM, Philippe Proulx
<eeppeliteloop at gmail.com> wrote:
> On Mon, Apr 30, 2018 at 5:31 PM, Alexander Aring <aring at mojatatu.com> wrote:
>>
>> This patch adds an argument for the fs-src plugin to declare the
>> directory to find the metadata file instead of placing it in every
>> subdir of traces.
>>
>> If parameter assign every subdirectory which does not have a
>> subdirectory and at least some regular files will be assumed as a trace
>> directory. The regular files will be assumed as ctf trace files.
>
> Although I really appreciate the contribution effort, before even
> reading this patch, let me indicate that a CTF trace located on the file
> system is a directory containing the data stream and metadata stream
> files. Knowing this, this patch implements a hack to circumvent this,
> but I'm personally not willing to have this upstream as, in my opinion,
> it is the user's responsibility to have valid CTF traces to open.
>
> Your custom scenario asks for a custom solution on your side: copying
> the metadata file to each trace's directory seems appropriate here.
Just had a thought: you can also create symbolic links in each trace's
directory to your common metadata file.
Phil
>
> Also, do your CTF traces have UUIDs? If they do, they should all be
> different, but having the same metadata file makes them all the same.
> This is not valid either.
>
> Phil
>
>>
>> Signed-off-by: Alexander Aring <aring at mojatatu.com>
>> ---
>> cli/babeltrace-cfg-cli-args.c | 10 +++++
>> plugins/ctf/fs-src/fs.c | 88 +++++++++++++++++++++++++++++++++++--------
>> plugins/ctf/fs-src/fs.h | 3 +-
>> plugins/ctf/fs-src/metadata.c | 8 +++-
>> plugins/ctf/fs-src/metadata.h | 1 +
>> plugins/ctf/fs-src/query.c | 2 +-
>> 6 files changed, 94 insertions(+), 18 deletions(-)
>>
>> diff --git a/cli/babeltrace-cfg-cli-args.c b/cli/babeltrace-cfg-cli-args.c
>> index 8f01e64b..ab76852e 100644
>> --- a/cli/babeltrace-cfg-cli-args.c
>> +++ b/cli/babeltrace-cfg-cli-args.c
>> @@ -1306,6 +1306,7 @@ enum {
>> OPT_CLOCK_GMT,
>> OPT_CLOCK_OFFSET,
>> OPT_CLOCK_OFFSET_NS,
>> + OPT_METADATA_SRC,
>> OPT_CLOCK_SECONDS,
>> OPT_COLOR,
>> OPT_COMPONENT,
>> @@ -2789,6 +2790,7 @@ void print_convert_usage(FILE *fp)
>> fprintf(fp, "\n");
>> fprintf(fp, " --clock-offset=SEC Set clock offset to SEC seconds\n");
>> fprintf(fp, " --clock-offset-ns=NS Set clock offset to NS ns\n");
>> + fprintf(fp, " --metadata-src=PATH Set a path to find the metadata\n");
>> fprintf(fp, "\n");
>> fprintf(fp, "Implicit `sink.text.pretty` component options:\n");
>> fprintf(fp, "\n");
>> @@ -2886,6 +2888,7 @@ struct poptOption convert_long_options[] = {
>> { "clock-gmt", '\0', POPT_ARG_NONE, NULL, OPT_CLOCK_GMT, NULL, NULL },
>> { "clock-offset", '\0', POPT_ARG_STRING, NULL, OPT_CLOCK_OFFSET, NULL, NULL },
>> { "clock-offset-ns", '\0', POPT_ARG_STRING, NULL, OPT_CLOCK_OFFSET_NS, NULL, NULL },
>> + { "metadata-src", '\0', POPT_ARG_STRING, NULL, OPT_METADATA_SRC, NULL, NULL },
>> { "clock-seconds", '\0', POPT_ARG_NONE, NULL, OPT_CLOCK_SECONDS, NULL, NULL },
>> { "color", '\0', POPT_ARG_STRING, NULL, OPT_COLOR, NULL, NULL },
>> { "component", 'c', POPT_ARG_STRING, NULL, OPT_COMPONENT, NULL, NULL },
>> @@ -3942,6 +3945,7 @@ struct bt_config *bt_config_convert_from_args(int argc, const char *argv[],
>> case OPT_CLOCK_GMT:
>> case OPT_CLOCK_OFFSET:
>> case OPT_CLOCK_OFFSET_NS:
>> + case OPT_METADATA_SRC:
>> case OPT_CLOCK_SECONDS:
>> case OPT_COLOR:
>> case OPT_DEBUG:
>> @@ -4104,6 +4108,12 @@ struct bt_config *bt_config_convert_from_args(int argc, const char *argv[],
>> &base_implicit_ctf_input_args,
>> "clock-class-offset-ns", arg);
>> break;
>> + case OPT_METADATA_SRC:
>> + base_implicit_ctf_input_args.exists = true;
>> + append_implicit_component_param(
>> + &base_implicit_ctf_input_args,
>> + "metadata-src", arg);
>> + break;
>> case OPT_CLOCK_SECONDS:
>> append_implicit_component_param(
>> &implicit_text_args, "clock-seconds", "yes");
>> diff --git a/plugins/ctf/fs-src/fs.c b/plugins/ctf/fs-src/fs.c
>> index 2dacf97d..7f98dda5 100644
>> --- a/plugins/ctf/fs-src/fs.c
>> +++ b/plugins/ctf/fs-src/fs.c
>> @@ -1039,26 +1039,70 @@ end:
>> }
>>
>> BT_HIDDEN
>> -int ctf_fs_find_traces(GList **trace_paths, const char *start_path)
>> +int ctf_fs_find_traces(GList **trace_paths, const char *start_path,
>> + const char *metadata_src)
>> {
>> int ret;
>> GError *error = NULL;
>> GDir *dir = NULL;
>> const char *basename = NULL;
>> + bool subdirs = false;
>> + bool regfile = false;
>>
>> - /* Check if the starting path is a CTF trace itself */
>> - ret = path_is_ctf_trace(start_path);
>> - if (ret < 0) {
>> - goto end;
>> - }
>> + if (metadata_src) {
>> + ret = path_is_ctf_trace(metadata_src);
>> + if (ret < 0) {
>> + goto end;
>> + }
>>
>> - if (ret) {
>> - /*
>> - * Stop recursion: a CTF trace cannot contain another
>> - * CTF trace.
>> - */
>> - ret = add_trace_path(trace_paths, start_path);
>> - goto end;
>> + if (ret) {
>> + dir = g_dir_open(start_path, 0, &error);
>> + if (!dir) {
>> + goto end;
>> + }
>> +
>> + while ((basename = g_dir_read_name(dir))) {
>> + GString *sub_path = g_string_new(NULL);
>> +
>> + if (!sub_path) {
>> + ret = -1;
>> + goto end;
>> + }
>> +
>> + g_string_printf(sub_path, "%s" G_DIR_SEPARATOR_S "%s", start_path, basename);
>> + if (g_file_test(sub_path->str, G_FILE_TEST_IS_DIR)) {
>> + subdirs = true;
>> + }
>> + if (g_file_test(sub_path->str, G_FILE_TEST_IS_REGULAR)) {
>> + regfile = true;
>> + }
>> + g_string_free(sub_path, TRUE);
>> + }
>> +
>> + g_dir_close(dir);
>> + dir = NULL;
>> +
>> + /* Look if dir has no subdirs but regfile(s) */
>> + if (!subdirs && regfile) {
>> + ret = add_trace_path(trace_paths, start_path);
>> + goto end;
>> + }
>> + }
>> + } else {
>> + /* Check if the starting path is a CTF trace itself */
>> + ret = path_is_ctf_trace(start_path);
>> + if (ret < 0) {
>> + goto end;
>> + }
>> +
>> + if (ret) {
>> + /*
>> + * Stop recursion: a CTF trace cannot contain another
>> + * CTF trace.
>> + */
>> + ret = add_trace_path(trace_paths, start_path);
>> + goto end;
>> + }
>> }
>>
>> /* Look for subdirectories */
>> @@ -1090,7 +1134,7 @@ int ctf_fs_find_traces(GList **trace_paths, const char *start_path)
>> }
>>
>> g_string_printf(sub_path, "%s" G_DIR_SEPARATOR_S "%s", start_path, basename);
>> - ret = ctf_fs_find_traces(trace_paths, sub_path->str);
>> + ret = ctf_fs_find_traces(trace_paths, sub_path->str, metadata_src);
>> g_string_free(sub_path, TRUE);
>> if (ret) {
>> goto end;
>> @@ -1181,7 +1225,8 @@ int create_ctf_fs_traces(struct ctf_fs_component *ctf_fs,
>> goto error;
>> }
>>
>> - ret = ctf_fs_find_traces(&trace_paths, norm_path->str);
>> + ret = ctf_fs_find_traces(&trace_paths, norm_path->str,
>> + ctf_fs->metadata_config.metadata_src);
>> if (ret) {
>> goto error;
>> }
>> @@ -1287,6 +1332,19 @@ struct ctf_fs_component *ctf_fs_create(struct bt_private_component *priv_comp,
>> value_ret = bt_value_string_get(value, &path_param);
>> assert(value_ret == BT_VALUE_STATUS_OK);
>> BT_PUT(value);
>> +
>> + value = bt_value_map_get(params, "metadata-src");
>> + if (value) {
>> + if (!bt_value_is_string(value)) {
>> + goto error;
>> + }
>> +
>> + value_ret = bt_value_string_get(value,
>> + &ctf_fs->metadata_config.metadata_src);
>> + assert(value_ret == BT_VALUE_STATUS_OK);
>> + BT_PUT(value);
>> + }
>> +
>> value = bt_value_map_get(params, "clock-class-offset-s");
>> if (value) {
>> if (!bt_value_is_integer(value)) {
>> diff --git a/plugins/ctf/fs-src/fs.h b/plugins/ctf/fs-src/fs.h
>> index bbac1bb4..f80aea74 100644
>> --- a/plugins/ctf/fs-src/fs.h
>> +++ b/plugins/ctf/fs-src/fs.h
>> @@ -154,7 +154,8 @@ BT_HIDDEN
>> void ctf_fs_trace_destroy(struct ctf_fs_trace *trace);
>>
>> BT_HIDDEN
>> -int ctf_fs_find_traces(GList **trace_paths, const char *start_path);
>> +int ctf_fs_find_traces(GList **trace_paths, const char *start_path,
>> + const char *metadata_src);
>>
>> BT_HIDDEN
>> GList *ctf_fs_create_trace_names(GList *trace_paths, const char *base_path);
>> diff --git a/plugins/ctf/fs-src/metadata.c b/plugins/ctf/fs-src/metadata.c
>> index 231d946c..02cbd0cd 100644
>> --- a/plugins/ctf/fs-src/metadata.c
>> +++ b/plugins/ctf/fs-src/metadata.c
>> @@ -96,8 +96,14 @@ int ctf_fs_metadata_set_trace(struct ctf_fs_trace *ctf_fs_trace,
>> .clock_class_offset_s = config ? config->clock_class_offset_s : 0,
>> .clock_class_offset_ns = config ? config->clock_class_offset_ns : 0,
>> };
>> + const char *metadata_src;
>>
>> - file = get_file(ctf_fs_trace->path->str);
>> + if (config->metadata_src)
>> + metadata_src = config->metadata_src;
>> + else
>> + metadata_src = ctf_fs_trace->path->str;
>> +
>> + file = get_file(metadata_src);
>> if (!file) {
>> BT_LOGE("Cannot create metadata file object");
>> ret = -1;
>> diff --git a/plugins/ctf/fs-src/metadata.h b/plugins/ctf/fs-src/metadata.h
>> index 496a5ca9..00d8de67 100644
>> --- a/plugins/ctf/fs-src/metadata.h
>> +++ b/plugins/ctf/fs-src/metadata.h
>> @@ -36,6 +36,7 @@ struct ctf_fs_metadata;
>> struct ctf_fs_metadata_config {
>> int64_t clock_class_offset_s;
>> int64_t clock_class_offset_ns;
>> + const char *metadata_src;
>> };
>>
>> BT_HIDDEN
>> diff --git a/plugins/ctf/fs-src/query.c b/plugins/ctf/fs-src/query.c
>> index 04bf8c5b..6f2aa5fe 100644
>> --- a/plugins/ctf/fs-src/query.c
>> +++ b/plugins/ctf/fs-src/query.c
>> @@ -500,7 +500,7 @@ struct bt_component_class_query_method_return trace_info_query(
>> }
>> assert(path);
>>
>> - ret = ctf_fs_find_traces(&trace_paths, normalized_path->str);
>> + ret = ctf_fs_find_traces(&trace_paths, normalized_path->str, NULL);
>> if (ret) {
>> goto error;
>> }
>> --
>> 2.11.0
>>
>> _______________________________________________
>> lttng-dev mailing list
>> lttng-dev at lists.lttng.org
>> https://lists.lttng.org/cgi-bin/mailman/listinfo/lttng-dev
More information about the lttng-dev
mailing list