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