Re: [PATCH] perf ftrace: Restore to original trace settings on exit

Namhyung Kim
2025-05-15T18:18:15Z

Hello,

On Thu, May 15, 2025 at 01:10:56PM -0300, Arnaldo Carvalho de Melo wrote:
> On Thu, May 15, 2025 at 08:34:07AM +0200, Thomas Richter wrote:
> > Executing perf ftrace commands ftrace, profile and latency
> > leave tracing disabled as can seen in this output:
> >
> > # echo 1 > /sys/kernel/debug/tracing/tracing_on
> > # cat /sys/kernel/debug/tracing/tracing_on
> > 1
> > # perf ftrace trace --graph-opts depth=5 sleep 0.1 > /dev/null
> > # cat /sys/kernel/debug/tracing/tracing_on
> > 0
> > #
>
> > The tracing_on file is not restored to its value before the command.
> > Fix this behavior and restore the trace setting to what
> > is was before the invocation of the command.
> > On Fedora 41 and 42 tracing is turned on by default.
>
> This looks fragile as it takes a snapshot in time of what are the files
> in some particular directory to save them and then restore it at the
> end.
>
> The tool may at some point in the future go and touch other (added in
> the future) files in that directory, etc.
>
> I _think_ that instead we should move to use some "session mode" ftrace,
> which I _think_ is already available for quite some time, i.e. instead
> of touching the global ftrace files (which probably are there for
> historical reasons), we should use, lemme find the reference...
>
> I think the keyword to lookup is /sys/kernel/debug/tracing/instances/
>
> Ian did a lot of work on having 'perf test' run shell tests in parallel,
> so we need to think about ways of allowing for that by not touching
> global state.
>
> tldr; great idea, avoid global state.

Right, by using an tracing instance, you don't need to worry about the
original states.

Thanks,
Namhyung