Skip to content

Commit

Permalink
Refactoring some code
Browse files Browse the repository at this point in the history
  • Loading branch information
jordanmontt committed Sep 21, 2023
1 parent 0ab7cb9 commit 81cfa81
Show file tree
Hide file tree
Showing 17 changed files with 390 additions and 177 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ AllocationStatisticsTest >> testNumberOfMethods [
AllocationStatisticsTest >> testTimeDifferenceBetweenFirstAndLastAllocation [

self assert: statsModel timeDifferenceBetweenFirstAndLastAllocation
equals: fixture mockedAllocations last initializationTimestamp - fixture mockedAllocations first initializationTimestamp
equals: fixture mockedAllocations last initializationTime - fixture mockedAllocations first initializationTime
]

{ #category : 'tests' }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,63 +23,63 @@ AllocationStatisticsTestFixture >> allocationsOne [
add: (AllocationSiteInfoModel new
allocatorClass: Rectangle;
allocatorMethod: Margin >> #asMargin;
initializationTimestamp: DateAndTime now;
initializationTime: DateAndTime now;
allocatedObjectClass: OrderedCollection;
sizeInBytes: 16;
yourself);
add: (AllocationSiteInfoModel new
allocatorClass: Rectangle;
allocatorMethod: Margin >> #asMargin;
initializationTimestamp: DateAndTime now;
initializationTime: DateAndTime now;
allocatedObjectClass: OrderedCollection;
sizeInBytes: 16;
yourself);
add: (AllocationSiteInfoModel new
allocatorClass: Rectangle;
allocatorMethod: Margin >> #asMargin;
initializationTimestamp: DateAndTime now;
initializationTime: DateAndTime now;
allocatedObjectClass: Dictionary;
sizeInBytes: 16;
yourself);
add: (AllocationSiteInfoModel new
allocatorClass: Rectangle;
allocatorMethod: Margin >> #asMargin;
initializationTimestamp: DateAndTime now;
initializationTime: DateAndTime now;
allocatedObjectClass: ByteString;
sizeInBytes: 32;
yourself);
add: (AllocationSiteInfoModel new
allocatorClass: Rectangle;
allocatorMethod: Margin >> #asMargin;
initializationTimestamp: DateAndTime now;
initializationTime: DateAndTime now;
allocatedObjectClass: ByteString;
sizeInBytes: 48;
yourself);
add: (AllocationSiteInfoModel new
allocatorClass: Rectangle;
allocatorMethod: Object >> #'->';
initializationTimestamp: DateAndTime now;
initializationTime: DateAndTime now;
allocatedObjectClass: ByteString;
sizeInBytes: 100;
yourself);
add: (AllocationSiteInfoModel new
allocatorClass: Rectangle;
allocatorMethod: Object >> #'->';
initializationTimestamp: DateAndTime now;
initializationTime: DateAndTime now;
allocatedObjectClass: ByteString;
sizeInBytes: 55;
yourself);
add: (AllocationSiteInfoModel new
allocatorClass: Rectangle;
allocatorMethod: Object >> #'->';
initializationTimestamp: DateAndTime now;
initializationTime: DateAndTime now;
allocatedObjectClass: Color;
sizeInBytes: 60;
yourself);
add: (AllocationSiteInfoModel new
allocatorClass: Rectangle;
allocatorMethod: Object >> #'->';
initializationTimestamp: DateAndTime now;
initializationTime: DateAndTime now;
allocatedObjectClass: Color;
sizeInBytes: 16;
yourself).
Expand All @@ -94,7 +94,7 @@ AllocationStatisticsTestFixture >> allocationsThree [
allocations add: (AllocationSiteInfoModel new
allocatorClass: String;
allocatorMethod: Collection>>#sorted:;
initializationTimestamp: Time microsecondClockValue;
initializationTime: Time microsecondClockValue;
allocatedObjectClass: ByteArray;
sizeInBytes: 16;
yourself).
Expand All @@ -110,35 +110,35 @@ AllocationStatisticsTestFixture >> allocationsTwo [
add: (AllocationSiteInfoModel new
allocatorClass: OrderedCollection;
allocatorMethod: ArrayedCollection >> #add:;
initializationTimestamp: Time microsecondClockValue;
initializationTime: Time microsecondClockValue;
allocatedObjectClass: ByteString;
sizeInBytes: 16;
yourself);
add: (AllocationSiteInfoModel new
allocatorClass: OrderedCollection;
allocatorMethod: ArrayedCollection >> #add:;
initializationTimestamp: Time microsecondClockValue;
initializationTime: Time microsecondClockValue;
allocatedObjectClass: ByteString;
sizeInBytes: 16;
yourself);
add: (AllocationSiteInfoModel new
allocatorClass: OrderedCollection;
allocatorMethod: ArrayedCollection >> #add:;
initializationTimestamp: Time microsecondClockValue;
initializationTime: Time microsecondClockValue;
allocatedObjectClass: ByteString;
sizeInBytes: 32;
yourself);
add: (AllocationSiteInfoModel new
allocatorClass: OrderedCollection;
allocatorMethod: ArrayedCollection >> #add:;
initializationTimestamp: Time microsecondClockValue;
initializationTime: Time microsecondClockValue;
allocatedObjectClass: ByteArray;
sizeInBytes: 100;
yourself);
add: (AllocationSiteInfoModel new
allocatorClass: OrderedCollection;
allocatorMethod: ArrayedCollection >> #add:;
initializationTimestamp: Time microsecondClockValue;
initializationTime: Time microsecondClockValue;
allocatedObjectClass: ByteArray;
sizeInBytes: 16;
yourself).
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,11 @@ IllFinalizationProfilerTest >> testProfileOnFinalizesCorrectly [

self
assert: finalizationProfiler objectAllocations size
equals: (finalizationProfiler objectAllocations select: [ :e | e finalizationTimestamp isNotNil]) size.
equals: (finalizationProfiler objectAllocations select: [ :e | e finalizationTime isNotNil]) size.

finalizationProfiler objectAllocations do: [ :alloc |
"Finalization time must be after timeNow variable"
self assert: alloc finalizationTimestamp > timeNow ]
self assert: alloc finalizationTime > timeNow ]
]

{ #category : 'tests' }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ BasicAllocationInfoModel >> inspectableAssociations [
^ {
('Allocated Object Class' -> allocatedObjectClass).
('Memory Size' -> sizeInBytes humanReadableByteSizeString).
('Initialization timestamp' -> initializationTimestamp).
('Finalization timestamp' -> finalizationTimestamp).
('Initialization timestamp' -> initializationTime).
('Finalization timestamp' -> finalizationTime).
('Object''s lifetime' -> self lifetimeAsString) }
]

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,12 +99,12 @@ IllRoassalChartBuilder >> constructPerSecondLineChart: aCollection [
IllRoassalChartBuilder >> createLinePlotForAllocations: someAllocations [

| times linePlot indices sortedByTime |
sortedByTime := someAllocations sorted: [ :a :b | a initializationTimestamp < b initializationTimestamp ].
sortedByTime := someAllocations sorted: [ :a :b | a initializationTime < b initializationTime ].

"Roassal does not accepts Duration"
times := sortedByTime collect: [ :each | each timestampAsSeconds ].
times := sortedByTime collect: [ :each | each timeAsSeconds ].
"To start in 0"
times := times collect: [ :e | (e - sortedByTime first timestampAsSeconds) asFloat ].
times := times collect: [ :e | (e - sortedByTime first timeAsSeconds) asFloat ].

indices := 1 to: times size.
linePlot := RSLinePlot new x: times y: indices.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ AllocationStatistics >> rawAllocations: anObject [
{ #category : 'statistics - time' }
AllocationStatistics >> timeDifferenceBetweenFirstAndLastAllocation [

^ rawAllocations last initializationTimestamp - rawAllocations first initializationTimestamp
^ rawAllocations last initializationTime - rawAllocations first initializationTime
]

{ #category : 'statistics' }
Expand Down
32 changes: 16 additions & 16 deletions src/IllimaniAllocationProfiler/BasicAllocationInfoModel.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ Class {
#superclass : 'Object',
#instVars : [
'allocatedObjectClass',
'finalizationTimestamp',
'initializationTimestamp',
'sizeInBytes'
'sizeInBytes',
'finalizationTime',
'initializationTime'
],
#category : 'IllimaniAllocationProfiler-Model',
#package : 'IllimaniAllocationProfiler',
Expand All @@ -25,43 +25,43 @@ BasicAllocationInfoModel >> allocatedObjectClass: anObject [
]

{ #category : 'accessing' }
BasicAllocationInfoModel >> finalizationTimestamp [
BasicAllocationInfoModel >> finalizationTime [
"In microseconds"

^ finalizationTimestamp
^ finalizationTime
]

{ #category : 'accessing' }
BasicAllocationInfoModel >> finalizationTimestamp: anObject [
BasicAllocationInfoModel >> finalizationTime: anObject [
"In microseconds"

finalizationTimestamp := anObject
finalizationTime := anObject
]

{ #category : 'finalization' }
BasicAllocationInfoModel >> finalize [

finalizationTimestamp := Time microsecondClockValue
finalizationTime := Time microsecondClockValue
]

{ #category : 'accessing' }
BasicAllocationInfoModel >> initializationTimestamp [
BasicAllocationInfoModel >> initializationTime [
"In microseconds"

^ initializationTimestamp
^ initializationTime
]

{ #category : 'accessing' }
BasicAllocationInfoModel >> initializationTimestamp: microsecondsAsInt [
BasicAllocationInfoModel >> initializationTime: microsecondsAsInt [
"In microseconds"

initializationTimestamp := microsecondsAsInt
initializationTime := microsecondsAsInt
]

{ #category : 'accessing' }
BasicAllocationInfoModel >> lifetime [

^ finalizationTimestamp - initializationTimestamp
^ finalizationTime - initializationTime
]

{ #category : 'accessing' }
Expand All @@ -73,7 +73,7 @@ BasicAllocationInfoModel >> lifetimeAsDuration [
{ #category : 'accessing' }
BasicAllocationInfoModel >> lifetimeAsString [

finalizationTimestamp ifNil: [ ^ '-' ].
finalizationTime ifNil: [ ^ '-' ].
^ self lifetimeAsDuration humanReadablePrintString
]

Expand All @@ -91,7 +91,7 @@ BasicAllocationInfoModel >> sizeInBytes: aNumber [
]

{ #category : 'accessing' }
BasicAllocationInfoModel >> timestampAsSeconds [
BasicAllocationInfoModel >> timeAsSeconds [

^ initializationTimestamp / 1000000
^ initializationTime / 1000000
]
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ IllProfilerMpHandler >> handleObjectAllocation: newlyAllocatedObject [
allocatedObjectClass: newlyAllocatedObject class;
contextFingerprint: filteredContext;
sizeInBytes: newlyAllocatedObject sizeInMemory;
initializationTimestamp: Time microsecondClockValue.
initializationTime: Time microsecondClockValue.

objectAllocations add: allocationInformationHolder
]
Expand Down
106 changes: 106 additions & 0 deletions src/IllimaniFinalizationProfiler/IllEphemeron.class.st
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
Class {
#name : 'IllEphemeron',
#superclass : 'Association',
#type : 'ephemeron',
#instVars : [
'finalizationTime',
'sizeInBytes',
'initializationTime',
'allocatedObjectClass'
],
#category : 'IllimaniFinalizationProfiler-Ephemerons',
#package : 'IllimaniFinalizationProfiler',
#tag : 'Ephemerons'
}

{ #category : 'accessing' }
IllEphemeron >> allocatedObjectClass [

^ allocatedObjectClass
]

{ #category : 'accessing' }
IllEphemeron >> allocatedObjectClass: anObject [

allocatedObjectClass := anObject
]

{ #category : 'accessing' }
IllEphemeron >> finalizationTime [

^ finalizationTime
]

{ #category : 'accessing' }
IllEphemeron >> finalizationTime: anObject [

finalizationTime := anObject
]

{ #category : 'accessing' }
IllEphemeron >> initializationTime [

^ initializationTime
]

{ #category : 'accessing' }
IllEphemeron >> initializationTime: anObject [

initializationTime := anObject
]

{ #category : 'inspector' }
IllEphemeron >> inspectorExtension: aBuilder [

<inspectorPresentationOrder: 0 title: 'Overview'>
| tablePresenter elements items |
elements := {
('Allocated Object Class' -> allocatedObjectClass ).
('Memory Size' -> sizeInBytes humanReadableByteSizeString).
('Initialization time' -> initializationTime).
('Finalization time' -> finalizationTime).
('Object''s lifetime' -> self lifetimeAsDuration humanReadablePrintString) }.
items := elements collect: [ :e | StInspectorAssociationNode hostObject: e ].
tablePresenter := aBuilder newTable.
tablePresenter
addColumn: (SpStringTableColumn title: 'Name' evaluated: #key);
addColumn: (SpStringTableColumn title: 'Value' evaluated: #value);
items: items;
beResizable.
^ tablePresenter
]

{ #category : 'accessing' }
IllEphemeron >> lifetimeAsDuration [

^ Duration microSeconds: finalizationTime - initializationTime
]

{ #category : 'finalization' }
IllEphemeron >> mourn [

key ifNil: [ ^ self ].

key := nil.
finalizationTime := Time primUTCMicrosecondsClock
]

{ #category : 'printing' }
IllEphemeron >> printOn: aStream [

aStream << allocatedObjectClass name << ' lifetime: '
<< self lifetimeAsDuration totalSeconds asFloat asString << ' seconds' << ' weights '
<< sizeInBytes humanReadableByteSizeString
]

{ #category : 'accessing' }
IllEphemeron >> sizeInBytes [

^ sizeInBytes
]

{ #category : 'accessing' }
IllEphemeron >> sizeInBytes: anObject [

sizeInBytes := anObject
]
Loading

0 comments on commit 81cfa81

Please sign in to comment.