Skip to content

Instantly share code, notes, and snippets.

@chrisnas
Created May 27, 2019 12:07
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/7a203f0621dbd039c0b09a66af974ee5 to your computer and use it in GitHub Desktop.
Save chrisnas/7a203f0621dbd039c0b09a66af974ee5 to your computer and use it in GitHub Desktop.
// This event is used to figure out if a collection is compacting or not
// Note: last event for background GC (will be GCHeapStats for ephemeral (0/1) and non concurrent gen 2 collections)
private void OnGcGlobalHeapHistory(EventWrittenEventArgs e)
{
var currentGC = GetCurrentGC(_gcInfo);
// check unexpected event (we should have received a GCStart first)
if (currentGC == null)
return;
var globalMask = GetFieldValue<GCGlobalMechanisms>(e, "GlobalMechanisms");
currentGC.IsCompacting =
(globalMask & GCGlobalMechanisms.Compaction) == GCGlobalMechanisms.Compaction;
// this is the last event for gen 2 background collections
if ((GetFieldValue<int>(e, "CondemnedGeneration") == 2) && (currentGC.Type == GCType.BackgroundGC))
{
// check unexpected generation mismatch
var globalMask = (GCGlobalMechanisms)GetFieldValue<uint>(e, "GlobalMechanisms");
currentGC.IsCompacting =
(globalMask & GCGlobalMechanisms.Compaction) == GCGlobalMechanisms.Compaction;
// this is the last event for gen 2 background collections
if ((GetFieldValue<uint>(e, "CondemnedGeneration") == 2) && (currentGC.Type == GCType.BackgroundGC))
{
GcEvents?.Invoke(this, BuildGcArgs(currentGC));
ClearCollections(_gcInfo);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment