Skip to contentSkip to conversation

trace-cmd reset: Add option to preserve specific events

PATCH Superseded Metin Kaya 2 participants 5 messages Oct 10, 2024 – Oct 14, 2024

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore

Metin Kaya

author
#0 lore raw

cover trace-cmd reset: Add option to preserve specific events

We may want to preserve some of the dynamic events (e.g., kprobes) during a "trace-cmd reset" in some cases as discussed at [1]. Thus, introduce a new command line option to "trace-cmd reset" to permit sustaining specified events across reset.

To implement the necessary support, address a corner case in command line option parsing handler in "trace-cmd reset" first. Because all dynamic events gets destroyed even if the user passes an invalid parameter to "trace-cmd reset".

Here is an example usage with the new command line option (-k):

    # trace-cmd reset -h

trace-cmd version 3.3.0 (e4047ab9dfe261402e487a825bf79d04f10f5544+)

usage:
trace-cmd reset [-b size][-B buf][-k event][-a][-d][-t]
Disables the tracer (may reset trace file)
Used in conjunction with start
-b change the kernel buffer size (in kilobytes per CPU) -d delete the previous specified instance
-B reset the given buffer instance (may specify multiple -B) -a reset all instances (except top one)
-t reset the top level instance (useful with -B or -a) -k keep dynamic event during reset. Valid values:
'kprobe', 'kretprobe', 'uprobe', 'uretprobe', 'eprobe', 'synth' and 'all'.

# Add kprobe and kretprobe for sys_open():
$ echo 'p do_sys_open' > /sys/kernel/tracing/kprobe_events $ echo 1 > /sys/kernel/tracing/events/kprobes/p_do_sys_open_0/enable $ echo 'r do_sys_open' >> /sys/kernel/tracing/kprobe_events $ echo 1 > /sys/kernel/tracing/events/kprobes/r_do_sys_open_0/enable $ cat /sys/kernel/tracing/kprobe_events p:kprobes/p_do_sys_open_0 do_sys_open r128:kprobes/r_do_sys_open_0 do_sys_open

# Issue reset, but keep kprobes and kretprobes ('-k all' would keep # all existing dynamic events):
$ trace-cmd reset -k kprobe -k kretprobe
$ cat /sys/kernel/tracing/kprobe_events p:kprobes/p_do_sys_open_0 do_sys_open r128:kprobes/r_do_sys_open_0 do_sys_open

# Issue reset, but this time only keep kretprobes:
$ trace-cmd reset -k kretprobe
$ cat /sys/kernel/tracing/kprobe_events r128:kprobes/r_do_sys_open_0 do_sys_open

# Don't preserve any dynamic event:
$ trace-cmd reset
$ cat /sys/kernel/tracing/kprobe_events
$

[1] https://bugzilla.kernel.org/show_bug.cgi?id=219302

Metin Kaya (2):
trace-cmd reset: Bail out immediately if user provides an invalid
option
trace-cmd reset: Add option to preserve specific dynamic events

 tracecmd/trace-record.c | 62 +++++++++++++++++++++++++++++++++++++----
 tracecmd/trace-usage.c  |  5 +++-
 2 files changed, 60 insertions(+), 7 deletions(-)
Signature · 1 line
2.34.1
author
#1 lore raw

PATCH 1/2 trace-cmd reset: Bail out immediately if user provides an invalid option

trace_reset() does not care invalid command line options and carries on execution. For instance, "trace-cmd reset -x" command successfully completes the reset request (despite of "reset: invalid option -- 'x'" warning). Thus, show the usage message and terminate execution instead of running the reset routine.

---
 tracecmd/trace-record.c | 3 +++
 1 file changed, 3 insertions(+)
tracecmd/trace-record.c +3 -0
index 3c705270..c695cd23 100644
@@ -6102,6 +6102,9 @@ void trace_reset(int argc, char **argv)
 				instance->flags &= ~BUFFER_FL_KEEP;
 			}
 			break;
+		default:
+			usage(argv);
+			break;
 		}
 	}
 	update_first_instance(instance, topt);
Signature · 1 line
2.34.1
author
#2 lore raw

PATCH 2/2 trace-cmd reset: Add option to preserve specific dynamic events

In reply to Metin Kaya

One may want to preserve some of the dynamic events (e.g., kprobes) during a trace-cmd reset. Thus, provide -k command line option for trace-cmd reset to allow keeping specified events untouched during the reset operation.

For example, it's possible to prevent kprobes & kretprobes from being destroyed in trace-cmd reset with this patch:

# Add kprobe and kretprobe for sys_open():
$ echo 'p do_sys_open' > /sys/kernel/tracing/kprobe_events $ echo 1 > /sys/kernel/tracing/events/kprobes/p_do_sys_open_0/enable $ echo 'r do_sys_open' >> /sys/kernel/tracing/kprobe_events $ echo 1 > /sys/kernel/tracing/events/kprobes/r_do_sys_open_0/enable $ cat /sys/kernel/tracing/kprobe_events p:kprobes/p_do_sys_open_0 do_sys_open r128:kprobes/r_do_sys_open_0 do_sys_open

# Issue reset, but keep kprobes and kretprobes ('-k all' would keep # all existing dynamic events):
$ trace-cmd reset -k kprobe -k kretprobe
$ cat /sys/kernel/tracing/kprobe_events p:kprobes/p_do_sys_open_0 do_sys_open r128:kprobes/r_do_sys_open_0 do_sys_open

# Issue reset, but this time only keep kretprobes:
$ trace-cmd reset -k kretprobe
$ cat /sys/kernel/tracing/kprobe_events r128:kprobes/r_do_sys_open_0 do_sys_open

# Don't preserve any dynamic event:
$ trace-cmd reset
$ cat /sys/kernel/tracing/kprobe_events
$

Bugzilla: https://bugzilla.kernel.org/show_bug.cgi?id=219302

---
 tracecmd/trace-record.c | 59 ++++++++++++++++++++++++++++++++++++-----
 tracecmd/trace-usage.c  |  5 +++-
 2 files changed, 57 insertions(+), 7 deletions(-)
tracecmd/trace-record.c +53 -6
index c695cd23..f80b386f 100644
@@ -5399,11 +5399,15 @@ static void clear_error_log(void)
 		clear_instance_error_log(instance);
 }
 
-static void clear_all_dynamic_events(void)
+static void clear_all_dynamic_events(unsigned int exclude_types)
 {
-	/* Clear event probes first, as they may be attached to other dynamic event */
-	tracefs_dynevent_destroy_all(TRACEFS_DYNEVENT_EPROBE, true);
-	tracefs_dynevent_destroy_all(TRACEFS_DYNEVENT_ALL, true);
+	/*
+	 * Clear event probes first (if they are not excluded), as they may be
+	 * attached to other dynamic event.
+	 */
+	if (!(TRACEFS_DYNEVENT_EPROBE & exclude_types))
+		tracefs_dynevent_destroy_all(TRACEFS_DYNEVENT_EPROBE, true);
+	tracefs_dynevent_destroy_all(TRACEFS_DYNEVENT_ALL & ~exclude_types, true);
 }
 
 static void clear_func_filters(void)
@@ -6036,11 +6040,51 @@ void trace_restart(int argc, char **argv)
 	exit(0);
 }
 
+/**
+ * find_dynevent_type - Find string formatted dynamic event type
+ *			in "enum tracefs_dynevent_type".
+ *
+ * @type: Dynamic event type in string format.
+ *
+ * Returns an unsigned int value for the event specified in @type.
+ */
+static unsigned int find_dynevent_type(const char *type)
+{
+	/* WARN: Should be kept in sync with "enum tracefs_dynevent_type". */
+	if (!strcmp(type, "kprobe"))
+		return TRACEFS_DYNEVENT_KPROBE;
+	else if (!strcmp(type, "kretprobe"))
+		return TRACEFS_DYNEVENT_KRETPROBE;
+	else if (!strcmp(type, "uprobe"))
+		return TRACEFS_DYNEVENT_UPROBE;
+	else if (!strcmp(type, "uretprobe"))
+		return TRACEFS_DYNEVENT_URETPROBE;
+	else if (!strcmp(type, "eprobe"))
+		return TRACEFS_DYNEVENT_EPROBE;
+	else if (!strcmp(type, "synth"))
+		return TRACEFS_DYNEVENT_SYNTH;
+	else if (!strcmp(type, "all"))
+		/*
+		 * Unfortunately TRACEFS_DYNEVENT_ALL does not work here.
+		 * Because tracefs_dynevent_destroy_all() assumes 0 means all
+		 * and destroys all dynamic events.
+		 */
+		return (TRACEFS_DYNEVENT_KPROBE |
+			TRACEFS_DYNEVENT_KRETPROBE |
+			TRACEFS_DYNEVENT_UPROBE |
+			TRACEFS_DYNEVENT_URETPROBE |
+			TRACEFS_DYNEVENT_EPROBE |
+			TRACEFS_DYNEVENT_SYNTH);
+	else
+		die("Invalid event type '%s'!\n", type);
+}
+
 void trace_reset(int argc, char **argv)
 {
 	int c;
 	int topt = 0;
 	struct buffer_instance *instance = &top_instance;
+	unsigned int excluded_types = 0;
 
 	init_top_instance();
 
@@ -6048,7 +6092,7 @@ void trace_reset(int argc, char **argv)
 	int last_specified_all = 0;
 	struct buffer_instance *inst; /* iterator */
 
-	while ((c = getopt(argc-1, argv+1, "hab:B:td")) >= 0) {
+	while ((c = getopt(argc-1, argv+1, "hab:B:tdk:")) >= 0) {
 
 		switch (c) {
 		case 'h':
@@ -6102,6 +6146,9 @@ void trace_reset(int argc, char **argv)
 				instance->flags &= ~BUFFER_FL_KEEP;
 			}
 			break;
+		case 'k':
+			excluded_types |= find_dynevent_type(optarg);
+			break;
 		default:
 			usage(argv);
 			break;
@@ -6112,7 +6159,7 @@ void trace_reset(int argc, char **argv)
 	set_buffer_size();
 	clear_filters();
 	clear_triggers();
-	clear_all_dynamic_events();
+	clear_all_dynamic_events(excluded_types);
 	clear_error_log();
 	/* set clock to "local" */
 	reset_clock();
tracecmd/trace-usage.c +4 -1
index 8bbf2e3e..f159e5e1 100644
@@ -193,7 +193,7 @@ static struct usage_help usage_help[] = {
 	{
 		"reset",
 		"disable all kernel tracing and clear the trace buffers",
-		" %s reset [-b size][-B buf][-a][-d][-t]\n"
+		" %s reset [-b size][-B buf][-k event][-a][-d][-t]\n"
 		"          Disables the tracer (may reset trace file)\n"
 		"          Used in conjunction with start\n"
 		"          -b change the kernel buffer size (in kilobytes per CPU)\n"
@@ -201,6 +201,9 @@ static struct usage_help usage_help[] = {
 		"          -B reset the given buffer instance (may specify multiple -B)\n"
 		"          -a reset all instances (except top one)\n"
 		"          -t reset the top level instance (useful with -B or -a)\n"
+		"          -k keep dynamic event during reset. Valid values are:\n"
+		"              'kprobe', 'kretprobe', 'uprobe', 'uretprobe',\n"
+		"              'eprobe', 'synth' and 'all'.\n"
 	},
 	{
 		"clear",
Signature · 1 line
2.34.1
#3 lore raw

Re: [PATCH 2/2] trace-cmd reset: Add option to preserve specific dynamic events

On Thu, 10 Oct 2024 09:53:50 +0100
Metin Kaya <[email protected]> wrote:

Hi Metin,

Quoted 50 lines

One may want to preserve some of the dynamic events (e.g., kprobes) during a trace-cmd reset. Thus, provide -k command line option for trace-cmd reset to allow keeping specified events untouched during the reset operation.

For example, it's possible to prevent kprobes & kretprobes from being destroyed in trace-cmd reset with this patch:

# Add kprobe and kretprobe for sys_open():
$ echo 'p do_sys_open' > /sys/kernel/tracing/kprobe_events $ echo 1 > /sys/kernel/tracing/events/kprobes/p_do_sys_open_0/enable $ echo 'r do_sys_open' >> /sys/kernel/tracing/kprobe_events $ echo 1 > /sys/kernel/tracing/events/kprobes/r_do_sys_open_0/enable $ cat /sys/kernel/tracing/kprobe_events p:kprobes/p_do_sys_open_0 do_sys_open r128:kprobes/r_do_sys_open_0 do_sys_open

# Issue reset, but keep kprobes and kretprobes ('-k all' would keep # all existing dynamic events):
$ trace-cmd reset -k kprobe -k kretprobe
$ cat /sys/kernel/tracing/kprobe_events p:kprobes/p_do_sys_open_0 do_sys_open r128:kprobes/r_do_sys_open_0 do_sys_open

# Issue reset, but this time only keep kretprobes:
$ trace-cmd reset -k kretprobe
$ cat /sys/kernel/tracing/kprobe_events r128:kprobes/r_do_sys_open_0 do_sys_open

# Don't preserve any dynamic event:
$ trace-cmd reset
$ cat /sys/kernel/tracing/kprobe_events
$

Bugzilla: https://bugzilla.kernel.org/show_bug.cgi?id=219302

---
 tracecmd/trace-record.c | 59 ++++++++++++++++++++++++++++++++++++-----
 tracecmd/trace-usage.c  |  5 +++-
 2 files changed, 57 insertions(+), 7 deletions(-)
tracecmd/trace-record.c +0 -1
index c695cd23..f80b386f 100644
@@ -5399,11 +5399,15 @@ static void clear_error_log(void)
 		clear_instance_error_log(instance);
 }
 
-static void clear_all_dynamic_events(void)

tracecmd/trace-record.c static void clear_error_log(void) · line 5408

Quoted 10 lines
tracecmd/trace-record.c +6 -3
+static void clear_all_dynamic_events(unsigned int exclude_types)
 {
-	/* Clear event probes first, as they may be attached to other dynamic event */
-	tracefs_dynevent_destroy_all(TRACEFS_DYNEVENT_EPROBE, true);
-	tracefs_dynevent_destroy_all(TRACEFS_DYNEVENT_ALL, true);
+	/*
+	 * Clear event probes first (if they are not excluded), as they may be
+	 * attached to other dynamic event.
+	 */
+	if (!(TRACEFS_DYNEVENT_EPROBE & exclude_types))

BTW, I prefer the variable first notation. Not "FLAG & var", but "var & FLAG" as that's the way I read it in English. I read it as "exclude_types has TRACEFS_DYNEVENT_EPROBE set" but the way it is written it sounds like: "TRACEFS_DYNEVENT_EPROBE has exclude_types set" in my head, and that confuses me.

Quoted 34 lines
tracecmd/trace-record.c +27 -0
+		tracefs_dynevent_destroy_all(TRACEFS_DYNEVENT_EPROBE, true);
+	tracefs_dynevent_destroy_all(TRACEFS_DYNEVENT_ALL & ~exclude_types, true);
 }
 
 static void clear_func_filters(void)
@@ -6036,11 +6040,51 @@ void trace_restart(int argc, char **argv)
 	exit(0);
 }
 
+/**
+ * find_dynevent_type - Find string formatted dynamic event type
+ *			in "enum tracefs_dynevent_type".
+ *
+ * @type: Dynamic event type in string format.
+ *
+ * Returns an unsigned int value for the event specified in @type.
+ */
+static unsigned int find_dynevent_type(const char *type)
+{
+	/* WARN: Should be kept in sync with "enum tracefs_dynevent_type". */
+	if (!strcmp(type, "kprobe"))
+		return TRACEFS_DYNEVENT_KPROBE;
+	else if (!strcmp(type, "kretprobe"))
+		return TRACEFS_DYNEVENT_KRETPROBE;
+	else if (!strcmp(type, "uprobe"))
+		return TRACEFS_DYNEVENT_UPROBE;
+	else if (!strcmp(type, "uretprobe"))
+		return TRACEFS_DYNEVENT_URETPROBE;
+	else if (!strcmp(type, "eprobe"))
+		return TRACEFS_DYNEVENT_EPROBE;
+	else if (!strcmp(type, "synth"))
+		return TRACEFS_DYNEVENT_SYNTH;
+	else if (!strcmp(type, "all"))
+		/*

tracecmd/trace-record.c void trace_restart(int argc, char **argv) · line 6077

Quoted 10 lines
tracecmd/trace-record.c +10 -0
+		 * Unfortunately TRACEFS_DYNEVENT_ALL does not work here.
+		 * Because tracefs_dynevent_destroy_all() assumes 0 means all
+		 * and destroys all dynamic events.
+		 */
+		return (TRACEFS_DYNEVENT_KPROBE |
+			TRACEFS_DYNEVENT_KRETPROBE |
+			TRACEFS_DYNEVENT_UPROBE |
+			TRACEFS_DYNEVENT_URETPROBE |
+			TRACEFS_DYNEVENT_EPROBE |
+			TRACEFS_DYNEVENT_SYNTH);

return is not a function. You don't need the parenthesis.

Quoted 55 lines
tracecmd/trace-record.c +10 -2
+	else
+		die("Invalid event type '%s'!\n", type);
+}
+
 void trace_reset(int argc, char **argv)
 {
 	int c;
 	int topt = 0;
 	struct buffer_instance *instance = &top_instance;
+	unsigned int excluded_types = 0;
 
 	init_top_instance();
 
@@ -6048,7 +6092,7 @@ void trace_reset(int argc, char **argv)
 	int last_specified_all = 0;
 	struct buffer_instance *inst; /* iterator */
 
-	while ((c = getopt(argc-1, argv+1, "hab:B:td")) >= 0) {
+	while ((c = getopt(argc-1, argv+1, "hab:B:tdk:")) >= 0) {
 
 		switch (c) {
 		case 'h':
@@ -6102,6 +6146,9 @@ void trace_reset(int argc, char **argv)
 				instance->flags &= ~BUFFER_FL_KEEP;
 			}
 			break;
+		case 'k':
+			excluded_types |= find_dynevent_type(optarg);
+			break;
 		default:
 			usage(argv);
 			break;
@@ -6112,7 +6159,7 @@ void trace_reset(int argc, char **argv)
 	set_buffer_size();
 	clear_filters();
 	clear_triggers();
-	clear_all_dynamic_events();
+	clear_all_dynamic_events(excluded_types);
 	clear_error_log();
 	/* set clock to "local" */
 	reset_clock();
tracecmd/trace-usage.c +1 -1
index 8bbf2e3e..f159e5e1 100644
@@ -193,7 +193,7 @@ static struct usage_help usage_help[] = {
 	{
 		"reset",
 		"disable all kernel tracing and clear the trace buffers",
-		" %s reset [-b size][-B buf][-a][-d][-t]\n"
+		" %s reset [-b size][-B buf][-k event][-a][-d][-t]\n"
 		"          Disables the tracer (may reset trace file)\n"
 		"          Used in conjunction with start\n"
 		"          -b change the kernel buffer size (in kilobytes per CPU)\n"

tracecmd/trace-usage.c static struct usage_help usage_help[] = { · line 209

Quoted 9 lines
tracecmd/trace-usage.c +3 -0
@@ -201,6 +201,9 @@ static struct usage_help usage_help[] = {
 		"          -B reset the given buffer instance (may specify multiple -B)\n"
 		"          -a reset all instances (except top one)\n"
 		"          -t reset the top level instance (useful with -B or -a)\n"
+		"          -k keep dynamic event during reset. Valid values are:\n"
+		"              'kprobe', 'kretprobe', 'uprobe', 'uretprobe',\n"
+		"              'eprobe', 'synth' and 'all'.\n"
 	},
 	{
 		"clear",

Could you send a patch that updates the man page:

Documentation/trace-cmd/trace-cmd-reset.1.txt

As well as one that handles bash completion, so people don't need to remember what to type.

tracecmd/trace-cmd.bash

Thanks,

-- Steve

author
#4 lore raw

Re: [PATCH 2/2] trace-cmd reset: Add option to preserve specific dynamic events

On 12/10/2024 12:54 am, Steven Rostedt wrote:

Hey Steve,

Quoted 63 lines

On Thu, 10 Oct 2024 09:53:50 +0100
Metin Kaya <[email protected]> wrote:

Hi Metin,

Quoted 58 lines

One may want to preserve some of the dynamic events (e.g., kprobes) during a trace-cmd reset. Thus, provide -k command line option for trace-cmd reset to allow keeping specified events untouched during the reset operation.

For example, it's possible to prevent kprobes & kretprobes from being destroyed in trace-cmd reset with this patch:

# Add kprobe and kretprobe for sys_open():
$ echo 'p do_sys_open' > /sys/kernel/tracing/kprobe_events $ echo 1 > /sys/kernel/tracing/events/kprobes/p_do_sys_open_0/enable $ echo 'r do_sys_open' >> /sys/kernel/tracing/kprobe_events $ echo 1 > /sys/kernel/tracing/events/kprobes/r_do_sys_open_0/enable $ cat /sys/kernel/tracing/kprobe_events p:kprobes/p_do_sys_open_0 do_sys_open r128:kprobes/r_do_sys_open_0 do_sys_open

# Issue reset, but keep kprobes and kretprobes ('-k all' would keep # all existing dynamic events):
$ trace-cmd reset -k kprobe -k kretprobe
$ cat /sys/kernel/tracing/kprobe_events p:kprobes/p_do_sys_open_0 do_sys_open r128:kprobes/r_do_sys_open_0 do_sys_open

# Issue reset, but this time only keep kretprobes:
$ trace-cmd reset -k kretprobe
$ cat /sys/kernel/tracing/kprobe_events r128:kprobes/r_do_sys_open_0 do_sys_open

# Don't preserve any dynamic event:
$ trace-cmd reset
$ cat /sys/kernel/tracing/kprobe_events
$

Bugzilla: https://bugzilla.kernel.org/show_bug.cgi?id=219302

---
  tracecmd/trace-record.c | 59 ++++++++++++++++++++++++++++++++++++-----
  tracecmd/trace-usage.c  |  5 +++-
  2 files changed, 57 insertions(+), 7 deletions(-)
tracecmd/trace-record.c +4 -4
index c695cd23..f80b386f 100644
@@ -5399,11 +5399,15 @@ static void clear_error_log(void)
             clear_instance_error_log(instance);
  }
 
-static void clear_all_dynamic_events(void)
+static void clear_all_dynamic_events(unsigned int exclude_types)
  {
-    /* Clear event probes first, as they may be attached to other dynamic event */
-    tracefs_dynevent_destroy_all(TRACEFS_DYNEVENT_EPROBE, true);
-    tracefs_dynevent_destroy_all(TRACEFS_DYNEVENT_ALL, true);
+    /*
+     * Clear event probes first (if they are not excluded), as they may be
+     * attached to other dynamic event.
Quoted 8 lines

tracecmd/trace-record.c static void clear_error_log(void) · line 5408

Quoted 2 lines
tracecmd/trace-record.c +2 -0
+     */
+    if (!(TRACEFS_DYNEVENT_EPROBE & exclude_types))

BTW, I prefer the variable first notation. Not "FLAG & var", but "var & FLAG" as that's the way I read it in English. I read it as "exclude_types has TRACEFS_DYNEVENT_EPROBE set" but the way it is written it sounds like: "TRACEFS_DYNEVENT_EPROBE has exclude_types set" in my head, and that confuses me.

Gotcha. Will fix the ordering to ease reading.

Quoted 39 lines
Quoted 39 lines
tracecmd/trace-record.c +31 -0
+            tracefs_dynevent_destroy_all(TRACEFS_DYNEVENT_EPROBE, true);
+    tracefs_dynevent_destroy_all(TRACEFS_DYNEVENT_ALL & ~exclude_types, true);
  }
 
  static void clear_func_filters(void)
@@ -6036,11 +6040,51 @@ void trace_restart(int argc, char **argv)
     exit(0);
  }
 
+/**
+ * find_dynevent_type - Find string formatted dynamic event type
+ *                  in "enum tracefs_dynevent_type".
+ *
+ * @type: Dynamic event type in string format.
+ *
+ * Returns an unsigned int value for the event specified in @type.
+ */
+static unsigned int find_dynevent_type(const char *type)
+{
+    /* WARN: Should be kept in sync with "enum tracefs_dynevent_type". */
+    if (!strcmp(type, "kprobe"))
+            return TRACEFS_DYNEVENT_KPROBE;
+    else if (!strcmp(type, "kretprobe"))
+            return TRACEFS_DYNEVENT_KRETPROBE;
+    else if (!strcmp(type, "uprobe"))
+            return TRACEFS_DYNEVENT_UPROBE;
+    else if (!strcmp(type, "uretprobe"))
+            return TRACEFS_DYNEVENT_URETPROBE;
+    else if (!strcmp(type, "eprobe"))
+            return TRACEFS_DYNEVENT_EPROBE;
+    else if (!strcmp(type, "synth"))
+            return TRACEFS_DYNEVENT_SYNTH;
+    else if (!strcmp(type, "all"))
+            /*
+             * Unfortunately TRACEFS_DYNEVENT_ALL does not work here.
+             * Because tracefs_dynevent_destroy_all() assumes 0 means all
+             * and destroys all dynamic events.
+             */
Quoted 8 lines

tracecmd/trace-record.c void trace_restart(int argc, char **argv) · line 6077

Quoted 6 lines
tracecmd/trace-record.c +6 -0
+            return (TRACEFS_DYNEVENT_KPROBE |
+                    TRACEFS_DYNEVENT_KRETPROBE |
+                    TRACEFS_DYNEVENT_UPROBE |
+                    TRACEFS_DYNEVENT_URETPROBE |
+                    TRACEFS_DYNEVENT_EPROBE |
+                    TRACEFS_DYNEVENT_SYNTH);

return is not a function. You don't need the parenthesis.

Sure. Removed them.

Quoted 68 lines
Quoted 56 lines
tracecmd/trace-record.c +10 -2
+    else
+            die("Invalid event type '%s'!\n", type);
+}
+
  void trace_reset(int argc, char **argv)
  {
     int c;
     int topt = 0;
     struct buffer_instance *instance = &top_instance;
+    unsigned int excluded_types = 0;
 
     init_top_instance();
 
@@ -6048,7 +6092,7 @@ void trace_reset(int argc, char **argv)
     int last_specified_all = 0;
     struct buffer_instance *inst; /* iterator */
 
-    while ((c = getopt(argc-1, argv+1, "hab:B:td")) >= 0) {
+    while ((c = getopt(argc-1, argv+1, "hab:B:tdk:")) >= 0) {
 
             switch (c) {
             case 'h':
@@ -6102,6 +6146,9 @@ void trace_reset(int argc, char **argv)
                             instance->flags &= ~BUFFER_FL_KEEP;
                     }
                     break;
+            case 'k':
+                    excluded_types |= find_dynevent_type(optarg);
+                    break;
             default:
                     usage(argv);
                     break;
@@ -6112,7 +6159,7 @@ void trace_reset(int argc, char **argv)
     set_buffer_size();
     clear_filters();
     clear_triggers();
-    clear_all_dynamic_events();
+    clear_all_dynamic_events(excluded_types);
     clear_error_log();
     /* set clock to "local" */
     reset_clock();
tracecmd/trace-usage.c +1 -1
index 8bbf2e3e..f159e5e1 100644
@@ -193,7 +193,7 @@ static struct usage_help usage_help[] = {
     {
             "reset",
             "disable all kernel tracing and clear the trace buffers",
-            " %s reset [-b size][-B buf][-a][-d][-t]\n"
+            " %s reset [-b size][-B buf][-k event][-a][-d][-t]\n"
             "          Disables the tracer (may reset trace file)\n"
             "          Used in conjunction with start\n"
             "          -b change the kernel buffer size (in kilobytes per CPU)\n"

tracecmd/trace-usage.c static struct usage_help usage_help[] = { · line 209

Quoted 9 lines
tracecmd/trace-usage.c +3 -0
@@ -201,6 +201,9 @@ static struct usage_help usage_help[] = {
             "          -B reset the given buffer instance (may specify multiple -B)\n"
             "          -a reset all instances (except top one)\n"
             "          -t reset the top level instance (useful with -B or -a)\n"
+            "          -k keep dynamic event during reset. Valid values are:\n"
+            "              'kprobe', 'kretprobe', 'uprobe', 'uretprobe',\n"
+            "              'eprobe', 'synth' and 'all'.\n"
     },
     {
             "clear",

Could you send a patch that updates the man page:

Quoted 6 lines

Documentation/trace-cmd/trace-cmd-reset.1.txt

As well as one that handles bash completion, so people don't need to remember what to type.

tracecmd/trace-cmd.bash

Ah, missed that part. Sorry.

Thanks a lot for the review.
Will post v2 in a short while.

Quoted 5 lines

Thanks,

-- Steve

IMPORTANT NOTICE: The contents of this email and any attachments are confidential and may also be privileged. If you are not the intended recipient, please notify the sender immediately and do not disclose the contents to any other person, use it for any purpose, or store or copy the information in any medium. Thank you.