Browse Source

changed debug output

Dave Schuyler 19 years ago
parent
commit
75ecd2cf92
1 changed files with 44 additions and 18 deletions
  1. 44 18
      direct/src/distributed/DoInterestManager.py

+ 44 - 18
direct/src/distributed/DoInterestManager.py

@@ -50,7 +50,8 @@ class DoInterestManager(DirectObject.DirectObject):
 
 
     _interests = {}
     _interests = {}
     if __debug__:
     if __debug__:
-        _debug_currentInterests = []
+        _debug_currentInterests = {}
+        _debug_interestHistory = []
 
 
     def __init__(self):
     def __init__(self):
         assert DoInterestManager.notify.debugCall()
         assert DoInterestManager.notify.debugCall()
@@ -66,7 +67,8 @@ class DoInterestManager(DirectObject.DirectObject):
             scopeId = self._getNextScopeId()
             scopeId = self._getNextScopeId()
         else:
         else:
             scopeId = NO_SCOPE
             scopeId = NO_SCOPE
-        DoInterestManager._interests[handle] = [description, STATE_ACTIVE, scopeId, event]
+        DoInterestManager._interests[handle] = [
+            description, STATE_ACTIVE, scopeId, event]
         if self.InterestDebug:
         if self.InterestDebug:
             print 'INTEREST DEBUG: addInterest(): handle=%s, parent=%s, zoneIds=%s, description=%s, event=%s' % (
             print 'INTEREST DEBUG: addInterest(): handle=%s, parent=%s, zoneIds=%s, description=%s, event=%s' % (
                 handle, parentId, zoneIdList, description, event)
                 handle, parentId, zoneIdList, description, event)
@@ -90,14 +92,17 @@ class DoInterestManager(DirectObject.DirectObject):
             DoInterestManager._interests[handle][SCOPE] = scopeId
             DoInterestManager._interests[handle][SCOPE] = scopeId
             DoInterestManager._interests[handle][EVENT] = event
             DoInterestManager._interests[handle][EVENT] = event
             if self.InterestDebug:
             if self.InterestDebug:
-                print 'INTEREST DEBUG: removeInterest(): handle=%s, event=%s' % (handle, event)
+                print 'INTEREST DEBUG: removeInterest(): handle=%s, event=%s' % (
+                    handle, event)
             self._sendRemoveInterest(handle, scopeId)
             self._sendRemoveInterest(handle, scopeId)
         else:
         else:
-            DoInterestManager.notify.warning("removeInterest: handle not found: %s" % (handle))
+            DoInterestManager.notify.warning(
+                "removeInterest: handle not found: %s" % (handle))
         assert self.printInterestsIfDebug()
         assert self.printInterestsIfDebug()
         return existed
         return existed
 
 
-    def alterInterest(self, handle, parentId, zoneIdList, description=None, event=None):
+    def alterInterest(self, handle, parentId, zoneIdList, description=None,
+            event=None):
         """
         """
         Removes old interests and adds new interests.
         Removes old interests and adds new interests.
 
 
@@ -125,7 +130,8 @@ class DoInterestManager(DirectObject.DirectObject):
             exists = True
             exists = True
             assert self.printInterestsIfDebug()
             assert self.printInterestsIfDebug()
         else:
         else:
-            DoInterestManager.notify.warning("alterInterest: handle not found: %s" % (handle))
+            DoInterestManager.notify.warning(
+                "alterInterest: handle not found: %s" % (handle))
         return exists
         return exists
 
 
     def _getNextHandle(self):
     def _getNextHandle(self):
@@ -135,7 +141,8 @@ class DoInterestManager(DirectObject.DirectObject):
             # skip handles that are already in use
             # skip handles that are already in use
             if handle not in DoInterestManager._interests:
             if handle not in DoInterestManager._interests:
                 break
                 break
-            DoInterestManager.notify.warning('interest %s already in use' % handle)
+            DoInterestManager.notify.warning(
+                'interest %s already in use' % handle)
         DoInterestManager._HandleSerialNum = handle
         DoInterestManager._HandleSerialNum = handle
         return DoInterestManager._HandleSerialNum
         return DoInterestManager._HandleSerialNum
     def _getNextScopeId(self):
     def _getNextScopeId(self):
@@ -163,18 +170,27 @@ class DoInterestManager(DirectObject.DirectObject):
         def printInterestsIfDebug(self):
         def printInterestsIfDebug(self):
             if DoInterestManager.notify.getDebug():
             if DoInterestManager.notify.getDebug():
                 self.printInterests()
                 self.printInterests()
-            return 1 # for assert()
+            return 1 # for assert
 
 
         def printInterests(self):
         def printInterests(self):
-            print "*********************** Interest Sets **************"
-            print "handle: [Description, State, Scope, Event]"
+            print "***************** Interest History *************"
+            format = '%9s %6s %6s %9s %s'
+            print format % (
+                "Action", "Handle", "Scope", "ParentId",
+                "ZoneIdList")
+            for i in DoInterestManager._debug_interestHistory:
+                print format % tuple(i)
+            print "Note: interests with a Scope of 0 do not get" \
+                " done/finished notices."
+            print "******************* Interest Sets **************"
+            format = '%6s %20s %10s %8s %5s %9s %9s %s'
+            print format % (
+                "Handle", "Description", "State", "Scope", "Event", 
+                "ScopeId", "ParentId", "ZoneIdList")
             for id, data in DoInterestManager._interests.items():
             for id, data in DoInterestManager._interests.items():
-                print '%s: %s' % (id, data)
-            print "************************** History *****************"
-            print "(Handle, ScopeId, ParentId, ZoneIdList)"
-            for i in DoInterestManager._debug_currentInterests:
-                print i
-            print "****************************************************"
+                print format % tuple((id,) + tuple(data) + \
+                    DoInterestManager._debug_currentInterests.get(id))
+            print "************************************************"
 
 
     def _sendAddInterest(self, handle, scopeId, parentId, zoneIdList):
     def _sendAddInterest(self, handle, scopeId, parentId, zoneIdList):
         """
         """
@@ -189,8 +205,10 @@ class DoInterestManager(DirectObject.DirectObject):
         if __debug__:
         if __debug__:
             if isinstance(zoneIdList, types.ListType):
             if isinstance(zoneIdList, types.ListType):
                 zoneIdList.sort()
                 zoneIdList.sort()
-            DoInterestManager._debug_currentInterests.append(
-                (handle, scopeId, parentId, zoneIdList))
+            DoInterestManager._debug_currentInterests[handle]=(
+                scopeId, parentId, zoneIdList)
+            DoInterestManager._debug_interestHistory.append(
+                ("add", handle, scopeId, parentId, zoneIdList))
         if parentId == 0:
         if parentId == 0:
             DoInterestManager.notify.error(
             DoInterestManager.notify.error(
                 'trying to set interest to invalid parent: %s' % parentId)
                 'trying to set interest to invalid parent: %s' % parentId)
@@ -225,6 +243,10 @@ class DoInterestManager(DirectObject.DirectObject):
         if scopeId != 0:
         if scopeId != 0:
             datagram.addUint32(scopeId)
             datagram.addUint32(scopeId)
         self.send(datagram)
         self.send(datagram)
+        if __debug__:
+            DoInterestManager._debug_interestHistory.append(
+                ("remove", handle, scopeId) +
+                DoInterestManager._debug_currentInterests.get(handle)[1:])
 
 
     def handleInterestDoneMessage(self, di):
     def handleInterestDoneMessage(self, di):
         """
         """
@@ -251,5 +273,9 @@ class DoInterestManager(DirectObject.DirectObject):
                 "handleInterestDoneMessage--> Expecting scope %s, got %s" % (
                 "handleInterestDoneMessage--> Expecting scope %s, got %s" % (
                 DoInterestManager._interests[handle][SCOPE], scopeId))
                 DoInterestManager._interests[handle][SCOPE], scopeId))
         self._considerRemoveInterest(handle)
         self._considerRemoveInterest(handle)
+        if __debug__:
+            DoInterestManager._debug_interestHistory.append(
+                ("finished", handle, scopeId) +
+                DoInterestManager._debug_currentInterests.get(handle)[1:])
 
 
         assert self.printInterestsIfDebug()
         assert self.printInterestsIfDebug()