Skip to content

Commit

Permalink
Added tables in the ui to show the gc survived cycles
Browse files Browse the repository at this point in the history
  • Loading branch information
jordanmontt committed Sep 25, 2023
1 parent 46cc1e4 commit ff8eb76
Show file tree
Hide file tree
Showing 6 changed files with 164 additions and 61 deletions.
20 changes: 16 additions & 4 deletions src/IllimaniProfiler/IllEphemeron.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,8 @@ IllEphemeron >> initialize [

super initialize.
initializationTime := Time primUTCMicrosecondsClock.
scavengesAtStart := Smalltalk vm incrementalGCCount.
fullGCsAtStart := Smalltalk vm fullGCCount
survivedScavenges := Smalltalk vm incrementalGCCount.
survivedFullGC := Smalltalk vm fullGCCount
]

{ #category : 'inspector' }
Expand Down Expand Up @@ -98,8 +98,8 @@ IllEphemeron >> mourn [

key := nil.
finalizationTime := Time primUTCMicrosecondsClock.
survivedScavenges := Smalltalk vm incrementalGCCount - scavengesAtStart.
survivedFullGC := Smalltalk vm fullGCCount - fullGCsAtStart
survivedScavenges := Smalltalk vm incrementalGCCount - survivedScavenges.
survivedFullGC := Smalltalk vm fullGCCount - survivedFullGC
]

{ #category : 'printing' }
Expand All @@ -121,3 +121,15 @@ IllEphemeron >> sizeInBytes: anObject [

sizeInBytes := anObject
]

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

^ survivedFullGC
]

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

^ survivedScavenges
]
79 changes: 79 additions & 0 deletions src/IllimaniUI/AllocationsGroupedByTablePresenter.class.st
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
Class {
#name : 'AllocationsGroupedByTablePresenter',
#superclass : 'SpPresenter',
#instVars : [
'tablePresenter',
'totalMemory',
'totalAllocations',
'groupedAllocations'
],
#category : 'IllimaniUI-Widgets',
#package : 'IllimaniUI',
#tag : 'Widgets'
}

{ #category : 'initialization' }
AllocationsGroupedByTablePresenter >> connectPresenters [

tablePresenter whenSelectedDo: [ :item | item value inspect ]
]

{ #category : 'initialization' }
AllocationsGroupedByTablePresenter >> convertToPercentageString: aNumber [

^ (aNumber * 100 printShowingDecimalPlaces: 2) , '%'
]

{ #category : 'layout' }
AllocationsGroupedByTablePresenter >> defaultLayout [

^ SpBoxLayout newTopToBottom
add: tablePresenter;
yourself
]

{ #category : 'accessing - model' }
AllocationsGroupedByTablePresenter >> groupAllocations: someObjectAllocations [

^ self subclassResponsibility
]

{ #category : 'initialization' }
AllocationsGroupedByTablePresenter >> initializePresenters [

tablePresenter := self newTable
activateOnSingleClick;
items: groupedAllocations;
alternateRowsColor;
addColumn: (SpStringTableColumn
title: self titleForGroupingColumn
evaluated: [ :assoc | assoc key ]);
addColumn: (SpStringTableColumn
title: 'Total allocated memory'
evaluated: [ :assoc | (assoc value sum: [ :e | e sizeInBytes ]) humanReadableByteSizeString ]);
addColumn: (SpStringTableColumn
title: '% Memory'
evaluated: [ :assoc | self convertToPercentageString: (assoc value sum: [ :e | e sizeInBytes ]) / totalMemory ]);
addColumn: (SpStringTableColumn
title: '# of allocated objects'
evaluated: [ :assoc | assoc value size asStringWithCommas ]);
addColumn: (SpStringTableColumn
title: '% Allocated objects'
evaluated: [ :assoc | self convertToPercentageString: (assoc value size / totalAllocations) ]);
yourself
]

{ #category : 'accessing - model' }
AllocationsGroupedByTablePresenter >> setModelBeforeInitialization: someObjectAllocations [

groupedAllocations := self groupAllocations: someObjectAllocations.
groupedAllocations sort: [ :a :b | a key < b key ].
totalMemory := groupedAllocations sum: [ :assoc | assoc value sum: [ :e | e sizeInBytes ] ].
totalAllocations := groupedAllocations sum: [ :assoc | assoc value size ].
]

{ #category : 'initialization' }
AllocationsGroupedByTablePresenter >> titleForGroupingColumn [

^ self subclassResponsibility
]
20 changes: 20 additions & 0 deletions src/IllimaniUI/FinalizationFullGCCyclesTablePresenter.class.st
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
Class {
#name : 'FinalizationFullGCCyclesTablePresenter',
#superclass : 'AllocationsGroupedByTablePresenter',
#category : 'IllimaniUI-Widgets',
#package : 'IllimaniUI',
#tag : 'Widgets'
}

{ #category : 'accessing - model' }
FinalizationFullGCCyclesTablePresenter >> groupAllocations: someObjectAllocations [

^ (someObjectAllocations groupedBy: [ :allocationModel |
allocationModel survivedFullGC ]) associations
]

{ #category : 'initialization' }
FinalizationFullGCCyclesTablePresenter >> titleForGroupingColumn [

^ '# of full GCs survived'
]
62 changes: 7 additions & 55 deletions src/IllimaniUI/FinalizationLifetimesTablePresenter.class.st
Original file line number Diff line number Diff line change
@@ -1,68 +1,20 @@
Class {
#name : 'FinalizationLifetimesTablePresenter',
#superclass : 'SpPresenter',
#instVars : [
'tablePresenter',
'groupedAllocationsBySeconds',
'totalMemory',
'totalAllocations'
],
#superclass : 'AllocationsGroupedByTablePresenter',
#category : 'IllimaniUI-Widgets',
#package : 'IllimaniUI',
#tag : 'Widgets'
}

{ #category : 'initialization' }
FinalizationLifetimesTablePresenter >> connectPresenters [

tablePresenter whenSelectedDo: [ :item | item value inspect ]
]

{ #category : 'initialization' }
FinalizationLifetimesTablePresenter >> convertToPercentageString: aNumber [

^ (aNumber * 100 printShowingDecimalPlaces: 2) , '%'
]

{ #category : 'layout' }
FinalizationLifetimesTablePresenter >> defaultLayout [
{ #category : 'accessing - model' }
FinalizationLifetimesTablePresenter >> groupAllocations: someObjectAllocations [

^ SpBoxLayout newTopToBottom
add: tablePresenter;
yourself
^ (someObjectAllocations groupedBy: [ :allocationModel |
allocationModel lifetimeAsDuration asSeconds ]) associations
]

{ #category : 'initialization' }
FinalizationLifetimesTablePresenter >> initializePresenters [

tablePresenter := self newTable
activateOnSingleClick;
items: groupedAllocationsBySeconds;
alternateRowsColor;
addColumn: (SpStringTableColumn
title: 'Lifetime duration (seconds)'
evaluated: [ :assoc | assoc key ]);
addColumn: (SpStringTableColumn
title: 'Total allocated memory'
evaluated: [ :assoc | (assoc value sum: [ :e | e sizeInBytes ]) humanReadableByteSizeString ]);
addColumn: (SpStringTableColumn
title: '% Memory'
evaluated: [ :assoc | self convertToPercentageString: (assoc value sum: [ :e | e sizeInBytes ]) / totalMemory ]);
addColumn: (SpStringTableColumn
title: '# of allocated objects'
evaluated: [ :assoc | assoc value size asStringWithCommas ]);
addColumn: (SpStringTableColumn
title: '% Allocated objects'
evaluated: [ :assoc | self convertToPercentageString: (assoc value size / totalAllocations) ]);
yourself
]

{ #category : 'accessing - model' }
FinalizationLifetimesTablePresenter >> setModelBeforeInitialization: someObjectAllocations [
FinalizationLifetimesTablePresenter >> titleForGroupingColumn [

groupedAllocationsBySeconds := (someObjectAllocations groupedBy: [ :allocationModel |
allocationModel lifetimeAsDuration asSeconds ]) associations.
groupedAllocationsBySeconds sort: [ :a :b | a key < b key ].
totalMemory := groupedAllocationsBySeconds sum: [ :assoc | assoc value sum: [ :e | e sizeInBytes ] ].
totalAllocations := groupedAllocationsBySeconds sum: [ :assoc | assoc value size ].
^ 'Lifetime duration (seconds)'
]
20 changes: 20 additions & 0 deletions src/IllimaniUI/FinalizationScavengesCyclesTablePresenter.class.st
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
Class {
#name : 'FinalizationScavengesCyclesTablePresenter',
#superclass : 'AllocationsGroupedByTablePresenter',
#category : 'IllimaniUI-Widgets',
#package : 'IllimaniUI',
#tag : 'Widgets'
}

{ #category : 'accessing - model' }
FinalizationScavengesCyclesTablePresenter >> groupAllocations: someObjectAllocations [

^ (someObjectAllocations groupedBy: [ :allocationModel |
allocationModel survivedScavenges ]) associations
]

{ #category : 'initialization' }
FinalizationScavengesCyclesTablePresenter >> titleForGroupingColumn [

^ '# of scavenges survived'
]
24 changes: 22 additions & 2 deletions src/IllimaniUI/IllFinalizationProfilerUI.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ Class {
#superclass : 'IllAbstractUI',
#instVars : [
'densityChartPresenter',
'lifetimesTable'
'lifetimesTable',
'gcCyclesTable'
],
#category : 'IllimaniUI-Main Presenter',
#package : 'IllimaniUI',
Expand All @@ -23,6 +24,13 @@ IllFinalizationProfilerUI >> densityChartPresenter [
^ densityChartPresenter
]

{ #category : 'accessing - lazy presenters' }
IllFinalizationProfilerUI >> gcCyclesTable [

gcCyclesTable ifNil: [ self initializeGCCyclesTable ].
^ gcCyclesTable
]

{ #category : 'initialization - lazy presenters' }
IllFinalizationProfilerUI >> initializeDensityChartPresenter [

Expand All @@ -48,6 +56,17 @@ IllFinalizationProfilerUI >> initializeDensityChartPresenter [
yourself
]

{ #category : 'initialization - lazy presenters' }
IllFinalizationProfilerUI >> initializeGCCyclesTable [

gcCyclesTable := AlternatorPresenter new
presenterOne: (FinalizationScavengesCyclesTablePresenter on: profiler objectAllocations)
withName: 'Group by scavenges';
presenterTwo: (FinalizationFullGCCyclesTablePresenter on: profiler objectAllocations)
withName: 'Group by full GCs';
yourself
]

{ #category : 'initialization - lazy presenters' }
IllFinalizationProfilerUI >> initializeLifetimesTable [

Expand All @@ -61,8 +80,9 @@ IllFinalizationProfilerUI >> initializeNotebook [

notebookPresenter := self newNotebook
addPageTitle: 'Summary' provider: [ self summaryAndEvaluatorPresenter ];
addPageTitle: 'Allocated Objects' provider: [ self allocatedObjectsTablePresenter ];
addPageTitle: 'Lifetimes Table' provider: [ self lifetimesTable ];
addPageTitle: 'Survived GC cycles' provider: [ self gcCyclesTable ];
addPageTitle: 'Allocated Objects' provider: [ self allocatedObjectsTablePresenter ];
addPageTitle: 'Lifetimes Density' provider: [ self densityChartPresenter ];

addPageTitle: 'Evaluator' provider: [ self codeEvaluator ];
Expand Down

0 comments on commit ff8eb76

Please sign in to comment.