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