Skip to content

Commit baa8c94

Browse files
authored
Added fixes for a number of POH issues (#2144)
* Fixing POH related issues * Added POH consideration for allocTick s * Fix for cases where the NumGenerations doesn't contain Pinned Object heap
1 parent 930041c commit baa8c94

File tree

2 files changed

+27
-15
lines changed

2 files changed

+27
-15
lines changed

src/TraceEvent/Computers/TraceManagedProcess.cs

Lines changed: 26 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -692,10 +692,15 @@ internal static void SetupCallbacks(TraceEventDispatcher source)
692692
// is an int???
693693
stats.GC.m_stats.allocTickCurrentMB[0] += valueMB;
694694
}
695-
else
695+
else if (data.AllocationKind == GCAllocationKind.Large)
696696
{
697697
stats.GC.m_stats.allocTickCurrentMB[1] += valueMB;
698698
}
699+
700+
else // POH
701+
{
702+
stats.GC.m_stats.allocTickCurrentMB[2] += valueMB;
703+
}
699704
};
700705

701706
source.Clr.GCStart += delegate (GCStartTraceData data)
@@ -1172,6 +1177,7 @@ internal static void SetupCallbacks(TraceEventDispatcher source)
11721177
_gc.HasAllocTickEvents = true;
11731178
_gc.AllocedSinceLastGCBasedOnAllocTickMB[0] = stats.GC.m_stats.allocTickCurrentMB[0] - stats.GC.m_stats.allocTickAtLastGC[0];
11741179
_gc.AllocedSinceLastGCBasedOnAllocTickMB[1] = stats.GC.m_stats.allocTickCurrentMB[1] - stats.GC.m_stats.allocTickAtLastGC[1];
1180+
_gc.AllocedSinceLastGCBasedOnAllocTickMB[2] = stats.GC.m_stats.allocTickCurrentMB[2] - stats.GC.m_stats.allocTickAtLastGC[2];
11751181
}
11761182

11771183
// This is where a background GC ends.
@@ -1205,6 +1211,7 @@ internal static void SetupCallbacks(TraceEventDispatcher source)
12051211
stats.GC.m_stats.ProcessCpuAtLastGC = process.CPUMSec;
12061212
stats.GC.m_stats.allocTickAtLastGC[0] = stats.GC.m_stats.allocTickCurrentMB[0];
12071213
stats.GC.m_stats.allocTickAtLastGC[1] = stats.GC.m_stats.allocTickCurrentMB[1];
1214+
stats.GC.m_stats.allocTickAtLastGC[2] = stats.GC.m_stats.allocTickCurrentMB[2];
12081215
stats.GC.m_stats.lastRestartEndTimeRelativeMSec = data.TimeStampRelativeMSec;
12091216
};
12101217

@@ -2151,7 +2158,7 @@ public double SurvivalPercent(Gens gen)
21512158

21522159
long SurvRate = 0;
21532160

2154-
if (gen == Gens.GenLargeObj)
2161+
if (gen == Gens.GenLargeObj || gen == Gens.GenPinObj)
21552162
{
21562163
if (Generation < 2)
21572164
{
@@ -2680,8 +2687,9 @@ internal void OnEnd(TraceGarbageCollector details)
26802687
HeapSizePeakMB = GetHeapSizePeakMB(details.GCs, this);
26812688
UserAllocated[(int)Gens.Gen0] = GetUserAllocated(details.GCs, this, Gens.Gen0);
26822689
UserAllocated[(int)Gens.GenLargeObj] = GetUserAllocated(details.GCs, this, Gens.GenLargeObj);
2690+
UserAllocated[(int)Gens.GenPinObj] = GetUserAllocated(details.GCs, this, Gens.GenPinObj);
26832691
HeapSizeBeforeMB = GetHeapSizeBeforeMB(details.GCs, this);
2684-
for (int gen = (int)Gens.Gen0; gen <= (int)Gens.GenLargeObj; gen++)
2692+
for (int gen = (int)Gens.Gen0; gen <= (int)Gens.GenPinObj; gen++)
26852693
{
26862694
GenSizeBeforeMB[gen] = GetGenSizeBeforeMB(details.GCs, this, (Gens)gen);
26872695
}
@@ -2769,12 +2777,13 @@ internal static FreeListEfficiency GetFreeListEfficiency(List<TraceGC> GCs, Trac
27692777
Gens gen = Gens.Gen2;
27702778
FreeListEfficiency freeList = new FreeListEfficiency();
27712779

2772-
// I am not worried about gen0 or LOH's free list efficiency right now - it's
2780+
// I am not worried about gen0 or LOH's or POH's free list efficiency right now - it's
27732781
// calculated differently.
27742782
if ((gc.PerHeapHistories == null) ||
27752783
(gc.PerHeapHistories.Count == 0) ||
27762784
(gen == Gens.Gen0) ||
27772785
(gen == Gens.GenLargeObj) ||
2786+
(gen == Gens.GenPinObj) ||
27782787
(gc.Index <= 0) ||
27792788
!(gc.PerHeapHistories[0].VersionRecognized))
27802789
{
@@ -2854,7 +2863,7 @@ internal static FreeListEfficiency GetFreeListEfficiency(List<TraceGC> GCs, Trac
28542863

28552864
internal static double GetAllocedSinceLastGCMB(List<TraceGC> GCs, TraceGC gc)
28562865
{
2857-
return GetUserAllocated(GCs, gc, Gens.Gen0) + GetUserAllocated(GCs, gc, Gens.GenLargeObj);
2866+
return GetUserAllocated(GCs, gc, Gens.Gen0) + GetUserAllocated(GCs, gc, Gens.GenLargeObj) + GetUserAllocated(GCs, gc, Gens.GenPinObj);
28582867
}
28592868

28602869
internal static double GetRatioPeakAfter(List<TraceGC> GCs, TraceGC gc) { if (gc.HeapSizeAfterMB == 0) { return 0; } return GetHeapSizePeakMB(GCs, gc) / gc.HeapSizeAfterMB; }
@@ -2886,7 +2895,7 @@ internal static double GetHeapSizePeakMB(List<TraceGC> GCs, TraceGC gc)
28862895
/// </summary>
28872896
internal static double GetUserAllocated(List<TraceGC> GCs, TraceGC gc, Gens gen)
28882897
{
2889-
Debug.Assert((gen == Gens.Gen0) || (gen == Gens.GenLargeObj));
2898+
Debug.Assert((gen == Gens.Gen0) || (gen == Gens.GenLargeObj) || (gen == Gens.GenPinObj));
28902899

28912900
if ((gc.Type == GCType.BackgroundGC) && (gen == Gens.Gen0))
28922901
{
@@ -2919,7 +2928,7 @@ internal static double GetUserAllocated(List<TraceGC> GCs, TraceGC gc, Gens gen)
29192928
internal static double GetHeapSizeBeforeMB(List<TraceGC> GCs, TraceGC gc)
29202929
{
29212930
double ret = 0;
2922-
for (Gens gen = Gens.Gen0; gen <= Gens.GenLargeObj; gen++)
2931+
for (Gens gen = Gens.Gen0; gen <= Gens.GenPinObj; gen++)
29232932
{
29242933
ret += GetGenSizeBeforeMB(GCs, gc, gen);
29252934
}
@@ -2935,7 +2944,10 @@ internal static double GetGenSizeBeforeMB(List<TraceGC> GCs, TraceGC gc, Gens ge
29352944
double ret = 0.0;
29362945
for (int HeapIndex = 0; HeapIndex < gc.PerHeapHistories.Count; HeapIndex++)
29372946
{
2938-
ret += gc.PerHeapHistories[HeapIndex].GenData[(int)gen].SizeBefore / 1000000.0;
2947+
if (gc.PerHeapHistories[HeapIndex].GenData.Length > (int)gen)
2948+
{
2949+
ret += gc.PerHeapHistories[HeapIndex].GenData[(int)gen].SizeBefore / 1000000.0;
2950+
}
29392951
}
29402952

29412953
return ret;
@@ -3022,15 +3034,15 @@ private static double GetUserAllocatedPerHeap(List<TraceGC> GCs, TraceGC gc, int
30223034
long prevObjSize = 0;
30233035
if (gc.Index > 0)
30243036
{
3025-
// If the prevous GC has that heap get its size.
3037+
// If the previous GC has that heap get its size.
30263038
var perHeapGenData = GCs[gc.Index - 1].PerHeapHistories;
30273039
if (perHeapGenData?.Count > 0 && HeapIndex < perHeapGenData.Count)
30283040
{
30293041
prevObjSize = perHeapGenData[HeapIndex].GenData[(int)gen].ObjSizeAfter;
3030-
// Note that for gen3 we need to do something extra as its after data may not be updated if the last
3042+
// Note that for gen3 or gen4 we need to do something extra as its after data may not be updated if the last
30313043
// GC was a gen0 GC (A GC will update its size after data up to (Generation + 1) because that's all
30323044
// it would change).
3033-
if ((gen == Gens.GenLargeObj) && (prevObjSize == 0) && (GCs[gc.Index - 1].Generation < (int)Gens.Gen1))
3045+
if ((gen == Gens.GenLargeObj || gen == Gens.GenPinObj) && (prevObjSize == 0) && (GCs[gc.Index - 1].Generation < (int)Gens.Gen1))
30343046
{
30353047
prevObjSize = perHeapGenData[HeapIndex].GenData[(int)gen].ObjSpaceBefore;
30363048
}
@@ -4672,8 +4684,8 @@ private static TraceGC GetLastGC(TraceLoadedDotNetRuntime proc)
46724684
// candidate to be made private/ex
46734685
//
46744686
// The amount of memory allocated by the user threads. So they are divided up into gen0 and LOH allocations.
4675-
internal double[] allocTickCurrentMB = { 0.0, 0.0 };
4676-
internal double[] allocTickAtLastGC = { 0.0, 0.0 };
4687+
internal double[] allocTickCurrentMB = { 0.0, 0.0, 0.0 };
4688+
internal double[] allocTickAtLastGC = { 0.0, 0.0, 0.0 };
46774689
internal bool HasAllocTickEvents = false;
46784690
internal bool SeenBadAllocTick = false;
46794691

@@ -4851,7 +4863,7 @@ internal static void ProcessPerHeapHistory(TraceLoadedDotNetRuntime proc, GCPerH
48514863
hist.GenData[(int)GenIndex] = data.GenData(GenIndex);
48524864
}
48534865

4854-
if (_event.PerHeapHistories == null) { _event.PerHeapHistories = new List<GCPerHeapHistory>(); }
4866+
Debug.Assert(_event.PerHeapHistories != null);
48554867
_event.PerHeapHistories.Add(hist);
48564868
}
48574869
}

src/TraceEvent/Parsers/ClrTraceEventParser.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6186,7 +6186,7 @@ public int Count
61866186
}
61876187
}
61886188
public bool HasCount { get { return Version >= 3; } }
6189-
public int NumGenerations { get { return HasCount ? Count : 4; } }
6189+
public int NumGenerations { get { return HasCount ? Count : 5; } }
61906190
public int MemoryPressure
61916191
{
61926192
get

0 commit comments

Comments
 (0)