author | Claus Gittinger <cg@exept.de> |
Fri, 16 Dec 2016 13:00:39 +0100 | |
changeset 17169 | 91a80ba50915 |
parent 14202 | 336beb9d98f6 |
child 17215 | 4a42de8e888a |
child 17226 | 66b523a67429 |
permissions | -rw-r--r-- |
980 | 1 |
" |
2 |
COPYRIGHT (c) 1997 by Claus Gittinger |
|
14202 | 3 |
All Rights Reserved |
980 | 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 |
" |
|
4253 | 12 |
"{ Package: 'stx:libtool' }" |
13 |
||
17169 | 14 |
"{ NameSpace: Smalltalk }" |
15 |
||
982 | 16 |
SystemStatusMonitor subclass:#SemaphoreMonitor |
980 | 17 |
instanceVariableNames:'semaphores' |
18 |
classVariableNames:'' |
|
19 |
poolDictionaries:'' |
|
1053 | 20 |
category:'Monitors-ST/X' |
980 | 21 |
! |
22 |
||
23 |
!SemaphoreMonitor class methodsFor:'documentation'! |
|
24 |
||
25 |
copyright |
|
26 |
" |
|
27 |
COPYRIGHT (c) 1997 by Claus Gittinger |
|
14202 | 28 |
All Rights Reserved |
980 | 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 |
! |
|
40 |
||
41 |
documentation |
|
42 |
" |
|
17169 | 43 |
This view shows smalltalk's semaphores - a debugging tool. |
980 | 44 |
|
17169 | 45 |
[disclaimer:] |
46 |
this is 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 |
||
980 | 49 |
[see also:] |
17169 | 50 |
Semaphore SemaphoreSet |
51 |
Process ProcessorScheduler |
|
52 |
WindowGroup |
|
53 |
ProcessMonitor |
|
980 | 54 |
|
55 |
[author:] |
|
17169 | 56 |
Claus Gittinger |
980 | 57 |
|
58 |
[start with:] |
|
17169 | 59 |
SemaphoreMonitor open |
980 | 60 |
" |
61 |
! ! |
|
62 |
||
63 |
!SemaphoreMonitor class methodsFor:'defaults'! |
|
64 |
||
65 |
defaultLabel |
|
66 |
^ 'Semaphore Monitor' |
|
67 |
||
68 |
"Created: 23.1.1997 / 02:52:53 / cg" |
|
69 |
! ! |
|
70 |
||
71 |
!SemaphoreMonitor methodsFor:'drawing'! |
|
72 |
||
73 |
titleLine |
|
4253 | 74 |
^ ' Id Name Count Owner Waiting Process(es) '. |
980 | 75 |
|
76 |
" |
|
77 |
SemaphoreMonitor open |
|
78 |
" |
|
79 |
||
1692 | 80 |
"Modified: / 17.6.1998 / 14:52:48 / cg" |
980 | 81 |
! |
82 |
||
83 |
updateList |
|
84 |
"update list of semaphores" |
|
85 |
||
86 |
|newList| |
|
87 |
||
88 |
shown ifTrue:[ |
|
14202 | 89 |
newList := Semaphore allSubInstances. |
980 | 90 |
|
14202 | 91 |
"sort by hashKey - will not always generate unique numbers, |
92 |
but most of the time, this works ... for now" |
|
980 | 93 |
|
14202 | 94 |
newList sort:[:s1 :s2 | s1 identityHash < s2 identityHash]. |
980 | 95 |
|
14202 | 96 |
newList ~= semaphores ifTrue:[ |
97 |
self updateStatus:newList |
|
98 |
]. |
|
980 | 99 |
]. |
100 |
updateBlock notNil ifTrue:[ |
|
14202 | 101 |
Processor removeTimedBlock:listUpdateBlock. |
102 |
Processor addTimedBlock:listUpdateBlock afterSeconds:listUpdateDelay |
|
980 | 103 |
]. |
104 |
||
2487
4ac80975b91d
avoid loosing the selection when the list is updated
Claus Gittinger <cg@exept.de>
parents:
1838
diff
changeset
|
105 |
"Modified: / 3.7.1996 / 13:37:29 / stefan" |
4ac80975b91d
avoid loosing the selection when the list is updated
Claus Gittinger <cg@exept.de>
parents:
1838
diff
changeset
|
106 |
"Created: / 23.1.1997 / 02:44:48 / cg" |
4ac80975b91d
avoid loosing the selection when the list is updated
Claus Gittinger <cg@exept.de>
parents:
1838
diff
changeset
|
107 |
"Modified: / 14.12.1999 / 20:52:44 / cg" |
980 | 108 |
! |
109 |
||
2487
4ac80975b91d
avoid loosing the selection when the list is updated
Claus Gittinger <cg@exept.de>
parents:
1838
diff
changeset
|
110 |
updateStatus:newSemaphoreList |
980 | 111 |
"update status display of semaphores" |
112 |
||
1692 | 113 |
|oldList list oldSelection newSelection| |
980 | 114 |
|
115 |
shown ifTrue:[ |
|
17169 | 116 |
oldList := listView list. |
117 |
oldSelection := listView selectionValue. |
|
118 |
oldSelection notNil ifTrue:[ |
|
119 |
oldSelection := oldSelection collect:[:line | line asCollectionOfWords first asNumber]. |
|
120 |
newSelection := OrderedCollection new. |
|
121 |
]. |
|
980 | 122 |
|
17169 | 123 |
newSemaphoreList notNil ifTrue:[ |
124 |
semaphores := WeakArray withAll:newSemaphoreList. |
|
125 |
]. |
|
126 |
semaphores notNil ifTrue:[ |
|
127 |
list := OrderedCollection new:(semaphores size + self numberOfHeadlines). |
|
128 |
list add:self titleLine. |
|
129 |
list add:(String new:self titleLine size withAll:$-). |
|
980 | 130 |
|
17169 | 131 |
semaphores validElementsDo:[:aSemaphore | |
132 |
|waiters waitersNames nm id str owner color line count| |
|
980 | 133 |
|
17169 | 134 |
"/ need a copy - it may change while being enumerated |
135 |
[ |
|
136 |
count := aSemaphore count. |
|
137 |
waiters := aSemaphore waitingProcesses copy. |
|
138 |
] valueUninterruptably. |
|
980 | 139 |
|
17169 | 140 |
str := '' writeStream. |
141 |
[ |
|
142 |
waiters notNil ifTrue:[ |
|
143 |
waiters do:[:aProcess | |
|
144 |
str nextPut:$[. |
|
145 |
aProcess id printOn:str. |
|
146 |
str nextPutAll:' '''. |
|
147 |
str nextPutAll:(aProcess name contractTo:40). |
|
148 |
str nextPutAll:'''<'. |
|
149 |
aProcess priority printOn:str. |
|
150 |
str nextPutAll:'>]'. |
|
151 |
str space. |
|
152 |
]. |
|
153 |
] |
|
154 |
] valueUninterruptably. |
|
155 |
waitersNames := str contents. |
|
980 | 156 |
|
17169 | 157 |
(aSemaphore respondsTo:#name) ifTrue:[ |
158 |
nm := aSemaphore name. |
|
159 |
nm isNil ifTrue:[ |
|
160 |
nm := '' |
|
161 |
] |
|
162 |
] ifFalse:[ |
|
163 |
nm := '' |
|
164 |
]. |
|
165 |
id := aSemaphore identityHash bitShift:-12. |
|
166 |
owner := aSemaphore lastOwnerId. |
|
167 |
owner isNil ifTrue:[ |
|
168 |
owner := ' ' |
|
169 |
] ifFalse:[ |
|
170 |
owner := owner printStringLeftPaddedTo:5 |
|
171 |
]. |
|
172 |
line := (id printStringPaddedTo:6) |
|
173 |
, ' ' |
|
174 |
, ((nm contractTo:25) paddedTo:25) |
|
175 |
, ' ' |
|
176 |
, (count printStringLeftPaddedTo:3) |
|
177 |
, ' ' |
|
178 |
, owner printString |
|
179 |
, ' ' |
|
180 |
, (waiters size printStringLeftPaddedTo:3) |
|
181 |
, ' ' |
|
182 |
, waitersNames. |
|
12399 | 183 |
|
17169 | 184 |
count > 0 ifTrue:[ |
185 |
waiters size > 0 ifTrue:[ |
|
186 |
"this happens if a low priority process is ready to run but didn't wake up yet" |
|
187 |
color := Color red. |
|
12399 | 188 |
"/ self beep. |
17169 | 189 |
] ifFalse:[ |
190 |
"fine, this semaphore is available" |
|
191 |
color := Color blue. |
|
192 |
]. |
|
193 |
line := line colorizeAllWith:color. |
|
194 |
] ifFalse:[ |
|
195 |
waiters size > 0 ifTrue:[ |
|
196 |
line := line colorizeAllWith:Color brown. |
|
197 |
]. |
|
198 |
]. |
|
14202 | 199 |
|
17169 | 200 |
list add:line. |
201 |
oldSelection notNil ifTrue:[ |
|
202 |
(oldSelection includes:id) ifTrue:[ |
|
203 |
newSelection add:list size. |
|
204 |
] |
|
205 |
] |
|
206 |
]. |
|
207 |
]. |
|
208 |
"avoid flicker" |
|
209 |
(oldList notNil and:[oldList size == list size]) ifTrue:[ |
|
210 |
list keysAndValuesDo:[:idx :entry | |
|
211 |
(oldList at:idx) ~= entry ifTrue:[ |
|
212 |
listView at:idx put:entry |
|
213 |
] |
|
214 |
] |
|
215 |
] ifFalse:[ |
|
216 |
listView setList:list. |
|
217 |
"the first two entries cannot be selected" |
|
218 |
listView attributeAt:1 put:#disabled. |
|
219 |
listView attributeAt:2 put:#disabled. |
|
220 |
]. |
|
221 |
newSelection notNil ifTrue:[ |
|
222 |
listView selectWithoutScroll:newSelection |
|
223 |
]. |
|
224 |
listView flush |
|
980 | 225 |
]. |
226 |
updateBlock notNil ifTrue:[ |
|
17169 | 227 |
Processor removeTimedBlock:updateBlock. |
228 |
Processor addTimedBlock:updateBlock afterSeconds:updateDelay |
|
980 | 229 |
] |
230 |
||
1692 | 231 |
"Modified: / 3.7.1996 / 13:56:01 / stefan" |
2487
4ac80975b91d
avoid loosing the selection when the list is updated
Claus Gittinger <cg@exept.de>
parents:
1838
diff
changeset
|
232 |
"Created: / 14.12.1999 / 20:52:29 / cg" |
4ac80975b91d
avoid loosing the selection when the list is updated
Claus Gittinger <cg@exept.de>
parents:
1838
diff
changeset
|
233 |
"Modified: / 14.12.1999 / 20:53:14 / cg" |
980 | 234 |
! ! |
235 |
||
236 |
!SemaphoreMonitor methodsFor:'menu'! |
|
237 |
||
1692 | 238 |
debugWaiters |
239 |
"open a debugger on the selected semaphores waiting processes" |
|
240 |
||
14202 | 241 |
self selectedSemaphoresDo:[:aSema | |
242 |
aSema waitingProcesses do:[:aProcess | |
|
243 |
DebugView openOn:aProcess |
|
244 |
] |
|
1692 | 245 |
] |
246 |
||
247 |
"Modified: / 23.1.1997 / 03:12:06 / cg" |
|
248 |
"Created: / 17.6.1998 / 14:56:55 / cg" |
|
249 |
! |
|
250 |
||
995 | 251 |
inspectSemaphore |
980 | 252 |
"open an inspector on the selected semaphores" |
253 |
||
254 |
self selectedSemaphoresDo:[:aSema | aSema inspect] |
|
255 |
||
256 |
"Modified: 23.1.1997 / 03:12:06 / cg" |
|
995 | 257 |
"Created: 24.1.1997 / 23:11:50 / cg" |
980 | 258 |
! |
259 |
||
1692 | 260 |
inspectWaiters |
261 |
"open an inspector on the selected semaphores waiting processes" |
|
262 |
||
14202 | 263 |
self selectedSemaphoresDo:[:aSema | |
264 |
aSema waitingProcesses do:[:aProcess | |
|
265 |
aProcess inspect |
|
266 |
] |
|
1692 | 267 |
] |
268 |
||
269 |
"Modified: / 23.1.1997 / 03:12:06 / cg" |
|
270 |
"Created: / 17.6.1998 / 14:17:41 / cg" |
|
271 |
! |
|
272 |
||
980 | 273 |
selectedSemaphoresDo:aBlock |
274 |
"evaluate aBlock on all selected semaphores" |
|
275 |
||
276 |
|p nr sel| |
|
277 |
||
278 |
sel := listView selection. |
|
279 |
sel isNil ifTrue:[^ self]. |
|
280 |
||
281 |
(sel isKindOf:Collection) ifTrue:[ |
|
17169 | 282 |
sel do:[:n | |
283 |
nr := n - self numberOfHeadlines. |
|
284 |
nr notNil ifTrue:[ |
|
285 |
nr > 0 ifTrue:[ |
|
286 |
p := semaphores at:nr. |
|
287 |
(p notNil and:[p ~~ 0]) ifTrue:[ |
|
288 |
aBlock value:p |
|
289 |
] |
|
290 |
] |
|
291 |
] |
|
292 |
] |
|
980 | 293 |
] ifFalse:[ |
17169 | 294 |
nr := sel - self numberOfHeadlines. |
295 |
nr notNil ifTrue:[ |
|
296 |
nr > 0 ifTrue:[ |
|
297 |
p := semaphores at:nr. |
|
298 |
(p notNil and:[p ~~ 0]) ifTrue:[ |
|
299 |
aBlock value:p |
|
300 |
] |
|
301 |
] |
|
302 |
] |
|
980 | 303 |
]. |
304 |
||
305 |
"Created: 23.1.1997 / 03:11:24 / cg" |
|
306 |
! |
|
307 |
||
308 |
signalSemaphore |
|
309 |
"signal all selected semaphores" |
|
310 |
||
311 |
self selectedSemaphoresDo:[:aSema | aSema signal] |
|
312 |
||
313 |
"Created: 23.1.1997 / 03:12:30 / cg" |
|
314 |
! |
|
315 |
||
316 |
statusMenu |
|
317 |
"return a popUpMenu" |
|
318 |
||
1692 | 319 |
<resource: #programMenu> |
320 |
||
4253 | 321 |
|labels selectors m| |
980 | 322 |
|
323 |
labels := resources array:#( |
|
14202 | 324 |
'Inspect' |
325 |
'Inspect Waiters' |
|
326 |
'Debug Waiters' |
|
327 |
'-' |
|
328 |
'Signal' |
|
329 |
). |
|
980 | 330 |
selectors := #( |
14202 | 331 |
inspectSemaphore |
332 |
inspectWaiters |
|
333 |
debugWaiters |
|
334 |
nil |
|
335 |
signalSemaphore |
|
336 |
). |
|
980 | 337 |
|
338 |
updateProcess isNil ifTrue:[ |
|
14202 | 339 |
labels := (resources array:#('Update' '-')) , labels. |
340 |
selectors := #(updateView nil) , selectors |
|
980 | 341 |
]. |
342 |
||
343 |
m := PopUpMenu labels:labels |
|
14202 | 344 |
selectors:selectors. |
980 | 345 |
|
346 |
||
347 |
listView hasSelection ifFalse:[ |
|
14202 | 348 |
m disableAll:#( |
349 |
inspectSemaphore |
|
350 |
signalSemaphore |
|
351 |
) |
|
980 | 352 |
]. |
353 |
^ m |
|
354 |
||
1692 | 355 |
"Modified: / 17.6.1998 / 14:17:05 / cg" |
980 | 356 |
! ! |
357 |
||
358 |
!SemaphoreMonitor methodsFor:'queries'! |
|
359 |
||
17169 | 360 |
numberOfHeadlines |
361 |
^ 2 |
|
980 | 362 |
! ! |
363 |
||
364 |
!SemaphoreMonitor methodsFor:'user actions'! |
|
365 |
||
366 |
doubleClicked |
|
367 |
"open an inspector on the selected semaphore" |
|
368 |
||
1023 | 369 |
self inspectSemaphore |
980 | 370 |
|
371 |
"Created: 23.1.1997 / 03:22:04 / cg" |
|
1023 | 372 |
"Modified: 31.1.1997 / 22:33:27 / cg" |
980 | 373 |
! ! |
374 |
||
375 |
!SemaphoreMonitor class methodsFor:'documentation'! |
|
376 |
||
377 |
version |
|
17169 | 378 |
^ '$Header$' |
980 | 379 |
! ! |
12399 | 380 |