Profiling: Difference between revisions

From FreeCAD Documentation
(Profiling the code of FreeCAD helps find bottlenecks in the algorithms used to create or manipulate objects.)
 
(Marked this version for translation)
Line 2: Line 2:
<translate>
<translate>


== Description ==
== Description == <!--T:1-->


<!--T:2-->
Profiling the code of FreeCAD helps find bottlenecks in the algorithms used to create or manipulate objects.
Profiling the code of FreeCAD helps find bottlenecks in the algorithms used to create or manipulate objects.


<!--T:3-->
To profile [[Python|Python]] code use the standard {{incode|cProfile}} module to define start and end points to profile in the code.
To profile [[Python|Python]] code use the standard {{incode|cProfile}} module to define start and end points to profile in the code.
</translate>
</translate>
Line 22: Line 24:
<translate>
<translate>


<!--T:4-->
Then install and use {{incode|pyprof2calltree}} to convert the profile output into cachegrind input.
Then install and use {{incode|pyprof2calltree}} to convert the profile output into cachegrind input.
</translate>
</translate>
Line 29: Line 32:
<translate>
<translate>


<!--T:5-->
Then visualize this information with {{incode|kcachegrind}} for Linux or {{incode|qcachegrind}} for Windows.
Then visualize this information with {{incode|kcachegrind}} for Linux or {{incode|qcachegrind}} for Windows.
</translate>
</translate>
Line 36: Line 40:
<translate>
<translate>


== Resources ==
== Resources == <!--T:6-->


<!--T:7-->
* [https://docs.python.org/3/library/profile.html The Python profilers], {{incode|cProfile}} and {{incode|python}}.
* [https://docs.python.org/3/library/profile.html The Python profilers], {{incode|cProfile}} and {{incode|python}}.
* [https://pypi.org/project/pyprof2calltree/ pyprof2calltree] at PyPI; [https://github.com/pwaller/pyprof2calltree/ pyprof2calltree] repository.
* [https://pypi.org/project/pyprof2calltree/ pyprof2calltree] at PyPI; [https://github.com/pwaller/pyprof2calltree/ pyprof2calltree] repository.

Revision as of 16:46, 12 August 2020

Description

Profiling the code of FreeCAD helps find bottlenecks in the algorithms used to create or manipulate objects.

To profile Python code use the standard cProfile module to define start and end points to profile in the code.

import cProfile
pr = cProfile.Profile()
pr.enable()

# --------------------------------------
# Lines of code that you want to profile
# --------------------------------------

pr.disable()
pr.dump_stats("/tmp/profile.cprof")

Then install and use pyprof2calltree to convert the profile output into cachegrind input.

pyprof2calltree -i /tmp/profile.cprof -o /tmp/callgrind.out

Then visualize this information with kcachegrind for Linux or qcachegrind for Windows.

kcachegrind /tmp/callgrind.out

Resources