author | Jan Vrany <jan.vrany@fit.cvut.cz> |
Wed, 19 Jul 2017 09:42:32 +0200 | |
branch | jv |
changeset 17619 | edb119820fcb |
parent 17277 | 11e4a5ca80a5 |
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:[ |
|
157 |
nm := '' |
|
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 |
|
1692 | 227 |
"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
|
228 |
"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
|
229 |
"Modified: / 14.12.1999 / 20:53:14 / cg" |
980 | 230 |
! ! |
231 |
||
232 |
!SemaphoreMonitor methodsFor:'menu'! |
|
233 |
||
17226 | 234 |
debugLastOwningProcess |
235 |
"open a debugger on the selected semaphores' (last) owning processes" |
|
1692 | 236 |
|
14202 | 237 |
self selectedSemaphoresDo:[:aSema | |
17226 | 238 |
|p| |
239 |
||
240 |
(p := aSema lastOwner) notNil ifTrue:[ |
|
241 |
DebugView openOn:p |
|
242 |
] |
|
243 |
] |
|
244 |
! |
|
245 |
||
246 |
debugWaiters |
|
247 |
"open a debugger on the selected semaphores' waiting processes" |
|
248 |
||
249 |
self selectedSemaphoresDo:[:aSema | |
|
250 |
aSema waitingProcesses do:[:aProcess | |
|
251 |
DebugView openOn:aProcess |
|
252 |
] |
|
1692 | 253 |
] |
254 |
||
255 |
"Modified: / 23.1.1997 / 03:12:06 / cg" |
|
256 |
"Created: / 17.6.1998 / 14:56:55 / cg" |
|
257 |
! |
|
258 |
||
995 | 259 |
inspectSemaphore |
17226 | 260 |
"open an inspector on the selected semaphore(s)" |
980 | 261 |
|
262 |
self selectedSemaphoresDo:[:aSema | aSema inspect] |
|
263 |
||
264 |
"Modified: 23.1.1997 / 03:12:06 / cg" |
|
995 | 265 |
"Created: 24.1.1997 / 23:11:50 / cg" |
980 | 266 |
! |
267 |
||
1692 | 268 |
inspectWaiters |
17226 | 269 |
"open an inspector on the selected semaphores' waiting processes" |
1692 | 270 |
|
14202 | 271 |
self selectedSemaphoresDo:[:aSema | |
17226 | 272 |
aSema waitingProcesses do:[:aProcess | |
273 |
aProcess inspect |
|
274 |
] |
|
1692 | 275 |
] |
276 |
||
277 |
"Modified: / 23.1.1997 / 03:12:06 / cg" |
|
278 |
"Created: / 17.6.1998 / 14:17:41 / cg" |
|
279 |
! |
|
280 |
||
980 | 281 |
selectedSemaphoresDo:aBlock |
17226 | 282 |
"evaluate aBlock on all selected semaphore(s)" |
980 | 283 |
|
17226 | 284 |
self selectionIndicesDo:[:n | |
285 |
|nr p| |
|
286 |
||
287 |
nr := n - self numberOfHeadlines. |
|
17169 | 288 |
nr notNil ifTrue:[ |
289 |
nr > 0 ifTrue:[ |
|
290 |
p := semaphores at:nr. |
|
291 |
(p notNil and:[p ~~ 0]) ifTrue:[ |
|
292 |
aBlock value:p |
|
293 |
] |
|
294 |
] |
|
295 |
] |
|
980 | 296 |
]. |
297 |
! |
|
298 |
||
299 |
signalSemaphore |
|
300 |
"signal all selected semaphores" |
|
301 |
||
302 |
self selectedSemaphoresDo:[:aSema | aSema signal] |
|
303 |
||
304 |
"Created: 23.1.1997 / 03:12:30 / cg" |
|
305 |
! |
|
306 |
||
307 |
statusMenu |
|
308 |
"return a popUpMenu" |
|
309 |
||
1692 | 310 |
<resource: #programMenu> |
311 |
||
4253 | 312 |
|labels selectors m| |
980 | 313 |
|
314 |
labels := resources array:#( |
|
17226 | 315 |
'Inspect' |
316 |
'Inspect Waiters' |
|
317 |
'Debug Waiters' |
|
318 |
'Debug Last Owning Process' |
|
319 |
'-' |
|
320 |
'Signal' |
|
321 |
). |
|
980 | 322 |
selectors := #( |
17226 | 323 |
inspectSemaphore |
324 |
inspectWaiters |
|
325 |
debugWaiters |
|
326 |
debugLastOwningProcess |
|
327 |
nil |
|
328 |
signalSemaphore |
|
329 |
). |
|
980 | 330 |
|
331 |
updateProcess isNil ifTrue:[ |
|
17226 | 332 |
labels := (resources array:#('Update' '-')) , labels. |
333 |
selectors := #(updateView nil) , selectors |
|
980 | 334 |
]. |
335 |
||
336 |
m := PopUpMenu labels:labels |
|
17226 | 337 |
selectors:selectors. |
980 | 338 |
|
339 |
||
340 |
listView hasSelection ifFalse:[ |
|
17226 | 341 |
m disableAll:#( |
342 |
inspectSemaphore |
|
343 |
inspectWaiters |
|
344 |
debugWaiters |
|
345 |
debugLastOwningProcess |
|
346 |
signalSemaphore |
|
347 |
) |
|
980 | 348 |
]. |
349 |
^ m |
|
350 |
||
1692 | 351 |
"Modified: / 17.6.1998 / 14:17:05 / cg" |
980 | 352 |
! ! |
353 |
||
354 |
!SemaphoreMonitor methodsFor:'queries'! |
|
355 |
||
17169 | 356 |
numberOfHeadlines |
357 |
^ 2 |
|
980 | 358 |
! ! |
359 |
||
360 |
!SemaphoreMonitor methodsFor:'user actions'! |
|
361 |
||
362 |
doubleClicked |
|
363 |
"open an inspector on the selected semaphore" |
|
364 |
||
1023 | 365 |
self inspectSemaphore |
980 | 366 |
|
367 |
"Created: 23.1.1997 / 03:22:04 / cg" |
|
1023 | 368 |
"Modified: 31.1.1997 / 22:33:27 / cg" |
980 | 369 |
! ! |
370 |
||
371 |
!SemaphoreMonitor class methodsFor:'documentation'! |
|
372 |
||
373 |
version |
|
17169 | 374 |
^ '$Header$' |
980 | 375 |
! ! |
12399 | 376 |