forked from pharo-project/pharo
/
ProcessBrowser.class.st
1175 lines (1018 loc) · 32.2 KB
/
ProcessBrowser.class.st
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
"
Change Set: ProcessBrowser
Date: 14 March 2000
Author: Ned Konz
email: ned@bike-nomad.com
This is distributed under the Squeak License.
Added 14 March:
CPUWatcher integration
automatically start and stop CPUWatcher
added CPUWatcher to process list menu
Added 29 October:
MVC version
2.8, 2.7 compatibility
rearranged menus
added pointer inspection and chasing
added suspend/resume
recognized more well-known processes
misc. bug fixes
Added 26 October: highlight pc in source code
Added 27 October: added 'signal semaphore'
added 'inspect receiver', 'explore receiver', 'message tally' to stack list menu
added 'find context', 'next context' to process list menu
added 'change priority' and 'debug' choices to process list menu
27 October mods by Bob Arning:
alters process display in Ned's ProcessBrowser to
- show process priority
- drop 'a Process in' that appears on each line
- show in priority order
- prettier names for known processes
- fix to Utilities to forget update downloading process when it ends (1 less dead
process)
- correct stack dump for the active process
"
Class {
#name : #ProcessBrowser,
#superclass : #Model,
#instVars : [
'selectedProcess',
'selectedContext',
'methodText',
'processList',
'processListIndex',
'stackList',
'stackListIndex',
'selectedClass',
'selectedSelector',
'searchString',
'autoUpdateProcess',
'deferredMessageRecipient',
'lastUpdate',
'startedCPUWatcher',
'keyEventsDict',
'textModel'
],
#classVars : [
'SuspendedProcesses',
'WellKnownProcesses'
],
#category : #'Tool-ProcessBrowser'
}
{ #category : #initialization }
ProcessBrowser class >> cleanUp [
"Remove terminated processes from my suspended list"
self suspendedProcesses keysDo: [:ea |
ea isTerminated ifTrue: [self suspendedProcesses removeKey: ea]]
]
{ #category : #'process control' }
ProcessBrowser class >> debugProcess: aProcess [
self resumeProcess: aProcess.
aProcess debugWithTitle: 'Interrupted from the Process Browser'.
]
{ #category : #'CPU utilization' }
ProcessBrowser class >> dumpPigStackOn: aStream [
"Must run forked on its own process, so the monitored behavior is not affected too much"
| promise tally process depth stack suspendedContext |
promise := Processor tallyCPUUsageFor: 1 every: 10.
tally := promise value.
"WorldState addDeferredUIMessage: [self dumpTallyOnTranscript: tally]."
aStream nextPutAll: '====Al processes===='; cr.
self dumpTally: tally on: aStream.
aStream cr; nextPutAll: '====Process using most CPU===='; cr.
process := tally sortedCounts first value.
(100.0 * (tally occurrencesOf: process) / tally size) rounded printOn: aStream.
aStream
nextPutAll: ' % ';
nextPutAll: (process browserPrintStringWith: (self nameAndRulesFor: process) first);
cr.
depth := 20.
stack := process == Processor activeProcess
ifTrue: [thisContext stackOfSize: depth]
ifFalse: [suspendedContext := process suspendedContext.
suspendedContext
ifNotNil: [suspendedContext stackOfSize: depth]].
stack
ifNil: [ aStream nextPutAll: 'No context'; cr]
ifNotNil: [
stack do: [ :c |
c printOn: aStream.
aStream cr]].
]
{ #category : #'CPU utilization' }
ProcessBrowser class >> dumpTally: tally on: aStream [
"tally is from ProcessorScheduler>>tallyCPUUsageFor:
Dumps lines with percentage of time, hash of process, and a friendly name"
tally sortedCounts do: [ :assoc | | procName |
procName := (self nameAndRulesFor: assoc value) first.
(((assoc key / tally size) * 100.0) roundTo: 1) printOn: aStream.
aStream
nextPutAll: '% ';
print: assoc value identityHash; space;
nextPutAll: procName;
cr.
]
]
{ #category : #'CPU utilization' }
ProcessBrowser class >> dumpTallyOnTranscript: tally [
"tally is from ProcessorScheduler>>tallyCPUUsageFor:
Dumps lines with percentage of time, hash of process, and a friendly name"
self dumpTally: tally on: Transcript.
Transcript flush.
]
{ #category : #initialization }
ProcessBrowser class >> initialize [
"ProcessBrowser initialize"
SuspendedProcesses ifNil: [ SuspendedProcesses := IdentityDictionary new ].
self registerWellKnownProcesses
]
{ #category : #'process control' }
ProcessBrowser class >> isUIProcess: aProcess [
^ aProcess == UIManager default uiProcess
]
{ #category : #'world menu' }
ProcessBrowser class >> menuCommandOn: aBuilder [
<worldMenu>
(aBuilder item: #'Process Browser')
parent: #System;
order: 0;
action:[ self open ];
help: 'Provides a view of all of the processes (threads) executing in Smalltalk.';
icon: self taskbarIcon.
]
{ #category : #'process control' }
ProcessBrowser class >> nameAndRulesFor: aProcess [
"Answer a nickname and two flags: allow-stop, and allow-debug"
| rules |
rules := {nil. true. true}.
WellKnownProcesses do: [:blockAndRules |
blockAndRules key value == aProcess
ifTrue: [ rules := blockAndRules value value ]].
rules first ifNil: [
rules at: 1 put: aProcess suspendedContext asString ].
^ rules
]
{ #category : #'instance creation' }
ProcessBrowser class >> open [
"ProcessBrowser open"
"Create and schedule a ProcessBrowser."
Smalltalk garbageCollect.
^ self new build
]
{ #category : #'tools registry' }
ProcessBrowser class >> registerToolsOn: registry [
"Add ourselves to registry. See [Smalltalk tools]"
registry register: self as: #processBrowser
]
{ #category : #'process control' }
ProcessBrowser class >> registerWellKnownProcess: aBlockForProcess label: nickname allowStop: allowStop allowDebug: allowDebug [
"Add an entry to the registry of well known processes. aBlockForProcess
evaluates to a known process to be identified by nickname, and allowStop
and allowDebug are flags controlling allowable actions for this process
in the browser."
WellKnownProcesses add: aBlockForProcess->[{nickname . allowStop . allowDebug}]
]
{ #category : #initialization }
ProcessBrowser class >> registerWellKnownProcesses [
"Associate each well-known process with a nickname and two flags: allow-stop, and allow-debug.
Additional processes may be added to this list as required"
WellKnownProcesses := OrderedCollection new.
self
registerWellKnownProcess: [ ]
label: 'no process'
allowStop: false
allowDebug: false.
self
registerWellKnownProcess: [ Smalltalk lowSpaceWatcherProcess ]
label: nil
allowStop: false
allowDebug: false.
self
registerWellKnownProcess: [ WeakArray runningFinalizationProcess ]
label: nil
allowStop: false
allowDebug: false.
self
registerWellKnownProcess: [ Processor backgroundProcess ]
label: nil
allowStop: false
allowDebug: false.
self
registerWellKnownProcess: [ InputEventFetcher default fetcherProcess ]
label: nil
allowStop: false
allowDebug: false.
self
registerWellKnownProcess: [ UIManager default uiProcess ]
label: nil
allowStop: false
allowDebug: false.
self
registerWellKnownProcess: [ Smalltalk globals at: #CPUWatcher ifPresent: [ :cw | cw currentWatcherProcess ] ]
label: 'the CPUWatcher'
allowStop: false
allowDebug: false.
self
registerWellKnownProcess: [ Delay schedulingProcess ]
label: nil
allowStop: false
allowDebug: false
]
{ #category : #'process control' }
ProcessBrowser class >> resumeProcess: aProcess [
| priority |
priority := self suspendedProcesses
removeKey: aProcess
ifAbsent: [aProcess priority].
aProcess priority: priority.
aProcess suspendedContext ifNotNil: [ aProcess resume ]
]
{ #category : #'process control' }
ProcessBrowser class >> setProcess: aProcess toPriority: priority [
| oldPriority |
oldPriority := self suspendedProcesses at: aProcess ifAbsent: [ ].
oldPriority ifNotNil: [ self suspendedProcesses at: aProcess put: priority ].
aProcess priority: priority.
^oldPriority
]
{ #category : #'process control' }
ProcessBrowser class >> suspendProcess: aProcess [
| priority |
priority := aProcess priority.
self suspendedProcesses at: aProcess put: priority.
"Need to take the priority down below the caller's
so that it can keep control after signaling the Semaphore"
(aProcess suspendingList isKindOf: Semaphore)
ifTrue: [aProcess priority: Processor lowestPriority.
aProcess suspendingList signal].
[aProcess suspend]
on: Error
do: [:ex | self suspendedProcesses removeKey: aProcess].
aProcess priority: priority.
]
{ #category : #'process control' }
ProcessBrowser class >> suspendedProcesses [
"Answer a collection of processes that my instances have suspended.
This is so that they don't get garbage collected."
^ SuspendedProcesses
ifNil: [SuspendedProcesses := IdentityDictionary new]
]
{ #category : #'CPU utilization' }
ProcessBrowser class >> tallyCPUUsageFor: seconds [
"Compute CPU usage using a 10-msec sample for the given number of seconds,
then dump the usage statistics on the Transcript. The UI is free to continue, meanwhile"
"ProcessBrowser tallyCPUUsageFor: 10"
^self tallyCPUUsageFor: seconds every: 10
]
{ #category : #'CPU utilization' }
ProcessBrowser class >> tallyCPUUsageFor: seconds every: msec [
"Compute CPU usage using a msec millisecond sample for the given number of seconds,
then dump the usage statistics on the Transcript. The UI is free to continue, meanwhile"
"ProcessBrowser tallyCPUUsageFor: 10 every: 100"
| promise |
promise := Processor tallyCPUUsageFor: seconds every: msec.
[ | tally |
tally := promise value.
UIManager default defer: [ self dumpTallyOnTranscript: tally ].
] fork.
]
{ #category : #icons }
ProcessBrowser class >> taskbarIconName [
"Answer the icon for the receiver in a task bar."
^#processBrowserIcon
]
{ #category : #'process control' }
ProcessBrowser class >> terminateProcess: aProcess [
aProcess ifNotNil: [
self suspendedProcesses
removeKey: aProcess
ifAbsent: [].
aProcess terminate
].
]
{ #category : #'process control' }
ProcessBrowser class >> unregisterWellKnownProcess: aProcess [
"Remove the first registry entry that matches aProcess. Use
with caution if more than one registry entry may match aProcess."
"self unregisterWellKnownProcess: Smalltalk lowSpaceWatcherProcess"
WellKnownProcesses detect: [ :e | e key value == aProcess ] ifFound: [ :entry | WellKnownProcesses remove: entry ]
]
{ #category : #'process control' }
ProcessBrowser class >> wasProcessSuspendedByProcessBrowser: aProcess [
^self suspendedProcesses includesKey: aProcess
]
{ #category : #'stack list' }
ProcessBrowser >> browseContext [
selectedContext ifNil: [ ^ self ].
Smalltalk tools browser openOnClass: self selectedClass selector: self selectedSelector
]
{ #category : #views }
ProcessBrowser >> browsedEnvironment [
^ Smalltalk globals
]
{ #category : #views }
ProcessBrowser >> build [
| window scrolledText |
window := (SystemWindow labelled: 'later') model: self.
self deferredMessageRecipient: WorldState.
window
addMorph: ((PluggableListMorph
on: self
list: #processNameList
selected: #processListIndex
changeSelected: #processListIndex:
menu: #menuProcessList:
keystroke: #processListKey:from:)
enableDragNDrop: false)
frame: (0 @ 0 extent: 0.5 @ 0.5).
window
addMorph: ((PluggableListMorph
on: self
list: #stackNameList
selected: #stackListIndex
changeSelected: #stackListIndex:
menu: #stackListMenu:
keystroke: #stackListKey:from:)
enableDragNDrop: false)
frame: (0.5 @ 0.0 extent: 0.5 @ 0.5).
textModel setText: self methodText.
textModel clearUserEdits.
scrolledText := textModel newScrolledText beForSmalltalkCode; yourself.
window
addMorph: scrolledText
frame: (0 @ 0.5 corner: 1 @ 1).
window setUpdatablePanesFrom: #(#processNameList #stackNameList ).
(window setLabel: 'Process Browser') openInWorld.
self mayBeStartCPUWatcher.
^ window
]
{ #category : #'process actions' }
ProcessBrowser >> changePriority [
| str newPriority nameAndRules |
nameAndRules := self nameAndRulesForSelectedProcess.
nameAndRules third
ifFalse: [self inform: 'Nope, won''t change priority of ' , nameAndRules first.
^ self].
str := UIManager default
request: 'New priority'
initialAnswer: selectedProcess priority asString.
str ifNil: [str := String new].
newPriority := str asNumber asInteger.
newPriority
ifNil: [^ self].
(newPriority < 1
or: [newPriority > Processor highestPriority])
ifTrue: [self inform: 'Bad priority'.
^ self].
self class setProcess: selectedProcess toPriority: newPriority.
self updateProcessList
]
{ #category : #'stack list' }
ProcessBrowser >> changeStackListTo: aCollection [
stackList := aCollection.
self changed: #stackNameList.
self stackListIndex: 0.
textModel setText: self methodText.
]
{ #category : #'process actions' }
ProcessBrowser >> debugProcess [
| nameAndRules |
nameAndRules := self nameAndRulesForSelectedProcess.
nameAndRules third
ifFalse: [self inform: 'Nope, won''t debug ' , nameAndRules first.
^ self].
self class debugProcess: selectedProcess.
]
{ #category : #accessing }
ProcessBrowser >> deferredMessageRecipient: anObject [
deferredMessageRecipient := anObject
]
{ #category : #accessing }
ProcessBrowser >> doItContext [
^selectedContext
]
{ #category : #accessing }
ProcessBrowser >> doItReceiver [
^selectedContext ifNil: [ selectedProcess ] ifNotNil: [ selectedContext receiver ]
]
{ #category : #'stack list' }
ProcessBrowser >> exploreContext [
selectedContext inspect
]
{ #category : #'process actions' }
ProcessBrowser >> explorePointers [
| saved |
selectedProcess ifNil: [ ^ self ].
saved := selectedProcess.
[ selectedProcess := nil.
(Smalltalk tools hasToolNamed: #pointerExplorer)
ifTrue: [ Smalltalk tools pointerExplorer openOn: saved ]
ifFalse: [ self inspectPointers ] ]
ensure: [ selectedProcess := saved ]
]
{ #category : #'process list' }
ProcessBrowser >> exploreProcess [
selectedProcess inspect
]
{ #category : #'stack list' }
ProcessBrowser >> exploreReceiver [
selectedContext ifNotNil: [ selectedContext receiver inspect ]
]
{ #category : #'process list' }
ProcessBrowser >> findContext [
| initialProcessIndex initialStackIndex found |
initialProcessIndex := self processListIndex.
initialStackIndex := self stackListIndex.
searchString := UIManager default
request: 'Enter a string to search for in the process stack lists'
initialAnswer: searchString.
searchString isEmptyOrNil
ifTrue: [^ false].
self processListIndex: 1.
self stackListIndex: 1.
found := self nextContext.
found
ifFalse: [self processListIndex: initialProcessIndex.
self stackListIndex: initialStackIndex].
^ found
]
{ #category : #views }
ProcessBrowser >> hasView [
^self dependents isEmptyOrNil not
]
{ #category : #initialization }
ProcessBrowser >> initialize [
super initialize.
self class registerWellKnownProcesses.
methodText := ''.
stackListIndex := 0.
searchString := ''.
lastUpdate := 0.
textModel := RubScrolledTextModel new interactionModel: self; yourself.
startedCPUWatcher := CPUWatcher cpuWatcherEnabled and: [ self startCPUWatcher ].
self updateProcessList; processListIndex: 1
]
{ #category : #'stack list' }
ProcessBrowser >> inspectContext [
selectedContext inspect
]
{ #category : #'process actions' }
ProcessBrowser >> inspectPointers [
| tc pointers |
selectedProcess ifNil: [ ^ self ].
tc := thisContext.
pointers := selectedProcess pointersToExcept: { self processList. tc. self}.
pointers ifEmpty: [ ^ self ].
pointers inspectWithLabel: 'Objects pointing to ' , selectedProcess browserPrintString
]
{ #category : #'process list' }
ProcessBrowser >> inspectProcess [
selectedProcess inspect
]
{ #category : #'stack list' }
ProcessBrowser >> inspectReceiver [
selectedContext
ifNotNil: [selectedContext receiver inspect]
]
{ #category : #updating }
ProcessBrowser >> isAutoUpdating [
^autoUpdateProcess notNil and: [ autoUpdateProcess isSuspended not ]
]
{ #category : #updating }
ProcessBrowser >> isAutoUpdatingPaused [
^autoUpdateProcess notNil and: [ autoUpdateProcess isSuspended ]
]
{ #category : #'process list' }
ProcessBrowser >> keyEventsDict [
^ keyEventsDict ifNil: [
keyEventsDict := Dictionary newFromPairs: #(
$i #inspectProcess
$I #exploreProcess
$e #explorePointers
$P #inspectPointers
$t #terminateProcess
$r #resumeProcess
$s #suspendProcess
$d #debugProcess
$p #changePriority
$m #messageTally
$f #findContext
$g #nextContext
$a #toggleAutoUpdate
$u #updateProcessList
$S #signalSemaphore
$k #moreStack
)
]
]
{ #category : #initialization }
ProcessBrowser >> mayBeStartCPUWatcher [
startedCPUWatcher ifTrue: [ self setUpdateCallbackAfter: 7 ].
]
{ #category : #menu }
ProcessBrowser >> menuProcessList: aMenuMorph [
selectedProcess
ifNotNil: [
| nameAndRules |
nameAndRules := self nameAndRulesForSelectedProcess.
aMenuMorph addMenuItem: ((ToggleMenuItemMorph new contents: #'Inspect')
keyText: 'i';
selector: #inspectProcess;
target: self;
yourself).
aMenuMorph addMenuItem: ((ToggleMenuItemMorph new contents: #'Explore')
keyText: 'I';
selector: #exploreProcess;
target: self;
yourself).
aMenuMorph addMenuItem: ((ToggleMenuItemMorph new contents: #'Inspect Pointers')
keyText: 'P';
selector: #inspectPointers;
target: self;
yourself).
(Smalltalk globals includesKey: #PointerExplorer)
ifTrue: [
aMenuMorph addMenuItem: ((ToggleMenuItemMorph new contents: #'Explore pointers')
keyText: 'e';
selector: #explorePointers;
target: self;
yourself). ].
nameAndRules second
ifTrue: [
aMenuMorph addMenuItem: ((ToggleMenuItemMorph new contents: #'Terminate')
keyText: 't';
selector: #terminateProcess;
target: self;
yourself).
selectedProcess isSuspended
ifTrue: [
aMenuMorph addMenuItem: ((ToggleMenuItemMorph new contents: #'Resume')
keyText: 'r';
selector: #resumeProcess;
target: self;
yourself). ]
ifFalse: [
aMenuMorph addMenuItem: ((ToggleMenuItemMorph new contents: #'Suspend')
keyText: 's';
selector: #suspendProcess;
target: self;
yourself). ] ].
nameAndRules third
ifTrue: [
aMenuMorph addMenuItem: ((ToggleMenuItemMorph new contents: #'Change priority')
keyText: 'p';
selector: #changePriority;
target: self;
yourself).
aMenuMorph addMenuItem: ((ToggleMenuItemMorph new contents: #'Debug')
keyText: 'd';
selector: #debugProcess;
target: self;
yourself) ].
aMenuMorph addMenuItem: ((ToggleMenuItemMorph new contents: #'Profile messages')
keyText: 'm';
selector: #messageTally;
target: self;
yourself).
(selectedProcess suspendingList isKindOf: Semaphore)
ifTrue: [
aMenuMorph addMenuItem: ((ToggleMenuItemMorph new contents: #'Signal Semaphore')
keyText: 'S';
selector: #signalSemaphore;
target: self;
yourself). ].
aMenuMorph addMenuItem: ((ToggleMenuItemMorph new contents: #'Full stack')
keyText: 'k';
selector: #moreStack;
target: self;
yourself).
aMenuMorph addMenuItem: (MenuLineMorph new)].
aMenuMorph addMenuItem: ((ToggleMenuItemMorph new contents: #'Find context...')
keyText: 'f';
selector: #findContext;
target: self;
yourself).
aMenuMorph addMenuItem: ((ToggleMenuItemMorph new contents: #'Find again')
keyText: 'g';
selector: #nextContext;
target: self;
yourself).
aMenuMorph addMenuItem: (MenuLineMorph new).
aMenuMorph addMenuItem: ((ToggleMenuItemMorph new contents: (self isAutoUpdating
ifTrue: [ #'Turn off auto-update' ]
ifFalse: [ #'Turn on auto-update' ]))
keyText: 'a';
selector: #toggleAutoUpdate;
target: self;
yourself).
aMenuMorph addMenuItem: ((ToggleMenuItemMorph new contents: #'Update list')
keyText: 'u';
selector: #updateProcessList;
target: self;
yourself).
Smalltalk globals
at: #CPUWatcher
ifPresent: [ :pw |
aMenuMorph addMenuItem: (MenuLineMorph new).
pw isMonitoring
ifTrue: [
aMenuMorph addMenuItem: ((ToggleMenuItemMorph new contents: #'Stop CPUWatcher')
selector: #stopCPUWatcher;
target: self;
yourself) ]
ifFalse: [
aMenuMorph addMenuItem: ((ToggleMenuItemMorph new contents: #'Start CPUWatcher')
selector: #startCPUWatcher;
target: self;
yourself) ] ].
^ aMenuMorph
]
{ #category : #menu }
ProcessBrowser >> menuStackList: aMenuMorph [
aMenuMorph addMenuItem: ((ToggleMenuItemMorph new contents: #'Inspect context')
keyText: 'c';
selector: #inspectContext;
target: self;
yourself).
aMenuMorph addMenuItem: ((ToggleMenuItemMorph new contents: #'Explore context')
keyText: 'C';
selector: #exploreContext;
target: self;
yourself).
aMenuMorph addMenuItem: MenuLineMorph new.
aMenuMorph addMenuItem:((ToggleMenuItemMorph new contents: #'Explore context')
keyText: 'C';
selector: #exploreContext;
target: self;
yourself).
aMenuMorph addMenuItem:((ToggleMenuItemMorph new contents: #'Inspect receiver')
keyText: 'i';
selector: #inspectReceiver;
target: self;
yourself).
aMenuMorph addMenuItem:((ToggleMenuItemMorph new contents: #'Explore receiver')
keyText: 'I';
selector: #exploreReceiver;
target: self;
yourself).
aMenuMorph addMenuItem: MenuLineMorph new.
aMenuMorph addMenuItem:((ToggleMenuItemMorph new contents: #'Browse')
keyText: 'b';
selector: #browseContext;
target: self;
yourself).
]
{ #category : #'stack list' }
ProcessBrowser >> messageTally [
| secString secs |
secString := UIManager default request: 'Profile for how many seconds?' initialAnswer: '4'.
secString ifNil: [secString := String new].
secs := secString asNumber asInteger.
(secs isNil
or: [secs isZero])
ifTrue: [^ self].
[ Smalltalk tools timeProfiler spyOnProcess: selectedProcess forMilliseconds: secs * 1000 ] forkAt: selectedProcess priority + 1.
]
{ #category : #accessing }
ProcessBrowser >> methodText [
^ methodText ifNil: [methodText := selectedContext
ifNil: ['']
ifNotNil: [| pcRange |
methodText := [ selectedContext sourceCode ]
onErrorDo: [ 'error getting method text' ].
pcRange := self pcRange.
methodText asText
addAttribute: TextColor red
from: pcRange first
to: pcRange last;
addAttribute: TextEmphasis bold
from: pcRange first
to: pcRange last]]
]
{ #category : #'stack list' }
ProcessBrowser >> moreStack [
self updateStackList: 2000
]
{ #category : #'process actions' }
ProcessBrowser >> nameAndRulesFor: aProcess [
"Answer a nickname and two flags: allow-stop, and allow-debug"
aProcess == autoUpdateProcess ifTrue: [ ^{'my auto-update process'. true. true} ].
^self class nameAndRulesFor: aProcess
]
{ #category : #'process actions' }
ProcessBrowser >> nameAndRulesForSelectedProcess [
"Answer a nickname and two flags: allow-stop, and allow-debug"
^self nameAndRulesFor: selectedProcess
]
{ #category : #'process list' }
ProcessBrowser >> nextContext [
| initialProcessIndex initialStackIndex found |
searchString isEmpty ifTrue: [ ^false ].
initialProcessIndex := self processListIndex.
initialStackIndex := self stackListIndex.
found := false.
initialProcessIndex
to: self processList size
do: [:pi | found
ifFalse: [self processListIndex: pi.
self stackNameList
withIndexDo: [:name :si | (found not
and: [pi ~= initialProcessIndex
or: [si > initialStackIndex]])
ifTrue: [(name includesSubstring: searchString)
ifTrue: [self stackListIndex: si.
found := true]]]]].
found
ifFalse: [self processListIndex: initialProcessIndex.
self stackListIndex: initialStackIndex].
^ found
]
{ #category : #'process list' }
ProcessBrowser >> notify: errorString at: location in: aStream [
"A syntax error happened when I was trying to highlight my pc.
Raise a signal so that it can be ignored."
Warning signal: 'syntax error'
]
{ #category : #updating }
ProcessBrowser >> pauseAutoUpdate [
self isAutoUpdating
ifTrue: [ autoUpdateProcess suspend ].
self updateProcessList
]
{ #category : #'stack list' }
ProcessBrowser >> pcRange [
"Answer the indices in the source code for the method corresponding to
the selected context's program counter value."
(selectedContext isNil or: [methodText isEmptyOrNil])
ifTrue: [^ 1 to: 0].
^selectedContext pcRangeContextIsActive: (stackListIndex = 1)
]
{ #category : #'process list' }
ProcessBrowser >> prettyNameForProcess: aProcess [
| nameAndRules |
aProcess ifNil: [ ^'<nil>' ].
nameAndRules := self nameAndRulesFor: aProcess.
^ aProcess browserPrintStringWith: nameAndRules first
]
{ #category : #accessing }
ProcessBrowser >> processList [
^ processList
]
{ #category : #accessing }
ProcessBrowser >> processListIndex [
^ processListIndex
]
{ #category : #accessing }
ProcessBrowser >> processListIndex: index [
processListIndex := index.
selectedProcess := processList
at: index
ifAbsent: [].
self updateStackList.
self changed: #processListIndex.
]
{ #category : #'process list' }
ProcessBrowser >> processListKey: aKey from: aView [
self perform: (self keyEventsDict at: aKey ifAbsent: [ ^ self ])
]
{ #category : #'process list' }
ProcessBrowser >> processNameList [
"since processList is a WeakArray, we have to strengthen the result"
| tally |
tally := CPUWatcher ifNotNil: [ CPUWatcher current ifNotNil: [ CPUWatcher current tally ] ].
^ (processList asOrderedCollection copyWithout: nil)
collect: [ :each |
| percent |
percent := tally
ifNotNil: [ (((tally occurrencesOf: each) * 100.0 / tally size roundTo: 1) asString padLeftTo: 2) , '% ' ]
ifNil: [ '' ].
percent , (self prettyNameForProcess: each) ]
]
{ #category : #views }
ProcessBrowser >> refactor [
^ NautilusRefactoring model: self
]
{ #category : #'process actions' }
ProcessBrowser >> resumeProcess [
selectedProcess
ifNil: [^ self].
self class resumeProcess: selectedProcess.
self updateProcessList
]
{ #category : #accessing }
ProcessBrowser >> selectedClass [
"Answer the class in which the currently selected context's method was found."
^ selectedClass
ifNil: [ selectedClass := selectedContext receiver
ifNil: [ selectedSelector := selectedContext method selector.
selectedContext method methodClass ]
ifNotNil: [ selectedContext methodClass ]]
]
{ #category : #accessing }
ProcessBrowser >> selectedClassOrMetaClass [
^self doItReceiver class
]
{ #category : #accessing }
ProcessBrowser >> selectedMethod [
^selectedContext ifNotNil: [ selectedContext method ]
]
{ #category : #accessing }
ProcessBrowser >> selectedProcess [
^selectedProcess
]
{ #category : #accessing }
ProcessBrowser >> selectedSelector [
"Answer the class in which the currently selected context's method was
found."
^ selectedSelector
ifNil: [selectedSelector := selectedContext receiver
ifNil: [selectedClass := selectedContext method methodClass
selectedContext method selector]
ifNotNil: [selectedContext selector]]
]
{ #category : #updating }
ProcessBrowser >> setUpdateCallbackAfter: seconds [
deferredMessageRecipient
ifNotNil: [
| d |
d := Delay forSeconds: seconds.
[ d wait.
d := nil.
deferredMessageRecipient defer: [ self updateProcessList ] ] fork ]
]
{ #category : #updating }
ProcessBrowser >> shoutAboutToStyle: aPluggableShoutMorphOrView [
selectedContext ifNil: [^false].
aPluggableShoutMorphOrView classOrMetaClass: self selectedClass.
^ true
]
{ #category : #'process actions' }
ProcessBrowser >> signalSemaphore [
(selectedProcess suspendingList isKindOf: Semaphore)
ifFalse: [^ self].
[selectedProcess suspendingList signal] fork.
(Delay forMilliseconds: 300) wait.
"Hate to make the UI wait, but it's convenient..."
self updateProcessList
]
{ #category : #accessing }
ProcessBrowser >> stackList [
^ stackList
]
{ #category : #accessing }
ProcessBrowser >> stackListIndex [
^ stackListIndex
]
{ #category : #accessing }