From 34eb2bdc00b6ead8872951fc746160c9ab825f3c Mon Sep 17 00:00:00 2001 From: jordanmontt Date: Tue, 26 Sep 2023 14:43:37 +0200 Subject: [PATCH] Added Gc process into the finalization profiler. Running the gc when stopped profiling --- .../IllFinalizationProfiler.class.st | 30 ++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-) diff --git a/src/IllimaniProfiler/IllFinalizationProfiler.class.st b/src/IllimaniProfiler/IllFinalizationProfiler.class.st index 3039133..0936384 100644 --- a/src/IllimaniProfiler/IllFinalizationProfiler.class.st +++ b/src/IllimaniProfiler/IllFinalizationProfiler.class.st @@ -3,7 +3,8 @@ Class { #superclass : 'IllAbstractProfiler', #instVars : [ 'ephemeronsCollection', - 'statsModel' + 'statsModel', + 'gcProcess' ], #category : 'IllimaniProfiler-Finalization-Profiler', #package : 'IllimaniProfiler', @@ -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 ] ] @@ -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 ]