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 |
"
|
|
12 |
|
|
13 |
'From Smalltalk/X, Version:2.10.3 on 30-sep-1994 at 11:13:14'!
|
|
14 |
|
19
|
15 |
StandardSystemView subclass:#MemoryUsageView
|
45
|
16 |
instanceVariableNames:'info list sortBlock'
|
|
17 |
classVariableNames:''
|
|
18 |
poolDictionaries:''
|
|
19 |
category:'Interface-Tools'
|
19
|
20 |
!
|
|
21 |
|
45
|
22 |
MemoryUsageView comment:'
|
|
23 |
COPYRIGHT (c) 1992 by Claus Gittinger
|
|
24 |
All Rights Reserved
|
|
25 |
'!
|
19
|
26 |
|
45
|
27 |
!MemoryUsageView class methodsFor:'documentation'!
|
19
|
28 |
|
45
|
29 |
copyright
|
|
30 |
"
|
|
31 |
COPYRIGHT (c) 1992 by Claus Gittinger
|
|
32 |
All Rights Reserved
|
19
|
33 |
|
45
|
34 |
This software is furnished under a license and may be used
|
|
35 |
only in accordance with the terms of that license and with the
|
|
36 |
inclusion of the above copyright notice. This software may not
|
|
37 |
be provided or otherwise made available to, or used by, any
|
|
38 |
other person. No title to or ownership of the software is
|
|
39 |
hereby transferred.
|
|
40 |
"
|
|
41 |
!
|
19
|
42 |
|
45
|
43 |
version
|
|
44 |
"
|
49
|
45 |
$Header: /cvs/stx/stx/libtool/MemoryUsageView.st,v 1.3 1994-10-28 03:30:32 claus Exp $
|
45
|
46 |
"
|
|
47 |
!
|
19
|
48 |
|
45
|
49 |
documentation
|
|
50 |
"
|
|
51 |
this view shows an overview over the memory usage of the system.
|
|
52 |
usage:
|
|
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.
|
|
58 |
"
|
19
|
59 |
! !
|
|
60 |
|
|
61 |
!MemoryUsageView methodsFor:'menu actions'!
|
|
62 |
|
|
63 |
sortByClass
|
|
64 |
self label:'Memory usage; by class'.
|
|
65 |
sortBlock := [:a :b | (a at:1) name < (b at:1) name].
|
|
66 |
self updateDisplay
|
|
67 |
!
|
|
68 |
|
|
69 |
sortByInstCount
|
|
70 |
self label:'Memory usage; by instance count'.
|
|
71 |
sortBlock := [:a :b | (a at:2) > (b at:2) ].
|
|
72 |
self updateDisplay
|
|
73 |
!
|
|
74 |
|
|
75 |
sortByMemoryUsage
|
|
76 |
self label:'Memory usage; by memory usage'.
|
|
77 |
sortBlock := [:a :b | (a at:3) > (b at:3)].
|
|
78 |
self updateDisplay
|
|
79 |
!
|
|
80 |
|
45
|
81 |
inspectInstances
|
|
82 |
|line className class|
|
|
83 |
|
|
84 |
line := list selectionValue.
|
|
85 |
(line notNil and:[line notEmpty]) ifTrue:[
|
|
86 |
className := line asCollectionOfWords first.
|
|
87 |
"
|
|
88 |
special kludge
|
|
89 |
"
|
|
90 |
(className startsWith:'<') ifFalse:[
|
|
91 |
(className startsWith:'all') ifFalse:[
|
|
92 |
class := Smalltalk at:className asSymbol.
|
|
93 |
class allInstances inspect
|
|
94 |
]
|
|
95 |
]
|
|
96 |
]
|
|
97 |
!
|
|
98 |
|
19
|
99 |
update
|
|
100 |
self updateInfo.
|
|
101 |
self updateDisplay
|
|
102 |
! !
|
|
103 |
|
45
|
104 |
!MemoryUsageView methodsFor:'realization'!
|
|
105 |
|
|
106 |
realize
|
|
107 |
super realize.
|
|
108 |
self updateInfo.
|
|
109 |
self sortByClass.
|
|
110 |
! !
|
|
111 |
|
19
|
112 |
!MemoryUsageView methodsFor:'private'!
|
|
113 |
|
45
|
114 |
updateDisplay
|
|
115 |
"update the displayed list"
|
19
|
116 |
|
|
117 |
|classNames counts sumSizes percents avgSizes rawData l line allMemory overAllCount overAllAvgSize|
|
|
118 |
|
49
|
119 |
windowGroup withCursor:Cursor wait do:[
|
|
120 |
|
|
121 |
rawData := info asSortedCollection:sortBlock.
|
19
|
122 |
|
49
|
123 |
"/ "this avoids getting a sorted collection in the collect: below"
|
|
124 |
"/ rawData := rawData asArray.
|
19
|
125 |
|
49
|
126 |
classNames := rawData collect:[:i |
|
|
127 |
|cls|
|
19
|
128 |
|
49
|
129 |
cls := i at:1.
|
|
130 |
cls == Class ifTrue:[
|
|
131 |
'<all classes>'
|
45
|
132 |
] ifFalse:[
|
49
|
133 |
cls == Metaclass ifTrue:[
|
|
134 |
'<all metaclasses>'
|
|
135 |
] ifFalse:[
|
|
136 |
cls displayString "/name
|
|
137 |
]
|
45
|
138 |
]
|
49
|
139 |
].
|
19
|
140 |
|
49
|
141 |
counts := rawData collect:[:i | (i at:2) ].
|
|
142 |
sumSizes := rawData collect:[:i | (i at:3) ].
|
|
143 |
allMemory := ObjectMemory bytesUsed.
|
|
144 |
percents := sumSizes collect:[:sz | (sz / allMemory * 100 * 10) rounded / 10.0].
|
|
145 |
avgSizes := (1 to:sumSizes size) collect:[:i | (((sumSizes at:i) / (counts at:i)) * 10) rounded / 10.0].
|
19
|
146 |
|
49
|
147 |
l := OrderedCollection new.
|
|
148 |
1 to:classNames size do:[:i |
|
|
149 |
line := (classNames at:i) printStringPaddedTo:30 with:Character space.
|
|
150 |
line := line , ((counts at:i) printStringLeftPaddedTo:10).
|
|
151 |
line := line , ((avgSizes at:i) printStringLeftPaddedTo:10).
|
|
152 |
line := line , ((sumSizes at:i) printStringLeftPaddedTo:10).
|
|
153 |
line := line , ((percents at:i) printStringLeftPaddedTo:7).
|
|
154 |
l add:line
|
|
155 |
].
|
19
|
156 |
|
49
|
157 |
"add summary line"
|
|
158 |
overAllCount := counts inject:0 into:[:sum :this | sum + this].
|
|
159 |
overAllAvgSize := ((allMemory / overAllCount) * 10) rounded / 10.0.
|
19
|
160 |
|
49
|
161 |
l add:''.
|
|
162 |
line := 'all objects' printStringPaddedTo:30 with:Character space.
|
|
163 |
line := line , (overAllCount printStringLeftPaddedTo:10).
|
|
164 |
line := line , (overAllAvgSize printStringLeftPaddedTo:10).
|
|
165 |
line := line , (allMemory printStringLeftPaddedTo:10).
|
|
166 |
line := line , (100.0 printStringLeftPaddedTo:7).
|
|
167 |
l add:line.
|
19
|
168 |
|
49
|
169 |
list list:l.
|
|
170 |
]
|
45
|
171 |
!
|
19
|
172 |
|
45
|
173 |
updateInfo
|
|
174 |
"scan all memory and collect the information"
|
|
175 |
|
|
176 |
|myProcess myPriority|
|
|
177 |
|
49
|
178 |
windowGroup withCursor:Cursor questionMark do:[
|
45
|
179 |
|
|
180 |
info := IdentityDictionary new:600.
|
|
181 |
|
|
182 |
"find all objects, collect stuff in info"
|
|
183 |
|
|
184 |
"
|
|
185 |
this is a time consuming operation; therefore lower my priority ...
|
|
186 |
"
|
|
187 |
myProcess := Processor activeProcess.
|
|
188 |
myPriority := myProcess priority.
|
|
189 |
myProcess priority:(Processor userBackgroundPriority).
|
|
190 |
|
|
191 |
[
|
|
192 |
ObjectMemory allObjectsDo:[:o |
|
|
193 |
|i class|
|
|
194 |
|
|
195 |
o isBehavior ifTrue:[
|
|
196 |
o isMeta ifTrue:[
|
|
197 |
class := Metaclass
|
|
198 |
] ifFalse:[
|
|
199 |
class := Class
|
|
200 |
]
|
|
201 |
] ifFalse:[
|
|
202 |
class := o class.
|
|
203 |
].
|
|
204 |
(info includesKey:class) ifFalse:[
|
|
205 |
info at:class put:(Array with:class
|
|
206 |
with:1
|
|
207 |
with:(ObjectMemory sizeOf:o))
|
|
208 |
] ifTrue:[
|
|
209 |
i := info at:class.
|
|
210 |
i at:2 put:((i at:2) + 1).
|
|
211 |
i at:3 put:((i at:3) + (ObjectMemory sizeOf:o))
|
|
212 |
]
|
|
213 |
].
|
|
214 |
] valueNowOrOnUnwindDo:[
|
|
215 |
myProcess priority:myPriority.
|
|
216 |
].
|
|
217 |
]
|
19
|
218 |
! !
|
45
|
219 |
|
|
220 |
!MemoryUsageView methodsFor:'initialization'!
|
|
221 |
|
|
222 |
initialize
|
|
223 |
|l helpView headLine|
|
|
224 |
|
|
225 |
super initialize.
|
|
226 |
self label:'Memory usage'.
|
|
227 |
|
|
228 |
headLine := ' class # of insts avg sz bytes %mem '.
|
|
229 |
|
|
230 |
l := Label in:self.
|
|
231 |
l origin:(0.0 @ 0.0) corner:(1.0 @ l height).
|
|
232 |
l borderWidth:0.
|
|
233 |
l label:headLine.
|
|
234 |
l adjust:#left.
|
|
235 |
|
|
236 |
self extent:((font widthOf:headLine) + (device horizontalPixelPerMillimeter * 15) rounded) @ self height.
|
|
237 |
|
|
238 |
helpView := ScrollableView for:SelectionInListView in:self.
|
|
239 |
helpView origin:(0.0 @ l height) corner:1.0 @ 1.0.
|
|
240 |
|
|
241 |
l origin:(helpView scrollBar width @ 0.0).
|
|
242 |
|
|
243 |
list := helpView scrolledView.
|
|
244 |
list font:(self font).
|
|
245 |
list middleButtonMenu:(PopUpMenu
|
|
246 |
labels:(
|
|
247 |
resources array:#(
|
|
248 |
'sort by class'
|
|
249 |
'sort by inst count'
|
|
250 |
'sort by memory usage'
|
|
251 |
'-'
|
|
252 |
'inspect instances'
|
|
253 |
'-'
|
|
254 |
'update'
|
|
255 |
))
|
|
256 |
|
|
257 |
selectors:#(sortByClass
|
|
258 |
sortByInstCount
|
|
259 |
sortByMemoryUsage
|
|
260 |
nil
|
|
261 |
inspectInstances
|
|
262 |
nil
|
|
263 |
update
|
|
264 |
)
|
|
265 |
receiver:self
|
|
266 |
for:list).
|
|
267 |
|
|
268 |
"MemoryUsageView start"
|
|
269 |
! !
|
|
270 |
|