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