Skip to content

Commit ab4135f

Browse files
committed
Measure survived once in the constructor to allow jitter to make its allocations for the memory monitor.
1 parent db259cd commit ab4135f

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

src/BenchmarkDotNet/Engines/Engine.cs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,10 +82,16 @@ internal Engine(
8282
pilotStage = new EnginePilotStage(this);
8383
actualStage = new EngineActualStage(this);
8484

85+
// Necessary for CORE runtimes.
8586
if (includeSurvivedMemory)
8687
{
87-
// Run the clock once to set static memory (necessary for CORE runtimes).
88+
// Measure survived once to allow jit to make its allocations.
89+
GcStats.StartMeasuringSurvived(includeSurvivedMemory);
90+
// Run the clock once to set static memory.
8891
MeasureAction(_ => { }, 0);
92+
GcStats.StopMeasuringSurvived(includeSurvivedMemory);
93+
// Clear total measured to not pollute actual measurement.
94+
GcStats.ClearTotalMeasuredSurvived();
8995
}
9096
}
9197

src/BenchmarkDotNet/Engines/GcStats.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -269,6 +269,11 @@ public static long StopMeasuringSurvived(bool measure)
269269
return measured;
270270
}
271271

272+
public static void ClearTotalMeasuredSurvived()
273+
{
274+
_totalMeasured = 0;
275+
}
276+
272277
private static long GetTotalBytes(bool actual)
273278
{
274279
if (!actual || RuntimeInformation.IsMono) // Monitoring is not available in Mono.

0 commit comments

Comments
 (0)