diff mbox series

trace-cmd reset: Clear all dynamic events

Message ID 20220114105748.46761-1-tz.stoyanov@gmail.com (mailing list archive)
State Accepted
Commit 75d58b9fc8669c1fdb7ab9f94946ea2f3d4efc92
Headers show
Series trace-cmd reset: Clear all dynamic events | expand

Commit Message

Tzvetomir Stoyanov (VMware) Jan. 14, 2022, 10:57 a.m. UTC
The "trace-cmd reset" command should set ftrace state to default,
including all dynamically created events. Currently only synthetic events
are deleted. The command is enhanced to delete all dynamic events, using
the new tracefs library API for dynamic events.

Signed-off-by: Tzvetomir Stoyanov (VMware) <tz.stoyanov@gmail.com>
---
 tracecmd/trace-record.c | 43 ++++++++++-------------------------------
 1 file changed, 10 insertions(+), 33 deletions(-)

Comments

Steven Rostedt Feb. 12, 2022, 2:56 a.m. UTC | #1
On Fri, 14 Jan 2022 12:57:48 +0200
"Tzvetomir Stoyanov (VMware)" <tz.stoyanov@gmail.com> wrote:

> +	/* 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_KPROBE |
> +				     TRACEFS_DYNEVENT_KRETPROBE |
> +				     TRACEFS_DYNEVENT_UPROBE |
> +				     TRACEFS_DYNEVENT_URETPROBE |
> +				     TRACEFS_DYNEVENT_SYNTH,
> +				     true);
>  }

I accepted this patch, but really, tracefs needs something to define:

	TRACEFS_DYNEVENT_ALL

as callers should not have to call out each type of dynamic event.
Especially when we are about to add new dynamic events, causing this to
break again.

Want to add that?

Thanks Tzvetomir,

-- Steve
Tzvetomir Stoyanov (VMware) Feb. 14, 2022, 4:15 a.m. UTC | #2
On Sat, Feb 12, 2022 at 4:56 AM Steven Rostedt <rostedt@goodmis.org> wrote:
>
> On Fri, 14 Jan 2022 12:57:48 +0200
> "Tzvetomir Stoyanov (VMware)" <tz.stoyanov@gmail.com> wrote:
>
> > +     /* 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_KPROBE |
> > +                                  TRACEFS_DYNEVENT_KRETPROBE |
> > +                                  TRACEFS_DYNEVENT_UPROBE |
> > +                                  TRACEFS_DYNEVENT_URETPROBE |
> > +                                  TRACEFS_DYNEVENT_SYNTH,
> > +                                  true);
> >  }
>
> I accepted this patch, but really, tracefs needs something to define:
>
>         TRACEFS_DYNEVENT_ALL
>
> as callers should not have to call out each type of dynamic event.
> Especially when we are about to add new dynamic events, causing this to
> break again.
>
> Want to add that?
>

Sure, I'll send a patch with that.
Thanks!


> Thanks Tzvetomir,
>
> -- Steve
diff mbox series

Patch

diff --git a/tracecmd/trace-record.c b/tracecmd/trace-record.c
index b4200db1..aee3b01a 100644
--- a/tracecmd/trace-record.c
+++ b/tracecmd/trace-record.c
@@ -5221,41 +5221,18 @@  static void clear_error_log(void)
 		clear_instance_error_log(instance);
 }
 
-static void clear_all_synth_events(void)
+static void clear_all_dynamic_events(void)
 {
-	char sevent[BUFSIZ];
-	char *save = NULL;
-	char *line;
-	char *file;
-	char *buf;
-	int len;
-
-	file = tracefs_instance_get_file(NULL, "synthetic_events");
-	if (!file)
-		return;
-
-	buf = read_file(file);
-	if (!buf)
-		goto out;
-
-	sevent[0] = '!';
-
-	for (line = strtok_r(buf, "\n", &save); line; line = strtok_r(NULL, "\n", &save)) {
-		len = strlen(line);
-		if (len > BUFSIZ - 2)
-			len = BUFSIZ - 2;
-		strncpy(sevent + 1, line, len);
-		sevent[len + 1] = '\0';
-		write_file(file, sevent);
-	}
-out:
-	free(buf);
-	tracefs_put_tracing_file(file);
-
+	/* 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_KPROBE |
+				     TRACEFS_DYNEVENT_KRETPROBE |
+				     TRACEFS_DYNEVENT_UPROBE |
+				     TRACEFS_DYNEVENT_URETPROBE |
+				     TRACEFS_DYNEVENT_SYNTH,
+				     true);
 }
 
-
-
 static void clear_func_filters(void)
 {
 	struct buffer_instance *instance;
@@ -5951,7 +5928,7 @@  void trace_reset(int argc, char **argv)
 	set_buffer_size();
 	clear_filters();
 	clear_triggers();
-	clear_all_synth_events();
+	clear_all_dynamic_events();
 	clear_error_log();
 	/* set clock to "local" */
 	reset_clock();