Skip to content

Fixed timings associated with the MarkTimes and MarkPromoted fields for the per heap mark times. #2143

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 9 commits into from
Jan 29, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 18 additions & 27 deletions src/PerfView/GcStats.cs
Original file line number Diff line number Diff line change
Expand Up @@ -515,6 +515,7 @@ public static void ToXmlAttribs(TextWriter writer, TraceProcess stats, TraceLoad
{
if (gc.TimingInfo[(int)TraceGC.TimingType.MarkRoot].HasValue) { writer.Write(" MarkRoot=\"{0}\"", gc.TimingInfo[(int)TraceGC.TimingType.MarkRoot].Value); }
if (gc.TimingInfo[(int)TraceGC.TimingType.MarkScanFinalization].HasValue) { writer.Write(" MarkScanFinalization=\"{0}\"", gc.TimingInfo[(int)TraceGC.TimingType.MarkScanFinalization].Value); }
if (gc.TimingInfo[(int)TraceGC.TimingType.MarkShortWeak].HasValue) { writer.Write(" MarkShortWeak=\"{0}\"", gc.TimingInfo[(int)TraceGC.TimingType.MarkShortWeak].Value); }
if (gc.TimingInfo[(int)TraceGC.TimingType.MarkLongWeak].HasValue) { writer.Write(" MarkLongWeak=\"{0}\"", gc.TimingInfo[(int)TraceGC.TimingType.MarkLongWeak].Value); }
if (gc.TimingInfo[(int)TraceGC.TimingType.Plan].HasValue) { writer.Write(" Plan=\"{0}\"", gc.TimingInfo[(int)TraceGC.TimingType.Plan].Value); }
if (gc.TimingInfo[(int)TraceGC.TimingType.Relocate].HasValue) { writer.Write(" Relocate=\"{0}\"", gc.TimingInfo[(int)TraceGC.TimingType.Relocate].Value); }
Expand Down Expand Up @@ -542,44 +543,34 @@ public static void ToXmlAttribs(TextWriter writer, TraceProcess stats, TraceLoad

if (mt != null)
{
writer.Write(" MarkStack =\"{0:n3}", mt.MarkTimes[(int)MarkRootType.MarkStack]);
if (mt.MarkPromoted != null)
void WriteMarkRootTypeInfo(MarkRootType type)
{
writer.Write("({0})", mt.MarkPromoted[(int)MarkRootType.MarkStack]);
}
int markRootIndex = (int)type;

writer.Write("\" MarkFQ =\"{0:n3}", mt.MarkTimes[(int)MarkRootType.MarkFQ]);
if (mt.MarkPromoted != null)
{
writer.Write("({0})", mt.MarkPromoted[(int)MarkRootType.MarkFQ]);
}
if (markRootIndex >= mt.MarkTimes.Length)
{
return;
}

writer.Write("\" MarkHandles =\"{0:n3}", mt.MarkTimes[(int)MarkRootType.MarkHandles]);
if (mt.MarkPromoted != null)
{
writer.Write("({0})", mt.MarkPromoted[(int)MarkRootType.MarkHandles]);
}
if (mt.MarkTimes[markRootIndex] == -1)
{
return;
}

writer.Write("\"");
if (gc.Generation != 2)
{
writer.Write(" MarkOldGen =\"{0:n3}", mt.MarkTimes[(int)MarkRootType.MarkOlder]);
writer.Write(" {0} =\"{1:n3}", type, mt.MarkTimes[markRootIndex]);
if (mt.MarkPromoted != null)
{
writer.Write("({0})", mt.MarkPromoted[(int)MarkRootType.MarkOlder]);
writer.Write("({0})", mt.MarkPromoted[markRootIndex]);
}

writer.Write("\"");
}
if (mt.MarkTimes[(int)MarkRootType.MarkOverflow] != 0.0)

foreach (MarkRootType markRootType in Enum.GetValues(typeof(MarkRootType)))
{
writer.Write(" MarkOverflow =\"{0:n3}", mt.MarkTimes[(int)MarkRootType.MarkOverflow]);
if (mt.MarkPromoted != null)
{
writer.Write("({0})", mt.MarkPromoted[(int)MarkRootType.MarkOverflow]);
}
WriteMarkRootTypeInfo(markRootType);
}
}

if (gc.LOHCompactInfos.Count > 0)
{
GCLOHCompactInfo lohCompactInfo = gc.LOHCompactInfos[HeapNum];
Expand Down Expand Up @@ -1728,4 +1719,4 @@ public static string WriteUsersGuide(string inputFileName)
return Path.GetFileName(usersGuideName); // return the relative path
}
}
}
}
48 changes: 29 additions & 19 deletions src/TraceEvent/Computers/TraceManagedProcess.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3175,40 +3175,40 @@ private void ConvertMarkTimes()

if (PerHeapMarkTimes != null)
{
List<(MarkRootType, double)> perRootMarkTime = new List<(MarkRootType, double)>((int)MarkRootType.MarkMax);

foreach (KeyValuePair<int, MarkInfo> item in PerHeapMarkTimes)
{
if (item.Value.MarkTimes[(int)MarkRootType.MarkSizedRef] == 0.0)
// Accumulate all the times that have a corresponding mark event.
for (int i = 0; i < item.Value.MarkTimes.Length; i++)
{
item.Value.MarkTimes[(int)MarkRootType.MarkSizedRef] = StartRelativeMSec;
if (item.Value.MarkTimes[i] != -1)
{
perRootMarkTime.Add(((MarkRootType)i, item.Value.MarkTimes[i]));
}
}

if (item.Value.MarkTimes[(int)MarkRootType.MarkOverflow] > StartRelativeMSec)
// Sort the perRootMarkTime in place so we can accumulate the times.
perRootMarkTime.Sort((first, second) => first.Item2.CompareTo(second.Item2));

for (int orderedDataIdx = 0; orderedDataIdx < perRootMarkTime.Count; orderedDataIdx++)
{
if (item.Value.MarkTimes[(int)MarkRootType.MarkOlder] == 0.0)
var orderedItem = perRootMarkTime[orderedDataIdx];
if (orderedDataIdx == 0)
{
item.Value.MarkTimes[(int)MarkRootType.MarkOverflow] -= item.Value.MarkTimes[(int)MarkRootType.MarkOlder];
item.Value.MarkTimes[(int)orderedItem.Item1] = orderedItem.Item2 - StartRelativeMSec;
}
else
{
item.Value.MarkTimes[(int)MarkRootType.MarkOverflow] -= item.Value.MarkTimes[(int)MarkRootType.MarkHandles];
var prevItem = perRootMarkTime[orderedDataIdx - 1];
item.Value.MarkTimes[(int)orderedItem.Item1] = orderedItem.Item2 - prevItem.Item2;
}
}

if (Generation == 2)
{
item.Value.MarkTimes[(int)MarkRootType.MarkOlder] = 0;
}
else
{
item.Value.MarkTimes[(int)MarkRootType.MarkOlder] -= item.Value.MarkTimes[(int)MarkRootType.MarkHandles];
}

item.Value.MarkTimes[(int)MarkRootType.MarkHandles] -= item.Value.MarkTimes[(int)MarkRootType.MarkFQ];
item.Value.MarkTimes[(int)MarkRootType.MarkFQ] -= item.Value.MarkTimes[(int)MarkRootType.MarkStack];
item.Value.MarkTimes[(int)MarkRootType.MarkStack] -= item.Value.MarkTimes[(int)MarkRootType.MarkSizedRef];
item.Value.MarkTimes[(int)MarkRootType.MarkSizedRef] -= StartRelativeMSec;
perRootMarkTime.Clear();
}
}

fMarkTimesConverted = true;
}

Expand Down Expand Up @@ -3702,9 +3702,19 @@ public class MarkInfo
public MarkInfo(bool initPromoted = true)
{
MarkTimes = new double[(int)MarkRootType.MarkMax];

for (int i = 0; i < MarkTimes.Length; i++)
{
MarkTimes[i] = -1;
}

if (initPromoted)
{
MarkPromoted = new long[(int)MarkRootType.MarkMax];
for (int i = 0; i < MarkPromoted.Length; i++)
{
MarkPromoted[i] = -1;
}
}
}
};
Expand Down