author | Stefan Vogel <sv@exept.de> |
Thu, 23 Feb 2017 16:29:12 +0100 | |
changeset 17438 | b1ed3554236b |
parent 17423 | 4535ffc68731 |
child 17443 | e4ab616db8de |
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 |
newList := Semaphore allSubInstances. |
980 | 90 |
|
17226 | 91 |
"sort by hashKey - will not always generate unique numbers, |
92 |
but most of the time, this works ... for now" |
|
980 | 93 |
|
17226 | 94 |
newList sort:[:s1 :s2 | s1 identityHash < s2 identityHash]. |
95 |
||
96 |
newList ~= semaphores ifTrue:[ |
|
97 |
self updateStatus:newList |
|
98 |
]. |
|
980 | 99 |
]. |
17226 | 100 |
self installDelayedUpdate. |
980 | 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:[ |
|
17169 | 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 |
|
17169 | 120 |
newSemaphoreList notNil ifTrue:[ |
121 |
semaphores := WeakArray withAll:newSemaphoreList. |
|
122 |
]. |
|
123 |
semaphores notNil ifTrue:[ |
|
124 |
list := OrderedCollection new:(semaphores size + self numberOfHeadlines). |
|
125 |
list add:self titleLine. |
|
126 |
list add:(String new:self titleLine size withAll:$-). |
|
980 | 127 |
|
17169 | 128 |
semaphores validElementsDo:[:aSemaphore | |
129 |
|waiters waitersNames nm id str owner color line count| |
|
980 | 130 |
|
17169 | 131 |
"/ need a copy - it may change while being enumerated |
132 |
[ |
|
133 |
count := aSemaphore count. |
|
134 |
waiters := aSemaphore waitingProcesses copy. |
|
135 |
] valueUninterruptably. |
|
980 | 136 |
|
17169 | 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 |
|
17169 | 154 |
(aSemaphore respondsTo:#name) ifTrue:[ |
155 |
nm := aSemaphore name. |
|
156 |
nm isNil ifTrue:[ |
|
17423 | 157 |
nm := aSemaphore className. |
17169 | 158 |
] |
159 |
] ifFalse:[ |
|
160 |
nm := '' |
|
161 |
]. |
|
162 |
id := aSemaphore identityHash bitShift:-12. |
|
163 |
owner := aSemaphore lastOwnerId. |
|
164 |
owner isNil ifTrue:[ |
|
17226 | 165 |
owner := '' |
17169 | 166 |
] ifFalse:[ |
17226 | 167 |
owner := owner printString |
17169 | 168 |
]. |
17226 | 169 |
owner := owner leftPaddedTo:6. |
170 |
||
17169 | 171 |
line := (id printStringPaddedTo:6) |
172 |
, ' ' |
|
173 |
, ((nm contractTo:25) paddedTo:25) |
|
174 |
, ' ' |
|
175 |
, (count printStringLeftPaddedTo:3) |
|
176 |
, ' ' |
|
177 |
, owner printString |
|
178 |
, ' ' |
|
179 |
, (waiters size printStringLeftPaddedTo:3) |
|
180 |
, ' ' |
|
181 |
, waitersNames. |
|
12399 | 182 |
|
17169 | 183 |
count > 0 ifTrue:[ |
184 |
waiters size > 0 ifTrue:[ |
|
185 |
"this happens if a low priority process is ready to run but didn't wake up yet" |
|
186 |
color := Color red. |
|
12399 | 187 |
"/ self beep. |
17169 | 188 |
] ifFalse:[ |
189 |
"fine, this semaphore is available" |
|
190 |
color := Color blue. |
|
191 |
]. |
|
192 |
line := line colorizeAllWith:color. |
|
193 |
] ifFalse:[ |
|
194 |
waiters size > 0 ifTrue:[ |
|
195 |
line := line colorizeAllWith:Color brown. |
|
196 |
]. |
|
197 |
]. |
|
14202 | 198 |
|
17169 | 199 |
list add:line. |
200 |
oldSelection notNil ifTrue:[ |
|
201 |
(oldSelection includes:id) ifTrue:[ |
|
202 |
newSelection add:list size. |
|
203 |
] |
|
204 |
] |
|
205 |
]. |
|
206 |
]. |
|
207 |
"avoid flicker" |
|
208 |
(oldList notNil and:[oldList size == list size]) ifTrue:[ |
|
209 |
list keysAndValuesDo:[:idx :entry | |
|
210 |
(oldList at:idx) ~= entry ifTrue:[ |
|
211 |
listView at:idx put:entry |
|
212 |
] |
|
213 |
] |
|
214 |
] ifFalse:[ |
|
215 |
listView setList:list. |
|
216 |
"the first two entries cannot be selected" |
|
217 |
listView attributeAt:1 put:#disabled. |
|
218 |
listView attributeAt:2 put:#disabled. |
|
219 |
]. |
|
220 |
newSelection notNil ifTrue:[ |
|
221 |
listView selectWithoutScroll:newSelection |
|
222 |
]. |
|
223 |
listView flush |
|
980 | 224 |
]. |
17226 | 225 |
self installDelayedUpdate. |
980 | 226 |
|
17423 | 227 |
"Created: / 14-12-1999 / 20:52:29 / cg" |
228 |
"Modified: / 20-02-2017 / 16:46:30 / stefan" |
|
980 | 229 |
! ! |
230 |
||
231 |
!SemaphoreMonitor methodsFor:'menu'! |
|
232 |
||
17226 | 233 |
debugLastOwningProcess |
234 |
"open a debugger on the selected semaphores' (last) owning processes" |
|
1692 | 235 |
|
14202 | 236 |
self selectedSemaphoresDo:[:aSema | |
17226 | 237 |
|p| |
238 |
||
239 |
(p := aSema lastOwner) notNil ifTrue:[ |
|
240 |
DebugView openOn:p |
|
241 |
] |
|
242 |
] |
|
243 |
! |
|
244 |
||
245 |
debugWaiters |
|
246 |
"open a debugger on the selected semaphores' waiting processes" |
|
247 |
||
248 |
self selectedSemaphoresDo:[:aSema | |
|
249 |
aSema waitingProcesses do:[:aProcess | |
|
250 |
DebugView openOn:aProcess |
|
251 |
] |
|
1692 | 252 |
] |
253 |
||
254 |
"Modified: / 23.1.1997 / 03:12:06 / cg" |
|
255 |
"Created: / 17.6.1998 / 14:56:55 / cg" |
|
256 |
! |
|
257 |
||
17438 | 258 |
findRefChainToSemaphore |
259 |
"open an ref chain dialog on the selected semaphore(s)" |
|
260 |
||
261 |
|coll| |
|
262 |
||
263 |
coll := OrderedCollection new. |
|
264 |
self selectedSemaphoresDo:[:aSema | coll add:aSema]. |
|
265 |
ObjectMemory displayRefChainToAny:coll. |
|
266 |
||
267 |
"Created: / 23-02-2017 / 15:17:01 / stefan" |
|
268 |
! |
|
269 |
||
995 | 270 |
inspectSemaphore |
17226 | 271 |
"open an inspector on the selected semaphore(s)" |
980 | 272 |
|
273 |
self selectedSemaphoresDo:[:aSema | aSema inspect] |
|
274 |
||
275 |
"Modified: 23.1.1997 / 03:12:06 / cg" |
|
995 | 276 |
"Created: 24.1.1997 / 23:11:50 / cg" |
980 | 277 |
! |
278 |
||
1692 | 279 |
inspectWaiters |
17226 | 280 |
"open an inspector on the selected semaphores' waiting processes" |
1692 | 281 |
|
14202 | 282 |
self selectedSemaphoresDo:[:aSema | |
17226 | 283 |
aSema waitingProcesses do:[:aProcess | |
284 |
aProcess inspect |
|
285 |
] |
|
1692 | 286 |
] |
287 |
||
288 |
"Modified: / 23.1.1997 / 03:12:06 / cg" |
|
289 |
"Created: / 17.6.1998 / 14:17:41 / cg" |
|
290 |
! |
|
291 |
||
980 | 292 |
selectedSemaphoresDo:aBlock |
17226 | 293 |
"evaluate aBlock on all selected semaphore(s)" |
980 | 294 |
|
17226 | 295 |
self selectionIndicesDo:[:n | |
296 |
|nr p| |
|
297 |
||
298 |
nr := n - self numberOfHeadlines. |
|
17169 | 299 |
nr notNil ifTrue:[ |
300 |
nr > 0 ifTrue:[ |
|
301 |
p := semaphores at:nr. |
|
302 |
(p notNil and:[p ~~ 0]) ifTrue:[ |
|
303 |
aBlock value:p |
|
304 |
] |
|
305 |
] |
|
306 |
] |
|
980 | 307 |
]. |
308 |
! |
|
309 |
||
310 |
signalSemaphore |
|
311 |
"signal all selected semaphores" |
|
312 |
||
313 |
self selectedSemaphoresDo:[:aSema | aSema signal] |
|
314 |
||
315 |
"Created: 23.1.1997 / 03:12:30 / cg" |
|
316 |
! |
|
317 |
||
318 |
statusMenu |
|
319 |
"return a popUpMenu" |
|
320 |
||
1692 | 321 |
<resource: #programMenu> |
322 |
||
4253 | 323 |
|labels selectors m| |
980 | 324 |
|
325 |
labels := resources array:#( |
|
17226 | 326 |
'Inspect' |
327 |
'Inspect Waiters' |
|
17438 | 328 |
'Show reference chains' |
17226 | 329 |
'Debug Waiters' |
330 |
'Debug Last Owning Process' |
|
331 |
'-' |
|
332 |
'Signal' |
|
333 |
). |
|
980 | 334 |
selectors := #( |
17226 | 335 |
inspectSemaphore |
336 |
inspectWaiters |
|
17438 | 337 |
findRefChainToSemaphore |
17226 | 338 |
debugWaiters |
339 |
debugLastOwningProcess |
|
340 |
nil |
|
341 |
signalSemaphore |
|
342 |
). |
|
980 | 343 |
|
344 |
updateProcess isNil ifTrue:[ |
|
17226 | 345 |
labels := (resources array:#('Update' '-')) , labels. |
346 |
selectors := #(updateView nil) , selectors |
|
980 | 347 |
]. |
348 |
||
349 |
m := PopUpMenu labels:labels |
|
17226 | 350 |
selectors:selectors. |
980 | 351 |
|
352 |
||
353 |
listView hasSelection ifFalse:[ |
|
17226 | 354 |
m disableAll:#( |
355 |
inspectSemaphore |
|
356 |
inspectWaiters |
|
357 |
debugWaiters |
|
358 |
debugLastOwningProcess |
|
359 |
signalSemaphore |
|
360 |
) |
|
980 | 361 |
]. |
362 |
^ m |
|
363 |
||
17438 | 364 |
"Modified: / 17-06-1998 / 14:17:05 / cg" |
365 |
"Modified: / 23-02-2017 / 15:18:50 / stefan" |
|
980 | 366 |
! ! |
367 |
||
368 |
!SemaphoreMonitor methodsFor:'queries'! |
|
369 |
||
17169 | 370 |
numberOfHeadlines |
371 |
^ 2 |
|
980 | 372 |
! ! |
373 |
||
374 |
!SemaphoreMonitor methodsFor:'user actions'! |
|
375 |
||
376 |
doubleClicked |
|
377 |
"open an inspector on the selected semaphore" |
|
378 |
||
1023 | 379 |
self inspectSemaphore |
980 | 380 |
|
381 |
"Created: 23.1.1997 / 03:22:04 / cg" |
|
1023 | 382 |
"Modified: 31.1.1997 / 22:33:27 / cg" |
980 | 383 |
! ! |
384 |
||
385 |
!SemaphoreMonitor class methodsFor:'documentation'! |
|
386 |
||
387 |
version |
|
17169 | 388 |
^ '$Header$' |
980 | 389 |
! ! |
12399 | 390 |