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