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