Skip to contentSkip to conversation

trace-cmd split: Enable support for buffer selection

PATCH Superseded Pierre Gondois 2 participants 2 messages Feb 14, 2024 – Feb 16, 2024 Documentation

v4 of 5 Superseded Latest is v5 →

lore
Share & tools
lore
#0 lore raw

PATCH v4 1/1 trace-cmd split: Enable support for buffer selection

The 'trace-cmd split' command conserves all buffers/instances of the input .dat file. Add support to select the instances to keep:
- '--top' to keep the top instance
- '-b' top rename the top instance. Must follow '--top'.
- '-B buffer' to keep a buffer/instance
- t top promote a buffer to the top instance.
Must follow '-B'.

For example, with a trace recorded with:

  $ trace-cmd record -e sched_wakeup -B switch_instance \
    -e sched_switch

Creating a test.dat file containing the top instance and the switch_instance:

  $ trace-cmd split --top -B switch_instance -o test.dat

Creating a test.dat file containing the switch_instance as the top instance, and the initial top instance as an instance named 'old_top':

  $ trace-cmd split --top -b old_top -B switch_instance -t \
    -o test.dat

Also update the trace-usage.c and the relevant documentation for the new options.

---

Notes:

    v4:
    - Update the options as discussed at:
    https://lore.kernel.org/all/[email protected]/
 Documentation/trace-cmd/trace-cmd-split.1.txt |  25 +++
 tracecmd/trace-split.c                        | 182 ++++++++++++++++--
 tracecmd/trace-usage.c                        |   7 +
 3 files changed, 203 insertions(+), 11 deletions(-)
Documentation/trace-cmd/trace-cmd-split.1.txt +25 -0
index 25385796..d2fea252 100644
@@ -86,6 +86,31 @@ OPTIONS
 
     This will split out all the events for cpu 1 in the file.
 
+*--top*::
+    This allows to keep the top buffer.
+    The top buffer can be renamed using the '-b' option.
+
+    trace-cmd split --top
+
+    This will keep only the top buffer.
+
+    trace-cmd split --top -b old_top
+
+    This will keep only the top buffer and rename it 'old_top'.
+
+*-B* 'buffer'::
+    This allows to keep the selected buffer.
+    A buffer can be promoted to the top buffer using the '-t' option.
+
+    trace-cmd split -B timer -B sched
+
+    This will keep the 'timer' and 'sched' buffers.
+
+    trace-cmd split -B timer -t -B sched
+
+    This will keep the 'timer' and 'sched' buffers, with the events
+    from the 'timer' buffer promoted to the top instance.
+
 SEE ALSO
 --------
 trace-cmd(1), trace-cmd-record(1), trace-cmd-report(1), trace-cmd-start(1),
tracecmd/trace-split.c +171 -11

272 lines not on this page · raw message

tracecmd/trace-usage.c +7 -0
index 6944a2c7..8bbf2e3e 100644
@@ -311,6 +311,13 @@ static struct usage_help usage_help[] = {
 		"          -u n  split file up by n microseconds\n"
 		"          -e n  split file up by n events\n"
 		"          -p n  split file up by n pages\n"
+		"          -C n  select CPU n\n"
+		"          -B buffer  keep buffer in resulting .dat file\n"
+		"                     Use -t to promote the buffer to the top instance.\n"
+		"          -t    promote preceding buffer to the top instance.\n"
+		"                Must follow -B.\n"
+		"          --top keep top buffer in resulting .dat file.\n"
+		"          -b    new name of the top instance. Must follow --top.\n"
 		"          -r    repeat from start to end\n"
 		"          -c    per cpu, that is -p 2 will be 2 pages for each CPU\n"
 		"          if option is specified, it will split the file\n"
Signature · 1 line
2.25.1
#1 lore raw
Quoted 35 lines · On Wed, 14 Feb 2024 18:40:13 +0100 Pierre Gondois <[email protected]>…
tracecmd/trace-split.c +15 -4
@@ -55,13 +55,10 @@ struct handle_list {
 	struct list_head		list;
 	const char			*name;
 	int				index;
-	struct tracecmd_input 		*handle;
+	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;
@@ -120,6 +117,51 @@ static void free_handles(struct list_head *list)
 	}
 }
 
+static struct list_head inst_list;
+
+struct inst_list {
+	struct list_head		list;
+	const char			*name;
+	struct handle_list		*handle;
+
+	/* Identify the top instance in the input trace. */
+	bool				was_top_instance;
+
+	/* Identify the top instance in the output trace. */
+	bool				is_top_instance;
+};
+

tracecmd/trace-split.c static void free_handles(struct list_head *list) · line 143

Quoted 10 lines
tracecmd/trace-split.c +10 -0
+static void free_inst(struct list_head *list)
+{
+	struct inst_list *item;
+
+	while (!list_empty(list)) {
+		item = container_of(list->next, struct inst_list, list);
+		list_del(&item->list);
+		free((char *)item->name);
+		free(item);
+	}

Nit, the above could be simplified as:

	struct inst_list *item, *n;

	list_for_each_entry_safe(item, n, head, list) {
		list_del(&item->list);
		free((char *)item->name);
		free(item);
	}

That way you don't need to deal with "container_of()".

Quoted 2 lines
tracecmd/trace-split.c +2 -0
+}
+