PythonPart function profiling with pyinstrument

Performance profiling of the functions with pyinstrument is supported by the PythonParts framework class ProfileUtil such as

ProfileUtil.profile(modify_element_property_local, page, name, value,
                    profiler_type = ProfilerType.PY_INSTRUMENT)

The profiling results are shown in the explorer like

../../../_images/pyinstrument.png

pyinstrument

The installation is done with the help of the PythonPart InstallPythonPackage

Inside the PythonParts script the profiling can be included e.g. in the function modify_element_property as follows

PROFILE_FUNCTION = True
...

def modify_element_property(self, page, name, value):
    ...

    if PROFILE_FUNCTION:
        return ProfileUtil.profile(modify_element_property_local, page, name, value,
                                   profiler_type = ProfilerType.PY_INSTRUMENT))
    else:
        return modify_element_property_local(page, name, value)

def modify_element_property_local(self, page, name, value):
    ...