Browse Source

log number of garbage cycles even if we've previously printed the full info on those cycles

Darren Ranalli 17 years ago
parent
commit
fcfd9f8e20
1 changed files with 11 additions and 8 deletions
  1. 11 8
      direct/src/showbase/GarbageReport.py

+ 11 - 8
direct/src/showbase/GarbageReport.py

@@ -514,8 +514,9 @@ class GarbageReport(Job):
 class GarbageLogger(GarbageReport):
 class GarbageLogger(GarbageReport):
     """If you just want to log the current garbage to the log file, make
     """If you just want to log the current garbage to the log file, make
     one of these. It automatically destroys itself after logging"""
     one of these. It automatically destroys itself after logging"""
-    # variable for checkForGarbageLeaks
+    # for checkForGarbageLeaks
     LastNumGarbage = 0
     LastNumGarbage = 0
+    LastNumCycles = 0
     def __init__(self, name, *args, **kArgs):
     def __init__(self, name, *args, **kArgs):
         kArgs['log'] = True
         kArgs['log'] = True
         kArgs['autoDestroy'] = True
         kArgs['autoDestroy'] = True
@@ -524,18 +525,20 @@ class GarbageLogger(GarbageReport):
 def checkForGarbageLeaks():
 def checkForGarbageLeaks():
     gc.collect()
     gc.collect()
     numGarbage = len(gc.garbage)
     numGarbage = len(gc.garbage)
-    if ((numGarbage != GarbageLogger.LastNumGarbage) and
-        (not configIsToday('disable-garbage-logging'))):
-        GarbageLogger.LastNumGarbage = numGarbage
-        print
-        gr = GarbageLogger('found garbage', threaded=False, collect=False)
-        print
+    if (numGarbage > 0 and (not configIsToday('disable-garbage-logging'))):
+        if (numGarbage != GarbageLogger.LastNumGarbage):
+            print
+            gr = GarbageLogger('found garbage', threaded=False, collect=False)
+            print
+            GarbageLogger.LastNumGarbage = numGarbage
+            GarbageLogger.LastNumCycles = gr.getNumCycles()
         notify = directNotify.newCategory("GarbageDetect")
         notify = directNotify.newCategory("GarbageDetect")
         if config.GetBool('allow-garbage-cycles', 1):
         if config.GetBool('allow-garbage-cycles', 1):
             func = notify.warning
             func = notify.warning
         else:
         else:
             func = notify.error
             func = notify.error
-        func('%s garbage cycles found, see info above' % gr.getNumCycles())
+        func('%s garbage cycles found, see info above' %
+             GarbageLogger.LastNumCycles)
     return numGarbage
     return numGarbage
 
 
 def b_checkForGarbageLeaks(wantReply=False):
 def b_checkForGarbageLeaks(wantReply=False):