19046
|
1 |
"
|
|
2 |
COPYRIGHT (c) 2019 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 |
"{ Package: 'stx:libtool' }"
|
|
13 |
|
|
14 |
"{ NameSpace: Smalltalk }"
|
|
15 |
|
|
16 |
SystemStatusMonitor subclass:#OSProcessMonitor
|
19164
|
17 |
instanceVariableNames:'processes showTime filterLiveProcessesOnlyHolder'
|
19046
|
18 |
classVariableNames:''
|
|
19 |
poolDictionaries:''
|
|
20 |
category:'Monitors-ST/X'
|
|
21 |
!
|
|
22 |
|
|
23 |
!OSProcessMonitor class methodsFor:'documentation'!
|
|
24 |
|
|
25 |
copyright
|
|
26 |
"
|
|
27 |
COPYRIGHT (c) 2019 by Claus Gittinger
|
|
28 |
All Rights Reserved
|
|
29 |
|
|
30 |
This software is furnished under a license and may be used
|
|
31 |
only in accordance with the terms of that license and with the
|
|
32 |
inclusion of the above copyright notice. This software may not
|
|
33 |
be provided or otherwise made available to, or used by, any
|
|
34 |
other person. No title to or ownership of the software is
|
|
35 |
hereby transferred.
|
|
36 |
"
|
|
37 |
!
|
|
38 |
|
|
39 |
documentation
|
|
40 |
"
|
|
41 |
This view shows OS processes started by smalltalk - a debugging tool.
|
|
42 |
|
|
43 |
[disclaimer:]
|
|
44 |
this is based on one of the oldest tools in the system, written in the early 90's.
|
|
45 |
It does in no way reflect the way GUIs are designed/written these days.
|
19112
|
46 |
However, after all those years, they are still very very useful (and not found in many other systems)
|
19046
|
47 |
|
|
48 |
[see also:]
|
|
49 |
OSProcess
|
|
50 |
|
|
51 |
[author:]
|
|
52 |
Claus Gittinger
|
|
53 |
|
|
54 |
[start with:]
|
|
55 |
OSProcessMonitor open
|
|
56 |
"
|
|
57 |
! !
|
|
58 |
|
|
59 |
!OSProcessMonitor class methodsFor:'defaults'!
|
|
60 |
|
|
61 |
defaultLabel
|
|
62 |
^ 'OS Process Monitor'
|
|
63 |
|
|
64 |
"Created: 23.1.1997 / 02:52:53 / cg"
|
|
65 |
! !
|
|
66 |
|
|
67 |
!OSProcessMonitor class methodsFor:'menu specs'!
|
|
68 |
|
19164
|
69 |
filterMenu
|
|
70 |
"This resource specification was automatically generated
|
|
71 |
by the MenuEditor of ST/X."
|
|
72 |
|
|
73 |
"Do not manually edit this!! If it is corrupted,
|
|
74 |
the MenuEditor may not be able to read the specification."
|
|
75 |
|
|
76 |
|
|
77 |
"
|
|
78 |
MenuEditor new openOnClass:ExternalStreamMonitor andSelector:#filterMenu
|
|
79 |
(Menu new fromLiteralArrayEncoding:(ExternalStreamMonitor filterMenu)) startUp
|
|
80 |
"
|
|
81 |
|
|
82 |
<resource: #menu>
|
|
83 |
|
|
84 |
^
|
|
85 |
#(Menu
|
|
86 |
(
|
|
87 |
(MenuItem
|
|
88 |
label: 'Live Processes Only'
|
|
89 |
indication: filterLiveProcessesOnlyHolder
|
|
90 |
)
|
|
91 |
)
|
|
92 |
nil
|
|
93 |
nil
|
|
94 |
)
|
|
95 |
!
|
|
96 |
|
19046
|
97 |
mainMenu
|
|
98 |
"This resource specification was automatically generated
|
|
99 |
by the MenuEditor of ST/X."
|
|
100 |
|
|
101 |
"Do not manually edit this!! If it is corrupted,
|
|
102 |
the MenuEditor may not be able to read the specification."
|
|
103 |
|
|
104 |
|
|
105 |
"
|
|
106 |
MenuEditor new openOnClass:OSProcessMonitor andSelector:#mainMenu
|
|
107 |
(Menu new fromLiteralArrayEncoding:(OSProcessMonitor mainMenu)) startUp
|
|
108 |
"
|
|
109 |
|
|
110 |
<resource: #menu>
|
|
111 |
|
|
112 |
^
|
|
113 |
#(Menu
|
|
114 |
(MenuItem
|
|
115 |
label: 'File'
|
|
116 |
submenuChannel: fileMenu
|
|
117 |
)
|
|
118 |
(MenuItem
|
|
119 |
label: 'View'
|
|
120 |
submenuChannel: viewMenu
|
|
121 |
)
|
19164
|
122 |
(MenuItem
|
|
123 |
label: 'Filter'
|
|
124 |
submenuChannel: filterMenu
|
|
125 |
)
|
19046
|
126 |
(MenuItem
|
|
127 |
label: 'Operations'
|
|
128 |
submenuChannel: operationsMenu
|
|
129 |
)
|
|
130 |
)
|
|
131 |
!
|
|
132 |
|
|
133 |
operationsMenu
|
|
134 |
"This resource specification was automatically generated
|
|
135 |
by the MenuEditor of ST/X."
|
|
136 |
|
|
137 |
"Do not manually edit this!! If it is corrupted,
|
|
138 |
the MenuEditor may not be able to read the specification."
|
|
139 |
|
|
140 |
|
|
141 |
"
|
|
142 |
MenuEditor new openOnClass:ExternalStreamMonitor andSelector:#operationsMenu
|
|
143 |
(Menu new fromLiteralArrayEncoding:(ExternalStreamMonitor operationsMenu)) startUp
|
|
144 |
"
|
|
145 |
|
|
146 |
<resource: #menu>
|
|
147 |
|
|
148 |
^
|
|
149 |
#(Menu
|
|
150 |
(
|
|
151 |
(MenuItem
|
|
152 |
label: 'Terminate'
|
|
153 |
itemValue: menuTerminateSelected
|
19345
|
154 |
enabled: hasSelection
|
|
155 |
)
|
|
156 |
(MenuItem
|
|
157 |
label: 'Terminate Group'
|
|
158 |
itemValue: menuTerminateSelectedGroup
|
|
159 |
enabled: hasSelection
|
19046
|
160 |
)
|
|
161 |
(MenuItem
|
|
162 |
label: '-'
|
|
163 |
)
|
|
164 |
(MenuItem
|
|
165 |
label: 'Inspect'
|
|
166 |
itemValue: inspectProcess
|
19345
|
167 |
enabled: hasSelection
|
19046
|
168 |
)
|
|
169 |
(MenuItem
|
|
170 |
label: 'Owners'
|
|
171 |
itemValue: inspectOwners
|
19345
|
172 |
enabled: hasSelection
|
19046
|
173 |
)
|
|
174 |
)
|
|
175 |
nil
|
|
176 |
nil
|
|
177 |
)
|
|
178 |
! !
|
|
179 |
|
19164
|
180 |
!OSProcessMonitor methodsFor:'aspects'!
|
|
181 |
|
|
182 |
filterLiveProcessesOnlyHolder
|
|
183 |
filterLiveProcessesOnlyHolder isNil ifTrue:[
|
|
184 |
filterLiveProcessesOnlyHolder := true asValue.
|
|
185 |
filterLiveProcessesOnlyHolder onChangeSend:#filterHolderChanged to:self.
|
|
186 |
].
|
|
187 |
^ filterLiveProcessesOnlyHolder
|
|
188 |
! !
|
|
189 |
|
19046
|
190 |
!OSProcessMonitor methodsFor:'drawing'!
|
|
191 |
|
|
192 |
titleLine
|
|
193 |
"/ 123456789|12345|1234567890
|
|
194 |
^ 'PID Status Command '.
|
|
195 |
|
|
196 |
"
|
|
197 |
OSProcessMonitor open
|
|
198 |
"
|
|
199 |
|
|
200 |
"Modified: / 17-06-1998 / 14:52:48 / cg"
|
|
201 |
"Modified: / 29-10-2018 / 15:28:22 / Claus Gittinger"
|
|
202 |
!
|
|
203 |
|
|
204 |
updateList
|
|
205 |
"update list of processes"
|
|
206 |
|
|
207 |
|newList|
|
|
208 |
|
|
209 |
shown ifTrue:[
|
19156
|
210 |
newList := OSProcess allSubInstances select:[:p | p pid notNil].
|
19164
|
211 |
self filterLiveProcessesOnlyHolder value ifTrue:[
|
|
212 |
newList := newList select:[:p | p isAlive].
|
|
213 |
].
|
19341
|
214 |
newList sort:[:a :b | a numericPid < b numericPid].
|
19046
|
215 |
|
|
216 |
newList ~= processes ifTrue:[
|
|
217 |
self updateStatus:newList
|
|
218 |
].
|
|
219 |
].
|
|
220 |
self installDelayedUpdate.
|
|
221 |
|
|
222 |
"Modified: / 29-10-2018 / 15:39:43 / Claus Gittinger"
|
|
223 |
!
|
|
224 |
|
|
225 |
updateStatus:newList
|
|
226 |
"update status display of processes"
|
|
227 |
|
19055
|
228 |
|numberOfHeadlines oldList list oldSelection newSelection|
|
19046
|
229 |
|
|
230 |
shown ifTrue:[
|
19055
|
231 |
numberOfHeadlines := self numberOfHeadlines.
|
|
232 |
|
19046
|
233 |
oldList := listView list.
|
|
234 |
oldSelection := listView selection.
|
|
235 |
oldSelection notNil ifTrue:[
|
|
236 |
oldSelection := oldSelection
|
19055
|
237 |
select:[:lineNr | lineNr > numberOfHeadlines]
|
|
238 |
thenCollect:[:lineNr |
|
|
239 |
processes at:(lineNr - numberOfHeadlines) ifAbsent:nil
|
19046
|
240 |
].
|
|
241 |
newSelection := OrderedCollection new.
|
|
242 |
].
|
|
243 |
|
|
244 |
newList notNil ifTrue:[
|
|
245 |
processes := WeakArray withAll:newList.
|
|
246 |
].
|
|
247 |
processes notNil ifTrue:[
|
19055
|
248 |
list := OrderedCollection new:(processes size + numberOfHeadlines).
|
19111
|
249 |
showTime == true ifTrue:[
|
|
250 |
list add:'Time: ',(Time now printString).
|
|
251 |
].
|
19046
|
252 |
list add:self titleLine.
|
|
253 |
list add:(String new:(self titleLine size+20) withAll:$-).
|
|
254 |
|
|
255 |
processes validElementsDo:[:process |
|
|
256 |
|waiters waitersNames type globalNameOrNil handleString
|
|
257 |
isOpen handle detail color line status exitCode|
|
|
258 |
|
|
259 |
(status := process exitStatus) notNil ifTrue:[
|
|
260 |
exitCode := status code.
|
|
261 |
].
|
|
262 |
|
|
263 |
line := (process pid printString) paddedTo:9.
|
|
264 |
line := line , ' '.
|
|
265 |
line := line , ((exitCode isNil ifTrue:[''] ifFalse:[exitCode printString]) paddedTo:4).
|
|
266 |
line := line , ' '.
|
19060
|
267 |
line := line , (process commandString).
|
19046
|
268 |
|
19059
|
269 |
process isAlive ifFalse:[
|
|
270 |
status success ifTrue:[
|
|
271 |
color := Color grey.
|
|
272 |
] ifFalse:[
|
|
273 |
color := Color red.
|
|
274 |
].
|
|
275 |
line := line withColor:color.
|
|
276 |
].
|
19046
|
277 |
|
|
278 |
list add:line.
|
|
279 |
oldSelection notNil ifTrue:[
|
|
280 |
(oldSelection includesIdentical:process) ifTrue:[
|
|
281 |
newSelection add:list size.
|
|
282 |
]
|
|
283 |
]
|
|
284 |
].
|
|
285 |
].
|
|
286 |
"avoid flicker"
|
|
287 |
(oldList notNil and:[oldList size == list size]) ifTrue:[
|
|
288 |
list keysAndValuesDo:[:idx :entry |
|
|
289 |
(oldList at:idx) ~= entry ifTrue:[
|
|
290 |
listView at:idx put:entry
|
|
291 |
]
|
|
292 |
]
|
|
293 |
] ifFalse:[
|
|
294 |
listView setList:list.
|
19055
|
295 |
"the first few entries cannot be selected"
|
|
296 |
1 to:numberOfHeadlines do:[:lNr |
|
|
297 |
listView attributeAt:numberOfHeadlines put:#disabled.
|
|
298 |
].
|
19046
|
299 |
].
|
|
300 |
newSelection notNil ifTrue:[
|
|
301 |
listView selectWithoutScroll:newSelection
|
|
302 |
].
|
|
303 |
listView flush
|
|
304 |
].
|
|
305 |
self installDelayedUpdate.
|
|
306 |
|
|
307 |
"Modified: / 11-10-2017 / 13:56:14 / cg"
|
|
308 |
"Modified: / 07-06-2019 / 22:10:36 / Claus Gittinger"
|
|
309 |
! !
|
|
310 |
|
|
311 |
!OSProcessMonitor methodsFor:'menu'!
|
|
312 |
|
|
313 |
selectedProcesses
|
|
314 |
"return all selected streams"
|
|
315 |
|
|
316 |
^ Array streamContents:[:s |
|
|
317 |
self selectedProcessesDo:[:each | s nextPut:each]
|
|
318 |
].
|
|
319 |
|
|
320 |
"Created: / 29-10-2018 / 17:00:35 / Claus Gittinger"
|
|
321 |
!
|
|
322 |
|
|
323 |
selectedProcessesDo:aBlock
|
|
324 |
"evaluate aBlock on all selected streams"
|
|
325 |
|
|
326 |
self selectionIndicesDo:[:n |
|
|
327 |
|nr process|
|
|
328 |
|
|
329 |
nr := n - self numberOfHeadlines.
|
|
330 |
nr notNil ifTrue:[
|
|
331 |
nr > 0 ifTrue:[
|
|
332 |
process := processes at:nr.
|
|
333 |
(process notNil and:[process ~~ 0]) ifTrue:[
|
|
334 |
aBlock value:process
|
|
335 |
]
|
|
336 |
]
|
|
337 |
]
|
|
338 |
].
|
|
339 |
!
|
|
340 |
|
|
341 |
statusMenu
|
|
342 |
"return a popUpMenu"
|
|
343 |
|
|
344 |
<resource: #programMenu>
|
|
345 |
|
|
346 |
|labels selectors m|
|
|
347 |
|
|
348 |
labels := resources array:#(
|
|
349 |
'Terminate'
|
19177
|
350 |
'Terminate Group'
|
19046
|
351 |
'-'
|
|
352 |
'Inspect'
|
|
353 |
'References'
|
|
354 |
).
|
|
355 |
selectors := #(
|
|
356 |
menuTerminateSelected
|
19177
|
357 |
menuTerminateSelectedGroup
|
19046
|
358 |
nil
|
|
359 |
inspectProcess
|
|
360 |
menuReferences
|
|
361 |
).
|
|
362 |
|
|
363 |
updateProcess isNil ifTrue:[
|
|
364 |
labels := labels,(resources array:#('-' 'Update' )).
|
|
365 |
selectors := selectors , #(nil updateView).
|
|
366 |
].
|
|
367 |
|
|
368 |
m := PopUpMenu labels:labels
|
|
369 |
selectors:selectors.
|
|
370 |
|
|
371 |
|
|
372 |
listView hasSelection ifFalse:[
|
|
373 |
m disableAll:#(
|
|
374 |
menuCloseSelected
|
|
375 |
inspectStream
|
|
376 |
)
|
|
377 |
].
|
|
378 |
^ m
|
|
379 |
|
|
380 |
"Modified: / 18-08-2017 / 14:34:12 / cg"
|
|
381 |
! !
|
|
382 |
|
|
383 |
!OSProcessMonitor methodsFor:'queries'!
|
|
384 |
|
|
385 |
numberOfHeadlines
|
19111
|
386 |
^ 2 + (showTime == true ifTrue:1 ifFalse:0)
|
19046
|
387 |
|
|
388 |
"Modified: / 29-10-2018 / 15:24:14 / Claus Gittinger"
|
|
389 |
! !
|
|
390 |
|
|
391 |
!OSProcessMonitor methodsFor:'user actions'!
|
|
392 |
|
|
393 |
doubleClicked
|
|
394 |
"open an inspector on the selected process"
|
|
395 |
|
|
396 |
self inspectProcess
|
|
397 |
|
|
398 |
"Created: / 23-01-1997 / 03:22:04 / cg"
|
|
399 |
"Modified: / 31-01-1997 / 22:33:27 / cg"
|
|
400 |
"Modified (comment): / 07-04-2017 / 14:28:01 / cg"
|
|
401 |
!
|
|
402 |
|
19164
|
403 |
filterHolderChanged
|
|
404 |
self sensor pushUserEvent:#updateList for:self
|
|
405 |
!
|
|
406 |
|
19046
|
407 |
inspectProcess
|
|
408 |
"open an inspector on the selected process(es)"
|
|
409 |
|
|
410 |
self selectedProcessesDo:[:eachProcess | eachProcess inspect]
|
|
411 |
|
|
412 |
"Modified (format): / 07-04-2017 / 14:27:45 / cg"
|
|
413 |
!
|
|
414 |
|
|
415 |
menuReferences
|
|
416 |
"show references to the selected processes"
|
|
417 |
|
|
418 |
ObjectMemory
|
|
419 |
displayRefChainToAny:(self selectedProcesses)
|
|
420 |
limitNumberOfSearchedReferences:100.
|
|
421 |
|
|
422 |
"Modified (format): / 07-04-2017 / 14:27:45 / cg"
|
|
423 |
"Modified: / 29-10-2018 / 17:01:00 / Claus Gittinger"
|
|
424 |
!
|
|
425 |
|
|
426 |
menuTerminateSelected
|
|
427 |
"close the selected stream(s)"
|
|
428 |
|
|
429 |
self selectedProcessesDo:[:eachProcess | eachProcess terminate].
|
|
430 |
self updateList.
|
|
431 |
|
|
432 |
"Created: / 07-04-2017 / 14:26:04 / cg"
|
19177
|
433 |
!
|
|
434 |
|
|
435 |
menuTerminateSelectedGroup
|
|
436 |
"close the selected stream(s)"
|
|
437 |
|
|
438 |
self selectedProcessesDo:[:eachProcess | eachProcess terminateGroup].
|
|
439 |
self updateList.
|
|
440 |
|
|
441 |
"Created: / 07-04-2017 / 14:26:04 / cg"
|
19046
|
442 |
! !
|
|
443 |
|
|
444 |
!OSProcessMonitor class methodsFor:'documentation'!
|
|
445 |
|
|
446 |
version_CVS
|
|
447 |
^ '$Header$'
|
|
448 |
! !
|
|
449 |
|