docstr: Execute the command-line arguments in args after instrumenting for tracing.
  
  Restore the classes to their initial state after tracing.
docstr_tok: ["Execute","the","command-line","arguments","in","args","after","instrumenting","for","tracing",".","Restore","the","classes","to","their","initial","state","after","tracing","."]
code: def trace(self, *args: Any, init_globals=None) -> Optional[dict]:
      """Execute the command-line arguments in args after instrumenting for tracing.
  
      Restore the classes to their initial state after tracing.
  
      """
      args = list(args)
      script = args[0]
      script_dir = Path(script).parent.absolute()
  
      sys_path = sys.path[:]
      sys_argv = sys.argv[:]
  
      sys.path.append(str(script_dir))
  
      sys.argv = args
  
      self._instrument()
  
      res = runpy.run_path(
          script,
          run_name="__main__",
          init_globals=init_globals or globals(),
      )
  
      self._restore()
      self._cleanup()
  
      sys.path = sys_path[:]
      sys.argv = sys_argv[:]
  
      res["tracer_res"] = self.res
  
      return res
  
file_path: pytorch-lightning/src/lightning/app/utilities/tracer.py
imports: import functools
  import inspect
  import runpy
  import sys
  import time
  from pathlib import Path
  from typing import Any, Optional
label_desc: Use image node_id 6 for calling the Tracer obj's underlying member method code with example usage: obj.trace() and returns: res