From e9b3611fd9d989a57b1f384a4a638d5a6905b0e1 Mon Sep 17 00:00:00 2001 From: Philippe Proulx Date: Fri, 20 Sep 2019 23:34:12 -0400 Subject: [PATCH] src.ctf.fs: deterministically sort trace's DS file groups This patch makes a `src.ctf.fs` component deterministically sort its trace's DS file groups. The order of the DS file group array directly influences: * The order of the output ports. * Which DS file group gets which stream ID if the trace's packet headers do not contain a `stream_instance_id` field (automatic stream IDs). It's important that, whatever the build or file system, the component always assigns the same IDs to the same DS file group for a given trace. This can help debugging and testing. Signed-off-by: Philippe Proulx Change-Id: I105f44e7885a2974ace4d62abe0ee5384316b350 Reviewed-on: https://review.lttng.org/c/babeltrace/+/2079 Tested-by: jenkins Reviewed-by: Simon Marchi --- src/plugins/ctf/fs-src/fs.c | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/src/plugins/ctf/fs-src/fs.c b/src/plugins/ctf/fs-src/fs.c index f82ef74c..cf3cc714 100644 --- a/src/plugins/ctf/fs-src/fs.c +++ b/src/plugins/ctf/fs-src/fs.c @@ -1969,6 +1969,22 @@ end: return ret; } +static +gint compare_ds_file_groups_by_first_path(gconstpointer a, gconstpointer b) +{ + struct ctf_fs_ds_file_group * const *ds_file_group_a = a; + struct ctf_fs_ds_file_group * const *ds_file_group_b = b; + const struct ctf_fs_ds_file_info *first_ds_file_info_a; + const struct ctf_fs_ds_file_info *first_ds_file_info_b; + + BT_ASSERT((*ds_file_group_a)->ds_file_infos->len > 0); + BT_ASSERT((*ds_file_group_b)->ds_file_infos->len > 0); + first_ds_file_info_a = (*ds_file_group_a)->ds_file_infos->pdata[0]; + first_ds_file_info_b = (*ds_file_group_b)->ds_file_infos->pdata[0]; + return strcmp(first_ds_file_info_a->path->str, + first_ds_file_info_b->path->str); +} + int ctf_fs_component_create_ctf_fs_trace( struct ctf_fs_component *ctf_fs, const bt_value *paths_value, @@ -2065,6 +2081,20 @@ int ctf_fs_component_create_ctf_fs_trace( "Failed to fix packet index tracer bugs."); } + /* + * Sort data stream file groups by first data stream file info + * path to get a deterministic order. This order influences the + * order of the output ports. It also influences the order of + * the automatic stream IDs if the trace's packet headers do not + * contain a `stream_instance_id` field, in which case the data + * stream file to stream ID association is always the same, + * whatever the build and the system. + * + * Having a deterministic order here can help debugging and + * testing. + */ + g_ptr_array_sort(ctf_fs->trace->ds_file_groups, + compare_ds_file_groups_by_first_path); goto end; error: ret = -1; -- 2.34.1