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