On Mon, 22 Jan 2024 17:43:32 +0100 Pierre Gondois <pierre.gondois@xxxxxxx> wrote: > To prepare handling of multiple instances, store instance > handles in a local list, similarly to what is currently > done in tracecmd/trace-read.c. > > To help achieve this goal, add a 'struct handle_list' and > add_handle()/free_handles() functions. 'struct handle' elements > are added to the static list, but not used in this patch. > > Signed-off-by: Pierre Gondois <pierre.gondois@xxxxxxx> > --- > tracecmd/trace-split.c | 60 ++++++++++++++++++++++++++++++++++++++++++ > 1 file changed, 60 insertions(+) > > diff --git a/tracecmd/trace-split.c b/tracecmd/trace-split.c > index b6c056b5..f46813d1 100644 > --- a/tracecmd/trace-split.c > +++ b/tracecmd/trace-split.c > @@ -19,10 +19,12 @@ > #include <ctype.h> > #include <errno.h> > > +#include "list.h" > #include "trace-local.h" > > static unsigned int page_size; > static const char *default_input_file = DEFAULT_INPUT_FILE; > +static const char *default_top_instance_name = "top"; > static const char *input_file; > > enum split_types { > @@ -49,6 +51,46 @@ struct cpu_data { > char *file; > }; > > +struct handle_list { > + struct list_head list; > + const char *name; > + int index; > + > + /* Identify the top instance in the input trace. */ > + bool was_top_instance; > + > + /* Identify the top instance in each output trace. */ > + bool is_top_instance; > +}; > + > +static struct list_head handle_list; > + > +static void add_handle(const char *name, int index, bool was_top_instance) > +{ > + struct handle_list *item; > + > + item = calloc(1, sizeof(*item)); > + if (!item) > + die("Failed to allocate handle item"); > + > + item->name = strdup(name); Nit, need to check for strdup() errors. -- Steve > + item->index = index; > + item->was_top_instance = was_top_instance; > + list_add_tail(&item->list, &handle_list); > +} > +