From e67bd55986c571e50b89749cd6195302682b8161 Mon Sep 17 00:00:00 2001
From: Michael Hanselmann <hansmi@google.com>
Date: Tue, 26 Aug 2008 15:44:34 +0000
Subject: [PATCH] Add simple lock debug output

Currently it can only be enabled by modifying utils.py, but we can
add a command line parameter later if needed.

Reviewed-by: schreiberal
---
 lib/utils.py | 9 +++++++++
 1 file changed, 9 insertions(+)

diff --git a/lib/utils.py b/lib/utils.py
index e2ac3d36a..a861d7363 100644
--- a/lib/utils.py
+++ b/lib/utils.py
@@ -52,6 +52,7 @@ _locksheld = []
 _re_shell_unquoted = re.compile('^[-.,=:/_+@A-Za-z0-9]+$')
 
 debug = False
+debug_locks = False
 no_fork = False
 
 
@@ -1202,14 +1203,22 @@ def LockedMethod(fn):
   object's own lock which is hardcoded to '_lock'.
 
   """
+  def _LockDebug(*args, **kwargs):
+    if debug_locks:
+      logging.debug(*args, **kwargs)
+
   def wrapper(self, *args, **kwargs):
     assert hasattr(self, '_lock')
     lock = self._lock
+    _LockDebug("Waiting for %s", lock)
     lock.acquire()
     try:
+      _LockDebug("Acquired %s", lock)
       result = fn(self, *args, **kwargs)
     finally:
+      _LockDebug("Releasing %s", lock)
       lock.release()
+      _LockDebug("Released %s", lock)
     return result
   return wrapper
 
-- 
GitLab