MemoryUsageView.st
changeset 769 56ecc821f8be
parent 643 837eeb5cf043
child 770 3da310ebef8d
equal deleted inserted replaced
768:c74bce2106ae 769:56ecc821f8be
    15 	classVariableNames:''
    15 	classVariableNames:''
    16 	poolDictionaries:''
    16 	poolDictionaries:''
    17 	category:'Interface-Tools'
    17 	category:'Interface-Tools'
    18 !
    18 !
    19 
    19 
    20 !MemoryUsageView  class methodsFor:'documentation'!
    20 !MemoryUsageView class methodsFor:'documentation'!
    21 
    21 
    22 copyright
    22 copyright
    23 "
    23 "
    24  COPYRIGHT (c) 1992 by Claus Gittinger
    24  COPYRIGHT (c) 1992 by Claus Gittinger
    25 	      All Rights Reserved
    25 	      All Rights Reserved
   249 
   249 
   250 updateDisplay
   250 updateDisplay
   251     "update the displayed list"
   251     "update the displayed list"
   252 
   252 
   253     windowGroup withCursor:Cursor wait do:[
   253     windowGroup withCursor:Cursor wait do:[
   254 	|classNames counts sumSizes maxSizes percents avgSizes 
   254         |classNames counts sumSizes maxSizes percents avgSizes 
   255 	 l line allMemory 
   255          l line allMemory 
   256 	 overAllCount overAllAvgSize overAllMaxSize|
   256          overAllCount overAllAvgSize overAllMaxSize|
   257 
   257 
   258 	info := rawInfo asSortedCollection:sortBlock.
   258         info := rawInfo asSortedCollection:sortBlock.
   259 
   259 
   260 	classNames := info collect:[:infoArray | 
   260         classNames := info collect:[:infoArray | 
   261 	    |cls|
   261             |cls|
   262 
   262 
   263 	    cls := infoArray at:1.
   263             cls := infoArray at:1.
   264 	    cls == Class ifTrue:[
   264             cls == Class ifTrue:[
   265 		'<all classes>'
   265                 '<all classes>'
   266 	    ] ifFalse:[
   266             ] ifFalse:[
   267 		cls == Metaclass ifTrue:[
   267                 cls == Metaclass ifTrue:[
   268 		    '<all metaclasses>'
   268                     '<all metaclasses>'
   269 		] ifFalse:[
   269                 ] ifFalse:[
   270 		    cls displayString "/name
   270                     cls == PrivateMetaclass ifTrue:[
   271 		] 
   271                         '<all private classes>'
   272 	    ] 
   272                     ] ifFalse:[
   273 	].
   273                         cls displayString "/name
   274 
   274                     ]
   275 	counts := info collect:[:infoArray | (infoArray at:2) ].
   275                 ] 
   276 	sumSizes := info collect:[:infoArray | (infoArray at:3) ].
   276             ] 
   277 	maxSizes := info collect:[:infoArray | (infoArray at:4) ].
   277         ].
   278 	allMemory := sumSizes inject:0 into:[:sum :this | sum + this].
   278 
   279 	"/ allMemory := ObjectMemory bytesUsed.
   279         counts := info collect:[:infoArray | (infoArray at:2) ].
   280 	percents := sumSizes collect:[:sz | (sz asFloat / allMemory * 1000) rounded / 10.0].
   280         sumSizes := info collect:[:infoArray | (infoArray at:3) ].
   281 	avgSizes := (1 to:sumSizes size) collect:[:i | (((sumSizes at:i) / (counts at:i)) * 10) rounded / 10.0].
   281         maxSizes := info collect:[:infoArray | (infoArray at:4) ].
   282 
   282         allMemory := sumSizes inject:0 into:[:sum :this | sum + this].
   283 	l := OrderedCollection new.
   283         "/ allMemory := ObjectMemory bytesUsed.
   284 	1 to:classNames size do:[:i |
   284         percents := sumSizes collect:[:sz | (sz asFloat / allMemory * 1000) rounded / 10.0].
   285 	    |line avgSz maxSz|
   285         avgSizes := (1 to:sumSizes size) collect:[:i | (((sumSizes at:i) / (counts at:i)) * 10) rounded / 10.0].
   286 
   286 
   287 	    avgSz := avgSizes at:i.
   287         l := OrderedCollection new.
   288 	    maxSz := maxSizes at:i.
   288         1 to:classNames size do:[:i |
   289 	    avgSz = maxSz ifTrue:[
   289             |line avgSz maxSz|
   290 		avgSz := avgSz asInteger printString , '  '.
   290 
   291 	    ].
   291             avgSz := avgSizes at:i.
   292 	    line := (classNames at:i) printStringPaddedTo:33 with:Character space.
   292             maxSz := maxSizes at:i.
   293 	    line := line , ((counts at:i) printStringLeftPaddedTo:7).
   293             avgSz = maxSz ifTrue:[
   294 	    line := line , (avgSz printStringLeftPaddedTo:10).
   294                 avgSz := avgSz asInteger printString , '  '.
   295 	    line := line , (maxSz printStringLeftPaddedTo:8).
   295             ].
   296 	    line := line , ((sumSizes at:i) printStringLeftPaddedTo:10).
   296             line := (classNames at:i) printStringPaddedTo:33 with:Character space.
   297 	    line := line , ((percents at:i) printStringLeftPaddedTo:7).
   297             line := line , ((counts at:i) printStringLeftPaddedTo:7).
   298 	    l add:line
   298             line := line , (avgSz printStringLeftPaddedTo:10).
   299 	].
   299             line := line , (maxSz printStringLeftPaddedTo:8).
   300 
   300             line := line , ((sumSizes at:i) printStringLeftPaddedTo:10).
   301 	"add summary line"
   301             line := line , ((percents at:i) printStringLeftPaddedTo:7).
   302 	overAllCount := counts inject:0 into:[:sum :this | sum + this].
   302             l add:line
   303 	overAllAvgSize := ((allMemory / overAllCount) * 10) rounded / 10.0.
   303         ].
   304 	overAllMaxSize := maxSizes max.
   304 
   305 
   305         "add summary line"
   306 	l add:''.
   306         overAllCount := counts inject:0 into:[:sum :this | sum + this].
   307 	line := 'all objects' printStringPaddedTo:33 with:Character space.
   307         overAllAvgSize := ((allMemory / overAllCount) * 10) rounded / 10.0.
   308 	line := line , (overAllCount printStringLeftPaddedTo:7).
   308         overAllMaxSize := maxSizes max.
   309 	line := line , (overAllAvgSize printStringLeftPaddedTo:10).
   309 
   310 	line := line , (overAllMaxSize printStringLeftPaddedTo:8).
   310         l add:''.
   311 	line := line , (allMemory printStringLeftPaddedTo:10).
   311         line := 'all objects' printStringPaddedTo:33 with:Character space.
   312 	line := line , (100.0 printStringLeftPaddedTo:7).
   312         line := line , (overAllCount printStringLeftPaddedTo:7).
   313 	l add:line.
   313         line := line , (overAllAvgSize printStringLeftPaddedTo:10).
   314 
   314         line := line , (overAllMaxSize printStringLeftPaddedTo:8).
   315 	list list:l.
   315         line := line , (allMemory printStringLeftPaddedTo:10).
       
   316         line := line , (100.0 printStringLeftPaddedTo:7).
       
   317         l add:line.
       
   318 
       
   319         list list:l.
   316     ]
   320     ]
   317 
   321 
   318     "Created: 19.9.1995 / 15:30:47 / claus"
   322     "Created: 19.9.1995 / 15:30:47 / claus"
       
   323     "Modified: 15.10.1996 / 21:59:36 / cg"
   319 !
   324 !
   320 
   325 
   321 updateInfo
   326 updateInfo
   322     "scan all memory and collect the information"
   327     "scan all memory and collect the information"
   323 
   328 
   345 "/              o isBehavior ifTrue:[
   350 "/              o isBehavior ifTrue:[
   346                 class := o class.
   351                 class := o class.
   347                 (class flags bitAnd:behaviorFlag) ~~ 0 ifTrue:[
   352                 (class flags bitAnd:behaviorFlag) ~~ 0 ifTrue:[
   348                     o isObsolete ifFalse:[
   353                     o isObsolete ifFalse:[
   349                         o isMeta ifTrue:[
   354                         o isMeta ifTrue:[
   350                             class := Metaclass
   355                             o isPrivate ifTrue:[
       
   356                                 class := PrivateMetaclass
       
   357                             ] ifFalse:[
       
   358                                 class := Metaclass
       
   359                             ]
   351                         ] ifFalse:[
   360                         ] ifFalse:[
   352                             class := Class
   361 "/                            o isPrivate ifTrue:[
       
   362 "/                                class := PrivateMetaclass
       
   363 "/                            ] ifFalse:[
       
   364                                 class := Class
       
   365 "/                            ]    
   353                         ]
   366                         ]
   354                     ]
   367                     ]
   355                 ].
   368                 ].
       
   369 
   356                 bytes := ObjectMemory sizeOf:o.
   370                 bytes := ObjectMemory sizeOf:o.
   357                 infoArray := rawInfo at:class ifAbsent:[].
   371                 infoArray := rawInfo at:class ifAbsent:[].
   358                 infoArray isNil ifTrue:[
   372                 infoArray isNil ifTrue:[
   359                     infoArray := Array 
   373                     infoArray := Array 
   360                             with:class 
   374                             with:class 
   372             myProcess priority:myPriority.
   386             myProcess priority:myPriority.
   373         ].
   387         ].
   374     ]
   388     ]
   375 
   389 
   376     "Modified: 19.9.1995 / 15:29:10 / claus"
   390     "Modified: 19.9.1995 / 15:29:10 / claus"
       
   391     "Modified: 15.10.1996 / 22:02:00 / cg"
   377 ! !
   392 ! !
   378 
   393 
   379 !MemoryUsageView methodsFor:'realization'!
   394 !MemoryUsageView methodsFor:'realization'!
   380 
   395 
   381 realize
   396 realize
   382     super realize.
   397     super realize.
   383     self updateInfo.
   398     self updateInfo.
   384     self sortByClass.
   399     self sortByClass.
   385 ! !
   400 ! !
   386 
   401 
   387 !MemoryUsageView  class methodsFor:'documentation'!
   402 !MemoryUsageView class methodsFor:'documentation'!
   388 
   403 
   389 version
   404 version
   390     ^ '$Header: /cvs/stx/stx/libtool/MemoryUsageView.st,v 1.16 1996-06-28 13:46:05 cg Exp $'
   405     ^ '$Header: /cvs/stx/stx/libtool/MemoryUsageView.st,v 1.17 1996-10-15 21:03:16 cg Exp $'
   391 ! !
   406 ! !