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