Skip to content

Commit

Permalink
Removed copyExecutionStack funtionality as it is too slow. Simplified…
Browse files Browse the repository at this point in the history
… filtering context calculation. Reduced AllocationSiteInfoModel instance variables
  • Loading branch information
jordanmontt committed Jul 19, 2024
1 parent 2cd3bb3 commit 1306586
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 98 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,55 +21,46 @@ AllocationStatisticsTestFixture >> allocationsOne [
allocations := OrderedCollection new.
allocations
add: (AllocationSiteInfoModel new
allocatorClass: Rectangle;
allocatorMethod: Margin >> #asMargin;
allocatedObjectClass: OrderedCollection;
sizeInBytes: 16;
yourself);
add: (AllocationSiteInfoModel new
allocatorClass: Rectangle;
allocatorMethod: Margin >> #asMargin;
allocatedObjectClass: OrderedCollection;
sizeInBytes: 16;
yourself);
add: (AllocationSiteInfoModel new
allocatorClass: Rectangle;
allocatorMethod: Margin >> #asMargin;
allocatedObjectClass: Dictionary;
sizeInBytes: 16;
yourself);
add: (AllocationSiteInfoModel new
allocatorClass: Rectangle;
allocatorMethod: Margin >> #asMargin;
allocatedObjectClass: ByteString;
sizeInBytes: 32;
yourself);
add: (AllocationSiteInfoModel new
allocatorClass: Rectangle;
allocatorMethod: Margin >> #asMargin;
allocatedObjectClass: ByteString;
sizeInBytes: 48;
yourself);
add: (AllocationSiteInfoModel new
allocatorClass: Rectangle;
allocatorMethod: Object >> #'->';
allocatedObjectClass: ByteString;
sizeInBytes: 100;
yourself);
add: (AllocationSiteInfoModel new
allocatorClass: Rectangle;
allocatorMethod: Object >> #'->';
allocatedObjectClass: ByteString;
sizeInBytes: 55;
yourself);
add: (AllocationSiteInfoModel new
allocatorClass: Rectangle;
allocatorMethod: Object >> #'->';
allocatedObjectClass: Color;
sizeInBytes: 60;
yourself);
add: (AllocationSiteInfoModel new
allocatorClass: Rectangle;
allocatorMethod: Object >> #'->';
allocatedObjectClass: Color;
sizeInBytes: 16;
Expand All @@ -83,7 +74,6 @@ AllocationStatisticsTestFixture >> allocationsThree [
| allocations |
allocations := OrderedCollection new.
allocations add: (AllocationSiteInfoModel new
allocatorClass: String;
allocatorMethod: Collection>>#sorted:;
allocatedObjectClass: ByteArray;
sizeInBytes: 16;
Expand All @@ -98,31 +88,26 @@ AllocationStatisticsTestFixture >> allocationsTwo [
allocations := OrderedCollection new.
allocations
add: (AllocationSiteInfoModel new
allocatorClass: OrderedCollection;
allocatorMethod: ArrayedCollection >> #add:;
allocatedObjectClass: ByteString;
sizeInBytes: 16;
yourself);
add: (AllocationSiteInfoModel new
allocatorClass: OrderedCollection;
allocatorMethod: ArrayedCollection >> #add:;
allocatedObjectClass: ByteString;
sizeInBytes: 16;
yourself);
add: (AllocationSiteInfoModel new
allocatorClass: OrderedCollection;
allocatorMethod: ArrayedCollection >> #add:;
allocatedObjectClass: ByteString;
sizeInBytes: 32;
yourself);
add: (AllocationSiteInfoModel new
allocatorClass: OrderedCollection;
allocatorMethod: ArrayedCollection >> #add:;
allocatedObjectClass: ByteArray;
sizeInBytes: 100;
yourself);
add: (AllocationSiteInfoModel new
allocatorClass: OrderedCollection;
allocatorMethod: ArrayedCollection >> #add:;
allocatedObjectClass: ByteArray;
sizeInBytes: 16;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ IllAllocationSiteExporterTest >> fakeAllocations [
allocatorClasses := 'Kernel' asPackage definedClasses asArray last: 10.
^ (1 to: 1000) collect: [ :i | AllocationSiteInfoModel new
allocatedObjectClass: allocatedClasses atRandom;
allocatorClass: allocatorClasses atRandom;
allocatorMethod: Collection>>#sorted:;
sizeInBytes: 100;
yourself ]
Expand Down
25 changes: 4 additions & 21 deletions src/IllimaniProfiler-Tests/IllAllocationSiteProfilerTest.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -17,31 +17,14 @@ IllAllocationSiteProfilerTest >> testFilterContextIgnoringClass [

profiler
instrumentator: (IllMockInstrumentator onProfiler: profiler);
copyExecutionStack;
samplingRate: 1;
startProfiling.

Object illNew.

self assert: profiler objectAllocations first context receiver class equals: self class.
self assert: profiler objectAllocations first context homeMethod
equals: self class >> #testFilterContextIgnoringClass
]

{ #category : 'tests' }
IllAllocationSiteProfilerTest >> testProfileOnCopyExecutionStack [

profiler
samplingRate: 1;
copyExecutionStack;
profileOn: [ 100 timesRepeat: [ Object new ] ].

"Take one random allocation to check"
self assert: profiler objectAllocations last context class equals: Context.
Object illNew.

self assert: profiler objectAllocations size >= 100.
profiler objectAllocations do: [ :alloc | "Stack was copied"
self assert: alloc context class equals: Context ]
self assert: profiler objectAllocations first contextFingerprint first methodClass equals: self class.
self assert: profiler objectAllocations first contextFingerprint first
equals: self class >> #testFilterContextIgnoringClass
]

{ #category : 'tests' }
Expand Down
29 changes: 4 additions & 25 deletions src/IllimaniProfiler/AllocationSiteInfoModel.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,7 @@ Class {
#instVars : [
'allocatedObjectClass',
'sizeInBytes',
'context',
'allocatorMethod',
'allocatorClass',
'contextFingerprint',
'initializationTime'
],
Expand All @@ -30,13 +28,7 @@ AllocationSiteInfoModel >> allocatedObjectClass: anObject [
{ #category : 'accessing' }
AllocationSiteInfoModel >> allocatorClass [

^ allocatorClass
]

{ #category : 'accessing' }
AllocationSiteInfoModel >> allocatorClass: anObject [

allocatorClass := anObject
^ allocatorMethod methodClass
]

{ #category : 'accessing' }
Expand All @@ -51,18 +43,6 @@ AllocationSiteInfoModel >> allocatorMethod: aCompiledMethod [
allocatorMethod := aCompiledMethod
]

{ #category : 'accessing' }
AllocationSiteInfoModel >> context [

^ context
]

{ #category : 'accessing' }
AllocationSiteInfoModel >> context: anObject [

context := anObject
]

{ #category : 'accessing' }
AllocationSiteInfoModel >> contextFingerprint [

Expand All @@ -75,7 +55,7 @@ AllocationSiteInfoModel >> contextFingerprint: aContext [
| sender |
"Using #to:do: because of performance"
sender := aContext.
"10 is the size of the arrat of contextFingerPrint"
"10 is the size of the array of contextFingerPrint"
1 to: 10 do: [ :i |
sender ifNil: [ ^ self ].
contextFingerprint at: i put: sender method.
Expand All @@ -89,7 +69,7 @@ AllocationSiteInfoModel >> flattenedInstanceVariables [
allocatedObjectClass.
sizeInBytes.
initializationTime.
allocatorClass.
self allocatorClass.
allocatorMethod name }
]

Expand Down Expand Up @@ -121,9 +101,8 @@ AllocationSiteInfoModel >> inspectableAssociations [
^ {
('Allocated object class' -> allocatedObjectClass).
('Memory size' -> sizeInBytes humanReadableByteSizeString).
('Allocator class' -> allocatorClass).
('Allocator class' -> self allocatorClass).
('Allocator method' -> allocatorMethod).
('Context' -> context).
('Initialization timestamp' -> initializationTime) }
]

Expand Down
46 changes: 10 additions & 36 deletions src/IllimaniProfiler/IllAllocationSiteProfiler.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -71,16 +71,6 @@ IllAllocationSiteProfiler >> allocationsStats [
statisticsModel := AllocationsStatsModel new rawAllocations: objectAllocations ]
]

{ #category : 'api' }
IllAllocationSiteProfiler >> copyExecutionStack [
"When this is set to true, for each object allocationn the full execution stack from which
the method was created will be copied and store. This information will be available for
making analysis. Keep in mind that when there is a lot of allocations going the size of
the image can grow quickly and drastically."

copyExecutionStack := true
]

{ #category : 'initialization' }
IllAllocationSiteProfiler >> defaultClassesToAvoidInTheContextSearch [

Expand All @@ -95,31 +85,12 @@ IllAllocationSiteProfiler >> defaultClassesToAvoidInTheContextSearch [
"CompiledBlock" }
]

{ #category : 'api' }
IllAllocationSiteProfiler >> doNotCopyExecutionStack [
"See the comment of my opposite method"

copyExecutionStack := false
]

{ #category : 'exporting' }
IllAllocationSiteProfiler >> exporterClass [

^ IllAllocationSiteExporter
]

{ #category : 'profiling' }
IllAllocationSiteProfiler >> filterContext: aContext ignoringClass: aClass [

| sender |
sender := aContext sender.
[
sender receiver class = aClass class or: [
classesToAvoidInTheContextSearch includes: sender receiver class ] ]
whileTrue: [ sender := sender sender ].
^ sender
]

{ #category : 'initialization' }
IllAllocationSiteProfiler >> initialize [

Expand All @@ -132,17 +103,20 @@ IllAllocationSiteProfiler >> initialize [
{ #category : 'profiling' }
IllAllocationSiteProfiler >> internalRegisterAllocation: newlyAllocatedObject [

| filteredContext allocationInformationHolder |
| filteredContext allocationInformationHolder allocatedObjectClass |

allocationInformationHolder := AllocationSiteInfoModel new.
filteredContext := self filterContext: thisContext ignoringClass: newlyAllocatedObject class.

copyExecutionStack ifTrue: [ allocationInformationHolder context: filteredContext copyStack ].
allocatedObjectClass := newlyAllocatedObject class.

filteredContext := thisContext.
[
filteredContext receiver class = allocatedObjectClass class or: [
classesToAvoidInTheContextSearch includes: filteredContext receiver class ] ]
whileTrue: [ filteredContext := filteredContext sender ].

allocationInformationHolder
allocatorClass: filteredContext receiver class;
allocatorMethod: filteredContext compiledCode method;
allocatedObjectClass: newlyAllocatedObject class;
allocatorMethod: filteredContext homeMethod;
allocatedObjectClass: allocatedObjectClass;
contextFingerprint: filteredContext;
sizeInBytes: newlyAllocatedObject sizeInMemory.

Expand Down

0 comments on commit 1306586

Please sign in to comment.