author | Claus Gittinger <cg@exept.de> |
Sat, 27 Apr 1996 20:00:04 +0200 | |
changeset 517 | cc3d4e0fc758 |
parent 478 | b0b974490a51 |
child 619 | 62db60834422 |
permissions | -rw-r--r-- |
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 |
||
93 | 13 |
SimpleView subclass:#ProcessMonitor |
315
8a86faf847d1
create a new updateProcess when restarted
Claus Gittinger <cg@exept.de>
parents:
314
diff
changeset
|
14 |
instanceVariableNames:'listView processes listUpdateDelay updateDelay updateBlock |
8a86faf847d1
create a new updateProcess when restarted
Claus Gittinger <cg@exept.de>
parents:
314
diff
changeset
|
15 |
listUpdateBlock updateProcess hideDead runColor suspendedColor |
8a86faf847d1
create a new updateProcess when restarted
Claus Gittinger <cg@exept.de>
parents:
314
diff
changeset
|
16 |
waitColor cpuUsages showDetail' |
8a86faf847d1
create a new updateProcess when restarted
Claus Gittinger <cg@exept.de>
parents:
314
diff
changeset
|
17 |
classVariableNames:'' |
8a86faf847d1
create a new updateProcess when restarted
Claus Gittinger <cg@exept.de>
parents:
314
diff
changeset
|
18 |
poolDictionaries:'' |
8a86faf847d1
create a new updateProcess when restarted
Claus Gittinger <cg@exept.de>
parents:
314
diff
changeset
|
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 |
documentation |
|
39 |
" |
|
40 |
This view shows smalltalks (light-weight) processes, and also offers |
|
41 |
a popup menu for various useful operations on them. |
|
42 |
Especially 'debug' is useful, to see what a process is currently |
|
43 |
doing. |
|
85 | 44 |
|
52 | 45 |
The information shown is: |
90 | 46 |
id - the numeric id of the process |
47 |
name - the name (if any) of the process |
|
48 |
(the name has no semantic meaning; it exists for the processMonitor only) |
|
49 |
state - what is it doing; |
|
50 |
wait - waiting on a semaphore |
|
51 |
eventWait - waiting on a view-event semaphore |
|
52 |
ioWait - waiting on an io-semaphore |
|
53 |
timeWait - waiting for a time-semaphore |
|
54 |
run - run, but currently not scheduled |
|
55 |
active - really running (this info is useless, since at |
|
56 |
update time, its always the update process which is |
|
57 |
running) |
|
58 |
suspended - suspended; not waiting on a semaphore |
|
59 |
light - not yet started (i.e. has no stack yet) |
|
52 | 60 |
|
90 | 61 |
prio - the processes priority (1..30) |
62 |
usedStack - the current stack use |
|
63 |
totalStack - the stack currently allocated (i.e. the maximum ever needed) |
|
52 | 64 |
" |
65 |
! ! |
|
66 |
||
56 | 67 |
!ProcessMonitor class methodsFor:'defaults'! |
19 | 68 |
|
56 | 69 |
defaultIcon |
70 |
|i| |
|
19 | 71 |
|
93 | 72 |
i := Image fromFile:'ProcMon.xbm'. |
56 | 73 |
i notNil ifTrue:[^ i]. |
85 | 74 |
^ StandardSystemView defaultIcon |
208 | 75 |
! |
76 |
||
77 |
defaultLabel |
|
78 |
^ 'Process Monitor' |
|
85 | 79 |
! ! |
80 |
||
81 |
!ProcessMonitor class methodsFor:'startup'! |
|
82 |
||
83 |
open |
|
84 |
|top monitor| |
|
85 |
||
86 |
top := StandardSystemView new. |
|
87 |
monitor := self origin:0.0@0.0 corner:1.0@1.0 in:top. |
|
105 | 88 |
top extent:monitor preferredExtent. |
85 | 89 |
top label:self defaultLabel. |
90 |
top icon:self defaultIcon. |
|
91 |
top open |
|
92 |
||
93 |
" |
|
94 |
ProcessMonitor open |
|
95 |
" |
|
96 |
! ! |
|
97 |
||
143 | 98 |
!ProcessMonitor methodsFor:'destroying'! |
99 |
||
100 |
destroy |
|
101 |
updateBlock notNil ifTrue:[ |
|
102 |
Processor removeTimedBlock:updateBlock. |
|
103 |
Processor removeTimedBlock:listUpdateBlock. |
|
104 |
] ifFalse:[ |
|
105 |
updateProcess notNil ifTrue:[updateProcess terminate] |
|
106 |
]. |
|
107 |
super destroy |
|
108 |
! ! |
|
109 |
||
85 | 110 |
!ProcessMonitor methodsFor:'drawing'! |
111 |
||
112 |
titleLine |
|
109 | 113 |
showDetail ifTrue:[ |
143 | 114 |
^ 'id name state prio usedStack totalStack current-segment switches where'. |
109 | 115 |
]. |
143 | 116 |
^ 'id name state prio usedStack where'. |
85 | 117 |
! |
118 |
||
119 |
updateList |
|
120 |
"update list of processes" |
|
121 |
||
122 |
|newList| |
|
123 |
||
124 |
shown ifTrue:[ |
|
208 | 125 |
showDetail ifTrue:[ |
126 |
newList := Process allInstances asOrderedCollection. |
|
127 |
] ifFalse:[ |
|
128 |
newList := ProcessorScheduler knownProcesses asOrderedCollection. |
|
129 |
]. |
|
130 |
newList := newList select:[:p | p id notNil]. |
|
85 | 131 |
|
208 | 132 |
"sort by id - take care of nil ids of dead processes" |
133 |
newList sort:[:p1 :p2 | |
|
134 |
|id1 id2| |
|
85 | 135 |
|
208 | 136 |
(p1 isNil or:[(id1 := p1 id) isNil]) |
137 |
ifTrue:[true] |
|
138 |
ifFalse:[ |
|
139 |
(p2 isNil or:[(id2 := p2 id) isNil]) |
|
140 |
ifTrue:[false] |
|
141 |
ifFalse:[id1 < id2] |
|
142 |
] |
|
143 |
]. |
|
144 |
newList ~= processes ifTrue:[ |
|
145 |
processes := WeakArray withAll:newList. |
|
146 |
self updateStatus |
|
147 |
]. |
|
85 | 148 |
]. |
149 |
updateBlock notNil ifTrue:[ |
|
208 | 150 |
Processor removeTimedBlock:listUpdateBlock. |
151 |
Processor addTimedBlock:listUpdateBlock afterSeconds:listUpdateDelay |
|
85 | 152 |
]. |
153 |
! |
|
154 |
||
155 |
updateStatus |
|
156 |
"update status display of processes" |
|
157 |
||
517 | 158 |
|oldList list line dIndex con interrupted plist |
159 |
aProcess nm st c c0 n found sender running sel| |
|
85 | 160 |
|
161 |
shown ifTrue:[ |
|
208 | 162 |
oldList := listView list. |
163 |
processes notNil ifTrue:[ |
|
164 |
list := OrderedCollection new. |
|
165 |
list add:self titleLine. |
|
166 |
list add:(String new:self titleLine size withAll:$-). |
|
85 | 167 |
|
208 | 168 |
interrupted := Processor interruptedProcess. |
85 | 169 |
|
208 | 170 |
dIndex := 1. |
171 |
1 to:processes size do:[:index | |
|
172 |
|totalStack| |
|
85 | 173 |
|
208 | 174 |
aProcess := processes at:index. |
175 |
aProcess notNil ifTrue:[ |
|
176 |
(aProcess id notNil or:[hideDead not]) ifTrue:[ |
|
177 |
line := aProcess id printStringPaddedTo:5. |
|
178 |
(nm := aProcess name) isNil ifFalse:[ |
|
179 |
nm := nm printString |
|
180 |
] ifTrue:[ |
|
181 |
nm := ' ' |
|
182 |
]. |
|
183 |
nm size >= 29 ifTrue:[ |
|
184 |
nm := (nm contractTo:28) , ' ' |
|
185 |
] ifFalse:[ |
|
186 |
nm := (nm printStringPaddedTo:29). |
|
187 |
]. |
|
188 |
line := line , nm. |
|
85 | 189 |
"/ n := cpuUsages at:(aProcess id) ifAbsent:[0]. |
190 |
"/ n ~~ 0 ifTrue:[ |
|
191 |
"/ line := line , ((n * 4) printStringLeftPaddedTo:3) |
|
192 |
"/ ] ifFalse:[ |
|
193 |
"/ line := line , ' ' |
|
194 |
"/ ]. |
|
208 | 195 |
st := aProcess state. |
196 |
(st == #run |
|
197 |
and:[aProcess == interrupted]) ifTrue:[ |
|
198 |
c := ' *'. |
|
322
e3ccd5e431df
fixed context display (dont search for suspending context in running processes)
Claus Gittinger <cg@exept.de>
parents:
315
diff
changeset
|
199 |
running := true. |
208 | 200 |
] ifFalse:[ |
201 |
c := ' '. |
|
322
e3ccd5e431df
fixed context display (dont search for suspending context in running processes)
Claus Gittinger <cg@exept.de>
parents:
315
diff
changeset
|
202 |
running := false. |
208 | 203 |
]. |
204 |
line := line , c , (st printStringPaddedTo:9). |
|
205 |
line := line , (aProcess priority printStringLeftPaddedTo:3). |
|
206 |
line := line , (aProcess usedStackSize printStringLeftPaddedTo:11). |
|
143 | 207 |
|
208 | 208 |
n := aProcess numberOfStackSegments. |
322
e3ccd5e431df
fixed context display (dont search for suspending context in running processes)
Claus Gittinger <cg@exept.de>
parents:
315
diff
changeset
|
209 |
true "showDetail" ifTrue:[ |
208 | 210 |
con := aProcess suspendedContext. |
211 |
con isNil ifTrue:[ |
|
212 |
aProcess == Processor activeProcess ifTrue:[ |
|
213 |
con := thisContext |
|
214 |
] |
|
215 |
]. |
|
322
e3ccd5e431df
fixed context display (dont search for suspending context in running processes)
Claus Gittinger <cg@exept.de>
parents:
315
diff
changeset
|
216 |
]. |
208 | 217 |
showDetail ifTrue:[ |
218 |
aProcess id == 0 ifTrue:[ |
|
219 |
line := line , ('unlimited' leftPaddedTo:13). |
|
220 |
] ifFalse:[ |
|
221 |
line := line , (aProcess totalStackSize printStringLeftPaddedTo:10). |
|
222 |
line := line , '(' , n printString , ')'. |
|
223 |
]. |
|
224 |
con notNil ifTrue:[ |
|
225 |
line := line , ' '. |
|
226 |
line := line , (((ObjectMemory addressOf:con) printStringRadix:16) leftPaddedTo:8 with:$0). |
|
227 |
line := line , ' .. '. |
|
228 |
c := con. |
|
229 |
[(sender := c sender) notNil] whileTrue:[ |
|
230 |
c := sender |
|
231 |
]. |
|
232 |
line := line , (((ObjectMemory addressOf:c) printStringRadix:16) leftPaddedTo:8 with:$0). |
|
233 |
] ifFalse:[ |
|
234 |
line := line , (String new:20) |
|
235 |
]. |
|
236 |
line := line , ' '. |
|
237 |
line := line , (aProcess numberOfStackBoundaryHits printStringLeftPaddedTo:5). |
|
238 |
]. |
|
143 | 239 |
|
208 | 240 |
con notNil ifTrue:[ |
241 |
c := con. |
|
413
715a6a18f825
better display of running processes context
Claus Gittinger <cg@exept.de>
parents:
409
diff
changeset
|
242 |
found := false. |
322
e3ccd5e431df
fixed context display (dont search for suspending context in running processes)
Claus Gittinger <cg@exept.de>
parents:
315
diff
changeset
|
243 |
running ifFalse:[ |
e3ccd5e431df
fixed context display (dont search for suspending context in running processes)
Claus Gittinger <cg@exept.de>
parents:
315
diff
changeset
|
244 |
"/ search for a semaphore-wait in the top 10 contexts |
e3ccd5e431df
fixed context display (dont search for suspending context in running processes)
Claus Gittinger <cg@exept.de>
parents:
315
diff
changeset
|
245 |
|
208 | 246 |
1 to:10 do:[:n | |
247 |
found ifFalse:[ |
|
248 |
c notNil ifTrue:[ |
|
409
86125c414826
dont send #isMemberOf: to the receiver (could be nil-subclass)
Claus Gittinger <cg@exept.de>
parents:
322
diff
changeset
|
249 |
(c receiver class == Semaphore) ifTrue:[ |
322
e3ccd5e431df
fixed context display (dont search for suspending context in running processes)
Claus Gittinger <cg@exept.de>
parents:
315
diff
changeset
|
250 |
c selector == #wait ifTrue:[ |
e3ccd5e431df
fixed context display (dont search for suspending context in running processes)
Claus Gittinger <cg@exept.de>
parents:
315
diff
changeset
|
251 |
found := true. |
e3ccd5e431df
fixed context display (dont search for suspending context in running processes)
Claus Gittinger <cg@exept.de>
parents:
315
diff
changeset
|
252 |
] |
e3ccd5e431df
fixed context display (dont search for suspending context in running processes)
Claus Gittinger <cg@exept.de>
parents:
315
diff
changeset
|
253 |
]. |
e3ccd5e431df
fixed context display (dont search for suspending context in running processes)
Claus Gittinger <cg@exept.de>
parents:
315
diff
changeset
|
254 |
c := c sender. |
e3ccd5e431df
fixed context display (dont search for suspending context in running processes)
Claus Gittinger <cg@exept.de>
parents:
315
diff
changeset
|
255 |
] |
e3ccd5e431df
fixed context display (dont search for suspending context in running processes)
Claus Gittinger <cg@exept.de>
parents:
315
diff
changeset
|
256 |
] |
e3ccd5e431df
fixed context display (dont search for suspending context in running processes)
Claus Gittinger <cg@exept.de>
parents:
315
diff
changeset
|
257 |
]. |
413
715a6a18f825
better display of running processes context
Claus Gittinger <cg@exept.de>
parents:
409
diff
changeset
|
258 |
]. |
715a6a18f825
better display of running processes context
Claus Gittinger <cg@exept.de>
parents:
409
diff
changeset
|
259 |
found ifFalse:[ |
715a6a18f825
better display of running processes context
Claus Gittinger <cg@exept.de>
parents:
409
diff
changeset
|
260 |
"/ search for a non-processor receiver in the top 10 contexts |
715a6a18f825
better display of running processes context
Claus Gittinger <cg@exept.de>
parents:
409
diff
changeset
|
261 |
|
715a6a18f825
better display of running processes context
Claus Gittinger <cg@exept.de>
parents:
409
diff
changeset
|
262 |
c := con. |
715a6a18f825
better display of running processes context
Claus Gittinger <cg@exept.de>
parents:
409
diff
changeset
|
263 |
1 to:10 do:[:n | |
428
1c7406f57591
skip Process contexts in display
Claus Gittinger <cg@exept.de>
parents:
423
diff
changeset
|
264 |
|r| |
1c7406f57591
skip Process contexts in display
Claus Gittinger <cg@exept.de>
parents:
423
diff
changeset
|
265 |
|
413
715a6a18f825
better display of running processes context
Claus Gittinger <cg@exept.de>
parents:
409
diff
changeset
|
266 |
found ifFalse:[ |
715a6a18f825
better display of running processes context
Claus Gittinger <cg@exept.de>
parents:
409
diff
changeset
|
267 |
c notNil ifTrue:[ |
428
1c7406f57591
skip Process contexts in display
Claus Gittinger <cg@exept.de>
parents:
423
diff
changeset
|
268 |
((r := c receiver) ~~ Processor |
1c7406f57591
skip Process contexts in display
Claus Gittinger <cg@exept.de>
parents:
423
diff
changeset
|
269 |
and:[r class ~~ Process]) ifTrue:[ |
413
715a6a18f825
better display of running processes context
Claus Gittinger <cg@exept.de>
parents:
409
diff
changeset
|
270 |
found := true. |
715a6a18f825
better display of running processes context
Claus Gittinger <cg@exept.de>
parents:
409
diff
changeset
|
271 |
] ifFalse:[ |
715a6a18f825
better display of running processes context
Claus Gittinger <cg@exept.de>
parents:
409
diff
changeset
|
272 |
c := c sender. |
208 | 273 |
] |
274 |
] |
|
275 |
] |
|
413
715a6a18f825
better display of running processes context
Claus Gittinger <cg@exept.de>
parents:
409
diff
changeset
|
276 |
] |
715a6a18f825
better display of running processes context
Claus Gittinger <cg@exept.de>
parents:
409
diff
changeset
|
277 |
]. |
715a6a18f825
better display of running processes context
Claus Gittinger <cg@exept.de>
parents:
409
diff
changeset
|
278 |
found ifFalse:[ |
715a6a18f825
better display of running processes context
Claus Gittinger <cg@exept.de>
parents:
409
diff
changeset
|
279 |
c := con |
208 | 280 |
]. |
322
e3ccd5e431df
fixed context display (dont search for suspending context in running processes)
Claus Gittinger <cg@exept.de>
parents:
315
diff
changeset
|
281 |
|
208 | 282 |
[c notNil and:[c isBlockContext]] whileTrue:[ |
283 |
c := c home |
|
284 |
]. |
|
285 |
c notNil ifTrue:[ |
|
517 | 286 |
sel := c selector. |
287 |
sel isNil ifTrue:[ |
|
288 |
sel := '* unknown *' |
|
289 |
]. |
|
290 |
n := c receiver class name , '>>' , sel. |
|
208 | 291 |
line := line , ' ' , n |
292 |
] |
|
293 |
]. |
|
294 |
list add:line. |
|
295 |
processes at:dIndex put:aProcess. |
|
296 |
dIndex := dIndex + 1 |
|
297 |
] |
|
298 |
]. |
|
299 |
]. |
|
300 |
dIndex to:processes size do:[:index | |
|
301 |
processes at:index put:nil |
|
302 |
] |
|
303 |
]. |
|
304 |
"avoid flicker" |
|
305 |
(oldList notNil and:[oldList size == list size]) ifTrue:[ |
|
306 |
list keysAndValuesDo:[:idx :entry | |
|
307 |
(oldList at:idx) ~= entry ifTrue:[ |
|
308 |
listView at:idx put:entry |
|
309 |
] |
|
310 |
] |
|
311 |
] ifFalse:[ |
|
312 |
listView setList:list. |
|
313 |
"the first two entries cannot be selected" |
|
314 |
listView attributeAt:1 put:#disabled. |
|
315 |
listView attributeAt:2 put:#disabled. |
|
314
728eab568865
Flush output when updating display.
Stefan Vogel <sv@exept.de>
parents:
208
diff
changeset
|
316 |
]. |
322
e3ccd5e431df
fixed context display (dont search for suspending context in running processes)
Claus Gittinger <cg@exept.de>
parents:
315
diff
changeset
|
317 |
listView flush |
85 | 318 |
]. |
319 |
updateBlock notNil ifTrue:[ |
|
208 | 320 |
Processor removeTimedBlock:updateBlock. |
321 |
Processor addTimedBlock:updateBlock afterSeconds:updateDelay |
|
85 | 322 |
] |
322
e3ccd5e431df
fixed context display (dont search for suspending context in running processes)
Claus Gittinger <cg@exept.de>
parents:
315
diff
changeset
|
323 |
|
517 | 324 |
"Modified: 27.4.1996 / 14:17:15 / cg" |
85 | 325 |
! |
326 |
||
327 |
updateView |
|
328 |
self updateList. |
|
329 |
self updateStatus |
|
19 | 330 |
! ! |
331 |
||
143 | 332 |
!ProcessMonitor methodsFor:'events'! |
333 |
||
208 | 334 |
canHandle:key |
335 |
^ key == #InspectIt |
|
336 |
! |
|
337 |
||
143 | 338 |
keyPress:key x:x y:y |
339 |
<resource: #keyboard ( #InspectIt ) > |
|
340 |
||
341 |
key == #InspectIt ifTrue:[ |
|
342 |
^ self inspectProcess. |
|
343 |
]. |
|
344 |
^ super keyPress:key x:x y:y |
|
345 |
! ! |
|
346 |
||
19 | 347 |
!ProcessMonitor methodsFor:'initialization'! |
348 |
||
349 |
initialize |
|
107 | 350 |
|v| |
19 | 351 |
|
352 |
super initialize. |
|
353 |
||
45 | 354 |
hideDead := true. |
109 | 355 |
showDetail := Smalltalk at:#SystemDebugging ifAbsent:false. |
45 | 356 |
|
110 | 357 |
v := HVScrollableView for:SelectionInListView miniScrollerH:true in:self. |
19 | 358 |
v origin:0.0@0.0 corner:1.0@1.0. |
85 | 359 |
|
360 |
"/ self extent:(font widthOf:self titleLine) + v scrollBar width @ 100. |
|
361 |
||
19 | 362 |
listView := v scrolledView. |
363 |
listView font:font. |
|
98 | 364 |
listView menuHolder:self; menuPerformer:self; menuMessage:#processMenu. |
45 | 365 |
|
19 | 366 |
listView multipleSelectOk:true. |
97 | 367 |
listView delegate:(KeyboardForwarder toView:self). |
423 | 368 |
listView doubleClickAction:[:line | self debugProcess]. |
19 | 369 |
|
370 |
updateDelay := 0.5. |
|
371 |
listUpdateDelay := 5. |
|
45 | 372 |
|
315
8a86faf847d1
create a new updateProcess when restarted
Claus Gittinger <cg@exept.de>
parents:
314
diff
changeset
|
373 |
"/ event mode is no longer used; |
8a86faf847d1
create a new updateProcess when restarted
Claus Gittinger <cg@exept.de>
parents:
314
diff
changeset
|
374 |
"/ this event support may vanish |
478 | 375 |
Processor isPureEventDriven ifTrue:[ |
315
8a86faf847d1
create a new updateProcess when restarted
Claus Gittinger <cg@exept.de>
parents:
314
diff
changeset
|
376 |
updateBlock := [self updateStatus]. |
8a86faf847d1
create a new updateProcess when restarted
Claus Gittinger <cg@exept.de>
parents:
314
diff
changeset
|
377 |
listUpdateBlock := [self updateList]. |
19 | 378 |
]. |
45 | 379 |
|
19 | 380 |
device hasColors ifTrue:[ |
315
8a86faf847d1
create a new updateProcess when restarted
Claus Gittinger <cg@exept.de>
parents:
314
diff
changeset
|
381 |
runColor := Color green. |
8a86faf847d1
create a new updateProcess when restarted
Claus Gittinger <cg@exept.de>
parents:
314
diff
changeset
|
382 |
suspendedColor := Color yellow. |
8a86faf847d1
create a new updateProcess when restarted
Claus Gittinger <cg@exept.de>
parents:
314
diff
changeset
|
383 |
waitColor := Color red. |
19 | 384 |
] ifFalse:[ |
315
8a86faf847d1
create a new updateProcess when restarted
Claus Gittinger <cg@exept.de>
parents:
314
diff
changeset
|
385 |
runColor := suspendedColor := waitColor := Color black |
19 | 386 |
] |
387 |
||
45 | 388 |
" |
389 |
ProcessMonitor open |
|
390 |
" |
|
315
8a86faf847d1
create a new updateProcess when restarted
Claus Gittinger <cg@exept.de>
parents:
314
diff
changeset
|
391 |
|
478 | 392 |
"Modified: 13.4.1996 / 20:34:25 / cg" |
19 | 393 |
! |
394 |
||
85 | 395 |
mapped |
396 |
super mapped. |
|
397 |
self updateStatus. |
|
398 |
self updateList. |
|
399 |
! |
|
400 |
||
208 | 401 |
realize |
402 |
super realize. |
|
403 |
waitColor := waitColor on:device. |
|
404 |
runColor := runColor on:device. |
|
405 |
suspendedColor := suspendedColor on:device. |
|
406 |
||
407 |
self startUpdateProcess. |
|
408 |
! |
|
409 |
||
315
8a86faf847d1
create a new updateProcess when restarted
Claus Gittinger <cg@exept.de>
parents:
314
diff
changeset
|
410 |
reinitialize |
8a86faf847d1
create a new updateProcess when restarted
Claus Gittinger <cg@exept.de>
parents:
314
diff
changeset
|
411 |
updateProcess := nil. |
8a86faf847d1
create a new updateProcess when restarted
Claus Gittinger <cg@exept.de>
parents:
314
diff
changeset
|
412 |
super reinitialize. |
8a86faf847d1
create a new updateProcess when restarted
Claus Gittinger <cg@exept.de>
parents:
314
diff
changeset
|
413 |
self startUpdateProcess. |
8a86faf847d1
create a new updateProcess when restarted
Claus Gittinger <cg@exept.de>
parents:
314
diff
changeset
|
414 |
|
8a86faf847d1
create a new updateProcess when restarted
Claus Gittinger <cg@exept.de>
parents:
314
diff
changeset
|
415 |
"Created: 22.12.1995 / 22:48:37 / cg" |
8a86faf847d1
create a new updateProcess when restarted
Claus Gittinger <cg@exept.de>
parents:
314
diff
changeset
|
416 |
"Modified: 22.12.1995 / 22:51:14 / cg" |
8a86faf847d1
create a new updateProcess when restarted
Claus Gittinger <cg@exept.de>
parents:
314
diff
changeset
|
417 |
! |
8a86faf847d1
create a new updateProcess when restarted
Claus Gittinger <cg@exept.de>
parents:
314
diff
changeset
|
418 |
|
93 | 419 |
startUpdateProcess |
19 | 420 |
updateBlock notNil ifTrue:[ |
90 | 421 |
Processor addTimedBlock:updateBlock afterSeconds:updateDelay. |
422 |
Processor addTimedBlock:listUpdateBlock afterSeconds:listUpdateDelay. |
|
19 | 423 |
] ifFalse:[ |
90 | 424 |
updateProcess := [ |
425 |
Process terminateSignal handle:[:ex | |
|
426 |
updateProcess := nil |
|
427 |
] do:[ |
|
428 |
|id cnt| |
|
56 | 429 |
|
90 | 430 |
" |
431 |
every 20ms, we look which process runs; |
|
432 |
every half second, the status is updated. |
|
433 |
every 5 seconds, the list of processes is |
|
434 |
built up again |
|
435 |
" |
|
436 |
[true] whileTrue:[ |
|
437 |
1 to:9 do:[:i | |
|
85 | 438 |
"/ cpuUsages := IdentityDictionary new. |
439 |
"/ 1 to:25 do:[:i | |
|
440 |
"/ (Delay forSeconds:0.02) wait. |
|
441 |
"/ id := Processor interruptedProcess id. |
|
442 |
"/ cnt := cpuUsages at:id ifAbsent:[0]. |
|
443 |
"/ cpuUsages at:id put:cnt + 1. |
|
444 |
"/ ]. |
|
90 | 445 |
(Delay forSeconds:0.5) wait. |
446 |
self updateStatus. |
|
447 |
]. |
|
448 |
(Delay forSeconds:0.5) wait. |
|
449 |
self updateList. |
|
450 |
] |
|
451 |
] |
|
452 |
] forkAt:(Processor userSchedulingPriority + 1). |
|
453 |
updateProcess name:'monitor [' , |
|
454 |
Processor activeProcess id printString , |
|
455 |
'] update'. |
|
456 |
" |
|
457 |
raise my own priority |
|
458 |
" |
|
459 |
Processor activeProcess priority:(Processor userSchedulingPriority + 2) |
|
19 | 460 |
]. |
461 |
! ! |
|
462 |
||
463 |
!ProcessMonitor methodsFor:'menu actions'! |
|
464 |
||
208 | 465 |
abortProcess |
466 |
"abort (raise AbortSignal in) the selected process" |
|
467 |
||
468 |
self selectedProcessesDo:[:p | |
|
469 |
p interruptWith:[AbortSignal raise] |
|
470 |
] |
|
471 |
! |
|
472 |
||
473 |
debugProcess |
|
474 |
"open a debugger on the selected process" |
|
475 |
||
476 |
self selectedProcessesDo:[:p | |
|
477 |
Debugger openOn:p |
|
478 |
] |
|
479 |
! |
|
480 |
||
481 |
detail |
|
482 |
showDetail := showDetail not. |
|
483 |
self updateView |
|
484 |
! |
|
485 |
||
486 |
hideDead:aBoolean |
|
487 |
hideDead := aBoolean |
|
488 |
! |
|
489 |
||
490 |
inspectProcess |
|
491 |
"open an inspector on the selected process" |
|
492 |
||
493 |
self selectedProcessesSend:#inspect |
|
494 |
! |
|
495 |
||
496 |
lowerPrio |
|
497 |
"lower the selected processes priority" |
|
498 |
||
499 |
self selectedProcessesDo:[:p | |
|
500 |
p priority:(p priority - 1) |
|
501 |
] |
|
502 |
! |
|
503 |
||
85 | 504 |
processMenu |
505 |
|labels selectors m| |
|
506 |
||
109 | 507 |
device ctrlDown ifTrue:[ |
110 | 508 |
labels := resources array:#( |
109 | 509 |
'\c detail' |
510 |
). |
|
511 |
selectors := #( |
|
512 |
detail |
|
513 |
). |
|
514 |
] ifFalse:[ |
|
515 |
labels := resources array:#( |
|
516 |
'inspect' |
|
517 |
'debug' |
|
518 |
'-' |
|
519 |
'resume' |
|
520 |
'suspend' |
|
521 |
'stop' |
|
522 |
'abort' |
|
523 |
'terminate' |
|
524 |
'-' |
|
525 |
'raise prio' |
|
526 |
'lower prio' |
|
527 |
). |
|
528 |
selectors := #( |
|
529 |
inspectProcess |
|
530 |
debugProcess |
|
531 |
nil |
|
532 |
resumeProcess |
|
533 |
suspendProcess |
|
534 |
stopProcess |
|
535 |
abortProcess |
|
536 |
terminateProcess |
|
537 |
nil |
|
538 |
raisePrio |
|
539 |
lowerPrio |
|
540 |
). |
|
541 |
updateProcess isNil ifTrue:[ |
|
542 |
labels := (resources array:#('update' '-')) , labels. |
|
543 |
selectors := #(updateView nil) , selectors |
|
544 |
]. |
|
85 | 545 |
]. |
546 |
||
547 |
m := PopUpMenu labels:labels |
|
90 | 548 |
selectors:selectors. |
85 | 549 |
|
109 | 550 |
m checkToggleAt:#detail put:showDetail. |
85 | 551 |
^ m |
552 |
! |
|
19 | 553 |
|
208 | 554 |
raisePrio |
555 |
"raise the selected processes priority" |
|
143 | 556 |
|
557 |
self selectedProcessesDo:[:p | |
|
208 | 558 |
p priority:(p priority + 1) |
143 | 559 |
] |
560 |
! |
|
561 |
||
562 |
resumeProcess |
|
563 |
"resume the selected process (i.e. let it run) " |
|
564 |
||
565 |
self selectedProcessesSend:#resume |
|
566 |
! |
|
567 |
||
92 | 568 |
stopProcess |
569 |
"stop the selected process - not even interrupts will wake it up" |
|
570 |
||
571 |
self selectedProcessesSend:#stop |
|
572 |
! |
|
573 |
||
19 | 574 |
suspendProcess |
92 | 575 |
"suspend the selected process - interrupts will let it run again" |
576 |
||
58 | 577 |
self selectedProcessesSend:#suspend |
85 | 578 |
! |
45 | 579 |
|
208 | 580 |
terminateProcess |
581 |
"terminate the selected process" |
|
92 | 582 |
|
208 | 583 |
self selectedProcessesSend:#terminate |
19 | 584 |
! ! |
585 |
||
143 | 586 |
!ProcessMonitor methodsFor:'private'! |
587 |
||
588 |
selectedProcessesDo:aBlock |
|
589 |
|p nr sel| |
|
85 | 590 |
|
143 | 591 |
sel := listView selection. |
592 |
sel isNil ifTrue:[^ self]. |
|
593 |
(sel isKindOf:Collection) ifTrue:[ |
|
594 |
sel do:[:n | |
|
595 |
nr := n - 2. "for headlines" |
|
596 |
nr notNil ifTrue:[ |
|
597 |
nr > 0 ifTrue:[ |
|
598 |
p := processes at:nr. |
|
599 |
p notNil ifTrue:[ |
|
600 |
aBlock value:p |
|
601 |
] |
|
602 |
] |
|
603 |
] |
|
604 |
] |
|
85 | 605 |
] ifFalse:[ |
143 | 606 |
nr := sel - 2. "for headlines" |
607 |
nr notNil ifTrue:[ |
|
608 |
nr > 0 ifTrue:[ |
|
609 |
p := processes at:nr. |
|
610 |
p notNil ifTrue:[ |
|
611 |
aBlock value:p |
|
612 |
] |
|
613 |
] |
|
614 |
] |
|
85 | 615 |
]. |
143 | 616 |
! |
617 |
||
618 |
selectedProcessesSend:aSelector |
|
619 |
self selectedProcessesDo:[:p | |
|
620 |
p perform:aSelector |
|
621 |
]. |
|
622 |
self updateView. |
|
85 | 623 |
! ! |
624 |
||
625 |
!ProcessMonitor methodsFor:'queries'! |
|
626 |
||
105 | 627 |
preferredExtent |
85 | 628 |
^ (font widthOf:self titleLine) + 40 @ 100 |
629 |
! ! |
|
208 | 630 |
|
631 |
!ProcessMonitor class methodsFor:'documentation'! |
|
632 |
||
633 |
version |
|
517 | 634 |
^ '$Header: /cvs/stx/stx/libtool/ProcessMonitor.st,v 1.35 1996-04-27 18:00:04 cg Exp $'! ! |