You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

32 lines
847 B

  1. import controllers # noqa
  2. from cProfile import Profile
  3. def patch_openerp():
  4. """Modify OpenERP/Odoo entry points so that profile can record.
  5. Odoo is a multi-threaded program. Therefore, the :data:`profile` object
  6. needs to be enabled/disabled each in each thread to capture all the
  7. execution.
  8. For instance, OpenERP 7 spawns a new thread for each request.
  9. """
  10. from openerp.addons.web.http import JsonRequest
  11. from .core import profiling
  12. orig_dispatch = JsonRequest.dispatch
  13. def dispatch(*args, **kwargs):
  14. with profiling():
  15. return orig_dispatch(*args, **kwargs)
  16. JsonRequest.dispatch = dispatch
  17. def create_profile():
  18. """Create the global, shared profile object."""
  19. from . import core
  20. core.profile = Profile()
  21. def post_load():
  22. create_profile()
  23. patch_openerp()