From 12ef1dab52a499ffd2a426fb8b1a4912f84d1001 Mon Sep 17 00:00:00 2001 From: Bruno Garcia Date: Sat, 7 Jun 2025 18:16:01 -0400 Subject: [PATCH] gcdump reading experiment --- src/FastSerialization/FastSerialization.cs | 14 +++++++++++++ src/FastSerialization/FunctorComparer`1.cs | 1 + src/FastSerialization/GrowableArray.cs | 3 ++- .../MemoryMappedFileStreamReader.cs | 9 +++++++-- .../SegmentedDictionary/HashHelpers.cs | 3 ++- .../SegmentedDictionary.cs | 3 ++- .../SegmentedDictionary/ThrowHelper.cs | 3 ++- src/FastSerialization/SegmentedList.cs | 3 ++- .../SegmentedMemoryStreamReader.cs | 5 +++-- .../SegmentedMemoryStreamWriter.cs | 5 +++-- src/FastSerialization/StreamReaderWriter.cs | 1 + src/HeapDump/CollectionMetadata.cs | 3 ++- src/HeapDump/GCHeapDump.cs | 14 +++++++++---- src/HeapDump/HeapDumpException.cs | 2 ++ src/HeapDumpCommon/DotNetHeapInfo.cs | 1 + src/MemoryGraph/MemoryGraph.cs | 12 +++++++---- src/MemoryGraph/graph.cs | 20 ++++++++++--------- src/Utilities/XmlUtilities.cs | 3 +++ 18 files changed, 76 insertions(+), 29 deletions(-) diff --git a/src/FastSerialization/FastSerialization.cs b/src/FastSerialization/FastSerialization.cs index 5967b11a5..bf1d71c32 100644 --- a/src/FastSerialization/FastSerialization.cs +++ b/src/FastSerialization/FastSerialization.cs @@ -1,3 +1,4 @@ +#nullable disable // Copyright (c) Microsoft Corporation. All rights reserved. /* This file is best viewed using outline mode (Ctrl-M Ctrl-O) */ // This program uses code hyperlinks available as part of the HyperAddin Visual Studio plug-in. @@ -846,7 +847,9 @@ public void Log(string str) { if (log == null) { +#pragma warning disable SN0001 log = File.CreateText("log.serialize.xml"); +#pragma warning restore SN0001 } log.WriteLine(str); @@ -1132,7 +1135,10 @@ public string GetEntryTypeName() objType = (SerializationType)ReadObject(); } } +#pragma warning disable RCS1075 + // ReSharper disable once EmptyGeneralCatchClause catch (Exception) { } +#pragma warning restore RCS1075 reader.Goto(origPosition); if (objType == null) { @@ -1861,7 +1867,9 @@ public void Log(string str) { if (log == null) { +#pragma warning disable SN0001 log = File.CreateText("log.deserialize.xml"); +#pragma warning restore SN0001 } log.WriteLine(str); @@ -1992,7 +2000,9 @@ internal Func GetFactory(string fullName) } else { +#pragma warning disable IL2057 type = Type.GetType(fullName); +#pragma warning restore IL2057 } if (type == null) @@ -2014,7 +2024,9 @@ internal Func GetFactory(string fullName) // Factory of last resort. try { +#pragma warning disable IL2072 return (IFastSerializable)Activator.CreateInstance(type); +#pragma warning restore IL2072 } catch (MissingMethodException) { @@ -2427,7 +2439,9 @@ interface IFastSerializableVersion #if FASTSERIALIZATION_PUBLIC public #endif +#pragma warning disable RCS1194 class SerializationException : Exception +#pragma warning restore RCS1194 { /// /// Thown when a error occurs in serialization. diff --git a/src/FastSerialization/FunctorComparer`1.cs b/src/FastSerialization/FunctorComparer`1.cs index 872eb68d4..46e4cac39 100644 --- a/src/FastSerialization/FunctorComparer`1.cs +++ b/src/FastSerialization/FunctorComparer`1.cs @@ -4,6 +4,7 @@ // This program uses code hyperlinks available as part of the HyperAddin Visual Studio plug-in. // It is available from http://www.codeplex.com/hyperAddin // +#nullable disable namespace System.Collections.Generic { diff --git a/src/FastSerialization/GrowableArray.cs b/src/FastSerialization/GrowableArray.cs index b26d5ec92..ea75bcca6 100644 --- a/src/FastSerialization/GrowableArray.cs +++ b/src/FastSerialization/GrowableArray.cs @@ -1,4 +1,5 @@ -using System.Diagnostics; +#nullable disable +using System.Diagnostics; // Copyright (c) Microsoft Corporation. All rights reserved. // This file is best viewed using outline mode (Ctrl-M Ctrl-O) // diff --git a/src/FastSerialization/MemoryMappedFileStreamReader.cs b/src/FastSerialization/MemoryMappedFileStreamReader.cs index a7b14aa6c..0f410aca0 100644 --- a/src/FastSerialization/MemoryMappedFileStreamReader.cs +++ b/src/FastSerialization/MemoryMappedFileStreamReader.cs @@ -1,4 +1,5 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. +#nullable disable +// Copyright (c) Microsoft Corporation. All rights reserved. // This file is best viewed using outline mode (Ctrl-M Ctrl-O) // // This program uses code hyperlinks available as part of the HyperAddin Visual Studio plug-in. @@ -15,7 +16,7 @@ namespace FastSerialization { - public class MemoryMappedFileStreamReader : IStreamReader + internal class MemoryMappedFileStreamReader : IStreamReader { const int BlockCopyCapacity = 10 * 1024 * 1024; @@ -30,7 +31,9 @@ public class MemoryMappedFileStreamReader : IStreamReader private long _offset; public MemoryMappedFileStreamReader(string mapName, long length) +#pragma warning disable CA1416 : this(MemoryMappedFile.OpenExisting(mapName, MemoryMappedFileRights.Read), length, leaveOpen: false) +#pragma warning restore CA1416 { } @@ -55,7 +58,9 @@ public MemoryMappedFileStreamReader(MemoryMappedFile file, long length, bool lea public static MemoryMappedFileStreamReader CreateFromFile(string path) { +#pragma warning disable SN0001 // - Won't run on Switch long capacity = new FileInfo(path).Length; +#pragma warning restore SN0001 MemoryMappedFile file = MemoryMappedFile.CreateFromFile(path, FileMode.Open, Guid.NewGuid().ToString("N"), capacity, MemoryMappedFileAccess.Read); return new MemoryMappedFileStreamReader(file, capacity, leaveOpen: false); } diff --git a/src/FastSerialization/SegmentedDictionary/HashHelpers.cs b/src/FastSerialization/SegmentedDictionary/HashHelpers.cs index bb07be670..453fdf11c 100644 --- a/src/FastSerialization/SegmentedDictionary/HashHelpers.cs +++ b/src/FastSerialization/SegmentedDictionary/HashHelpers.cs @@ -1,4 +1,5 @@ -// Tests copied from dotnet/roslyn repo. Original source code can be found here: +#nullable disable +// Tests copied from dotnet/roslyn repo. Original source code can be found here: // https://github.com/dotnet/roslyn/blob/main/src/Dependencies/Collections/Internal/HashHelpers.cs using System; diff --git a/src/FastSerialization/SegmentedDictionary/SegmentedDictionary.cs b/src/FastSerialization/SegmentedDictionary/SegmentedDictionary.cs index c1254f543..0ceb29762 100644 --- a/src/FastSerialization/SegmentedDictionary/SegmentedDictionary.cs +++ b/src/FastSerialization/SegmentedDictionary/SegmentedDictionary.cs @@ -1,4 +1,5 @@ -using System.Diagnostics; +#nullable disable +using System.Diagnostics; using System.Runtime.CompilerServices; using Microsoft.Diagnostics.FastSerialization; diff --git a/src/FastSerialization/SegmentedDictionary/ThrowHelper.cs b/src/FastSerialization/SegmentedDictionary/ThrowHelper.cs index 72594c0c4..0ff015c7d 100644 --- a/src/FastSerialization/SegmentedDictionary/ThrowHelper.cs +++ b/src/FastSerialization/SegmentedDictionary/ThrowHelper.cs @@ -1,4 +1,5 @@ -// Tests copied from dotnet/roslyn repo. Original source code can be found here: +#nullable disable +// Tests copied from dotnet/roslyn repo. Original source code can be found here: // https://github.com/dotnet/roslyn/blob/main/src/Dependencies/Collections/Internal/ThrowHelper.cs using System; diff --git a/src/FastSerialization/SegmentedList.cs b/src/FastSerialization/SegmentedList.cs index 4326f3766..0436fb57c 100644 --- a/src/FastSerialization/SegmentedList.cs +++ b/src/FastSerialization/SegmentedList.cs @@ -1,4 +1,5 @@ -using System.Diagnostics; +#nullable disable +using System.Diagnostics; // --------------------------------------------------------------------------- // diff --git a/src/FastSerialization/SegmentedMemoryStreamReader.cs b/src/FastSerialization/SegmentedMemoryStreamReader.cs index 1cb94d244..4dab581b6 100644 --- a/src/FastSerialization/SegmentedMemoryStreamReader.cs +++ b/src/FastSerialization/SegmentedMemoryStreamReader.cs @@ -1,11 +1,12 @@ -using System; +#nullable disable +using System; using System.Collections.Generic; using System.Diagnostics; using System.Text; namespace FastSerialization { - public class SegmentedMemoryStreamReader + internal class SegmentedMemoryStreamReader { const int BlockCopyCapacity = 10 * 1024 * 1024; diff --git a/src/FastSerialization/SegmentedMemoryStreamWriter.cs b/src/FastSerialization/SegmentedMemoryStreamWriter.cs index e97783bad..78886e6d6 100644 --- a/src/FastSerialization/SegmentedMemoryStreamWriter.cs +++ b/src/FastSerialization/SegmentedMemoryStreamWriter.cs @@ -1,11 +1,12 @@ -using System; +#nullable disable +using System; using System.Collections.Generic; using System.Diagnostics; using System.IO; namespace FastSerialization { - public class SegmentedMemoryStreamWriter + internal class SegmentedMemoryStreamWriter { public SegmentedMemoryStreamWriter(SerializationConfiguration config = null) : this(64, config) { } public SegmentedMemoryStreamWriter(long initialSize, SerializationConfiguration config = null) diff --git a/src/FastSerialization/StreamReaderWriter.cs b/src/FastSerialization/StreamReaderWriter.cs index 2aa7efea6..c0f32097b 100644 --- a/src/FastSerialization/StreamReaderWriter.cs +++ b/src/FastSerialization/StreamReaderWriter.cs @@ -8,6 +8,7 @@ using System.Diagnostics; using System.IO; using System.Text; // For StringBuilder. +#nullable disable namespace FastSerialization { diff --git a/src/HeapDump/CollectionMetadata.cs b/src/HeapDump/CollectionMetadata.cs index 2d5c1f22e..9dbbc761a 100644 --- a/src/HeapDump/CollectionMetadata.cs +++ b/src/HeapDump/CollectionMetadata.cs @@ -1,4 +1,5 @@ -namespace Microsoft.Diagnostics.HeapDump +#nullable disable +namespace Microsoft.Diagnostics.HeapDump { using System.Collections.Generic; diff --git a/src/HeapDump/GCHeapDump.cs b/src/HeapDump/GCHeapDump.cs index 9c9405d03..cd943ec8f 100644 --- a/src/HeapDump/GCHeapDump.cs +++ b/src/HeapDump/GCHeapDump.cs @@ -1,20 +1,21 @@ -using FastSerialization; +#nullable disable +using FastSerialization; using Graphs; -using Microsoft.Diagnostics.Utilities; using System; using System.Collections.Generic; using System.Diagnostics; using System.IO; using System.Text.RegularExpressions; using System.Xml; +using Microsoft.Diagnostics.Utilities; using Address = System.UInt64; - +using SerializationException = FastSerialization.SerializationException; /// /// Represents a .GCDump file. You can open it for reading with the construtor /// and you can write one with WriteMemoryGraph /// -public class GCHeapDump : IFastSerializable, IFastSerializableVersion +internal class GCHeapDump : IFastSerializable, IFastSerializableVersion { public GCHeapDump(string inputFileName) : this(new Deserializer(inputFileName, new SerializationConfiguration() { StreamLabelWidth = StreamLabelWidth.FourBytes })) @@ -166,7 +167,10 @@ public static Dictionary GetProcessesWithGCHeaps() } } } + // ReSharper disable once EmptyGeneralCatchClause +#pragma warning disable RCS1075 catch (Exception) +#pragma warning restore RCS1075 { } if (info.UsesJavaScript || info.UsesDotNet) @@ -709,7 +713,9 @@ void IFastSerializable.FromStream(Deserializer deserializer) /// /// /// +#pragma warning disable RCS1102 internal class XmlGcHeapDump +#pragma warning restore RCS1102 { public static GCHeapDump ReadGCHeapDumpFromXml(string fileName) { diff --git a/src/HeapDump/HeapDumpException.cs b/src/HeapDump/HeapDumpException.cs index be5a255b0..cac759e06 100644 --- a/src/HeapDump/HeapDumpException.cs +++ b/src/HeapDump/HeapDumpException.cs @@ -2,7 +2,9 @@ namespace Microsoft.Diagnostics.HeapDump { +#pragma warning disable RCS1194 public class HeapDumpException : ApplicationException +#pragma warning restore RCS1194 { public HeapDumpException(string message, HR hr) : base(message) diff --git a/src/HeapDumpCommon/DotNetHeapInfo.cs b/src/HeapDumpCommon/DotNetHeapInfo.cs index 8f71b0808..8db6345e7 100644 --- a/src/HeapDumpCommon/DotNetHeapInfo.cs +++ b/src/HeapDumpCommon/DotNetHeapInfo.cs @@ -1,3 +1,4 @@ +#nullable disable using FastSerialization; using System.Collections.Generic; using Address = System.UInt64; diff --git a/src/MemoryGraph/MemoryGraph.cs b/src/MemoryGraph/MemoryGraph.cs index 0ea680875..f6cd764b8 100644 --- a/src/MemoryGraph/MemoryGraph.cs +++ b/src/MemoryGraph/MemoryGraph.cs @@ -1,11 +1,12 @@ -using FastSerialization; +#nullable disable +using FastSerialization; using System.Collections.Generic; using System.Diagnostics; using Address = System.UInt64; namespace Graphs { - public class MemoryGraph : Graph, IFastSerializable + internal class MemoryGraph : Graph, IFastSerializable { public MemoryGraph(int expectedSize, bool isVeryLargeGraph = false) : base(expectedSize, isVeryLargeGraph) @@ -32,7 +33,10 @@ public void WriteAsBinaryFile(string outputFileName) public static MemoryGraph ReadFromBinaryFile(string inputFileName) { Deserializer deserializer = new Deserializer(inputFileName); + // ReSharper disable once RedundantNameQualifier +#pragma warning disable IL2057 deserializer.TypeResolver = typeName => System.Type.GetType(typeName); // resolve types in this assembly (and mscorlib) +#pragma warning restore IL2057 deserializer.RegisterFactory(typeof(MemoryGraph), delegate () { return new MemoryGraph(1); }); deserializer.RegisterFactory(typeof(Graphs.Module), delegate () { return new Graphs.Module(0); }); return (MemoryGraph)deserializer.GetEntryObject(); @@ -172,7 +176,7 @@ void IFastSerializable.FromStream(Deserializer deserializer) /// /// Support class for code:MemoryGraph /// - public class MemoryNode : Node + internal class MemoryNode : Node { public Address Address { get { return m_memoryGraph.GetAddress(Index); } } #region private @@ -201,7 +205,7 @@ public override void WriteXml(System.IO.TextWriter writer, bool includeChildren /// you create the node. Instead you can keep adding children to it incrementally /// and when you are done you call Build() which finalizes it (and all its children) /// - public class MemoryNodeBuilder + internal class MemoryNodeBuilder { public MemoryNodeBuilder(MemoryGraph graph, string typeName, string moduleName = null, NodeIndex nodeIndex = NodeIndex.Invalid) { diff --git a/src/MemoryGraph/graph.cs b/src/MemoryGraph/graph.cs index 305c3b25a..bdd9836ec 100644 --- a/src/MemoryGraph/graph.cs +++ b/src/MemoryGraph/graph.cs @@ -1,3 +1,4 @@ +#nullable disable using FastSerialization; // For IStreamReader using Graphs; using Microsoft.Diagnostics.Utilities; @@ -63,7 +64,7 @@ namespace Graphs /// see code:Graph.SizeOfGraphDescription to determine the overhead for any particular graph. /// /// - public class Graph : IFastSerializable, IFastSerializableVersion + internal class Graph : IFastSerializable, IFastSerializableVersion { /// /// Given an arbitrary code:NodeIndex that identifies the node, Get a code:Node object. @@ -678,7 +679,7 @@ public void FromStream(Deserializer deserializer) /// /// A node implicitly knows where the 'next' child is (that is it is an iterator). /// - public class Node + internal class Node { public int Size { @@ -935,7 +936,7 @@ internal static void WriteCompressedInt(SegmentedMemoryStreamWriter writer, int /// /// Represents the nodeId of a particular node in the graph. /// - public class NodeType + internal class NodeType { /// /// Every nodeId has a name, this is it. @@ -1050,7 +1051,7 @@ protected internal NodeType(Graph graph) /// /// Holds all interesting data about a module (in particular enough to look up PDB information) /// - public class Module : IFastSerializable + internal class Module : IFastSerializable { /// /// Create new module. You must have at least a image base. Everything else is optional. @@ -1134,7 +1135,7 @@ public enum NodeTypeIndex { Invalid = -1 } /// /// Stuff that is useful but does not need to be in Graph. /// - public static class GraphUtils + internal static class GraphUtils { /// /// Write the graph as XML to a string and return it (useful for debugging small graphs). @@ -1353,7 +1354,8 @@ public static List NodesOfType(this Graph graph, string regExpression /// /// Thus this is a fairly expensive thing to create. /// -public class RefGraph +#nullable disable +internal class RefGraph { public RefGraph(Graph graph) { @@ -1514,7 +1516,7 @@ internal struct RefElem #endregion } -public class RefNode +internal class RefNode { /// /// Gets the first child for the node. Will return null if there are no children. @@ -1649,7 +1651,7 @@ internal RefNode(RefGraph refGraph) /// /// This is just a first cut... /// -public class SpanningTree +internal class SpanningTree { public SpanningTree(Graph graph, TextWriter log) { @@ -2137,7 +2139,7 @@ private void CheckInvariant() /// 2) We try hard to keep scale each object type by the count by which the whole /// graph was reduced. /// -public class GraphSampler +internal class GraphSampler { /// /// diff --git a/src/Utilities/XmlUtilities.cs b/src/Utilities/XmlUtilities.cs index 3e3a091f0..47f5054e6 100644 --- a/src/Utilities/XmlUtilities.cs +++ b/src/Utilities/XmlUtilities.cs @@ -4,6 +4,7 @@ // This program uses code hyperlinks available as part of the HyperAddin Visual Studio plug-in. // It is available from http://www.codeplex.com/hyperAddin // +#nullable disable using System; using System.Diagnostics; using System.Text; @@ -17,7 +18,9 @@ namespace Microsoft.Diagnostics.Utilities #if UTILITIES_PUBLIC public #endif +#pragma warning disable RCS1102 class XmlUtilities +#pragma warning restore RCS1102 { /// /// Given an XML element, remove the closing operator for it, so you can add new child elements to it by concatination.