Marcel Taeumel uploaded a new version of System to project The Trunk:
http://source.squeak.org/trunk/System-mt.1198.mcz ==================== Summary ==================== Name: System-mt.1198 Author: mt Time: 17 December 2020, 5:04:11.447084 pm UUID: 0e532d14-69bc-3e4f-9e1b-67f880aa3001 Ancestors: System-pre.1197, System-mt.1175 Refines System-mt.1175, which adds a way to compute a space tally for objects up to a certain depth. Updates class comment to provide more examples. (See http://forum.world.st/The-Inbox-System-mt-1175-mcz-tp5122678.html) =============== Diff against System-pre.1197 =============== Item was changed: Object subclass: #SpaceTally + instanceVariableNames: 'results depth' - instanceVariableNames: 'results' classVariableNames: '' poolDictionaries: '' category: 'System-Tools'! + !SpaceTally commentStamp: '<historical>' prior: 0! + I'm responsible to help getting information about system space usage. The information I compute is represented by a spaceTallyItem. - !SpaceTally commentStamp: 'sd 6/20/2003 22:31' prior: 0! - I'm responsible to help getting information about system space usage. The information I compute is represented by a spaceTallyItem + Here are some examples to inspect: + SpaceTally new spaceTally: (Array with: TextMorph with: Point). + SpaceTally new systemWideSpaceTally. + SpaceTally new depth: 2; spaceTally: (PackageInfo named: #Morphic) classes. + SpaceTally new depth: 1; spaceTally: (PackageInfo named: #Monticello) classes. "Includes cached source code" + SpaceTally new spaceForInstancesOf: Form depth: 2. "Includes bitmaps and large integers"! - try something like: - - ((SpaceTally new spaceTally: (Array with: TextMorph with: Point)) - asSortedCollection: [:a :b | a spaceForInstances > b spaceForInstances]) - - SpaceTally new systemWideSpaceTally - - - This class has been created from a part of SystemDictionary. It still deserves a nice - clean, such as using object instead of array having 4 slots. - - sd-20 June 2003! Item was changed: ----- Method: SpaceTally>>computeSpaceUsage (in category 'class analysis') ----- computeSpaceUsage + | seenObjects | + seenObjects := self depth > 0 ifTrue: [IdentitySet new]. results do: [ :entry | | class instanceSpaceAndCount | class := self class environment at: entry analyzedClassName. Smalltalk garbageCollectMost. + instanceSpaceAndCount := self spaceForInstancesOf: class depth: self depth seen: seenObjects. - instanceSpaceAndCount := self spaceForInstancesOf: class. entry codeSize: class spaceUsed; instanceCount: instanceSpaceAndCount second; + spaceForInstances: instanceSpaceAndCount first; + depthOfSpace: self depth ] - spaceForInstances: instanceSpaceAndCount first ] displayingProgress: 'Taking statistics...'! Item was added: + ----- Method: SpaceTally>>depth (in category 'accessing') ----- + depth + + ^ depth ifNil: [0]! Item was added: + ----- Method: SpaceTally>>depth: (in category 'accessing') ----- + depth: anInteger + + depth := anInteger.! Item was added: + ----- Method: SpaceTally>>spaceForInstance: (in category 'instance size') ----- + spaceForInstance: anObject + + ^ self spaceForInstance: anObject depth: self depth! Item was added: + ----- Method: SpaceTally>>spaceForInstance:depth: (in category 'instance size') ----- + spaceForInstance: anObject depth: anInteger + + ^ self spaceForInstance: anObject depth: anInteger seen: (anInteger > 0 ifTrue: [IdentitySet new])! Item was added: + ----- Method: SpaceTally>>spaceForInstance:depth:seen: (in category 'instance size') ----- + spaceForInstance: anObject depth: anInteger seen: seenObjectsOrNil + + | ctxt class basicSize depth total | + seenObjectsOrNil ifNotNil: [ + (seenObjectsOrNil ifAbsentAdd: anObject) ifFalse: [^ 0]]. + ctxt := thisContext. + class := ctxt objectClass: anObject. + basicSize := 0. + total := class isVariable + ifTrue: [class byteSizeOfInstanceOfSize: (basicSize := ctxt objectSize: anObject)] + ifFalse: [class isImmediateClass ifTrue: [0] ifFalse: [class byteSizeOfInstance]]. + (depth := anInteger - 1) >= 0 ifTrue: [ + anObject isCompiledCode + ifTrue: [ + anObject literalsDo: [:literal | + total := total + (self spaceForInstance: literal depth: depth seen: seenObjectsOrNil)]] + ifFalse: [ + 1 to: basicSize do: [:index | + total := total + (self spaceForInstance: (ctxt object: anObject basicAt: index) depth: depth seen: seenObjectsOrNil)]. + 1 to: class instSize do: [:index | + total := total + (self spaceForInstance: (ctxt object: anObject instVarAt: index) depth: depth seen: seenObjectsOrNil)]]]. + ^ total! Item was changed: ----- Method: SpaceTally>>spaceForInstancesOf: (in category 'instance size') ----- spaceForInstancesOf: aClass - "Answer a pair of the number of bytes consumed by all instances of the - given class, including their object headers, and the number of instances." + ^ self spaceForInstancesOf: aClass depth: self depth! - | instances total | - instances := aClass allInstances. - instances isEmpty ifTrue: [^#(0 0)]. - total := 0. - aClass isVariable - ifTrue: - [instances do: - [:i| total := total + (aClass byteSizeOfInstanceOfSize: i basicSize)]] - ifFalse: - [total := instances size * aClass byteSizeOfInstance]. - ^{ total. instances size }! Item was added: + ----- Method: SpaceTally>>spaceForInstancesOf:depth: (in category 'instance size') ----- + spaceForInstancesOf: aClass depth: anInteger + + ^ self spaceForInstancesOf: aClass depth: anInteger seen: (anInteger > 0 ifTrue: [IdentitySet new])! Item was added: + ----- Method: SpaceTally>>spaceForInstancesOf:depth:seen: (in category 'instance size') ----- + spaceForInstancesOf: aClass depth: anInteger seen: seenObjects + "Answer a pair of the number of bytes consumed by all instances of the given class, including their object headers, and the number of instances. Follow each instance's fields up to the given depth. Beware of cycles to shared objects, which will tamper the resulting numbers. + + SpaceTally new spaceForInstancesOf: Form depth: 0. --- Same as #spaceForInstancesOf: + SpaceTally new spaceForInstancesOf: Form depth: 1. --- Includes memory footprint for bits etc. + SpaceTally new spaceForInstancesOf: Form depth: 2. --- Also includes LargePositiveIntegers in bitmaps ;-) + " + + | instances total | + instances := aClass allInstances. + instances isEmpty ifTrue: [^#(0 0)]. + total := 0. + instances do: [:each | total := total + (self spaceForInstance: each depth: anInteger seen: seenObjects)]. + ^{ total. instances size }! Item was changed: Object subclass: #SpaceTallyItem + instanceVariableNames: 'analyzedClassName codeSize instanceCount spaceForInstances depthOfSpace' - instanceVariableNames: 'analyzedClassName codeSize instanceCount spaceForInstances' classVariableNames: '' poolDictionaries: '' category: 'System-Tools'! !SpaceTallyItem commentStamp: 'sd 6/20/2003 22:02' prior: 0! I'm represent an entry in the spaceTally.! Item was added: + ----- Method: SpaceTallyItem>>depthOfSpace (in category 'accessing') ----- + depthOfSpace + + ^ depthOfSpace! Item was added: + ----- Method: SpaceTallyItem>>depthOfSpace: (in category 'accessing') ----- + depthOfSpace: aNumber + + depthOfSpace := aNumber! Item was changed: ----- Method: SpaceTallyItem>>printOn: (in category 'printing') ----- printOn: aStream analyzedClassName ifNotNil: [ aStream nextPutAll: analyzedClassName asString]. aStream nextPutAll: ' ('. codeSize ifNotNil: [ aStream nextPutAll: 'code size: ' ; nextPutAll: codeSize asString]. instanceCount ifNotNil: [ aStream nextPutAll: ' instance count: ' ; nextPutAll: instanceCount asString]. spaceForInstances ifNotNil: [ aStream nextPutAll: ' space for instances: ' ; nextPutAll: spaceForInstances asBytesDescription]. + depthOfSpace + ifNotNil: [ aStream nextPutAll: ' depth of space: ' ; nextPutAll: depthOfSpace asString]. aStream nextPut: $). ! |
Hmmm... this one generates LargePositiveIntegers while counting ... it never finishes: SpaceTally new spaceForInstancesOf: Bitmap depth: 1. Any ideas? =) The use of IdentitySet for depth > 0 might require some blacklisting ... Best, Marcel
|
Could it be that LargePositiveIntegers are created on-the-fly when accessing a Bitmap via #basicAt: (or the mirror primitive)? Best, Marcel
|
Free forum by Nabble | Edit this page |