docstr: Cleanup trace by converting trace[class_name][instance_id][method_name][frame_id] to
  trace[class_name][][method_name][] thereby removing references to instance ids.
docstr_tok: ["Cleanup","trace","by","converting","trace","[","class_name","]","[","instance_id","]","[","method_name","]","[","frame_id","]","to","trace","[","class_name","]","[","]","[","method_name","]","[","]","thereby","removing","references","to","instance","ids","."]
code: def _cleanup(self):
      """Cleanup trace by converting trace[class_name][instance_id][method_name][frame_id] to
      trace[class_name][][method_name][] thereby removing references to instance ids.
      """
      out = {}
      for class_name in self.res:
          out[class_name] = []
          for self_id in self.res[class_name]:
              instance = self.res[class_name][self_id]
              out_instance = {"id": self_id}
              for method_name, method in instance.items():
                  frames = []
                  for frame_id, frame in method.items():
                      frame["id"] = frame_id
                      frames.append(frame)
                  out_instance[method_name] = frames
              out[class_name].append(out_instance)
      self.res = out
  
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 5 for calling the Tracer obj's underlying member method code with example usage: obj._cleanup() without return types