Skip to contentSkip to conversation

trace-cmd: Enhance "trace-cmd clear" to be instance aware

PATCH New Tzvetomir Stoyanov (VMware) 1 participant 1 message Nov 26, 2020 Documentation

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 trace-cmd: Enhance "trace-cmd clear" to be instance aware

Added new options "trace-cmd clear -B <name> -a" which allow the command to work per ftrace instance:
-B clear the given buffer (may specify multiple -B)
-a clear all existing buffers, including the top level one

---
v2 changes:
- Changed the implementation to use the latest libtracefs APIs.

 Documentation/trace-cmd-clear.1.txt |  13 ++-
 tracecmd/Makefile                   |   1 +
 tracecmd/trace-clear.c              | 126 ++++++++++++++++++++++++++++
 tracecmd/trace-record.c             |  24 ------
 tracecmd/trace-usage.c              |   4 +-
 5 files changed, 142 insertions(+), 26 deletions(-)
 create mode 100644 tracecmd/trace-clear.c
Documentation/trace-cmd-clear.1.txt +12 -1
index 67e5851a..a0ae36e9 100644
@@ -7,12 +7,23 @@ trace-cmd-clear - clear the Ftrace buffer.
 
 SYNOPSIS
 --------
-*trace-cmd clear*
+*trace-cmd clear* ['OPTIONS']
 
 DESCRIPTION
 -----------
 The *trace-cmd(1) clear* clears the content of the Ftrace ring buffer.
 
+OPTIONS
+-------
+*-B* 'buffer-name'::
+    If the kernel supports multiple buffers, this will clear only the given
+    buffer. It does not affect any other buffers. This may be used multiple
+    times to specify different buffers. The top level buffer will not be
+    clearded if this option is given.
+
+*-a*::
+    Clear all existing buffers, including the top level one.
+
 SEE ALSO
 --------
 trace-cmd(1), trace-cmd-record(1), trace-cmd-report(1), trace-cmd-start(1),
tracecmd/Makefile +1 -0
index 5e59adf8..01f36c61 100644
@@ -31,6 +31,7 @@ TRACE_CMD_OBJS += trace-show.o
 TRACE_CMD_OBJS += trace-list.o
 TRACE_CMD_OBJS += trace-usage.o
 TRACE_CMD_OBJS += trace-dump.o
+TRACE_CMD_OBJS += trace-clear.o
 ifeq ($(VSOCK_DEFINED), 1)
 TRACE_CMD_OBJS += trace-tsync.o
 endif
tracecmd/trace-clear.c new file +126 -0

126 lines not on this page · raw message

tracecmd/trace-record.c +0 -24
index 908adb93..3a63f1bd 100644
@@ -845,21 +845,6 @@ static void clear_trace_instances(void)
 		__clear_trace(instance);
 }
 
-static void clear_trace(void)
-{
-	FILE *fp;
-	char *path;
-
-	/* reset the trace */
-	path = tracefs_get_tracing_file("trace");
-	fp = fopen(path, "w");
-	if (!fp)
-		die("writing to '%s'", path);
-	tracefs_put_tracing_file(path);
-	fwrite("0", 1, 1, fp);
-	fclose(fp);
-}
-
 static void reset_max_latency(struct buffer_instance *instance)
 {
 	tracefs_instance_file_write(instance->tracefs,
@@ -6701,15 +6686,6 @@ void trace_profile(int argc, char **argv)
 	exit(0);
 }
 
-void trace_clear(int argc, char **argv)
-{
-	if (argc > 2)
-		usage(argv);
-	else
-		clear_trace();
-	exit(0);
-}
-
 void trace_record(int argc, char **argv)
 {
 	struct common_record_context ctx;
tracecmd/trace-usage.c +3 -1
index 3f0b2d07..79610bd3 100644
@@ -180,7 +180,9 @@ static struct usage_help usage_help[] = {
 	{
 		"clear",
 		"clear the trace buffers",
-		" %s clear\n"
+		" %s clear [-B buf][-a]\n"
+		"          -B clear the given buffer (may specify multiple -B)\n"
+		"          -a clear all existing buffers, including the top level one\n"
 	},
 	{
 		"report",
Signature · 1 line
2.28.0