Fundraising in PDF.
[wolnelektury.git] / src / wolnelektury / management / profile.py
1 # This file is part of Wolne Lektury, licensed under GNU Affero GPLv3 or later.
2 # Copyright © Fundacja Wolne Lektury. See NOTICE for more information.
3 #
4 import cProfile
5 import functools
6 import os
7
8 _object = None
9
10
11 def profile(meth):
12     def _wrapper(self, *args, **kwargs):
13         setattr(self, "__%s" % meth.__name__, meth)
14         cProfile.runctx(
15             'object.__%s(object, *args, **kwargs)' % (meth.__name__, ), globals(), locals(),
16             'profile.%d' % os.getpid())
17
18     functools.update_wrapper(_wrapper, meth)
19     return _wrapper