Skip to content

Commit

Permalink
feat: add React UI
Browse files Browse the repository at this point in the history
- generate TypeScript client by kiota and dotnet swagger
- migrate to .NET 8
- update Microsoft.Diagnostics.Runtime
  • Loading branch information
Ne4to committed Jan 17, 2024
1 parent 57243dc commit bc9b652
Show file tree
Hide file tree
Showing 51 changed files with 2,429 additions and 204 deletions.
18 changes: 18 additions & 0 deletions .config/dotnet-tools.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"version": 1,
"isRoot": true,
"tools": {
"microsoft.openapi.kiota": {
"version": "1.10.1",
"commands": [
"kiota"
]
},
"swashbuckle.aspnetcore.cli": {
"version": "6.5.0",
"commands": [
"swagger"
]
}
}
}
2 changes: 1 addition & 1 deletion Directory.Build.props
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<Project>
<PropertyGroup>
<TargetFramework>net7.0</TargetFramework>
<TargetFramework>net8.0</TargetFramework>
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
</PropertyGroup>
Expand Down
28 changes: 28 additions & 0 deletions scripts/update-ts-client.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
$ErrorActionPreference = "Stop"

$RepositoryRoot = Split-Path $PSScriptRoot
$FrontendRoot = Join-Path $RepositoryRoot 'src/Heartbeat.WebUI/ClientApp'
$ContractPath = Join-Path $FrontendRoot 'api.yml'
$DllPath = Join-Path $RepositoryRoot 'src/Heartbeat.WebUI/bin/Debug/net8.0/Heartbeat.WebUI.dll'

Push-Location
try
{
Set-Location $RepositoryRoot

dotnet tool restore
dotnet build --configuration Debug

Set-Location $FrontendRoot
dotnet swagger tofile --yaml --output $ContractPath $DllPath Heartbeat
dotnet kiota generate -l typescript --openapi $ContractPath -c HeartbeatClient -o ./src/client

# TODO try --serializer Microsoft.Kiota.Serialization.Json.JsonSerializationWriterFactory --deserializer Microsoft.Kiota.Serialization.Json.JsonParseNodeFactory
}
catch {
Write-Host 'Generate client - FAILED!' -ForegroundColor Red
throw
}
finally {
Pop-Location
}
18 changes: 18 additions & 0 deletions src/.config/dotnet-tools.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"version": 1,
"isRoot": true,
"tools": {
"microsoft.openapi.kiota": {
"version": "1.10.1",
"commands": [
"kiota"
]
},
"swashbuckle.aspnetcore.cli": {
"version": "6.5.0",
"commands": [
"swagger"
]
}
}
}
2 changes: 1 addition & 1 deletion src/DebugHost/DebugHost.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.Diagnostics.Runtime" Version="2.3.405304" />
<PackageReference Include="Microsoft.Diagnostics.Runtime" Version="3.1.456101" />
</ItemGroup>

<ItemGroup>
Expand Down
2 changes: 2 additions & 0 deletions src/Heartbeat.Domain/Size.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ public readonly record struct Size(ulong Bytes) : IComparable<Size>, IComparable
private const ulong _mb = _k * _k;
private const ulong _gb = _mb * _k;

public static implicit operator ulong(Size bytes) => bytes.Bytes;

public override string ToString()
{
if (Bytes >= _gb)
Expand Down
3 changes: 2 additions & 1 deletion src/Heartbeat.Runtime/Analyzers/AsyncStateMachineAnalyzer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,8 @@ from clrObject in Context.EnumerateObjects(TraversingHeapMode)

foreach (var (_, token) in coreLibModule.EnumerateTypeDefToMethodTableMap())
{
var clrType = coreLibModule.ResolveToken(token);
// TODO var clrType = coreLibModule.ResolveToken(token);
ClrType? clrType = null;
if (clrType?.Name == null)
{
continue;
Expand Down
4 changes: 2 additions & 2 deletions src/Heartbeat.Runtime/Extensions/ClrHeapExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ public static class ClrHeapExtensions
{
if (mt == methodTable)
{
var clrType = module.ResolveToken(token);
return clrType;
// TODO var clrType = module.ResolveToken(token);
// return clrType;
}
}
}
Expand Down
7 changes: 4 additions & 3 deletions src/Heartbeat.Runtime/Extensions/ClrTypeExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,9 @@ public static string GetClrTypeName(this ClrType clrType)
{
return !string.IsNullOrWhiteSpace(clrType.Name)
? clrType.Name
: (clrType.IsInternal
? $"Internal {clrType.Module}"
: $"UNKNOWN {clrType.Module}");
: $"UNKNOWN {clrType.Module}";
// TODO : (clrType.IsInternal
// ? $"Internal {clrType.Module}"
// : $"UNKNOWN {clrType.Module}");
}
}
11 changes: 4 additions & 7 deletions src/Heartbeat.Runtime/HeapIndex.cs
Original file line number Diff line number Diff line change
@@ -1,23 +1,20 @@
using Heartbeat.Runtime.Proxies;

using Microsoft.Diagnostics.Runtime;
using Microsoft.Diagnostics.Runtime.Implementation;

namespace Heartbeat.Runtime;

public sealed class HeapIndex
{
private readonly ObjectSet _roots;
private readonly ObjectSet _walkableFromRoot;
private readonly HashSet<ulong> _roots;
private readonly HashSet<ulong> _walkableFromRoot;
private readonly Dictionary<ulong, List<ulong>> _referencesToObject = new(100000);

public HeapIndex(ClrHeap heap)
{
// Evaluation stack
Stack<ulong> eval = new();

_roots = new ObjectSet(heap);
_walkableFromRoot = new ObjectSet(heap);
_roots = new HashSet<ulong>();
_walkableFromRoot = new HashSet<ulong>();

foreach (var clrRoot in heap.EnumerateRoots())
{
Expand Down
6 changes: 3 additions & 3 deletions src/Heartbeat.Runtime/Heartbeat.Runtime.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="Microsoft.Diagnostics.Runtime" Version="2.3.405304" />
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="7.0.0" />
<PackageReference Include="Microsoft.VisualStudio.Threading.Analyzers" Version="17.4.33">
<PackageReference Include="Microsoft.Diagnostics.Runtime" Version="3.1.456101" />
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="8.0.0" />
<PackageReference Include="Microsoft.VisualStudio.Threading.Analyzers" Version="17.8.14">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
Expand Down
8 changes: 4 additions & 4 deletions src/Heartbeat.Runtime/LogExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public static void LogHeapSegments(this ClrHeap heap, ILogger logger)
$"\t{segment} ObjectRange: {segment.ObjectRange} {Size.ToString(segment.ObjectRange.Length)} " +
$"CommittedMemory: {segment.CommittedMemory} {Size.ToString(segment.CommittedMemory.Length)} " +
$"ReservedMemory: {segment.ReservedMemory} {Size.ToString(segment.ReservedMemory.Length)} " +
$"IsEphemeralSegment: {segment.IsEphemeralSegment}, IsLargeObjectSegment: {segment.IsLargeObjectSegment}");
$"IsEphemeralSegment: {segment.Kind == GCSegmentKind.Ephemeral}, IsLargeObjectSegment: {segment.Kind == GCSegmentKind.Large}");

totalSize += segment.Length;
}
Expand Down Expand Up @@ -584,9 +584,9 @@ public static void LogThreads(
string[] propNames =
{
nameof(ClrThread.IsAlive),
nameof(ClrThread.IsBackground),
// nameof(ClrThread.IsBackground),
nameof(ClrThread.IsFinalizer),
nameof(ClrThread.IsDebugSuspended),
// nameof(ClrThread.IsDebugSuspended),
};

var logLineBuilder = new StringBuilder();
Expand Down Expand Up @@ -760,7 +760,7 @@ from clrObject in heap.EnumerateObjects()
where type != null
&& !type.IsFree
// && !type.IsString
&& !type.IsInternal
// && !type.IsInternal
orderby clrObject.Size descending
select clrObject;

Expand Down
6 changes: 3 additions & 3 deletions src/Heartbeat.Web/Pages/Index.razor
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,9 @@
Segments = Context.Heap.Segments.Select(s => new HeapSegment(
new Address(s.Start),
new Address(s.End),
s.IsEphemeralSegment,
s.IsLargeObjectSegment,
s.IsPinnedObjectSegment)).ToArray();
s.Kind == GCSegmentKind.Ephemeral,
s.Kind == GCSegmentKind.Large,
s.Kind == GCSegmentKind.Pinned)).ToArray();
}

}
2 changes: 2 additions & 0 deletions src/Heartbeat.WebUI/ClientApp/.env
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
BROWSER=none
# https://stackoverflow.com/questions/70599784/failed-to-parse-source-map
GENERATE_SOURCEMAP=false
Loading

0 comments on commit bc9b652

Please sign in to comment.