Sound good to me!
> Personally I'd also like some more refactoring, like rewriting
> spaceForInstancesOf: withInstanceCount into
> #spaceForInstancesOfClass: aClass, delegating to:
> #spaceFor: amount instancesOfClass: aFixedClass (private category?)
> #spaceForInstancesOfVariableClass: aVariableClass (private category?)
>
>
I was thinking more or less the same. Even more, if we integrate Object >>
sizeInMemory
why not adding also:
Class >> spaceForInstances
| totalSize |
totalSize := 0.
self allInstancesDo: [ :inst |
totalSize := totalSize + inst sizeInMemory.
].
^ totalSize
?
Then we can also replace spaceForInstancesOf: withInstanceCount with
spaceForInstances
Example:
printSpaceAnalysis: threshold on: aStream
"SpaceTally new printSpaceAnalysis: 1 on:(FileStream forceNewFileNamed:
'STspace.text')"
"sd-This method should be rewrote to be more coherent within the rest of
the class
ie using preAllocate and spaceForInstanceOf:"
"If threshold > 0, then only those classes with more than that number
of instances will be shown, and they will be sorted by total instance
space.
If threshold = 0, then all classes will appear, sorted by name."
| totalCodeSpace totalInstCount totalInstSpace n totalPercent |
Smalltalk garbageCollect.
totalCodeSpace := totalInstCount := totalInstSpace := n := 0.
results := OrderedCollection new: Smalltalk classNames size.
'Taking statistics...'
displayProgressAt: Sensor cursorPoint
from: 0 to: Smalltalk classNames size
during: [:bar |
(Smalltalk globals allClasses) do:
[:cl | | codeSpace instCount instSpace eltSize | codeSpace := cl
spaceUsed.
bar value: (n := n+1).
Smalltalk garbageCollectMost.
instCount := cl instanceCount.
instSpace := cl spaceForInstances.
results add: (SpaceTallyItem analyzedClassName: cl name
codeSize: codeSpace instanceCount: instCount spaceForInstances: instSpace).
totalCodeSpace := totalCodeSpace + codeSpace.
totalInstCount := totalInstCount + instCount.
totalInstSpace := totalInstSpace + instSpace]].
totalPercent := 0.0.
"aStream timeStamp."
aStream
nextPutAll: ('Class' padded: #right to: 30 with: $ );
nextPutAll: ('code space' padded: #left to: 12 with: $ );
nextPutAll: ('# instances' padded: #left to: 12 with: $ );
nextPutAll: ('inst space' padded: #left to: 12 with: $ );
nextPutAll: ('percent' padded: #left to: 8 with: $ ); cr.
threshold > 0 ifTrue: [
"If inst count threshold > 0, then sort by space"
results := (results select: [:s | s instanceCount >= threshold or:
[s spaceForInstances > (totalInstSpace // 500)]])
asSortedCollection: [:s :s2 | s spaceForInstances > s2
spaceForInstances]].
results do: [:s | | percent |
aStream
nextPutAll: (s analyzedClassName padded: #right to: 30 with: $
);
nextPutAll: (s codeSize printString padded: #left to: 12 with: $
);
nextPutAll: (s instanceCount printString padded: #left to: 12
with: $ );
nextPutAll: (s spaceForInstances printString padded: #left to:
14 with: $ ).
percent := s spaceForInstances*100.0/totalInstSpace roundTo: 0.1.
totalPercent := totalPercent + percent.
percent >= 0.1 ifTrue: [
aStream nextPutAll: (percent printString padded: #left to: 8
with: $ )].
aStream cr].
aStream
cr; nextPutAll: ('Total' padded: #right to: 30 with: $ );
nextPutAll: (totalCodeSpace printString padded: #left to: 12 with: $
);
nextPutAll: (totalInstCount printString padded: #left to: 12 with: $
);
nextPutAll: (totalInstSpace printString padded: #left to: 14 with: $
);
nextPutAll: ((totalPercent roundTo: 0.1) printString padded: #left
to: 8 with: $ ).
agree??
thanks
That way you also move ugly instance counting out of the loop.
>
> Also, while you're at it, what about factoring out
> contentBytes > 255
> ifTrue: [12]
> ifFalse: [isCompact ifTrue: [4] ifFalse: [8].
> into, say, #headerBytesOfClass: aClass ?
>
> And really, wtf?
> An instance of a compact, variable class with more than 255 bytes in it
> will have a 12-byte header, while those with less will have a 4-byte header?
> Plus, setting a class with more than 63 instance variables will never have
> an effect, its instances will always have 12-byte headers?
>
> Cheers,
> Henry
>
> _______________________________________________
> Pharo-project mailing list
> [email protected]
> http://lists.gforge.inria.fr/cgi-bin/mailman/listinfo/pharo-project
>
_______________________________________________
Pharo-project mailing list
[email protected]
http://lists.gforge.inria.fr/cgi-bin/mailman/listinfo/pharo-project