(#22581) Add test for apply profiling

Since apply doesn't need to change profiling while it is running there
is no need for it to explicitly set the profiling to NONE when it is
disabled. It can just use whatever the default for the system is.
However, since the *tests* will run in the same process we need to add a
method to Profiler to clear it back to the original state.