code: def get_timing_context(
      state: State, event_name: str
  ) -> Generator[Tuple[ContextManager, ContextManager], None, None]:
      """
      Returns a context manager that records an event to a :class:`~torchtnt.utils.timer.Timer` and to PyTorch Profiler.
  
      Args:
          state: an instance of :class:`~torchtnt.framework.state.State`
          event_name: string identifier to use for timing
      """
      timer_context = (
          state.timer.time(event_name)
          if state.timer is not None
          else nullcontext()
      )
      profiler_context = record_function(event_name)
      with timer_context, profiler_context:
          yield (timer_context, profiler_context)
  
imports: import logging
  from contextlib import contextmanager, nullcontext
  from typing import ContextManager, Generator, Tuple, TypeVar
  from torch.profiler import record_function
  from torchtnt.framework.state import State
label_desc: Use image node_id 1 for calling a global function with example usage: get_timing_context(state, event_name) without return types