author | convert-repo |
Fri, 06 Jul 2018 03:31:58 +0000 | |
changeset 18262 | 18e456b91b31 |
parent 17443 | e4ab616db8de |
child 19056 | 9bb181a447f7 |
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 |
||
17169 | 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 |
" |
|
17169 | 43 |
This view shows smalltalk's semaphores - a debugging tool. |
980 | 44 |
|
17169 | 45 |
[disclaimer:] |
46 |
this is one of the oldest tools in the system, written in the early 90's. |
|
47 |
It does in no way reflect the way GUIs are designed/written these days. |
|
48 |
||
980 | 49 |
[see also:] |
17169 | 50 |
Semaphore SemaphoreSet |
51 |
Process ProcessorScheduler |
|
52 |
WindowGroup |
|
53 |
ProcessMonitor |
|
980 | 54 |
|
55 |
[author:] |
|
17169 | 56 |
Claus Gittinger |
980 | 57 |
|
58 |
[start with:] |
|
17169 | 59 |
SemaphoreMonitor open |
980 | 60 |
" |
61 |
! ! |
|
62 |
||
63 |
!SemaphoreMonitor class methodsFor:'defaults'! |
|
64 |
||
65 |
defaultLabel |
|
66 |
^ 'Semaphore Monitor' |
|
67 |
||
68 |
"Created: 23.1.1997 / 02:52:53 / cg" |
|
69 |
! ! |
|
70 |
||
71 |
!SemaphoreMonitor methodsFor:'drawing'! |
|
72 |
||
73 |
titleLine |
|
17226 | 74 |
^ 'Id Name Count Owner Waiting Process(es)'. |
980 | 75 |
|
76 |
" |
|
77 |
SemaphoreMonitor open |
|
78 |
" |
|
79 |
||
1692 | 80 |
"Modified: / 17.6.1998 / 14:52:48 / cg" |
980 | 81 |
! |
82 |
||
83 |
updateList |
|
84 |
"update list of semaphores" |
|
85 |
||
86 |
|newList| |
|
87 |
||
88 |
shown ifTrue:[ |
|
17226 | 89 |
"sort by hashKey - will not always generate unique numbers, |
90 |
but most of the time, this works ... for now" |
|
17443 | 91 |
newList := SortedCollection sortBlock:[:s1 :s2 | s1 identityHash < s2 identityHash]. |
92 |
Semaphore allSubInstancesDo:[:each| |
|
93 |
newList add:each. |
|
94 |
]. |
|
95 |
(newList isSameSequenceAs:semaphores) ifFalse:[ |
|
17226 | 96 |
self updateStatus:newList |
97 |
]. |
|
980 | 98 |
]. |
17226 | 99 |
self installDelayedUpdate. |
980 | 100 |
|
17443 | 101 |
"Created: / 23-01-1997 / 02:44:48 / cg" |
102 |
"Modified: / 14-12-1999 / 20:52:44 / cg" |
|
103 |
"Modified: / 24-02-2017 / 13:44:09 / stefan" |
|
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:[ |
|
17169 | 112 |
oldList := listView list. |
113 |
oldSelection := listView selectionValue. |
|
114 |
oldSelection notNil ifTrue:[ |
|
115 |
oldSelection := oldSelection collect:[:line | line asCollectionOfWords first asNumber]. |
|
116 |
newSelection := OrderedCollection new. |
|
117 |
]. |
|
980 | 118 |
|
17169 | 119 |
newSemaphoreList notNil ifTrue:[ |
120 |
semaphores := WeakArray withAll:newSemaphoreList. |
|
121 |
]. |
|
122 |
semaphores notNil ifTrue:[ |
|
123 |
list := OrderedCollection new:(semaphores size + self numberOfHeadlines). |
|
124 |
list add:self titleLine. |
|
125 |
list add:(String new:self titleLine size withAll:$-). |
|
980 | 126 |
|
17169 | 127 |
semaphores validElementsDo:[:aSemaphore | |
128 |
|waiters waitersNames nm id str owner color line count| |
|
980 | 129 |
|
17169 | 130 |
"/ need a copy - it may change while being enumerated |
131 |
[ |
|
132 |
count := aSemaphore count. |
|
133 |
waiters := aSemaphore waitingProcesses copy. |
|
134 |
] valueUninterruptably. |
|
980 | 135 |
|
17169 | 136 |
str := '' writeStream. |
17443 | 137 |
waiters notEmptyOrNil 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 |
]. |
|
17169 | 149 |
waitersNames := str contents. |
980 | 150 |
|
17169 | 151 |
(aSemaphore respondsTo:#name) ifTrue:[ |
152 |
nm := aSemaphore name. |
|
153 |
nm isNil ifTrue:[ |
|
17423 | 154 |
nm := aSemaphore className. |
17169 | 155 |
] |
156 |
] ifFalse:[ |
|
17443 | 157 |
nm := aSemaphore className. |
17169 | 158 |
]. |
159 |
id := aSemaphore identityHash bitShift:-12. |
|
160 |
owner := aSemaphore lastOwnerId. |
|
161 |
owner isNil ifTrue:[ |
|
17226 | 162 |
owner := '' |
17169 | 163 |
] ifFalse:[ |
17226 | 164 |
owner := owner printString |
17169 | 165 |
]. |
17226 | 166 |
owner := owner leftPaddedTo:6. |
167 |
||
17169 | 168 |
line := (id printStringPaddedTo:6) |
169 |
, ' ' |
|
170 |
, ((nm contractTo:25) paddedTo:25) |
|
171 |
, ' ' |
|
172 |
, (count printStringLeftPaddedTo:3) |
|
173 |
, ' ' |
|
174 |
, owner printString |
|
175 |
, ' ' |
|
176 |
, (waiters size printStringLeftPaddedTo:3) |
|
177 |
, ' ' |
|
178 |
, waitersNames. |
|
12399 | 179 |
|
17169 | 180 |
count > 0 ifTrue:[ |
17443 | 181 |
waiters notEmpty ifTrue:[ |
17169 | 182 |
"this happens if a low priority process is ready to run but didn't wake up yet" |
183 |
color := Color red. |
|
12399 | 184 |
"/ self beep. |
17169 | 185 |
] ifFalse:[ |
186 |
"fine, this semaphore is available" |
|
187 |
color := Color blue. |
|
188 |
]. |
|
189 |
line := line colorizeAllWith:color. |
|
190 |
] ifFalse:[ |
|
17443 | 191 |
waiters notEmpty ifTrue:[ |
192 |
"someone waits on the Semaphore" |
|
17169 | 193 |
line := line colorizeAllWith:Color brown. |
194 |
]. |
|
195 |
]. |
|
14202 | 196 |
|
17169 | 197 |
list add:line. |
198 |
oldSelection notNil ifTrue:[ |
|
199 |
(oldSelection includes:id) ifTrue:[ |
|
200 |
newSelection add:list size. |
|
201 |
] |
|
202 |
] |
|
203 |
]. |
|
204 |
]. |
|
17443 | 205 |
|
17169 | 206 |
"avoid flicker" |
207 |
(oldList notNil and:[oldList size == list size]) ifTrue:[ |
|
208 |
list keysAndValuesDo:[:idx :entry | |
|
209 |
(oldList at:idx) ~= entry ifTrue:[ |
|
210 |
listView at:idx put:entry |
|
211 |
] |
|
212 |
] |
|
213 |
] ifFalse:[ |
|
214 |
listView setList:list. |
|
215 |
"the first two entries cannot be selected" |
|
216 |
listView attributeAt:1 put:#disabled. |
|
217 |
listView attributeAt:2 put:#disabled. |
|
218 |
]. |
|
219 |
newSelection notNil ifTrue:[ |
|
220 |
listView selectWithoutScroll:newSelection |
|
221 |
]. |
|
222 |
listView flush |
|
980 | 223 |
]. |
17226 | 224 |
self installDelayedUpdate. |
980 | 225 |
|
17423 | 226 |
"Created: / 14-12-1999 / 20:52:29 / cg" |
17443 | 227 |
"Modified: / 24-02-2017 / 13:39:25 / stefan" |
980 | 228 |
! ! |
229 |
||
230 |
!SemaphoreMonitor methodsFor:'menu'! |
|
231 |
||
17226 | 232 |
debugLastOwningProcess |
233 |
"open a debugger on the selected semaphores' (last) owning processes" |
|
1692 | 234 |
|
14202 | 235 |
self selectedSemaphoresDo:[:aSema | |
17226 | 236 |
|p| |
237 |
||
238 |
(p := aSema lastOwner) notNil ifTrue:[ |
|
239 |
DebugView openOn:p |
|
240 |
] |
|
241 |
] |
|
242 |
! |
|
243 |
||
244 |
debugWaiters |
|
245 |
"open a debugger on the selected semaphores' waiting processes" |
|
246 |
||
247 |
self selectedSemaphoresDo:[:aSema | |
|
248 |
aSema waitingProcesses do:[:aProcess | |
|
249 |
DebugView openOn:aProcess |
|
250 |
] |
|
1692 | 251 |
] |
252 |
||
253 |
"Modified: / 23.1.1997 / 03:12:06 / cg" |
|
254 |
"Created: / 17.6.1998 / 14:56:55 / cg" |
|
255 |
! |
|
256 |
||
17438 | 257 |
findRefChainToSemaphore |
258 |
"open an ref chain dialog on the selected semaphore(s)" |
|
259 |
||
260 |
|coll| |
|
261 |
||
262 |
coll := OrderedCollection new. |
|
263 |
self selectedSemaphoresDo:[:aSema | coll add:aSema]. |
|
264 |
ObjectMemory displayRefChainToAny:coll. |
|
265 |
||
266 |
"Created: / 23-02-2017 / 15:17:01 / stefan" |
|
267 |
! |
|
268 |
||
995 | 269 |
inspectSemaphore |
17226 | 270 |
"open an inspector on the selected semaphore(s)" |
980 | 271 |
|
272 |
self selectedSemaphoresDo:[:aSema | aSema inspect] |
|
273 |
||
274 |
"Modified: 23.1.1997 / 03:12:06 / cg" |
|
995 | 275 |
"Created: 24.1.1997 / 23:11:50 / cg" |
980 | 276 |
! |
277 |
||
1692 | 278 |
inspectWaiters |
17226 | 279 |
"open an inspector on the selected semaphores' waiting processes" |
1692 | 280 |
|
14202 | 281 |
self selectedSemaphoresDo:[:aSema | |
17226 | 282 |
aSema waitingProcesses do:[:aProcess | |
283 |
aProcess inspect |
|
284 |
] |
|
1692 | 285 |
] |
286 |
||
287 |
"Modified: / 23.1.1997 / 03:12:06 / cg" |
|
288 |
"Created: / 17.6.1998 / 14:17:41 / cg" |
|
289 |
! |
|
290 |
||
980 | 291 |
selectedSemaphoresDo:aBlock |
17226 | 292 |
"evaluate aBlock on all selected semaphore(s)" |
980 | 293 |
|
17226 | 294 |
self selectionIndicesDo:[:n | |
295 |
|nr p| |
|
296 |
||
297 |
nr := n - self numberOfHeadlines. |
|
17169 | 298 |
nr notNil ifTrue:[ |
299 |
nr > 0 ifTrue:[ |
|
300 |
p := semaphores at:nr. |
|
301 |
(p notNil and:[p ~~ 0]) ifTrue:[ |
|
302 |
aBlock value:p |
|
303 |
] |
|
304 |
] |
|
305 |
] |
|
980 | 306 |
]. |
307 |
! |
|
308 |
||
309 |
signalSemaphore |
|
310 |
"signal all selected semaphores" |
|
311 |
||
312 |
self selectedSemaphoresDo:[:aSema | aSema signal] |
|
313 |
||
314 |
"Created: 23.1.1997 / 03:12:30 / cg" |
|
315 |
! |
|
316 |
||
317 |
statusMenu |
|
318 |
"return a popUpMenu" |
|
319 |
||
1692 | 320 |
<resource: #programMenu> |
321 |
||
4253 | 322 |
|labels selectors m| |
980 | 323 |
|
324 |
labels := resources array:#( |
|
17226 | 325 |
'Inspect' |
326 |
'Inspect Waiters' |
|
17438 | 327 |
'Show reference chains' |
17226 | 328 |
'Debug Waiters' |
329 |
'Debug Last Owning Process' |
|
330 |
'-' |
|
331 |
'Signal' |
|
332 |
). |
|
980 | 333 |
selectors := #( |
17226 | 334 |
inspectSemaphore |
335 |
inspectWaiters |
|
17438 | 336 |
findRefChainToSemaphore |
17226 | 337 |
debugWaiters |
338 |
debugLastOwningProcess |
|
339 |
nil |
|
340 |
signalSemaphore |
|
341 |
). |
|
980 | 342 |
|
343 |
updateProcess isNil ifTrue:[ |
|
17226 | 344 |
labels := (resources array:#('Update' '-')) , labels. |
345 |
selectors := #(updateView nil) , selectors |
|
980 | 346 |
]. |
347 |
||
348 |
m := PopUpMenu labels:labels |
|
17226 | 349 |
selectors:selectors. |
980 | 350 |
|
351 |
||
352 |
listView hasSelection ifFalse:[ |
|
17226 | 353 |
m disableAll:#( |
354 |
inspectSemaphore |
|
355 |
inspectWaiters |
|
356 |
debugWaiters |
|
357 |
debugLastOwningProcess |
|
358 |
signalSemaphore |
|
359 |
) |
|
980 | 360 |
]. |
361 |
^ m |
|
362 |
||
17438 | 363 |
"Modified: / 17-06-1998 / 14:17:05 / cg" |
364 |
"Modified: / 23-02-2017 / 15:18:50 / stefan" |
|
980 | 365 |
! ! |
366 |
||
367 |
!SemaphoreMonitor methodsFor:'queries'! |
|
368 |
||
17169 | 369 |
numberOfHeadlines |
370 |
^ 2 |
|
980 | 371 |
! ! |
372 |
||
373 |
!SemaphoreMonitor methodsFor:'user actions'! |
|
374 |
||
375 |
doubleClicked |
|
376 |
"open an inspector on the selected semaphore" |
|
377 |
||
1023 | 378 |
self inspectSemaphore |
980 | 379 |
|
380 |
"Created: 23.1.1997 / 03:22:04 / cg" |
|
1023 | 381 |
"Modified: 31.1.1997 / 22:33:27 / cg" |
980 | 382 |
! ! |
383 |
||
384 |
!SemaphoreMonitor class methodsFor:'documentation'! |
|
385 |
||
386 |
version |
|
17169 | 387 |
^ '$Header$' |
17443 | 388 |
! |
389 |
||
390 |
version_CVS |
|
391 |
^ '$Header$' |
|
980 | 392 |
! ! |
12399 | 393 |