[squeak-dev] The Inbox: System-mt.1175.mcz

Marcel Taeumel marcel.taeumel at hpi.de
Tue Sep 29 11:21:41 UTC 2020


... we may want to add #spaceUsed on Object, too, and refine it for, e.g., Form to use depth = 2. Those depth values depend on the particular object/class design. Yet, being able to call "myMorph spaceUsed" or "myForm spaceUsed" could be a great debugging tool.

Best,
Marcel
Am 29.09.2020 13:16:58 schrieb commits at source.squeak.org <commits at source.squeak.org>:
A new version of System was added to project The Inbox:
http://source.squeak.org/inbox/System-mt.1175.mcz

==================== Summary ====================

Name: System-mt.1175
Author: mt
Time: 29 September 2020, 1:16:45.233157 pm
UUID: f0acc060-a48b-2c4f-8b56-aaf2f55601b4
Ancestors: System-topa.1174

Adds a way to compute a space tally for objects up to a certain depth.

Questions:
- Is the interface (i.e. "depth" and "seen") OK?
- Is the use of IdentitySet OK?
- Can we speed this up somehow?
- Do we need depth-messages for the "class analysis" protocol, too?

=============== Diff against System-topa.1174 ===============

Item was added:
+ ----- Method: SpaceTally>>spaceForInstance:depth: (in category 'instance size') -----
+ spaceForInstance: anObject depth: anInteger
+
+ ^ self spaceForInstance: anObject depth: anInteger seen: IdentitySet new!

Item was added:
+ ----- Method: SpaceTally>>spaceForInstance:depth:seen: (in category 'instance size') -----
+ spaceForInstance: anObject depth: anInteger seen: someObjects
+
+ | class depth total |
+ (someObjects includes: anObject) ifTrue: [^ 0].
+ someObjects add: anObject.
+ class := anObject class.
+ depth := anInteger - 1.
+ total := class isVariable
+ ifTrue: [class byteSizeOfInstanceOfSize: anObject basicSize]
+ ifFalse: [class isImmediateClass ifTrue: [0] ifFalse: [class byteSizeOfInstance]].
+ depth >= 0 ifTrue: [
+ anObject isCompiledCode
+ ifTrue: [
+ anObject literalsDo: [:literal |
+ total := total + (self spaceForInstance: literal depth: depth seen: someObjects)]]
+ ifFalse: [
+ 1 to: anObject basicSize do: [:index |
+ total := total + (self spaceForInstance: (anObject basicAt: index) depth: depth seen: someObjects)].
+ 1 to: class instSize do: [:index |
+ total := total + (self spaceForInstance: (anObject instVarAt: index) depth: depth seen: someObjects)]]].
+ ^ total!

Item was added:
+ ----- Method: SpaceTally>>spaceForInstancesOf:depth: (in category 'instance size') -----
+ spaceForInstancesOf: aClass depth: aNumber
+ "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 #spaceForInstanecsOf:
+ 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 sub depth |
+ instances := aClass allInstances.
+ instances isEmpty ifTrue: [^#(0 0)].
+ total := 0.
+ instances do: [:each | total := total + (self spaceForInstance: each depth: aNumber)].
+ ^{ total. instances size }!


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.squeakfoundation.org/pipermail/squeak-dev/attachments/20200929/add1d721/attachment.html>


More information about the Squeak-dev mailing list