From d65709f68b158a4db4718a565d510ba78f734d69 Mon Sep 17 00:00:00 2001 From: Xavier Morel Date: Wed, 5 Dec 2012 17:08:47 +0100 Subject: [PATCH] [IMP] simplify @profile implementation bzr revid: xmo@openerp.com-20121205160847-8zc8of4grueusbl2 --- openerp/tools/misc.py | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) diff --git a/openerp/tools/misc.py b/openerp/tools/misc.py index 4e3db23bc2d..209e4aaebdf 100644 --- a/openerp/tools/misc.py +++ b/openerp/tools/misc.py @@ -27,6 +27,7 @@ Miscellaneous tools used by OpenERP. """ from functools import wraps +import cProfile import subprocess import logging import os @@ -592,16 +593,10 @@ class profile(object): def __call__(self, f): @wraps(f) def wrapper(*args, **kwargs): - class profile_wrapper(object): - def __init__(self): - self.result = None - def __call__(self): - self.result = f(*args, **kwargs) - pw = profile_wrapper() - import cProfile - fname = self.fname or ("%s.cprof" % (f.func_name,)) - cProfile.runctx('pw()', globals(), locals(), filename=fname) - return pw.result + profile = cProfile.Profile() + result = profile.runcall(f, *args, **kwargs) + profile.dump_stats(self.fname or ("%s.cprof" % (f.func_name,))) + return result return wrapper