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