MemoryMonitorView.st
branchjv
changeset 17136 cb908d2ba02e
parent 16748 62486fba2d74
parent 17013 cf59893a8693
equal deleted inserted replaced
17135:81b78926f09a 17136:cb908d2ba02e
     1 "{ Encoding: utf8 }"
       
     2 
       
     3 "
     1 "
     4  COPYRIGHT (c) 1991 by Claus Gittinger
     2  COPYRIGHT (c) 1991 by Claus Gittinger
     5 	      All Rights Reserved
     3 	      All Rights Reserved
     6 
     4 
     7  This software is furnished under a license and may be used
     5  This software is furnished under a license and may be used
    19 	instanceVariableNames:'updateInterval updateBlock myProcess oldData newData freeData
    17 	instanceVariableNames:'updateInterval updateBlock myProcess oldData newData freeData
    20 		updateIndex org maxTotal minTotal dX newColor freeColor oldColor
    18 		updateIndex org maxTotal minTotal dX newColor freeColor oldColor
    21 		prevTotal prevLimit prevFree prevFree2 prevOld scale drawLock
    19 		prevTotal prevLimit prevFree prevFree2 prevOld scale drawLock
    22 		prevMemUsed prevCodeUsed prevNumWeak prevNumRem prevNumLifoRem
    20 		prevMemUsed prevCodeUsed prevNumWeak prevNumRem prevNumLifoRem
    23 		prevTenureAge prevIGCPhase prevLastScavengeReclamation
    21 		prevTenureAge prevIGCPhase prevLastScavengeReclamation
    24 		prevMinScavengeReclamation prevScavengeCount mallocColor'
    22 		prevMinScavengeReclamation prevScavengeCount mallocColor
       
    23 		drawAction'
    25 	classVariableNames:''
    24 	classVariableNames:''
    26 	poolDictionaries:''
    25 	poolDictionaries:''
    27 	category:'Monitors-ST/X'
    26 	category:'Monitors-ST/X'
    28 !
    27 !
    29 
    28 
    95 
    94 
    96 
    95 
    97     the popupMenu offers GC functions; keyboard options are:
    96     the popupMenu offers GC functions; keyboard options are:
    98         'f' -> faster; 's' -> slower; 'r' -> reset min/max
    97         'f' -> faster; 's' -> slower; 'r' -> reset min/max
    99 
    98 
       
    99     Disclaimer:
       
   100         this was one of the first tools written for ST/X (around 1989/90);
       
   101         today, it would probably be written differently...
       
   102         
   100     [author:]
   103     [author:]
   101         Claus Gittinger
   104         Claus Gittinger
   102 
   105 
   103     [start with:]
   106     [start with:]
   104         MemoryMonitor open
   107         MemoryMonitor open
   128     self displayOpaqueString:s x:0 y:y.
   131     self displayOpaqueString:s x:0 y:y.
   129 
   132 
   130     "Modified: / 23.9.1998 / 13:19:04 / cg"
   133     "Modified: / 23.9.1998 / 13:19:04 / cg"
   131 !
   134 !
   132 
   135 
       
   136 initializeDrawAction
       
   137     "extracted into a separate block to avoid memory allocation in updateDisplay"
       
   138     
       
   139     drawAction :=
       
   140         [    
       
   141             |total oldSpaceUsed newSpaceUsed freeMem oldSpaceSize
       
   142              realOldSpaceSize symSpaceSize realOldSpaceUsed
       
   143              gWidth shift scaleChange margin|
       
   144 
       
   145             realOldSpaceSize := ObjectMemory oldSpaceSize.
       
   146             symSpaceSize := ObjectMemory symSpaceSize.
       
   147             realOldSpaceUsed := ObjectMemory oldSpaceUsed.
       
   148             
       
   149             oldSpaceUsed := realOldSpaceUsed + ObjectMemory symSpaceUsed.
       
   150             newSpaceUsed := ObjectMemory newSpaceUsed.
       
   151             freeMem := ObjectMemory freeListSpace + (realOldSpaceSize - realOldSpaceUsed).
       
   152             oldSpaceSize := realOldSpaceSize + symSpaceSize.
       
   153             total := oldSpaceSize + ObjectMemory newSpaceSize.
       
   154 
       
   155             scaleChange := false.
       
   156 
       
   157             ((total - freeMem) < minTotal) ifTrue:[
       
   158                 minTotal := total - freeMem.
       
   159                 scaleChange := true
       
   160             ].
       
   161             (total > maxTotal) ifTrue:[
       
   162                 maxTotal := total.
       
   163                 scaleChange := true
       
   164             ].
       
   165 
       
   166             oldData at:updateIndex put:oldSpaceSize. "/ oldSpaceUsed.
       
   167             newData at:updateIndex put:newSpaceUsed.
       
   168             freeData at:updateIndex put:freeMem.
       
   169             updateIndex := updateIndex + 1.
       
   170 
       
   171             scaleChange ifTrue:[
       
   172                 scale := height asFloat / (maxTotal + 100000).
       
   173                 self redraw
       
   174             ].
       
   175 
       
   176             gWidth := width - org.
       
   177             margin := 1.
       
   178 
       
   179             ((updateIndex-1) >= (gWidth - margin)) ifTrue:[
       
   180                 "on slow displays, use:"
       
   181                 "/            shift := gWidth // 4.
       
   182 
       
   183                 "for smooth display, use:"
       
   184                 shift := 1.
       
   185 
       
   186                 oldData replaceFrom:1 with:oldData startingAt:shift+1.
       
   187                 newData replaceFrom:1 with:newData startingAt:shift+1.
       
   188                 freeData replaceFrom:1 with:freeData startingAt:shift+1.
       
   189 
       
   190                 updateIndex := updateIndex - shift.
       
   191                 dX := (dX ? 0) + shift.
       
   192 
       
   193                 "/ before copying, handle any outstanding exposes ...
       
   194                 self repairDamage.
       
   195                 "/ self catchExpose.
       
   196                 self 
       
   197                     copyFrom:self 
       
   198                     x:(org + shift) y:0 toX:org y:0
       
   199                     width:(gWidth - shift - margin) height:height
       
   200                     async:false.
       
   201 
       
   202                 self 
       
   203                     clearRectangleX:(width - margin - shift) y:0 
       
   204                     width:shift height:height.
       
   205 
       
   206                 "/ self waitForExpose.
       
   207             ].
       
   208 
       
   209             self 
       
   210                 updateLineX:(updateIndex - 1 + org - 1)
       
   211                 total:total 
       
   212                 old:oldSpaceSize "/ oldSpaceUsed
       
   213                 new:newSpaceUsed 
       
   214                 free:freeMem.
       
   215 
       
   216             self updateNumbers.
       
   217             self flush.
       
   218         ].
       
   219 !
       
   220 
   133 redraw
   221 redraw
   134     "redraw all"
   222     "redraw all"
   135 
   223 
   136     self clear.
   224     self clear.
   137     self redrawX:0 y:0 width:width height:height
   225     self redrawX:0 y:0 width:width height:height
   199 !
   287 !
   200 
   288 
   201 updateDisplay
   289 updateDisplay
   202     "update picture; trigger next update"
   290     "update picture; trigger next update"
   203 
   291 
   204     |total oldSpaceUsed newSpaceUsed freeMem oldSpaceSize
       
   205      gWidth shift scaleChange margin|
       
   206 
       
   207     shown ifTrue:[
   292     shown ifTrue:[
   208         drawLock wouldBlock ifFalse:[
   293         drawLock wouldBlock ifFalse:[
   209             drawLock critical:[
   294             drawLock critical:drawAction.
   210                 
       
   211                 oldSpaceUsed := ObjectMemory oldSpaceUsed + ObjectMemory symSpaceUsed.
       
   212                 newSpaceUsed := ObjectMemory newSpaceUsed.
       
   213                 freeMem := ObjectMemory freeListSpace + (ObjectMemory oldSpaceSize - ObjectMemory oldSpaceUsed).
       
   214                 oldSpaceSize := ObjectMemory oldSpaceSize + ObjectMemory symSpaceSize.
       
   215                 total := oldSpaceSize + ObjectMemory newSpaceSize.
       
   216 
       
   217                 scaleChange := false.
       
   218 
       
   219                 ((total - freeMem) < minTotal) ifTrue:[
       
   220                     minTotal := total - freeMem.
       
   221                     scaleChange := true
       
   222                 ].
       
   223                 (total > maxTotal) ifTrue:[
       
   224                     maxTotal := total.
       
   225                     scaleChange := true
       
   226                 ].
       
   227 
       
   228                 oldData at:updateIndex put:oldSpaceSize. "/ oldSpaceUsed.
       
   229                 newData at:updateIndex put:newSpaceUsed.
       
   230                 freeData at:updateIndex put:freeMem.
       
   231                 updateIndex := updateIndex + 1.
       
   232 
       
   233                 scaleChange ifTrue:[
       
   234                     scale := height asFloat / (maxTotal + 100000).
       
   235                     self redraw
       
   236                 ].
       
   237 
       
   238                 gWidth := width - org.
       
   239                 margin := 1.
       
   240 
       
   241                 ((updateIndex-1) >= (gWidth - margin)) ifTrue:[
       
   242         "on slow displays, use:"
       
   243         "/            shift := gWidth // 4.
       
   244 
       
   245         "for smooth display, use:"
       
   246                     shift := 1.
       
   247 
       
   248                     oldData replaceFrom:1 with:oldData startingAt:shift+1.
       
   249                     newData replaceFrom:1 with:newData startingAt:shift+1.
       
   250                     freeData replaceFrom:1 with:freeData startingAt:shift+1.
       
   251 
       
   252                     updateIndex := updateIndex - shift.
       
   253                     dX := (dX ? 0) + shift.
       
   254 
       
   255                     "/ before copying, handle any outstanding exposes ...
       
   256                     self repairDamage.
       
   257                     "/ self catchExpose.
       
   258                     self copyFrom:self 
       
   259                                 x:(org + shift) y:0
       
   260                               toX:org y:0
       
   261                             width:(gWidth - shift - margin)
       
   262                            height:height
       
   263                             async:false.
       
   264 
       
   265                     self clearRectangleX:(width - margin - shift) y:0 
       
   266                                    width:shift height:height.
       
   267 
       
   268                     "/ self waitForExpose.
       
   269                 ].
       
   270 
       
   271                 self updateLineX:(updateIndex - 1 + org - 1)
       
   272                            total:total 
       
   273                            old:oldSpaceSize "/ oldSpaceUsed
       
   274                            new:newSpaceUsed 
       
   275                            free:freeMem.
       
   276 
       
   277                 self updateNumbers.
       
   278                 self flush.
       
   279             ].
       
   280         ].
   295         ].
   281     ].
   296     ].
   282 
   297 
   283     updateBlock notNil ifTrue:[
   298     updateBlock notNil ifTrue:[
   284         Processor addTimedBlock:updateBlock afterSeconds:updateInterval
   299         Processor addTimedBlock:updateBlock afterSeconds:updateInterval
   339 
   354 
   340     |oldSpaceSize newSpaceSize memUsed oldMemUsed newMemUsed freeMem free2
   355     |oldSpaceSize newSpaceSize memUsed oldMemUsed newMemUsed freeMem free2
   341      mallocAllocated mallocTotal
   356      mallocAllocated mallocTotal
   342      codeUsed numWeak numRem numLifoRem tenureAge igcPhase 
   357      codeUsed numWeak numRem numLifoRem tenureAge igcPhase 
   343      minScavengeReclamation lastScavengeReclamation scavengeCount
   358      minScavengeReclamation lastScavengeReclamation scavengeCount
   344      y half s fontHeight fontAscent fontDescent 
   359      y half s font fontHeight fontAscent fontDescent 
   345      limit total n prevMallocAllocated prevMallocTotal|
   360      limit total n prevMallocAllocated prevMallocTotal|
   346 
   361 
   347     oldMemUsed := ObjectMemory oldSpaceUsed + ObjectMemory symSpaceUsed.
   362     oldMemUsed := ObjectMemory oldSpaceUsed + ObjectMemory symSpaceUsed.
   348     newMemUsed := ObjectMemory newSpaceUsed.
   363     newMemUsed := ObjectMemory newSpaceUsed.
   349     freeMem := ObjectMemory freeListSpace.
   364     freeMem := ObjectMemory freeListSpace.
   358     total := oldSpaceSize + newSpaceSize.
   373     total := oldSpaceSize + newSpaceSize.
   359     free2 := ObjectMemory freeSpace.
   374     free2 := ObjectMemory freeSpace.
   360 
   375 
   361     self paint:self whiteColor on:self blackColor.
   376     self paint:self whiteColor on:self blackColor.
   362 
   377 
   363     fontDescent := gc font descent.
   378     font := gc font.
   364     fontAscent := gc font ascent.
   379     fontDescent := font descent.
   365     fontHeight := gc font height + fontDescent.
   380     fontAscent := font ascent.
       
   381     fontHeight := font height + fontDescent.
   366     half := height // 2 + fontDescent.
   382     half := height // 2 + fontDescent.
   367 
   383 
   368     y := half - (fontHeight * 8).
   384     y := half - (fontHeight * 8).
   369 
   385 
   370     limit ~~ prevLimit ifTrue:[
   386     limit ~~ prevLimit ifTrue:[
   611     super destroy
   627     super destroy
   612 !
   628 !
   613 
   629 
   614 initialize
   630 initialize
   615     super initialize.
   631     super initialize.
       
   632 
       
   633     self initializeDrawAction.
   616 
   634 
   617     drawLock := Semaphore forMutualExclusion name:'drawLock'.
   635     drawLock := Semaphore forMutualExclusion name:'drawLock'.
   618 
   636 
   619     updateInterval := 0.5.
   637     updateInterval := 0.5.
   620     ProcessorScheduler isPureEventDriven ifTrue:[
   638     ProcessorScheduler isPureEventDriven ifTrue:[