From fe5fbbebd9f073dff4f35b0142ed96f1044e1ad1 Mon Sep 17 00:00:00 2001 From: Xavier-Do Date: Wed, 10 Aug 2022 12:58:17 +0000 Subject: [PATCH] [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 --- odoo/tests/common.py | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/odoo/tests/common.py b/odoo/tests/common.py index a7fbb0fe7e5..a1a0b9cd41b 100644 --- a/odoo/tests/common.py +++ b/odoo/tests/common.py @@ -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):