Fix scoped Chromium event reset (#184973)
Summary:
`chromium_event_timed(..., reset_event_log_on_exit=True)` used the full
`ChromiumEventLogger.reset()` helper when the context exited. That cleared the
entire thread-local event stack, PT2 compile substack, event metadata, and
profiler record functions. If such a context ran inside an outer chromium event,
the outer start event was removed before the outer event ended, so the later end
path warned that the start event was not in the stack.
Record the logger state when entering a reset-on-exit context and restore only
to that saved state on exit. Plain `ChromiumEventLogger.reset()` still clears all
state for compile recovery, while scoped resets now clean up only events and
profiler ranges introduced by the scoped context.
The alternative was to downgrade or suppress the warning, but that would leave
the logger stack corrupted. Restoring to the entry state preserves the intended
outer event lifetime and removes only the inner scope's state.
Fixes #171148
Generated by my agent
X-link: https://github.com/pytorch/pytorch/pull/184973
Approved by: https://github.com/yushangdi
Reviewed By: jeanschmidt
Differential Revision: D107035514
fbshipit-source-id: 1b2a487505ed67820ef06ec326f05ada9254c2b5