--- a/MemMonitor.st Thu Nov 17 15:44:34 1994 +0100
+++ b/MemMonitor.st Thu Nov 17 15:47:59 1994 +0100
@@ -12,8 +12,9 @@
StandardSystemView subclass:#MemoryMonitor
instanceVariableNames:'updateInterval updateBlock myProcess oldData newData
- freeData updateIndex org maxTotal minTotal newColor dX
- freeColor oldColor prevTotal prevFree prevFree2 prevOld'
+ freeData updateIndex org maxTotal minTotal dX
+ newColor freeColor oldColor
+ prevTotal prevFree prevFree2 prevOld scale'
classVariableNames:''
poolDictionaries:''
category:'Interface-Tools'
@@ -23,7 +24,7 @@
COPYRIGHT (c) 1991 by Claus Gittinger
All Rights Reserved
-$Header: /cvs/stx/stx/libtool/Attic/MemMonitor.st,v 1.3 1994-10-28 03:30:33 claus Exp $
+$Header: /cvs/stx/stx/libtool/Attic/MemMonitor.st,v 1.4 1994-11-17 14:46:56 claus Exp $
'!
!MemoryMonitor class methodsFor:'documentation'!
@@ -44,7 +45,7 @@
version
"
-$Header: /cvs/stx/stx/libtool/Attic/MemMonitor.st,v 1.3 1994-10-28 03:30:33 claus Exp $
+$Header: /cvs/stx/stx/libtool/Attic/MemMonitor.st,v 1.4 1994-11-17 14:46:56 claus Exp $
"
!
@@ -61,22 +62,30 @@
new current newSpace in use
- free the first number shows free space in (fragmented) free lists
- the second shows the compact free area above the used oldSpace
+ frl free space in (fragmented) free lists
+ fre compact free area above the used oldSpace
old current oldSpace in use
- max, extreme values of 'all' since the monitor started
- min
+ max, extreme values of 'tot' since the monitor started
+ min (can be reset by typing 'r' in the view)
t tenure threshold
I incremental GC state
+ % percentage of live objects in newSpace after last scavenge
+ (i.e. this is the garbage vs. living objects ratio of
+ newSpace objects after the last scavenge)
+
the graphic shows:
yellow newSpace used
green free memory in freeLists
white oldSpace used
+
+
+ the popupMenu offers GC functions; keyboard options are:
+ 'f' -> faster; 's' -> slower; 'r' -> reset min/max
"
! !
@@ -84,25 +93,18 @@
defaultExtent
^ (200 @ 200)
-! !
-
-!MemoryMonitor class methodsFor:'startup'!
+!
-open
- |m|
-
- m := self new.
+defaultLabel
+ ^ 'Memory Monitor'
+!
- m label:'Memory Monitor'.
- m icon:(Form fromFile:'Monitor.icon' resolution:100).
- m minExtent:(100 @ 100).
+defaultIcon
+ |i|
- m open.
- ^ m
-
- "
- MemoryMonitor open
- "
+ i := Image fromFile:'bitmaps/monitor.icon'.
+ i notNil ifTrue:[^ i].
+ ^ super defaultIcon
! !
!MemoryMonitor methodsFor:'drawing'!
@@ -117,26 +119,26 @@
redrawX:x y:y width:w height:h
"redraw data"
- |total oldSpaceUsed newSpaceUsed freeMem lx scale s startIdx endIdx|
+ |total oldSpaceUsed newSpaceUsed freeMem lx s startIdx endIdx
+ right|
shown ifFalse:[^ self].
- (x + w - 1) > org ifTrue:[
+ right := x + w - 1.
+ right >= org ifTrue:[
lx := x.
lx < org ifTrue:[
lx := org
].
- scale := height asFloat / (maxTotal + 100000).
-
total := ObjectMemory oldSpaceSize + ObjectMemory newSpaceSize.
- startIdx := (x-org+1).
+ startIdx := (lx-org+1).
startIdx < 1 ifTrue:[
startIdx := 1
].
- endIdx := (x + w - 1)-org+1.
+ endIdx := right-org+1.
endIdx >= updateIndex ifTrue:[
endIdx := updateIndex-1.
].
@@ -152,8 +154,7 @@
total:total
old:oldSpaceUsed
new:newSpaceUsed
- free:freeMem
- scale:scale.
+ free:freeMem.
].
lx := lx + 1
]
@@ -163,28 +164,16 @@
prevFree := prevFree2 := prevOld := prevTotal := nil.
self updateNumbers.
-
- self paint:White on:Black.
- s := 'max ' , ((maxTotal // 1024) printStringRightAdjustLen:5) , 'k '.
- self displayOpaqueString:s x:0 y:font ascent.
-
- s := 'min ' , ((minTotal // 1024) printStringRightAdjustLen:5) , 'k '.
- self displayOpaqueString:s x:0 y:(height - font descent).
-
]
!
-updateLineX:x total:total old:oldSpaceUsed new:newSpaceUsed free:freeMem scale:scale
+updateLineX:x total:total old:oldSpaceUsed new:newSpaceUsed free:freeMem
|hNew hOld hFree y1 y2|
hNew := (newSpaceUsed * scale) asInteger.
- hOld := (oldSpaceUsed * scale) asInteger // 2.
+ hOld := (oldSpaceUsed * scale) // 2.
hFree := (freeMem * scale) asInteger.
-"/ self paint:Black.
-"/ self displayLineFromX:x y:0 toX:x y:height-1.
-
-
y1 := height - 1.
y2 := y1 - hOld.
self paint:oldColor.
@@ -214,8 +203,7 @@
"
|oldSpaceSize newSpaceSize memUsed oldMemUsed newMemUsed freeMem free2
- x y
- half scaleChange s thisStringLen scale fontHeight total|
+ x y half s thisStringLen fontHeight total n|
oldMemUsed := ObjectMemory oldSpaceUsed.
newMemUsed := ObjectMemory newSpaceUsed.
@@ -227,13 +215,6 @@
total := oldSpaceSize + newSpaceSize.
free2 := oldSpaceSize - oldMemUsed.
- ((total - freeMem) < minTotal) ifTrue:[
- minTotal := total - freeMem.
- ].
- (total > maxTotal) ifTrue:[
- maxTotal := total.
- ].
-
self paint:White on:Black.
fontHeight := font height + font descent.
@@ -242,8 +223,22 @@
y := half - (fontHeight * 3).
total ~~ prevTotal ifTrue:[
+ ((total - freeMem) < minTotal) ifTrue:[
+ minTotal := total - freeMem.
+ ].
+ (total > maxTotal) ifTrue:[
+ maxTotal := total.
+ ].
+
+ s := 'max ' , ((maxTotal // 1024) printStringRightAdjustLen:5) , 'k '.
+ self displayOpaqueString:s x:0 y:font ascent.
+
+ s := 'min ' , ((minTotal // 1024) printStringRightAdjustLen:5) , 'k '.
+ self displayOpaqueString:s x:0 y:(height - font descent).
+
s := 'tot ' , ((total // 1024) printStringRightAdjustLen:5) , 'k '.
self displayOpaqueString:s x:0 y:y.
+
prevTotal := total.
].
@@ -259,7 +254,7 @@
y := y + fontHeight.
freeMem ~~ prevFree ifTrue:[
self paint:freeColor.
- s := 'free' , ((freeMem // 1024) printStringRightAdjustLen:5) , 'k '.
+ s := 'frl ' , ((freeMem // 1024) printStringRightAdjustLen:5) , 'k '.
self displayOpaqueString:s x:0 y:y.
prevFree := freeMem.
].
@@ -267,7 +262,7 @@
y := y + fontHeight.
free2 ~~ prevFree2 ifTrue:[
self paint:freeColor.
- s := ' ' , ((free2 // 1024) printStringRightAdjustLen:5) , 'k '.
+ s := 'fre ' , ((free2 // 1024) printStringRightAdjustLen:5) , 'k '.
self displayOpaqueString:s x:0 y:y.
prevFree2 := free2.
].
@@ -295,13 +290,18 @@
"/ self displayOpaqueString:'single' x:0 y:(half + (fontHeight*4)).
"/ ].
+ y := y + fontHeight.
+ n := ObjectMemory lastScavangeReclamation / ObjectMemory newSpaceSize * 100.0.
+ n := 100 - n asInteger.
+ s := (n printStringRightAdjustLen:2) , '%'.
+ self displayOpaqueString:s x:0 y:y.
!
updateDisplay
"update picture; trigger next update"
|total oldSpaceUsed newSpaceUsed freeMem
- gWidth shift scaleChange scale margin|
+ gWidth shift scaleChange margin mustWait|
shown ifTrue:[
oldSpaceUsed := ObjectMemory oldSpaceUsed.
@@ -310,7 +310,7 @@
total := oldSpaceUsed + newSpaceUsed.
scaleChange := false.
-
+
((total - freeMem) < minTotal) ifTrue:[
minTotal := total - freeMem.
scaleChange := true
@@ -326,12 +326,14 @@
updateIndex := updateIndex + 1.
scaleChange ifTrue:[
+ scale := height asFloat / (maxTotal + 100000).
self redraw
].
gWidth := width - org.
margin := 1.
+ mustWait := false.
((updateIndex-1) >= (gWidth - margin)) ifTrue:[
"on slow displays, use:"
"/ shift := gWidth // 4.
@@ -354,18 +356,19 @@
height:height.
self clearRectangleX:(width - margin - shift) y:0
width:shift height:height.
- self waitForExpose.
+ mustWait := true.
].
- scale := height asFloat / (maxTotal + 100000).
- self updateLineX:(updateIndex - 1 + org)
+ self updateLineX:(updateIndex - 1 + org - 1)
total:total
old:oldSpaceUsed
new:newSpaceUsed
- free:freeMem
- scale:scale.
+ free:freeMem.
self updateNumbers.
+ mustWait ifTrue:[
+ self waitForExpose.
+ ]
].
@@ -391,10 +394,18 @@
keyPress:key x:x y:y
key == $f ifTrue:[
+ "faster"
updateInterval := updateInterval / 2
].
key == $s ifTrue:[
+ "slower"
updateInterval := updateInterval * 2
+ ].
+ key == $r ifTrue:[
+ "reset max"
+ maxTotal := prevTotal.
+ scale := height asFloat / (maxTotal + 100000).
+ self redraw.
]
!
@@ -429,6 +440,8 @@
oldData := no.
freeData := nf.
+ scale := height asFloat / (maxTotal + 100000).
+ self clear.
self redraw
! !
@@ -469,7 +482,8 @@
freeData := Array new:1000.
updateIndex := 1.
- org := font widthOf:'used:9999k '.
+ org := font widthOf:'max 99999k'.
+ level := 0.
maxTotal := minTotal := ObjectMemory oldSpaceSize + ObjectMemory newSpaceSize.
@@ -490,5 +504,37 @@
"
MemoryMonitor open
"
+!
+
+initializeMiddleButtonMenu
+ self middleButtonMenu:
+ (PopUpMenu labels:(resources array:#(
+ 'collect Garbage'
+ 'collect Garbage & compress'
+ '-'
+ 'background collect'
+ ))
+ selectors:#(
+ garbageCollect
+ compressingGarbageCollect
+ nil
+ backgroundCollect
+ )
+ receiver:self
+ for:self)
! !
+!MemoryMonitor methodsFor:'menu functions'!
+
+garbageCollect
+ ObjectMemory markAndSweep
+!
+
+compressingGarbageCollect
+ ObjectMemory verboseGarbageCollect
+!
+
+backgroundCollect
+ [ObjectMemory incrementalGC] forkAt:4
+! !
+