code: def profile(
      mode: str = "interval", wait_until_completed: bool = False
  ):
      r"""Context Manager to enabling generating OS Signpost tracing from MPS backend.
  
      Args:
          mode(str): OS Signpost tracing mode could be "interval", "event",
              or both "interval,event".
              The interval mode traces the duration of execution of the operations,
              whereas event mode marks the completion of executions.
              See document `Recording Performance Data`_ for more info.
          wait_until_completed(bool): Waits until the MPS Stream complete
              executing each encoded GPU operation. This helps generating single
              dispatches on the trace's timeline.
              Note that enabling this option would affect the performance negatively.
  
      .. _Recording Performance Data:
         https://developer.apple.com/documentation/os/logging/recording_performance_data
      """
      try:
          start(mode, wait_until_completed)
          yield
      finally:
          stop()
  
imports: import contextlib
  import torch
label_desc: Use image node_id 3 for calling a global function with example usage: profile(mode, wait_until_completed) without return types