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