author | Claus Gittinger <cg@exept.de> |
Tue, 14 Dec 1999 21:15:14 +0100 | |
changeset 2487 | 4ac80975b91d |
parent 1838 | 67a4474636c1 |
child 4253 | fb44beaa9aa1 |
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:[ |
|
2487
4ac80975b91d
avoid loosing the selection when the list is updated
Claus Gittinger <cg@exept.de>
parents:
1838
diff
changeset
|
93 |
self updateStatus:newList |
980 | 94 |
]. |
95 |
]. |
|
96 |
updateBlock notNil ifTrue:[ |
|
97 |
Processor removeTimedBlock:listUpdateBlock. |
|
98 |
Processor addTimedBlock:listUpdateBlock afterSeconds:listUpdateDelay |
|
99 |
]. |
|
100 |
||
2487
4ac80975b91d
avoid loosing the selection when the list is updated
Claus Gittinger <cg@exept.de>
parents:
1838
diff
changeset
|
101 |
"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
|
102 |
"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
|
103 |
"Modified: / 14.12.1999 / 20:52:44 / cg" |
980 | 104 |
! |
105 |
||
2487
4ac80975b91d
avoid loosing the selection when the list is updated
Claus Gittinger <cg@exept.de>
parents:
1838
diff
changeset
|
106 |
updateStatus:newSemaphoreList |
980 | 107 |
"update status display of semaphores" |
108 |
||
1692 | 109 |
|oldList list oldSelection newSelection| |
980 | 110 |
|
111 |
shown ifTrue:[ |
|
112 |
oldList := listView list. |
|
1692 | 113 |
oldSelection := listView selectionValue. |
114 |
oldSelection notNil ifTrue:[ |
|
115 |
oldSelection := oldSelection collect:[:line | line asCollectionOfWords first asNumber]. |
|
116 |
newSelection := OrderedCollection new. |
|
117 |
]. |
|
980 | 118 |
|
2487
4ac80975b91d
avoid loosing the selection when the list is updated
Claus Gittinger <cg@exept.de>
parents:
1838
diff
changeset
|
119 |
newSemaphoreList notNil ifTrue:[ |
4ac80975b91d
avoid loosing the selection when the list is updated
Claus Gittinger <cg@exept.de>
parents:
1838
diff
changeset
|
120 |
semaphores := WeakArray withAll:newSemaphoreList. |
4ac80975b91d
avoid loosing the selection when the list is updated
Claus Gittinger <cg@exept.de>
parents:
1838
diff
changeset
|
121 |
]. |
980 | 122 |
semaphores notNil ifTrue:[ |
123 |
list := OrderedCollection new:(semaphores size + 2). |
|
124 |
list add:self titleLine. |
|
125 |
list add:(String new:self titleLine size withAll:$-). |
|
126 |
||
127 |
semaphores validElementsDo:[:aSemaphore | |
|
995 | 128 |
|waiters waitersNames nm id str owner| |
980 | 129 |
|
999 | 130 |
"/ need a copy - it may change while being enumerated |
131 |
||
132 |
waiters := aSemaphore waitingProcesses copy. |
|
980 | 133 |
|
134 |
str := '' writeStream. |
|
1760
07c940be883e
walk waiting-processes list uninterruptable
Claus Gittinger <cg@exept.de>
parents:
1692
diff
changeset
|
135 |
[ |
07c940be883e
walk waiting-processes list uninterruptable
Claus Gittinger <cg@exept.de>
parents:
1692
diff
changeset
|
136 |
waiters notNil ifTrue:[ |
07c940be883e
walk waiting-processes list uninterruptable
Claus Gittinger <cg@exept.de>
parents:
1692
diff
changeset
|
137 |
waiters do:[:aProcess | |
07c940be883e
walk waiting-processes list uninterruptable
Claus Gittinger <cg@exept.de>
parents:
1692
diff
changeset
|
138 |
str nextPut:$[. |
07c940be883e
walk waiting-processes list uninterruptable
Claus Gittinger <cg@exept.de>
parents:
1692
diff
changeset
|
139 |
str nextPutAll:(aProcess id printString). |
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 nextPutAll:(aProcess name contractTo:40). |
07c940be883e
walk waiting-processes list uninterruptable
Claus Gittinger <cg@exept.de>
parents:
1692
diff
changeset
|
142 |
str nextPutAll:''']'. |
07c940be883e
walk waiting-processes list uninterruptable
Claus Gittinger <cg@exept.de>
parents:
1692
diff
changeset
|
143 |
str space. |
07c940be883e
walk waiting-processes list uninterruptable
Claus Gittinger <cg@exept.de>
parents:
1692
diff
changeset
|
144 |
]. |
07c940be883e
walk waiting-processes list uninterruptable
Claus Gittinger <cg@exept.de>
parents:
1692
diff
changeset
|
145 |
] |
07c940be883e
walk waiting-processes list uninterruptable
Claus Gittinger <cg@exept.de>
parents:
1692
diff
changeset
|
146 |
] valueUninterruptably. |
980 | 147 |
waitersNames := str contents. |
148 |
||
984 | 149 |
(aSemaphore respondsTo:#name) ifTrue:[ |
150 |
nm := aSemaphore name. |
|
1022 | 151 |
nm isNil ifTrue:[ |
152 |
nm := '' |
|
153 |
] |
|
984 | 154 |
] ifFalse:[ |
155 |
nm := '' |
|
156 |
]. |
|
980 | 157 |
id := aSemaphore identityHash bitShift:-12. |
995 | 158 |
owner := aSemaphore lastOwnerId. |
159 |
owner isNil ifTrue:[ |
|
1692 | 160 |
owner := ' ' |
995 | 161 |
] ifFalse:[ |
1692 | 162 |
owner := owner printStringLeftPaddedTo:5 |
995 | 163 |
]. |
984 | 164 |
list add:( |
165 |
(id printStringPaddedTo:6) |
|
980 | 166 |
, ' ' |
993 | 167 |
, ((nm contractTo:25) paddedTo:25) |
984 | 168 |
, ' ' |
993 | 169 |
, (aSemaphore count printStringLeftPaddedTo:3) |
984 | 170 |
, ' ' |
1838 | 171 |
, owner printString |
995 | 172 |
, ' ' |
993 | 173 |
, (waiters size printStringLeftPaddedTo:3) |
980 | 174 |
, ' ' |
175 |
, waitersNames). |
|
1692 | 176 |
oldSelection notNil ifTrue:[ |
177 |
(oldSelection includes:id) ifTrue:[ |
|
178 |
newSelection add:list size. |
|
179 |
] |
|
180 |
] |
|
980 | 181 |
]. |
182 |
]. |
|
183 |
"avoid flicker" |
|
184 |
(oldList notNil and:[oldList size == list size]) ifTrue:[ |
|
185 |
list keysAndValuesDo:[:idx :entry | |
|
186 |
(oldList at:idx) ~= entry ifTrue:[ |
|
187 |
listView at:idx put:entry |
|
188 |
] |
|
189 |
] |
|
190 |
] ifFalse:[ |
|
191 |
listView setList:list. |
|
192 |
"the first two entries cannot be selected" |
|
193 |
listView attributeAt:1 put:#disabled. |
|
194 |
listView attributeAt:2 put:#disabled. |
|
195 |
]. |
|
1692 | 196 |
newSelection notNil ifTrue:[ |
197 |
listView selectWithoutScroll:newSelection |
|
198 |
]. |
|
980 | 199 |
listView flush |
200 |
]. |
|
201 |
updateBlock notNil ifTrue:[ |
|
202 |
Processor removeTimedBlock:updateBlock. |
|
203 |
Processor addTimedBlock:updateBlock afterSeconds:updateDelay |
|
204 |
] |
|
205 |
||
1692 | 206 |
"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
|
207 |
"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
|
208 |
"Modified: / 14.12.1999 / 20:53:14 / cg" |
980 | 209 |
! ! |
210 |
||
211 |
!SemaphoreMonitor methodsFor:'menu'! |
|
212 |
||
1692 | 213 |
debugWaiters |
214 |
"open a debugger on the selected semaphores waiting processes" |
|
215 |
||
216 |
self selectedSemaphoresDo:[:aSema | |
|
217 |
aSema waitingProcesses do:[:aProcess | |
|
218 |
DebugView openOn:aProcess |
|
219 |
] |
|
220 |
] |
|
221 |
||
222 |
"Modified: / 23.1.1997 / 03:12:06 / cg" |
|
223 |
"Created: / 17.6.1998 / 14:56:55 / cg" |
|
224 |
! |
|
225 |
||
995 | 226 |
inspectSemaphore |
980 | 227 |
"open an inspector on the selected semaphores" |
228 |
||
229 |
self selectedSemaphoresDo:[:aSema | aSema inspect] |
|
230 |
||
231 |
"Modified: 23.1.1997 / 03:12:06 / cg" |
|
995 | 232 |
"Created: 24.1.1997 / 23:11:50 / cg" |
980 | 233 |
! |
234 |
||
1692 | 235 |
inspectWaiters |
236 |
"open an inspector on the selected semaphores waiting processes" |
|
237 |
||
238 |
self selectedSemaphoresDo:[:aSema | |
|
239 |
aSema waitingProcesses do:[:aProcess | |
|
240 |
aProcess inspect |
|
241 |
] |
|
242 |
] |
|
243 |
||
244 |
"Modified: / 23.1.1997 / 03:12:06 / cg" |
|
245 |
"Created: / 17.6.1998 / 14:17:41 / cg" |
|
246 |
! |
|
247 |
||
980 | 248 |
selectedSemaphoresDo:aBlock |
249 |
"evaluate aBlock on all selected semaphores" |
|
250 |
||
251 |
|p nr sel| |
|
252 |
||
253 |
sel := listView selection. |
|
254 |
sel isNil ifTrue:[^ self]. |
|
255 |
||
256 |
(sel isKindOf:Collection) ifTrue:[ |
|
257 |
sel do:[:n | |
|
258 |
nr := n - 2. "for headlines" |
|
259 |
nr notNil ifTrue:[ |
|
260 |
nr > 0 ifTrue:[ |
|
261 |
p := semaphores at:nr. |
|
262 |
(p notNil and:[p ~~ 0]) ifTrue:[ |
|
263 |
aBlock value:p |
|
264 |
] |
|
265 |
] |
|
266 |
] |
|
267 |
] |
|
268 |
] ifFalse:[ |
|
269 |
nr := sel - 2. "for headlines" |
|
270 |
nr notNil ifTrue:[ |
|
271 |
nr > 0 ifTrue:[ |
|
272 |
p := semaphores at:nr. |
|
273 |
(p notNil and:[p ~~ 0]) ifTrue:[ |
|
274 |
aBlock value:p |
|
275 |
] |
|
276 |
] |
|
277 |
] |
|
278 |
]. |
|
279 |
||
280 |
"Created: 23.1.1997 / 03:11:24 / cg" |
|
281 |
! |
|
282 |
||
283 |
signalSemaphore |
|
284 |
"signal all selected semaphores" |
|
285 |
||
286 |
self selectedSemaphoresDo:[:aSema | aSema signal] |
|
287 |
||
288 |
"Created: 23.1.1997 / 03:12:30 / cg" |
|
289 |
! |
|
290 |
||
291 |
statusMenu |
|
292 |
"return a popUpMenu" |
|
293 |
||
1692 | 294 |
<resource: #programMenu> |
295 |
||
980 | 296 |
|labels selectors m sel| |
297 |
||
298 |
labels := resources array:#( |
|
299 |
'inspect' |
|
1692 | 300 |
'inspect waiters' |
301 |
'debug waiters' |
|
980 | 302 |
'-' |
303 |
'signal' |
|
304 |
). |
|
305 |
selectors := #( |
|
306 |
inspectSemaphore |
|
1692 | 307 |
inspectWaiters |
308 |
debugWaiters |
|
980 | 309 |
nil |
310 |
signalSemaphore |
|
311 |
). |
|
312 |
||
313 |
updateProcess isNil ifTrue:[ |
|
314 |
labels := (resources array:#('update' '-')) , labels. |
|
315 |
selectors := #(updateView nil) , selectors |
|
316 |
]. |
|
317 |
||
318 |
m := PopUpMenu labels:labels |
|
319 |
selectors:selectors. |
|
320 |
||
321 |
||
322 |
listView hasSelection ifFalse:[ |
|
323 |
m disableAll:#( |
|
324 |
inspectSemaphore |
|
325 |
signalSemaphore |
|
326 |
) |
|
327 |
]. |
|
328 |
^ m |
|
329 |
||
1692 | 330 |
"Modified: / 17.6.1998 / 14:17:05 / cg" |
980 | 331 |
! ! |
332 |
||
333 |
!SemaphoreMonitor methodsFor:'queries'! |
|
334 |
||
335 |
preferredExtent |
|
336 |
"return my preferred extent" |
|
337 |
||
338 |
^ (font widthOf:self titleLine) + 40 @ 250 |
|
339 |
||
340 |
"Modified: 23.1.1997 / 02:35:01 / cg" |
|
341 |
"Created: 23.1.1997 / 03:04:58 / cg" |
|
342 |
! ! |
|
343 |
||
344 |
!SemaphoreMonitor methodsFor:'user actions'! |
|
345 |
||
346 |
doubleClicked |
|
347 |
"open an inspector on the selected semaphore" |
|
348 |
||
1023 | 349 |
self inspectSemaphore |
980 | 350 |
|
351 |
"Created: 23.1.1997 / 03:22:04 / cg" |
|
1023 | 352 |
"Modified: 31.1.1997 / 22:33:27 / cg" |
980 | 353 |
! ! |
354 |
||
355 |
!SemaphoreMonitor class methodsFor:'documentation'! |
|
356 |
||
357 |
version |
|
2487
4ac80975b91d
avoid loosing the selection when the list is updated
Claus Gittinger <cg@exept.de>
parents:
1838
diff
changeset
|
358 |
^ '$Header: /cvs/stx/stx/libtool/SemaphoreMonitor.st,v 1.15 1999-12-14 20:15:14 cg Exp $' |
980 | 359 |
! ! |