Skip to content

Commit

Permalink
Split model into multiple files
Browse files Browse the repository at this point in the history
  • Loading branch information
xoofx committed Dec 21, 2024
1 parent 4ad8e98 commit 9862b9f
Show file tree
Hide file tree
Showing 34 changed files with 1,285 additions and 903 deletions.
2 changes: 2 additions & 0 deletions src/Ultra.Core/DiagnosticsClientHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,15 @@ internal static class DiagnosticsClientHelper
/// <summary>
/// Wait for an available diagnostic endpoint to the runtime instance.
/// </summary>
/// <param name="client">The <see cref="DiagnosticsClient"/> instance.</param>
/// <param name="timeout">The amount of time to wait before cancelling the wait for the connection.</param>
[UnsafeAccessor(UnsafeAccessorKind.Method, Name = nameof(WaitForConnection))]
public static extern void WaitForConnection(this DiagnosticsClient client, TimeSpan timeout);

/// <summary>
/// Wait for an available diagnostic endpoint to the runtime instance.
/// </summary>
/// <param name="client">The <see cref="DiagnosticsClient"/> instance.</param>
/// <param name="token">The token to monitor for cancellation requests.</param>
/// <returns>
/// A task the completes when a diagnostic endpoint to the runtime instance becomes available.
Expand Down
31 changes: 31 additions & 0 deletions src/Ultra.Core/Model/Markers/GCAllocationTickTraceMarker.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
// Copyright (c) Alexandre Mutel. All rights reserved.
// Licensed under the BSD-Clause 2 license.
// See license.txt file in the project root for full license information.

namespace Ultra.Core.Model;

/// <summary>
/// Represents a garbage collection allocation tick profile marker.
/// </summary>
public record GCAllocationTickTraceMarker : UTraceMarker
{
/// <summary>
/// Gets or sets the amount of memory allocated.
/// </summary>
public long AllocationAmount { get; set; }

/// <summary>
/// Gets or sets the kind of allocation.
/// </summary>
public string? AllocationKind { get; set; }

/// <summary>
/// Gets or sets the type name of the allocated object.
/// </summary>
public string? TypeName { get; set; }

/// <summary>
/// Gets or sets the index of the heap where the allocation occurred.
/// </summary>
public int HeapIndex { get; set; }
}
96 changes: 96 additions & 0 deletions src/Ultra.Core/Model/Markers/GCHeapStatsTraceMarker.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
// Copyright (c) Alexandre Mutel. All rights reserved.
// Licensed under the BSD-Clause 2 license.
// See license.txt file in the project root for full license information.

namespace Ultra.Core.Model;

/// <summary>
/// Represents a garbage collection heap stats event marker payload for Firefox Profiler.
/// </summary>
public record GCHeapStatsTraceMarker : UTraceMarker
{
/// <summary>
/// Gets or sets the total heap size.
/// </summary>
public long TotalHeapSize { get; set; }

/// <summary>
/// Gets or sets the total promoted size.
/// </summary>
public long TotalPromoted { get; set; }

/// <summary>
/// Gets or sets the size of generation 0.
/// </summary>
public long GenerationSize0 { get; set; }

/// <summary>
/// Gets or sets the total promoted size of generation 0.
/// </summary>
public long TotalPromotedSize0 { get; set; }

/// <summary>
/// Gets or sets the size of generation 1.
/// </summary>
public long GenerationSize1 { get; set; }

/// <summary>
/// Gets or sets the total promoted size of generation 1.
/// </summary>
public long TotalPromotedSize1 { get; set; }

/// <summary>
/// Gets or sets the size of generation 2.
/// </summary>
public long GenerationSize2 { get; set; }

/// <summary>
/// Gets or sets the total promoted size of generation 2.
/// </summary>
public long TotalPromotedSize2 { get; set; }

/// <summary>
/// Gets or sets the size of generation 3.
/// </summary>
public long GenerationSize3 { get; set; }

/// <summary>
/// Gets or sets the total promoted size of generation 3.
/// </summary>
public long TotalPromotedSize3 { get; set; }

/// <summary>
/// Gets or sets the size of generation 4.
/// </summary>
public long GenerationSize4 { get; set; }

/// <summary>
/// Gets or sets the total promoted size of generation 4.
/// </summary>
public long TotalPromotedSize4 { get; set; }

/// <summary>
/// Gets or sets the finalization promoted size.
/// </summary>
public long FinalizationPromotedSize { get; set; }

/// <summary>
/// Gets or sets the finalization promoted count.
/// </summary>
public long FinalizationPromotedCount { get; set; }

/// <summary>
/// Gets or sets the pinned object count.
/// </summary>
public int PinnedObjectCount { get; set; }

/// <summary>
/// Gets or sets the sink block count.
/// </summary>
public int SinkBlockCount { get; set; }

/// <summary>
/// Gets or sets the GC handle count.
/// </summary>
public int GCHandleCount { get; set; }
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
// Copyright (c) Alexandre Mutel. All rights reserved.
// Licensed under the BSD-Clause 2 license.
// See license.txt file in the project root for full license information.

namespace Ultra.Core.Model;

/// <summary>
/// Represents an event that indicates the .NET garbage collector has restarted the execution engine.
/// </summary>
public record GCRestartExecutionEngineTraceMarker : UTraceMarker;
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
// Copyright (c) Alexandre Mutel. All rights reserved.
// Licensed under the BSD-Clause 2 license.
// See license.txt file in the project root for full license information.

namespace Ultra.Core.Model;

/// <summary>
/// Represents an event that marks the suspension of the execution engine by the garbage collector.
/// </summary>
public record GCSuspendExecutionEngineTraceMarker : UTraceMarker
{
/// <summary>
/// Gets or sets the reason for the suspension.
/// </summary>
public string? Reason { get; set; }

/// <summary>
/// Gets or sets the count of suspensions.
/// </summary>
public int Count { get; set; }
}
31 changes: 31 additions & 0 deletions src/Ultra.Core/Model/Markers/GCTraceMarker.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
// Copyright (c) Alexandre Mutel. All rights reserved.
// Licensed under the BSD-Clause 2 license.
// See license.txt file in the project root for full license information.

namespace Ultra.Core.Model;

/// <summary>
/// Represents a garbage collection event marker payload for Firefox Profiler.
/// </summary>
public record GCTraceMarker : UTraceMarker
{
/// <summary>
/// Gets or sets the reason for the garbage collection.
/// </summary>
public string? Reason { get; set; }

/// <summary>
/// Gets or sets the count of garbage collections.
/// </summary>
public int Count { get; set; }

/// <summary>
/// Gets or sets the depth of the garbage collection.
/// </summary>
public int Depth { get; set; }

/// <summary>
/// Gets or sets the type of garbage collection.
/// </summary>
public string? GCType { get; set; }
}
21 changes: 21 additions & 0 deletions src/Ultra.Core/Model/Markers/JitCompileTraceMarker.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
// Copyright (c) Alexandre Mutel. All rights reserved.
// Licensed under the BSD-Clause 2 license.
// See license.txt file in the project root for full license information.

namespace Ultra.Core.Model;

/// <summary>
/// Represents a JIT compile event marker payload for the Firefox Profiler.
/// </summary>
public record JitCompileTraceMarker : UTraceMarker
{
/// <summary>
/// Gets or sets the full name of the method.
/// </summary>
public required string FullName { get; init; }

/// <summary>
/// Gets or sets the IL size of the method.
/// </summary>
public int MethodILSize { get; set; }
}
108 changes: 108 additions & 0 deletions src/Ultra.Core/Model/UAddress.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
// Copyright (c) Alexandre Mutel. All rights reserved.
// Licensed under the BSD-Clause 2 license.
// See license.txt file in the project root for full license information.

namespace Ultra.Core.Model;

/// <summary>
/// Represents an address in the traced process.
/// </summary>
public readonly record struct UAddress(ulong Value) : IComparable<UAddress>, IComparable
{
/// <inheritdoc />
public override string ToString() => $"0x{Value:X}";

/// <summary>
/// Adds an offset to the address.
/// </summary>
public static UAddress operator +(UAddress address, ulong offset) => new(address.Value + offset);

/// <summary>
/// Subtracts an offset from the address.
/// </summary>
public static UAddress operator -(UAddress address, ulong offset) => new(address.Value - offset);

/// <summary>
/// Adds an offset to the address.
/// </summary>
public static UAddress operator +(UAddress address, long offset) => new(address.Value + (ulong)offset);

/// <summary>
/// Subtracts an offset from the address.
/// </summary>
public static UAddress operator -(UAddress address, long offset) => new(address.Value - (ulong)offset);

/// <summary>
/// Adds an offset to the address.
/// </summary>
public static UAddress operator +(UAddress address, int offset) => new(address.Value + (ulong)offset);

/// <summary>
/// Subtracts an offset from the address.
/// </summary>
public static UAddress operator -(UAddress address, int offset) => new(address.Value - (ulong)offset);

/// <summary>
/// Subtracts two addresses to return the size difference.
/// </summary>
public static USize operator -(UAddress left, UAddress right) => new(left.Value - right.Value);

/// <summary>
/// Implicit conversion to <see cref="ulong"/>.
/// </summary>
public static implicit operator ulong(UAddress address) => address.Value;

/// <summary>
/// Explicit conversion from <see cref="ulong"/>.
/// </summary>
public static implicit operator UAddress(ulong value) => new(value);

/// <inheritdoc />
public int CompareTo(UAddress other)
{
return Value.CompareTo(other.Value);
}

/// <inheritdoc />
public int CompareTo(object? obj)
{
if (obj is null)
{
return 1;
}

return obj is UAddress other ? CompareTo(other) : throw new ArgumentException($"Object must be of type {nameof(UAddress)}");
}

/// <summary>
/// Compares two addresses for less than.
/// </summary>
public static bool operator <(UAddress left, UAddress right)
{
return left.CompareTo(right) < 0;
}

/// <summary>
/// Compares two addresses for greater than.
/// </summary>
public static bool operator >(UAddress left, UAddress right)
{
return left.CompareTo(right) > 0;
}

/// <summary>
/// Compares two addresses for less than or equal.
/// </summary>
public static bool operator <=(UAddress left, UAddress right)
{
return left.CompareTo(right) <= 0;
}

/// <summary>
/// Compares two addresses for greater than or equal.
/// </summary>
public static bool operator >=(UAddress left, UAddress right)
{
return left.CompareTo(right) >= 0;
}
}
47 changes: 47 additions & 0 deletions src/Ultra.Core/Model/UAddressRange.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
// Copyright (c) Alexandre Mutel. All rights reserved.
// Licensed under the BSD-Clause 2 license.
// See license.txt file in the project root for full license information.

using System.Runtime.CompilerServices;
using XenoAtom.Collections;

namespace Ultra.Core.Model;

/// <summary>
/// Represents an address range in the traced process.
/// </summary>
public readonly record struct UAddressRange(UAddress BeginAddress, UAddress EndAddress, int Index)
{
/// <summary>
/// Determines if the address is contained within the range.
/// </summary>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public bool Contains(ulong address) => address >= BeginAddress && address < EndAddress;
}

/// <summary>
/// Represents a comparer for address ranges.
/// </summary>
readonly record struct UAddressRangeFinder(ulong Address) : IComparable<UAddressRange>
{
/// <summary>
/// Compares the address range finder with another address range.
/// </summary>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public int CompareTo(UAddressRange other)
{
return other.Contains(Address) ? 0 : Address.CompareTo(other.BeginAddress);
}
}

/// <summary>
/// Represents a comparer for address ranges based on their beginning address.
/// </summary>
readonly record struct UAddressRangeComparer : IComparerByRef<UAddressRange>
{
/// <summary>
/// Compares two address ranges for less than.
/// </summary>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public bool LessThan(in UAddressRange left, in UAddressRange right) => left.BeginAddress < right.BeginAddress;
}
Loading

0 comments on commit 9862b9f

Please sign in to comment.