Skip to content

Commit

Permalink
Added new profiler to get the allocation rate
Browse files Browse the repository at this point in the history
  • Loading branch information
jordanmontt committed Sep 29, 2023
1 parent 247e55e commit b91b4f2
Show file tree
Hide file tree
Showing 10 changed files with 269 additions and 138 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ IllFinalizationProfilerUnconstructedCollectionTest >> testObjectAllocations [
profiler registerAllocation: allocation.
profiler finalize: allocation.

allocationHolderExpected := BasicAllocationInfoModel new
allocationHolderExpected := AllocationFinalizationInfoModel new
allocatedObjectClass: allocation class;
sizeInBytes: allocation sizeInMemory;
yourself.
Expand All @@ -101,15 +101,15 @@ IllFinalizationProfilerUnconstructedCollectionTest >> testObjectAllocationsTwoOb
allocation := Array new.
profiler registerAllocation: allocation.
profiler finalize: allocation.
allocationHolderExpected1 := BasicAllocationInfoModel new
allocationHolderExpected1 := AllocationFinalizationInfoModel new
allocatedObjectClass: allocation class;
sizeInBytes: allocation sizeInMemory;
yourself.

allocation := OrderedCollection new.
profiler registerAllocation: allocation.
profiler finalize: allocation.
allocationHolderExpected2 := BasicAllocationInfoModel new
allocationHolderExpected2 := AllocationFinalizationInfoModel new
allocatedObjectClass: allocation class;
sizeInBytes: allocation sizeInMemory;
yourself.
Expand All @@ -125,15 +125,15 @@ IllFinalizationProfilerUnconstructedCollectionTest >> testObjectAllocationsTwoOb
allocation := Array new.
profiler registerAllocation: allocation.
profiler finalize: allocation.
allocationHolderExpected1 := BasicAllocationInfoModel new
allocationHolderExpected1 := AllocationFinalizationInfoModel new
allocatedObjectClass: allocation class;
sizeInBytes: allocation sizeInMemory;
yourself.

allocation := OrderedCollection new.
profiler registerAllocation: allocation.
profiler finalize: allocation.
allocationHolderExpected2 := BasicAllocationInfoModel new
allocationHolderExpected2 := AllocationFinalizationInfoModel new
allocatedObjectClass: allocation class;
sizeInBytes: allocation sizeInMemory;
yourself.
Expand All @@ -151,7 +151,7 @@ IllFinalizationProfilerUnconstructedCollectionTest >> testObjectAllocationsWithT
profiler registerAllocation: allocation.
profiler finalize: allocation.

allocationHolderExpected := BasicAllocationInfoModel new
allocationHolderExpected := AllocationFinalizationInfoModel new
allocatedObjectClass: allocation class;
sizeInBytes: allocation sizeInMemory;
yourself.
Expand Down
60 changes: 60 additions & 0 deletions src/IllimaniProfiler/AllocationBasicInfoModel.class.st
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
Class {
#name : 'AllocationBasicInfoModel',
#superclass : 'Object',
#instVars : [
'allocatedObjectClass',
'sizeInBytes'
],
#category : 'IllimaniProfiler-Model-Allocation',
#package : 'IllimaniProfiler',
#tag : 'Model-Allocation'
}

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

^ allocatedObjectClass
]

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

allocatedObjectClass := anObject
]

{ #category : 'inspector - extensions' }
AllocationBasicInfoModel >> inspectableAssociations [

^ {
('Allocated Object Class' -> allocatedObjectClass).
('Memory Size' -> sizeInBytes humanReadableByteSizeString) }
]

{ #category : 'inspector - extensions' }
AllocationBasicInfoModel >> inspectorExtension: aBuilder [

<inspectorPresentationOrder: 0 title: 'Overview'>
| tablePresenter elements items |
elements := self inspectableAssociations.
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' }
AllocationBasicInfoModel >> sizeInBytes [
"Returns the size in memory in bytes"

^ sizeInBytes
]

{ #category : 'accessing' }
AllocationBasicInfoModel >> sizeInBytes: aNumber [

sizeInBytes := aNumber
]
79 changes: 79 additions & 0 deletions src/IllimaniProfiler/AllocationFinalizationInfoModel.class.st
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
Class {
#name : 'AllocationFinalizationInfoModel',
#superclass : 'AllocationBasicInfoModel',
#instVars : [
'finalizationTime',
'initializationTime'
],
#category : 'IllimaniProfiler-Model-Allocation',
#package : 'IllimaniProfiler',
#tag : 'Model-Allocation'
}

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

^ finalizationTime
]

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

finalizationTime := anObject
]

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

finalizationTime := Time microsecondClockValue
]

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

^ initializationTime
]

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

initializationTime := microsecondsAsInt
]

{ #category : 'inspector - extensions' }
AllocationFinalizationInfoModel >> inspectableAssociations [

^ super inspectableAssociations , {
('Initialization timestamp' -> initializationTime).
('Finalization timestamp' -> finalizationTime).
('Object''s lifetime' -> self lifetimeAsString) }
]

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

^ finalizationTime - initializationTime
]

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

^ Duration microSeconds: self lifetime
]

{ #category : 'accessing' }
AllocationFinalizationInfoModel >> lifetimeAsString [

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

{ #category : 'accessing' }
AllocationFinalizationInfoModel >> timeAsSeconds [

^ initializationTime / 1000000
]
2 changes: 1 addition & 1 deletion src/IllimaniProfiler/AllocationSiteInfoModel.class.st
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Class {
#name : 'AllocationSiteInfoModel',
#superclass : 'BasicAllocationInfoModel',
#superclass : 'AllocationFinalizationInfoModel',
#instVars : [
'context',
'allocatorClass',
Expand Down
124 changes: 0 additions & 124 deletions src/IllimaniProfiler/BasicAllocationInfoModel.class.st

This file was deleted.

68 changes: 68 additions & 0 deletions src/IllimaniProfiler/IllAllocationStatisticsProfiler.class.st
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
Class {
#name : 'IllAllocationStatisticsProfiler',
#superclass : 'IllAbstractProfiler',
#instVars : [
'allocationsRegistry',
'objectAllocations'
],
#category : 'IllimaniProfiler-Allocation-Profiler',
#package : 'IllimaniProfiler',
#tag : 'Allocation-Profiler'
}

{ #category : 'accessing - statistics' }
IllAllocationStatisticsProfiler >> allocatedMemoryRatePerSecond [

^ self stats totalAllocatedMemory
/ (Duration microSeconds: totalTime) totalSeconds asFloat
]

{ #category : 'accessing - statistics' }
IllAllocationStatisticsProfiler >> allocationRatePerSecond [

^ self stats totalAllocatedObjects
/ (Duration microSeconds: totalTime) totalSeconds asFloat
]

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

super initialize.
allocationsRegistry := OrderedCollection new: 3000000
]

{ #category : 'profiling' }
IllAllocationStatisticsProfiler >> internalRegisterAllocation: anObject [

allocationsRegistry add: anObject class -> anObject sizeInMemory
]

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

objectAllocations ifNil: [
objectAllocations := allocationsRegistry collect: [ :assoc |
AllocationBasicInfoModel new
allocatedObjectClass: assoc key;
sizeInBytes: assoc value;
yourself ] ].
^ objectAllocations
]

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

^ self
]

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

^ self objectAllocations sum: #sizeInBytes
]

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

^ allocationsRegistry size
]
Loading

0 comments on commit b91b4f2

Please sign in to comment.