MemoryMonitorView.st
changeset 17013 cf59893a8693
parent 16743 539e6058dba1
child 17136 cb908d2ba02e
child 17434 bfd610008561
--- a/MemoryMonitorView.st	Thu Nov 03 15:33:22 2016 +0100
+++ b/MemoryMonitorView.st	Thu Nov 03 21:32:42 2016 +0100
@@ -1,5 +1,3 @@
-"{ Encoding: utf8 }"
-
 "
  COPYRIGHT (c) 1991 by Claus Gittinger
 	      All Rights Reserved
@@ -21,7 +19,8 @@
 		prevTotal prevLimit prevFree prevFree2 prevOld scale drawLock
 		prevMemUsed prevCodeUsed prevNumWeak prevNumRem prevNumLifoRem
 		prevTenureAge prevIGCPhase prevLastScavengeReclamation
-		prevMinScavengeReclamation prevScavengeCount mallocColor'
+		prevMinScavengeReclamation prevScavengeCount mallocColor
+		drawAction'
 	classVariableNames:''
 	poolDictionaries:''
 	category:'Monitors-ST/X'
@@ -97,6 +96,10 @@
     the popupMenu offers GC functions; keyboard options are:
         'f' -> faster; 's' -> slower; 'r' -> reset min/max
 
+    Disclaimer:
+        this was one of the first tools written for ST/X (around 1989/90);
+        today, it would probably be written differently...
+        
     [author:]
         Claus Gittinger
 
@@ -130,6 +133,91 @@
     "Modified: / 23.9.1998 / 13:19:04 / cg"
 !
 
+initializeDrawAction
+    "extracted into a separate block to avoid memory allocation in updateDisplay"
+    
+    drawAction :=
+        [    
+            |total oldSpaceUsed newSpaceUsed freeMem oldSpaceSize
+             realOldSpaceSize symSpaceSize realOldSpaceUsed
+             gWidth shift scaleChange margin|
+
+            realOldSpaceSize := ObjectMemory oldSpaceSize.
+            symSpaceSize := ObjectMemory symSpaceSize.
+            realOldSpaceUsed := ObjectMemory oldSpaceUsed.
+            
+            oldSpaceUsed := realOldSpaceUsed + ObjectMemory symSpaceUsed.
+            newSpaceUsed := ObjectMemory newSpaceUsed.
+            freeMem := ObjectMemory freeListSpace + (realOldSpaceSize - realOldSpaceUsed).
+            oldSpaceSize := realOldSpaceSize + symSpaceSize.
+            total := oldSpaceSize + ObjectMemory newSpaceSize.
+
+            scaleChange := false.
+
+            ((total - freeMem) < minTotal) ifTrue:[
+                minTotal := total - freeMem.
+                scaleChange := true
+            ].
+            (total > maxTotal) ifTrue:[
+                maxTotal := total.
+                scaleChange := true
+            ].
+
+            oldData at:updateIndex put:oldSpaceSize. "/ oldSpaceUsed.
+            newData at:updateIndex put:newSpaceUsed.
+            freeData at:updateIndex put:freeMem.
+            updateIndex := updateIndex + 1.
+
+            scaleChange ifTrue:[
+                scale := height asFloat / (maxTotal + 100000).
+                self redraw
+            ].
+
+            gWidth := width - org.
+            margin := 1.
+
+            ((updateIndex-1) >= (gWidth - margin)) ifTrue:[
+                "on slow displays, use:"
+                "/            shift := gWidth // 4.
+
+                "for smooth display, use:"
+                shift := 1.
+
+                oldData replaceFrom:1 with:oldData startingAt:shift+1.
+                newData replaceFrom:1 with:newData startingAt:shift+1.
+                freeData replaceFrom:1 with:freeData startingAt:shift+1.
+
+                updateIndex := updateIndex - shift.
+                dX := (dX ? 0) + shift.
+
+                "/ before copying, handle any outstanding exposes ...
+                self repairDamage.
+                "/ self catchExpose.
+                self 
+                    copyFrom:self 
+                    x:(org + shift) y:0 toX:org y:0
+                    width:(gWidth - shift - margin) height:height
+                    async:false.
+
+                self 
+                    clearRectangleX:(width - margin - shift) y:0 
+                    width:shift height:height.
+
+                "/ self waitForExpose.
+            ].
+
+            self 
+                updateLineX:(updateIndex - 1 + org - 1)
+                total:total 
+                old:oldSpaceSize "/ oldSpaceUsed
+                new:newSpaceUsed 
+                free:freeMem.
+
+            self updateNumbers.
+            self flush.
+        ].
+!
+
 redraw
     "redraw all"
 
@@ -201,82 +289,9 @@
 updateDisplay
     "update picture; trigger next update"
 
-    |total oldSpaceUsed newSpaceUsed freeMem oldSpaceSize
-     gWidth shift scaleChange margin|
-
     shown ifTrue:[
         drawLock wouldBlock ifFalse:[
-            drawLock critical:[
-                
-                oldSpaceUsed := ObjectMemory oldSpaceUsed + ObjectMemory symSpaceUsed.
-                newSpaceUsed := ObjectMemory newSpaceUsed.
-                freeMem := ObjectMemory freeListSpace + (ObjectMemory oldSpaceSize - ObjectMemory oldSpaceUsed).
-                oldSpaceSize := ObjectMemory oldSpaceSize + ObjectMemory symSpaceSize.
-                total := oldSpaceSize + ObjectMemory newSpaceSize.
-
-                scaleChange := false.
-
-                ((total - freeMem) < minTotal) ifTrue:[
-                    minTotal := total - freeMem.
-                    scaleChange := true
-                ].
-                (total > maxTotal) ifTrue:[
-                    maxTotal := total.
-                    scaleChange := true
-                ].
-
-                oldData at:updateIndex put:oldSpaceSize. "/ oldSpaceUsed.
-                newData at:updateIndex put:newSpaceUsed.
-                freeData at:updateIndex put:freeMem.
-                updateIndex := updateIndex + 1.
-
-                scaleChange ifTrue:[
-                    scale := height asFloat / (maxTotal + 100000).
-                    self redraw
-                ].
-
-                gWidth := width - org.
-                margin := 1.
-
-                ((updateIndex-1) >= (gWidth - margin)) ifTrue:[
-        "on slow displays, use:"
-        "/            shift := gWidth // 4.
-
-        "for smooth display, use:"
-                    shift := 1.
-
-                    oldData replaceFrom:1 with:oldData startingAt:shift+1.
-                    newData replaceFrom:1 with:newData startingAt:shift+1.
-                    freeData replaceFrom:1 with:freeData startingAt:shift+1.
-
-                    updateIndex := updateIndex - shift.
-                    dX := (dX ? 0) + shift.
-
-                    "/ before copying, handle any outstanding exposes ...
-                    self repairDamage.
-                    "/ self catchExpose.
-                    self copyFrom:self 
-                                x:(org + shift) y:0
-                              toX:org y:0
-                            width:(gWidth - shift - margin)
-                           height:height
-                            async:false.
-
-                    self clearRectangleX:(width - margin - shift) y:0 
-                                   width:shift height:height.
-
-                    "/ self waitForExpose.
-                ].
-
-                self updateLineX:(updateIndex - 1 + org - 1)
-                           total:total 
-                           old:oldSpaceSize "/ oldSpaceUsed
-                           new:newSpaceUsed 
-                           free:freeMem.
-
-                self updateNumbers.
-                self flush.
-            ].
+            drawLock critical:drawAction.
         ].
     ].
 
@@ -341,7 +356,7 @@
      mallocAllocated mallocTotal
      codeUsed numWeak numRem numLifoRem tenureAge igcPhase 
      minScavengeReclamation lastScavengeReclamation scavengeCount
-     y half s fontHeight fontAscent fontDescent 
+     y half s font fontHeight fontAscent fontDescent 
      limit total n prevMallocAllocated prevMallocTotal|
 
     oldMemUsed := ObjectMemory oldSpaceUsed + ObjectMemory symSpaceUsed.
@@ -360,9 +375,10 @@
 
     self paint:self whiteColor on:self blackColor.
 
-    fontDescent := gc font descent.
-    fontAscent := gc font ascent.
-    fontHeight := gc font height + fontDescent.
+    font := gc font.
+    fontDescent := font descent.
+    fontAscent := font ascent.
+    fontHeight := font height + fontDescent.
     half := height // 2 + fontDescent.
 
     y := half - (fontHeight * 8).
@@ -614,6 +630,8 @@
 initialize
     super initialize.
 
+    self initializeDrawAction.
+
     drawLock := Semaphore forMutualExclusion name:'drawLock'.
 
     updateInterval := 0.5.