From b94f5b5276193a1eb222192e881dd1124407c1e3 Mon Sep 17 00:00:00 2001 From: jordanmontt Date: Thu, 29 Sep 2022 13:26:53 +0200 Subject: [PATCH] Created handler for recording the color creation --- .project | 3 ++ src/.properties | 3 ++ .../MpColorAllocationProfilerHandler.class.st | 49 +++++++++++++++++++ src/MethodProxiesSebas/package.st | 1 + 4 files changed, 56 insertions(+) create mode 100644 .project create mode 100644 src/.properties create mode 100644 src/MethodProxiesSebas/MpColorAllocationProfilerHandler.class.st create mode 100644 src/MethodProxiesSebas/package.st diff --git a/.project b/.project new file mode 100644 index 0000000..81083cc --- /dev/null +++ b/.project @@ -0,0 +1,3 @@ +{ + 'srcDirectory' : 'src' +} \ No newline at end of file diff --git a/src/.properties b/src/.properties new file mode 100644 index 0000000..ad0471d --- /dev/null +++ b/src/.properties @@ -0,0 +1,3 @@ +{ + #format : #tonel +} \ No newline at end of file diff --git a/src/MethodProxiesSebas/MpColorAllocationProfilerHandler.class.st b/src/MethodProxiesSebas/MpColorAllocationProfilerHandler.class.st new file mode 100644 index 0000000..64de887 --- /dev/null +++ b/src/MethodProxiesSebas/MpColorAllocationProfilerHandler.class.st @@ -0,0 +1,49 @@ +" +I am a handler that register when a color is created. I keep that of both the color and the creation context +" +Class { + #name : #MpColorAllocationProfilerHandler, + #superclass : #MpHandler, + #instVars : [ + 'allocations', + 'classesToAvoid' + ], + #category : #MethodProxiesSebas +} + +{ #category : #evaluating } +MpColorAllocationProfilerHandler >> afterExecutionWithReceiver: receiver arguments: arguments returnValue: returnValue [ + + returnValue class = Color ifTrue: [ + allocations add: (self contextThatCreatesTheColor: thisContext) -> returnValue ]. + ^ returnValue +] + +{ #category : #evaluating } +MpColorAllocationProfilerHandler >> contextThatCreatesTheColor: aContext [ + + "(classToAvoid includes: aContext sender methodClass) ifFalse: [ + ^ aContext sender methodClass ]. + ^ self classThatCreatesTheColor: aContext sender" + + | sender | + sender := aContext sender. + [ classesToAvoid includes: sender methodClass ] whileTrue: [ + sender := sender sender ]. + ^ sender +] + +{ #category : #initialization } +MpColorAllocationProfilerHandler >> initialize [ + + super initialize. + allocations := OrderedCollection new. + classesToAvoid := { + Color class. + Color. + MpColorAllocationProfilerHandler. + MpMethodProxy. + BlockClosure. + FullBlockClosure. + CompiledBlock } +] diff --git a/src/MethodProxiesSebas/package.st b/src/MethodProxiesSebas/package.st new file mode 100644 index 0000000..d39927a --- /dev/null +++ b/src/MethodProxiesSebas/package.st @@ -0,0 +1 @@ +Package { #name : #MethodProxiesSebas }