Skip to content

Commit

Permalink
Refactors
Browse files Browse the repository at this point in the history
  • Loading branch information
jordanmontt committed Sep 21, 2023
1 parent 81cfa81 commit 09f67b7
Show file tree
Hide file tree
Showing 4 changed files with 113 additions and 131 deletions.
71 changes: 27 additions & 44 deletions src/IllimaniFinalizationProfiler/IllFinalizationProfiler.class.st
Original file line number Diff line number Diff line change
@@ -1,56 +1,58 @@
"
I profile the Garbage Collector and provide information about the lifetime of objects.
"
Class {
#name : 'IllFinalizationProfiler',
#superclass : 'Object',
#traits : 'IllTAllocatorWrapper',
#classTraits : 'IllTAllocatorWrapper classTrait',
#instVars : [
'ephemeronsCollection',
'profilerHandler',
'finalizationRegistry'
'statsModel'
],
#category : 'IllimaniFinalizationProfiler-Profiler',
#package : 'IllimaniFinalizationProfiler',
#tag : 'Profiler'
}

{ #category : 'api' }
IllFinalizationProfiler >> addFinalizationFor: newlyAllocatedObject finalizer: objectFinalizationModel [

finalizationRegistry add: newlyAllocatedObject finalizer: objectFinalizationModel
]

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

"We force the finalization timestamp for the not yet finalized objects."
finalizationRegistry finalizeAllEphemerons.
"Then we stop referencing the finalization registry to not re-finalize the objects."
finalizationRegistry := FinalizationRegistry new
ephemeronsCollection do: [ :e | e mourn ]
]

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

super initialize.
finalizationRegistry := FinalizationRegistry new.
profilerHandler := self initializeHandler.
ephemeronsCollection := OrderedCollection new: 10000000.
profilerHandler := IllFinalizationMpHandlerFast new
profiler: self;
yourself.
self initializeMethodProxies: profilerHandler
]

{ #category : 'initialization' }
IllFinalizationProfiler >> initializeHandler [
{ #category : 'api' }
IllFinalizationProfiler >> objectAllocations [

^ IllFinalizationMpHandler new
profiler: self;
yourself
^ ephemeronsCollection
]

{ #category : 'api' }
IllFinalizationProfiler >> objectAllocations [
{ #category : 'instance creation' }
IllFinalizationProfiler >> open [

^ (IllFinalizationProfilerUI profiler: self announcer: IllAnnouncer new)
open;
yourself
]

^ profilerHandler objectAllocations
{ #category : 'profiling' }
IllFinalizationProfiler >> registerAllocation: anObject [

ephemeronsCollection add: (IllEphemeron newPinned
key: anObject value: nil;
initializationTime: Time primUTCMicrosecondsClock;
allocatedObjectClass: anObject class;
sizeInBytes: anObject sizeInMemory;
yourself)
]

{ #category : 'api' }
Expand All @@ -68,9 +70,8 @@ IllFinalizationProfiler >> startProfiling [

{ #category : 'accessing - statistics' }
IllFinalizationProfiler >> stats [
"There is no stats model for this profiler yet"

^ self
^ statsModel ifNil: [ statsModel := IllFinalizationStatsModel on: ephemeronsCollection ]
]

{ #category : 'profiling' }
Expand All @@ -80,21 +81,3 @@ IllFinalizationProfiler >> stopProfiling [
self forceFinalizationOfObjects.
self updateStatsWhenFinishingProfiling
]

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

^ self objectAllocations last initializationTime - self objectAllocations first initializationTime
]

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

^ self objectAllocations inject: 0 into: [ :sum : elem | sum + elem sizeInBytes ]
]

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

^ self objectAllocations size
]

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
Class {
#name : 'IllFinalizationProfilerUnconstructedCollection',
#superclass : 'IllFinalizationProfiler',
#superclass : 'Object',
#traits : 'IllTAllocatorWrapper',
#classTraits : 'IllTAllocatorWrapper classTrait',
#instVars : [
'profilerHandler',
'statsModel'
],
#category : 'IllimaniFinalizationProfiler-Profiler',
#package : 'IllimaniFinalizationProfiler',
#tag : 'Profiler'
Expand All @@ -14,7 +19,36 @@ IllFinalizationProfilerUnconstructedCollection >> forceFinalizationOfObjects [
]

{ #category : 'initialization' }
IllFinalizationProfilerUnconstructedCollection >> initializeHandler [
IllFinalizationProfilerUnconstructedCollection >> initialize [

^ IllFinalizationMpHandlerUnconstructedCollection new
super initialize.
profilerHandler := IllFinalizationMpHandlerUnconstructedCollection new.
self initializeMethodProxies: profilerHandler
]

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

^ profilerHandler objectAllocations
]

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

self initializeProfilingBasicStats.
self installMethodProxies
]

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

^ statsModel ifNil: [ statsModel := IllFinalizationStatsModel on: self objectAllocations ]
]

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

self uninstallMethodProxies.
self forceFinalizationOfObjects.
self updateStatsWhenFinishingProfiling
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
Class {
#name : 'IllFinalizationStatsModel',
#superclass : 'Object',
#classTraits : 'IllTAllocatorWrapper classTrait',
#instVars : [
'objectAllocations'
],
#category : 'IllimaniFinalizationProfiler-Profiler',
#package : 'IllimaniFinalizationProfiler',
#tag : 'Profiler'
}

{ #category : 'instance creation' }
IllFinalizationStatsModel class >> on: objectAllocations [

^ self new
objectAllocations: objectAllocations;
yourself
]

{ #category : 'accessing' }
IllFinalizationStatsModel >> objectAllocations [

^ objectAllocations
]

{ #category : 'accessing' }
IllFinalizationStatsModel >> objectAllocations: anObject [

objectAllocations := anObject
]

{ #category : 'statistics - time' }
IllFinalizationStatsModel >> timeDifferenceBetweenFirstAndLastAllocation [

^ self objectAllocations last initializationTime - self objectAllocations first initializationTime
]

{ #category : 'accessing' }
IllFinalizationStatsModel >> totalAllocatedMemory [

^ self objectAllocations inject: 0 into: [ :sum : elem | sum + elem sizeInBytes ]
]

{ #category : 'accessing' }
IllFinalizationStatsModel >> totalAllocatedObjects [

^ self objectAllocations size
]

0 comments on commit 09f67b7

Please sign in to comment.