def aggregate_repeated_calls(frame, options):
    '''
    Converts a timeline into a time-aggregate summary.
    Adds together calls along the same call stack, so that repeated calls appear as the same
    frame. Removes time-linearity - frames are sorted according to total time spent.
    Useful for outputs that display a summary of execution (e.g. text and html outputs)
    '''
    if frame is None:
        return None
    children_by_identifier = {}
    for child in frame.children:
        if child.identifier in children_by_identifier:
            aggregate_frame = children_by_identifier[child.identifier]
            aggregate_frame.self_time += child.self_time
            if child.children:
                aggregate_frame.add_children(child.children)
            child.remove_from_parent()
        else:
            children_by_identifier[child.identifier] = child
    for child in frame.children:
        aggregate_repeated_calls(child, options=options)
    frame._children.sort(key=methodcaller('time'), reverse=True)
    return frame