Skip to content
Merged
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
3 changes: 2 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ jobs:
strategy:
fail-fast: false
matrix:
tfm: [ net6.0, net7.0, net8.0, net9.0 ]
tfm: [ net6.0, net7.0, net8.0, net9.0, net10.0 ]

steps:
- uses: actions/checkout@v3
Expand All @@ -30,6 +30,7 @@ jobs:
7.0.x
8.0.x
9.0.x
10.0.x

# Restore & build all target frameworks
- name: Restore dependencies
Expand Down
7 changes: 4 additions & 3 deletions src/Directory.Build.props
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
<Project>
<PropertyGroup>
<Version>0.4.5</Version>
<Version>0.4.6</Version>
<Authors>Tony Redondo, Grégory Léocadie</Authors>
<TargetFrameworks>net6.0;net7.0;net8.0;net9.0</TargetFrameworks>
<TargetFrameworks>net6.0;net7.0;net8.0;net9.0;net10.0</TargetFrameworks>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<LangVersion>13</LangVersion>
<ContinuousIntegrationBuild>true</ContinuousIntegrationBuild>
<ServerGarbageCollection>false</ServerGarbageCollection>
<RollForward>LatestMajor</RollForward>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="DotNet.ReproducibleBuilds" Version="1.2.25" PrivateAssets="All"/>
<PackageReference Include="DotNet.ReproducibleBuilds" Version="1.2.39" PrivateAssets="All"/>
</ItemGroup>
</Project>
42 changes: 28 additions & 14 deletions src/TimeItSharp.Common/ScenarioProcessor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -839,23 +839,37 @@ private async Task<DataPoint> RunCommandAsync(int index, Scenario scenario, Time
await using (var file = File.Open(metricsFilePath, FileMode.Open, FileAccess.Read, FileShare.Read))
using (var reader = new BinaryReader(file))
{
while (file.Position < file.Length)
while (file.Position + 4 < file.Length)
{
// Read magic number
if (reader.ReadInt32() != 7248)
BinaryFileStorage.MetricType type;
int nameLength;
byte[] nameBytes;
string name;
double value;

try
{
continue;
}
// Read magic number
if (reader.ReadInt32() != 7248)
{
continue;
}

// Read metric type
var type = (BinaryFileStorage.MetricType)reader.ReadByte();
// Read name length
var nameLength = reader.ReadInt32();
// Read name
var nameBytes = reader.ReadBytes(nameLength);
var name = Encoding.UTF8.GetString(nameBytes);
// Read value
var value = reader.ReadDouble();
// Read metric type
type = (BinaryFileStorage.MetricType)reader.ReadByte();
// Read name length
nameLength = reader.ReadInt32();
// Read name
nameBytes = reader.ReadBytes(nameLength);
name = Encoding.UTF8.GetString(nameBytes);
// Read value
value = reader.ReadDouble();
}
catch (EndOfStreamException)
{
// We reached the end of the stream, corrupted data, just break
break;
}

try
{
Expand Down
2 changes: 1 addition & 1 deletion src/TimeItSharp.Common/TimeItSharp.Common.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
<PackageReference Include="CliWrap" Version="3.9.0" />
<PackageReference Include="Datadog.Trace.BenchmarkDotNet" Version="2.61.0" />
<PackageReference Include="MathNet.Numerics" Version="5.0.0" />
<PackageReference Include="Spectre.Console" Version="0.50.0" />
<PackageReference Include="Spectre.Console" Version="0.51.1" />
<PackageReference Include="IgnoresAccessChecksToGenerator" Version="0.8.0">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
Expand Down
74 changes: 40 additions & 34 deletions src/TimeItSharp.StartupHook/RuntimeMetrics/BinaryFileStorage.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;

namespace TimeItSharp.RuntimeMetrics;

Expand All @@ -11,7 +12,7 @@ public void WritePayload(in MetricPayload payload)
{
lock (_binaryWriter)
{
InternalWritePayload(in payload);
payload.WriteTo(_binaryWriter);
}
}

Expand All @@ -20,8 +21,8 @@ public void WritePayload(in MetricPayload payload1, in MetricPayload payload2)
{
lock (_binaryWriter)
{
InternalWritePayload(in payload1);
InternalWritePayload(in payload2);
payload1.WriteTo(_binaryWriter);
payload2.WriteTo(_binaryWriter);
}
}

Expand All @@ -30,9 +31,9 @@ public void WritePayload(in MetricPayload payload1, in MetricPayload payload2, i
{
lock (_binaryWriter)
{
InternalWritePayload(in payload1);
InternalWritePayload(in payload2);
InternalWritePayload(in payload3);
payload1.WriteTo(_binaryWriter);
payload2.WriteTo(_binaryWriter);
payload3.WriteTo(_binaryWriter);
}
}

Expand All @@ -41,10 +42,10 @@ public void WritePayload(in MetricPayload payload1, in MetricPayload payload2, i
{
lock (_binaryWriter)
{
InternalWritePayload(in payload1);
InternalWritePayload(in payload2);
InternalWritePayload(in payload3);
InternalWritePayload(in payload4);
payload1.WriteTo(_binaryWriter);
payload2.WriteTo(_binaryWriter);
payload3.WriteTo(_binaryWriter);
payload4.WriteTo(_binaryWriter);
}
}

Expand All @@ -53,14 +54,14 @@ public void WritePayload(in MetricPayload payload1, in MetricPayload payload2, i
{
lock (_binaryWriter)
{
InternalWritePayload(in payload1);
InternalWritePayload(in payload2);
InternalWritePayload(in payload3);
InternalWritePayload(in payload4);
InternalWritePayload(in payload5);
InternalWritePayload(in payload6);
InternalWritePayload(in payload7);
InternalWritePayload(in payload8);
payload1.WriteTo(_binaryWriter);
payload2.WriteTo(_binaryWriter);
payload3.WriteTo(_binaryWriter);
payload4.WriteTo(_binaryWriter);
payload5.WriteTo(_binaryWriter);
payload6.WriteTo(_binaryWriter);
payload7.WriteTo(_binaryWriter);
payload8.WriteTo(_binaryWriter);
}
}

Expand All @@ -72,16 +73,6 @@ public void Dispose()
}
}

[MethodImpl(MethodImplOptions.AggressiveInlining)]
private void InternalWritePayload(in MetricPayload payload)
{
_binaryWriter.Write((int)7248); // Magic number for identification
_binaryWriter.Write((byte)payload.Type); // Metric type
_binaryWriter.Write(payload.Name.Length); // Length of the name
_binaryWriter.Write(payload.Name); // Name of the metric
_binaryWriter.Write(payload.Value); // Value of the metric
}

internal enum MetricType : byte
{
Counter,
Expand All @@ -92,15 +83,30 @@ internal enum MetricType : byte

public readonly ref struct MetricPayload
{
public readonly MetricType Type;
public readonly ReadOnlySpan<byte> Name;
public readonly double Value;
private const int MagicNumber = 7248;
private readonly MetricType _type;
private readonly ReadOnlySpan<byte> _name;
private readonly double _value;

public MetricPayload(MetricType type, ReadOnlySpan<byte> name, double value)
{
Type = type;
Name = name;
Value = value;
_type = type;
_name = name;
_value = value;
}

public void WriteTo(BinaryWriter writer)
{
// Magic number (4 bytes) + Type (1 byte) + Name Length (4 bytes) + Name (variable) + Value (8 bytes)
var payloadLength = 4 + 1 + 4 + _name.Length + 8; // Total length of the payload
Span<byte> buffer = payloadLength <= 1024 ? stackalloc byte[payloadLength] : new byte[payloadLength];

Unsafe.WriteUnaligned(ref buffer[0], MagicNumber); // Magic number for identification
buffer[4] = (byte)_type; // Metric type
Unsafe.WriteUnaligned(ref buffer[5], _name.Length); // Length of the name
_name.CopyTo(buffer.Slice(9)); // Name of the metric
Unsafe.WriteUnaligned(ref buffer[9 + _name.Length], _value); // Value of the metric
writer.Write(buffer);
}
}
}
2 changes: 2 additions & 0 deletions src/TimeItSharp.StartupHook/TimeItSharp.StartupHook.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,15 @@
<Description>Command execution time meter library</Description>
<Copyright>Tony Redondo @ 2023</Copyright>
<PackageTags>timeit, timeitsharp, benchmark, performance</PackageTags>
<PackageReadmeFile>README.md</PackageReadmeFile>
<PackageLicenseFile>LICENSE</PackageLicenseFile>
<PackageIcon>icon.png</PackageIcon>
<NoWarn>NETSDK1138</NoWarn>
<PackageOutputPath>..\..\artifacts</PackageOutputPath>
</PropertyGroup>

<ItemGroup>
<None Include="..\..\README.md" Pack="true" PackagePath="\" />
<None Include="..\..\LICENSE" Pack="true" PackagePath="\" />
<None Include="..\..\icon.png" Pack="true" PackagePath="\" />
</ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFrameworks>net6.0;net7.0;net8.0;net9.0</TargetFrameworks>
<TargetFrameworks>net6.0;net7.0;net8.0;net9.0;net10.0</TargetFrameworks>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
Expand Down
Loading