author | Claus Gittinger <cg@exept.de> |
Wed, 20 Jan 2010 22:05:44 +0100 | |
changeset 9340 | 5c9f76236b92 |
parent 9339 | ff3e7cc06bf1 |
child 9387 | c5f99e84ed65 |
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 |
||
19 | 14 |
StandardSystemView subclass:#MemoryUsageView |
1348 | 15 |
instanceVariableNames:'rawInfo info list sortBlock titleLabel' |
437
9526cb043cbc
list obsolete & removed classes separately
Claus Gittinger <cg@exept.de>
parents:
165
diff
changeset
|
16 |
classVariableNames:'' |
9526cb043cbc
list obsolete & removed classes separately
Claus Gittinger <cg@exept.de>
parents:
165
diff
changeset
|
17 |
poolDictionaries:'' |
1053 | 18 |
category:'Monitors-ST/X' |
19 | 19 |
! |
20 |
||
769 | 21 |
!MemoryUsageView class methodsFor:'documentation'! |
19 | 22 |
|
45 | 23 |
copyright |
24 |
" |
|
25 |
COPYRIGHT (c) 1992 by Claus Gittinger |
|
26 |
All Rights Reserved |
|
19 | 27 |
|
45 | 28 |
This software is furnished under a license and may be used |
29 |
only in accordance with the terms of that license and with the |
|
30 |
inclusion of the above copyright notice. This software may not |
|
31 |
be provided or otherwise made available to, or used by, any |
|
32 |
other person. No title to or ownership of the software is |
|
33 |
hereby transferred. |
|
34 |
" |
|
35 |
! |
|
19 | 36 |
|
45 | 37 |
documentation |
38 |
" |
|
39 |
this view shows an overview over the memory usage of the system. |
|
40 |
usage: |
|
41 |
MemoryUsageView new open |
|
19 | 42 |
|
45 | 43 |
Since scanning all memory takes some time, this is not done |
44 |
automatically, but upon request. See the middlebuttonmenu-'update' |
|
45 |
function. |
|
46 |
" |
|
19 | 47 |
! ! |
48 |
||
1823 | 49 |
!MemoryUsageView class methodsFor:'startup'! |
50 |
||
51 |
isVisualStartable |
|
52 |
^ true |
|
53 |
||
54 |
"Created: / 10.8.1998 / 16:02:59 / cg" |
|
55 |
! ! |
|
56 |
||
437
9526cb043cbc
list obsolete & removed classes separately
Claus Gittinger <cg@exept.de>
parents:
165
diff
changeset
|
57 |
!MemoryUsageView methodsFor:'initialization'! |
9526cb043cbc
list obsolete & removed classes separately
Claus Gittinger <cg@exept.de>
parents:
165
diff
changeset
|
58 |
|
9526cb043cbc
list obsolete & removed classes separately
Claus Gittinger <cg@exept.de>
parents:
165
diff
changeset
|
59 |
initialize |
1348 | 60 |
|helpView headLine| |
437
9526cb043cbc
list obsolete & removed classes separately
Claus Gittinger <cg@exept.de>
parents:
165
diff
changeset
|
61 |
|
9526cb043cbc
list obsolete & removed classes separately
Claus Gittinger <cg@exept.de>
parents:
165
diff
changeset
|
62 |
super initialize. |
4253 | 63 |
self label:'Memory Usage'. |
19 | 64 |
|
6501 | 65 |
headLine := ' Class' paddedTo:50 with:Character space. |
66 |
headLine := headLine , '# of Insts Avg sz Max sz Bytes %Mem %Accum.'. |
|
437
9526cb043cbc
list obsolete & removed classes separately
Claus Gittinger <cg@exept.de>
parents:
165
diff
changeset
|
67 |
|
1348 | 68 |
titleLabel := Label in:self. |
69 |
titleLabel origin:(0.0 @ 0.0) corner:(1.0 @ titleLabel height). |
|
70 |
titleLabel borderWidth:0. |
|
71 |
titleLabel label:headLine. |
|
72 |
titleLabel adjust:#left. |
|
437
9526cb043cbc
list obsolete & removed classes separately
Claus Gittinger <cg@exept.de>
parents:
165
diff
changeset
|
73 |
|
9526cb043cbc
list obsolete & removed classes separately
Claus Gittinger <cg@exept.de>
parents:
165
diff
changeset
|
74 |
self extent:((font widthOf:headLine) + (device horizontalPixelPerMillimeter * 15) rounded) @ self height. |
19 | 75 |
|
437
9526cb043cbc
list obsolete & removed classes separately
Claus Gittinger <cg@exept.de>
parents:
165
diff
changeset
|
76 |
helpView := ScrollableView for:SelectionInListView in:self. |
1348 | 77 |
helpView origin:(0.0 @ titleLabel height) corner:1.0 @ 1.0. |
92 | 78 |
|
437
9526cb043cbc
list obsolete & removed classes separately
Claus Gittinger <cg@exept.de>
parents:
165
diff
changeset
|
79 |
list := helpView scrolledView. |
9526cb043cbc
list obsolete & removed classes separately
Claus Gittinger <cg@exept.de>
parents:
165
diff
changeset
|
80 |
|
1348 | 81 |
titleLabel origin:(list originRelativeTo:self) x @ 0.0. |
92 | 82 |
|
1273
3a8a91e6c5fa
give my listView a fixed font.
Claus Gittinger <cg@exept.de>
parents:
1053
diff
changeset
|
83 |
list font:(EditTextView defaultFont). |
1348 | 84 |
titleLabel font:(EditTextView defaultFont). |
437
9526cb043cbc
list obsolete & removed classes separately
Claus Gittinger <cg@exept.de>
parents:
165
diff
changeset
|
85 |
list menuHolder:self; menuPerformer:self; menuMessage:#usageMenu. |
92 | 86 |
|
437
9526cb043cbc
list obsolete & removed classes separately
Claus Gittinger <cg@exept.de>
parents:
165
diff
changeset
|
87 |
" |
9526cb043cbc
list obsolete & removed classes separately
Claus Gittinger <cg@exept.de>
parents:
165
diff
changeset
|
88 |
MemoryUsageView open |
9526cb043cbc
list obsolete & removed classes separately
Claus Gittinger <cg@exept.de>
parents:
165
diff
changeset
|
89 |
" |
1273
3a8a91e6c5fa
give my listView a fixed font.
Claus Gittinger <cg@exept.de>
parents:
1053
diff
changeset
|
90 |
|
1348 | 91 |
"Modified: 14.10.1997 / 21:30:23 / cg" |
437
9526cb043cbc
list obsolete & removed classes separately
Claus Gittinger <cg@exept.de>
parents:
165
diff
changeset
|
92 |
! ! |
9526cb043cbc
list obsolete & removed classes separately
Claus Gittinger <cg@exept.de>
parents:
165
diff
changeset
|
93 |
|
9526cb043cbc
list obsolete & removed classes separately
Claus Gittinger <cg@exept.de>
parents:
165
diff
changeset
|
94 |
!MemoryUsageView methodsFor:'menu actions'! |
19 | 95 |
|
1348 | 96 |
collectGarbageAndUpdate |
97 |
self withWaitCursorDo:[ |
|
1387
355fc1057e11
better print of java objects
Claus Gittinger <cg@exept.de>
parents:
1348
diff
changeset
|
98 |
ObjectMemory tenure. |
355fc1057e11
better print of java objects
Claus Gittinger <cg@exept.de>
parents:
1348
diff
changeset
|
99 |
ObjectMemory compressingGarbageCollect. |
1348 | 100 |
]. |
101 |
self update. |
|
102 |
||
103 |
"Created: 14.10.1997 / 21:36:38 / cg" |
|
104 |
"Modified: 14.10.1997 / 21:41:11 / cg" |
|
105 |
! |
|
106 |
||
1450 | 107 |
displayGlobalRefChainsToInsts |
108 |
|class| |
|
109 |
||
110 |
list selection notNil ifTrue:[ |
|
111 |
class := (info at:(list selection)) at:1. |
|
112 |
self withCursor:(Cursor questionMark) do:[ |
|
9339
ff3e7cc06bf1
changed: #displayGlobalRefChainsToInsts
Claus Gittinger <cg@exept.de>
parents:
7950
diff
changeset
|
113 |
|insts limit answer| |
1450 | 114 |
|
115 |
" |
|
116 |
special kludge |
|
117 |
" |
|
118 |
class isSymbol ifTrue:[ |
|
2653 | 119 |
class == #NameSpace ifFalse:[ |
1450 | 120 |
self information:'classes are directly refered to by Smalltalk'. |
121 |
^ self. |
|
122 |
]. |
|
123 |
class := (Smalltalk at:class) class. |
|
124 |
insts := class allSubInstances. |
|
125 |
insts remove:class soleInstance ifAbsent:nil |
|
126 |
] ifFalse:[ |
|
127 |
insts := class allInstances. |
|
128 |
]. |
|
9339
ff3e7cc06bf1
changed: #displayGlobalRefChainsToInsts
Claus Gittinger <cg@exept.de>
parents:
7950
diff
changeset
|
129 |
insts size > 10 ifTrue:[ |
ff3e7cc06bf1
changed: #displayGlobalRefChainsToInsts
Claus Gittinger <cg@exept.de>
parents:
7950
diff
changeset
|
130 |
answer := Dialog |
ff3e7cc06bf1
changed: #displayGlobalRefChainsToInsts
Claus Gittinger <cg@exept.de>
parents:
7950
diff
changeset
|
131 |
request:('There are ' , insts size printString , ' instances.\Do you really want to follow them all ?\\(Give number to follow or cancel)' withCRs) |
ff3e7cc06bf1
changed: #displayGlobalRefChainsToInsts
Claus Gittinger <cg@exept.de>
parents:
7950
diff
changeset
|
132 |
initialAnswer:insts size printString. |
ff3e7cc06bf1
changed: #displayGlobalRefChainsToInsts
Claus Gittinger <cg@exept.de>
parents:
7950
diff
changeset
|
133 |
|
ff3e7cc06bf1
changed: #displayGlobalRefChainsToInsts
Claus Gittinger <cg@exept.de>
parents:
7950
diff
changeset
|
134 |
limit := Integer readFrom:answer onError:nil. |
ff3e7cc06bf1
changed: #displayGlobalRefChainsToInsts
Claus Gittinger <cg@exept.de>
parents:
7950
diff
changeset
|
135 |
limit isNil ifTrue:[^ self]. |
ff3e7cc06bf1
changed: #displayGlobalRefChainsToInsts
Claus Gittinger <cg@exept.de>
parents:
7950
diff
changeset
|
136 |
insts := (insts asArray copyTo:limit) |
1450 | 137 |
]. |
138 |
insts := insts asArray. |
|
9340
5c9f76236b92
changed: #displayGlobalRefChainsToInsts
Claus Gittinger <cg@exept.de>
parents:
9339
diff
changeset
|
139 |
ObjectMemory displayRefChainToAny:insts limitNumberOfSearchedReferences:(limit ? 1000). |
1450 | 140 |
] |
141 |
] |
|
142 |
||
143 |
"Modified: / 15.10.1996 / 22:09:29 / cg" |
|
144 |
"Created: / 3.2.1998 / 00:03:22 / cg" |
|
145 |
! |
|
146 |
||
45 | 147 |
inspectInstances |
57 | 148 |
|class| |
45 | 149 |
|
57 | 150 |
list selection notNil ifTrue:[ |
2697
b4f4e431b71e
browserClass from preferences
Claus Gittinger <cg@exept.de>
parents:
2653
diff
changeset
|
151 |
class := (info at:(list selection)) at:1. |
b4f4e431b71e
browserClass from preferences
Claus Gittinger <cg@exept.de>
parents:
2653
diff
changeset
|
152 |
self withCursor:(Cursor questionMark) do:[ |
b4f4e431b71e
browserClass from preferences
Claus Gittinger <cg@exept.de>
parents:
2653
diff
changeset
|
153 |
|insts| |
52 | 154 |
|
2697
b4f4e431b71e
browserClass from preferences
Claus Gittinger <cg@exept.de>
parents:
2653
diff
changeset
|
155 |
" |
b4f4e431b71e
browserClass from preferences
Claus Gittinger <cg@exept.de>
parents:
2653
diff
changeset
|
156 |
special kludge |
b4f4e431b71e
browserClass from preferences
Claus Gittinger <cg@exept.de>
parents:
2653
diff
changeset
|
157 |
" |
b4f4e431b71e
browserClass from preferences
Claus Gittinger <cg@exept.de>
parents:
2653
diff
changeset
|
158 |
class isSymbol ifTrue:[ |
b4f4e431b71e
browserClass from preferences
Claus Gittinger <cg@exept.de>
parents:
2653
diff
changeset
|
159 |
class == #NameSpace ifFalse:[ |
b4f4e431b71e
browserClass from preferences
Claus Gittinger <cg@exept.de>
parents:
2653
diff
changeset
|
160 |
^ UserPreferences current systemBrowserClass open |
b4f4e431b71e
browserClass from preferences
Claus Gittinger <cg@exept.de>
parents:
2653
diff
changeset
|
161 |
]. |
b4f4e431b71e
browserClass from preferences
Claus Gittinger <cg@exept.de>
parents:
2653
diff
changeset
|
162 |
class := (Smalltalk at:class) class. |
b4f4e431b71e
browserClass from preferences
Claus Gittinger <cg@exept.de>
parents:
2653
diff
changeset
|
163 |
insts := class allSubInstances. |
b4f4e431b71e
browserClass from preferences
Claus Gittinger <cg@exept.de>
parents:
2653
diff
changeset
|
164 |
insts remove:class soleInstance ifAbsent:nil |
b4f4e431b71e
browserClass from preferences
Claus Gittinger <cg@exept.de>
parents:
2653
diff
changeset
|
165 |
] ifFalse:[ |
b4f4e431b71e
browserClass from preferences
Claus Gittinger <cg@exept.de>
parents:
2653
diff
changeset
|
166 |
insts := class allInstances. |
b4f4e431b71e
browserClass from preferences
Claus Gittinger <cg@exept.de>
parents:
2653
diff
changeset
|
167 |
]. |
b4f4e431b71e
browserClass from preferences
Claus Gittinger <cg@exept.de>
parents:
2653
diff
changeset
|
168 |
insts size > 500 ifTrue:[ |
b4f4e431b71e
browserClass from preferences
Claus Gittinger <cg@exept.de>
parents:
2653
diff
changeset
|
169 |
(self confirm:'there are ' , insts size printString , ' instances.\\Do you really want to see them all ?' withCRs) |
b4f4e431b71e
browserClass from preferences
Claus Gittinger <cg@exept.de>
parents:
2653
diff
changeset
|
170 |
ifFalse:[^ self] |
b4f4e431b71e
browserClass from preferences
Claus Gittinger <cg@exept.de>
parents:
2653
diff
changeset
|
171 |
]. |
b4f4e431b71e
browserClass from preferences
Claus Gittinger <cg@exept.de>
parents:
2653
diff
changeset
|
172 |
insts inspect |
b4f4e431b71e
browserClass from preferences
Claus Gittinger <cg@exept.de>
parents:
2653
diff
changeset
|
173 |
] |
52 | 174 |
] |
770 | 175 |
|
176 |
"Modified: 15.10.1996 / 22:09:29 / cg" |
|
52 | 177 |
! |
178 |
||
1738 | 179 |
inspectInstancesWithSearch |
180 |
|filter filterBlock class| |
|
181 |
||
182 |
filter := '[:inst | "<some condition for inst>" ]'. |
|
183 |
[filterBlock isNil] whileTrue:[ |
|
184 |
filter := Dialog request:'filter block:' initialAnswer:filter. |
|
185 |
filter size == 0 ifTrue:[^ self]. |
|
186 |
||
187 |
filterBlock := Compiler evaluate:filter. |
|
188 |
filterBlock isBlock ifFalse:[ |
|
189 |
self information:'bad syntax in block'. |
|
190 |
filterBlock := nil. |
|
191 |
]. |
|
192 |
]. |
|
193 |
||
194 |
list selection notNil ifTrue:[ |
|
195 |
class := (info at:(list selection)) at:1. |
|
196 |
self withCursor:(Cursor questionMark) do:[ |
|
197 |
|insts| |
|
198 |
||
199 |
" |
|
200 |
special kludge |
|
201 |
" |
|
202 |
class isSymbol ifTrue:[ |
|
2653 | 203 |
class == #NameSpace ifFalse:[ |
2697
b4f4e431b71e
browserClass from preferences
Claus Gittinger <cg@exept.de>
parents:
2653
diff
changeset
|
204 |
^ UserPreferences current systemBrowserClass open |
1738 | 205 |
]. |
206 |
class := (Smalltalk at:class) class. |
|
207 |
insts := class allSubInstances. |
|
208 |
insts remove:class soleInstance ifAbsent:nil |
|
209 |
] ifFalse:[ |
|
210 |
insts := class allInstances. |
|
211 |
]. |
|
212 |
insts := insts select:filterBlock. |
|
213 |
insts size > 500 ifTrue:[ |
|
214 |
(self confirm:'there are ' , insts size printString , ' instances.\\Do you really want to see them all ?' withCRs) |
|
215 |
ifFalse:[^ self] |
|
216 |
]. |
|
217 |
insts inspect |
|
218 |
] |
|
219 |
] |
|
220 |
||
221 |
"Modified: 15.10.1996 / 22:09:29 / cg" |
|
222 |
! |
|
223 |
||
52 | 224 |
inspectOwners |
69 | 225 |
|class inspector| |
52 | 226 |
|
57 | 227 |
list selection notNil ifTrue:[ |
7918 | 228 |
class := (info at:(list selection)) at:1. |
229 |
" |
|
230 |
special kludge |
|
231 |
" |
|
232 |
class isSymbol ifTrue:[^self]. |
|
770 | 233 |
|
7918 | 234 |
self withCursor:(Cursor questionMark) do:[ |
235 |
|owners dict| |
|
52 | 236 |
|
7918 | 237 |
owners := (ObjectMemory whoReferencesInstancesOf:class). |
238 |
owners isEmptyOrNil ifTrue:[ |
|
239 |
self information:'No owners found - next GC should remove it'. |
|
240 |
^ self |
|
241 |
]. |
|
242 |
owners := owners asOrderedCollection. |
|
243 |
owners size > 500 ifTrue:[ |
|
244 |
(self confirm:'there are ' , owners size printString , ' owners.\\Do you really want to see them all ?' withCRs) |
|
245 |
ifFalse:[^ self] |
|
246 |
]. |
|
247 |
dict := IdentityDictionary new. |
|
248 |
owners do:[:owner | |
|
7950 | 249 |
|set names oClass s nMore| |
52 | 250 |
|
7918 | 251 |
" |
252 |
skip weakArrays ... (they dont count) |
|
253 |
" |
|
254 |
(owner isMemberOf:WeakArray) ifFalse:[ |
|
7950 | 255 |
nMore := nil. |
7918 | 256 |
set := Set new. |
257 |
owner == Smalltalk ifTrue:[ |
|
258 |
owner keysAndValuesDo:[:key :val | |
|
259 |
(val isMemberOf:class) ifTrue:[ |
|
260 |
set add:key |
|
261 |
] |
|
262 |
] |
|
263 |
] ifFalse:[ |
|
264 |
names := owner class allInstVarNames. |
|
265 |
oClass := owner class. |
|
266 |
1 to:oClass instSize do:[:i | |
|
267 |
((owner instVarAt:i) isMemberOf:class) ifTrue:[ |
|
268 |
set add:(names at:i). |
|
269 |
]. |
|
270 |
]. |
|
271 |
oClass isVariable ifTrue:[ |
|
272 |
oClass isPointers ifTrue:[ |
|
273 |
1 to:owner basicSize do:[:i | |
|
274 |
((owner basicAt:i) isMemberOf:class) ifTrue:[ |
|
7950 | 275 |
nMore isNil ifTrue:[ |
276 |
set add:i. |
|
277 |
set size > 500 ifTrue:[ |
|
278 |
nMore := 0. |
|
279 |
] |
|
280 |
] ifFalse:[ |
|
281 |
nMore := nMore + 1. |
|
282 |
] |
|
7918 | 283 |
] |
284 |
] |
|
285 |
] |
|
286 |
]. |
|
287 |
]. |
|
288 |
" |
|
289 |
put a describing string into the dictionary |
|
290 |
" |
|
7950 | 291 |
s := WriteStream on:String new. |
292 |
s nextPutAll:'references in: '. |
|
7918 | 293 |
set do:[:name | |
7950 | 294 |
name isString ifTrue:[ |
295 |
s nextPutAll:name; nextPutAll:' ' |
|
296 |
] ifFalse:[ |
|
297 |
s nextPutAll:'['; nextPutAll:name printString; nextPutAll:'] ' |
|
298 |
] |
|
299 |
]. |
|
300 |
nMore notNil ifTrue:[ |
|
301 |
s nextPutAll:'... (', nMore printString,' more)' |
|
302 |
]. |
|
303 |
dict at:owner put:(s contents). |
|
57 | 304 |
"/ dict at:owner put:set |
7918 | 305 |
] |
306 |
]. |
|
307 |
inspector := DictionaryInspectorView openOn:dict. |
|
308 |
inspector listView doubleClickAction:[:lineNr | inspector doInspectKey]. |
|
309 |
] |
|
45 | 310 |
] |
770 | 311 |
|
312 |
"Modified: 15.10.1996 / 22:09:38 / cg" |
|
45 | 313 |
! |
314 |
||
2858 | 315 |
nilInstances |
316 |
|class| |
|
317 |
||
318 |
list selection notNil ifTrue:[ |
|
319 |
class := (info at:(list selection)) at:1. |
|
320 |
self withCursor:(Cursor questionMark) do:[ |
|
321 |
|insts| |
|
322 |
||
323 |
insts := class allInstances. |
|
324 |
insts notEmpty ifTrue:[ |
|
325 |
(self confirm:'there are ' , insts size printString , ' instances.\\Do you really want to nil them all ?' withCRs) |
|
326 |
ifTrue:[ |
|
327 |
insts do:[:each | |
|
328 |
each becomeNil |
|
329 |
] |
|
330 |
] |
|
331 |
]. |
|
332 |
] |
|
333 |
] |
|
334 |
||
335 |
"Modified: 15.10.1996 / 22:09:29 / cg" |
|
336 |
! |
|
337 |
||
437
9526cb043cbc
list obsolete & removed classes separately
Claus Gittinger <cg@exept.de>
parents:
165
diff
changeset
|
338 |
sortByAverageSize |
9526cb043cbc
list obsolete & removed classes separately
Claus Gittinger <cg@exept.de>
parents:
165
diff
changeset
|
339 |
self label:'Memory usage; by average size'. |
924 | 340 |
"/ sortBlock := [:a :b | ((a at:3)/(a at:2)) > ((b at:3)/(b at:2))]. |
341 |
sortBlock := [:a :b | |n1 n2 m1 m2| |
|
1387
355fc1057e11
better print of java objects
Claus Gittinger <cg@exept.de>
parents:
1348
diff
changeset
|
342 |
n1 := ((a at:3)/(a at:2)). |
355fc1057e11
better print of java objects
Claus Gittinger <cg@exept.de>
parents:
1348
diff
changeset
|
343 |
n2 := ((b at:3)/(b at:2)). |
355fc1057e11
better print of java objects
Claus Gittinger <cg@exept.de>
parents:
1348
diff
changeset
|
344 |
n1 > n2 |
355fc1057e11
better print of java objects
Claus Gittinger <cg@exept.de>
parents:
1348
diff
changeset
|
345 |
or:[n1 == n2 |
355fc1057e11
better print of java objects
Claus Gittinger <cg@exept.de>
parents:
1348
diff
changeset
|
346 |
and:[(a at:1) displayString < (b at:1) displayString]]]. |
437
9526cb043cbc
list obsolete & removed classes separately
Claus Gittinger <cg@exept.de>
parents:
165
diff
changeset
|
347 |
self updateDisplay |
9526cb043cbc
list obsolete & removed classes separately
Claus Gittinger <cg@exept.de>
parents:
165
diff
changeset
|
348 |
|
9526cb043cbc
list obsolete & removed classes separately
Claus Gittinger <cg@exept.de>
parents:
165
diff
changeset
|
349 |
|
9526cb043cbc
list obsolete & removed classes separately
Claus Gittinger <cg@exept.de>
parents:
165
diff
changeset
|
350 |
! |
9526cb043cbc
list obsolete & removed classes separately
Claus Gittinger <cg@exept.de>
parents:
165
diff
changeset
|
351 |
|
9526cb043cbc
list obsolete & removed classes separately
Claus Gittinger <cg@exept.de>
parents:
165
diff
changeset
|
352 |
sortByClass |
9526cb043cbc
list obsolete & removed classes separately
Claus Gittinger <cg@exept.de>
parents:
165
diff
changeset
|
353 |
self label:'Memory usage; by class'. |
2757 | 354 |
sortBlock := [:a :b | |c1 c2 s1 s2| |
355 |
||
356 |
c1 := (a at:1). |
|
357 |
c2 := (b at:1). |
|
358 |
||
359 |
s1 := c1 isBehavior ifTrue:[ c1 name] ifFalse:[ c1 displayString ]. |
|
360 |
s2 := c2 isBehavior ifTrue:[ c2 name ] ifFalse:[ c2 displayString ]. |
|
361 |
s1 < s2]. |
|
437
9526cb043cbc
list obsolete & removed classes separately
Claus Gittinger <cg@exept.de>
parents:
165
diff
changeset
|
362 |
self updateDisplay |
643 | 363 |
|
364 |
"Modified: 28.6.1996 / 14:32:38 / cg" |
|
437
9526cb043cbc
list obsolete & removed classes separately
Claus Gittinger <cg@exept.de>
parents:
165
diff
changeset
|
365 |
! |
9526cb043cbc
list obsolete & removed classes separately
Claus Gittinger <cg@exept.de>
parents:
165
diff
changeset
|
366 |
|
2757 | 367 |
sortByClassNameWithoutPrefix |
368 |
self label:'Memory usage; by className without prefix'. |
|
369 |
sortBlock := [:a :b | |c1 c2 s1 s2| |
|
370 |
||
371 |
c1 := (a at:1). |
|
372 |
c2 := (b at:1). |
|
373 |
||
374 |
s1 := c1 isBehavior ifTrue:[ c1 nameWithoutPrefix ] ifFalse:[ c1 displayString ]. |
|
375 |
s2 := c2 isBehavior ifTrue:[ c2 nameWithoutPrefix ] ifFalse:[ c2 displayString ]. |
|
376 |
s1 < s2]. |
|
377 |
self updateDisplay |
|
378 |
||
379 |
||
380 |
||
381 |
||
382 |
||
383 |
||
384 |
||
385 |
! |
|
386 |
||
437
9526cb043cbc
list obsolete & removed classes separately
Claus Gittinger <cg@exept.de>
parents:
165
diff
changeset
|
387 |
sortByInstCount |
9526cb043cbc
list obsolete & removed classes separately
Claus Gittinger <cg@exept.de>
parents:
165
diff
changeset
|
388 |
self label:'Memory usage; by instance count'. |
924 | 389 |
"/ sortBlock := [:a :b | (a at:2) > (b at:2) ]. |
390 |
sortBlock := [:a :b | |n1 n2| |
|
1387
355fc1057e11
better print of java objects
Claus Gittinger <cg@exept.de>
parents:
1348
diff
changeset
|
391 |
n1 := (a at:2). |
355fc1057e11
better print of java objects
Claus Gittinger <cg@exept.de>
parents:
1348
diff
changeset
|
392 |
n2 := (b at:2). |
355fc1057e11
better print of java objects
Claus Gittinger <cg@exept.de>
parents:
1348
diff
changeset
|
393 |
n1 > n2 |
355fc1057e11
better print of java objects
Claus Gittinger <cg@exept.de>
parents:
1348
diff
changeset
|
394 |
or:[n1 == n2 |
355fc1057e11
better print of java objects
Claus Gittinger <cg@exept.de>
parents:
1348
diff
changeset
|
395 |
and:[(a at:1) displayString < (b at:1) displayString]]]. |
437
9526cb043cbc
list obsolete & removed classes separately
Claus Gittinger <cg@exept.de>
parents:
165
diff
changeset
|
396 |
self updateDisplay |
9526cb043cbc
list obsolete & removed classes separately
Claus Gittinger <cg@exept.de>
parents:
165
diff
changeset
|
397 |
! |
9526cb043cbc
list obsolete & removed classes separately
Claus Gittinger <cg@exept.de>
parents:
165
diff
changeset
|
398 |
|
924 | 399 |
sortByMaxSize |
400 |
self label:'Memory usage; by maximum size'. |
|
401 |
"/ sortBlock := [:a :b | (a at:4) > (b at:4)]. |
|
402 |
sortBlock := [:a :b | |n1 n2 m1 m2| |
|
1387
355fc1057e11
better print of java objects
Claus Gittinger <cg@exept.de>
parents:
1348
diff
changeset
|
403 |
n1 := (a at:4). |
355fc1057e11
better print of java objects
Claus Gittinger <cg@exept.de>
parents:
1348
diff
changeset
|
404 |
n2 := (b at:4). |
355fc1057e11
better print of java objects
Claus Gittinger <cg@exept.de>
parents:
1348
diff
changeset
|
405 |
n1 > n2 |
355fc1057e11
better print of java objects
Claus Gittinger <cg@exept.de>
parents:
1348
diff
changeset
|
406 |
or:[n1 == n2 |
355fc1057e11
better print of java objects
Claus Gittinger <cg@exept.de>
parents:
1348
diff
changeset
|
407 |
and:[(a at:1) displayString < (b at:1) displayString]]]. |
924 | 408 |
self updateDisplay |
409 |
||
410 |
||
411 |
! |
|
412 |
||
437
9526cb043cbc
list obsolete & removed classes separately
Claus Gittinger <cg@exept.de>
parents:
165
diff
changeset
|
413 |
sortByMemoryUsage |
9526cb043cbc
list obsolete & removed classes separately
Claus Gittinger <cg@exept.de>
parents:
165
diff
changeset
|
414 |
self label:'Memory usage; by memory usage'. |
924 | 415 |
"/ sortBlock := [:a :b | (a at:3) > (b at:3)]. |
416 |
sortBlock := [:a :b | |n1 n2| |
|
1387
355fc1057e11
better print of java objects
Claus Gittinger <cg@exept.de>
parents:
1348
diff
changeset
|
417 |
n1 := (a at:3). |
355fc1057e11
better print of java objects
Claus Gittinger <cg@exept.de>
parents:
1348
diff
changeset
|
418 |
n2 := (b at:3). |
355fc1057e11
better print of java objects
Claus Gittinger <cg@exept.de>
parents:
1348
diff
changeset
|
419 |
n1 > n2 |
355fc1057e11
better print of java objects
Claus Gittinger <cg@exept.de>
parents:
1348
diff
changeset
|
420 |
or:[n1 == n2 |
355fc1057e11
better print of java objects
Claus Gittinger <cg@exept.de>
parents:
1348
diff
changeset
|
421 |
and:[(a at:1) displayString < (b at:1) displayString]]]. |
437
9526cb043cbc
list obsolete & removed classes separately
Claus Gittinger <cg@exept.de>
parents:
165
diff
changeset
|
422 |
self updateDisplay |
9526cb043cbc
list obsolete & removed classes separately
Claus Gittinger <cg@exept.de>
parents:
165
diff
changeset
|
423 |
|
9526cb043cbc
list obsolete & removed classes separately
Claus Gittinger <cg@exept.de>
parents:
165
diff
changeset
|
424 |
|
9526cb043cbc
list obsolete & removed classes separately
Claus Gittinger <cg@exept.de>
parents:
165
diff
changeset
|
425 |
! |
9526cb043cbc
list obsolete & removed classes separately
Claus Gittinger <cg@exept.de>
parents:
165
diff
changeset
|
426 |
|
19 | 427 |
update |
428 |
self updateInfo. |
|
429 |
self updateDisplay |
|
92 | 430 |
! |
45 | 431 |
|
437
9526cb043cbc
list obsolete & removed classes separately
Claus Gittinger <cg@exept.de>
parents:
165
diff
changeset
|
432 |
usageMenu |
1619
6e4b1930841a
use new itemList message from PopUpMenu
Claus Gittinger <cg@exept.de>
parents:
1617
diff
changeset
|
433 |
<resource: #programMenu> |
6e4b1930841a
use new itemList message from PopUpMenu
Claus Gittinger <cg@exept.de>
parents:
1617
diff
changeset
|
434 |
|
1348 | 435 |
|m| |
436 |
||
437 |
m := PopUpMenu |
|
1617
2403cee7dc5a
use new itemList message from PopUpMenu
Claus Gittinger <cg@exept.de>
parents:
1513
diff
changeset
|
438 |
itemList:#( |
4253 | 439 |
('Sort by Class Name' sortByClass ) |
440 |
('Sort by Classes Basename' sortByClassNameWithoutPrefix ) |
|
441 |
('Sort by Inst Count' sortByInstCount ) |
|
442 |
('Sort by Memory Usage' sortByMemoryUsage ) |
|
443 |
('Sort by Average Size' sortByAverageSize ) |
|
444 |
('Sort by Maximum Size' sortByMaxSize ) |
|
1617
2403cee7dc5a
use new itemList message from PopUpMenu
Claus Gittinger <cg@exept.de>
parents:
1513
diff
changeset
|
445 |
('-') |
4253 | 446 |
('Inspect Instances' inspectInstances ) |
447 |
('Inspect with Search' inspectInstancesWithSearch ) |
|
448 |
('Inspect Owners' inspectOwners ) |
|
449 |
('Ref Chains' displayGlobalRefChainsToInsts ) |
|
450 |
('Clear (nil) Instances' nilInstances ) |
|
1617
2403cee7dc5a
use new itemList message from PopUpMenu
Claus Gittinger <cg@exept.de>
parents:
1513
diff
changeset
|
451 |
('-') |
4253 | 452 |
('Update' update ) |
453 |
('Collect Garbage & Update' collectGarbageAndUpdate ) |
|
1617
2403cee7dc5a
use new itemList message from PopUpMenu
Claus Gittinger <cg@exept.de>
parents:
1513
diff
changeset
|
454 |
) |
2403cee7dc5a
use new itemList message from PopUpMenu
Claus Gittinger <cg@exept.de>
parents:
1513
diff
changeset
|
455 |
resources:resources. |
437
9526cb043cbc
list obsolete & removed classes separately
Claus Gittinger <cg@exept.de>
parents:
165
diff
changeset
|
456 |
|
1348 | 457 |
list hasSelection ifFalse:[ |
1741 | 458 |
m disableAll:#(inspectInstances inspectInstancesWithSearch |
459 |
inspectOwners |
|
460 |
displayGlobalRefChainsToInsts). |
|
1348 | 461 |
]. |
462 |
^ m |
|
437
9526cb043cbc
list obsolete & removed classes separately
Claus Gittinger <cg@exept.de>
parents:
165
diff
changeset
|
463 |
|
1450 | 464 |
"Modified: / 3.2.1998 / 00:04:16 / cg" |
45 | 465 |
! ! |
466 |
||
19 | 467 |
!MemoryUsageView methodsFor:'private'! |
468 |
||
45 | 469 |
updateDisplay |
470 |
"update the displayed list" |
|
19 | 471 |
|
49 | 472 |
windowGroup withCursor:Cursor wait do:[ |
1513 | 473 |
|classNames counts sumSizes maxSizes percents avgSizes |
474 |
l line allMemory |
|
475 |
overAllCount overAllAvgSize overAllMaxSize |
|
476 |
lastP sumPercent| |
|
49 | 477 |
|
1513 | 478 |
info := rawInfo asSortedCollection:sortBlock. |
19 | 479 |
|
1513 | 480 |
classNames := info collect:[:infoArray | |
481 |
|cls| |
|
19 | 482 |
|
1513 | 483 |
cls := infoArray at:1. |
484 |
cls == #Class ifTrue:[ |
|
485 |
'<all classes>' |
|
486 |
] ifFalse:[ |
|
487 |
cls == #Metaclass ifTrue:[ |
|
488 |
'<all metaclasses>' |
|
489 |
] ifFalse:[ |
|
490 |
cls == #PrivateMetaclass ifTrue:[ |
|
491 |
'<all private meta classes>' |
|
492 |
] ifFalse:[ |
|
493 |
cls == #PrivateClass ifTrue:[ |
|
494 |
'<all private classes>' |
|
495 |
] ifFalse:[ |
|
496 |
cls == #ObsoleteClass ifTrue:[ |
|
497 |
'<all obsolete classes>' |
|
498 |
] ifFalse:[ |
|
2653 | 499 |
cls == #NameSpace ifTrue:[ |
1513 | 500 |
'<all namespaces>' |
501 |
] ifFalse:[ |
|
502 |
cls isJavaClass ifTrue:[ |
|
1728 | 503 |
cls fullName asString copyReplaceAll:$/ with:$. |
1513 | 504 |
] ifFalse:[ |
6391 | 505 |
cls isObsolete ifTrue:[ |
506 |
cls name,' (obsolete)' |
|
507 |
] ifFalse:[ |
|
508 |
cls "displayString" name |
|
509 |
] |
|
1513 | 510 |
] |
511 |
] |
|
512 |
] |
|
513 |
] |
|
514 |
] |
|
515 |
] |
|
516 |
] |
|
517 |
]. |
|
19 | 518 |
|
1513 | 519 |
counts := info collect:[:infoArray | (infoArray at:2) ]. |
520 |
sumSizes := info collect:[:infoArray | (infoArray at:3) ]. |
|
521 |
maxSizes := info collect:[:infoArray | (infoArray at:4) ]. |
|
522 |
allMemory := sumSizes inject:0 into:[:sum :this | sum + this]. |
|
523 |
"/ allMemory := ObjectMemory bytesUsed. |
|
524 |
percents := sumSizes collect:[:sz | (sz asFloat / allMemory * 100)]. |
|
525 |
avgSizes := (1 to:sumSizes size) collect:[:i | (((sumSizes at:i) / (counts at:i)) * 10) rounded / 10.0]. |
|
526 |
sumPercent := 0. |
|
52 | 527 |
|
1513 | 528 |
l := OrderedCollection new. |
529 |
1 to:classNames size do:[:i | |
|
530 |
|line avgSz maxSz percent| |
|
19 | 531 |
|
1513 | 532 |
avgSz := avgSizes at:i. |
533 |
maxSz := maxSizes at:i. |
|
534 |
avgSz = maxSz ifTrue:[ |
|
535 |
avgSz := avgSz asInteger printString , ' '. |
|
536 |
]. |
|
6391 | 537 |
line := (classNames at:i) printStringPaddedTo:50 with:Character space. |
538 |
line := line contractTo:50. |
|
1513 | 539 |
line := line , ((counts at:i) printStringLeftPaddedTo:7). |
540 |
line := line , (avgSz printStringLeftPaddedTo:10). |
|
541 |
line := line , (maxSz printStringLeftPaddedTo:8). |
|
542 |
line := line , ((sumSizes at:i) printStringLeftPaddedTo:10). |
|
543 |
percent := (percents at:i). |
|
1348 | 544 |
"/ percent < 0.0 ifTrue:[self halt]. |
1513 | 545 |
line := line , ((percent asFixedPoint:1) printStringLeftPaddedTo:7). |
546 |
lastP := sumPercent := ((sumPercent + percent) min:100.0). |
|
547 |
line := line , ((sumPercent asFixedPoint:1) printStringLeftPaddedTo:7). |
|
548 |
l add:line |
|
549 |
]. |
|
1348 | 550 |
"/ (((lastP asFixedPoint:1) printStringLeftPaddedTo:7) startsWith:'99.') ifTrue:[self halt]. |
1513 | 551 |
"add summary line" |
552 |
overAllCount := counts inject:0 into:[:sum :this | sum + this]. |
|
553 |
overAllAvgSize := ((allMemory / overAllCount) * 10) rounded / 10.0. |
|
554 |
overAllMaxSize := maxSizes max. |
|
19 | 555 |
|
1513 | 556 |
l add:''. |
557 |
line := 'all objects' printStringPaddedTo:33 with:Character space. |
|
558 |
line := line , (overAllCount printStringLeftPaddedTo:7). |
|
559 |
line := line , (overAllAvgSize printStringLeftPaddedTo:10). |
|
560 |
line := line , (overAllMaxSize printStringLeftPaddedTo:8). |
|
561 |
line := line , (allMemory printStringLeftPaddedTo:10). |
|
562 |
line := line , (100.0 printStringLeftPaddedTo:7). |
|
563 |
l add:line. |
|
92 | 564 |
|
1513 | 565 |
list list:l. |
49 | 566 |
] |
142 | 567 |
|
1513 | 568 |
"Created: / 19.9.1995 / 15:30:47 / claus" |
1728 | 569 |
"Modified: / 19.7.1998 / 00:47:08 / cg" |
45 | 570 |
! |
19 | 571 |
|
45 | 572 |
updateInfo |
573 |
"scan all memory and collect the information" |
|
574 |
||
49 | 575 |
windowGroup withCursor:Cursor questionMark do:[ |
2651 | 576 |
|myProcess myPriority| |
45 | 577 |
|
2651 | 578 |
"find all objects, collect stuff in info" |
45 | 579 |
|
2651 | 580 |
" |
581 |
this is a time consuming operation; therefore lower my priority ... |
|
582 |
" |
|
583 |
myProcess := Processor activeProcess. |
|
584 |
myPriority := myProcess priority. |
|
585 |
myProcess priority:(Processor userBackgroundPriority). |
|
45 | 586 |
|
2651 | 587 |
rawInfo := IdentityDictionary new:600. |
52 | 588 |
|
2651 | 589 |
[ |behaviorFlag| |
142 | 590 |
|
2651 | 591 |
behaviorFlag := Behavior flagBehavior. |
142 | 592 |
|
2651 | 593 |
ObjectMemory allObjectsDo:[:o | |
7860 | 594 |
|infoArray class bytes flags| |
45 | 595 |
|
142 | 596 |
"/ o isBehavior ifTrue:[ |
2651 | 597 |
class := o class. |
7860 | 598 |
flags := class flags. |
599 |
(flags notNil and:[flags class == SmallInteger]) ifTrue:[ |
|
600 |
(flags bitAnd:behaviorFlag) ~~ 0 ifTrue:[ |
|
601 |
Error |
|
602 |
handle:[:ex |] |
|
603 |
do:[ |
|
604 |
o isObsolete ifTrue:[ |
|
605 |
class := #ObsoleteClass |
|
606 |
] ifFalse:[ |
|
607 |
o isMeta ifTrue:[ |
|
608 |
o isPrivate ifTrue:[ |
|
609 |
class := #PrivateMetaclass |
|
610 |
] ifFalse:[ |
|
611 |
class := #Metaclass |
|
612 |
] |
|
6825 | 613 |
] ifFalse:[ |
7860 | 614 |
o isPrivate ifTrue:[ |
615 |
class := #PrivateClass |
|
616 |
] ifFalse:[ |
|
617 |
(o isNameSpace |
|
618 |
and:[o ~~ NameSpace |
|
619 |
and:[o ~~ Smalltalk]]) |
|
620 |
ifTrue:[ |
|
621 |
class := #NameSpace |
|
622 |
] ifFalse:[ |
|
623 |
class := #Class |
|
624 |
] |
|
625 |
] |
|
6825 | 626 |
] |
627 |
] |
|
2651 | 628 |
] |
7860 | 629 |
]. |
2651 | 630 |
]. |
769 | 631 |
|
2651 | 632 |
bytes := ObjectMemory sizeOf:o. |
633 |
infoArray := rawInfo at:class ifAbsent:[]. |
|
634 |
infoArray isNil ifTrue:[ |
|
635 |
infoArray := Array |
|
636 |
with:class |
|
637 |
with:1 |
|
638 |
with:bytes |
|
639 |
with:bytes. |
|
640 |
rawInfo at:class put:infoArray. |
|
641 |
] ifFalse:[ |
|
642 |
infoArray at:2 put:((infoArray at:2) + 1). |
|
643 |
infoArray at:3 put:((infoArray at:3) + bytes). |
|
644 |
infoArray at:4 put:((infoArray at:4) max: bytes). |
|
645 |
] |
|
646 |
]. |
|
647 |
] valueNowOrOnUnwindDo:[ |
|
648 |
myProcess priority:myPriority. |
|
649 |
]. |
|
45 | 650 |
] |
142 | 651 |
|
6825 | 652 |
"Modified: / 19-09-1995 / 15:29:10 / claus" |
7860 | 653 |
"Modified: / 11-10-2007 / 14:46:55 / cg" |
19 | 654 |
! ! |
45 | 655 |
|
92 | 656 |
!MemoryUsageView methodsFor:'realization'! |
657 |
||
658 |
realize |
|
659 |
super realize. |
|
1348 | 660 |
titleLabel origin:(list originRelativeTo:self) x @ 0.0. |
92 | 661 |
self updateInfo. |
662 |
self sortByClass. |
|
1348 | 663 |
|
664 |
"Modified: 14.10.1997 / 21:03:52 / cg" |
|
92 | 665 |
! ! |
666 |
||
769 | 667 |
!MemoryUsageView class methodsFor:'documentation'! |
45 | 668 |
|
437
9526cb043cbc
list obsolete & removed classes separately
Claus Gittinger <cg@exept.de>
parents:
165
diff
changeset
|
669 |
version |
9340
5c9f76236b92
changed: #displayGlobalRefChainsToInsts
Claus Gittinger <cg@exept.de>
parents:
9339
diff
changeset
|
670 |
^ '$Header: /cvs/stx/stx/libtool/MemoryUsageView.st,v 1.52 2010-01-20 21:05:44 cg Exp $' |
9339
ff3e7cc06bf1
changed: #displayGlobalRefChainsToInsts
Claus Gittinger <cg@exept.de>
parents:
7950
diff
changeset
|
671 |
! |
ff3e7cc06bf1
changed: #displayGlobalRefChainsToInsts
Claus Gittinger <cg@exept.de>
parents:
7950
diff
changeset
|
672 |
|
ff3e7cc06bf1
changed: #displayGlobalRefChainsToInsts
Claus Gittinger <cg@exept.de>
parents:
7950
diff
changeset
|
673 |
version_CVS |
9340
5c9f76236b92
changed: #displayGlobalRefChainsToInsts
Claus Gittinger <cg@exept.de>
parents:
9339
diff
changeset
|
674 |
^ '$Header: /cvs/stx/stx/libtool/MemoryUsageView.st,v 1.52 2010-01-20 21:05:44 cg Exp $' |
45 | 675 |
! ! |