docstr: Modify classes by wrapping methods that need to be traced.
  
  Initialize the output trace dict.
docstr_tok: ["Modify","classes","by","wrapping","methods","that","need","to","be","traced",".","Initialize","the","output","trace","dict","."]
code: def _instrument(self):
      """Modify classes by wrapping methods that need to be traced.
  
      Initialize the output trace dict.
  
      """
      self.res = {}
      for cls, method, stack_level, pre_fn, post_fn in self.methods:
          fn = getattr(cls, method)
          # this checks if the passed function is a class method
          fn_is_class_method: bool = hasattr(fn, "__self__")
  
          if cls not in self.orig:
              self.orig[cls] = {}
          self.orig[cls][method] = fn
          wrapped_fn = wrap_fn(
              fn,
              cls,
              method,
              self.res,
              stack_level=stack_level,
              pre_fn=pre_fn,
              post_fn=post_fn,
              is_class_method=fn_is_class_method,
          )
  
          # this is needed to wrap class methods
          if fn_is_class_method:
              wrapped_fn = classmethod(wrapped_fn)
  
          setattr(cls, method, wrapped_fn)
  
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 3 for calling the Tracer obj's underlying member method code with example usage: obj._instrument() without return types