Skip to contentSkip to conversation

trace-cmd record: Add updates for subbuffer size

PATCH New Steven Rostedt 1 participant 3 messages Jan 10, 2024 Documentation

lore
Share & tools
lore
#0 lore raw

cover trace-cmd record: Add updates for subbuffer size

From: "Steven Rostedt (Google)" <[email protected]>

Add --subbuf-size option to trace-cmd record, and also save and restore the previous settings of what they were if they are modified.

Steven Rostedt (Google) (2):
trace-cmd record: Add --subbuf-size option trace-cmd record: Reset buffer_size and subbuf_size when done

 .../trace-cmd/trace-cmd-record.1.txt          | 15 ++++
 tracecmd/include/trace-local.h                |  3 +
 tracecmd/trace-record.c                       | 68 ++++++++++++++-----
 tracecmd/trace-usage.c                        |  1 +
 4 files changed, 71 insertions(+), 16 deletions(-)
Signature · 1 line
2.43.0
#1 lore raw

PATCH 1/2 trace-cmd record: Add --subbuf-size option

From: "Steven Rostedt (Google)" <[email protected]>

Add an option that will change the sub-buffer size if the kernel supports it.

Also change the '-b' option that changes the buffer size to use the libtracefs helper function: tracefs_instance_set_buffer_size().

---
 .../trace-cmd/trace-cmd-record.1.txt          | 15 +++++++
 tracecmd/include/trace-local.h                |  1 +
 tracecmd/trace-record.c                       | 44 ++++++++++++-------
 tracecmd/trace-usage.c                        |  1 +
 4 files changed, 45 insertions(+), 16 deletions(-)
Documentation/trace-cmd/trace-cmd-record.1.txt +15 -0
index f46b2564c73a..7cb652bc3c0c 100644
@@ -198,6 +198,21 @@ OPTIONS
     inside the kernel. Using "-b 10000" on a machine with 4 CPUs will make
     Ftrace have a total buffer size of 40 Megs.
 
+*--subbuf-size*::
+    The Linux kernel tracing ring buffer is broken up into sub-buffers.
+    These sub-buffers are typically the size of the architecture "page-size".
+    (4096 or x86). An event can only be as big as the data portion of a
+    sub-buffer, but in most cases that's not an issue. But the time the
+    writer takes to switch from one sub-buffer to the next has a bit more
+    overhead than adding events within the sub-buffer. By increasing its
+    size, it will allow bigger events (although that is seldom an issue)
+    but also speed up the tracing itself.
+
+    The downside of larger sub-buffers is that a "read" of the ring buffer
+    will pull the sub-buffer size out of the ring buffer and replace it
+    with a new sub-buffer. This may not have any real impact, but it may
+    change the behavior slightly. Or it may not!
+
 *-B* 'buffer-name'::
     If the kernel supports multiple buffers, this will add a buffer with
     the given name. If the buffer name already exists, that buffer is just
tracecmd/include/trace-local.h +1 -0
index 557b2eb0fb07..03738c518aa8 100644
@@ -286,6 +286,7 @@ struct buffer_instance {
 	int			tracing_on_init_val;
 	int			tracing_on_fd;
 	int			buffer_size;
+	int			subbuf_size;
 	int			cpu_count;
 
 	int			proxy_fd;
tracecmd/trace-record.c +28 -16

85 lines not on this page · raw message

tracecmd/trace-usage.c +1 -0
index 61acce5f18d2..6944a2c7cf29 100644
@@ -55,6 +55,7 @@ static struct usage_help usage_help[] = {
 		"          -G when profiling, set soft and hard irqs as global\n"
 		"          --quiet print no output to the screen\n"
 		"          --temp specify a directory to store the temp files used to create trace.dat\n"
+		"          --subbuf-size to specify the sub-buffer size in kilobytes\n"
 		"          --module filter module name\n"
 		"          --by-comm used with --profile, merge events for related comms\n"
 		"          --profile enable tracing options needed for report --profile\n"
Signature · 1 line
2.43.0
#2 lore raw

PATCH 2/2 trace-cmd record: Reset buffer_size and subbuf_size when done

In reply to Steven Rostedt

From: "Steven Rostedt (Google)" <[email protected]>

Save the current buffer_size_kb and subbuf_size_kb files before updating them, and put them back to what they were when finished with recording.

---
 tracecmd/include/trace-local.h |  2 ++
 tracecmd/trace-record.c        | 24 ++++++++++++++++++++++++
 2 files changed, 26 insertions(+)
tracecmd/include/trace-local.h +2 -0
index 03738c518aa8..55934f98aa32 100644
@@ -286,7 +286,9 @@ struct buffer_instance {
 	int			tracing_on_init_val;
 	int			tracing_on_fd;
 	int			buffer_size;
+	int			old_buffer_size;
 	int			subbuf_size;
+	int			old_subbuf_size;
 	int			cpu_count;
 
 	int			proxy_fd;
tracecmd/trace-record.c +24 -0
index 4646d8eb41f6..762afba4703a 100644
@@ -2522,6 +2522,26 @@ static void update_reset_triggers(void)
 	}
 }
 
+static void reset_buffer_files_instance(struct buffer_instance *instance)
+{
+	if (instance->old_buffer_size != instance->buffer_size)
+		tracefs_instance_set_buffer_size(instance->tracefs,
+						 instance->old_buffer_size, -1);
+
+	if (instance->old_subbuf_size != instance->subbuf_size)
+		tracefs_instance_set_subbuf_size(instance->tracefs,
+						 instance->old_subbuf_size);
+}
+
+static void reset_buffer_files(void)
+{
+	struct buffer_instance *instance;
+
+	for_all_instances(instance) {
+		reset_buffer_files_instance(instance);
+	}
+}
+
 static void update_reset_files(void)
 {
 	struct reset_file *reset;
@@ -2536,6 +2556,8 @@ static void update_reset_files(void)
 		free(reset->reset);
 		free(reset);
 	}
+
+	reset_buffer_files();
 }
 
 static void
@@ -5110,6 +5132,7 @@ static void set_buffer_size_instance(struct buffer_instance *instance)
 	if (buffer_size < 0)
 		die("buffer size must be positive");
 
+	instance->old_buffer_size = tracefs_instance_get_buffer_size(instance->tracefs, 0);
 	ret = tracefs_instance_set_buffer_size(instance->tracefs, buffer_size, -1);
 	if (ret < 0)
 		warning("Can't set buffer size");
@@ -5129,6 +5152,7 @@ static void set_subbuf_size_instance(struct buffer_instance *instance)
 	if (subbuf_size < 0)
 		die("sub-buffer size must be positive");
 
+	instance->old_subbuf_size = tracefs_instance_get_subbuf_size(instance->tracefs);
 	ret = tracefs_instance_set_subbuf_size(instance->tracefs, subbuf_size);
 	if (ret < 0)
 		warning("Can't set sub-buffer size");
Signature · 1 line
2.43.0