52
|
1 |
"
|
|
2 |
COPYRIGHT (c) 1993 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 |
|
19
|
13 |
StandardSystemView subclass:#ProcessMonitor
|
45
|
14 |
instanceVariableNames:'listView processes listUpdateDelay updateDelay
|
|
15 |
updateBlock listUpdateBlock updateProcess hideDead
|
56
|
16 |
runColor suspendedColor waitColor cpuUsages'
|
45
|
17 |
classVariableNames:''
|
|
18 |
poolDictionaries:''
|
|
19 |
category:'Interface-Tools'
|
19
|
20 |
!
|
|
21 |
|
52
|
22 |
!ProcessMonitor class methodsFor:'documentation'!
|
|
23 |
|
|
24 |
copyright
|
|
25 |
"
|
|
26 |
COPYRIGHT (c) 1993 by Claus Gittinger
|
|
27 |
All Rights Reserved
|
|
28 |
|
|
29 |
This software is furnished under a license and may be used
|
|
30 |
only in accordance with the terms of that license and with the
|
|
31 |
inclusion of the above copyright notice. This software may not
|
|
32 |
be provided or otherwise made available to, or used by, any
|
|
33 |
other person. No title to or ownership of the software is
|
|
34 |
hereby transferred.
|
|
35 |
"
|
|
36 |
!
|
|
37 |
|
|
38 |
version
|
|
39 |
"
|
57
|
40 |
$Header: /cvs/stx/stx/libtool/ProcessMonitor.st,v 1.6 1995-02-06 01:00:14 claus Exp $
|
52
|
41 |
"
|
|
42 |
!
|
|
43 |
|
|
44 |
documentation
|
|
45 |
"
|
|
46 |
This view shows smalltalks (light-weight) processes, and also offers
|
|
47 |
a popup menu for various useful operations on them.
|
|
48 |
Especially 'debug' is useful, to see what a process is currently
|
|
49 |
doing.
|
|
50 |
The information shown is:
|
|
51 |
id - the numeric id of the process
|
|
52 |
name - the name (if any) of the process
|
|
53 |
(the name has no semantic meaning; its for the processMonitor)
|
|
54 |
state - what is it doing;
|
|
55 |
wait - waiting on a semaphore
|
|
56 |
eventWait - waiting on a view-event semaphore
|
|
57 |
ioWait - waiting on an io-semaphore
|
|
58 |
timeWait - waiting for a time-semaphore
|
|
59 |
run - run, but currently not scheduled
|
|
60 |
active - really running
|
|
61 |
suspended - suspended; not waiting on a semaphore
|
|
62 |
light - not yet started (i.e. has no stack yet)
|
|
63 |
|
|
64 |
prio - the processes priority (1..30)
|
|
65 |
usedStack - the current stack use
|
|
66 |
totalStack - the stack currently allocated
|
|
67 |
"
|
|
68 |
! !
|
|
69 |
|
56
|
70 |
!ProcessMonitor class methodsFor:'defaults'!
|
19
|
71 |
|
56
|
72 |
defaultLabel
|
|
73 |
^ 'Process Monitor'
|
|
74 |
!
|
19
|
75 |
|
56
|
76 |
defaultIcon
|
|
77 |
|i|
|
19
|
78 |
|
56
|
79 |
i := Image fromFile:'bitmaps/ProcMon.xbm'.
|
|
80 |
i notNil ifTrue:[^ i].
|
|
81 |
^ super defaultIcon
|
19
|
82 |
! !
|
|
83 |
|
|
84 |
!ProcessMonitor methodsFor:'initialization'!
|
|
85 |
|
|
86 |
initialize
|
45
|
87 |
|v menu|
|
19
|
88 |
|
|
89 |
super initialize.
|
|
90 |
|
45
|
91 |
hideDead := true.
|
|
92 |
|
|
93 |
self extent:(font widthOf:'name/id state prio usedStack maxStack')
|
|
94 |
+ 40 @
|
|
95 |
100.
|
19
|
96 |
|
|
97 |
v := ScrollableView for:SelectionInListView in:self.
|
|
98 |
v origin:0.0@0.0 corner:1.0@1.0.
|
|
99 |
listView := v scrolledView.
|
|
100 |
listView font:font.
|
45
|
101 |
menu := (PopUpMenu
|
|
102 |
labels:#(
|
|
103 |
"/ hideDead functionality no longer needed;
|
|
104 |
"/ since ProcSched knownProcesses only returns living ones
|
|
105 |
"/
|
|
106 |
"/ '\c hide dead'
|
|
107 |
"/ '-'
|
|
108 |
'inspect'
|
|
109 |
'debug'
|
|
110 |
'-'
|
|
111 |
'resume'
|
|
112 |
'suspend'
|
|
113 |
'terminate'
|
|
114 |
'-'
|
|
115 |
'raise prio'
|
|
116 |
'lower prio'
|
|
117 |
)
|
|
118 |
selectors:#(
|
|
119 |
"/ hideDead:
|
|
120 |
"/ nil
|
|
121 |
inspectProcess
|
|
122 |
debugProcess
|
|
123 |
nil
|
|
124 |
resumeProcess
|
|
125 |
suspendProcess
|
|
126 |
terminateProcess
|
|
127 |
nil
|
|
128 |
raisePrio
|
|
129 |
lowerPrio
|
|
130 |
)
|
|
131 |
receiver:self
|
|
132 |
for:listView).
|
|
133 |
"/ menu checkToggleAt:#hideDead: put:hideDead.
|
|
134 |
listView middleButtonMenu:menu.
|
|
135 |
|
19
|
136 |
listView multipleSelectOk:true.
|
|
137 |
listView keyboardHandler:self.
|
|
138 |
|
|
139 |
updateDelay := 0.5.
|
|
140 |
listUpdateDelay := 5.
|
45
|
141 |
|
|
142 |
"/ true
|
|
143 |
ProcessorScheduler isPureEventDriven
|
|
144 |
ifTrue:[
|
|
145 |
updateBlock := [self updateStatus].
|
|
146 |
listUpdateBlock := [self updateList].
|
19
|
147 |
].
|
45
|
148 |
|
19
|
149 |
device hasColors ifTrue:[
|
45
|
150 |
runColor := Color green.
|
|
151 |
suspendedColor := Color yellow.
|
|
152 |
waitColor := Color red.
|
19
|
153 |
] ifFalse:[
|
45
|
154 |
runColor := suspendedColor := waitColor := Color black
|
19
|
155 |
]
|
|
156 |
|
45
|
157 |
"
|
|
158 |
ProcessMonitor open
|
|
159 |
"
|
19
|
160 |
!
|
|
161 |
|
|
162 |
realize
|
|
163 |
super realize.
|
45
|
164 |
|
19
|
165 |
updateBlock notNil ifTrue:[
|
45
|
166 |
Processor addTimedBlock:updateBlock afterSeconds:updateDelay.
|
|
167 |
Processor addTimedBlock:listUpdateBlock afterSeconds:listUpdateDelay.
|
19
|
168 |
] ifFalse:[
|
45
|
169 |
updateProcess := [
|
56
|
170 |
|id cnt|
|
|
171 |
|
45
|
172 |
"
|
56
|
173 |
every 20ms, we look which process runs;
|
45
|
174 |
every half second, the status is updated.
|
|
175 |
every 5 seconds, the list of processes is
|
|
176 |
built up again
|
|
177 |
"
|
|
178 |
[true] whileTrue:[
|
|
179 |
1 to:9 do:[:i |
|
56
|
180 |
"/ cpuUsages := IdentityDictionary new.
|
|
181 |
"/ 1 to:25 do:[:i |
|
|
182 |
"/ (Delay forSeconds:0.02) wait.
|
|
183 |
"/ id := Processor interruptedProcess id.
|
|
184 |
"/ cnt := cpuUsages at:id ifAbsent:[0].
|
|
185 |
"/ cpuUsages at:id put:cnt + 1.
|
|
186 |
"/ ].
|
45
|
187 |
(Delay forSeconds:0.5) wait.
|
|
188 |
self updateStatus.
|
|
189 |
].
|
|
190 |
(Delay forSeconds:0.5) wait.
|
|
191 |
self updateList.
|
|
192 |
]
|
|
193 |
] forkAt:(Processor userSchedulingPriority + 1).
|
|
194 |
updateProcess name:'process update'.
|
|
195 |
"
|
|
196 |
raise my own priority
|
|
197 |
"
|
|
198 |
Processor activeProcess priority:(Processor userSchedulingPriority + 2)
|
19
|
199 |
].
|
45
|
200 |
waitColor := waitColor on:device.
|
|
201 |
runColor := runColor on:device.
|
19
|
202 |
suspendedColor := suspendedColor on:device.
|
45
|
203 |
!
|
|
204 |
|
|
205 |
mapped
|
|
206 |
super mapped.
|
|
207 |
self updateStatus.
|
|
208 |
self updateList.
|
19
|
209 |
! !
|
|
210 |
|
|
211 |
!ProcessMonitor methodsFor:'destroying'!
|
|
212 |
|
|
213 |
destroy
|
|
214 |
updateBlock notNil ifTrue:[
|
45
|
215 |
Processor removeTimedBlock:updateBlock.
|
|
216 |
Processor removeTimedBlock:listUpdateBlock.
|
19
|
217 |
] ifFalse:[
|
45
|
218 |
updateProcess terminate
|
19
|
219 |
].
|
|
220 |
super destroy
|
|
221 |
! !
|
|
222 |
|
45
|
223 |
!ProcessMonitor methodsFor:'private'!
|
|
224 |
|
|
225 |
selectedProcessesDo:aBlock
|
|
226 |
|p nr sel|
|
|
227 |
|
|
228 |
sel := listView selection.
|
|
229 |
sel isNil ifTrue:[^ self].
|
|
230 |
(sel isKindOf:Collection) ifTrue:[
|
|
231 |
sel do:[:n |
|
|
232 |
nr := n - 2. "for headlines"
|
|
233 |
nr notNil ifTrue:[
|
|
234 |
nr > 0 ifTrue:[
|
|
235 |
p := processes at:nr.
|
|
236 |
p notNil ifTrue:[
|
|
237 |
aBlock value:p
|
|
238 |
]
|
|
239 |
]
|
|
240 |
]
|
|
241 |
]
|
|
242 |
] ifFalse:[
|
|
243 |
nr := sel - 2. "for headlines"
|
|
244 |
nr notNil ifTrue:[
|
|
245 |
nr > 0 ifTrue:[
|
|
246 |
p := processes at:nr.
|
|
247 |
p notNil ifTrue:[
|
|
248 |
aBlock value:p
|
|
249 |
]
|
|
250 |
]
|
|
251 |
]
|
|
252 |
].
|
57
|
253 |
"/ self updateStatus.
|
|
254 |
"/ self updateList.
|
45
|
255 |
! !
|
|
256 |
|
19
|
257 |
!ProcessMonitor methodsFor:'menu actions'!
|
|
258 |
|
45
|
259 |
hideDead:aBoolean
|
|
260 |
hideDead := aBoolean
|
19
|
261 |
!
|
|
262 |
|
|
263 |
debugProcess
|
|
264 |
self selectedProcessesDo:[:p |
|
|
265 |
Debugger openOn:p
|
|
266 |
]
|
|
267 |
!
|
|
268 |
|
|
269 |
inspectProcess
|
|
270 |
self selectedProcessesDo:[:p |
|
|
271 |
p inspect
|
|
272 |
]
|
|
273 |
!
|
|
274 |
|
|
275 |
terminateProcess
|
|
276 |
self selectedProcessesDo:[:p |
|
|
277 |
p terminate
|
|
278 |
]
|
|
279 |
!
|
|
280 |
|
|
281 |
resumeProcess
|
|
282 |
self selectedProcessesDo:[:p |
|
|
283 |
p resume
|
|
284 |
]
|
|
285 |
!
|
|
286 |
|
|
287 |
suspendProcess
|
|
288 |
self selectedProcessesDo:[:p |
|
|
289 |
p suspend
|
|
290 |
]
|
45
|
291 |
!
|
|
292 |
|
|
293 |
raisePrio
|
|
294 |
self selectedProcessesDo:[:p |
|
|
295 |
p priority:(p priority + 1)
|
|
296 |
]
|
|
297 |
!
|
|
298 |
|
|
299 |
lowerPrio
|
|
300 |
self selectedProcessesDo:[:p |
|
|
301 |
p priority:(p priority - 1)
|
|
302 |
]
|
19
|
303 |
! !
|
|
304 |
|
|
305 |
!ProcessMonitor methodsFor:'events'!
|
|
306 |
|
|
307 |
canHandle:key
|
|
308 |
^ key == #InspectIt
|
|
309 |
!
|
|
310 |
|
|
311 |
keyPress:key x:x y:y
|
|
312 |
key == #InspectIt ifTrue:[
|
45
|
313 |
^ self inspectProcess.
|
19
|
314 |
].
|
|
315 |
^ super keyPress:key x:x y:y
|
|
316 |
! !
|
|
317 |
|
|
318 |
!ProcessMonitor methodsFor:'drawing'!
|
|
319 |
|
|
320 |
updateList
|
|
321 |
"update list of processes"
|
|
322 |
|
|
323 |
|newList|
|
|
324 |
|
45
|
325 |
shown ifTrue:[
|
|
326 |
(Smalltalk at:#SystemDebugging ifAbsent:[false]) ifTrue:[
|
|
327 |
newList := Process allInstances.
|
|
328 |
] ifFalse:[
|
|
329 |
newList := ProcessorScheduler knownProcesses asOrderedCollection.
|
|
330 |
].
|
|
331 |
|
|
332 |
"sort by id - take care of nil ids of dead processes"
|
|
333 |
newList sort:[:p1 :p2 |
|
|
334 |
|id1 id2|
|
19
|
335 |
|
45
|
336 |
(p1 isNil or:[(id1 := p1 id) isNil])
|
|
337 |
ifTrue:[true]
|
|
338 |
ifFalse:[
|
|
339 |
(p2 isNil or:[(id2 := p2 id) isNil])
|
|
340 |
ifTrue:[false]
|
|
341 |
ifFalse:[id1 < id2]
|
|
342 |
]
|
|
343 |
].
|
|
344 |
newList ~= processes ifTrue:[
|
|
345 |
processes := WeakArray withAll:newList.
|
|
346 |
self updateStatus
|
|
347 |
].
|
19
|
348 |
].
|
|
349 |
updateBlock notNil ifTrue:[
|
45
|
350 |
Processor addTimedBlock:listUpdateBlock afterSeconds:listUpdateDelay
|
19
|
351 |
].
|
|
352 |
!
|
|
353 |
|
|
354 |
updateStatus
|
|
355 |
"update status display of processes"
|
|
356 |
|
49
|
357 |
|oldList list line dIndex con interrupted|
|
19
|
358 |
|
45
|
359 |
shown ifTrue:[
|
|
360 |
oldList := listView list.
|
|
361 |
processes notNil ifTrue:[
|
|
362 |
list := OrderedCollection new.
|
56
|
363 |
"/ list add:'id name cpu state prio usedStack totalStack'.
|
|
364 |
list add:'id name state prio usedStack totalStack'.
|
|
365 |
list add:'--------------------------------------------------------------------------'.
|
49
|
366 |
|
|
367 |
interrupted := Processor interruptedProcess.
|
19
|
368 |
|
45
|
369 |
dIndex := 1.
|
|
370 |
1 to:processes size do:[:index |
|
56
|
371 |
|aProcess nm st c n|
|
19
|
372 |
|
45
|
373 |
aProcess := processes at:index.
|
|
374 |
aProcess notNil ifTrue:[
|
|
375 |
(aProcess id notNil or:[hideDead not]) ifTrue:[
|
|
376 |
line := aProcess id printStringPaddedTo:5.
|
|
377 |
(nm := aProcess name) isNil ifFalse:[
|
|
378 |
nm := nm printString
|
|
379 |
] ifTrue:[
|
|
380 |
nm := ' '
|
|
381 |
].
|
52
|
382 |
nm size >= 29 ifTrue:[
|
|
383 |
nm := (nm contractTo:28) , ' '
|
45
|
384 |
] ifFalse:[
|
52
|
385 |
nm := (nm printStringPaddedTo:29).
|
45
|
386 |
].
|
|
387 |
line := line , nm.
|
56
|
388 |
"/ n := cpuUsages at:(aProcess id) ifAbsent:[0].
|
|
389 |
"/ n ~~ 0 ifTrue:[
|
|
390 |
"/ line := line , ((n * 4) printStringLeftPaddedTo:3)
|
|
391 |
"/ ] ifFalse:[
|
|
392 |
"/ line := line , ' '
|
|
393 |
"/ ].
|
49
|
394 |
st := aProcess state.
|
|
395 |
(st == #run
|
|
396 |
and:[aProcess == interrupted]) ifTrue:[
|
56
|
397 |
c := ' *'.
|
49
|
398 |
] ifFalse:[
|
56
|
399 |
c := ' '.
|
49
|
400 |
].
|
56
|
401 |
line := line , c , (st printStringPaddedTo:9).
|
45
|
402 |
line := line , (aProcess priority printStringLeftPaddedTo:3).
|
|
403 |
line := line , (aProcess usedStackSize printStringLeftPaddedTo:11).
|
|
404 |
line := line , (aProcess totalStackSize printStringLeftPaddedTo:10).
|
49
|
405 |
line := line , '(' , aProcess numberOfStackSegments printString , ')'.
|
45
|
406 |
(Smalltalk at:#SystemDebugging ifAbsent:[false]) ifTrue:[
|
|
407 |
con := aProcess suspendedContext.
|
|
408 |
con isNil ifTrue:[
|
|
409 |
aProcess == Processor activeProcess ifTrue:[
|
|
410 |
con := thisContext
|
|
411 |
]
|
|
412 |
].
|
|
413 |
con notNil ifTrue:[
|
|
414 |
line := line , ' '.
|
|
415 |
line := line , ((ObjectMemory addressOf:con) printStringRadix:16).
|
|
416 |
line := line , ' .. '.
|
|
417 |
[con sender notNil] whileTrue:[
|
|
418 |
con := con sender
|
|
419 |
].
|
|
420 |
line := line , ((ObjectMemory addressOf:con) printStringRadix:16).
|
|
421 |
]
|
|
422 |
].
|
|
423 |
list add:line.
|
|
424 |
processes at:dIndex put:aProcess.
|
|
425 |
dIndex := dIndex + 1
|
|
426 |
]
|
|
427 |
].
|
|
428 |
].
|
|
429 |
dIndex to:processes size do:[:index |
|
|
430 |
processes at:index put:nil
|
|
431 |
]
|
|
432 |
].
|
|
433 |
list ~= oldList ifTrue:[
|
|
434 |
"avoid flicker"
|
57
|
435 |
(oldList notNil and:[oldList size == list size]) ifTrue:[
|
45
|
436 |
list keysAndValuesDo:[:idx :entry |
|
|
437 |
(oldList at:idx) ~= entry ifTrue:[
|
|
438 |
listView at:idx put:entry
|
|
439 |
]
|
|
440 |
]
|
|
441 |
] ifFalse:[
|
|
442 |
listView setList:list.
|
49
|
443 |
"the first two entries cannot be selected"
|
|
444 |
listView attributeAt:1 put:#disabled.
|
|
445 |
listView attributeAt:2 put:#disabled.
|
45
|
446 |
]
|
|
447 |
].
|
19
|
448 |
].
|
|
449 |
updateBlock notNil ifTrue:[
|
45
|
450 |
Processor addTimedBlock:updateBlock afterSeconds:updateDelay
|
19
|
451 |
]
|
|
452 |
! !
|