From: Pierre Gondois <pierre.gondois@arm.com>
To: Linux Trace Devel <linux-trace-devel@vger.kernel.org>
Cc: Steven Rostedt <rostedt@goodmis.org>,
Pierre Gondois <pierre.gondois@arm.com>
Subject: [PATCH v3 1/5] trace-cmd split: Store instances in local list
Date: Tue, 23 Jan 2024 14:42:11 +0100 [thread overview]
Message-ID: <20240123134215.385415-2-pierre.gondois@arm.com> (raw)
In-Reply-To: <20240123134215.385415-1-pierre.gondois@arm.com>
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@arm.com>
---
tracecmd/trace-split.c | 89 ++++++++++++++++++++++++++++++++++++++++++
1 file changed, 89 insertions(+)
diff --git a/tracecmd/trace-split.c b/tracecmd/trace-split.c
index b6c056b5..d5b77ab7 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,75 @@ struct cpu_data {
char *file;
};
+struct handle_list {
+ struct list_head list;
+ const char *name;
+ int index;
+ struct tracecmd_input *handle;
+
+ /* 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;
+
+/**
+ * get_handle - Obtain a handle that must be closed once finished.
+ */
+static struct tracecmd_input *get_handle(struct handle_list *item)
+{
+ struct tracecmd_input *top_handle, *handle;
+
+ top_handle = tracecmd_open(input_file, 0);
+ if (!top_handle)
+ die("Error reading %s", input_file);
+
+ if (item->was_top_instance) {
+ return top_handle;
+ } else {
+ handle = tracecmd_buffer_instance_handle(top_handle, item->index);
+ if (!handle)
+ warning("Could not retrieve handle %s", item->name);
+
+ tracecmd_close(top_handle);
+ return handle;
+ }
+}
+
+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);
+ if (!item->name)
+ die("Failed to duplicate %s", name);
+
+ item->index = index;
+ item->was_top_instance = was_top_instance;
+ item->handle = get_handle(item);
+ list_add_tail(&item->list, &handle_list);
+}
+
+static void free_handles(struct list_head *list)
+{
+ struct handle_list *item;
+
+ while (!list_empty(list)) {
+ item = container_of(list->next, struct handle_list, list);
+ list_del(&item->list);
+ free((char *)item->name);
+ tracecmd_close(item->handle);
+ free(item);
+ }
+}
+
static int create_type_len(struct tep_handle *pevent, int time, int len)
{
static int bigendian = -1;
@@ -450,6 +521,7 @@ void trace_split (int argc, char **argv)
char *output_file;
enum split_types split_type = SPLIT_NONE;
enum split_types type = SPLIT_NONE;
+ int instances;
int count;
int repeat = 0;
int percpu = 0;
@@ -457,6 +529,8 @@ void trace_split (int argc, char **argv)
int ac;
int c;
+ list_head_init(&handle_list);
+
if (strcmp(argv[1], "split") != 0)
usage(argv);
@@ -561,6 +635,20 @@ void trace_split (int argc, char **argv)
die("Failed to allocate for %s", output);
c = 1;
+ add_handle(default_top_instance_name, -1, true);
+ instances = tracecmd_buffer_instances(handle);
+ if (instances) {
+ const char *name;
+ int i;
+
+ for (i = 0; i < instances; i++) {
+ name = tracecmd_buffer_instance_name(handle, i);
+ if (!name)
+ die("error in reading buffer instance");
+ add_handle(name, i, false);
+ }
+ }
+
do {
if (repeat)
sprintf(output_file, "%s.%04d", output, c++);
@@ -579,6 +667,7 @@ void trace_split (int argc, char **argv)
free(output_file);
tracecmd_close(handle);
+ free_handles(&handle_list);
return;
}
--
2.25.1
next prev parent reply other threads:[~2024-01-23 13:42 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-01-23 13:42 [PATCH v3 0/5] trace-cmd: split: Handle splitting files with multiple instances Pierre Gondois
2024-01-23 13:42 ` Pierre Gondois [this message]
2024-01-23 13:42 ` [PATCH v3 2/5] trace-cmd split: Add functions to generate temp files Pierre Gondois
2024-01-23 13:42 ` [PATCH v3 3/5] trace-cmd split: Handle splitting files with multiple instances Pierre Gondois
2024-01-24 22:35 ` Steven Rostedt
2024-01-23 13:42 ` [PATCH v3 4/5] trace-cmd split: Enable support for buffer selection Pierre Gondois
2024-01-24 22:37 ` Steven Rostedt
2024-01-25 15:16 ` Pierre Gondois
2024-01-25 16:28 ` Steven Rostedt
2024-01-25 16:51 ` Steven Rostedt
2024-01-25 17:10 ` Steven Rostedt
2024-01-26 8:54 ` Pierre Gondois
2024-02-02 2:17 ` Steven Rostedt
2024-02-05 13:38 ` Pierre Gondois
2024-02-11 23:35 ` Steven Rostedt
2024-02-12 9:11 ` Pierre Gondois
2024-02-12 21:28 ` Steven Rostedt
2024-01-23 13:42 ` [PATCH v3 5/5] trace-cmd split: Update usage Pierre Gondois
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20240123134215.385415-2-pierre.gondois@arm.com \
--to=pierre.gondois@arm.com \
--cc=linux-trace-devel@vger.kernel.org \
--cc=rostedt@goodmis.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).