Browse Source

[REF] profiler: Many changes (see list below)

- Refactor the import
 - Add player
 - Update display with css
 - Add access rule to show or hide the player
pull/375/head
jssuzanne 10 years ago
committed by Moisés López
parent
commit
d7186bfd8f
No known key found for this signature in database GPG Key ID: F49F27BE918BFA35
  1. 10
      profiler/__openerp__.py
  2. 23
      profiler/controllers.py
  3. 0
      profiler/controllers/main.py
  4. 11
      profiler/security/group.xml
  5. 21
      profiler/static/src/css/player.css
  6. 3
      profiler/static/src/js/boot.js
  7. 53
      profiler/static/src/js/player.js
  8. 32
      profiler/static/src/js/profiler.js
  9. 18
      profiler/static/src/xml/player.xml
  10. 50
      profiler/view/menu.xml

10
profiler/__openerp__.py

@ -31,18 +31,16 @@
'website': 'http://anybox.fr',
'depends': ['base', 'web'],
'data': [
'view/menu.xml',
],
'test': [
],
'demo': [
'security/group.xml',
],
'js': [
'static/src/js/profiler.js',
'static/src/js/player.js',
],
'qweb': [
'static/src/xml/player.xml',
],
'css': [
'static/src/css/player.css',
],
'installable': True,
'application': False,

23
profiler/controllers/__init__.py → profiler/controllers.py

@ -3,7 +3,7 @@ import logging
from datetime import datetime
from tempfile import mkstemp
import openerp.addons.web.http as openerpweb
from .. import core
from . import core
logger = logging.getLogger(__name__)
@ -12,20 +12,31 @@ class ProfilerController(openerpweb.Controller):
_cp_path = '/web/profiler'
player_state = 'profiler_player_clear'
"""Indicate the state(css class) of the player:
* profiler_player_clear
* profiler_player_enabled
* profiler_player_disabled
"""
@openerpweb.jsonrequest
def enable(self, request):
logger.info("Enabling")
core.enabled = True
ProfilerController.player_state = 'profiler_player_enabled'
@openerpweb.jsonrequest
def disable(self, request):
logger.info("Disabling")
core.disabled = True
core.enabled = False
ProfilerController.player_state = 'profiler_player_disabled'
@openerpweb.jsonrequest
def clear(self, request):
core.profile.clear()
logger.info("Cleared stats")
ProfilerController.player_state = 'profiler_player_clear'
@openerpweb.httprequest
def dump(self, request, token):
@ -48,3 +59,11 @@ class ProfilerController(openerpweb.Controller):
('Content-Disposition', 'attachment; filename="%s"' % filename),
('Content-Type', 'application/octet-stream')
], cookies={'fileToken': int(token)})
@openerpweb.jsonrequest
def initial_state(self, request):
user = request.session.model('res.users')
return {
'has_player_group': user.has_group('profiler.group_profiler_player'),
'player_state': ProfilerController.player_state,
}

0
profiler/controllers/main.py

11
profiler/security/group.xml

@ -0,0 +1,11 @@
<?xml version="1.0" encoding="UTF-8"?>
<openerp>
<data noupdate="1">
<record id="group_profiler_player" model="res.groups">
<field name="name">Profiling capability</field>
</record>
<record model="res.users" id="base.user_root">
<field name="groups_id" eval="[(4, ref('profiler.group_profiler_player'))]"/>
</record>
</data>
</openerp>

21
profiler/static/src/css/player.css

@ -0,0 +1,21 @@
.openerp .oe_topbar_item.profiler_player img {
cursor: pointer;
}
.openerp .oe_topbar_item.profiler_player.profiler_player_enabled img.profiler_enable {
display: None;
}
.openerp .oe_topbar_item.profiler_player.profiler_player_enabled img.profiler_dump {
display: None;
}
.openerp .oe_topbar_item.profiler_player.profiler_player_disabled img.profiler_disable {
display: None;
}
.openerp .oe_topbar_item.profiler_player.profiler_player_clear img.profiler_disable {
display: None;
}
.openerp .oe_topbar_item.profiler_player.profiler_player_clear img.profiler_clear {
display: None;
}
.openerp .oe_topbar_item.profiler_player.profiler_player_clear img.profiler_dump {
display: None;
}

3
profiler/static/src/js/boot.js

@ -1,3 +0,0 @@
openerp.profiler = function(instance) {
openerp.profiler.profiler_enable();
};

53
profiler/static/src/js/player.js

@ -0,0 +1,53 @@
openerp.profiler = function(instance) {
instance.profiler.Player = instance.web.Widget.extend({
template: 'profiler.player',
events: {
"click .profiler_enable": "enable",
"click .profiler_disable": "disable",
"click .profiler_clear": "clear",
"click .profiler_dump": "dump",
},
apply_class: function(css_class) {
console.log(css_class)
this.$el.removeClass('profiler_player_enabled');
this.$el.removeClass('profiler_player_disabled');
this.$el.removeClass('profiler_player_clear');
this.$el.addClass(css_class);
},
enable: function() {
this.rpc('/web/profiler/enable', {});
this.apply_class('profiler_player_enabled');
},
disable: function() {
this.rpc('/web/profiler/disable', {});
this.apply_class('profiler_player_disabled');
},
clear: function() {
this.rpc('/web/profiler/clear', {});
this.apply_class('profiler_player_clear');
},
dump: function() {
$.blockUI();
this.session.get_file({
url: '/web/profiler/dump',
complete: $.unblockUI
});
},
});
instance.web.UserMenu.include({
do_update: function () {
var self = this;
this.update_promise.done(function () {
self.rpc('/web/profiler/initial_state', {}).done(function(state) {
if (state.has_player_group) {
this.profiler_player = new instance.profiler.Player(this);
this.profiler_player.prependTo(instance.webclient.$('.oe_systray'));
this.profiler_player.apply_class(state.player_state);
}
});
});
return this._super();
},
});
};

32
profiler/static/src/js/profiler.js

@ -1,32 +0,0 @@
openerp.profiler = function(instance) {
openerp.profiler.profiler_enable(instance);
};
openerp.profiler.profiler_enable = function(instance) {
instance.profiler.controllers = {
'profiler.enable': 'enable',
'profiler.disable': 'disable',
'profiler.clear': 'clear',
};
instance.profiler.simple_action = function(parent, action) {
console.info(action);
parent.session.rpc('/web/profiler/' + instance.profiler.controllers[action.tag], {});
};
instance.profiler.dump = function(parent, action) {
$.blockUI();
parent.session.get_file({
url: '/web/profiler/dump',
complete: $.unblockUI
});
};
instance.web.client_actions.add("profiler.enable",
"instance.profiler.simple_action");
instance.web.client_actions.add("profiler.disable",
"instance.profiler.simple_action");
instance.web.client_actions.add("profiler.clear",
"instance.profiler.simple_action");
instance.web.client_actions.add("profiler.dump",
"instance.profiler.dump");
};

18
profiler/static/src/xml/player.xml

@ -0,0 +1,18 @@
<templates>
<t t-name="profiler.player">
<div class="oe_topbar_item profiler_player">
<img class="profiler_enable"
title="Enable the profiler"
src="/web/static/src/img/icons/gtk-media-record.png"/>
<img class="profiler_disable"
title="Disable the profiler"
src="/web/static/src/img/icons/gtk-media-pause.png"/>
<img class="profiler_clear"
title="Clean previous profiling"
src="/web/static/src/img/icons/gtk-media-stop.png"/>
<img class="profiler_dump"
title="Dump the previous profiling"
src="/web/static/src/img/icons/gtk-floppy.png"/>
</div>
</t>
</templates>

50
profiler/view/menu.xml

@ -1,50 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<openerp>
<data>
<menuitem id="menu_main"
parent="base.menu_administration"
sequence="0"
name="Profiler"/>
<record model="ir.actions.client" id="action_profiler_enable">
<field name="name">Enable Profiler</field>
<field name="tag">profiler.enable</field>
</record>
<menuitem id="menu_enable"
parent="menu_main"
sequence="10"
action="action_profiler_enable"
name="Start profiling"/>
<record model="ir.actions.client" id="action_profiler_disable">
<field name="name">Disable Profiler</field>
<field name="tag">profiler.disable</field>
</record>
<menuitem id="menu_disable"
parent="menu_main"
sequence="20"
action="action_profiler_disable"
name="Stop profiling"/>
<record model="ir.actions.client" id="action_profiler_dump">
<field name="name">Dump Stats</field>
<field name="tag">profiler.dump</field>
</record>
<menuitem id="menu_dump"
parent="menu_main"
sequence="30"
action="action_profiler_dump"
name="Dump stats"/>
<record model="ir.actions.client" id="action_profiler_clear">
<field name="name">Clear Stats</field>
<field name="tag">profiler.clear</field>
</record>
<menuitem id="menu_clear"
parent="menu_main"
sequence="40"
action="action_profiler_clear"
name="Clear stats"/>
</data>
</openerp>
Loading…
Cancel
Save