author | Sylvain Thénault <sylvain.thenault@logilab.fr> |
Thu, 11 Mar 2010 16:49:07 +0100 | |
branch | stable |
changeset 4866 | 550e35a69b75 |
parent 4865 | 90ad729d3540 |
child 4873 | bfebe3d14d53 |
permissions | -rw-r--r-- |
0 | 1 |
"""management and error screens |
2 |
||
3 |
||
4 |
:organization: Logilab |
|
4212
ab6573088b4a
update copyright: welcome 2010
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
2312
diff
changeset
|
5 |
:copyright: 2001-2010 LOGILAB S.A. (Paris, FRANCE), license is LGPL v2. |
0 | 6 |
:contact: http://www.logilab.fr/ -- mailto:contact@logilab.fr |
1977
606923dff11b
big bunch of copyright / docstring update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1802
diff
changeset
|
7 |
:license: GNU Lesser General Public License, v2.1 - http://www.gnu.org/licenses |
0 | 8 |
""" |
9 |
__docformat__ = "restructuredtext en" |
|
10 |
||
11 |
from time import strftime, localtime |
|
12 |
||
2312
af4d8f75c5db
use xml_escape
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1977
diff
changeset
|
13 |
from logilab.mtconverter import xml_escape |
0 | 14 |
|
635
305da8d6aa2d
require_group/match_user_group -> match_user_groups
sylvain.thenault@logilab.fr
parents:
0
diff
changeset
|
15 |
from cubicweb.selectors import none_rset, match_user_groups |
981
d86d1ee3b60e
fix some imports, update treeview for 3.2
sylvain.thenault@logilab.fr
parents:
742
diff
changeset
|
16 |
from cubicweb.view import StartupView |
0 | 17 |
|
18 |
def dict_to_html(w, dict): |
|
19 |
# XHTML doesn't allow emtpy <ul> nodes |
|
20 |
if dict: |
|
21 |
w(u'<ul>') |
|
22 |
for key in sorted(dict): |
|
23 |
w(u'<li><span class="label">%s</span>: <span>%s</span></li>' % ( |
|
2312
af4d8f75c5db
use xml_escape
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1977
diff
changeset
|
24 |
xml_escape(str(key)), xml_escape(repr(dict[key])))) |
0 | 25 |
w(u'</ul>') |
635
305da8d6aa2d
require_group/match_user_group -> match_user_groups
sylvain.thenault@logilab.fr
parents:
0
diff
changeset
|
26 |
|
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
981
diff
changeset
|
27 |
|
4714
fccda6dd91bf
merge debug and info views
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4252
diff
changeset
|
28 |
|
fccda6dd91bf
merge debug and info views
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4252
diff
changeset
|
29 |
class ProcessInformationView(StartupView): |
4865
90ad729d3540
[debug] minor improvments to the registry view
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4725
diff
changeset
|
30 |
"""display various web server /repository information""" |
4714
fccda6dd91bf
merge debug and info views
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4252
diff
changeset
|
31 |
__regid__ = 'info' |
742
99115e029dca
replaced most of __selectors__ assignments with __select__
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
635
diff
changeset
|
32 |
__select__ = none_rset() & match_user_groups('managers') |
4714
fccda6dd91bf
merge debug and info views
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4252
diff
changeset
|
33 |
|
fccda6dd91bf
merge debug and info views
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4252
diff
changeset
|
34 |
title = _('server information') |
0 | 35 |
|
36 |
def call(self, **kwargs): |
|
4714
fccda6dd91bf
merge debug and info views
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4252
diff
changeset
|
37 |
req = self._cw |
fccda6dd91bf
merge debug and info views
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4252
diff
changeset
|
38 |
dtformat = req.property_value('ui.datetime-format') |
fccda6dd91bf
merge debug and info views
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4252
diff
changeset
|
39 |
_ = req._ |
0 | 40 |
w = self.w |
4714
fccda6dd91bf
merge debug and info views
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4252
diff
changeset
|
41 |
# generic instance information |
fccda6dd91bf
merge debug and info views
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4252
diff
changeset
|
42 |
w(u'<h1>%s</h1>' % _('Instance')) |
fccda6dd91bf
merge debug and info views
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4252
diff
changeset
|
43 |
w(u'<table>') |
fccda6dd91bf
merge debug and info views
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4252
diff
changeset
|
44 |
w(u'<tr><th align="left">%s</th><td>%s</td></tr>' % ( |
fccda6dd91bf
merge debug and info views
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4252
diff
changeset
|
45 |
_('config type'), self._cw.vreg.config.name)) |
fccda6dd91bf
merge debug and info views
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4252
diff
changeset
|
46 |
w(u'<tr><th align="left">%s</th><td>%s</td></tr>' % ( |
fccda6dd91bf
merge debug and info views
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4252
diff
changeset
|
47 |
_('config mode'), self._cw.vreg.config.mode)) |
fccda6dd91bf
merge debug and info views
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4252
diff
changeset
|
48 |
w(u'<tr><th align="left">%s</th><td>%s</td></tr>' % ( |
fccda6dd91bf
merge debug and info views
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4252
diff
changeset
|
49 |
_('instance home'), self._cw.vreg.config.apphome)) |
fccda6dd91bf
merge debug and info views
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4252
diff
changeset
|
50 |
w(u'</table>') |
fccda6dd91bf
merge debug and info views
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4252
diff
changeset
|
51 |
vcconf = req.vreg.config.vc_config() |
fccda6dd91bf
merge debug and info views
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4252
diff
changeset
|
52 |
w(u'<h3>%s</h3>' % _('versions configuration')) |
fccda6dd91bf
merge debug and info views
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4252
diff
changeset
|
53 |
w(u'<table>') |
fccda6dd91bf
merge debug and info views
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4252
diff
changeset
|
54 |
w(u'<tr><th align="left">%s</th><td>%s</td></tr>' % ( |
fccda6dd91bf
merge debug and info views
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4252
diff
changeset
|
55 |
'CubicWeb', vcconf.get('cubicweb', _('no version information')))) |
fccda6dd91bf
merge debug and info views
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4252
diff
changeset
|
56 |
for cube in sorted(self._cw.vreg.config.cubes()): |
fccda6dd91bf
merge debug and info views
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4252
diff
changeset
|
57 |
cubeversion = vcconf.get(cube, _('no version information')) |
fccda6dd91bf
merge debug and info views
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4252
diff
changeset
|
58 |
w(u'<tr><th align="left">%s</th><td>%s</td></tr>' % ( |
fccda6dd91bf
merge debug and info views
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4252
diff
changeset
|
59 |
cube, cubeversion)) |
fccda6dd91bf
merge debug and info views
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4252
diff
changeset
|
60 |
w(u'</table>') |
fccda6dd91bf
merge debug and info views
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4252
diff
changeset
|
61 |
# repository information |
fccda6dd91bf
merge debug and info views
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4252
diff
changeset
|
62 |
repo = req.vreg.config.repository(None) |
fccda6dd91bf
merge debug and info views
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4252
diff
changeset
|
63 |
w(u'<h1>%s</h1>' % _('Repository')) |
fccda6dd91bf
merge debug and info views
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4252
diff
changeset
|
64 |
w(u'<h3>%s</h3>' % _('resources usage')) |
fccda6dd91bf
merge debug and info views
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4252
diff
changeset
|
65 |
w(u'<table>') |
fccda6dd91bf
merge debug and info views
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4252
diff
changeset
|
66 |
stats = repo.stats() |
fccda6dd91bf
merge debug and info views
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4252
diff
changeset
|
67 |
for element in sorted(stats): |
fccda6dd91bf
merge debug and info views
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4252
diff
changeset
|
68 |
w(u'<tr><th align="left">%s</th><td>%s %s</td></tr>' |
4725 | 69 |
% (element, xml_escape(unicode(stats[element])), |
4714
fccda6dd91bf
merge debug and info views
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4252
diff
changeset
|
70 |
element.endswith('percent') and '%' or '' )) |
fccda6dd91bf
merge debug and info views
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4252
diff
changeset
|
71 |
w(u'</table>') |
fccda6dd91bf
merge debug and info views
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4252
diff
changeset
|
72 |
if req.cnx._cnxtype == 'inmemory': |
fccda6dd91bf
merge debug and info views
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4252
diff
changeset
|
73 |
w(u'<h3>%s</h3>' % _('opened sessions')) |
fccda6dd91bf
merge debug and info views
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4252
diff
changeset
|
74 |
sessions = repo._sessions.values() |
fccda6dd91bf
merge debug and info views
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4252
diff
changeset
|
75 |
if sessions: |
fccda6dd91bf
merge debug and info views
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4252
diff
changeset
|
76 |
w(u'<ul>') |
fccda6dd91bf
merge debug and info views
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4252
diff
changeset
|
77 |
for session in sessions: |
fccda6dd91bf
merge debug and info views
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4252
diff
changeset
|
78 |
w(u'<li>%s (%s: %s)<br/>' % ( |
fccda6dd91bf
merge debug and info views
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4252
diff
changeset
|
79 |
xml_escape(unicode(session)), |
fccda6dd91bf
merge debug and info views
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4252
diff
changeset
|
80 |
_('last usage'), |
fccda6dd91bf
merge debug and info views
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4252
diff
changeset
|
81 |
strftime(dtformat, localtime(session.timestamp)))) |
fccda6dd91bf
merge debug and info views
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4252
diff
changeset
|
82 |
dict_to_html(w, session.data) |
fccda6dd91bf
merge debug and info views
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4252
diff
changeset
|
83 |
w(u'</li>') |
fccda6dd91bf
merge debug and info views
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4252
diff
changeset
|
84 |
w(u'</ul>') |
fccda6dd91bf
merge debug and info views
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4252
diff
changeset
|
85 |
else: |
fccda6dd91bf
merge debug and info views
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4252
diff
changeset
|
86 |
w(u'<p>%s</p>' % _('no repository sessions found')) |
fccda6dd91bf
merge debug and info views
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4252
diff
changeset
|
87 |
# web server information |
fccda6dd91bf
merge debug and info views
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4252
diff
changeset
|
88 |
w(u'<h1>%s</h1>' % _('Web server')) |
fccda6dd91bf
merge debug and info views
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4252
diff
changeset
|
89 |
w(u'<table>') |
fccda6dd91bf
merge debug and info views
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4252
diff
changeset
|
90 |
w(u'<tr><th align="left">%s</th><td>%s</td></tr>' % ( |
fccda6dd91bf
merge debug and info views
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4252
diff
changeset
|
91 |
_('base url'), req.base_url())) |
fccda6dd91bf
merge debug and info views
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4252
diff
changeset
|
92 |
w(u'<tr><th align="left">%s</th><td>%s</td></tr>' % ( |
fccda6dd91bf
merge debug and info views
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4252
diff
changeset
|
93 |
_('data directory url'), req.datadir_url)) |
fccda6dd91bf
merge debug and info views
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4252
diff
changeset
|
94 |
w(u'</table>') |
fccda6dd91bf
merge debug and info views
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4252
diff
changeset
|
95 |
from cubicweb.web.application import SESSION_MANAGER |
fccda6dd91bf
merge debug and info views
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4252
diff
changeset
|
96 |
sessions = SESSION_MANAGER.current_sessions() |
fccda6dd91bf
merge debug and info views
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4252
diff
changeset
|
97 |
w(u'<h3>%s</h3>' % _('opened web sessions')) |
0 | 98 |
if sessions: |
99 |
w(u'<ul>') |
|
4714
fccda6dd91bf
merge debug and info views
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4252
diff
changeset
|
100 |
for session in sessions: |
fccda6dd91bf
merge debug and info views
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4252
diff
changeset
|
101 |
w(u'<li>%s (%s: %s)<br/>' % ( |
fccda6dd91bf
merge debug and info views
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4252
diff
changeset
|
102 |
session.sessionid, |
fccda6dd91bf
merge debug and info views
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4252
diff
changeset
|
103 |
_('last usage'), |
fccda6dd91bf
merge debug and info views
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4252
diff
changeset
|
104 |
strftime(dtformat, localtime(session.last_usage_time)))) |
0 | 105 |
dict_to_html(w, session.data) |
106 |
w(u'</li>') |
|
107 |
w(u'</ul>') |
|
108 |
else: |
|
4714
fccda6dd91bf
merge debug and info views
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4252
diff
changeset
|
109 |
w(u'<p>%s</p>' % _('no web sessions found')) |
fccda6dd91bf
merge debug and info views
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4252
diff
changeset
|
110 |
|
3377
dd9d292b6a6d
use __regid__ instead of id on appobject classes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2312
diff
changeset
|
111 |
|
dd9d292b6a6d
use __regid__ instead of id on appobject classes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2312
diff
changeset
|
112 |
|
dd9d292b6a6d
use __regid__ instead of id on appobject classes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2312
diff
changeset
|
113 |
class RegistryView(StartupView): |
4865
90ad729d3540
[debug] minor improvments to the registry view
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4725
diff
changeset
|
114 |
"""display vregistry content""" |
3377
dd9d292b6a6d
use __regid__ instead of id on appobject classes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2312
diff
changeset
|
115 |
__regid__ = 'registry' |
dd9d292b6a6d
use __regid__ instead of id on appobject classes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2312
diff
changeset
|
116 |
__select__ = StartupView.__select__ & match_user_groups('managers') |
dd9d292b6a6d
use __regid__ instead of id on appobject classes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2312
diff
changeset
|
117 |
title = _('registry') |
dd9d292b6a6d
use __regid__ instead of id on appobject classes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2312
diff
changeset
|
118 |
|
dd9d292b6a6d
use __regid__ instead of id on appobject classes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2312
diff
changeset
|
119 |
def call(self, **kwargs): |
dd9d292b6a6d
use __regid__ instead of id on appobject classes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2312
diff
changeset
|
120 |
self.w(u'<h1>%s</h1>' % _("Registry's content")) |
3451
6b46d73823f5
[api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3377
diff
changeset
|
121 |
keys = sorted(self._cw.vreg) |
4865
90ad729d3540
[debug] minor improvments to the registry view
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4725
diff
changeset
|
122 |
url = self._cw.url() |
90ad729d3540
[debug] minor improvments to the registry view
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4725
diff
changeset
|
123 |
self.w(u'<p>%s</p>\n' % ' - '.join('<a href="%s#%s">%s</a>' |
90ad729d3540
[debug] minor improvments to the registry view
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4725
diff
changeset
|
124 |
% (url, key, key) for key in keys)) |
3377
dd9d292b6a6d
use __regid__ instead of id on appobject classes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2312
diff
changeset
|
125 |
for key in keys: |
4865
90ad729d3540
[debug] minor improvments to the registry view
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4725
diff
changeset
|
126 |
self.w(u'<h2 id="%s">%s</h2>' % (key, key)) |
90ad729d3540
[debug] minor improvments to the registry view
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4725
diff
changeset
|
127 |
if self._cw.vreg[key]: |
90ad729d3540
[debug] minor improvments to the registry view
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4725
diff
changeset
|
128 |
values = sorted(self._cw.vreg[key].iteritems()) |
90ad729d3540
[debug] minor improvments to the registry view
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4725
diff
changeset
|
129 |
self.wview('pyvaltable', pyvalue=[(key, xml_escape(repr(val))) |
90ad729d3540
[debug] minor improvments to the registry view
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4725
diff
changeset
|
130 |
for key, val in values]) |
3377
dd9d292b6a6d
use __regid__ instead of id on appobject classes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2312
diff
changeset
|
131 |
else: |
dd9d292b6a6d
use __regid__ instead of id on appobject classes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2312
diff
changeset
|
132 |
self.w(u'<p>Empty</p>\n') |
4866
550e35a69b75
[debug] a new view to help debugging memory leaks
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4865
diff
changeset
|
133 |
|
550e35a69b75
[debug] a new view to help debugging memory leaks
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4865
diff
changeset
|
134 |
|
550e35a69b75
[debug] a new view to help debugging memory leaks
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4865
diff
changeset
|
135 |
class GCView(StartupView): |
550e35a69b75
[debug] a new view to help debugging memory leaks
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4865
diff
changeset
|
136 |
"""display garbage collector information""" |
550e35a69b75
[debug] a new view to help debugging memory leaks
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4865
diff
changeset
|
137 |
__regid__ = 'gc' |
550e35a69b75
[debug] a new view to help debugging memory leaks
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4865
diff
changeset
|
138 |
__select__ = StartupView.__select__ & match_user_groups('managers') |
550e35a69b75
[debug] a new view to help debugging memory leaks
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4865
diff
changeset
|
139 |
title = _('garbage') |
550e35a69b75
[debug] a new view to help debugging memory leaks
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4865
diff
changeset
|
140 |
|
550e35a69b75
[debug] a new view to help debugging memory leaks
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4865
diff
changeset
|
141 |
def call(self, **kwargs): |
550e35a69b75
[debug] a new view to help debugging memory leaks
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4865
diff
changeset
|
142 |
from cubicweb._gcdebug import gc_info |
550e35a69b75
[debug] a new view to help debugging memory leaks
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4865
diff
changeset
|
143 |
from rql.stmts import Union |
550e35a69b75
[debug] a new view to help debugging memory leaks
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4865
diff
changeset
|
144 |
from cubicweb.appobject import AppObject |
550e35a69b75
[debug] a new view to help debugging memory leaks
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4865
diff
changeset
|
145 |
from cubicweb.rset import ResultSet |
550e35a69b75
[debug] a new view to help debugging memory leaks
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4865
diff
changeset
|
146 |
from cubicweb.dbapi import Connection, Cursor |
550e35a69b75
[debug] a new view to help debugging memory leaks
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4865
diff
changeset
|
147 |
from cubicweb.web.request import CubicWebRequestBase |
550e35a69b75
[debug] a new view to help debugging memory leaks
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4865
diff
changeset
|
148 |
lookupclasses = (AppObject, |
550e35a69b75
[debug] a new view to help debugging memory leaks
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4865
diff
changeset
|
149 |
Union, ResultSet, |
550e35a69b75
[debug] a new view to help debugging memory leaks
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4865
diff
changeset
|
150 |
Connection, Cursor, |
550e35a69b75
[debug] a new view to help debugging memory leaks
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4865
diff
changeset
|
151 |
CubicWebRequestBase) |
550e35a69b75
[debug] a new view to help debugging memory leaks
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4865
diff
changeset
|
152 |
try: |
550e35a69b75
[debug] a new view to help debugging memory leaks
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4865
diff
changeset
|
153 |
from cubicweb.server.session import Session, ChildSession, InternalSession |
550e35a69b75
[debug] a new view to help debugging memory leaks
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4865
diff
changeset
|
154 |
lookupclasses += (InternalSession, ChildSession, Session) |
550e35a69b75
[debug] a new view to help debugging memory leaks
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4865
diff
changeset
|
155 |
except ImportError: |
550e35a69b75
[debug] a new view to help debugging memory leaks
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4865
diff
changeset
|
156 |
pass # no server part installed |
550e35a69b75
[debug] a new view to help debugging memory leaks
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4865
diff
changeset
|
157 |
self.w(u'<h1>%s</h1>' % _('Garbage collection information')) |
550e35a69b75
[debug] a new view to help debugging memory leaks
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4865
diff
changeset
|
158 |
counters, ocounters, garbage = gc_info(lookupclasses, |
550e35a69b75
[debug] a new view to help debugging memory leaks
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4865
diff
changeset
|
159 |
viewreferrersclasses=()) |
550e35a69b75
[debug] a new view to help debugging memory leaks
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4865
diff
changeset
|
160 |
self.w(u'<h3>%s</h3>' % _('Looked up classes')) |
550e35a69b75
[debug] a new view to help debugging memory leaks
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4865
diff
changeset
|
161 |
values = sorted(counters.iteritems(), key=lambda x: x[1], reverse=True) |
550e35a69b75
[debug] a new view to help debugging memory leaks
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4865
diff
changeset
|
162 |
self.wview('pyvaltable', pyvalue=values) |
550e35a69b75
[debug] a new view to help debugging memory leaks
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4865
diff
changeset
|
163 |
self.w(u'<h3>%s</h3>' % _('Most referenced classes')) |
550e35a69b75
[debug] a new view to help debugging memory leaks
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4865
diff
changeset
|
164 |
values = sorted(ocounters.iteritems(), key=lambda x: x[1], reverse=True) |
550e35a69b75
[debug] a new view to help debugging memory leaks
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4865
diff
changeset
|
165 |
self.wview('pyvaltable', pyvalue=values[:self._cw.form.get('nb', 20)]) |
550e35a69b75
[debug] a new view to help debugging memory leaks
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4865
diff
changeset
|
166 |
if garbage: |
550e35a69b75
[debug] a new view to help debugging memory leaks
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4865
diff
changeset
|
167 |
self.w(u'<h3>%s</h3>' % _('Unreachable objects')) |
550e35a69b75
[debug] a new view to help debugging memory leaks
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4865
diff
changeset
|
168 |
values = sorted(xml_escape(repr(o) for o in garbage)) |
550e35a69b75
[debug] a new view to help debugging memory leaks
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4865
diff
changeset
|
169 |
self.wview('pyvallist', pyvalue=values) |