The profiling tools can be useful to profile a test of some execution point but this is not convenient to identify a problem on a running instance. With this commit, an option available in the debug menu allows to add a flag on the user sessions to enable profiling of all requests. Each request will be saved in a different 'ir.profile' entry, but will be grouped under the same session. The profiling can be activated on all sessions, even for a public user, but only if profiling is enabled on the database globally. This commits also adds a speedscope view to visualize saved results in the web client. closes odoo/odoo#66590 Signed-off-by: Xavier Dollé (xdo) <xdo@odoo.com>
35 lines
1.5 KiB
Python
35 lines
1.5 KiB
Python
# -*- coding: utf-8 -*-
|
|
# Part of Odoo. See LICENSE file for full copyright and licensing details.
|
|
import json
|
|
|
|
from odoo.exceptions import UserError
|
|
from odoo.http import Controller, request, Response, route
|
|
|
|
class Profiling(Controller):
|
|
|
|
@route('/web/set_profiling', type='http', auth='public', sitemap=False)
|
|
def profile(self, profile=None, collectors=None, **params):
|
|
if collectors is not None:
|
|
collectors = collectors.split(',')
|
|
else:
|
|
collectors = ['sql', 'traces_async']
|
|
profile = profile and profile != '0'
|
|
try:
|
|
state = request.env['ir.profile'].set_profiling(profile, collectors=collectors, params=params)
|
|
return json.dumps(state)
|
|
except UserError as e:
|
|
return Response(response='error: %s' % e, status=500)
|
|
|
|
@route(['/web/speedscope/', '/web/speedscope/<model("ir.profile"):profile>'], type='http', sitemap=False, auth='user')
|
|
def speedscope(self, profile=None):
|
|
# don't server speedscope index if profiling is not enabled
|
|
if not request.env['ir.profile']._enabled_until():
|
|
return request.not_found()
|
|
icp = request.env['ir.config_parameter']
|
|
context = {
|
|
'profile': profile,
|
|
'url_root': request.httprequest.url_root,
|
|
'cdn': icp.get_param('speedscope_cdn', "https://cdn.jsdelivr.net/npm/speedscope@1.13.0/dist/release/")
|
|
}
|
|
return request.render('web.view_speedscope_index', context)
|