author | Jan Vrany <jan.vrany@labware.com> |
Wed, 15 Sep 2021 21:39:40 +0100 | |
branch | jv |
changeset 19608 | 98f7cba0ce8c |
parent 17136 | cb908d2ba02e |
permissions | -rw-r--r-- |
45 | 1 |
" |
2 |
COPYRIGHT (c) 1992 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 |
" |
|
2651 | 12 |
"{ Package: 'stx:libtool' }" |
13 |
||
15318 | 14 |
"{ NameSpace: Smalltalk }" |
15 |
||
19 | 16 |
StandardSystemView subclass:#MemoryUsageView |
9887 | 17 |
instanceVariableNames:'rawInfo info list sortBlock titleLabel prevRawInfo |
9925 | 18 |
autoUpdateProcess autoUpdateInterval filter infoLabel' |
9929 | 19 |
classVariableNames:'LastSearchString' |
437
9526cb043cbc
list obsolete & removed classes separately
Claus Gittinger <cg@exept.de>
parents:
165
diff
changeset
|
20 |
poolDictionaries:'' |
1053 | 21 |
category:'Monitors-ST/X' |
19 | 22 |
! |
23 |
||
9887 | 24 |
Object subclass:#StatisticEntry |
25 |
instanceVariableNames:'classNameOrSymbol overallByteSize minByteSize maxByteSize |
|
26 |
averageSize instanceCount instanceAllocationRate |
|
27 |
memoryAllocationRate' |
|
28 |
classVariableNames:'' |
|
29 |
poolDictionaries:'' |
|
30 |
privateIn:MemoryUsageView |
|
31 |
! |
|
32 |
||
769 | 33 |
!MemoryUsageView class methodsFor:'documentation'! |
19 | 34 |
|
45 | 35 |
copyright |
36 |
" |
|
37 |
COPYRIGHT (c) 1992 by Claus Gittinger |
|
38 |
All Rights Reserved |
|
19 | 39 |
|
45 | 40 |
This software is furnished under a license and may be used |
41 |
only in accordance with the terms of that license and with the |
|
42 |
inclusion of the above copyright notice. This software may not |
|
43 |
be provided or otherwise made available to, or used by, any |
|
44 |
other person. No title to or ownership of the software is |
|
45 |
hereby transferred. |
|
46 |
" |
|
47 |
! |
|
19 | 48 |
|
45 | 49 |
documentation |
50 |
" |
|
51 |
this view shows an overview over the memory usage of the system. |
|
52 |
usage: |
|
9887 | 53 |
MemoryUsageView new open |
19 | 54 |
|
45 | 55 |
Since scanning all memory takes some time, this is not done |
56 |
automatically, but upon request. See the middlebuttonmenu-'update' |
|
57 |
function. |
|
9887 | 58 |
|
59 |
This is a very old application - definitely needs some pimping to look better... |
|
60 |
... any maybe a nice menu, graphical display etc. |
|
45 | 61 |
" |
19 | 62 |
! ! |
63 |
||
1823 | 64 |
!MemoryUsageView class methodsFor:'startup'! |
65 |
||
66 |
isVisualStartable |
|
67 |
^ true |
|
68 |
||
69 |
"Created: / 10.8.1998 / 16:02:59 / cg" |
|
70 |
! ! |
|
71 |
||
9887 | 72 |
!MemoryUsageView methodsFor:'auto update'! |
73 |
||
74 |
autoUpdate |
|
75 |
self pushEvent:#update |
|
76 |
||
77 |
"Created: / 05-05-2011 / 17:20:52 / cg" |
|
78 |
! |
|
79 |
||
80 |
autoUpdateInterval |
|
81 |
^ autoUpdateInterval ? 30 seconds |
|
82 |
||
83 |
"Created: / 05-05-2011 / 17:20:49 / cg" |
|
84 |
! |
|
85 |
||
86 |
autoUpdateLoop |
|
87 |
[true] whileTrue:[ |
|
88 |
self autoUpdate. |
|
89 |
Delay waitFor:self autoUpdateInterval |
|
90 |
]. |
|
91 |
||
92 |
"Created: / 05-05-2011 / 17:20:44 / cg" |
|
93 |
! |
|
94 |
||
95 |
openAutoUpdateIntervalDialog |
|
96 |
|s| |
|
97 |
||
98 |
s := Dialog request:'Update interval [smh]:' initialAnswer:self autoUpdateInterval printString. |
|
99 |
s isEmptyOrNil ifTrue:[^ self]. |
|
100 |
||
101 |
autoUpdateInterval := TimeDuration readFrom:s. |
|
102 |
||
103 |
"Created: / 05-05-2011 / 17:24:48 / cg" |
|
104 |
! |
|
105 |
||
106 |
startAutoUpdateProcess |
|
107 |
autoUpdateProcess notNil ifTrue:[ |
|
108 |
self stopAutoUpdateProcess. |
|
109 |
]. |
|
110 |
autoUpdateProcess := |
|
111 |
[ |
|
112 |
self autoUpdateLoop |
|
113 |
] fork |
|
114 |
||
115 |
"Created: / 05-05-2011 / 17:19:00 / cg" |
|
116 |
! |
|
117 |
||
118 |
stopAutoUpdateProcess |
|
119 |
|p| |
|
120 |
||
121 |
(p := autoUpdateProcess) notNil ifTrue:[ |
|
122 |
autoUpdateProcess := nil. |
|
123 |
p terminate. |
|
124 |
]. |
|
125 |
||
126 |
"Created: / 05-05-2011 / 17:19:03 / cg" |
|
127 |
! ! |
|
128 |
||
437
9526cb043cbc
list obsolete & removed classes separately
Claus Gittinger <cg@exept.de>
parents:
165
diff
changeset
|
129 |
!MemoryUsageView methodsFor:'initialization'! |
9526cb043cbc
list obsolete & removed classes separately
Claus Gittinger <cg@exept.de>
parents:
165
diff
changeset
|
130 |
|
9526cb043cbc
list obsolete & removed classes separately
Claus Gittinger <cg@exept.de>
parents:
165
diff
changeset
|
131 |
initialize |
1348 | 132 |
|helpView headLine| |
437
9526cb043cbc
list obsolete & removed classes separately
Claus Gittinger <cg@exept.de>
parents:
165
diff
changeset
|
133 |
|
9526cb043cbc
list obsolete & removed classes separately
Claus Gittinger <cg@exept.de>
parents:
165
diff
changeset
|
134 |
super initialize. |
4253 | 135 |
self label:'Memory Usage'. |
19 | 136 |
|
9887 | 137 |
headLine := ' Class' paddedTo:47 with:Character space. |
15742 | 138 |
headLine := headLine , ' # of Insts Bytes Avg sz Max sz %Mem %Accum. +Insts +Bytes'. |
437
9526cb043cbc
list obsolete & removed classes separately
Claus Gittinger <cg@exept.de>
parents:
165
diff
changeset
|
139 |
|
1348 | 140 |
titleLabel := Label in:self. |
9925 | 141 |
titleLabel origin:(0.0 @ 0.0) corner:(1.0 @ titleLabel preferredHeight). |
1348 | 142 |
titleLabel borderWidth:0. |
143 |
titleLabel label:headLine. |
|
144 |
titleLabel adjust:#left. |
|
437
9526cb043cbc
list obsolete & removed classes separately
Claus Gittinger <cg@exept.de>
parents:
165
diff
changeset
|
145 |
|
9925 | 146 |
infoLabel := Label in:self. |
147 |
infoLabel geometryLayout:(LayoutFrame |
|
148 |
leftFraction:0 offset:0 |
|
149 |
rightFraction:1.0 offset:0 |
|
150 |
topFraction:1.0 offset:infoLabel preferredHeight negated |
|
151 |
bottomFraction:1.0 offset:0). |
|
152 |
infoLabel borderWidth:0. |
|
153 |
infoLabel label:''. |
|
154 |
infoLabel adjust:#left. |
|
155 |
infoLabel level:-1. |
|
156 |
||
437
9526cb043cbc
list obsolete & removed classes separately
Claus Gittinger <cg@exept.de>
parents:
165
diff
changeset
|
157 |
helpView := ScrollableView for:SelectionInListView in:self. |
9925 | 158 |
helpView geometryLayout:(LayoutFrame |
159 |
leftFraction:0 offset:0 |
|
160 |
rightFraction:1.0 offset:0 |
|
161 |
topFraction:0 offset:titleLabel height |
|
162 |
bottomFraction:1.0 offset:infoLabel height negated). |
|
92 | 163 |
|
437
9526cb043cbc
list obsolete & removed classes separately
Claus Gittinger <cg@exept.de>
parents:
165
diff
changeset
|
164 |
list := helpView scrolledView. |
9526cb043cbc
list obsolete & removed classes separately
Claus Gittinger <cg@exept.de>
parents:
165
diff
changeset
|
165 |
|
1348 | 166 |
titleLabel origin:(list originRelativeTo:self) x @ 0.0. |
92 | 167 |
|
1273
3a8a91e6c5fa
give my listView a fixed font.
Claus Gittinger <cg@exept.de>
parents:
1053
diff
changeset
|
168 |
list font:(EditTextView defaultFont). |
1348 | 169 |
titleLabel font:(EditTextView defaultFont). |
437
9526cb043cbc
list obsolete & removed classes separately
Claus Gittinger <cg@exept.de>
parents:
165
diff
changeset
|
170 |
list menuHolder:self; menuPerformer:self; menuMessage:#usageMenu. |
92 | 171 |
|
16252 | 172 |
self extent:((list font widthOf:headLine) + ( device horizontalPixelPerMillimeter * 15) rounded) @ self height. |
9887 | 173 |
|
437
9526cb043cbc
list obsolete & removed classes separately
Claus Gittinger <cg@exept.de>
parents:
165
diff
changeset
|
174 |
" |
9526cb043cbc
list obsolete & removed classes separately
Claus Gittinger <cg@exept.de>
parents:
165
diff
changeset
|
175 |
MemoryUsageView open |
9526cb043cbc
list obsolete & removed classes separately
Claus Gittinger <cg@exept.de>
parents:
165
diff
changeset
|
176 |
" |
1273
3a8a91e6c5fa
give my listView a fixed font.
Claus Gittinger <cg@exept.de>
parents:
1053
diff
changeset
|
177 |
|
9925 | 178 |
"Modified: / 08-05-2011 / 12:45:06 / cg" |
14921
eb71540a0256
Fix in MemoryUsageView - user self device instead of diretly accessing instvar,
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
14692
diff
changeset
|
179 |
"Modified: / 26-11-2014 / 16:00:07 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
9887 | 180 |
! |
181 |
||
182 |
release |
|
183 |
self stopAutoUpdateProcess. |
|
184 |
super release. |
|
185 |
||
186 |
"Created: / 05-05-2011 / 17:26:24 / cg" |
|
437
9526cb043cbc
list obsolete & removed classes separately
Claus Gittinger <cg@exept.de>
parents:
165
diff
changeset
|
187 |
! ! |
9526cb043cbc
list obsolete & removed classes separately
Claus Gittinger <cg@exept.de>
parents:
165
diff
changeset
|
188 |
|
9887 | 189 |
!MemoryUsageView methodsFor:'menu-actions'! |
19 | 190 |
|
9387 | 191 |
browseClass |
192 |
|class| |
|
193 |
||
15778 | 194 |
(class := self selectedClass) isNil ifTrue:[ ^ self ]. |
15942 | 195 |
class browserClass openInClass:class. |
9930 | 196 |
|
197 |
"Modified: / 11-05-2011 / 14:34:38 / cg" |
|
9387 | 198 |
! |
199 |
||
1348 | 200 |
collectGarbageAndUpdate |
201 |
self withWaitCursorDo:[ |
|
1387
355fc1057e11
better print of java objects
Claus Gittinger <cg@exept.de>
parents:
1348
diff
changeset
|
202 |
ObjectMemory tenure. |
355fc1057e11
better print of java objects
Claus Gittinger <cg@exept.de>
parents:
1348
diff
changeset
|
203 |
ObjectMemory compressingGarbageCollect. |
1348 | 204 |
]. |
205 |
self update. |
|
206 |
||
207 |
"Created: 14.10.1997 / 21:36:38 / cg" |
|
208 |
"Modified: 14.10.1997 / 21:41:11 / cg" |
|
209 |
! |
|
210 |
||
1450 | 211 |
displayGlobalRefChainsToInsts |
212 |
|class| |
|
213 |
||
15778 | 214 |
(class := self selectedClassOrClassSymbol) isNil ifTrue:[ ^ self ]. |
215 |
||
216 |
self withCursor:(Cursor questionMark) do:[ |
|
217 |
|insts numInsts limit answer tooMany| |
|
1450 | 218 |
|
15778 | 219 |
" |
220 |
special kludge |
|
221 |
" |
|
222 |
class isSymbol ifTrue:[ |
|
223 |
class == #NameSpace ifFalse:[ |
|
224 |
self information:'classes are directly refered to by Smalltalk'. |
|
225 |
^ self. |
|
226 |
]. |
|
227 |
class := (Smalltalk at:class) class. |
|
228 |
insts := class allSubInstances. |
|
229 |
insts remove:class soleInstance ifAbsent:nil |
|
230 |
] ifFalse:[ |
|
231 |
tooMany := false. |
|
232 |
Error handle:[:ex | |
|
233 |
tooMany := true. |
|
234 |
] do:[ |
|
235 |
insts := class allInstances. |
|
236 |
numInsts := insts size |
|
237 |
]. |
|
238 |
tooMany ifTrue:[ |
|
239 |
numInsts := class instanceCount. |
|
240 |
]. |
|
241 |
]. |
|
242 |
numInsts > 10 ifTrue:[ |
|
243 |
answer := Dialog |
|
244 |
request:('There are ' , numInsts printString , ' instances.\Do you really want to follow them all ?\\(Give number to follow or cancel)' withCRs) |
|
245 |
initialAnswer:(numInsts min:10) printString. |
|
246 |
||
247 |
limit := Integer readFrom:answer onError:nil. |
|
248 |
limit isNil ifTrue:[^ self]. |
|
249 |
insts isNil ifTrue:[ |
|
250 |
[:exit | |
|
251 |
insts := OrderedCollection new. |
|
252 |
class allInstancesDo:[:inst | |
|
253 |
insts add:inst. |
|
254 |
insts size == limit ifTrue:[ exit value:nil ]. |
|
255 |
] |
|
256 |
] valueWithExit. |
|
1450 | 257 |
] ifFalse:[ |
15778 | 258 |
insts := (insts asArray copyTo:limit) |
259 |
] |
|
260 |
]. |
|
261 |
insts := insts asArray. |
|
262 |
ObjectMemory displayRefChainToAny:insts limitNumberOfSearchedReferences:(limit ? 1000). |
|
1450 | 263 |
] |
264 |
||
9930 | 265 |
"Created: / 03-02-1998 / 00:03:22 / cg" |
266 |
"Modified: / 11-05-2011 / 14:33:04 / cg" |
|
9936 | 267 |
"Modified: / 16-06-2011 / 16:14:40 / az" |
1450 | 268 |
! |
269 |
||
45 | 270 |
inspectInstances |
9930 | 271 |
self withCursor:(Cursor questionMark) do:[ |
272 |
self withInstancesOfSelectedClassDo:[:insts | |
|
9936 | 273 |
|answer| |
274 |
||
275 |
answer := true. |
|
2697
b4f4e431b71e
browserClass from preferences
Claus Gittinger <cg@exept.de>
parents:
2653
diff
changeset
|
276 |
insts size > 500 ifTrue:[ |
9936 | 277 |
answer := OptionBox |
278 |
request:('there are ' , insts size printString , ' instances.\\Do you really want to see them all ?' withCRs) |
|
15379 | 279 |
buttonLabels:#('No' 'Show me any 500' 'Yes' ) |
280 |
values:#( false #some true ) |
|
9936 | 281 |
default:true. |
2697
b4f4e431b71e
browserClass from preferences
Claus Gittinger <cg@exept.de>
parents:
2653
diff
changeset
|
282 |
]. |
9936 | 283 |
answer ~~ false ifTrue:[ |
284 |
answer == #some ifTrue:[ |
|
285 |
(insts copyTo:500) inspect. |
|
286 |
] ifFalse:[ |
|
287 |
insts inspect |
|
288 |
] |
|
289 |
]. |
|
2697
b4f4e431b71e
browserClass from preferences
Claus Gittinger <cg@exept.de>
parents:
2653
diff
changeset
|
290 |
] |
52 | 291 |
] |
770 | 292 |
|
9930 | 293 |
"Modified: / 11-05-2011 / 14:36:44 / cg" |
9936 | 294 |
"Modified: / 16-06-2011 / 15:57:52 / az" |
52 | 295 |
! |
296 |
||
1738 | 297 |
inspectInstancesWithSearch |
9930 | 298 |
|filterString filterBlock| |
299 |
||
300 |
list selection isNil ifTrue:[^ self]. |
|
1738 | 301 |
|
9929 | 302 |
filterString := LastSearchString ? '[:inst | "<some condition for inst>" ]'. |
1738 | 303 |
[filterBlock isNil] whileTrue:[ |
9929 | 304 |
filterString := Dialog request:'filter block:' initialAnswer:filterString. |
305 |
filterString size == 0 ifTrue:[^ self]. |
|
1738 | 306 |
|
9929 | 307 |
filterBlock := Compiler evaluate:filterString. |
1738 | 308 |
filterBlock isBlock ifFalse:[ |
309 |
self information:'bad syntax in block'. |
|
310 |
filterBlock := nil. |
|
311 |
]. |
|
312 |
]. |
|
313 |
||
9929 | 314 |
LastSearchString := filterString. |
315 |
||
9930 | 316 |
self withCursor:(Cursor questionMark) do:[ |
317 |
self withInstancesOfSelectedClassDo:[:insts | |
|
318 |
|filteredInsts| |
|
1738 | 319 |
|
9930 | 320 |
filteredInsts := insts select:filterBlock. |
321 |
filteredInsts size > 500 ifTrue:[ |
|
322 |
(self confirm:'there are ' , filteredInsts size printString , ' instances.\\Do you really want to see them all ?' withCRs) |
|
1738 | 323 |
ifFalse:[^ self] |
324 |
]. |
|
9930 | 325 |
filteredInsts inspect |
1738 | 326 |
] |
327 |
] |
|
328 |
||
9930 | 329 |
"Modified: / 11-05-2011 / 14:38:12 / cg" |
1738 | 330 |
! |
331 |
||
12030 | 332 |
inspectLargestInstances |
333 |
|tenBiggest smallestOfThe10| |
|
334 |
||
335 |
tenBiggest := SortedCollection new:20. |
|
336 |
tenBiggest sortBlock:[:a :b | a size > b size]. |
|
337 |
smallestOfThe10 := nil. |
|
338 |
||
339 |
self withCursor:(Cursor questionMark) do:[ |
|
340 |
self withInstancesOfSelectedClassDo:[:insts | |
|
341 |
insts do:[:each | |
|
342 |
smallestOfThe10 isNil ifTrue:[ |
|
343 |
smallestOfThe10 := each size. |
|
344 |
tenBiggest add:each. |
|
345 |
] ifFalse:[ |
|
346 |
each basicSize > smallestOfThe10 ifTrue:[ |
|
347 |
tenBiggest add:each. |
|
348 |
tenBiggest size > 10 ifTrue:[ |
|
349 |
tenBiggest removeLast. |
|
350 |
smallestOfThe10 := tenBiggest last size. |
|
351 |
] |
|
352 |
] |
|
353 |
]. |
|
354 |
]. |
|
355 |
tenBiggest inspect |
|
356 |
] |
|
357 |
] |
|
358 |
||
359 |
"Modified: / 11-05-2011 / 14:36:44 / cg" |
|
360 |
"Modified: / 16-06-2011 / 15:57:52 / az" |
|
361 |
! |
|
362 |
||
52 | 363 |
inspectOwners |
69 | 364 |
|class inspector| |
52 | 365 |
|
15778 | 366 |
(class := self selectedClass) isNil ifTrue:[ ^ self ]. |
9930 | 367 |
|
368 |
self withCursor:(Cursor questionMark) do:[ |
|
369 |
|owners dict| |
|
52 | 370 |
|
9930 | 371 |
owners := (ObjectMemory whoReferencesInstancesOf:class). |
372 |
owners isEmptyOrNil ifTrue:[ |
|
373 |
self information:'No owners found - next GC should remove it'. |
|
374 |
^ self |
|
375 |
]. |
|
376 |
owners := owners asOrderedCollection. |
|
377 |
owners size > 500 ifTrue:[ |
|
378 |
(self confirm:'there are ' , owners size printString , ' owners.\\Do you really want to see them all ?' withCRs) |
|
379 |
ifFalse:[^ self] |
|
380 |
]. |
|
381 |
dict := IdentityDictionary new. |
|
382 |
owners do:[:owner | |
|
383 |
|set names oClass s nMore| |
|
52 | 384 |
|
9930 | 385 |
" |
17033 | 386 |
skip weakArrays ... (they don't count) |
9930 | 387 |
" |
388 |
(owner isMemberOf:WeakArray) ifFalse:[ |
|
389 |
nMore := nil. |
|
390 |
set := Set new. |
|
391 |
owner == Smalltalk ifTrue:[ |
|
392 |
owner keysAndValuesDo:[:key :val | |
|
393 |
(val isMemberOf:class) ifTrue:[ |
|
394 |
set add:key |
|
7918 | 395 |
] |
9930 | 396 |
] |
397 |
] ifFalse:[ |
|
398 |
names := owner class allInstVarNames. |
|
399 |
oClass := owner class. |
|
400 |
1 to:oClass instSize do:[:i | |
|
401 |
((owner instVarAt:i) isMemberOf:class) ifTrue:[ |
|
402 |
set add:(names at:i). |
|
7918 | 403 |
]. |
9930 | 404 |
]. |
405 |
oClass isVariable ifTrue:[ |
|
406 |
oClass isPointers ifTrue:[ |
|
407 |
1 to:owner basicSize do:[:i | |
|
408 |
((owner basicAt:i) isMemberOf:class) ifTrue:[ |
|
409 |
nMore isNil ifTrue:[ |
|
410 |
set add:i. |
|
411 |
set size > 500 ifTrue:[ |
|
412 |
nMore := 0. |
|
7950 | 413 |
] |
9930 | 414 |
] ifFalse:[ |
415 |
nMore := nMore + 1. |
|
7918 | 416 |
] |
417 |
] |
|
418 |
] |
|
9930 | 419 |
] |
7918 | 420 |
]. |
9930 | 421 |
]. |
422 |
" |
|
423 |
put a describing string into the dictionary |
|
424 |
" |
|
16880 | 425 |
s := WriteStream on:''. |
9930 | 426 |
s nextPutAll:'references in: '. |
427 |
set do:[:name | |
|
428 |
name isString ifTrue:[ |
|
429 |
s nextPutAll:name; nextPutAll:' ' |
|
430 |
] ifFalse:[ |
|
431 |
s nextPutAll:'['; nextPutAll:name printString; nextPutAll:'] ' |
|
432 |
] |
|
433 |
]. |
|
434 |
nMore notNil ifTrue:[ |
|
435 |
s nextPutAll:'... (', nMore printString,' more)' |
|
436 |
]. |
|
437 |
dict at:owner put:(s contents). |
|
57 | 438 |
"/ dict at:owner put:set |
9930 | 439 |
] |
440 |
]. |
|
441 |
inspector := DictionaryInspectorView openOn:dict. |
|
442 |
inspector listView doubleClickAction:[:lineNr | inspector doInspectKey]. |
|
45 | 443 |
] |
770 | 444 |
|
9930 | 445 |
"Modified: / 11-05-2011 / 14:39:30 / cg" |
45 | 446 |
! |
447 |
||
2858 | 448 |
nilInstances |
449 |
|class| |
|
450 |
||
15778 | 451 |
(class := self selectedClass) isNil ifTrue:[ ^ self ]. |
2858 | 452 |
|
9930 | 453 |
self withCursor:(Cursor questionMark) do:[ |
454 |
|insts| |
|
455 |
||
456 |
insts := class allInstances. |
|
457 |
insts notEmpty ifTrue:[ |
|
458 |
(self confirm:'there are ' , insts size printString , ' instances.\\Do you really want to nil them all ?' withCRs) |
|
459 |
ifTrue:[ |
|
460 |
insts do:[:each | |
|
461 |
each becomeNil |
|
2858 | 462 |
] |
9930 | 463 |
] |
464 |
]. |
|
2858 | 465 |
] |
466 |
||
9930 | 467 |
"Modified: / 11-05-2011 / 14:39:33 / cg" |
2858 | 468 |
! |
469 |
||
13346 | 470 |
openInheritanceFilterDialog |
471 |
"only show instances which inherit from a set of classes" |
|
472 |
||
473 |
|names classes classToCheck| |
|
474 |
||
475 |
names := Dialog requestClassName:'Filter Instances by Inheritance:' initialAnswer:''. |
|
476 |
names isEmptyOrNil ifTrue:[^ self]. |
|
9924 | 477 |
|
13346 | 478 |
classes := (names asCollectionOfSubstringsSeparatedByAny:' ;,') |
479 |
collect:[:each | Smalltalk classNamed:each ] |
|
480 |
thenSelect:[:cls |cls notNil]. |
|
481 |
classes isEmpty ifTrue:[^ self]. |
|
9924 | 482 |
|
13346 | 483 |
classes size == 1 ifTrue:[ |
484 |
classToCheck := classes first. |
|
485 |
filter := [:inst :class | class includesBehavior:classToCheck ]. |
|
486 |
] ifFalse:[ |
|
487 |
classes := classes asArray. |
|
488 |
filter := [:inst :class | classes contains:[:cls | class includesBehavior:cls]]. |
|
489 |
]. |
|
9924 | 490 |
prevRawInfo := nil. |
9925 | 491 |
self update. |
492 |
||
13346 | 493 |
infoLabel label:'Filtered by Inheritance: ',names. |
494 |
||
495 |
"Created: / 08-05-2011 / 12:18:21 / cg" |
|
496 |
! |
|
497 |
||
498 |
openNamespaceFilterDialog |
|
499 |
"only show instances for classes from a number of namespaces" |
|
500 |
||
501 |
|names nameSpaces ns| |
|
502 |
||
503 |
names := Dialog requestNameSpace:'Filter Instances by Namespace:' initialAnswer:''. |
|
504 |
names isEmptyOrNil ifTrue:[^ self]. |
|
505 |
||
506 |
nameSpaces := (names asCollectionOfSubstringsSeparatedByAny:' ;,') |
|
507 |
collect:[:each | Smalltalk classNamed:each ] |
|
508 |
thenSelect:[:cls | cls notNil]. |
|
509 |
nameSpaces isEmpty ifTrue:[^ self]. |
|
510 |
||
511 |
nameSpaces size == 1 ifTrue:[ |
|
512 |
ns := nameSpaces first. |
|
513 |
filter := [:inst :class | class topNameSpace == ns ]. |
|
514 |
] ifFalse:[ |
|
515 |
nameSpaces := nameSpaces asArray. |
|
516 |
filter := [:inst :class | nameSpaces includesIdentical:(class topNameSpace) ]. |
|
517 |
]. |
|
518 |
||
519 |
prevRawInfo := nil. |
|
520 |
self update. |
|
521 |
||
522 |
infoLabel label:'Filtered by Namespace: ',names. |
|
9924 | 523 |
|
524 |
"Created: / 08-05-2011 / 12:18:21 / cg" |
|
525 |
! |
|
526 |
||
527 |
removeFilter |
|
528 |
filter := nil. |
|
529 |
prevRawInfo := nil. |
|
9925 | 530 |
self update. |
531 |
||
532 |
infoLabel label:'No Filter.'. |
|
9924 | 533 |
|
534 |
"Created: / 08-05-2011 / 12:16:43 / cg" |
|
535 |
! |
|
536 |
||
15778 | 537 |
showSizeHistogram |
538 |
|class| |
|
539 |
||
540 |
(class := self selectedClass) isNil ifTrue:[ ^ self ]. |
|
541 |
self showSizeHistogrammForClass:class |
|
542 |
! |
|
543 |
||
544 |
showSizeHistogrammForClass:class |
|
545 |
|sizeBag minSize maxSize numBags| |
|
546 |
||
547 |
numBags := 20. |
|
548 |
||
549 |
sizeBag := Bag new. |
|
550 |
class allInstancesDo:[:i | |
|
551 |
|sz| |
|
552 |
||
553 |
sz := i size. |
|
554 |
sizeBag add:sz. |
|
555 |
minSize := (minSize ? sz) min:sz. |
|
556 |
maxSize := (maxSize ? sz) max:sz. |
|
557 |
]. |
|
558 |
||
559 |
sizeBag isEmpty ifTrue:[ |
|
560 |
Dialog warn:'No instances'. |
|
561 |
^ self. |
|
562 |
]. |
|
563 |
sizeBag inspect. |
|
564 |
! |
|
565 |
||
19 | 566 |
update |
567 |
self updateInfo. |
|
568 |
self updateDisplay |
|
92 | 569 |
! |
45 | 570 |
|
437
9526cb043cbc
list obsolete & removed classes separately
Claus Gittinger <cg@exept.de>
parents:
165
diff
changeset
|
571 |
usageMenu |
1619
6e4b1930841a
use new itemList message from PopUpMenu
Claus Gittinger <cg@exept.de>
parents:
1617
diff
changeset
|
572 |
<resource: #programMenu> |
6e4b1930841a
use new itemList message from PopUpMenu
Claus Gittinger <cg@exept.de>
parents:
1617
diff
changeset
|
573 |
|
1348 | 574 |
|m| |
575 |
||
576 |
m := PopUpMenu |
|
1617
2403cee7dc5a
use new itemList message from PopUpMenu
Claus Gittinger <cg@exept.de>
parents:
1513
diff
changeset
|
577 |
itemList:#( |
9924 | 578 |
('Filter by Namespace...' openNamespaceFilterDialog ) |
13346 | 579 |
('Filter by Inheritance...' openInheritanceFilterDialog ) |
9924 | 580 |
('No Filter' removeFilter ) |
581 |
('-') |
|
4253 | 582 |
('Sort by Class Name' sortByClass ) |
583 |
('Sort by Classes Basename' sortByClassNameWithoutPrefix ) |
|
584 |
('Sort by Inst Count' sortByInstCount ) |
|
585 |
('Sort by Memory Usage' sortByMemoryUsage ) |
|
586 |
('Sort by Average Size' sortByAverageSize ) |
|
587 |
('Sort by Maximum Size' sortByMaxSize ) |
|
9887 | 588 |
('Sort by Inst Allocation Rate' sortByInstanceAllocationRate ) |
589 |
('Sort by Byte Allocation Rate' sortByMemoryAllocationRate ) |
|
1617
2403cee7dc5a
use new itemList message from PopUpMenu
Claus Gittinger <cg@exept.de>
parents:
1513
diff
changeset
|
590 |
('-') |
4253 | 591 |
('Inspect Instances' inspectInstances ) |
12030 | 592 |
('Inspect Largest Instances' inspectLargestInstances ) |
4253 | 593 |
('Inspect with Search' inspectInstancesWithSearch ) |
594 |
('Inspect Owners' inspectOwners ) |
|
9887 | 595 |
('-') |
4253 | 596 |
('Ref Chains' displayGlobalRefChainsToInsts ) |
597 |
('Clear (nil) Instances' nilInstances ) |
|
1617
2403cee7dc5a
use new itemList message from PopUpMenu
Claus Gittinger <cg@exept.de>
parents:
1513
diff
changeset
|
598 |
('-') |
9887 | 599 |
('Browse Class' browseClass ) |
15778 | 600 |
('Size Histogram' showSizeHistogram ) |
9387 | 601 |
('-') |
9924 | 602 |
('Collect Garbage & Update' collectGarbageAndUpdate ) |
9887 | 603 |
('Start Autoupdate' startAutoUpdateProcess ) |
9924 | 604 |
('Autoupdate Interval...' openAutoUpdateIntervalDialog ) |
605 |
('Update' update ) |
|
1617
2403cee7dc5a
use new itemList message from PopUpMenu
Claus Gittinger <cg@exept.de>
parents:
1513
diff
changeset
|
606 |
) |
2403cee7dc5a
use new itemList message from PopUpMenu
Claus Gittinger <cg@exept.de>
parents:
1513
diff
changeset
|
607 |
resources:resources. |
437
9526cb043cbc
list obsolete & removed classes separately
Claus Gittinger <cg@exept.de>
parents:
165
diff
changeset
|
608 |
|
9887 | 609 |
(list hasSelection not or:[list selection < 3]) ifTrue:[ |
1741 | 610 |
m disableAll:#(inspectInstances inspectInstancesWithSearch |
611 |
inspectOwners |
|
9887 | 612 |
displayGlobalRefChainsToInsts |
613 |
nilInstances browseClass). |
|
1348 | 614 |
]. |
9887 | 615 |
autoUpdateProcess notNil ifTrue:[ |
9925 | 616 |
m labelAt:#startAutoUpdateProcess put:'Stop Autoupdate'. |
617 |
m selectorAt:#startAutoUpdateProcess put:#stopAutoUpdateProcess |
|
9887 | 618 |
]. |
619 |
||
9924 | 620 |
filter isNil ifTrue:[ |
621 |
m disableAll:#(removeFilter) |
|
622 |
]. |
|
1348 | 623 |
^ m |
437
9526cb043cbc
list obsolete & removed classes separately
Claus Gittinger <cg@exept.de>
parents:
165
diff
changeset
|
624 |
|
9925 | 625 |
"Modified: / 08-05-2011 / 12:38:47 / cg" |
9930 | 626 |
! |
627 |
||
628 |
withInstancesOfSelectedClassDo:aBlock |
|
629 |
|class insts| |
|
630 |
||
15778 | 631 |
(class := self selectedClassOrClassSymbol) isNil ifTrue:[ ^ self ]. |
9930 | 632 |
|
633 |
" |
|
634 |
special kludge |
|
635 |
" |
|
636 |
class isSymbol ifTrue:[ |
|
9931 | 637 |
class == #NameSpace ifTrue:[ |
638 |
class := (Smalltalk at:class) class. |
|
639 |
insts := class allSubInstances. |
|
640 |
insts remove:class soleInstance ifAbsent:nil |
|
641 |
] ifFalse:[ |
|
642 |
class == #Metaclass ifTrue:[ |
|
643 |
insts := Metaclass allSubInstances. |
|
644 |
] ifFalse:[ |
|
645 |
class == #Class ifTrue:[ |
|
646 |
insts := Class allSubInstances. |
|
647 |
] ifFalse:[ |
|
648 |
^ self. |
|
649 |
]. |
|
650 |
] |
|
9930 | 651 |
]. |
15742 | 652 |
aBlock value:insts |
9930 | 653 |
] ifFalse:[ |
15755 | 654 |
aBlock value:(class allInstances). |
9930 | 655 |
]. |
656 |
||
657 |
"Created: / 11-05-2011 / 14:36:00 / cg" |
|
9887 | 658 |
! ! |
659 |
||
660 |
!MemoryUsageView methodsFor:'menu-sorting'! |
|
661 |
||
662 |
sortByAverageSize |
|
663 |
self label:'Memory usage; by average size'. |
|
664 |
||
665 |
sortBlock := [:a :b | |
|
666 |
|n1 n2 m1 m2| |
|
667 |
||
668 |
n1 := a averageSize. |
|
669 |
n2 := b averageSize. |
|
670 |
n1 > n2 |
|
671 |
or:[n1 == n2 |
|
672 |
and:[a classNameOrSymbol displayString < b classNameOrSymbol displayString]] |
|
673 |
]. |
|
674 |
self updateDisplay |
|
675 |
||
676 |
"Modified: / 05-05-2011 / 16:11:24 / cg" |
|
677 |
! |
|
678 |
||
679 |
sortByClass |
|
680 |
self label:'Memory usage; by class'. |
|
681 |
||
682 |
sortBlock := [:a :b | |
|
683 |
|c1 c2 s1 s2| |
|
684 |
||
685 |
c1 := a classNameOrSymbol. |
|
686 |
c2 := b classNameOrSymbol. |
|
687 |
||
688 |
s1 := c1 isBehavior ifTrue:[ c1 name] ifFalse:[ c1 displayString ]. |
|
689 |
s2 := c2 isBehavior ifTrue:[ c2 name ] ifFalse:[ c2 displayString ]. |
|
690 |
s1 < s2 |
|
691 |
]. |
|
692 |
self updateDisplay |
|
693 |
||
694 |
"Modified: / 05-05-2011 / 16:11:53 / cg" |
|
695 |
! |
|
696 |
||
697 |
sortByClassNameWithoutPrefix |
|
698 |
self label:'Memory usage; by className without prefix'. |
|
699 |
||
700 |
sortBlock := [:a :b | |
|
701 |
|c1 c2 s1 s2| |
|
702 |
||
703 |
c1 := a classNameOrSymbol. |
|
704 |
c2 := b classNameOrSymbol. |
|
705 |
||
706 |
s1 := c1 isBehavior ifTrue:[ c1 nameWithoutPrefix ] ifFalse:[ c1 displayString ]. |
|
707 |
s2 := c2 isBehavior ifTrue:[ c2 nameWithoutPrefix ] ifFalse:[ c2 displayString ]. |
|
708 |
s1 < s2 |
|
709 |
]. |
|
710 |
self updateDisplay |
|
711 |
||
712 |
"Modified: / 05-05-2011 / 16:12:10 / cg" |
|
713 |
! |
|
714 |
||
715 |
sortByInstCount |
|
716 |
self label:'Memory usage; by instance count'. |
|
717 |
||
718 |
sortBlock := [:a :b | |
|
719 |
|n1 n2| |
|
720 |
n1 := a instanceCount. |
|
721 |
n2 := b instanceCount. |
|
722 |
n1 > n2 |
|
723 |
or:[n1 == n2 |
|
724 |
and:[(a classNameOrSymbol) displayString < (b classNameOrSymbol) displayString]] |
|
725 |
]. |
|
726 |
self updateDisplay |
|
727 |
||
728 |
"Modified: / 05-05-2011 / 16:47:26 / cg" |
|
729 |
! |
|
730 |
||
731 |
sortByInstanceAllocationRate |
|
732 |
self label:'Memory usage; by inst allocation rate'. |
|
733 |
||
734 |
sortBlock := [:a :b | |
|
735 |
|n1 n2 m1 m2| |
|
736 |
||
737 |
n1 := a instanceAllocationRate. |
|
738 |
n2 := b instanceAllocationRate. |
|
739 |
n1 > n2 |
|
740 |
or:[n1 == n2 |
|
741 |
and:[a classNameOrSymbol displayString < b classNameOrSymbol displayString]] |
|
742 |
]. |
|
743 |
self updateDisplay |
|
744 |
||
745 |
"Created: / 05-05-2011 / 16:14:56 / cg" |
|
746 |
! |
|
747 |
||
748 |
sortByMaxSize |
|
749 |
self label:'Memory usage; by maximum size'. |
|
750 |
||
751 |
sortBlock := [:a :b | |
|
752 |
|n1 n2 m1 m2| |
|
753 |
||
754 |
n1 := a maxByteSize. |
|
755 |
n2 := b maxByteSize. |
|
756 |
n1 > n2 |
|
757 |
or:[n1 == n2 |
|
758 |
and:[(a classNameOrSymbol) displayString < (b classNameOrSymbol) displayString]] |
|
759 |
]. |
|
760 |
self updateDisplay |
|
761 |
||
762 |
"Modified: / 05-05-2011 / 16:13:20 / cg" |
|
763 |
! |
|
764 |
||
765 |
sortByMemoryAllocationRate |
|
766 |
self label:'Memory usage; by inst allocation rate'. |
|
767 |
||
768 |
sortBlock := [:a :b | |
|
769 |
|n1 n2 m1 m2| |
|
770 |
||
771 |
n1 := a memoryAllocationRate. |
|
772 |
n2 := b memoryAllocationRate. |
|
773 |
n1 > n2 |
|
774 |
or:[n1 == n2 |
|
775 |
and:[a classNameOrSymbol displayString < b classNameOrSymbol displayString]] |
|
776 |
]. |
|
777 |
self updateDisplay |
|
778 |
||
779 |
"Created: / 05-05-2011 / 16:15:17 / cg" |
|
780 |
! |
|
781 |
||
782 |
sortByMemoryUsage |
|
783 |
self label:'Memory usage; by memory usage'. |
|
784 |
||
785 |
sortBlock := [:a :b | |
|
786 |
|n1 n2| |
|
787 |
||
788 |
n1 := a overallByteSize. |
|
789 |
n2 := b overallByteSize. |
|
790 |
n1 > n2 |
|
791 |
or:[n1 == n2 |
|
792 |
and:[(a classNameOrSymbol) displayString < (b classNameOrSymbol) displayString]] |
|
793 |
]. |
|
794 |
self updateDisplay |
|
795 |
||
796 |
"Modified: / 05-05-2011 / 16:13:58 / cg" |
|
45 | 797 |
! ! |
798 |
||
19 | 799 |
!MemoryUsageView methodsFor:'private'! |
800 |
||
15778 | 801 |
selectedClass |
802 |
|classOrSymbol| |
|
803 |
||
804 |
(classOrSymbol := self selectedClassOrClassSymbol) notNil ifTrue:[ |
|
805 |
classOrSymbol isSymbol ifFalse:[ |
|
806 |
^ classOrSymbol |
|
807 |
] |
|
808 |
]. |
|
809 |
^ nil |
|
810 |
! |
|
811 |
||
812 |
selectedClassOrClassSymbol |
|
813 |
|selIdx| |
|
814 |
||
815 |
(selIdx := list selection) notNil ifTrue:[ |
|
816 |
^ (info at:selIdx) classNameOrSymbol. |
|
817 |
]. |
|
818 |
^ nil |
|
819 |
! |
|
820 |
||
45 | 821 |
updateDisplay |
822 |
"update the displayed list" |
|
19 | 823 |
|
9887 | 824 |
|nameLen countLen bytesUsedSize avgSizeLen maxSizeLen accumMemoryUseLen| |
825 |
||
12892 | 826 |
rawInfo isNil ifTrue:[^ self]. |
827 |
||
9887 | 828 |
nameLen := 50. |
15742 | 829 |
countLen := 9. |
830 |
bytesUsedSize := 12. |
|
9887 | 831 |
avgSizeLen := 10. |
832 |
maxSizeLen := 8. |
|
833 |
accumMemoryUseLen := 7. |
|
834 |
||
49 | 835 |
windowGroup withCursor:Cursor wait do:[ |
1513 | 836 |
|classNames counts sumSizes maxSizes percents avgSizes |
837 |
l line allMemory |
|
838 |
overAllCount overAllAvgSize overAllMaxSize |
|
839 |
lastP sumPercent| |
|
49 | 840 |
|
9887 | 841 |
prevRawInfo notNil ifTrue:[ |
842 |
rawInfo keysAndValuesDo:[:key :entry | |
|
843 |
|prevEntry deltaInstCount deltaInstBytes prevInstCount prevInstBytes| |
|
844 |
||
845 |
prevEntry := prevRawInfo at:key ifAbsent:nil. |
|
846 |
prevInstCount := prevEntry notNil ifTrue:[prevEntry instanceCount] ifFalse:[0]. |
|
847 |
prevInstBytes := prevEntry notNil ifTrue:[prevEntry overallByteSize] ifFalse:0. |
|
848 |
deltaInstCount := entry instanceCount - prevInstCount. |
|
849 |
deltaInstBytes := entry overallByteSize - prevInstBytes. |
|
850 |
||
851 |
entry instanceAllocationRate:deltaInstCount. |
|
852 |
entry memoryAllocationRate:deltaInstBytes. |
|
853 |
]. |
|
854 |
]. |
|
855 |
||
9931 | 856 |
info := (OrderedCollection withAll:rawInfo) sort:sortBlock. |
19 | 857 |
|
9887 | 858 |
sumSizes := info collect:[:infoEntry | infoEntry overallByteSize ]. |
859 |
allMemory := sumSizes sum. |
|
1513 | 860 |
percents := sumSizes collect:[:sz | (sz asFloat / allMemory * 100)]. |
861 |
sumPercent := 0. |
|
52 | 862 |
|
9887 | 863 |
overAllMaxSize := overAllCount := 0. |
864 |
||
1513 | 865 |
l := OrderedCollection new. |
9887 | 866 |
info doWithIndex:[:entry :i | |
12889 | 867 |
|line avgSz avgSzString maxSz instCount percent allocRate memRate s1 s2| |
19 | 868 |
|
9887 | 869 |
maxSz := entry maxByteSize. |
870 |
avgSz := entry averageSize asFixedPoint:1. |
|
1513 | 871 |
avgSz = maxSz ifTrue:[ |
9887 | 872 |
avgSzString := avgSz asInteger printString , ' '. |
873 |
] ifFalse:[ |
|
874 |
avgSzString := avgSz printString. |
|
1513 | 875 |
]. |
9887 | 876 |
instCount := entry instanceCount. |
877 |
||
878 |
line := entry classNameStringInList printStringPaddedTo:nameLen. |
|
879 |
line := line contractTo:nameLen. |
|
880 |
||
881 |
line := line , (instCount printStringLeftPaddedTo:countLen). |
|
882 |
line := line , (entry overallByteSize printStringLeftPaddedTo:bytesUsedSize). |
|
883 |
line := line , (avgSzString leftPaddedTo:avgSizeLen). |
|
884 |
line := line , (maxSz printStringLeftPaddedTo:maxSizeLen). |
|
1513 | 885 |
percent := (percents at:i). |
1348 | 886 |
"/ percent < 0.0 ifTrue:[self halt]. |
9887 | 887 |
line := line , ((percent asFixedPoint:1) printStringLeftPaddedTo:accumMemoryUseLen). |
1513 | 888 |
lastP := sumPercent := ((sumPercent + percent) min:100.0). |
9887 | 889 |
line := line , ((sumPercent asFixedPoint:1) printStringLeftPaddedTo:accumMemoryUseLen). |
890 |
||
12889 | 891 |
allocRate := entry instanceAllocationRate. |
892 |
memRate := entry memoryAllocationRate. |
|
893 |
s1 := allocRate printString. |
|
894 |
s2 := memRate printString. |
|
895 |
allocRate > 0 ifTrue:[ |
|
16516 | 896 |
s1 := s1 withColor:#red. |
897 |
s2 := s2 withColor:#red. |
|
12889 | 898 |
] ifFalse:[ |
899 |
allocRate < 0 ifTrue:[ |
|
16516 | 900 |
s1 := s1 withColor:(Color green darkened). |
901 |
s2 := s2 withColor:(Color green darkened). |
|
12889 | 902 |
] |
903 |
]. |
|
904 |
line := line , (s1 leftPaddedTo:countLen). |
|
905 |
line := line , (s2 leftPaddedTo:bytesUsedSize). |
|
9887 | 906 |
|
907 |
l add:line. |
|
908 |
||
909 |
overAllMaxSize := overAllMaxSize max:entry maxByteSize. |
|
910 |
overAllCount := overAllCount + instCount. |
|
1513 | 911 |
]. |
1348 | 912 |
"/ (((lastP asFixedPoint:1) printStringLeftPaddedTo:7) startsWith:'99.') ifTrue:[self halt]. |
1513 | 913 |
"add summary line" |
14692 | 914 |
overAllAvgSize := 0. |
915 |
overAllCount == 0 ifFalse:[ |
|
916 |
overAllAvgSize := ((allMemory / overAllCount) * 10) rounded / 10.0. |
|
917 |
]. |
|
19 | 918 |
|
9887 | 919 |
l addFirst:''. |
920 |
line := 'all objects' printStringPaddedTo:nameLen. |
|
921 |
line := line , (overAllCount printStringLeftPaddedTo:countLen). |
|
922 |
line := line , (allMemory printStringLeftPaddedTo:bytesUsedSize). |
|
923 |
line := line , (overAllAvgSize printStringLeftPaddedTo:avgSizeLen). |
|
924 |
line := line , (overAllMaxSize printStringLeftPaddedTo:maxSizeLen). |
|
925 |
line := line , (100.0 printStringLeftPaddedTo:accumMemoryUseLen). |
|
926 |
l addFirst:line. |
|
92 | 927 |
|
9931 | 928 |
info addFirst:nil; addFirst:nil. |
929 |
||
1513 | 930 |
list list:l. |
49 | 931 |
] |
142 | 932 |
|
9887 | 933 |
"Created: / 19-09-1995 / 15:30:47 / claus" |
9931 | 934 |
"Modified: / 11-05-2011 / 14:47:52 / cg" |
45 | 935 |
! |
19 | 936 |
|
45 | 937 |
updateInfo |
938 |
"scan all memory and collect the information" |
|
939 |
||
49 | 940 |
windowGroup withCursor:Cursor questionMark do:[ |
2651 | 941 |
|myProcess myPriority| |
45 | 942 |
|
2651 | 943 |
"find all objects, collect stuff in info" |
45 | 944 |
|
2651 | 945 |
" |
946 |
this is a time consuming operation; therefore lower my priority ... |
|
947 |
" |
|
948 |
myProcess := Processor activeProcess. |
|
949 |
myPriority := myProcess priority. |
|
950 |
myProcess priority:(Processor userBackgroundPriority). |
|
9887 | 951 |
prevRawInfo := rawInfo. |
45 | 952 |
|
2651 | 953 |
rawInfo := IdentityDictionary new:600. |
52 | 954 |
|
2651 | 955 |
[ |behaviorFlag| |
142 | 956 |
|
2651 | 957 |
behaviorFlag := Behavior flagBehavior. |
142 | 958 |
|
2651 | 959 |
ObjectMemory allObjectsDo:[:o | |
9924 | 960 |
|infoEntry class flags skip| |
961 |
||
962 |
skip := false. |
|
45 | 963 |
|
142 | 964 |
"/ o isBehavior ifTrue:[ |
2651 | 965 |
class := o class. |
7860 | 966 |
flags := class flags. |
967 |
(flags notNil and:[flags class == SmallInteger]) ifTrue:[ |
|
9924 | 968 |
(filter isNil or:[ filter value:o value:class ]) ifTrue:[ |
969 |
(flags bitAnd:behaviorFlag) ~~ 0 ifTrue:[ |
|
970 |
Error |
|
971 |
handle:[:ex |] |
|
972 |
do:[ |
|
973 |
o isObsolete ifTrue:[ |
|
974 |
class := #ObsoleteClass |
|
975 |
] ifFalse:[ |
|
976 |
o isMeta ifTrue:[ |
|
977 |
o isPrivate ifTrue:[ |
|
978 |
class := #PrivateMetaclass |
|
979 |
] ifFalse:[ |
|
980 |
class := #Metaclass |
|
981 |
] |
|
7860 | 982 |
] ifFalse:[ |
9924 | 983 |
o isPrivate ifTrue:[ |
984 |
class := #PrivateClass |
|
985 |
] ifFalse:[ |
|
986 |
(o isNameSpace |
|
987 |
and:[o ~~ NameSpace |
|
988 |
and:[o ~~ Smalltalk]]) |
|
989 |
ifTrue:[ |
|
990 |
class := #NameSpace |
|
991 |
] ifFalse:[ |
|
992 |
class := #Class |
|
993 |
] |
|
994 |
] |
|
7860 | 995 |
] |
6825 | 996 |
] |
997 |
] |
|
9924 | 998 |
] |
999 |
] ifFalse:[ |
|
1000 |
skip := true |
|
7860 | 1001 |
]. |
2651 | 1002 |
]. |
9924 | 1003 |
skip ifFalse:[ |
1004 |
infoEntry := rawInfo at:class ifAbsent:nil. |
|
1005 |
infoEntry isNil ifTrue:[ |
|
1006 |
infoEntry := StatisticEntry new. |
|
1007 |
rawInfo at:class put:infoEntry. |
|
1008 |
]. |
|
1009 |
infoEntry addStatisticForInstance:o class:class. |
|
1010 |
] ifTrue:[ |
|
1011 |
"/ self halt |
|
9887 | 1012 |
]. |
2651 | 1013 |
]. |
16264 | 1014 |
] ensure:[ |
2651 | 1015 |
myProcess priority:myPriority. |
1016 |
]. |
|
45 | 1017 |
] |
142 | 1018 |
|
6825 | 1019 |
"Modified: / 19-09-1995 / 15:29:10 / claus" |
9924 | 1020 |
"Modified: / 08-05-2011 / 12:35:11 / cg" |
19 | 1021 |
! ! |
45 | 1022 |
|
92 | 1023 |
!MemoryUsageView methodsFor:'realization'! |
1024 |
||
1025 |
realize |
|
1026 |
super realize. |
|
1348 | 1027 |
titleLabel origin:(list originRelativeTo:self) x @ 0.0. |
92 | 1028 |
self updateInfo. |
12892 | 1029 |
|
1030 |
"/ self sortByClass. |
|
1031 |
self sortByMemoryUsage. |
|
1032 |
||
1033 |
"/ self updateDisplay. |
|
1348 | 1034 |
|
1035 |
"Modified: 14.10.1997 / 21:03:52 / cg" |
|
92 | 1036 |
! ! |
1037 |
||
9887 | 1038 |
!MemoryUsageView::StatisticEntry methodsFor:'accessing'! |
1039 |
||
1040 |
averageSize |
|
1041 |
averageSize isNil ifTrue:[ |
|
1042 |
averageSize := overallByteSize / instanceCount |
|
1043 |
]. |
|
1044 |
^ averageSize. |
|
1045 |
||
1046 |
"Created: / 05-05-2011 / 16:09:35 / cg" |
|
1047 |
! |
|
1048 |
||
1049 |
classNameOrSymbol |
|
1050 |
^ classNameOrSymbol |
|
1051 |
! |
|
1052 |
||
1053 |
classNameStringInList |
|
1054 |
classNameOrSymbol == #Class ifTrue:[ |
|
1055 |
^ '<all classes>' |
|
1056 |
]. |
|
1057 |
classNameOrSymbol == #Metaclass ifTrue:[ |
|
1058 |
^ '<all metaclasses>' |
|
1059 |
]. |
|
1060 |
classNameOrSymbol == #PrivateMetaclass ifTrue:[ |
|
1061 |
^ '<all private meta classes>' |
|
1062 |
]. |
|
1063 |
classNameOrSymbol == #PrivateClass ifTrue:[ |
|
1064 |
^ '<all private classes>' |
|
1065 |
]. |
|
1066 |
classNameOrSymbol == #ObsoleteClass ifTrue:[ |
|
1067 |
^ '<all obsolete classes>' |
|
1068 |
]. |
|
1069 |
classNameOrSymbol == #NameSpace ifTrue:[ |
|
1070 |
^ '<all namespaces>' |
|
1071 |
]. |
|
1072 |
classNameOrSymbol isJavaClass ifTrue:[ |
|
1073 |
^ classNameOrSymbol fullName asString copyReplaceAll:$/ with:$. |
|
1074 |
]. |
|
1075 |
classNameOrSymbol isObsolete ifTrue:[ |
|
1076 |
^ classNameOrSymbol name , ' (obsolete)' |
|
1077 |
]. |
|
1078 |
^ classNameOrSymbol "displayString" name |
|
1079 |
||
1080 |
"Created: / 05-05-2011 / 16:32:58 / cg" |
|
1081 |
! |
|
1082 |
||
1083 |
instanceAllocationRate |
|
1084 |
^ instanceAllocationRate ? 0 |
|
1085 |
||
1086 |
"Modified: / 05-05-2011 / 17:10:50 / cg" |
|
1087 |
! |
|
1088 |
||
1089 |
instanceAllocationRate:something |
|
1090 |
instanceAllocationRate := something. |
|
1091 |
! |
|
1092 |
||
1093 |
instanceCount |
|
1094 |
^ instanceCount |
|
1095 |
! |
|
1096 |
||
1097 |
maxByteSize |
|
1098 |
^ maxByteSize |
|
1099 |
! |
|
1100 |
||
1101 |
memoryAllocationRate |
|
1102 |
^ memoryAllocationRate ? 0 |
|
1103 |
||
1104 |
"Modified: / 05-05-2011 / 17:10:56 / cg" |
|
1105 |
! |
|
1106 |
||
1107 |
memoryAllocationRate:something |
|
1108 |
memoryAllocationRate := something. |
|
1109 |
! |
|
1110 |
||
1111 |
minByteSize |
|
1112 |
^ minByteSize |
|
1113 |
! |
|
1114 |
||
1115 |
overallByteSize |
|
1116 |
^ overallByteSize |
|
1117 |
! ! |
|
1118 |
||
1119 |
!MemoryUsageView::StatisticEntry methodsFor:'updating'! |
|
1120 |
||
1121 |
addStatisticForInstance:o class:classNameOrSymbolArg |
|
1122 |
|bytes| |
|
1123 |
||
1124 |
bytes := ObjectMemory sizeOf:o. |
|
1125 |
instanceCount isNil ifTrue:[ |
|
1126 |
classNameOrSymbol := classNameOrSymbolArg. |
|
1127 |
overallByteSize := bytes. |
|
1128 |
minByteSize := maxByteSize := bytes. |
|
1129 |
instanceCount := 1. |
|
1130 |
] ifFalse:[ |
|
1131 |
overallByteSize := overallByteSize + bytes. |
|
1132 |
minByteSize := minByteSize min:bytes. |
|
1133 |
maxByteSize := maxByteSize max:bytes. |
|
1134 |
instanceCount := instanceCount + 1. |
|
1135 |
]. |
|
1136 |
averageSize := nil. |
|
1137 |
||
1138 |
"Created: / 05-05-2011 / 16:04:42 / cg" |
|
1139 |
! ! |
|
1140 |
||
769 | 1141 |
!MemoryUsageView class methodsFor:'documentation'! |
45 | 1142 |
|
437
9526cb043cbc
list obsolete & removed classes separately
Claus Gittinger <cg@exept.de>
parents:
165
diff
changeset
|
1143 |
version |
15742 | 1144 |
^ '$Header$' |
9339
ff3e7cc06bf1
changed: #displayGlobalRefChainsToInsts
Claus Gittinger <cg@exept.de>
parents:
7950
diff
changeset
|
1145 |
! |
ff3e7cc06bf1
changed: #displayGlobalRefChainsToInsts
Claus Gittinger <cg@exept.de>
parents:
7950
diff
changeset
|
1146 |
|
ff3e7cc06bf1
changed: #displayGlobalRefChainsToInsts
Claus Gittinger <cg@exept.de>
parents:
7950
diff
changeset
|
1147 |
version_CVS |
15742 | 1148 |
^ '$Header$' |
45 | 1149 |
! ! |
12889 | 1150 |