[IMP] profiler: profile requests in httpCase

When profiling an HTTPCase the only result will be the starting of the
browser and the ready/ok code. All requests are in other thread
and are not profiled.

HTTPCase profiler will now patch the _get_profiler_context_manager
in order to enable profiler on all requests during this time

closes odoo/odoo#99119

X-original-commit: 77d110de242c8b8e9b0f09dcecad25c203f32535
Signed-off-by: Julien Castiaux <juc@odoo.com>
This commit is contained in:
Xavier-Do
2022-08-30 20:23:25 +02:00
parent bedce02bb7
commit fe5fbbebd9
+12 -2
View File
@@ -775,12 +775,12 @@ class BaseCase(unittest.TestCase, metaclass=MetaCase):
def assertHTMLEqual(self, original, expected):
return self._assertXMLEqual(original, expected, 'html')
def profile(self, **kwargs):
def profile(self, description='', **kwargs):
test_method = getattr(self, '_testMethodName', 'Unknown test method')
if not hasattr(self, 'profile_session'):
self.profile_session = profiler.make_session(test_method)
return profiler.Profiler(
description='%s uid:%s %s' % (test_method, self.env.user.id, 'warm' if self.warm else 'cold'),
description='%s uid:%s %s %s' % (test_method, self.env.user.id, 'warm' if self.warm else 'cold', description),
db=self.env.cr.dbname,
profile_session=self.profile_session,
**kwargs)
@@ -1842,6 +1842,16 @@ class HttpCase(TransactionCase):
ready = kwargs.pop('ready', "odoo.__DEBUG__.services['web_tour.tour'].tours['%s'].ready" % tour_name)
return self.browser_js(url_path=url_path, code=code, ready=ready, **kwargs)
def profile(self, **kwargs):
"""
for http_case, also patch _get_profiler_context_manager in order to profile all requests
"""
sup = super()
_profiler = sup.profile(**kwargs)
def route_profiler(request):
return sup.profile(description=request.httprequest.full_path)
return profiler.Nested(_profiler, patch('odoo.http.Request._get_profiler_context_manager', route_profiler))
# kept for backward compatibility
class HttpSavepointCase(HttpCase):