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