How to use the pyinstrument.frame.SelfTimeFrame function in pyinstrument

To help you get started, we’ve selected a few pyinstrument examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github joerick / pyinstrument / test / test_processors.py View on Github external
def test_merge_consecutive_self_time():
    frame = Frame(
        identifier='\x00cibuildwheel/__init__.py\x0012',
        children=[
            Frame(
                identifier='strip_newlines\x00cibuildwheel/utils.py\x00997',
                self_time=0.1),
            SelfTimeFrame(
                self_time=0.2,
            ),
            SelfTimeFrame(
                self_time=0.1,
            ),
            Frame(
                identifier='calculate_metrics\x00cibuildwheel/utils.py\x007',
                self_time=0.1),
            SelfTimeFrame(
                self_time=0.05,
            ),
        ]
    )

    assert frame.time() == approx(0.55)
github joerick / pyinstrument / test / test_processors.py View on Github external
identifier='library_inner\x00env/lib/python3.6/django/http.py\x0054',
                        children=[
                            Frame(
                                identifier='library_callback\x00env/lib/python3.6/django/views.py\x0054',
                                children=[
                                    Frame(
                                        identifier='\x00cibuildwheel/views.py\x0012',
                                        self_time=0.3,
                                    ),
                                ]
                            ),
                        ]
                    ),
                ]
            ),
            SelfTimeFrame(
                self_time=0.5,
            ),
            Frame(
                identifier='strip_newlines\x00cibuildwheel/utils.py\x00997',
                self_time=0.5,
            ),
            Frame(
                identifier='calculate_metrics\x00cibuildwheel/utils.py\x007',
                self_time=0.1,
            ),
        ]
    )

    assert frame.time() == approx(1.4)

    frame = processors.group_library_frames_processor(frame, options={})
github joerick / pyinstrument / test / test_processors.py View on Github external
def test_remove_irrelevant_nodes():
    frame = Frame(
        identifier='\x00cibuildwheel/__init__.py\x0012',
        children=[
            Frame(
                identifier='strip_newlines\x00cibuildwheel/utils.py\x00997',
                children=[
                    Frame(
                        identifier='scan_string\x00cibuildwheel/utils.py\x0054',
                        self_time=10,
                    ),
                ]
            ),
            SelfTimeFrame(
                self_time=0.5,
            ),
            Frame(
                identifier='strip_newlines\x00cibuildwheel/utils.py\x00997',
                self_time=0.5,
            ),
            Frame(
                identifier='calculate_metrics\x00cibuildwheel/utils.py\x007',
                self_time=0.01,
            ),
        ]
    )

    assert frame.time() == approx(11.01)

    frame = processors.remove_irrelevant_nodes(frame, options={})
github joerick / pyinstrument / test / test_processors.py View on Github external
def test_remove_unnecessary_self_time_nodes():
    frame = Frame(
        identifier='\x00cibuildwheel/__init__.py\x0012',
        children=[
            Frame(
                identifier='strip_newlines\x00cibuildwheel/utils.py\x00997',
                children=[
                    SelfTimeFrame(
                        self_time=0.2,
                    ),
                ]
            ),
            SelfTimeFrame(
                self_time=0.5,
            ),
            Frame(
                identifier='strip_newlines\x00cibuildwheel/utils.py\x00997',
                self_time=0.5,
            ),
            Frame(
                identifier='calculate_metrics\x00cibuildwheel/utils.py\x007',
                self_time=0.1,
            ),
        ]
    )

    assert frame.time() == approx(1.3)

    frame = processors.remove_unnecessary_self_time_nodes(frame, options={})
github joerick / pyinstrument / test / test_processors.py View on Github external
),
            SelfTimeFrame(
                self_time=0.1,
            ),
            Frame(
                identifier='strip_newlines\x00cibuildwheel/utils.py\x00997',
                self_time=0.1,
            ),
            SelfTimeFrame(
                self_time=0.2,
            ),
            Frame(
                identifier='calculate_metrics\x00cibuildwheel/utils.py\x007',
                self_time=0.1,
            ),
            SelfTimeFrame(
                self_time=0.05,
            ),
        ]
    )

    assert frame.time() == approx(0.85)

    frame = processors.aggregate_repeated_calls(frame, options={})

    assert frame.time() == approx(0.85)
    # children should be sorted by time
    assert len(frame.children) == 3
    assert frame.children[0].function == 'strip_newlines'
    assert frame.children[0].time() == 0.4
    assert frame.children[0].children[0].function == 'scan_string'
    assert isinstance(frame.children[1], SelfTimeFrame)
github joerick / pyinstrument / pyinstrument / session.py View on Github external
frame = Frame(frame_identifier)
                    frame_stack.append(frame)
                    
                    if stack_depth == 0:
                        # There should only be one root frame, as far as I know
                        assert root_frame is None, ASSERTION_MESSAGE
                        root_frame = frame
                    else:
                        parent = frame_stack[stack_depth-1]
                        parent.add_child(frame)

            # trim any extra frames
            del frame_stack[stack_depth+1:]  # pylint: disable=W0631

            # assign the time to the final frame
            frame_stack[-1].add_child(SelfTimeFrame(self_time=time))
        
        if root_frame is None:
            return None
        
        if trim_stem:
            root_frame = self._trim_stem(root_frame)
        
        return root_frame
github joerick / pyinstrument / pyinstrument / processors.py View on Github external
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 frame
github joerick / pyinstrument / pyinstrument / processors.py View on Github external
def remove_unnecessary_self_time_nodes(frame, options):
    '''
    When a frame has only one child, and that is a self-time frame, remove that node, since it's
    unnecessary - it clutters the output and offers no additional information.
    '''
    if frame is None:
        return None

    if len(frame.children) == 1 and isinstance(frame.children[0], SelfTimeFrame):
        child = frame.children[0]
        frame.self_time += child.self_time
        child.remove_from_parent()
    
    for child in frame.children:
        remove_unnecessary_self_time_nodes(child, options=options)
    
    return frame