How to use pyinstrument - 10 common examples

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_overflow.py View on Github external
def deep_profiler_session():
    profiler = Profiler()
    profiler.start()

    # give 120 frames for pyinstrument to do its work.
    recursion_depth = sys.getrecursionlimit() - current_stack_depth() - 120
    recurse(recursion_depth)

    profiler.stop()
    return profiler.last_session
github mikedh / trimesh / tests / regression.py View on Github external
setup.format(file_name),
                                         repeat=repeats,
                                         number=iterations))
            timings[test_name][file_name] = time_min / iterations

    result = {}

    result['cpu_info'] = subprocess.check_output(['cat', '/proc/cpuinfo'])
    result['baseline'] = baseline.tolist()
    result['timestamp'] = time.time()
    result['timings'] = timings
    '''

    import pyinstrument

    profiler = pyinstrument.Profiler()
    profiler.start()

    typical_application()

    profiler.stop()
    print(profiler.output_text(unicode=True, color=True))
github joerick / pyinstrument / test / test_profiler.py View on Github external
def test_json_output():
    with Profiler() as profiler:
        long_function_a()
        long_function_b()

    output_data = profiler.output(renderers.JSONRenderer(), root=True)

    output = json.loads(output_data)

    assert output['function'] == 'test_json_output'
    assert len(output['children']) == 2
github pywbem / pywbem / tests / manualtest / run_response_performance.py View on Github external
def execute_test_code(xml_string, profiler):
    """
    The test code to be executed. If a profiler is defined it is enabled
    just before the test code is executed and disabled just after the
    code is executed.
    """
    if profiler:
        if isinstance(profiler, cProfile.Profile):
            profiler.enable()
        elif isinstance(profiler, Profiler):
            profiler.start()

    # The code to be tested
    tt = _tupletree.xml_to_tupletree_sax(xml_string, "TestData")

    parse_cim(tt)

    if profiler:
        if isinstance(profiler, cProfile.Profile):
            profiler.disable()
        elif isinstance(profiler, Profiler):
            profiler.stop()
github joerick / pyinstrument / test / test_processors.py View on Github external
def test_group_library_frames_processor():
    frame = Frame(
        identifier='\x00cibuildwheel/__init__.py\x0012',
        children=[
            Frame(
                identifier='library_function\x00env/lib/python3.6/django/__init__.py\x00997',
                children=[
                    Frame(
                        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,
                                    ),
                                ]
                            ),
                        ]
                    ),
github joerick / pyinstrument / test / test_processors.py View on Github external
def test_group_library_frames_processor():
    frame = Frame(
        identifier='\x00cibuildwheel/__init__.py\x0012',
        children=[
            Frame(
                identifier='library_function\x00env/lib/python3.6/django/__init__.py\x00997',
                children=[
                    Frame(
                        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,
                                    ),
                                ]
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,
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',
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(
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',