author | Claus Gittinger <cg@exept.de> |
Sat, 31 Jan 2015 13:51:50 +0100 | |
changeset 15133 | 3d069aea5d09 |
parent 14202 | 336beb9d98f6 |
child 15566 | 184cea584be5 |
child 17169 | 91a80ba50915 |
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 |
||
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 |
|
14202 | 26 |
All Rights Reserved |
980 | 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:] |
|
14202 | 44 |
Semaphore SemaphoreSet |
45 |
Process ProcessorScheduler |
|
46 |
WindowGroup |
|
47 |
ProcessMonitor |
|
980 | 48 |
|
49 |
[author:] |
|
14202 | 50 |
Claus Gittinger |
980 | 51 |
|
52 |
[start with:] |
|
14202 | 53 |
SemaphoreMonitor open |
980 | 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:[ |
|
14202 | 84 |
newList := Semaphore allSubInstances. |
980 | 85 |
|
14202 | 86 |
"sort by hashKey - will not always generate unique numbers, |
87 |
but most of the time, this works ... for now" |
|
980 | 88 |
|
14202 | 89 |
newList sort:[:s1 :s2 | s1 identityHash < s2 identityHash]. |
980 | 90 |
|
14202 | 91 |
newList ~= semaphores ifTrue:[ |
92 |
self updateStatus:newList |
|
93 |
]. |
|
980 | 94 |
]. |
95 |
updateBlock notNil ifTrue:[ |
|
14202 | 96 |
Processor removeTimedBlock:listUpdateBlock. |
97 |
Processor addTimedBlock:listUpdateBlock afterSeconds:listUpdateDelay |
|
980 | 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:[ |
|
14202 | 111 |
oldList := listView list. |
112 |
oldSelection := listView selectionValue. |
|
113 |
oldSelection notNil ifTrue:[ |
|
114 |
oldSelection := oldSelection collect:[:line | line asCollectionOfWords first asNumber]. |
|
115 |
newSelection := OrderedCollection new. |
|
116 |
]. |
|
980 | 117 |
|
14202 | 118 |
newSemaphoreList notNil ifTrue:[ |
119 |
semaphores := WeakArray withAll:newSemaphoreList. |
|
120 |
]. |
|
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:$-). |
|
980 | 125 |
|
14202 | 126 |
semaphores validElementsDo:[:aSemaphore | |
127 |
|waiters waitersNames nm id str owner color line count| |
|
980 | 128 |
|
14202 | 129 |
"/ need a copy - it may change while being enumerated |
130 |
[ |
|
131 |
count := aSemaphore count. |
|
132 |
waiters := aSemaphore waitingProcesses copy. |
|
133 |
] valueUninterruptably. |
|
980 | 134 |
|
14202 | 135 |
str := '' writeStream. |
136 |
[ |
|
137 |
waiters notNil ifTrue:[ |
|
138 |
waiters do:[:aProcess | |
|
139 |
str nextPut:$[. |
|
140 |
aProcess id printOn:str. |
|
141 |
str nextPutAll:' '''. |
|
142 |
str nextPutAll:(aProcess name contractTo:40). |
|
143 |
str nextPutAll:'''<'. |
|
144 |
aProcess priority printOn:str. |
|
145 |
str nextPutAll:'>]'. |
|
146 |
str space. |
|
147 |
]. |
|
148 |
] |
|
149 |
] valueUninterruptably. |
|
150 |
waitersNames := str contents. |
|
980 | 151 |
|
14202 | 152 |
(aSemaphore respondsTo:#name) ifTrue:[ |
153 |
nm := aSemaphore name. |
|
154 |
nm isNil ifTrue:[ |
|
155 |
nm := '' |
|
156 |
] |
|
157 |
] ifFalse:[ |
|
158 |
nm := '' |
|
159 |
]. |
|
160 |
id := aSemaphore identityHash bitShift:-12. |
|
161 |
owner := aSemaphore lastOwnerId. |
|
162 |
owner isNil ifTrue:[ |
|
163 |
owner := ' ' |
|
164 |
] ifFalse:[ |
|
165 |
owner := owner printStringLeftPaddedTo:5 |
|
166 |
]. |
|
167 |
line := (id printStringPaddedTo:6) |
|
168 |
, ' ' |
|
169 |
, ((nm contractTo:25) paddedTo:25) |
|
170 |
, ' ' |
|
171 |
, (count printStringLeftPaddedTo:3) |
|
172 |
, ' ' |
|
173 |
, owner printString |
|
174 |
, ' ' |
|
175 |
, (waiters size printStringLeftPaddedTo:3) |
|
176 |
, ' ' |
|
177 |
, waitersNames. |
|
12399 | 178 |
|
14202 | 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. |
|
12399 | 183 |
"/ self beep. |
14202 | 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. |
|
196 |
oldSelection notNil ifTrue:[ |
|
197 |
(oldSelection includes:id) ifTrue:[ |
|
198 |
newSelection add:list size. |
|
199 |
] |
|
200 |
] |
|
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 |
]. |
|
216 |
newSelection notNil ifTrue:[ |
|
217 |
listView selectWithoutScroll:newSelection |
|
218 |
]. |
|
219 |
listView flush |
|
980 | 220 |
]. |
221 |
updateBlock notNil ifTrue:[ |
|
14202 | 222 |
Processor removeTimedBlock:updateBlock. |
223 |
Processor addTimedBlock:updateBlock afterSeconds:updateDelay |
|
980 | 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 |
||
14202 | 236 |
self selectedSemaphoresDo:[:aSema | |
237 |
aSema waitingProcesses do:[:aProcess | |
|
238 |
DebugView openOn:aProcess |
|
239 |
] |
|
1692 | 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 |
||
14202 | 258 |
self selectedSemaphoresDo:[:aSema | |
259 |
aSema waitingProcesses do:[:aProcess | |
|
260 |
aProcess inspect |
|
261 |
] |
|
1692 | 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:[ |
|
14202 | 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 |
] |
|
980 | 288 |
] ifFalse:[ |
14202 | 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 |
] |
|
980 | 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:#( |
|
14202 | 319 |
'Inspect' |
320 |
'Inspect Waiters' |
|
321 |
'Debug Waiters' |
|
322 |
'-' |
|
323 |
'Signal' |
|
324 |
). |
|
980 | 325 |
selectors := #( |
14202 | 326 |
inspectSemaphore |
327 |
inspectWaiters |
|
328 |
debugWaiters |
|
329 |
nil |
|
330 |
signalSemaphore |
|
331 |
). |
|
980 | 332 |
|
333 |
updateProcess isNil ifTrue:[ |
|
14202 | 334 |
labels := (resources array:#('Update' '-')) , labels. |
335 |
selectors := #(updateView nil) , selectors |
|
980 | 336 |
]. |
337 |
||
338 |
m := PopUpMenu labels:labels |
|
14202 | 339 |
selectors:selectors. |
980 | 340 |
|
341 |
||
342 |
listView hasSelection ifFalse:[ |
|
14202 | 343 |
m disableAll:#( |
344 |
inspectSemaphore |
|
345 |
signalSemaphore |
|
346 |
) |
|
980 | 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 |
||
14202 | 358 |
^ (self font widthOf:self titleLine) + 40 @ 250 |
980 | 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 |
|
14202 | 378 |
^ '$Header: /cvs/stx/stx/libtool/SemaphoreMonitor.st,v 1.18 2014-04-11 14:22:55 stefan Exp $' |
980 | 379 |
! ! |
12399 | 380 |