Change in vdsm[master]: vm: debug aid to track of threads holding locks

fromani at redhat.com fromani at redhat.com
Wed Nov 5 09:48:29 UTC 2014


Francesco Romani has uploaded a new change for review.

Change subject: vm: debug aid to track of threads holding locks
......................................................................

vm: debug aid to track of threads holding locks

DO NOT MERGE
at best, this code does not belong here.

Change-Id: I631fb124b8a36d2950debfe806777df896094a9d
Signed-off-by: Francesco Romani <fromani at redhat.com>
---
M vdsm/virt/vm.py
1 file changed, 45 insertions(+), 1 deletion(-)


  git pull ssh://gerrit.ovirt.org:29418/vdsm refs/changes/11/34811/1

diff --git a/vdsm/virt/vm.py b/vdsm/virt/vm.py
index 9740ab3..3c4b9a6 100644
--- a/vdsm/virt/vm.py
+++ b/vdsm/virt/vm.py
@@ -24,6 +24,7 @@
 from contextlib import contextmanager
 from copy import deepcopy
 from xml.dom.minidom import parseString as _domParseStr
+import inspect
 import logging
 import os
 import tempfile
@@ -101,6 +102,49 @@
 
 # A libvirt constant for undefined cpu period
 _NO_CPU_PERIOD = 0
+
+
+# Class to wrap Lock and simplify logging of lock usage
+class LoggingLock(object):
+    """
+    Wraps a standard Lock, so that attempts to use the
+    lock according to its API are logged for debugging purposes
+
+    """
+    def __init__(self, name, log):
+        self.name = str(name)
+        self.log = log
+        self.lock = threading.Lock()
+        self.log.debug("{0} created {1}".format(
+            self._caller(), self.name))
+
+    def acquire(self, blocking=True):
+        self.log.debug("{0} trying to acquire {1}".format(
+            self._caller(), self.name))
+        ret = self.lock.acquire(blocking)
+        if ret == True:
+            self.log.debug("{0} acquired {1}".format(
+                self._caller(), self.name))
+        else:
+            self.log.debug("{0} non-blocking acquire of {1} lock failed".format(
+                self._caller(), self.name))
+        return ret
+
+    def release(self):
+        self.log.debug("{0} releasing {1}".format(
+            self.caller(), self.name))
+        self.lock.release()
+
+    def __enter__(self):
+        self.acquire()
+
+    def __exit__(self, exc_type, exc_val, exc_tb):
+        self.release()
+        return False # Do not swallow exceptions
+
+    def _caller(self, level=5):
+        # frame[3] is function/method name.
+        return ','.join(frame[3] for frame in inspect.stack()[:level+1])
 
 
 def _listDomains():
@@ -1249,7 +1293,7 @@
         self._monitorResponse = 0
         self.conf['clientIp'] = ''
         self.memCommitted = 0
-        self._confLock = threading.Lock()
+        self._confLock = LoggingLock('confLock', self.log)
         self._jobsLock = threading.Lock()
         self._creationThread = threading.Thread(target=self._startUnderlyingVm)
         if 'migrationDest' in self.conf:


-- 
To view, visit http://gerrit.ovirt.org/34811
To unsubscribe, visit http://gerrit.ovirt.org/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I631fb124b8a36d2950debfe806777df896094a9d
Gerrit-PatchSet: 1
Gerrit-Project: vdsm
Gerrit-Branch: master
Gerrit-Owner: Francesco Romani <fromani at redhat.com>


More information about the vdsm-patches mailing list