Skip to content

Commit

Permalink
Simplifying logic
Browse files Browse the repository at this point in the history
  • Loading branch information
jordanmontt committed Sep 21, 2023
1 parent af7fe70 commit 96ae1fa
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 71 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ Class {
IllProfilerMpHandlerTest >> setUp [

super setUp.
handler := IllProfilerMpHandler new
handler := IllAllocationProfilerMpHandler new
]

{ #category : 'tests' }
Expand Down
24 changes: 4 additions & 20 deletions src/IllimaniAllocationProfiler/IllAllocationProfiler.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -88,12 +88,6 @@ IllAllocationProfiler >> captureAllObjects [
profilerHandler captureAllObjects
]

{ #category : 'evaluating' }
IllAllocationProfiler >> cleanProfilingData [

profilerHandler cleanObjectAllocations
]

{ #category : 'api' }
IllAllocationProfiler >> copyExecutionStack [

Expand All @@ -110,7 +104,7 @@ IllAllocationProfiler >> copyObjectIdentityHash [
IllAllocationProfiler >> initialize [

super initialize.
profilerHandler := IllProfilerMpHandler new.
profilerHandler := IllAllocationProfilerMpHandler new.
illimaniAnnouncer := IllAnnouncer new.
self initializeMethodProxies: profilerHandler.
]
Expand Down Expand Up @@ -151,28 +145,18 @@ IllAllocationProfiler >> samplingRate: anInteger [
profilerHandler samplingRate: anInteger
]

{ #category : 'evaluating' }
IllAllocationProfiler >> startProfiling [

self cleanProfilingData.
self installMethodProxies.

self initializeProfilingBasicStats
]

{ #category : 'accessing - statistics' }
IllAllocationProfiler >> stats [

^ statisticsModel
^ statisticsModel ifNil: [
statisticsModel := AllocationStatistics new rawAllocations: profilerHandler objectAllocations.
statisticsModel ]
]

{ #category : 'evaluating' }
IllAllocationProfiler >> stopProfiling [

self uninstallMethodProxies.
self updateStatsWhenFinishingProfiling.
statisticsModel := AllocationStatistics new
rawAllocations: profilerHandler objectAllocations;
yourself.
self announceProfilerStopedProfiling
]
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ I am a class that defines the logic to only registed an specific type of object.
Please define my `classesToRegister` variable with the classes you want to capture or if you want to capture all use the message `captureAllObjects`
"
Class {
#name : 'IllProfilerMpHandler',
#name : 'IllAllocationProfilerMpHandler',
#superclass : 'MpHandler',
#instVars : [
'objectAllocations',
Expand All @@ -22,7 +22,7 @@ Class {
}

{ #category : 'evaluating' }
IllProfilerMpHandler >> afterExecutionWithReceiver: receiver arguments: arguments returnValue: newlyAllocatedObject [
IllAllocationProfilerMpHandler >> afterExecutionWithReceiver: receiver arguments: arguments returnValue: newlyAllocatedObject [

"Sampling"
samplingCounter := samplingCounter + 1.
Expand All @@ -34,21 +34,14 @@ IllProfilerMpHandler >> afterExecutionWithReceiver: receiver arguments: argument
]

{ #category : 'api' }
IllProfilerMpHandler >> captureAllObjects [
IllAllocationProfilerMpHandler >> captureAllObjects [
"When this turned to true I will capture all the allocations of all the objects"

captureAllObjects := true
]

{ #category : 'api' }
IllProfilerMpHandler >> cleanObjectAllocations [

objectAllocations removeAll.
samplingCounter := 0
]

{ #category : 'api' }
IllProfilerMpHandler >> copyExecutionStack [
IllAllocationProfilerMpHandler >> 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
Expand All @@ -58,33 +51,33 @@ IllProfilerMpHandler >> copyExecutionStack [
]

{ #category : 'initialization' }
IllProfilerMpHandler >> defaultClassesToAvoidInTheContextSearch [
IllAllocationProfilerMpHandler >> defaultClassesToAvoidInTheContextSearch [

^ {
Process.
IllProfilerMpHandler.
IllAllocationProfilerMpHandler.
MpMethodProxy.
"BlockClosure."
FullBlockClosure
"CompiledBlock" }
]

{ #category : 'api' }
IllProfilerMpHandler >> doNotCaptureAllObjects [
IllAllocationProfilerMpHandler >> doNotCaptureAllObjects [
"See the comment of my opposite method"

captureAllObjects := false
]

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

copyExecutionStack := false
]

{ #category : 'evaluating' }
IllProfilerMpHandler >> filterContext: aContext ignoringClass: aClass [
IllAllocationProfilerMpHandler >> filterContext: aContext ignoringClass: aClass [

| sender |
sender := aContext sender.
Expand All @@ -97,7 +90,7 @@ IllProfilerMpHandler >> filterContext: aContext ignoringClass: aClass [
]

{ #category : 'evaluating' }
IllProfilerMpHandler >> handleObjectAllocation: newlyAllocatedObject [
IllAllocationProfilerMpHandler >> handleObjectAllocation: newlyAllocatedObject [

| filteredContext allocationInformationHolder |

Expand All @@ -112,13 +105,13 @@ IllProfilerMpHandler >> handleObjectAllocation: newlyAllocatedObject [
allocatedObjectClass: newlyAllocatedObject class;
contextFingerprint: filteredContext;
sizeInBytes: newlyAllocatedObject sizeInMemory;
initializationTime: Time microsecondClockValue.
initializationTime: Time primUTCMicrosecondsClock.

objectAllocations add: allocationInformationHolder
]

{ #category : 'initialization' }
IllProfilerMpHandler >> initialize [
IllAllocationProfilerMpHandler >> initialize [

super initialize.

Expand All @@ -137,71 +130,64 @@ IllProfilerMpHandler >> initialize [
, (self defaultClassesToAvoidInTheContextSearch collect: [ :aClass | aClass class ])
]

{ #category : 'initialization' }
IllProfilerMpHandler >> initializeClassesToAvoidInContextSearch [

classesToAvoidInTheContextSearch := self defaultClassesToAvoidInTheContextSearch ,
(self defaultClassesToAvoidInTheContextSearch collect: [ :aClass | aClass class ])
]

{ #category : 'accessing' }
IllProfilerMpHandler >> objectAllocations [
IllAllocationProfilerMpHandler >> objectAllocations [

^ objectAllocations
]

{ #category : 'accessing' }
IllProfilerMpHandler >> objectsToCapture [
IllAllocationProfilerMpHandler >> objectsToCapture [

^ objectClassesToCapture
]

{ #category : 'accessing' }
IllProfilerMpHandler >> objectsToCapture: aCollectionOfClasses [
IllAllocationProfilerMpHandler >> objectsToCapture: aCollectionOfClasses [

objectClassesToCapture := aCollectionOfClasses
]

{ #category : 'accessing' }
IllProfilerMpHandler >> objectsToIgnore [
IllAllocationProfilerMpHandler >> objectsToIgnore [

^ objectClassesToIgnore
]

{ #category : 'accessing' }
IllProfilerMpHandler >> objectsToIgnore: aCollectionOfClasses [
IllAllocationProfilerMpHandler >> objectsToIgnore: aCollectionOfClasses [

objectClassesToIgnore := aCollectionOfClasses
]

{ #category : 'accessing' }
IllProfilerMpHandler >> samplingCounter [
IllAllocationProfilerMpHandler >> samplingCounter [

^ samplingCounter
]

{ #category : 'accessing' }
IllProfilerMpHandler >> samplingCounter: anInteger [
IllAllocationProfilerMpHandler >> samplingCounter: anInteger [
"This method is only for testing! As a user, you don't normally will need to use this
accessor"

samplingCounter := anInteger
]

{ #category : 'accessing' }
IllProfilerMpHandler >> samplingRate [
IllAllocationProfilerMpHandler >> samplingRate [
^ samplingRate
]

{ #category : 'api' }
IllProfilerMpHandler >> samplingRate: anInteger [
IllAllocationProfilerMpHandler >> samplingRate: anInteger [
"The anInteger needs to be an integer number between 1 and 100. "

samplingRate := (100 / anInteger) asInteger
]

{ #category : 'testing' }
IllProfilerMpHandler >> shouldICaptureTheObject: returnValue [
IllAllocationProfilerMpHandler >> shouldICaptureTheObject: returnValue [

"Objects to ignore have the priority"
(objectClassesToIgnore includes: returnValue class) ifTrue: [ ^ false ].
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,13 +61,6 @@ IllFinalizationProfiler >> samplingRate: anInteger [
profilerHandler samplingRate: anInteger
]

{ #category : 'profiling' }
IllFinalizationProfiler >> startProfiling [

self initializeProfilingBasicStats.
self installMethodProxies
]

{ #category : 'accessing - statistics' }
IllFinalizationProfiler >> stats [

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,6 @@ IllFinalizationProfilerUnconstructedCollection >> objectAllocations [
^ profilerHandler objectAllocations
]

{ #category : 'profiling' }
IllFinalizationProfilerUnconstructedCollection >> startProfiling [

self initializeProfilingBasicStats.
self installMethodProxies
]

{ #category : 'accessing - statistics' }
IllFinalizationProfilerUnconstructedCollection >> stats [

Expand Down
7 changes: 7 additions & 0 deletions src/IllimaniKernel/IllTAllocatorWrapper.trait.st
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,13 @@ IllTAllocatorWrapper >> profileOn: aBlock [
nil ] ensure: [ self stopProfiling ]
]

{ #category : 'profiling' }
IllTAllocatorWrapper >> startProfiling [

self installMethodProxies.
self initializeProfilingBasicStats
]

{ #category : 'accessing - statistics' }
IllTAllocatorWrapper >> totalGCTime [

Expand Down

0 comments on commit 96ae1fa

Please sign in to comment.