|
| 1 | +======== |
| 2 | +Profiler |
| 3 | +======== |
| 4 | + |
| 5 | +.. !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! |
| 6 | + !! This file is generated by oca-gen-addon-readme !! |
| 7 | + !! changes will be overwritten. !! |
| 8 | + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! |
| 9 | +
|
| 10 | +This module provides a decorator to profile Python functions using yappi |
| 11 | +and store the results in the database for later analysis. |
| 12 | + |
| 13 | +Yappi (Yet Another Python Profiler) is a tracing profiler that is thread-aware |
| 14 | +and provides more accurate timing information than cProfile, especially for |
| 15 | +multi-threaded applications like Odoo. |
| 16 | + |
| 17 | +**Table of contents** |
| 18 | + |
| 19 | +.. contents:: |
| 20 | + :local: |
| 21 | + |
| 22 | +Usage |
| 23 | +===== |
| 24 | + |
| 25 | +To profile a function, simply use the ``@profiled()`` decorator:: |
| 26 | + |
| 27 | + from odoo.addons.profiler.tools import profiled |
| 28 | + |
| 29 | + class MyModel(models.Model): |
| 30 | + _name = "my.model" |
| 31 | + |
| 32 | + @profiled() |
| 33 | + def my_method(self): |
| 34 | + # Your code here |
| 35 | + pass |
| 36 | + |
| 37 | +You can customize the sample rate (percentage of calls to profile):: |
| 38 | + |
| 39 | + @profiled(sample_rate=0.01) # Profile 1% of calls |
| 40 | + def another_method(self): |
| 41 | + # Your code here |
| 42 | + pass |
| 43 | + |
| 44 | +The profiling results are stored in the database and can be viewed in: |
| 45 | +Settings → Technical → Profiler → Profiler Results |
| 46 | + |
| 47 | +Each profiling result includes: |
| 48 | + |
| 49 | +* Interactive Call Graph visualization showing top functions by cumulative time |
| 50 | +* Raw statistics with detailed timing information |
| 51 | +* Download button to export .pstats files for external analysis |
| 52 | + |
| 53 | +You can download the .pstats file from any profiling result and use external tools |
| 54 | +like gprof2dot to generate detailed call graphs:: |
| 55 | + |
| 56 | + gprof2dot -f pstats my_function.pstats | dot -Tpng -o output.png |
| 57 | + |
| 58 | +Or use snakeviz for interactive visualization:: |
| 59 | + |
| 60 | + snakeviz my_function.pstats |
| 61 | + |
| 62 | +Bug Tracker |
| 63 | +=========== |
| 64 | + |
| 65 | +Bugs are tracked on `GitHub Issues <https://github.com/OCA/server-tools/issues>`_. |
| 66 | +In case of trouble, please check there if your issue has already been reported. |
| 67 | + |
| 68 | +Credits |
| 69 | +======= |
| 70 | + |
| 71 | +Authors |
| 72 | +~~~~~~~ |
| 73 | + |
| 74 | +* Camptocamp |
| 75 | + |
| 76 | +Contributors |
| 77 | +~~~~~~~~~~~~ |
| 78 | + |
| 79 | +* Camptocamp |
| 80 | + |
| 81 | +Maintainers |
| 82 | +~~~~~~~~~~~ |
| 83 | + |
| 84 | +This module is maintained by the OCA. |
| 85 | + |
| 86 | +.. image:: https://odoo-community.org/logo.png |
| 87 | + :alt: Odoo Community Association |
| 88 | + :target: https://odoo-community.org |
| 89 | + |
| 90 | +OCA, or the Odoo Community Association, is a nonprofit organization whose |
| 91 | +mission is to support the collaborative development of Odoo features and |
| 92 | +promote its widespread use. |
| 93 | + |
| 94 | +This module is part of the `OCA/server-tools <https://github.com/OCA/server-tools/tree/18.0/profiler>`_ project on GitHub. |
| 95 | + |
| 96 | +You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute. |
0 commit comments