Merge "Cleanup and adding timing to lockutils logging"
This commit is contained in:
commit
afdc56d83a
@ -280,14 +280,27 @@ def synchronized(name, lock_file_prefix=None, external=False, lock_path=None):
|
|||||||
def wrap(f):
|
def wrap(f):
|
||||||
@functools.wraps(f)
|
@functools.wraps(f)
|
||||||
def inner(*args, **kwargs):
|
def inner(*args, **kwargs):
|
||||||
|
t1 = time.time()
|
||||||
|
t2 = None
|
||||||
try:
|
try:
|
||||||
with lock(name, lock_file_prefix, external, lock_path):
|
with lock(name, lock_file_prefix, external, lock_path):
|
||||||
LOG.debug('Got semaphore / lock "%(function)s"',
|
t2 = time.time()
|
||||||
{'function': f.__name__})
|
LOG.debug('Lock "%(name)s" acquired by "%(function)s" :: '
|
||||||
|
'waited %(wait_secs)0.3fs',
|
||||||
|
{'name': name, 'function': f.__name__,
|
||||||
|
'wait_secs': (t2 - t1)})
|
||||||
return f(*args, **kwargs)
|
return f(*args, **kwargs)
|
||||||
finally:
|
finally:
|
||||||
LOG.debug('Semaphore / lock released "%(function)s"',
|
t3 = time.time()
|
||||||
{'function': f.__name__})
|
if t2 is None:
|
||||||
|
held_secs = "N/A"
|
||||||
|
else:
|
||||||
|
held_secs = "%0.3fs" % (t3 - t2)
|
||||||
|
|
||||||
|
LOG.debug('Lock "%(name)s" released by "%(function)s" :: held '
|
||||||
|
'%(held_secs)s',
|
||||||
|
{'name': name, 'function': f.__name__,
|
||||||
|
'held_secs': held_secs})
|
||||||
return inner
|
return inner
|
||||||
return wrap
|
return wrap
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user