ProcessMonitor.st
changeset 656 3a625e4aa73f
parent 619 62db60834422
child 663 befe6a1d886f
equal deleted inserted replaced
655:c9a1de4e627a 656:3a625e4aa73f
    17 	classVariableNames:''
    17 	classVariableNames:''
    18 	poolDictionaries:''
    18 	poolDictionaries:''
    19 	category:'Interface-Tools'
    19 	category:'Interface-Tools'
    20 !
    20 !
    21 
    21 
    22 !ProcessMonitor class methodsFor:'documentation'!
    22 !ProcessMonitor  class methodsFor:'documentation'!
    23 
    23 
    24 copyright
    24 copyright
    25 "
    25 "
    26  COPYRIGHT (c) 1993 by Claus Gittinger
    26  COPYRIGHT (c) 1993 by Claus Gittinger
    27 	      All Rights Reserved
    27 	      All Rights Reserved
    62 	usedStack  - the current stack use
    62 	usedStack  - the current stack use
    63 	totalStack - the stack currently allocated (i.e. the maximum ever needed)
    63 	totalStack - the stack currently allocated (i.e. the maximum ever needed)
    64 "
    64 "
    65 ! !
    65 ! !
    66 
    66 
    67 !ProcessMonitor class methodsFor:'defaults'!
    67 !ProcessMonitor  class methodsFor:'defaults'!
    68 
    68 
    69 defaultIcon
    69 defaultIcon
    70     |i|
    70     |i|
    71 
    71 
    72     i := Image fromFile:'ProcMon.xbm'.
    72     i := Image fromFile:'ProcMon.xbm'.
    76 
    76 
    77 defaultLabel
    77 defaultLabel
    78     ^ 'Process Monitor'
    78     ^ 'Process Monitor'
    79 ! !
    79 ! !
    80 
    80 
    81 !ProcessMonitor class methodsFor:'startup'!
    81 !ProcessMonitor  class methodsFor:'startup'!
    82 
    82 
    83 open
    83 open
    84     |top monitor|
    84     |top monitor|
    85 
    85 
    86     top := StandardSystemView new.
    86     top := StandardSystemView new.
   109 
   109 
   110 !ProcessMonitor methodsFor:'drawing'!
   110 !ProcessMonitor methodsFor:'drawing'!
   111 
   111 
   112 titleLine
   112 titleLine
   113     showDetail ifTrue:[
   113     showDetail ifTrue:[
   114     ^ 'id   name                           state    prio   usedStack  totalStack   current-segment   switches   where'.
   114     ^ 'id   name                           state    prio usedStack    totalStack   current-segment    switches  where'.
   115     ].
   115     ].
   116     ^ 'id   name                           state    prio   usedStack  where'.
   116     ^ 'id   name                           state    prio usedStack  where'.
       
   117 
       
   118     "Modified: 3.7.1996 / 13:57:38 / stefan"
   117 !
   119 !
   118 
   120 
   119 updateList
   121 updateList
   120     "update list of processes"
   122     "update list of processes"
   121 
   123 
   125         showDetail ifTrue:[
   127         showDetail ifTrue:[
   126             newList := Process allInstances asOrderedCollection.
   128             newList := Process allInstances asOrderedCollection.
   127         ] ifFalse:[
   129         ] ifFalse:[
   128             newList := ProcessorScheduler knownProcesses asOrderedCollection.
   130             newList := ProcessorScheduler knownProcesses asOrderedCollection.
   129         ].
   131         ].
   130         newList := newList  select:[:p | p id notNil].
       
   131 
   132 
   132         "sort by id - take care of nil ids of dead processes"
   133         "sort by id - take care of nil ids of dead processes"
   133         newList sort:[:p1 :p2 |
   134         newList sort:[:p1 :p2 |
   134                          |id1 id2|
   135                          |id1 id2|
   135 
   136 
   148     ].
   149     ].
   149     updateBlock notNil ifTrue:[
   150     updateBlock notNil ifTrue:[
   150         Processor removeTimedBlock:listUpdateBlock.
   151         Processor removeTimedBlock:listUpdateBlock.
   151         Processor addTimedBlock:listUpdateBlock afterSeconds:listUpdateDelay
   152         Processor addTimedBlock:listUpdateBlock afterSeconds:listUpdateDelay
   152     ].
   153     ].
       
   154 
       
   155     "Modified: 3.7.1996 / 13:37:29 / stefan"
   153 !
   156 !
   154 
   157 
   155 updateStatus
   158 updateStatus
   156     "update status display of processes"
   159     "update status display of processes"
   157 
   160 
   158     |oldList list line dIndex con interrupted plist 
   161     |oldList list line dIndex interrupted  
   159      aProcess nm st c c0 n found sender running sel|
   162      aProcess nm st n found running sel space|
       
   163 
       
   164     space := Character space.
   160 
   165 
   161     shown ifTrue:[
   166     shown ifTrue:[
   162         oldList := listView list.
   167         oldList := listView list.
   163         processes notNil ifTrue:[
   168         processes notNil ifTrue:[
   164             list := OrderedCollection new.
   169             list := OrderedCollection new:(processes size + 2).
   165             list add:self titleLine.
   170             list add:self titleLine.
   166             list add:(String new:self titleLine size withAll:$-).
   171             list add:(String new:self titleLine size withAll:$-).
   167 
   172 
   168             interrupted := Processor interruptedProcess.
   173             interrupted := Processor interruptedProcess.
   169 
   174 
   170             dIndex := 1.
   175             dIndex := 1.
   171             1 to:processes size do:[:index |
   176             1 to:processes size do:[:index |
   172                 |totalStack|
   177                 |con c totalStack sender|
   173 
   178 
   174                 aProcess := processes at:index.
   179                 aProcess := processes at:index.
   175                 aProcess notNil ifTrue:[
   180                 aProcess notNil ifTrue:[
   176                     (aProcess id notNil or:[hideDead not]) ifTrue:[
   181                     (aProcess id notNil or:[hideDead not]) ifTrue:[
   177                         line := aProcess id printStringPaddedTo:5.
   182                         line := WriteStream on:(String new:200).
       
   183 
       
   184                         aProcess id printOn:line paddedTo:5.
   178                         (nm := aProcess name) isNil ifFalse:[
   185                         (nm := aProcess name) isNil ifFalse:[
   179                             nm := nm printString
   186                             nm := nm printStringPaddedTo:28.
       
   187                             nm size >= 29 ifTrue:[
       
   188                                 nm := (nm contractTo:28).
       
   189                             ].
       
   190                             line nextPutAll:nm; nextPut:space.
   180                         ] ifTrue:[
   191                         ] ifTrue:[
   181                             nm := ' '
   192                             line next:29 put:space.
   182                         ].
   193                         ].
   183                         nm size >= 29 ifTrue:[
       
   184                             nm := (nm contractTo:28) , ' '
       
   185                         ] ifFalse:[
       
   186                             nm := (nm printStringPaddedTo:29).
       
   187                         ].
       
   188                         line := line , nm.
       
   189 "/                        n := cpuUsages at:(aProcess id) ifAbsent:[0].
   194 "/                        n := cpuUsages at:(aProcess id) ifAbsent:[0].
   190 "/                        n ~~ 0 ifTrue:[
   195 "/                        n ~~ 0 ifTrue:[
   191 "/                            line := line , ((n * 4) printStringLeftPaddedTo:3)
   196 "/                            line := line , ((n * 4) printStringLeftPaddedTo:3)
   192 "/                        ] ifFalse:[
   197 "/                        ] ifFalse:[
   193 "/                            line := line , '   '
   198 "/                            line := line , '   '
   199                             running := true.
   204                             running := true.
   200                         ] ifFalse:[
   205                         ] ifFalse:[
   201                             c := '  '.
   206                             c := '  '.
   202                             running := false.
   207                             running := false.
   203                         ].
   208                         ].
   204                         line := line , c , (st printStringPaddedTo:9).
   209                         line nextPutAll:c; nextPutAll:(st printStringPaddedTo:9).
   205                         line := line , (aProcess priority printStringLeftPaddedTo:3).
   210                         line nextPutAll:(aProcess priority printStringLeftPaddedTo:3).
   206                         line := line , (aProcess usedStackSize printStringLeftPaddedTo:11).
   211                         line nextPutAll:(aProcess usedStackSize printStringLeftPaddedTo:11).
   207 
   212 
   208                         n := aProcess numberOfStackSegments.
   213                         con := aProcess suspendedContext.
   209                         true "showDetail" ifTrue:[
   214                         con isNil ifTrue:[
   210                             con := aProcess suspendedContext.
   215                             aProcess == Processor activeProcess ifTrue:[
   211                             con isNil ifTrue:[
   216                                 con := thisContext
   212                                 aProcess == Processor activeProcess ifTrue:[
   217                             ]
   213                                     con := thisContext
       
   214                                 ]
       
   215                             ].
       
   216                         ].
   218                         ].
       
   219 
   217                         showDetail ifTrue:[
   220                         showDetail ifTrue:[
   218                             aProcess id == 0 ifTrue:[
   221                             aProcess id == 0 ifTrue:[
   219                                 line := line , ('unlimited' leftPaddedTo:13).
   222                                 line nextPutAll:('unlimited' leftPaddedTo:13).
   220                             ] ifFalse:[
   223                             ] ifFalse:[
   221                                 line := line , (aProcess totalStackSize printStringLeftPaddedTo:10).
   224                                 n := aProcess numberOfStackSegments.
   222                                 line := line , '(' , n printString , ')'.
   225                                 line nextPutAll:(aProcess totalStackSize printStringLeftPaddedTo:10).
       
   226                                 line nextPut:$( ; nextPutAll:n printString; nextPut:$).
   223                             ].
   227                             ].
   224                             con notNil ifTrue:[
   228                             con notNil ifTrue:[
   225                                 line := line , '    '.
   229                                 line nextPutAll:'    '.
   226                                 line := line , (((ObjectMemory addressOf:con) printStringRadix:16) leftPaddedTo:8 with:$0).
   230                                 line nextPutAll:(((ObjectMemory addressOf:con) printStringRadix:16) leftPaddedTo:8 with:$0).
   227                                 line := line , ' .. '.
   231                                 line nextPutAll:' .. '.
   228                                 c := con.
   232                                 c := con.
   229                                 [(sender := c sender) notNil] whileTrue:[
   233                                 [(sender := c sender) notNil] whileTrue:[
   230                                     c := sender
   234                                     c := sender
   231                                 ].
   235                                 ].
   232                                 line := line , (((ObjectMemory addressOf:c) printStringRadix:16) leftPaddedTo:8 with:$0).
   236                                 line nextPutAll:(((ObjectMemory addressOf:c) printStringRadix:16) leftPaddedTo:8 with:$0).
   233                             ] ifFalse:[
   237                             ] ifFalse:[
   234                                 line := line , (String new:20)
   238                                 line next:20 put:space.
   235                             ].
   239                             ].
   236                             line := line , ' '.
   240                             line nextPut:space.
   237                             line := line , (aProcess numberOfStackBoundaryHits printStringLeftPaddedTo:5).
   241                             line nextPutAll:(aProcess numberOfStackBoundaryHits printStringLeftPaddedTo:6).
   238                         ].
   242                         ].
   239 
   243 
   240                         con notNil ifTrue:[
   244                         con notNil ifTrue:[
   241                             c := con.
   245                             c := con.
   242                             found := false.
   246                             found := false.
   285                             c notNil ifTrue:[
   289                             c notNil ifTrue:[
   286                                 sel := c selector.
   290                                 sel := c selector.
   287                                 sel isNil ifTrue:[
   291                                 sel isNil ifTrue:[
   288                                     sel := '* unknown *'
   292                                     sel := '* unknown *'
   289                                 ].
   293                                 ].
   290                                 n := c receiver class name , '>>' , sel.
   294                                 line nextPutAll:'  '.
   291                                 line := line , '   ' , n
   295                                 line nextPutAll:c receiver class name.
       
   296                                 line nextPutAll:'>>'; nextPutAll:sel.
   292                             ]
   297                             ]
   293                         ].
   298                         ].
   294                         list add:line.
   299                         list add:line contents.
   295                         processes at:dIndex put:aProcess.
   300                         processes at:dIndex put:aProcess.
   296                         dIndex := dIndex + 1
   301                         dIndex := dIndex + 1
   297                     ]
   302                     ]
   298                 ].
   303                 ].
   299             ].
   304             ].
   320         Processor removeTimedBlock:updateBlock.
   325         Processor removeTimedBlock:updateBlock.
   321         Processor addTimedBlock:updateBlock afterSeconds:updateDelay
   326         Processor addTimedBlock:updateBlock afterSeconds:updateDelay
   322     ]
   327     ]
   323 
   328 
   324     "Modified: 27.4.1996 / 14:17:15 / cg"
   329     "Modified: 27.4.1996 / 14:17:15 / cg"
       
   330     "Modified: 3.7.1996 / 13:56:01 / stefan"
   325 !
   331 !
   326 
   332 
   327 updateView
   333 updateView
   328     self updateList.
   334     self updateList.
   329     self updateStatus
   335     self updateStatus
   628 
   634 
   629 preferredExtent
   635 preferredExtent
   630     ^ (font widthOf:self titleLine) + 40 @ 100
   636     ^ (font widthOf:self titleLine) + 40 @ 100
   631 ! !
   637 ! !
   632 
   638 
   633 !ProcessMonitor class methodsFor:'documentation'!
   639 !ProcessMonitor  class methodsFor:'documentation'!
   634 
   640 
   635 version
   641 version
   636 ^ '$Header: /cvs/stx/stx/libtool/ProcessMonitor.st,v 1.36 1996-06-12 18:28:14 cg Exp $'! !
   642 ^ '$Header: /cvs/stx/stx/libtool/ProcessMonitor.st,v 1.37 1996-07-03 12:59:46 stefan Exp $'! !