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