Skip to content

Commit

Permalink
Added Gc process into the finalization profiler. Running the gc when …
Browse files Browse the repository at this point in the history
…stopped profiling
  • Loading branch information
jordanmontt committed Sep 26, 2023
1 parent 1f9ad81 commit 34eb2bd
Showing 1 changed file with 29 additions and 1 deletion.
30 changes: 29 additions & 1 deletion src/IllimaniProfiler/IllFinalizationProfiler.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ Class {
#superclass : 'IllAbstractProfiler',
#instVars : [
'ephemeronsCollection',
'statsModel'
'statsModel',
'gcProcess'
],
#category : 'IllimaniProfiler-Finalization-Profiler',
#package : 'IllimaniProfiler',
Expand All @@ -13,6 +14,10 @@ Class {
{ #category : 'profiling' }
IllFinalizationProfiler >> forceFinalizationOfObjects [

"First, run several GCs to collect the non referenced objects.
We need to run some GCs because there can be nested dependencies between Ephemerons."
25 timesRepeat: [ Smalltalk garbageCollect ].
"Then, force the finalization of the unfinalized Ephemerons"
ephemeronsCollection do: [ :e | e forceFinalization ]
]

Expand All @@ -39,15 +44,38 @@ IllFinalizationProfiler >> objectAllocations [
^ ephemeronsCollection
]

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

gcProcess := [
[ true ] whileTrue: [
Smalltalk garbageCollect.
500 milliSeconds wait ] ] fork
]

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

super startProfiling.
self startGCProcess
]

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

^ statsModel ifNil: [ statsModel := FinalizationStatsModel on: ephemeronsCollection ]
]

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

gcProcess terminate
]

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

super stopProfiling.
self stopGCProcess.
self forceFinalizationOfObjects
]

0 comments on commit 34eb2bd

Please sign in to comment.