Timing infrastructure for the content server

This commit is contained in:
Kovid Goyal 2010-05-23 12:28:24 -06:00
parent 10ad5cabcc
commit d7fa2363a8

View File

@ -5,7 +5,9 @@ __license__ = 'GPL v3'
__copyright__ = '2010, Kovid Goyal <kovid@kovidgoyal.net>'
__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()