diff --git a/src/calibre/library/server/utils.py b/src/calibre/library/server/utils.py index 1732da540c..7dc0884e1a 100644 --- a/src/calibre/library/server/utils.py +++ b/src/calibre/library/server/utils.py @@ -5,7 +5,9 @@ __license__ = 'GPL v3' __copyright__ = '2010, Kovid Goyal ' __docformat__ = 'restructuredtext en' -from calibre import strftime as _strftime +import time + +from calibre import strftime as _strftime, prints from calibre.utils.date import now as nowf @@ -20,6 +22,19 @@ def expose(func): return cherrypy.expose(do) +def timeit(func): + + def do(self, *args, **kwargs): + if self.opts.develop: + start = time.time() + ans = func(self, *args, **kwargs) + if self.opts.develop: + prints('Function', func.__name__, 'called with args:', args, kwargs) + prints('\tTime:', func.__name__, time.time()-start) + return ans + + return do + def strftime(fmt='%Y/%m/%d %H:%M:%S', dt=None): if not hasattr(dt, 'timetuple'): dt = nowf()