2363
|
1 |
"
|
|
2 |
COPYRIGHT (c) 1991 by Claus Gittinger
|
|
3 |
All Rights Reserved
|
|
4 |
|
|
5 |
This software is furnished under a license and may be used
|
|
6 |
only in accordance with the terms of that license and with the
|
|
7 |
inclusion of the above copyright notice. This software may not
|
|
8 |
be provided or otherwise made available to, or used by, any
|
|
9 |
other person. No title to or ownership of the software is
|
|
10 |
hereby transferred.
|
|
11 |
"
|
|
12 |
|
|
13 |
View subclass:#MemoryMonitorView
|
|
14 |
instanceVariableNames:'updateInterval updateBlock myProcess oldData newData freeData
|
|
15 |
updateIndex org maxTotal minTotal dX newColor freeColor oldColor
|
|
16 |
prevTotal prevFree prevFree2 prevOld scale drawLock prevMemUsed
|
|
17 |
prevCodeUsed prevNumWeak prevNumRem prevNumLifoRem prevTenureAge
|
|
18 |
prevIGCPhase prevLastScavengeReclamation
|
|
19 |
prevMinScavengeReclamation prevScavengeCount'
|
|
20 |
classVariableNames:''
|
|
21 |
poolDictionaries:''
|
|
22 |
category:'Monitors-ST/X'
|
|
23 |
!
|
|
24 |
|
|
25 |
!MemoryMonitorView class methodsFor:'documentation'!
|
|
26 |
|
|
27 |
copyright
|
|
28 |
"
|
|
29 |
COPYRIGHT (c) 1991 by Claus Gittinger
|
|
30 |
All Rights Reserved
|
|
31 |
|
|
32 |
This software is furnished under a license and may be used
|
|
33 |
only in accordance with the terms of that license and with the
|
|
34 |
inclusion of the above copyright notice. This software may not
|
|
35 |
be provided or otherwise made available to, or used by, any
|
|
36 |
other person. No title to or ownership of the software is
|
|
37 |
hereby transferred.
|
|
38 |
"
|
|
39 |
!
|
|
40 |
|
|
41 |
documentation
|
|
42 |
"
|
|
43 |
Shows memory usage (oldspace + newspace). Simple, but useful.
|
|
44 |
|
|
45 |
The numbers shown are:
|
|
46 |
tot total memory usage (i.e. allocated oldSpace + allocated newSpace)
|
|
47 |
(does not include the second semispace and other help-areas,
|
|
48 |
such as the remembered set etc.)
|
|
49 |
|
|
50 |
all current oldSpace in use + newSpace in use
|
|
51 |
|
|
52 |
new current newSpace in use
|
|
53 |
|
|
54 |
frl free space in (fragmented) free lists
|
|
55 |
fre compact free area above the used oldSpace
|
|
56 |
|
|
57 |
old current oldSpace in use
|
|
58 |
|
|
59 |
cod dynamic compiled code space size (just in time compiler)
|
|
60 |
|
|
61 |
max, extreme values of 'tot' since the monitor started
|
|
62 |
min (can be reset by typing 'r' in the view)
|
|
63 |
|
|
64 |
t tenure threshold (1 .. 30)
|
|
65 |
|
|
66 |
I incremental GC state (2 = idle)
|
|
67 |
|
|
68 |
weak number of weak objects
|
|
69 |
|
|
70 |
rem size of rememberedSet
|
|
71 |
|
|
72 |
minsc: percent of newspace remaining after scavenge (worst case)
|
|
73 |
(i.e. the minimum %% of scavenged objects)
|
|
74 |
|
|
75 |
count number of scavenges since system started
|
|
76 |
|
|
77 |
% percentage of live objects in newSpace after last scavenge
|
|
78 |
(i.e. this is the garbage vs. living objects ratio of
|
|
79 |
newSpace objects after the last scavenge)
|
|
80 |
|
|
81 |
the graphic shows:
|
|
82 |
orange newSpace used
|
|
83 |
green free memory in freeLists
|
|
84 |
white oldSpace used
|
|
85 |
|
|
86 |
|
|
87 |
the popupMenu offers GC functions; keyboard options are:
|
|
88 |
'f' -> faster; 's' -> slower; 'r' -> reset min/max
|
|
89 |
|
|
90 |
[author:]
|
|
91 |
Claus Gittinger
|
|
92 |
|
|
93 |
[start with:]
|
|
94 |
MemoryMonitorView open
|
|
95 |
|
|
96 |
[see also:]
|
|
97 |
ObjectMemory
|
|
98 |
MemoryUsageMonitor ProcessMonitor
|
|
99 |
"
|
|
100 |
! !
|
|
101 |
|
|
102 |
!MemoryMonitorView class methodsFor:'defaults'!
|
|
103 |
|
|
104 |
defaultExtent
|
|
105 |
^ (200 @ 320)
|
|
106 |
|
|
107 |
"Modified: 24.8.1996 / 12:04:21 / cg"
|
|
108 |
!
|
|
109 |
|
|
110 |
defaultIcon
|
|
111 |
|i|
|
|
112 |
|
|
113 |
i := Image fromFile:'MemMonitor.xbm'.
|
|
114 |
i notNil ifTrue:[^ i].
|
|
115 |
^ StandardSystemView defaultIcon
|
|
116 |
!
|
|
117 |
|
|
118 |
defaultLabel
|
|
119 |
^ 'Memory Monitor'
|
|
120 |
! !
|
|
121 |
|
|
122 |
!MemoryMonitorView class methodsFor:'startup'!
|
|
123 |
|
|
124 |
isVisualStartable
|
|
125 |
"returns whether this application class can be started via #open
|
|
126 |
(i.e. via a double click on the class in the browser)"
|
|
127 |
|
|
128 |
^ true
|
|
129 |
|
|
130 |
"Created: / 15.7.1998 / 12:59:58 / cg"
|
|
131 |
! !
|
|
132 |
|
|
133 |
!MemoryMonitorView methodsFor:'drawing'!
|
|
134 |
|
|
135 |
displayKilo:aNumber name:nm y:y
|
|
136 |
|s|
|
|
137 |
|
|
138 |
aNumber >= (1024*1024*99) ifTrue:[
|
|
139 |
s := nm , ((aNumber // (1024*1024)) printStringLeftPaddedTo:5) , 'M '.
|
|
140 |
] ifFalse:[
|
|
141 |
s := nm , ((aNumber // 1024) printStringLeftPaddedTo:5) , 'k '.
|
|
142 |
].
|
|
143 |
self displayOpaqueString:s x:0 y:y.
|
|
144 |
|
|
145 |
"Modified: / 23.9.1998 / 13:19:04 / cg"
|
|
146 |
!
|
|
147 |
|
|
148 |
redraw
|
|
149 |
"redraw all"
|
|
150 |
|
|
151 |
self clear.
|
|
152 |
self redrawX:0 y:0 width:width height:height
|
|
153 |
!
|
|
154 |
|
|
155 |
redrawX:x y:y width:w height:h
|
|
156 |
"redraw data"
|
|
157 |
|
|
158 |
|total oldSpaceUsed newSpaceUsed freeMem lx startIdx endIdx
|
|
159 |
right|
|
|
160 |
|
|
161 |
shown ifFalse:[^ self].
|
|
162 |
|
|
163 |
right := x + w - 1.
|
|
164 |
right >= org ifTrue:[
|
|
165 |
lx := x.
|
|
166 |
lx < org ifTrue:[
|
|
167 |
lx := org
|
|
168 |
].
|
|
169 |
|
|
170 |
total := ObjectMemory symSpaceSize
|
|
171 |
+ ObjectMemory oldSpaceSize
|
|
172 |
+ ObjectMemory newSpaceSize.
|
|
173 |
|
|
174 |
startIdx := (lx-org+1).
|
|
175 |
startIdx < 1 ifTrue:[
|
|
176 |
startIdx := 1
|
|
177 |
].
|
|
178 |
|
|
179 |
endIdx := right-org+1.
|
|
180 |
endIdx >= updateIndex ifTrue:[
|
|
181 |
endIdx := updateIndex-1.
|
|
182 |
].
|
|
183 |
dX := 0.
|
|
184 |
|
|
185 |
startIdx to:endIdx do:[:i |
|
|
186 |
newSpaceUsed := newData at:i.
|
|
187 |
newSpaceUsed notNil ifTrue:[
|
|
188 |
oldSpaceUsed := oldData at:i.
|
|
189 |
freeMem := freeData at:i.
|
|
190 |
|
|
191 |
self updateLineX:lx - dX
|
|
192 |
total:total
|
|
193 |
old:oldSpaceUsed
|
|
194 |
new:newSpaceUsed
|
|
195 |
free:freeMem.
|
|
196 |
].
|
|
197 |
lx := lx + 1
|
|
198 |
]
|
|
199 |
].
|
|
200 |
|
|
201 |
x < org ifTrue:[
|
|
202 |
"/ force redraw.
|
|
203 |
|
|
204 |
prevFree := prevFree2 := prevOld := prevTotal := nil.
|
|
205 |
prevMemUsed := prevCodeUsed := prevNumWeak := prevNumRem := nil.
|
|
206 |
prevNumLifoRem := prevTenureAge := prevIGCPhase := nil.
|
|
207 |
prevLastScavengeReclamation := prevMinScavengeReclamation := nil.
|
|
208 |
prevScavengeCount := nil.
|
|
209 |
|
|
210 |
self updateNumbers.
|
|
211 |
]
|
|
212 |
|
|
213 |
"Modified: / 14.7.1998 / 23:33:47 / cg"
|
|
214 |
!
|
|
215 |
|
|
216 |
updateDisplay
|
|
217 |
"update picture; trigger next update"
|
|
218 |
|
|
219 |
|total oldSpaceUsed newSpaceUsed freeMem oldSpaceSize
|
|
220 |
gWidth shift scaleChange margin|
|
|
221 |
|
|
222 |
shown ifTrue:[
|
|
223 |
drawLock wouldBlock ifFalse:[
|
|
224 |
drawLock critical:[
|
|
225 |
oldSpaceUsed := ObjectMemory oldSpaceUsed + ObjectMemory symSpaceUsed.
|
|
226 |
newSpaceUsed := ObjectMemory newSpaceUsed.
|
|
227 |
freeMem := ObjectMemory freeListSpace + (ObjectMemory oldSpaceSize - ObjectMemory oldSpaceUsed).
|
|
228 |
oldSpaceSize := ObjectMemory oldSpaceSize + ObjectMemory symSpaceSize.
|
|
229 |
total := oldSpaceSize + ObjectMemory newSpaceSize.
|
|
230 |
|
|
231 |
scaleChange := false.
|
|
232 |
|
|
233 |
((total - freeMem) < minTotal) ifTrue:[
|
|
234 |
minTotal := total - freeMem.
|
|
235 |
scaleChange := true
|
|
236 |
].
|
|
237 |
(total > maxTotal) ifTrue:[
|
|
238 |
maxTotal := total.
|
|
239 |
scaleChange := true
|
|
240 |
].
|
|
241 |
|
|
242 |
oldData at:updateIndex put:oldSpaceSize. "/ oldSpaceUsed.
|
|
243 |
newData at:updateIndex put:newSpaceUsed.
|
|
244 |
freeData at:updateIndex put:freeMem.
|
|
245 |
updateIndex := updateIndex + 1.
|
|
246 |
|
|
247 |
scaleChange ifTrue:[
|
|
248 |
scale := height asFloat / (maxTotal + 100000).
|
|
249 |
self redraw
|
|
250 |
].
|
|
251 |
|
|
252 |
gWidth := width - org.
|
|
253 |
margin := 1.
|
|
254 |
|
|
255 |
((updateIndex-1) >= (gWidth - margin)) ifTrue:[
|
|
256 |
"on slow displays, use:"
|
|
257 |
"/ shift := gWidth // 4.
|
|
258 |
|
|
259 |
"for smooth display, use:"
|
|
260 |
shift := 1.
|
|
261 |
|
|
262 |
oldData replaceFrom:1 with:oldData startingAt:shift+1.
|
|
263 |
newData replaceFrom:1 with:newData startingAt:shift+1.
|
|
264 |
freeData replaceFrom:1 with:freeData startingAt:shift+1.
|
|
265 |
|
|
266 |
updateIndex := updateIndex - shift.
|
|
267 |
dX := dX + shift.
|
|
268 |
|
|
269 |
"/ before copying, handle any outstanding exposes ...
|
|
270 |
self repairDamage.
|
|
271 |
"/ self catchExpose.
|
|
272 |
self copyFrom:self
|
|
273 |
x:(org + shift) y:0
|
|
274 |
toX:org y:0
|
|
275 |
width:(gWidth - shift - margin)
|
|
276 |
height:height
|
|
277 |
async:false.
|
|
278 |
|
|
279 |
self clearRectangleX:(width - margin - shift) y:0
|
|
280 |
width:shift height:height.
|
|
281 |
|
|
282 |
"/ self waitForExpose.
|
|
283 |
].
|
|
284 |
|
|
285 |
self updateLineX:(updateIndex - 1 + org - 1)
|
|
286 |
total:total
|
|
287 |
old:oldSpaceSize "/ oldSpaceUsed
|
|
288 |
new:newSpaceUsed
|
|
289 |
free:freeMem.
|
|
290 |
|
|
291 |
self updateNumbers.
|
|
292 |
self flush.
|
|
293 |
].
|
|
294 |
].
|
|
295 |
].
|
|
296 |
|
|
297 |
updateBlock notNil ifTrue:[
|
|
298 |
Processor addTimedBlock:updateBlock afterSeconds:updateInterval
|
|
299 |
].
|
|
300 |
|
|
301 |
"Modified: / 5.8.1998 / 13:13:18 / cg"
|
|
302 |
!
|
|
303 |
|
|
304 |
updateLineX:x total:total old:oldSpaceSize new:newSpaceUsed free:freeMem
|
|
305 |
|hNew hOld hFree y1 y2 y3|
|
|
306 |
|
|
307 |
hNew := (newSpaceUsed * scale) asInteger.
|
|
308 |
hOld := (oldSpaceSize * scale) // 2.
|
|
309 |
hFree := (freeMem * scale) // 2.
|
|
310 |
|
|
311 |
y1 := height - 1.
|
|
312 |
|
|
313 |
y2 := y1 - hOld.
|
|
314 |
self paint:oldColor.
|
|
315 |
self displayLineFromX:x y:y1 toX:x y:y2.
|
|
316 |
|
|
317 |
y3 := y1 - hFree.
|
|
318 |
self paint:freeColor.
|
|
319 |
self displayLineFromX:x y:y1 toX:x y:y3.
|
|
320 |
|
|
321 |
y1 := y2 - hNew.
|
|
322 |
y1 ~= y2 ifTrue:[
|
|
323 |
self paint:newColor.
|
|
324 |
self displayLineFromX:x y:y1 toX:x y:y2.
|
|
325 |
]
|
|
326 |
|
|
327 |
"Modified: / 29.1.1999 / 20:45:07 / stefan"
|
|
328 |
!
|
|
329 |
|
|
330 |
updateNumbers
|
|
331 |
"redraw numbers.
|
|
332 |
The values shown are:
|
|
333 |
max: maximum memory used since monitor started
|
|
334 |
min: minimum memory used since monitor started
|
|
335 |
tot: total memory used (overall oldSpace + overall newSpace)
|
|
336 |
all: current memory in use (oldSpace + newSpace)
|
|
337 |
new: current newSpace in use
|
|
338 |
fre: current size of freelist in oldSpace
|
|
339 |
old: current oldSpace in use
|
|
340 |
code: current just-in-time compiled code cache size
|
|
341 |
t: current tenure age
|
|
342 |
I: IGC state
|
|
343 |
weak: number of weak arrays in the system
|
|
344 |
rem remembered set size
|
|
345 |
lrem lifo remembered set size
|
|
346 |
minsc: percent of newspace remaining after scavenge (worst case)
|
|
347 |
irq: max. interrupt delay
|
|
348 |
count of scavenges / last scavenge survivor rate
|
|
349 |
|
|
350 |
"
|
|
351 |
|
|
352 |
|oldSpaceSize newSpaceSize memUsed oldMemUsed newMemUsed freeMem free2
|
|
353 |
codeUsed numWeak numRem numLifoRem tenureAge igcPhase
|
|
354 |
minScavengeReclamation lastScavengeReclamation scavengeCount
|
|
355 |
y half s fontHeight fontDescent total n|
|
|
356 |
|
|
357 |
oldMemUsed := ObjectMemory oldSpaceUsed + ObjectMemory symSpaceUsed.
|
|
358 |
newMemUsed := ObjectMemory newSpaceUsed.
|
|
359 |
freeMem := ObjectMemory freeListSpace.
|
|
360 |
oldSpaceSize := ObjectMemory oldSpaceSize + ObjectMemory symSpaceSize.
|
|
361 |
newSpaceSize := ObjectMemory newSpaceSize.
|
|
362 |
|
|
363 |
memUsed := oldMemUsed + newMemUsed "- freeMem".
|
|
364 |
total := oldSpaceSize + newSpaceSize.
|
|
365 |
free2 := ObjectMemory freeSpace.
|
|
366 |
|
|
367 |
self paint:White on:Black.
|
|
368 |
|
|
369 |
fontDescent := font descent.
|
|
370 |
fontHeight := font height + fontDescent.
|
|
371 |
half := height // 2 + fontDescent.
|
|
372 |
|
|
373 |
y := half - (fontHeight * 5).
|
|
374 |
|
|
375 |
total ~~ prevTotal ifTrue:[
|
|
376 |
((total - freeMem) < minTotal) ifTrue:[
|
|
377 |
minTotal := total - freeMem.
|
|
378 |
].
|
|
379 |
(total > maxTotal) ifTrue:[
|
|
380 |
maxTotal := total.
|
|
381 |
].
|
|
382 |
|
|
383 |
self displayKilo:maxTotal name:'max ' y:font ascent.
|
|
384 |
self displayKilo:minTotal name:'min ' y:(height - font descent).
|
|
385 |
self displayKilo:total name:'tot ' y:y.
|
|
386 |
|
|
387 |
prevTotal := total.
|
|
388 |
].
|
|
389 |
|
|
390 |
y := y + fontHeight.
|
|
391 |
memUsed ~~ prevMemUsed ifTrue:[
|
|
392 |
self displayKilo:memUsed name:'all ' y:y.
|
|
393 |
prevMemUsed := memUsed.
|
|
394 |
].
|
|
395 |
|
|
396 |
y := y + fontHeight.
|
|
397 |
self paint:newColor.
|
|
398 |
self displayKilo:newMemUsed name:'new ' y:y.
|
|
399 |
|
|
400 |
y := y + fontHeight.
|
|
401 |
freeMem ~~ prevFree ifTrue:[
|
|
402 |
self paint:freeColor.
|
|
403 |
self displayKilo:freeMem name:'frl ' y:y.
|
|
404 |
prevFree := freeMem.
|
|
405 |
].
|
|
406 |
|
|
407 |
y := y + fontHeight.
|
|
408 |
free2 ~~ prevFree2 ifTrue:[
|
|
409 |
self paint:freeColor.
|
|
410 |
self displayKilo:free2 name:'fre ' y:y.
|
|
411 |
prevFree2 := free2.
|
|
412 |
].
|
|
413 |
|
|
414 |
y := y + fontHeight.
|
|
415 |
(oldMemUsed - freeMem) ~~ prevOld ifTrue:[
|
|
416 |
self paint:oldColor.
|
|
417 |
self displayKilo:(oldMemUsed - freeMem) name:'old ' y:y.
|
|
418 |
prevOld := (oldMemUsed - freeMem).
|
|
419 |
].
|
|
420 |
|
|
421 |
y := y + fontHeight.
|
|
422 |
ObjectMemory supportsJustInTimeCompilation ifTrue:[
|
|
423 |
codeUsed := ObjectMemory compiledCodeSpaceUsed.
|
|
424 |
prevCodeUsed ~~ codeUsed ifTrue:[
|
|
425 |
self paint:oldColor.
|
|
426 |
codeUsed > 9999 ifTrue:[
|
|
427 |
s := 'code ' , ((codeUsed // 1024) printStringLeftPaddedTo:4) , 'k'.
|
|
428 |
] ifFalse:[
|
|
429 |
s := 'code ' , (codeUsed printStringLeftPaddedTo:4) , ' '.
|
|
430 |
].
|
|
431 |
self displayOpaqueString:s x:0 y:y.
|
|
432 |
prevCodeUsed := codeUsed.
|
|
433 |
]
|
|
434 |
].
|
|
435 |
|
|
436 |
"
|
|
437 |
the following is internal - normally only interesting when debugging the VM
|
|
438 |
"
|
|
439 |
y := y + fontHeight.
|
|
440 |
tenureAge := ObjectMemory tenureAge.
|
|
441 |
igcPhase := ObjectMemory incrementalGCPhase.
|
|
442 |
(prevTenureAge ~~ tenureAge
|
|
443 |
or:[prevIGCPhase ~~ igcPhase]) ifTrue:[
|
|
444 |
self paint:oldColor.
|
|
445 |
s := 't:' , (tenureAge printStringLeftPaddedTo:2) , ' '.
|
|
446 |
s := s , ' I:' , (igcPhase printStringLeftPaddedTo:2) , ' '.
|
|
447 |
self displayOpaqueString:s x:0 y:y.
|
|
448 |
prevTenureAge := tenureAge.
|
|
449 |
prevIGCPhase := igcPhase.
|
|
450 |
].
|
|
451 |
|
|
452 |
y := y + fontHeight.
|
|
453 |
numWeak := ObjectMemory numberOfWeakObjects.
|
|
454 |
prevNumWeak ~~ numWeak ifTrue:[
|
|
455 |
self paint:oldColor.
|
|
456 |
s := 'weak: ' , (numWeak printStringLeftPaddedTo:4).
|
|
457 |
self displayOpaqueString:s x:0 y:y.
|
|
458 |
prevNumWeak := numWeak.
|
|
459 |
].
|
|
460 |
|
|
461 |
y := y + fontHeight.
|
|
462 |
numRem := ObjectMemory rememberedSetSize.
|
|
463 |
prevNumRem ~~ numRem ifTrue:[
|
|
464 |
self paint:oldColor.
|
|
465 |
s := 'rem: ' , (numRem printStringLeftPaddedTo:5).
|
|
466 |
self displayOpaqueString:s x:0 y:y.
|
|
467 |
prevNumRem := numRem.
|
|
468 |
].
|
|
469 |
|
|
470 |
y := y + fontHeight.
|
|
471 |
numLifoRem := ObjectMemory lifoRememberedSetSize.
|
|
472 |
prevNumLifoRem ~~ numLifoRem ifTrue:[
|
|
473 |
self paint:oldColor.
|
|
474 |
s := 'lrem: ' , (numLifoRem printStringLeftPaddedTo:4 ifLarger:['****']).
|
|
475 |
self displayOpaqueString:s x:0 y:y.
|
|
476 |
prevNumLifoRem := numLifoRem.
|
|
477 |
].
|
|
478 |
|
|
479 |
"/ does no longer make sense to show ....
|
|
480 |
"/ y := y + fontHeight.
|
|
481 |
"/ ObjectMemory runsSingleOldSpace ifTrue:[
|
|
482 |
"/ self displayOpaqueString:'single' x:0 y:(half + (fontHeight*4)).
|
|
483 |
"/ ].
|
|
484 |
|
|
485 |
y := y + fontHeight.
|
|
486 |
minScavengeReclamation := ObjectMemory minScavengeReclamation * 100 // ObjectMemory newSpaceSize.
|
|
487 |
prevMinScavengeReclamation ~~ minScavengeReclamation ifTrue:[
|
|
488 |
minScavengeReclamation := 100 - minScavengeReclamation asInteger.
|
|
489 |
s := 'minSc ', (minScavengeReclamation printStringLeftPaddedTo:3) , '%'.
|
|
490 |
self paint:oldColor.
|
|
491 |
self displayOpaqueString:s x:0 y:y.
|
|
492 |
prevMinScavengeReclamation := minScavengeReclamation.
|
|
493 |
].
|
|
494 |
|
|
495 |
y := y + fontHeight.
|
|
496 |
n := ObjectMemory maxInterruptLatency.
|
|
497 |
n notNil ifTrue:[
|
|
498 |
s := 'irq ', (n printStringLeftPaddedTo:3) , ' ms'.
|
|
499 |
] ifFalse:[
|
|
500 |
s := ''
|
|
501 |
].
|
|
502 |
self displayOpaqueString:s x:0 y:y.
|
|
503 |
|
|
504 |
y := y + fontHeight.
|
|
505 |
scavengeCount := ObjectMemory scavengeCount.
|
|
506 |
lastScavengeReclamation := ObjectMemory lastScavengeReclamation * 100 // ObjectMemory newSpaceSize.
|
|
507 |
(prevScavengeCount ~~ scavengeCount
|
|
508 |
or:[prevLastScavengeReclamation ~~ lastScavengeReclamation]) ifTrue:[
|
|
509 |
lastScavengeReclamation := 100 - lastScavengeReclamation asInteger.
|
|
510 |
s := (scavengeCount printStringLeftPaddedTo:6)
|
|
511 |
, (lastScavengeReclamation printStringLeftPaddedTo:3) , '%'.
|
|
512 |
self displayOpaqueString:s x:0 y:y.
|
|
513 |
prevLastScavengeReclamation := lastScavengeReclamation.
|
|
514 |
prevScavengeCount := scavengeCount.
|
|
515 |
].
|
|
516 |
|
|
517 |
"Created: / 7.11.1995 / 14:48:16 / cg"
|
|
518 |
"Modified: / 14.7.1998 / 23:35:53 / cg"
|
|
519 |
! !
|
|
520 |
|
|
521 |
!MemoryMonitorView methodsFor:'events'!
|
|
522 |
|
|
523 |
keyPress:key x:x y:y
|
|
524 |
key == $f ifTrue:[
|
|
525 |
"faster"
|
|
526 |
updateInterval := updateInterval / 2
|
|
527 |
].
|
|
528 |
key == $s ifTrue:[
|
|
529 |
"slower"
|
|
530 |
updateInterval := updateInterval * 2
|
|
531 |
].
|
|
532 |
key == $r ifTrue:[
|
|
533 |
"reset max"
|
|
534 |
maxTotal := prevTotal.
|
|
535 |
scale := height asFloat / (maxTotal + 100000).
|
|
536 |
self resetStatisticValues.
|
|
537 |
self redraw.
|
|
538 |
]
|
|
539 |
|
|
540 |
"Modified: 7.11.1995 / 17:45:13 / cg"
|
|
541 |
!
|
|
542 |
|
|
543 |
sizeChanged:how
|
|
544 |
|nn no nf delta oldSize newSize|
|
|
545 |
|
|
546 |
super sizeChanged:how.
|
|
547 |
|
|
548 |
(width == 0 or:[height == 0]) ifTrue:[
|
|
549 |
^self
|
|
550 |
].
|
|
551 |
|
|
552 |
oldSize := oldData size.
|
|
553 |
newSize := width-org+1.
|
|
554 |
|
|
555 |
(newSize ~~ oldSize) ifTrue:[
|
|
556 |
nn := Array new:newSize.
|
|
557 |
no := Array new:newSize.
|
|
558 |
nf := Array new:newSize.
|
|
559 |
|
|
560 |
(newSize > oldSize) ifTrue:[
|
|
561 |
nn replaceFrom:1 to:oldSize with:newData.
|
|
562 |
no replaceFrom:1 to:oldSize with:oldData.
|
|
563 |
nf replaceFrom:1 to:oldSize with:freeData
|
|
564 |
] ifFalse:[
|
|
565 |
delta := (oldSize - newSize).
|
|
566 |
nn replaceFrom:1 with:newData startingAt:delta+1.
|
|
567 |
no replaceFrom:1 with:oldData startingAt:delta+1.
|
|
568 |
nf replaceFrom:1 with:freeData startingAt:delta+1.
|
|
569 |
updateIndex > newSize ifTrue:[
|
|
570 |
updateIndex := updateIndex - delta.
|
|
571 |
]
|
|
572 |
].
|
|
573 |
newData := nn.
|
|
574 |
oldData := no.
|
|
575 |
freeData := nf.
|
|
576 |
|
|
577 |
scale := height asFloat / (maxTotal + 100000).
|
|
578 |
].
|
|
579 |
self clear.
|
|
580 |
self redraw.
|
|
581 |
|
|
582 |
"Modified: / 7.9.1998 / 21:41:13 / cg"
|
|
583 |
! !
|
|
584 |
|
|
585 |
!MemoryMonitorView methodsFor:'initialize / release'!
|
|
586 |
|
|
587 |
destroy
|
|
588 |
updateBlock notNil ifTrue:[
|
|
589 |
Processor removeTimedBlock:updateBlock.
|
|
590 |
] ifFalse:[
|
|
591 |
myProcess terminate.
|
|
592 |
myProcess := nil
|
|
593 |
].
|
|
594 |
oldData := newData := freeData := nil.
|
|
595 |
super destroy
|
|
596 |
!
|
|
597 |
|
|
598 |
initialize
|
|
599 |
super initialize.
|
|
600 |
|
|
601 |
drawLock := Semaphore forMutualExclusion name:'drawLock'.
|
|
602 |
|
|
603 |
updateInterval := 0.5.
|
|
604 |
ProcessorScheduler isPureEventDriven ifTrue:[
|
|
605 |
updateBlock := [self updateDisplay].
|
|
606 |
].
|
|
607 |
oldData := Array new:1000.
|
|
608 |
newData := Array new:1000.
|
|
609 |
freeData := Array new:1000.
|
|
610 |
|
|
611 |
updateIndex := 1.
|
|
612 |
|
|
613 |
self font:((Font family:'courier' face:'medium' style:'roman' size:10) onDevice:device).
|
|
614 |
org := font widthOf:'max 99999k '.
|
|
615 |
level := 0.
|
|
616 |
|
|
617 |
maxTotal := minTotal := ObjectMemory oldSpaceSize
|
|
618 |
+ ObjectMemory symSpaceSize
|
|
619 |
+ ObjectMemory newSpaceSize.
|
|
620 |
|
|
621 |
viewBackground := Black.
|
|
622 |
|
|
623 |
device hasColors ifTrue:[
|
|
624 |
newColor := Color orange. "/ yellow.
|
|
625 |
freeColor := Color green.
|
|
626 |
oldColor := Color white.
|
|
627 |
] ifFalse:[
|
|
628 |
newColor := Color grey:67.
|
|
629 |
freeColor := Color grey:33.
|
|
630 |
oldColor := Color white.
|
|
631 |
].
|
|
632 |
|
|
633 |
self model:self.
|
|
634 |
self menu:#memoryMenu
|
|
635 |
|
|
636 |
"
|
|
637 |
MemoryMonitor open
|
|
638 |
"
|
|
639 |
|
|
640 |
"Modified: / 27.7.1998 / 19:57:07 / cg"
|
|
641 |
!
|
|
642 |
|
|
643 |
memoryMenu
|
|
644 |
<resource: #programMenu>
|
|
645 |
|
|
646 |
|m items moreItems specialMenu|
|
|
647 |
|
|
648 |
items := #(
|
|
649 |
('background collect now' backgroundCollect)
|
|
650 |
('hi prio incremental collect' incrementalCollect)
|
|
651 |
('-')
|
|
652 |
('scavenge' scavenge)
|
|
653 |
('tenure' tenure)
|
|
654 |
('-')
|
|
655 |
('cleanup memory' cleanupMemory)
|
|
656 |
('flush method history' cleanupMethodHistory)
|
|
657 |
('unload autoloaded classes' unloadAllAutoloadedClasses)
|
|
658 |
('-')
|
|
659 |
('compress sources' compressSources)
|
|
660 |
).
|
|
661 |
|
|
662 |
ObjectMemory backgroundCollectorRunning ifFalse:[
|
|
663 |
moreItems := #(
|
|
664 |
('start background collector' restartBackgroundCollector )
|
|
665 |
)
|
|
666 |
] ifTrue:[
|
|
667 |
(ObjectMemory backgroundCollectProcess priorityRange notNil)
|
|
668 |
ifTrue:[
|
|
669 |
moreItems := #(
|
|
670 |
('stop background collector' stopBackgroundCollector )
|
|
671 |
('background collect with fix priority' backgroundCollectWithFixPrio )
|
|
672 |
)
|
|
673 |
] ifFalse:[
|
|
674 |
moreItems := #(
|
|
675 |
('stop background collector' stopBackgroundCollector )
|
|
676 |
('background collect with dynamic priority' backgroundCollectWithDynamicPrio )
|
|
677 |
)
|
|
678 |
].
|
|
679 |
].
|
|
680 |
items := moreItems , items.
|
|
681 |
|
|
682 |
specialMenu := PopUpMenu
|
|
683 |
itemList:items
|
|
684 |
resources:resources.
|
|
685 |
|
|
686 |
device ctrlDown ifTrue:[
|
|
687 |
^ specialMenu
|
|
688 |
].
|
|
689 |
|
|
690 |
items := #(
|
|
691 |
('collect garbage' collectGarbage )
|
|
692 |
('collect garbage & symbols' collectGarbageAndSymbols )
|
|
693 |
('collect garbage & compress' collectGarbageAndCompress )
|
|
694 |
('-')
|
|
695 |
('reset statistic values' resetStatisticValues )
|
|
696 |
('-')
|
|
697 |
('others' otherMenu Ctrl)
|
|
698 |
).
|
|
699 |
|
|
700 |
m := PopUpMenu itemList:items resources:resources.
|
|
701 |
m subMenuAt:#otherMenu put:specialMenu.
|
|
702 |
|
|
703 |
^ m
|
|
704 |
|
|
705 |
"Modified: / 5.8.1998 / 15:35:14 / cg"
|
|
706 |
!
|
|
707 |
|
|
708 |
realize
|
|
709 |
super realize.
|
|
710 |
updateBlock notNil ifTrue:[
|
|
711 |
Processor addTimedBlock:updateBlock afterSeconds:updateInterval.
|
|
712 |
] ifFalse:[
|
|
713 |
myProcess := [
|
|
714 |
self updateProcess
|
|
715 |
] forkAt:6.
|
|
716 |
myProcess name:'monitor [' ,
|
|
717 |
Processor activeProcess id printString ,
|
|
718 |
'] update'
|
|
719 |
].
|
|
720 |
|
|
721 |
newColor := newColor on:device.
|
|
722 |
freeColor := freeColor on:device.
|
|
723 |
oldColor := oldColor on:device.
|
|
724 |
|
|
725 |
"Modified: / 23.9.1998 / 12:41:10 / cg"
|
|
726 |
!
|
|
727 |
|
|
728 |
reinitStyle
|
|
729 |
"ignore style changes"
|
|
730 |
|
|
731 |
"Created: / 15.9.1998 / 15:22:46 / cg"
|
|
732 |
! !
|
|
733 |
|
|
734 |
!MemoryMonitorView methodsFor:'menu functions'!
|
|
735 |
|
|
736 |
backgroundCollect
|
|
737 |
"start a background (non disturbing) incremental GC.
|
|
738 |
Since the GC is performed at a low priority, it may not make progress if higher
|
|
739 |
prio processes are running"
|
|
740 |
|
|
741 |
[
|
|
742 |
ObjectMemory incrementalGC
|
|
743 |
] forkAt:5
|
|
744 |
!
|
|
745 |
|
|
746 |
backgroundCollectWithDynamicPrio
|
|
747 |
"setup the background collector to run at dynamic priority.
|
|
748 |
This is a new experimental feature."
|
|
749 |
|
|
750 |
Processor isTimeSlicing ifFalse:[
|
|
751 |
Processor startTimeSlicing.
|
|
752 |
Processor supportDynamicPriorities:true
|
|
753 |
].
|
|
754 |
|
|
755 |
ObjectMemory backgroundCollectProcess priorityRange:(5 to:9).
|
|
756 |
ObjectMemory backgroundFinalizationProcess priorityRange:(5 to:9).
|
|
757 |
|
|
758 |
"Modified: / 4.8.1998 / 02:16:02 / cg"
|
|
759 |
!
|
|
760 |
|
|
761 |
backgroundCollectWithFixPrio
|
|
762 |
"setup the background collector to run at a fix priority.
|
|
763 |
This is the default."
|
|
764 |
|
|
765 |
ObjectMemory backgroundCollectProcess priorityRange:nil.
|
|
766 |
ObjectMemory backgroundFinalizationProcess priorityRange:nil.
|
|
767 |
|
|
768 |
"Modified: / 4.8.1998 / 02:00:31 / cg"
|
|
769 |
!
|
|
770 |
|
|
771 |
cleanupMemory
|
|
772 |
"let all classes release unneeded, cached
|
|
773 |
data ..."
|
|
774 |
|
|
775 |
ObjectMemory performLowSpaceCleanup.
|
|
776 |
|
|
777 |
"
|
|
778 |
then, perform a GC (incl. symbol reclamation)
|
|
779 |
"
|
|
780 |
ObjectMemory reclaimSymbols.
|
|
781 |
"
|
|
782 |
finally, compress
|
|
783 |
"
|
|
784 |
ObjectMemory tenure.
|
|
785 |
ObjectMemory verboseGarbageCollect.
|
|
786 |
|
|
787 |
"Modified: 26.6.1997 / 17:12:53 / cg"
|
|
788 |
!
|
|
789 |
|
|
790 |
cleanupMethodHistory
|
|
791 |
"release the oldMethod history"
|
|
792 |
|
|
793 |
(self confirm:'This removes the previous method history,
|
|
794 |
which is kept for all changed methods in the system.
|
|
795 |
After that, the browsers cannot easily switch back to a methods
|
|
796 |
previous version.
|
|
797 |
|
|
798 |
However, this is normally not a problem, since
|
|
799 |
a methods previous code should still be accessable through
|
|
800 |
either the changes-file, the sourceCode repository or the classes original
|
|
801 |
source file.
|
|
802 |
|
|
803 |
cleanup now ?') ifTrue:[
|
|
804 |
|
|
805 |
|
|
806 |
Class flushMethodHistory.
|
|
807 |
|
|
808 |
"
|
|
809 |
then, perform a GC (incl. symbol reclamation)
|
|
810 |
"
|
|
811 |
ObjectMemory reclaimSymbols.
|
|
812 |
"
|
|
813 |
finally, compress
|
|
814 |
"
|
|
815 |
ObjectMemory verboseGarbageCollect.
|
|
816 |
]
|
|
817 |
|
|
818 |
|
|
819 |
|
|
820 |
!
|
|
821 |
|
|
822 |
collectGarbage
|
|
823 |
"perform a blocking (non compressing) garbage collect"
|
|
824 |
|
|
825 |
windowGroup withWaitCursorDo:[
|
|
826 |
ObjectMemory tenure.
|
|
827 |
ObjectMemory markAndSweep
|
|
828 |
]
|
|
829 |
|
|
830 |
"Modified: 30.7.1997 / 21:19:35 / cg"
|
|
831 |
!
|
|
832 |
|
|
833 |
collectGarbageAndCompress
|
|
834 |
"perform a blocking compressing garbage collect."
|
|
835 |
|
|
836 |
windowGroup withWaitCursorDo:[
|
|
837 |
ObjectMemory tenure.
|
|
838 |
ObjectMemory verboseGarbageCollect
|
|
839 |
]
|
|
840 |
|
|
841 |
"Modified: 30.7.1997 / 21:19:47 / cg"
|
|
842 |
!
|
|
843 |
|
|
844 |
collectGarbageAndSymbols
|
|
845 |
"perform a blocking (non compressing) garbage collect
|
|
846 |
and reclaim unreferenced symbols."
|
|
847 |
|
|
848 |
windowGroup withWaitCursorDo:[
|
|
849 |
ObjectMemory tenure.
|
|
850 |
ObjectMemory reclaimSymbols
|
|
851 |
]
|
|
852 |
|
|
853 |
"Modified: 30.7.1997 / 21:19:41 / cg"
|
|
854 |
!
|
|
855 |
|
|
856 |
compressSources
|
|
857 |
(self confirm:'This saves all in-memory source strings into a file
|
|
858 |
and makes methods reference these (file-) strings,
|
|
859 |
freeing all in-memory sources.
|
|
860 |
|
|
861 |
If that source file is ever lost or gets out of sync with
|
|
862 |
your system, those method sources are lost and the browser
|
|
863 |
will show garbage.
|
|
864 |
However, you still have a change file as backup.
|
|
865 |
|
|
866 |
(Be especially careful, if you move images around:
|
|
867 |
the source file must then be the correct one for that image)
|
|
868 |
|
|
869 |
A compress is only useful, if you added many methods
|
|
870 |
and the systems response time suffers from paging.
|
|
871 |
|
|
872 |
Compress anyway ?') ifTrue:[
|
|
873 |
windowGroup withWaitCursorDo:[
|
|
874 |
Smalltalk compressSources.
|
|
875 |
ObjectMemory markAndSweep
|
|
876 |
]
|
|
877 |
]
|
|
878 |
|
|
879 |
"Modified: 9.2.1996 / 18:17:22 / cg"
|
|
880 |
!
|
|
881 |
|
|
882 |
incrementalCollect
|
|
883 |
"start an incremental GC which does not disturb too much, but is guaranteed to
|
|
884 |
make progress.
|
|
885 |
This is done by doing the IGC at a very high priority, but giving up the CPU after
|
|
886 |
every step. Due to the long delays, this may take a while to finish.
|
|
887 |
Notice, that this is different from doing a background collect: that one
|
|
888 |
may not make any progress if higher prio processes are runnable."
|
|
889 |
|
|
890 |
|done delay|
|
|
891 |
|
|
892 |
[
|
|
893 |
done := false.
|
|
894 |
delay := Delay new.
|
|
895 |
[done] whileFalse:[
|
|
896 |
10 timesRepeat:[
|
|
897 |
done ifFalse:[done := ObjectMemory gcStep].
|
|
898 |
].
|
|
899 |
(delay delay:10) wait
|
|
900 |
]
|
|
901 |
] forkAt:Processor highestPriority
|
|
902 |
|
|
903 |
"Modified: 23.12.1995 / 17:31:55 / cg"
|
|
904 |
!
|
|
905 |
|
|
906 |
resetStatisticValues
|
|
907 |
ObjectMemory resetMaxInterruptLatency.
|
|
908 |
ObjectMemory resetMinScavengeReclamation.
|
|
909 |
|
|
910 |
"Created: 7.11.1995 / 17:44:59 / cg"
|
|
911 |
!
|
|
912 |
|
|
913 |
restartBackgroundCollector
|
|
914 |
"(re)start a background (non disturbing) incremental GC.
|
|
915 |
Since the GC is performed at a low priority, it may not make progress if higher
|
|
916 |
prio processes are running"
|
|
917 |
|
|
918 |
ObjectMemory backgroundCollectorRunning
|
|
919 |
ifFalse:[
|
|
920 |
ObjectMemory startBackgroundCollectorAt:5.
|
|
921 |
ObjectMemory startBackgroundFinalizationAt:5
|
|
922 |
]
|
|
923 |
|
|
924 |
"Created: / 21.1.1997 / 00:09:30 / cg"
|
|
925 |
"Modified: / 5.8.1998 / 14:30:17 / cg"
|
|
926 |
!
|
|
927 |
|
|
928 |
scavenge
|
|
929 |
"perform a blocking newspace garbage collect.
|
|
930 |
(this is for debugging only - the system does this automatically)"
|
|
931 |
|
|
932 |
ObjectMemory scavenge
|
|
933 |
!
|
|
934 |
|
|
935 |
stopBackgroundCollector
|
|
936 |
"stop the background (non disturbing) incremental GC.
|
|
937 |
We do not recommend this - but maybe useful for debugging and
|
|
938 |
evaluating the programs behavior in heavy-load situations
|
|
939 |
(background collector cannot keep up with the allocation rate)"
|
|
940 |
|
|
941 |
ObjectMemory stopBackgroundCollector.
|
|
942 |
ObjectMemory stopBackgroundFinalization
|
|
943 |
|
|
944 |
"Created: / 5.8.1998 / 14:29:40 / cg"
|
|
945 |
!
|
|
946 |
|
|
947 |
tenure
|
|
948 |
"empty the newSpace, by aging all new objects immediately and transfering them
|
|
949 |
into oldSpace.
|
|
950 |
(this is for debugging only - the system does this automatically)"
|
|
951 |
|
|
952 |
ObjectMemory tenure
|
|
953 |
!
|
|
954 |
|
|
955 |
unloadAllAutoloadedClasses
|
|
956 |
"unload all classes which were autoloaded and have no instances"
|
|
957 |
|
|
958 |
Autoload loadedClasses copy do:[:anAutoloadedClass |
|
|
959 |
anAutoloadedClass hasInstances ifFalse:[
|
|
960 |
anAutoloadedClass unload
|
|
961 |
]
|
|
962 |
].
|
|
963 |
|
|
964 |
"Created: 27.6.1997 / 14:21:45 / cg"
|
|
965 |
"Modified: 27.6.1997 / 14:22:47 / cg"
|
|
966 |
! !
|
|
967 |
|
|
968 |
!MemoryMonitorView methodsFor:'private'!
|
|
969 |
|
|
970 |
updateProcess
|
|
971 |
[true] whileTrue:[
|
|
972 |
Delay waitForSeconds:updateInterval.
|
|
973 |
self updateDisplay
|
|
974 |
]
|
|
975 |
|
|
976 |
"Modified: / 23.9.1998 / 12:40:31 / cg"
|
|
977 |
! !
|
|
978 |
|
|
979 |
!MemoryMonitorView class methodsFor:'documentation'!
|
|
980 |
|
|
981 |
version
|
|
982 |
^ '$Header: /cvs/stx/stx/libtool/MemoryMonitorView.st,v 1.1 1999-08-28 12:14:13 cg Exp $'
|
|
983 |
! !
|