Skip to content
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

Update files cloned from PerfView #3255

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using Graphs;
using Graphs;
using Microsoft.Diagnostics.Tracing;
using Microsoft.Diagnostics.Tracing.Parsers;
using Microsoft.Diagnostics.Tracing.Parsers.Clr;
Expand Down Expand Up @@ -182,6 +182,12 @@ internal void SetupCallbacks(MemoryGraph memoryGraph, TraceEventDispatcher sourc
}
};

source.Clr.GCGenAwareStart += delegate (GenAwareBeginTraceData data)
{
m_seenStart = true;
m_ignoreEvents = false;
};

source.Clr.GCStart += delegate (GCStartTraceData data)
{
// If this GC is not part of a heap dump, ignore it.
Expand Down Expand Up @@ -231,8 +237,6 @@ internal void SetupCallbacks(MemoryGraph memoryGraph, TraceEventDispatcher sourc
}
};



source.Clr.GCStop += delegate (GCEndTraceData data)
{
if (m_ignoreEvents || data.ProcessID != m_processId)
Expand Down Expand Up @@ -262,6 +266,17 @@ internal void SetupCallbacks(MemoryGraph memoryGraph, TraceEventDispatcher sourc
}
};

source.Clr.GCGenAwareEnd += delegate (GenAwareEndTraceData data)
{
m_ignoreEvents = true;
if (m_nodeBlocks.Count == 0 && m_typeBlocks.Count == 0 && m_edgeBlocks.Count == 0)
{
m_log.WriteLine("Found no node events, looking for another GC");
m_seenStart = false;
return;
}
};

source.Clr.TypeBulkType += delegate (GCBulkTypeTraceData data)
{
// Don't check m_ignoreEvents here, as BulkType events can be emitted by other events...such as the GC allocation event.
Expand Down Expand Up @@ -474,6 +489,9 @@ internal void SetupCallbacks(MemoryGraph memoryGraph, TraceEventDispatcher sourc
case 3:
segment.Gen3End = end;
break;
case 4:
segment.Gen4End = end;
break;
default:
throw new Exception("Invalid generation in GCGenerationRangeTraceData");
}
Expand Down
21 changes: 19 additions & 2 deletions src/Tools/dotnet-gcdump/DotNetHeapDump/DotNetHeapInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,11 @@ public int GenerationFor(Address obj)
}
}

if (obj < m_lastSegment.Gen4End)
{
return 4;
}

if (obj < m_lastSegment.Gen3End)
{
return 3;
Expand Down Expand Up @@ -107,14 +112,21 @@ void IFastSerializable.FromStream(Deserializer deserializer)
#endregion
}

public class GCHeapDumpSegment : IFastSerializable
public class GCHeapDumpSegment : IFastSerializable, IFastSerializableVersion
{
public Address Start { get; internal set; }
public Address End { get; internal set; }
public Address Gen0End { get; internal set; }
public Address Gen1End { get; internal set; }
public Address Gen2End { get; internal set; }
public Address Gen3End { get; internal set; }
public Address Gen4End { get; internal set; }

public int Version => 1;

public int MinimumVersionCanRead => 0;

public int MinimumReaderVersion => 1;

#region private
void IFastSerializable.ToStream(Serializer serializer)
Expand All @@ -125,6 +137,7 @@ void IFastSerializable.ToStream(Serializer serializer)
serializer.Write((long)Gen1End);
serializer.Write((long)Gen2End);
serializer.Write((long)Gen3End);
serializer.Write((long)Gen4End);
}

void IFastSerializable.FromStream(Deserializer deserializer)
Expand All @@ -135,6 +148,10 @@ void IFastSerializable.FromStream(Deserializer deserializer)
Gen1End = (Address)deserializer.ReadInt64();
Gen2End = (Address)deserializer.ReadInt64();
Gen3End = (Address)deserializer.ReadInt64();
if (deserializer.VersionBeingRead >= 1)
{
Gen4End = (Address)deserializer.ReadInt64();
}
}
#endregion
}
}
18 changes: 9 additions & 9 deletions src/Tools/dotnet-gcdump/DotNetHeapDump/GCHeapDump.cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
using FastSerialization;
using FastSerialization;
using Graphs;
using Microsoft.Diagnostics.Utilities;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Security;
using System.Text.RegularExpressions;
using System.Xml;
using Address = System.UInt64;
Expand All @@ -18,11 +17,11 @@
public class GCHeapDump : IFastSerializable, IFastSerializableVersion
{
public GCHeapDump(string inputFileName) :
this(new Deserializer(inputFileName))
this(new Deserializer(inputFileName, new SerializationConfiguration() { StreamLabelWidth = StreamLabelWidth.FourBytes }))
{ }

public GCHeapDump(Stream inputStream, string streamName) :
this(new Deserializer(inputStream, streamName))
this(new Deserializer(inputStream, streamName, new SerializationConfiguration() { StreamLabelWidth = StreamLabelWidth.FourBytes }))
{ }

/// <summary>
Expand Down Expand Up @@ -110,7 +109,7 @@ public static Dictionary<int, ProcessInfo> GetProcessesWithGCHeaps()
var ret = new Dictionary<int, ProcessInfo>();

// Do the 64 bit processes first, then do us
if (System.Environment.Is64BitOperatingSystem && !System.Environment.Is64BitProcess)
if (EnvironmentUtilities.Is64BitOperatingSystem && !EnvironmentUtilities.Is64BitProcess)
{
GetProcessesWithGCHeapsFromHeapDump(ret);
}
Expand Down Expand Up @@ -193,7 +192,7 @@ public static Dictionary<int, ProcessInfo> GetProcessesWithGCHeaps()
private void Write(string outputFileName)
{
Debug.Assert(MemoryGraph != null);
var serializer = new Serializer(outputFileName, this);
var serializer = new Serializer(new IOStreamStreamWriter(outputFileName, config: new SerializationConfiguration() { StreamLabelWidth = StreamLabelWidth.FourBytes }), this);
serializer.Close();
}

Expand Down Expand Up @@ -848,7 +847,7 @@ internal static void WriteGCDumpToXml(GCHeapDump gcDump, StreamWriter writer)
writer.WriteLine("<TimeCollected>{0}</TimeCollected>", gcDump.TimeCollected);
if (!string.IsNullOrWhiteSpace(gcDump.CollectionLog))
{
writer.WriteLine("<CollectionLog>{0}</CollectionLog>", SecurityElement.Escape(gcDump.CollectionLog));
writer.WriteLine("<CollectionLog>{0}</CollectionLog>", XmlUtilities.XmlEscape(gcDump.CollectionLog));
}

if (!string.IsNullOrWhiteSpace(gcDump.MachineName))
Expand All @@ -858,7 +857,7 @@ internal static void WriteGCDumpToXml(GCHeapDump gcDump, StreamWriter writer)

if (!string.IsNullOrWhiteSpace(gcDump.ProcessName))
{
writer.WriteLine("<ProcessName>{0}</ProcessName>", SecurityElement.Escape(gcDump.ProcessName));
writer.WriteLine("<ProcessName>{0}</ProcessName>", XmlUtilities.XmlEscape(gcDump.ProcessName));
}

if (gcDump.ProcessID != 0)
Expand All @@ -883,7 +882,7 @@ internal static void WriteGCDumpToXml(GCHeapDump gcDump, StreamWriter writer)
for (int i = 0; i < gcDump.CountMultipliersByType.Length; i++)
{
writer.WriteLine("<CountMultipliers TypeIndex=\"{0}\" TypeName=\"{1}\" Value=\"{2:f4}\"/>", i,
SecurityElement.Escape(gcDump.MemoryGraph.GetType((NodeTypeIndex)i, typeStorage).Name),
XmlUtilities.XmlEscape(gcDump.MemoryGraph.GetType((NodeTypeIndex)i, typeStorage).Name),
gcDump.CountMultipliersByType[i]);
}

Expand Down Expand Up @@ -1087,3 +1086,4 @@ private static float FetchFloat(XmlReader reader, string attributeName, float de


}

Loading