Commit fe8565ea authored by Vincent Pelletier's avatar Vincent Pelletier

extension.erp5.pprofile: Update fr pprofile 1.8.3 .

1.8.3 is now required to use profiling.
It provides two important features:
- SQL query tracing (which queries were executed, how many times,
how long did they take to run)
- ZODB __setstate__ per-oid statistics
parent 488fc7da
import pprofile
from email.mime.multipart import MIMEMultipart
from email.mime.text import MIMEText
from email.mime.application import MIMEApplication
from email.encoders import encode_quopri
from cStringIO import StringIO
import os
_allsep = os.sep + (os.altsep or '')
def _relpath(name):
return os.path.normpath(os.path.splitdrive(name)[1]).lstrip(_allsep)
class ZopeBase(object):
__allow_access_to_unprotected_subobjects__ = 1
def _getFilename(self, filename, f_globals):
if 'Script (Python)' in filename:
try:
script = f_globals['script']
except KeyError:
pass
else:
filename = script.id
return filename
def asMIMEString(self):
"""
Return a mime-multipart representation of both callgrind profiling
statistics and all involved source code.
Avoids relying on a tempfile, as a zipfile/tarfile would require.
To unpack resulting file, see "unpack a MIME message" in
http://docs.python.org/2/library/email-examples.html
"""
result = MIMEMultipart()
out = StringIO()
self.callgrind(out, relative_path=True)
profile = MIMEApplication(out.getvalue(), 'x-kcachegrind', encode_quopri)
profile.add_header(
'Content-Disposition',
'attachment',
filename='cachegrind.out.pprofile',
)
result.attach(profile)
for name, lines in self.iterSource():
lines = ''.join(lines)
if lines:
pyfile = MIMEText(lines, 'x-python')
pyfile.add_header(
'Content-Disposition',
'attachment',
filename=_relpath(name),
)
result.attach(pyfile)
return result.as_string(), result['content-type']
class ZopeProfiler(ZopeBase, pprofile.Profile):
pass
class ZopeStatisticalProfile(ZopeBase, pprofile.StatisticalProfile):
pass
class ZopeStatisticalThread(pprofile.StatisticalThread):
__allow_access_to_unprotected_subobjects__ = 1
def getProfiler(verbose=False, **kw):
"""
Get a Zope-friendly pprofile.Profile instance.
"""
return ZopeProfiler(**kw)
def getStatisticalProfilerAndThread(**kw):
"""
Get Zope-friendly pprofile.StatisticalProfile and pprofile.StatisticalThread
instances. Arguments are forwarded to StatisticalThread.__init__ .
"""
profiler = ZopeStatisticalProfile()
return profiler, ZopeStatisticalThread(
profiler=profiler,
**kw
)
from zpprofile import getProfiler, getStatisticalProfilerAndThread
......@@ -43,7 +43,10 @@
<item>
<key> <string>text_content_warning_message</string> </key>
<value>
<tuple/>
<tuple>
<string>W: 1, 0: Unused getProfiler imported from zpprofile (unused-import)</string>
<string>W: 1, 0: Unused getStatisticalProfilerAndThread imported from zpprofile (unused-import)</string>
</tuple>
</value>
</item>
<item>
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment