author | Claus Gittinger <cg@exept.de> |
Sun, 14 Apr 1996 00:21:25 +0200 | |
changeset 478 | b0b974490a51 |
parent 428 | 1c7406f57591 |
child 517 | cc3d4e0fc758 |
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 |
||
322
e3ccd5e431df
fixed context display (dont search for suspending context in running processes)
Claus Gittinger <cg@exept.de>
parents:
315
diff
changeset
|
158 |
|oldList list line dIndex con interrupted plist aProcess nm st c c0 n found sender running| |
85 | 159 |
|
160 |
shown ifTrue:[ |
|
208 | 161 |
oldList := listView list. |
162 |
processes notNil ifTrue:[ |
|
163 |
list := OrderedCollection new. |
|
164 |
list add:self titleLine. |
|
165 |
list add:(String new:self titleLine size withAll:$-). |
|
85 | 166 |
|
208 | 167 |
interrupted := Processor interruptedProcess. |
85 | 168 |
|
208 | 169 |
dIndex := 1. |
170 |
1 to:processes size do:[:index | |
|
171 |
|totalStack| |
|
85 | 172 |
|
208 | 173 |
aProcess := processes at:index. |
174 |
aProcess notNil ifTrue:[ |
|
175 |
(aProcess id notNil or:[hideDead not]) ifTrue:[ |
|
176 |
line := aProcess id printStringPaddedTo:5. |
|
177 |
(nm := aProcess name) isNil ifFalse:[ |
|
178 |
nm := nm printString |
|
179 |
] ifTrue:[ |
|
180 |
nm := ' ' |
|
181 |
]. |
|
182 |
nm size >= 29 ifTrue:[ |
|
183 |
nm := (nm contractTo:28) , ' ' |
|
184 |
] ifFalse:[ |
|
185 |
nm := (nm printStringPaddedTo:29). |
|
186 |
]. |
|
187 |
line := line , nm. |
|
85 | 188 |
"/ n := cpuUsages at:(aProcess id) ifAbsent:[0]. |
189 |
"/ n ~~ 0 ifTrue:[ |
|
190 |
"/ line := line , ((n * 4) printStringLeftPaddedTo:3) |
|
191 |
"/ ] ifFalse:[ |
|
192 |
"/ line := line , ' ' |
|
193 |
"/ ]. |
|
208 | 194 |
st := aProcess state. |
195 |
(st == #run |
|
196 |
and:[aProcess == interrupted]) ifTrue:[ |
|
197 |
c := ' *'. |
|
322
e3ccd5e431df
fixed context display (dont search for suspending context in running processes)
Claus Gittinger <cg@exept.de>
parents:
315
diff
changeset
|
198 |
running := true. |
208 | 199 |
] ifFalse:[ |
200 |
c := ' '. |
|
322
e3ccd5e431df
fixed context display (dont search for suspending context in running processes)
Claus Gittinger <cg@exept.de>
parents:
315
diff
changeset
|
201 |
running := false. |
208 | 202 |
]. |
203 |
line := line , c , (st printStringPaddedTo:9). |
|
204 |
line := line , (aProcess priority printStringLeftPaddedTo:3). |
|
205 |
line := line , (aProcess usedStackSize printStringLeftPaddedTo:11). |
|
143 | 206 |
|
208 | 207 |
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
|
208 |
true "showDetail" ifTrue:[ |
208 | 209 |
con := aProcess suspendedContext. |
210 |
con isNil ifTrue:[ |
|
211 |
aProcess == Processor activeProcess ifTrue:[ |
|
212 |
con := thisContext |
|
213 |
] |
|
214 |
]. |
|
322
e3ccd5e431df
fixed context display (dont search for suspending context in running processes)
Claus Gittinger <cg@exept.de>
parents:
315
diff
changeset
|
215 |
]. |
208 | 216 |
showDetail ifTrue:[ |
217 |
aProcess id == 0 ifTrue:[ |
|
218 |
line := line , ('unlimited' leftPaddedTo:13). |
|
219 |
] ifFalse:[ |
|
220 |
line := line , (aProcess totalStackSize printStringLeftPaddedTo:10). |
|
221 |
line := line , '(' , n printString , ')'. |
|
222 |
]. |
|
223 |
con notNil ifTrue:[ |
|
224 |
line := line , ' '. |
|
225 |
line := line , (((ObjectMemory addressOf:con) printStringRadix:16) leftPaddedTo:8 with:$0). |
|
226 |
line := line , ' .. '. |
|
227 |
c := con. |
|
228 |
[(sender := c sender) notNil] whileTrue:[ |
|
229 |
c := sender |
|
230 |
]. |
|
231 |
line := line , (((ObjectMemory addressOf:c) printStringRadix:16) leftPaddedTo:8 with:$0). |
|
232 |
] ifFalse:[ |
|
233 |
line := line , (String new:20) |
|
234 |
]. |
|
235 |
line := line , ' '. |
|
236 |
line := line , (aProcess numberOfStackBoundaryHits printStringLeftPaddedTo:5). |
|
237 |
]. |
|
143 | 238 |
|
208 | 239 |
con notNil ifTrue:[ |
240 |
c := con. |
|
413
715a6a18f825
better display of running processes context
Claus Gittinger <cg@exept.de>
parents:
409
diff
changeset
|
241 |
found := false. |
322
e3ccd5e431df
fixed context display (dont search for suspending context in running processes)
Claus Gittinger <cg@exept.de>
parents:
315
diff
changeset
|
242 |
running ifFalse:[ |
e3ccd5e431df
fixed context display (dont search for suspending context in running processes)
Claus Gittinger <cg@exept.de>
parents:
315
diff
changeset
|
243 |
"/ 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
|
244 |
|
208 | 245 |
1 to:10 do:[:n | |
246 |
found ifFalse:[ |
|
247 |
c notNil ifTrue:[ |
|
409
86125c414826
dont send #isMemberOf: to the receiver (could be nil-subclass)
Claus Gittinger <cg@exept.de>
parents:
322
diff
changeset
|
248 |
(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
|
249 |
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
|
250 |
found := true. |
e3ccd5e431df
fixed context display (dont search for suspending context in running processes)
Claus Gittinger <cg@exept.de>
parents:
315
diff
changeset
|
251 |
] |
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 |
c := c sender. |
e3ccd5e431df
fixed context display (dont search for suspending context in running processes)
Claus Gittinger <cg@exept.de>
parents:
315
diff
changeset
|
254 |
] |
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 |
]. |
413
715a6a18f825
better display of running processes context
Claus Gittinger <cg@exept.de>
parents:
409
diff
changeset
|
257 |
]. |
715a6a18f825
better display of running processes context
Claus Gittinger <cg@exept.de>
parents:
409
diff
changeset
|
258 |
found ifFalse:[ |
715a6a18f825
better display of running processes context
Claus Gittinger <cg@exept.de>
parents:
409
diff
changeset
|
259 |
"/ 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
|
260 |
|
715a6a18f825
better display of running processes context
Claus Gittinger <cg@exept.de>
parents:
409
diff
changeset
|
261 |
c := con. |
715a6a18f825
better display of running processes context
Claus Gittinger <cg@exept.de>
parents:
409
diff
changeset
|
262 |
1 to:10 do:[:n | |
428
1c7406f57591
skip Process contexts in display
Claus Gittinger <cg@exept.de>
parents:
423
diff
changeset
|
263 |
|r| |
1c7406f57591
skip Process contexts in display
Claus Gittinger <cg@exept.de>
parents:
423
diff
changeset
|
264 |
|
413
715a6a18f825
better display of running processes context
Claus Gittinger <cg@exept.de>
parents:
409
diff
changeset
|
265 |
found ifFalse:[ |
715a6a18f825
better display of running processes context
Claus Gittinger <cg@exept.de>
parents:
409
diff
changeset
|
266 |
c notNil ifTrue:[ |
428
1c7406f57591
skip Process contexts in display
Claus Gittinger <cg@exept.de>
parents:
423
diff
changeset
|
267 |
((r := c receiver) ~~ Processor |
1c7406f57591
skip Process contexts in display
Claus Gittinger <cg@exept.de>
parents:
423
diff
changeset
|
268 |
and:[r class ~~ Process]) ifTrue:[ |
413
715a6a18f825
better display of running processes context
Claus Gittinger <cg@exept.de>
parents:
409
diff
changeset
|
269 |
found := true. |
715a6a18f825
better display of running processes context
Claus Gittinger <cg@exept.de>
parents:
409
diff
changeset
|
270 |
] ifFalse:[ |
715a6a18f825
better display of running processes context
Claus Gittinger <cg@exept.de>
parents:
409
diff
changeset
|
271 |
c := c sender. |
208 | 272 |
] |
273 |
] |
|
274 |
] |
|
413
715a6a18f825
better display of running processes context
Claus Gittinger <cg@exept.de>
parents:
409
diff
changeset
|
275 |
] |
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 |
found ifFalse:[ |
715a6a18f825
better display of running processes context
Claus Gittinger <cg@exept.de>
parents:
409
diff
changeset
|
278 |
c := con |
208 | 279 |
]. |
322
e3ccd5e431df
fixed context display (dont search for suspending context in running processes)
Claus Gittinger <cg@exept.de>
parents:
315
diff
changeset
|
280 |
|
208 | 281 |
[c notNil and:[c isBlockContext]] whileTrue:[ |
282 |
c := c home |
|
283 |
]. |
|
284 |
c notNil ifTrue:[ |
|
285 |
n := c receiver class name , '>>' , c selector. |
|
286 |
line := line , ' ' , n |
|
287 |
] |
|
288 |
]. |
|
289 |
list add:line. |
|
290 |
processes at:dIndex put:aProcess. |
|
291 |
dIndex := dIndex + 1 |
|
292 |
] |
|
293 |
]. |
|
294 |
]. |
|
295 |
dIndex to:processes size do:[:index | |
|
296 |
processes at:index put:nil |
|
297 |
] |
|
298 |
]. |
|
299 |
"avoid flicker" |
|
300 |
(oldList notNil and:[oldList size == list size]) ifTrue:[ |
|
301 |
list keysAndValuesDo:[:idx :entry | |
|
302 |
(oldList at:idx) ~= entry ifTrue:[ |
|
303 |
listView at:idx put:entry |
|
304 |
] |
|
305 |
] |
|
306 |
] ifFalse:[ |
|
307 |
listView setList:list. |
|
308 |
"the first two entries cannot be selected" |
|
309 |
listView attributeAt:1 put:#disabled. |
|
310 |
listView attributeAt:2 put:#disabled. |
|
314
728eab568865
Flush output when updating display.
Stefan Vogel <sv@exept.de>
parents:
208
diff
changeset
|
311 |
]. |
322
e3ccd5e431df
fixed context display (dont search for suspending context in running processes)
Claus Gittinger <cg@exept.de>
parents:
315
diff
changeset
|
312 |
listView flush |
85 | 313 |
]. |
314 |
updateBlock notNil ifTrue:[ |
|
208 | 315 |
Processor removeTimedBlock:updateBlock. |
316 |
Processor addTimedBlock:updateBlock afterSeconds:updateDelay |
|
85 | 317 |
] |
322
e3ccd5e431df
fixed context display (dont search for suspending context in running processes)
Claus Gittinger <cg@exept.de>
parents:
315
diff
changeset
|
318 |
|
413
715a6a18f825
better display of running processes context
Claus Gittinger <cg@exept.de>
parents:
409
diff
changeset
|
319 |
"Modified: 29.2.1996 / 03:33:25 / cg" |
85 | 320 |
! |
321 |
||
322 |
updateView |
|
323 |
self updateList. |
|
324 |
self updateStatus |
|
19 | 325 |
! ! |
326 |
||
143 | 327 |
!ProcessMonitor methodsFor:'events'! |
328 |
||
208 | 329 |
canHandle:key |
330 |
^ key == #InspectIt |
|
331 |
! |
|
332 |
||
143 | 333 |
keyPress:key x:x y:y |
334 |
<resource: #keyboard ( #InspectIt ) > |
|
335 |
||
336 |
key == #InspectIt ifTrue:[ |
|
337 |
^ self inspectProcess. |
|
338 |
]. |
|
339 |
^ super keyPress:key x:x y:y |
|
340 |
! ! |
|
341 |
||
19 | 342 |
!ProcessMonitor methodsFor:'initialization'! |
343 |
||
344 |
initialize |
|
107 | 345 |
|v| |
19 | 346 |
|
347 |
super initialize. |
|
348 |
||
45 | 349 |
hideDead := true. |
109 | 350 |
showDetail := Smalltalk at:#SystemDebugging ifAbsent:false. |
45 | 351 |
|
110 | 352 |
v := HVScrollableView for:SelectionInListView miniScrollerH:true in:self. |
19 | 353 |
v origin:0.0@0.0 corner:1.0@1.0. |
85 | 354 |
|
355 |
"/ self extent:(font widthOf:self titleLine) + v scrollBar width @ 100. |
|
356 |
||
19 | 357 |
listView := v scrolledView. |
358 |
listView font:font. |
|
98 | 359 |
listView menuHolder:self; menuPerformer:self; menuMessage:#processMenu. |
45 | 360 |
|
19 | 361 |
listView multipleSelectOk:true. |
97 | 362 |
listView delegate:(KeyboardForwarder toView:self). |
423 | 363 |
listView doubleClickAction:[:line | self debugProcess]. |
19 | 364 |
|
365 |
updateDelay := 0.5. |
|
366 |
listUpdateDelay := 5. |
|
45 | 367 |
|
315
8a86faf847d1
create a new updateProcess when restarted
Claus Gittinger <cg@exept.de>
parents:
314
diff
changeset
|
368 |
"/ event mode is no longer used; |
8a86faf847d1
create a new updateProcess when restarted
Claus Gittinger <cg@exept.de>
parents:
314
diff
changeset
|
369 |
"/ this event support may vanish |
478 | 370 |
Processor isPureEventDriven ifTrue:[ |
315
8a86faf847d1
create a new updateProcess when restarted
Claus Gittinger <cg@exept.de>
parents:
314
diff
changeset
|
371 |
updateBlock := [self updateStatus]. |
8a86faf847d1
create a new updateProcess when restarted
Claus Gittinger <cg@exept.de>
parents:
314
diff
changeset
|
372 |
listUpdateBlock := [self updateList]. |
19 | 373 |
]. |
45 | 374 |
|
19 | 375 |
device hasColors ifTrue:[ |
315
8a86faf847d1
create a new updateProcess when restarted
Claus Gittinger <cg@exept.de>
parents:
314
diff
changeset
|
376 |
runColor := Color green. |
8a86faf847d1
create a new updateProcess when restarted
Claus Gittinger <cg@exept.de>
parents:
314
diff
changeset
|
377 |
suspendedColor := Color yellow. |
8a86faf847d1
create a new updateProcess when restarted
Claus Gittinger <cg@exept.de>
parents:
314
diff
changeset
|
378 |
waitColor := Color red. |
19 | 379 |
] ifFalse:[ |
315
8a86faf847d1
create a new updateProcess when restarted
Claus Gittinger <cg@exept.de>
parents:
314
diff
changeset
|
380 |
runColor := suspendedColor := waitColor := Color black |
19 | 381 |
] |
382 |
||
45 | 383 |
" |
384 |
ProcessMonitor open |
|
385 |
" |
|
315
8a86faf847d1
create a new updateProcess when restarted
Claus Gittinger <cg@exept.de>
parents:
314
diff
changeset
|
386 |
|
478 | 387 |
"Modified: 13.4.1996 / 20:34:25 / cg" |
19 | 388 |
! |
389 |
||
85 | 390 |
mapped |
391 |
super mapped. |
|
392 |
self updateStatus. |
|
393 |
self updateList. |
|
394 |
! |
|
395 |
||
208 | 396 |
realize |
397 |
super realize. |
|
398 |
waitColor := waitColor on:device. |
|
399 |
runColor := runColor on:device. |
|
400 |
suspendedColor := suspendedColor on:device. |
|
401 |
||
402 |
self startUpdateProcess. |
|
403 |
! |
|
404 |
||
315
8a86faf847d1
create a new updateProcess when restarted
Claus Gittinger <cg@exept.de>
parents:
314
diff
changeset
|
405 |
reinitialize |
8a86faf847d1
create a new updateProcess when restarted
Claus Gittinger <cg@exept.de>
parents:
314
diff
changeset
|
406 |
updateProcess := nil. |
8a86faf847d1
create a new updateProcess when restarted
Claus Gittinger <cg@exept.de>
parents:
314
diff
changeset
|
407 |
super reinitialize. |
8a86faf847d1
create a new updateProcess when restarted
Claus Gittinger <cg@exept.de>
parents:
314
diff
changeset
|
408 |
self startUpdateProcess. |
8a86faf847d1
create a new updateProcess when restarted
Claus Gittinger <cg@exept.de>
parents:
314
diff
changeset
|
409 |
|
8a86faf847d1
create a new updateProcess when restarted
Claus Gittinger <cg@exept.de>
parents:
314
diff
changeset
|
410 |
"Created: 22.12.1995 / 22:48:37 / cg" |
8a86faf847d1
create a new updateProcess when restarted
Claus Gittinger <cg@exept.de>
parents:
314
diff
changeset
|
411 |
"Modified: 22.12.1995 / 22:51:14 / cg" |
8a86faf847d1
create a new updateProcess when restarted
Claus Gittinger <cg@exept.de>
parents:
314
diff
changeset
|
412 |
! |
8a86faf847d1
create a new updateProcess when restarted
Claus Gittinger <cg@exept.de>
parents:
314
diff
changeset
|
413 |
|
93 | 414 |
startUpdateProcess |
19 | 415 |
updateBlock notNil ifTrue:[ |
90 | 416 |
Processor addTimedBlock:updateBlock afterSeconds:updateDelay. |
417 |
Processor addTimedBlock:listUpdateBlock afterSeconds:listUpdateDelay. |
|
19 | 418 |
] ifFalse:[ |
90 | 419 |
updateProcess := [ |
420 |
Process terminateSignal handle:[:ex | |
|
421 |
updateProcess := nil |
|
422 |
] do:[ |
|
423 |
|id cnt| |
|
56 | 424 |
|
90 | 425 |
" |
426 |
every 20ms, we look which process runs; |
|
427 |
every half second, the status is updated. |
|
428 |
every 5 seconds, the list of processes is |
|
429 |
built up again |
|
430 |
" |
|
431 |
[true] whileTrue:[ |
|
432 |
1 to:9 do:[:i | |
|
85 | 433 |
"/ cpuUsages := IdentityDictionary new. |
434 |
"/ 1 to:25 do:[:i | |
|
435 |
"/ (Delay forSeconds:0.02) wait. |
|
436 |
"/ id := Processor interruptedProcess id. |
|
437 |
"/ cnt := cpuUsages at:id ifAbsent:[0]. |
|
438 |
"/ cpuUsages at:id put:cnt + 1. |
|
439 |
"/ ]. |
|
90 | 440 |
(Delay forSeconds:0.5) wait. |
441 |
self updateStatus. |
|
442 |
]. |
|
443 |
(Delay forSeconds:0.5) wait. |
|
444 |
self updateList. |
|
445 |
] |
|
446 |
] |
|
447 |
] forkAt:(Processor userSchedulingPriority + 1). |
|
448 |
updateProcess name:'monitor [' , |
|
449 |
Processor activeProcess id printString , |
|
450 |
'] update'. |
|
451 |
" |
|
452 |
raise my own priority |
|
453 |
" |
|
454 |
Processor activeProcess priority:(Processor userSchedulingPriority + 2) |
|
19 | 455 |
]. |
456 |
! ! |
|
457 |
||
458 |
!ProcessMonitor methodsFor:'menu actions'! |
|
459 |
||
208 | 460 |
abortProcess |
461 |
"abort (raise AbortSignal in) the selected process" |
|
462 |
||
463 |
self selectedProcessesDo:[:p | |
|
464 |
p interruptWith:[AbortSignal raise] |
|
465 |
] |
|
466 |
! |
|
467 |
||
468 |
debugProcess |
|
469 |
"open a debugger on the selected process" |
|
470 |
||
471 |
self selectedProcessesDo:[:p | |
|
472 |
Debugger openOn:p |
|
473 |
] |
|
474 |
! |
|
475 |
||
476 |
detail |
|
477 |
showDetail := showDetail not. |
|
478 |
self updateView |
|
479 |
! |
|
480 |
||
481 |
hideDead:aBoolean |
|
482 |
hideDead := aBoolean |
|
483 |
! |
|
484 |
||
485 |
inspectProcess |
|
486 |
"open an inspector on the selected process" |
|
487 |
||
488 |
self selectedProcessesSend:#inspect |
|
489 |
! |
|
490 |
||
491 |
lowerPrio |
|
492 |
"lower the selected processes priority" |
|
493 |
||
494 |
self selectedProcessesDo:[:p | |
|
495 |
p priority:(p priority - 1) |
|
496 |
] |
|
497 |
! |
|
498 |
||
85 | 499 |
processMenu |
500 |
|labels selectors m| |
|
501 |
||
109 | 502 |
device ctrlDown ifTrue:[ |
110 | 503 |
labels := resources array:#( |
109 | 504 |
'\c detail' |
505 |
). |
|
506 |
selectors := #( |
|
507 |
detail |
|
508 |
). |
|
509 |
] ifFalse:[ |
|
510 |
labels := resources array:#( |
|
511 |
'inspect' |
|
512 |
'debug' |
|
513 |
'-' |
|
514 |
'resume' |
|
515 |
'suspend' |
|
516 |
'stop' |
|
517 |
'abort' |
|
518 |
'terminate' |
|
519 |
'-' |
|
520 |
'raise prio' |
|
521 |
'lower prio' |
|
522 |
). |
|
523 |
selectors := #( |
|
524 |
inspectProcess |
|
525 |
debugProcess |
|
526 |
nil |
|
527 |
resumeProcess |
|
528 |
suspendProcess |
|
529 |
stopProcess |
|
530 |
abortProcess |
|
531 |
terminateProcess |
|
532 |
nil |
|
533 |
raisePrio |
|
534 |
lowerPrio |
|
535 |
). |
|
536 |
updateProcess isNil ifTrue:[ |
|
537 |
labels := (resources array:#('update' '-')) , labels. |
|
538 |
selectors := #(updateView nil) , selectors |
|
539 |
]. |
|
85 | 540 |
]. |
541 |
||
542 |
m := PopUpMenu labels:labels |
|
90 | 543 |
selectors:selectors. |
85 | 544 |
|
109 | 545 |
m checkToggleAt:#detail put:showDetail. |
85 | 546 |
^ m |
547 |
! |
|
19 | 548 |
|
208 | 549 |
raisePrio |
550 |
"raise the selected processes priority" |
|
143 | 551 |
|
552 |
self selectedProcessesDo:[:p | |
|
208 | 553 |
p priority:(p priority + 1) |
143 | 554 |
] |
555 |
! |
|
556 |
||
557 |
resumeProcess |
|
558 |
"resume the selected process (i.e. let it run) " |
|
559 |
||
560 |
self selectedProcessesSend:#resume |
|
561 |
! |
|
562 |
||
92 | 563 |
stopProcess |
564 |
"stop the selected process - not even interrupts will wake it up" |
|
565 |
||
566 |
self selectedProcessesSend:#stop |
|
567 |
! |
|
568 |
||
19 | 569 |
suspendProcess |
92 | 570 |
"suspend the selected process - interrupts will let it run again" |
571 |
||
58 | 572 |
self selectedProcessesSend:#suspend |
85 | 573 |
! |
45 | 574 |
|
208 | 575 |
terminateProcess |
576 |
"terminate the selected process" |
|
92 | 577 |
|
208 | 578 |
self selectedProcessesSend:#terminate |
19 | 579 |
! ! |
580 |
||
143 | 581 |
!ProcessMonitor methodsFor:'private'! |
582 |
||
583 |
selectedProcessesDo:aBlock |
|
584 |
|p nr sel| |
|
85 | 585 |
|
143 | 586 |
sel := listView selection. |
587 |
sel isNil ifTrue:[^ self]. |
|
588 |
(sel isKindOf:Collection) ifTrue:[ |
|
589 |
sel do:[:n | |
|
590 |
nr := n - 2. "for headlines" |
|
591 |
nr notNil ifTrue:[ |
|
592 |
nr > 0 ifTrue:[ |
|
593 |
p := processes at:nr. |
|
594 |
p notNil ifTrue:[ |
|
595 |
aBlock value:p |
|
596 |
] |
|
597 |
] |
|
598 |
] |
|
599 |
] |
|
85 | 600 |
] ifFalse:[ |
143 | 601 |
nr := sel - 2. "for headlines" |
602 |
nr notNil ifTrue:[ |
|
603 |
nr > 0 ifTrue:[ |
|
604 |
p := processes at:nr. |
|
605 |
p notNil ifTrue:[ |
|
606 |
aBlock value:p |
|
607 |
] |
|
608 |
] |
|
609 |
] |
|
85 | 610 |
]. |
143 | 611 |
! |
612 |
||
613 |
selectedProcessesSend:aSelector |
|
614 |
self selectedProcessesDo:[:p | |
|
615 |
p perform:aSelector |
|
616 |
]. |
|
617 |
self updateView. |
|
85 | 618 |
! ! |
619 |
||
620 |
!ProcessMonitor methodsFor:'queries'! |
|
621 |
||
105 | 622 |
preferredExtent |
85 | 623 |
^ (font widthOf:self titleLine) + 40 @ 100 |
624 |
! ! |
|
208 | 625 |
|
626 |
!ProcessMonitor class methodsFor:'documentation'! |
|
627 |
||
628 |
version |
|
478 | 629 |
^ '$Header: /cvs/stx/stx/libtool/ProcessMonitor.st,v 1.34 1996-04-13 22:21:25 cg Exp $'! ! |