Skip to content

Instantly share code, notes, and snippets.

@chrisnas
Created May 27, 2019 12:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save chrisnas/4cf77c2d75d101be23cdc95036f761b5 to your computer and use it in GitHub Desktop.
Save chrisnas/4cf77c2d75d101be23cdc95036f761b5 to your computer and use it in GitHub Desktop.
// This event provides the size of each generation after the collection
// Note: last event for non background GC (will be GCGlobalHeapHistory for background gen 2)
private void OnGcHeapStats(EventWrittenEventArgs e)
{
var currentGC = GetCurrentGC(_gcInfo);
if (currentGC == null)
return;
currentGC.Heaps.Gen0Size = (long)GetFieldValue<ulong>(e, "GenerationSize0");
currentGC.Heaps.Gen1Size = (long)GetFieldValue<ulong>(e, "GenerationSize1");
currentGC.Heaps.Gen2Size = (long)GetFieldValue<ulong>(e, "GenerationSize2");
currentGC.Heaps.LOHSize = (long)GetFieldValue<ulong>(e, "GenerationSize3");
// this is the last event for non background collections during a background gen2 collections
if (
(_gcInfo.CurrentBGC != null) &&
(currentGC.Generation < 2)
)
{
GcEvents?.Invoke(this, BuildGcArgs(currentGC));
_gcInfo.GCInProgress = null;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment