Skip to content

Commit

Permalink
add bytesInScope stats for lgc,cgc
Browse files Browse the repository at this point in the history
  • Loading branch information
shwestrick committed Oct 28, 2022
1 parent 385eb8e commit 83b4b68
Show file tree
Hide file tree
Showing 9 changed files with 43 additions and 0 deletions.
4 changes: 4 additions & 0 deletions basis-library/mpl/gc.sig
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ sig
val localBytesReclaimed: unit -> IntInf.int
val localBytesReclaimedOfProc: int -> IntInf.int

val bytesInScopeForLocal: unit -> IntInf.int

val numLocalGCs: unit -> IntInf.int
val numLocalGCsOfProc: int -> IntInf.int

Expand All @@ -61,6 +63,8 @@ sig
val ccBytesReclaimed: unit -> IntInf.int
val ccBytesReclaimedOfProc: int -> IntInf.int

val bytesInScopeForCC: unit -> IntInf.int

val ccTime: unit -> Time.time
val ccTimeOfProc: int -> Time.time

Expand Down
6 changes: 6 additions & 0 deletions basis-library/mpl/gc.sml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,12 @@ struct
fun getCCBytesReclaimedOfProc p =
GC.getCCBytesReclaimedOfProc (gcState (), Word32.fromInt p)

fun bytesInScopeForLocal () =
C_UIntmax.toLargeInt (GC.bytesInScopeForLocal (gcState ()))

fun bytesInScopeForCC () =
C_UIntmax.toLargeInt (GC.bytesInScopeForCC (gcState ()))

fun numberDisentanglementChecks () =
C_UIntmax.toLargeInt (GC.numberDisentanglementChecks (gcState ()))

Expand Down
8 changes: 8 additions & 0 deletions basis-library/primitive/prim-mlton.sml
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,14 @@ structure GC =
val getCumulativeStatisticsLocalBytesReclaimedOfProc = _import
"GC_getCumulativeStatisticsLocalBytesReclaimedOfProc" runtime private: GCState.t * Word32.word -> C_UIntmax.t;

val bytesInScopeForLocal =
_import "GC_bytesInScopeForLocal" runtime private:
GCState.t -> C_UIntmax.t;

val bytesInScopeForCC =
_import "GC_bytesInScopeForCC" runtime private:
GCState.t -> C_UIntmax.t;

val getNumCCsOfProc = _import "GC_getNumCCsOfProc" runtime private: GCState.t * Word32.word -> C_UIntmax.t;
val getCCMillisecondsOfProc = _import "GC_getCCMillisecondsOfProc" runtime private: GCState.t * Word32.word -> C_UIntmax.t;
val getCCBytesReclaimedOfProc = _import "GC_getCCBytesReclaimedOfProc" runtime private: GCState.t * Word32.word -> C_UIntmax.t;
Expand Down
1 change: 1 addition & 0 deletions runtime/gc/concurrent-collection.c
Original file line number Diff line number Diff line change
Expand Up @@ -1192,6 +1192,7 @@ size_t CC_collectWithRoots(
s->cumulativeStatistics->numCCs++;
assert(bytesScanned >= bytesSaved);
uintmax_t bytesReclaimed = bytesScanned-bytesSaved;
s->cumulativeStatistics->bytesInScopeForCC += bytesScanned;
s->cumulativeStatistics->bytesReclaimedByCC += bytesReclaimed;

return lists.bytesSaved;
Expand Down
16 changes: 16 additions & 0 deletions runtime/gc/gc_state.c
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,22 @@ uintmax_t GC_getCumulativeStatisticsLocalBytesReclaimedOfProc(GC_state s, uint32
return s->procStates[proc].cumulativeStatistics->bytesReclaimedByLocal;
}

uintmax_t GC_bytesInScopeForLocal(GC_state s) {
uintmax_t retVal = 0;
for (size_t i = 0; i < s->numberOfProcs; i++) {
retVal += s->procStates[i].cumulativeStatistics->bytesInScopeForLocal;
}
return retVal;
}

uintmax_t GC_bytesInScopeForCC(GC_state s) {
uintmax_t retVal = 0;
for (size_t i = 0; i < s->numberOfProcs; i++) {
retVal += s->procStates[i].cumulativeStatistics->bytesInScopeForCC;
}
return retVal;
}

uintmax_t GC_getCumulativeStatisticsBytesAllocated (GC_state s) {
/* return sum across all processors */
size_t retVal = 0;
Expand Down
2 changes: 2 additions & 0 deletions runtime/gc/gc_state.h
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,8 @@ PRIVATE uintmax_t GC_getCumulativeStatisticsNumLocalGCsOfProc(GC_state s, uint32
PRIVATE uintmax_t GC_getNumCCsOfProc(GC_state s, uint32_t proc);
PRIVATE uintmax_t GC_getCCMillisecondsOfProc(GC_state s, uint32_t proc);
PRIVATE uintmax_t GC_getCCBytesReclaimedOfProc(GC_state s, uint32_t proc);
PRIVATE uintmax_t GC_bytesInScopeForLocal(GC_state s);
PRIVATE uintmax_t GC_bytesInScopeForCC(GC_state s);
PRIVATE uintmax_t GC_numDisentanglementChecks(GC_state s);
PRIVATE uintmax_t GC_numEntanglements(GC_state s);
PRIVATE float GC_approxRaceFactor(GC_state s);
Expand Down
2 changes: 2 additions & 0 deletions runtime/gc/hierarchical-heap-collection.c
Original file line number Diff line number Diff line change
Expand Up @@ -957,6 +957,8 @@ void HM_HHC_collectLocal(uint32_t desiredScope)
}
}

s->cumulativeStatistics->bytesInScopeForLocal += totalSizeBefore;

if (totalSizeAfter > totalSizeBefore)
{
// whoops?
Expand Down
2 changes: 2 additions & 0 deletions runtime/gc/statistics.c
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ struct GC_cumulativeStatistics *newCumulativeStatistics(void) {
cumulativeStatistics->bytesHHLocaled = 0;
cumulativeStatistics->bytesReclaimedByLocal = 0;
cumulativeStatistics->bytesReclaimedByCC = 0;
cumulativeStatistics->bytesInScopeForLocal = 0;
cumulativeStatistics->bytesInScopeForCC = 0;
cumulativeStatistics->maxBytesLive = 0;
cumulativeStatistics->maxBytesLiveSinceReset = 0;
cumulativeStatistics->maxHeapSize = 0;
Expand Down
2 changes: 2 additions & 0 deletions runtime/gc/statistics.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ struct GC_cumulativeStatistics {
uintmax_t bytesHHLocaled;
uintmax_t bytesReclaimedByLocal;
uintmax_t bytesReclaimedByCC;
uintmax_t bytesInScopeForLocal;
uintmax_t bytesInScopeForCC;

size_t maxBytesLive;
size_t maxBytesLiveSinceReset;
Expand Down

0 comments on commit 83b4b68

Please sign in to comment.