19
|
1 |
StandardSystemView subclass:#ProcessMonitor
|
45
|
2 |
instanceVariableNames:'listView processes listUpdateDelay updateDelay
|
|
3 |
updateBlock listUpdateBlock updateProcess hideDead
|
|
4 |
runColor suspendedColor waitColor'
|
|
5 |
classVariableNames:''
|
|
6 |
poolDictionaries:''
|
|
7 |
category:'Interface-Tools'
|
19
|
8 |
!
|
|
9 |
|
|
10 |
!ProcessMonitor class methodsFor:'startup'!
|
|
11 |
|
45
|
12 |
open
|
19
|
13 |
|m|
|
|
14 |
|
|
15 |
m := self new.
|
|
16 |
m label:'Process Monitor'.
|
|
17 |
m icon:(Form fromFile:'PMonitor.icon' resolution:100).
|
|
18 |
m minExtent:(100 @ 100).
|
|
19 |
|
|
20 |
m open.
|
|
21 |
^ m
|
|
22 |
|
45
|
23 |
"
|
|
24 |
ProcessMonitor open
|
|
25 |
"
|
19
|
26 |
! !
|
|
27 |
|
|
28 |
!ProcessMonitor methodsFor:'initialization'!
|
|
29 |
|
|
30 |
initialize
|
45
|
31 |
|v menu|
|
19
|
32 |
|
|
33 |
super initialize.
|
|
34 |
|
45
|
35 |
hideDead := true.
|
|
36 |
|
|
37 |
self extent:(font widthOf:'name/id state prio usedStack maxStack')
|
|
38 |
+ 40 @
|
|
39 |
100.
|
19
|
40 |
|
|
41 |
v := ScrollableView for:SelectionInListView in:self.
|
|
42 |
v origin:0.0@0.0 corner:1.0@1.0.
|
|
43 |
listView := v scrolledView.
|
|
44 |
listView font:font.
|
45
|
45 |
menu := (PopUpMenu
|
|
46 |
labels:#(
|
|
47 |
"/ hideDead functionality no longer needed;
|
|
48 |
"/ since ProcSched knownProcesses only returns living ones
|
|
49 |
"/
|
|
50 |
"/ '\c hide dead'
|
|
51 |
"/ '-'
|
|
52 |
'inspect'
|
|
53 |
'debug'
|
|
54 |
'-'
|
|
55 |
'resume'
|
|
56 |
'suspend'
|
|
57 |
'terminate'
|
|
58 |
'-'
|
|
59 |
'raise prio'
|
|
60 |
'lower prio'
|
|
61 |
)
|
|
62 |
selectors:#(
|
|
63 |
"/ hideDead:
|
|
64 |
"/ nil
|
|
65 |
inspectProcess
|
|
66 |
debugProcess
|
|
67 |
nil
|
|
68 |
resumeProcess
|
|
69 |
suspendProcess
|
|
70 |
terminateProcess
|
|
71 |
nil
|
|
72 |
raisePrio
|
|
73 |
lowerPrio
|
|
74 |
)
|
|
75 |
receiver:self
|
|
76 |
for:listView).
|
|
77 |
"/ menu checkToggleAt:#hideDead: put:hideDead.
|
|
78 |
listView middleButtonMenu:menu.
|
|
79 |
|
19
|
80 |
listView multipleSelectOk:true.
|
|
81 |
listView keyboardHandler:self.
|
|
82 |
|
|
83 |
updateDelay := 0.5.
|
|
84 |
listUpdateDelay := 5.
|
45
|
85 |
|
|
86 |
"/ true
|
|
87 |
ProcessorScheduler isPureEventDriven
|
|
88 |
ifTrue:[
|
|
89 |
updateBlock := [self updateStatus].
|
|
90 |
listUpdateBlock := [self updateList].
|
19
|
91 |
].
|
45
|
92 |
|
19
|
93 |
device hasColors ifTrue:[
|
45
|
94 |
runColor := Color green.
|
|
95 |
suspendedColor := Color yellow.
|
|
96 |
waitColor := Color red.
|
19
|
97 |
] ifFalse:[
|
45
|
98 |
runColor := suspendedColor := waitColor := Color black
|
19
|
99 |
]
|
|
100 |
|
45
|
101 |
"
|
|
102 |
ProcessMonitor open
|
|
103 |
"
|
19
|
104 |
!
|
|
105 |
|
|
106 |
realize
|
|
107 |
super realize.
|
45
|
108 |
|
19
|
109 |
updateBlock notNil ifTrue:[
|
45
|
110 |
Processor addTimedBlock:updateBlock afterSeconds:updateDelay.
|
|
111 |
Processor addTimedBlock:listUpdateBlock afterSeconds:listUpdateDelay.
|
19
|
112 |
] ifFalse:[
|
45
|
113 |
updateProcess := [
|
|
114 |
"
|
|
115 |
every half second, the status is updated.
|
|
116 |
every 5 seconds, the list of processes is
|
|
117 |
built up again
|
|
118 |
"
|
|
119 |
[true] whileTrue:[
|
|
120 |
1 to:9 do:[:i |
|
|
121 |
(Delay forSeconds:0.5) wait.
|
|
122 |
self updateStatus.
|
|
123 |
].
|
|
124 |
(Delay forSeconds:0.5) wait.
|
|
125 |
self updateList.
|
|
126 |
]
|
|
127 |
] forkAt:(Processor userSchedulingPriority + 1).
|
|
128 |
updateProcess name:'process update'.
|
|
129 |
"
|
|
130 |
raise my own priority
|
|
131 |
"
|
|
132 |
Processor activeProcess priority:(Processor userSchedulingPriority + 2)
|
19
|
133 |
].
|
45
|
134 |
waitColor := waitColor on:device.
|
|
135 |
runColor := runColor on:device.
|
19
|
136 |
suspendedColor := suspendedColor on:device.
|
45
|
137 |
!
|
|
138 |
|
|
139 |
mapped
|
|
140 |
super mapped.
|
|
141 |
self updateStatus.
|
|
142 |
self updateList.
|
19
|
143 |
! !
|
|
144 |
|
|
145 |
!ProcessMonitor methodsFor:'destroying'!
|
|
146 |
|
|
147 |
destroy
|
|
148 |
updateBlock notNil ifTrue:[
|
45
|
149 |
Processor removeTimedBlock:updateBlock.
|
|
150 |
Processor removeTimedBlock:listUpdateBlock.
|
19
|
151 |
] ifFalse:[
|
45
|
152 |
updateProcess terminate
|
19
|
153 |
].
|
|
154 |
super destroy
|
|
155 |
! !
|
|
156 |
|
45
|
157 |
!ProcessMonitor methodsFor:'private'!
|
|
158 |
|
|
159 |
selectedProcessesDo:aBlock
|
|
160 |
|p nr sel|
|
|
161 |
|
|
162 |
sel := listView selection.
|
|
163 |
sel isNil ifTrue:[^ self].
|
|
164 |
(sel isKindOf:Collection) ifTrue:[
|
|
165 |
sel do:[:n |
|
|
166 |
nr := n - 2. "for headlines"
|
|
167 |
nr notNil ifTrue:[
|
|
168 |
nr > 0 ifTrue:[
|
|
169 |
p := processes at:nr.
|
|
170 |
p notNil ifTrue:[
|
|
171 |
aBlock value:p
|
|
172 |
]
|
|
173 |
]
|
|
174 |
]
|
|
175 |
]
|
|
176 |
] ifFalse:[
|
|
177 |
nr := sel - 2. "for headlines"
|
|
178 |
nr notNil ifTrue:[
|
|
179 |
nr > 0 ifTrue:[
|
|
180 |
p := processes at:nr.
|
|
181 |
p notNil ifTrue:[
|
|
182 |
aBlock value:p
|
|
183 |
]
|
|
184 |
]
|
|
185 |
]
|
|
186 |
].
|
|
187 |
! !
|
|
188 |
|
19
|
189 |
!ProcessMonitor methodsFor:'menu actions'!
|
|
190 |
|
45
|
191 |
hideDead:aBoolean
|
|
192 |
hideDead := aBoolean
|
19
|
193 |
!
|
|
194 |
|
|
195 |
debugProcess
|
|
196 |
self selectedProcessesDo:[:p |
|
|
197 |
Debugger openOn:p
|
|
198 |
]
|
|
199 |
!
|
|
200 |
|
|
201 |
inspectProcess
|
|
202 |
self selectedProcessesDo:[:p |
|
|
203 |
p inspect
|
|
204 |
]
|
|
205 |
!
|
|
206 |
|
|
207 |
terminateProcess
|
|
208 |
self selectedProcessesDo:[:p |
|
|
209 |
p terminate
|
|
210 |
]
|
|
211 |
!
|
|
212 |
|
|
213 |
resumeProcess
|
|
214 |
self selectedProcessesDo:[:p |
|
|
215 |
p resume
|
|
216 |
]
|
|
217 |
!
|
|
218 |
|
|
219 |
suspendProcess
|
|
220 |
self selectedProcessesDo:[:p |
|
|
221 |
p suspend
|
|
222 |
]
|
45
|
223 |
!
|
|
224 |
|
|
225 |
raisePrio
|
|
226 |
self selectedProcessesDo:[:p |
|
|
227 |
p priority:(p priority + 1)
|
|
228 |
]
|
|
229 |
!
|
|
230 |
|
|
231 |
lowerPrio
|
|
232 |
self selectedProcessesDo:[:p |
|
|
233 |
p priority:(p priority - 1)
|
|
234 |
]
|
19
|
235 |
! !
|
|
236 |
|
|
237 |
!ProcessMonitor methodsFor:'events'!
|
|
238 |
|
|
239 |
canHandle:key
|
|
240 |
^ key == #InspectIt
|
|
241 |
!
|
|
242 |
|
|
243 |
keyPress:key x:x y:y
|
|
244 |
key == #InspectIt ifTrue:[
|
45
|
245 |
^ self inspectProcess.
|
19
|
246 |
].
|
|
247 |
^ super keyPress:key x:x y:y
|
|
248 |
! !
|
|
249 |
|
|
250 |
!ProcessMonitor methodsFor:'drawing'!
|
|
251 |
|
|
252 |
updateList
|
|
253 |
"update list of processes"
|
|
254 |
|
|
255 |
|newList|
|
|
256 |
|
45
|
257 |
shown ifTrue:[
|
|
258 |
(Smalltalk at:#SystemDebugging ifAbsent:[false]) ifTrue:[
|
|
259 |
newList := Process allInstances.
|
|
260 |
] ifFalse:[
|
|
261 |
newList := ProcessorScheduler knownProcesses asOrderedCollection.
|
|
262 |
].
|
|
263 |
|
|
264 |
"sort by id - take care of nil ids of dead processes"
|
|
265 |
newList sort:[:p1 :p2 |
|
|
266 |
|id1 id2|
|
19
|
267 |
|
45
|
268 |
(p1 isNil or:[(id1 := p1 id) isNil])
|
|
269 |
ifTrue:[true]
|
|
270 |
ifFalse:[
|
|
271 |
(p2 isNil or:[(id2 := p2 id) isNil])
|
|
272 |
ifTrue:[false]
|
|
273 |
ifFalse:[id1 < id2]
|
|
274 |
]
|
|
275 |
].
|
|
276 |
newList ~= processes ifTrue:[
|
|
277 |
processes := WeakArray withAll:newList.
|
|
278 |
self updateStatus
|
|
279 |
].
|
19
|
280 |
].
|
|
281 |
updateBlock notNil ifTrue:[
|
45
|
282 |
Processor addTimedBlock:listUpdateBlock afterSeconds:listUpdateDelay
|
19
|
283 |
].
|
|
284 |
!
|
|
285 |
|
|
286 |
updateStatus
|
|
287 |
"update status display of processes"
|
|
288 |
|
49
|
289 |
|oldList list line dIndex con interrupted|
|
19
|
290 |
|
45
|
291 |
shown ifTrue:[
|
|
292 |
oldList := listView list.
|
|
293 |
processes notNil ifTrue:[
|
|
294 |
list := OrderedCollection new.
|
49
|
295 |
list add:'id name state prio usedStack totalStack'.
|
|
296 |
list add:'-------------------------------------------------------------------'.
|
|
297 |
|
|
298 |
interrupted := Processor interruptedProcess.
|
19
|
299 |
|
45
|
300 |
dIndex := 1.
|
|
301 |
1 to:processes size do:[:index |
|
49
|
302 |
|aProcess nm st|
|
19
|
303 |
|
45
|
304 |
aProcess := processes at:index.
|
|
305 |
aProcess notNil ifTrue:[
|
|
306 |
(aProcess id notNil or:[hideDead not]) ifTrue:[
|
|
307 |
line := aProcess id printStringPaddedTo:5.
|
|
308 |
(nm := aProcess name) isNil ifFalse:[
|
|
309 |
nm := nm printString
|
|
310 |
] ifTrue:[
|
|
311 |
nm := ' '
|
|
312 |
].
|
49
|
313 |
nm size >= 24 ifTrue:[
|
|
314 |
nm := (nm copyTo:23) , ' '
|
45
|
315 |
] ifFalse:[
|
49
|
316 |
nm := (nm printStringPaddedTo:24).
|
45
|
317 |
].
|
|
318 |
line := line , nm.
|
49
|
319 |
st := aProcess state.
|
|
320 |
(st == #run
|
|
321 |
and:[aProcess == interrupted]) ifTrue:[
|
|
322 |
line := line , '*' , (st printStringPaddedTo:9).
|
|
323 |
] ifFalse:[
|
|
324 |
line := line , ' ' , (st printStringPaddedTo:9).
|
|
325 |
].
|
45
|
326 |
line := line , (aProcess priority printStringLeftPaddedTo:3).
|
|
327 |
line := line , (aProcess usedStackSize printStringLeftPaddedTo:11).
|
|
328 |
line := line , (aProcess totalStackSize printStringLeftPaddedTo:10).
|
49
|
329 |
line := line , '(' , aProcess numberOfStackSegments printString , ')'.
|
45
|
330 |
(Smalltalk at:#SystemDebugging ifAbsent:[false]) ifTrue:[
|
|
331 |
con := aProcess suspendedContext.
|
|
332 |
con isNil ifTrue:[
|
|
333 |
aProcess == Processor activeProcess ifTrue:[
|
|
334 |
con := thisContext
|
|
335 |
]
|
|
336 |
].
|
|
337 |
con notNil ifTrue:[
|
|
338 |
line := line , ' '.
|
|
339 |
line := line , ((ObjectMemory addressOf:con) printStringRadix:16).
|
|
340 |
line := line , ' .. '.
|
|
341 |
[con sender notNil] whileTrue:[
|
|
342 |
con := con sender
|
|
343 |
].
|
|
344 |
line := line , ((ObjectMemory addressOf:con) printStringRadix:16).
|
|
345 |
]
|
|
346 |
].
|
|
347 |
list add:line.
|
|
348 |
processes at:dIndex put:aProcess.
|
|
349 |
dIndex := dIndex + 1
|
|
350 |
]
|
|
351 |
].
|
|
352 |
].
|
|
353 |
dIndex to:processes size do:[:index |
|
|
354 |
processes at:index put:nil
|
|
355 |
]
|
|
356 |
].
|
|
357 |
list ~= oldList ifTrue:[
|
|
358 |
"avoid flicker"
|
|
359 |
oldList size == list size ifTrue:[
|
|
360 |
list keysAndValuesDo:[:idx :entry |
|
|
361 |
(oldList at:idx) ~= entry ifTrue:[
|
|
362 |
listView at:idx put:entry
|
|
363 |
]
|
|
364 |
]
|
|
365 |
] ifFalse:[
|
|
366 |
listView setList:list.
|
49
|
367 |
"the first two entries cannot be selected"
|
|
368 |
listView attributeAt:1 put:#disabled.
|
|
369 |
listView attributeAt:2 put:#disabled.
|
45
|
370 |
]
|
|
371 |
].
|
19
|
372 |
].
|
|
373 |
updateBlock notNil ifTrue:[
|
45
|
374 |
Processor addTimedBlock:updateBlock afterSeconds:updateDelay
|
19
|
375 |
]
|
|
376 |
! !
|