Skip to content

gcdump reading experiment #2

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

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
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
14 changes: 14 additions & 0 deletions src/FastSerialization/FastSerialization.cs
Original file line number Diff line number Diff line change
@@ -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.
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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)
{
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -1992,7 +2000,9 @@ internal Func<IFastSerializable> GetFactory(string fullName)
}
else
{
#pragma warning disable IL2057
type = Type.GetType(fullName);
#pragma warning restore IL2057
}

if (type == null)
Expand All @@ -2014,7 +2024,9 @@ internal Func<IFastSerializable> GetFactory(string fullName)
// Factory of last resort.
try
{
#pragma warning disable IL2072
return (IFastSerializable)Activator.CreateInstance(type);
#pragma warning restore IL2072
}
catch (MissingMethodException)
{
Expand Down Expand Up @@ -2427,7 +2439,9 @@ interface IFastSerializableVersion
#if FASTSERIALIZATION_PUBLIC
public
#endif
#pragma warning disable RCS1194
class SerializationException : Exception
#pragma warning restore RCS1194
{
/// <summary>
/// Thown when a error occurs in serialization.
Expand Down
1 change: 1 addition & 0 deletions src/FastSerialization/FunctorComparer`1.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down
3 changes: 2 additions & 1 deletion src/FastSerialization/GrowableArray.cs
Original file line number Diff line number Diff line change
@@ -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)
//
Expand Down
9 changes: 7 additions & 2 deletions src/FastSerialization/MemoryMappedFileStreamReader.cs
Original file line number Diff line number Diff line change
@@ -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.
Expand All @@ -15,7 +16,7 @@

namespace FastSerialization
{
public class MemoryMappedFileStreamReader : IStreamReader
internal class MemoryMappedFileStreamReader : IStreamReader
{
const int BlockCopyCapacity = 10 * 1024 * 1024;

Expand All @@ -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
{
}

Expand All @@ -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);
}
Expand Down
3 changes: 2 additions & 1 deletion src/FastSerialization/SegmentedDictionary/HashHelpers.cs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Diagnostics;
#nullable disable
using System.Diagnostics;
using System.Runtime.CompilerServices;
using Microsoft.Diagnostics.FastSerialization;

Expand Down
3 changes: 2 additions & 1 deletion src/FastSerialization/SegmentedDictionary/ThrowHelper.cs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
3 changes: 2 additions & 1 deletion src/FastSerialization/SegmentedList.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Diagnostics;
#nullable disable
using System.Diagnostics;

// ---------------------------------------------------------------------------
// <copyright file="SegmentedList.cs" company="Microsoft">
Expand Down
5 changes: 3 additions & 2 deletions src/FastSerialization/SegmentedMemoryStreamReader.cs
Original file line number Diff line number Diff line change
@@ -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;

Expand Down
5 changes: 3 additions & 2 deletions src/FastSerialization/SegmentedMemoryStreamWriter.cs
Original file line number Diff line number Diff line change
@@ -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)
Expand Down
1 change: 1 addition & 0 deletions src/FastSerialization/StreamReaderWriter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
using System.Diagnostics;
using System.IO;
using System.Text; // For StringBuilder.
#nullable disable

namespace FastSerialization
{
Expand Down
3 changes: 2 additions & 1 deletion src/HeapDump/CollectionMetadata.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
namespace Microsoft.Diagnostics.HeapDump
#nullable disable
namespace Microsoft.Diagnostics.HeapDump
{
using System.Collections.Generic;

Expand Down
14 changes: 10 additions & 4 deletions src/HeapDump/GCHeapDump.cs
Original file line number Diff line number Diff line change
@@ -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;

/// <summary>
/// Represents a .GCDump file. You can open it for reading with the construtor
/// and you can write one with WriteMemoryGraph
/// </summary>
public class GCHeapDump : IFastSerializable, IFastSerializableVersion
internal class GCHeapDump : IFastSerializable, IFastSerializableVersion
{
public GCHeapDump(string inputFileName) :
this(new Deserializer(inputFileName, new SerializationConfiguration() { StreamLabelWidth = StreamLabelWidth.FourBytes }))
Expand Down Expand Up @@ -166,7 +167,10 @@ public static Dictionary<int, ProcessInfo> GetProcessesWithGCHeaps()
}
}
}
// ReSharper disable once EmptyGeneralCatchClause
#pragma warning disable RCS1075
catch (Exception)
#pragma warning restore RCS1075
{
}
if (info.UsesJavaScript || info.UsesDotNet)
Expand Down Expand Up @@ -709,7 +713,9 @@ void IFastSerializable.FromStream(Deserializer deserializer)
/// </graph>
///
/// </summary>
#pragma warning disable RCS1102
internal class XmlGcHeapDump
#pragma warning restore RCS1102
{
public static GCHeapDump ReadGCHeapDumpFromXml(string fileName)
{
Expand Down
2 changes: 2 additions & 0 deletions src/HeapDump/HeapDumpException.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
1 change: 1 addition & 0 deletions src/HeapDumpCommon/DotNetHeapInfo.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#nullable disable
using FastSerialization;
using System.Collections.Generic;
using Address = System.UInt64;
Expand Down
12 changes: 8 additions & 4 deletions src/MemoryGraph/MemoryGraph.cs
Original file line number Diff line number Diff line change
@@ -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)
Expand All @@ -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();
Expand Down Expand Up @@ -172,7 +176,7 @@ void IFastSerializable.FromStream(Deserializer deserializer)
/// <summary>
/// Support class for code:MemoryGraph
/// </summary>
public class MemoryNode : Node
internal class MemoryNode : Node
{
public Address Address { get { return m_memoryGraph.GetAddress(Index); } }
#region private
Expand Down Expand Up @@ -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)
/// </summary>
public class MemoryNodeBuilder
internal class MemoryNodeBuilder
{
public MemoryNodeBuilder(MemoryGraph graph, string typeName, string moduleName = null, NodeIndex nodeIndex = NodeIndex.Invalid)
{
Expand Down
20 changes: 11 additions & 9 deletions src/MemoryGraph/graph.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#nullable disable
using FastSerialization; // For IStreamReader
using Graphs;
using Microsoft.Diagnostics.Utilities;
Expand Down Expand Up @@ -63,7 +64,7 @@ namespace Graphs
/// see code:Graph.SizeOfGraphDescription to determine the overhead for any particular graph.
///
/// </summary>
public class Graph : IFastSerializable, IFastSerializableVersion
internal class Graph : IFastSerializable, IFastSerializableVersion
{
/// <summary>
/// Given an arbitrary code:NodeIndex that identifies the node, Get a code:Node object.
Expand Down Expand Up @@ -678,7 +679,7 @@ public void FromStream(Deserializer deserializer)
///
/// A node implicitly knows where the 'next' child is (that is it is an iterator).
/// </summary>
public class Node
internal class Node
{
public int Size
{
Expand Down Expand Up @@ -935,7 +936,7 @@ internal static void WriteCompressedInt(SegmentedMemoryStreamWriter writer, int
/// <summary>
/// Represents the nodeId of a particular node in the graph.
/// </summary>
public class NodeType
internal class NodeType
{
/// <summary>
/// Every nodeId has a name, this is it.
Expand Down Expand Up @@ -1050,7 +1051,7 @@ protected internal NodeType(Graph graph)
/// <summary>
/// Holds all interesting data about a module (in particular enough to look up PDB information)
/// </summary>
public class Module : IFastSerializable
internal class Module : IFastSerializable
{
/// <summary>
/// Create new module. You must have at least a image base. Everything else is optional.
Expand Down Expand Up @@ -1134,7 +1135,7 @@ public enum NodeTypeIndex { Invalid = -1 }
/// <summary>
/// Stuff that is useful but does not need to be in Graph.
/// </summary>
public static class GraphUtils
internal static class GraphUtils
{
/// <summary>
/// Write the graph as XML to a string and return it (useful for debugging small graphs).
Expand Down Expand Up @@ -1353,7 +1354,8 @@ public static List<NodeIndex> NodesOfType(this Graph graph, string regExpression
///
/// Thus this is a fairly expensive thing to create.
/// </summary>
public class RefGraph
#nullable disable
internal class RefGraph
{
public RefGraph(Graph graph)
{
Expand Down Expand Up @@ -1514,7 +1516,7 @@ internal struct RefElem
#endregion
}

public class RefNode
internal class RefNode
{
/// <summary>
/// Gets the first child for the node. Will return null if there are no children.
Expand Down Expand Up @@ -1649,7 +1651,7 @@ internal RefNode(RefGraph refGraph)
///
/// This is just a first cut...
/// </summary>
public class SpanningTree
internal class SpanningTree
{
public SpanningTree(Graph graph, TextWriter log)
{
Expand Down Expand Up @@ -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.
/// </summary>
public class GraphSampler
internal class GraphSampler
{
/// <summary>
///
Expand Down
Loading