code: def merge_consecutive_self_time(frame, options):
      '''
      Combines consecutive 'self time' frames
      '''
      if frame is None:
          return None
  
      previous_self_time_frame = None
  
      for child in frame.children:
          if isinstance(child, SelfTimeFrame):
              if previous_self_time_frame:
                  # merge
                  previous_self_time_frame.self_time += child.self_time
                  child.remove_from_parent()
              else:
                  # keep a reference, maybe it'll be added to on the next loop
                  previous_self_time_frame = child
          else:
              previous_self_time_frame = None
      
      for child in frame.children:
          merge_consecutive_self_time(child, options=options)
      
      return framf merge_consecutive_self_time(frame, options):
      '''
      Combines consecutive 'self time' frames
      '''
      if frame is None:
          return None
  
      previous_self_time_frame = None
  
      for child in frame.children:
          if isinstance(child, SelfTimeFrame):
              if previous_self_time_frame:
                  # merge
                  previous_self_time_frame.self_time += child.self_time
                  child.remove_from_parent()
              else:
                  # keep a reference, maybe it'll be added to on the next loop
                  previous_self_time_frame = child
          else:
              previous_self_time_frame = None
      
      for child in frame.children:
          merge_consecutive_self_time(child, options=options)
      
      return frame
docs: Combines consecutive 'self time' frames