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