Commit 13e4fe3a authored by Jérome Perrin's avatar Jérome Perrin

testPerformance: support choosing between pprofile and cProfile

parent 18edf533
...@@ -110,8 +110,13 @@ LISTBOX_COEF=0.00173 # 0.02472 ...@@ -110,8 +110,13 @@ LISTBOX_COEF=0.00173 # 0.02472
# LISTBOX_COEF : 0.02472 -> 0.001725 # LISTBOX_COEF : 0.02472 -> 0.001725
DO_TEST = 1 DO_TEST = 1
# Profiler support.
# set 1 to get profiler's result (unit_test/tests/<func_name>) # set 1 to get profiler's result (unit_test/tests/<func_name>)
PROFILE=0 PROFILE = 0
# set this to 'pprofile' to profile with pprofile ( https://github.com/vpelletier/pprofile )
# instad of python's standard library profiler ( https://docs.python.org/2/library/profile.html )
PROFILER = 'pprofile'
class TestPerformanceMixin(ERP5TypeTestCase, LogInterceptor): class TestPerformanceMixin(ERP5TypeTestCase, LogInterceptor):
...@@ -147,15 +152,26 @@ class TestPerformanceMixin(ERP5TypeTestCase, LogInterceptor): ...@@ -147,15 +152,26 @@ class TestPerformanceMixin(ERP5TypeTestCase, LogInterceptor):
""" """
return self.portal['bar_module'] return self.portal['bar_module']
def profile(self, func, suffix=''): def profile(self, func, suffix='', args=(), kw=None):
"""Profile `func(*args, **kw)` with selected profiler,
and dump output in a file called `func.__name__ + suffix`
"""
if not kw:
kw = {}
if PROFILER == 'pprofile':
import pprofile
prof = pprofile.Profile()
else:
from cProfile import Profile from cProfile import Profile
prof = Profile()
prof_file = '%s%s' % (func.__name__, suffix) prof_file = '%s%s' % (func.__name__, suffix)
try: try:
os.unlink(prof_file) os.unlink(prof_file)
except OSError: except OSError:
pass pass
prof = Profile() prof.runcall(func, *args, **kw)
prof.runcall(func)
prof.dump_stats(prof_file) prof.dump_stats(prof_file)
def beforeTearDown(self): def beforeTearDown(self):
...@@ -163,6 +179,7 @@ class TestPerformanceMixin(ERP5TypeTestCase, LogInterceptor): ...@@ -163,6 +179,7 @@ class TestPerformanceMixin(ERP5TypeTestCase, LogInterceptor):
gc.enable() gc.enable()
self.abort() self.abort()
class TestPerformance(TestPerformanceMixin): class TestPerformance(TestPerformanceMixin):
def getTitle(self): def getTitle(self):
......
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