-
Notifications
You must be signed in to change notification settings - Fork 27
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
8d829c2
commit 5692c7e
Showing
76 changed files
with
1,722 additions
and
70 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
using System.Text.Json; | ||
using System.Text.Json.Serialization; | ||
using System.Text.Json.Serialization.Metadata; | ||
using Perfolizer.Phd; | ||
using Perfolizer.Phd.Base; | ||
|
||
namespace Perfolizer.Tests.Phd; | ||
|
||
public class PolymorphicTypeResolver(PhdSchema schema) : DefaultJsonTypeInfoResolver | ||
{ | ||
public override JsonTypeInfo GetTypeInfo(Type type, JsonSerializerOptions options) | ||
{ | ||
var jsonTypeInfo = base.GetTypeInfo(type, options); | ||
|
||
foreach (var implementation in schema.Implementations) | ||
{ | ||
if (jsonTypeInfo.Type == implementation.Base) | ||
{ | ||
jsonTypeInfo.PolymorphismOptions = new JsonPolymorphismOptions | ||
{ | ||
TypeDiscriminatorPropertyName = "$type", | ||
IgnoreUnrecognizedTypeDiscriminators = true, | ||
UnknownDerivedTypeHandling = JsonUnknownDerivedTypeHandling.FailSerialization, | ||
DerivedTypes = | ||
{ | ||
new JsonDerivedType(implementation.Derived, schema.Name) | ||
} | ||
}; | ||
} | ||
} | ||
|
||
return jsonTypeInfo; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
using System.Runtime.CompilerServices; | ||
|
||
namespace Perfolizer.Tests.Phd; | ||
|
||
public static class ModuleInit | ||
{ | ||
[ModuleInitializer] | ||
public static void Init() | ||
{ | ||
VerifierSettings.UseStrictJson(); | ||
VerifierSettings.AutoVerify(); | ||
VerifierSettings.DontScrubGuids(); | ||
VerifierSettings.DontScrubDateTimes(); | ||
VerifierSettings.DontSortDictionaries(); | ||
} | ||
|
||
[ModuleInitializer] | ||
public static void InitDerivePathInfo() => | ||
DerivePathInfo( | ||
(_, _, type, method) => new(AttributeReader.GetProjectDirectory(), typeName: type.Name, method.Name)); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
using JetBrains.Annotations; | ||
using Perfolizer.Horology; | ||
using Perfolizer.Phd; | ||
|
||
namespace Perfolizer.Tests.Phd; | ||
|
||
// public class PhdBdnTests : PhdTestsBase | ||
// { | ||
// [Fact] | ||
// public Task PhdBdn() | ||
// { | ||
// PerfMetric Metric(double value, int iterationIndex) => new() | ||
// { Value = value, Unit = TimeUnit.Nanosecond, IterationIndex = iterationIndex, InvocationCount = 2 }; | ||
// | ||
// var root = new PhdAttributes | ||
// { | ||
// Info = new BdnInfo { Title = "BenchmarkDotNet.Samples.IntroExportJson-20240309-013216" }, | ||
// Host = new BdnHost | ||
// { | ||
// BenchmarkDotNetCaption = "BenchmarkDotNet", | ||
// BenchmarkDotNetVersion = "0.13.13-develop (2024-03-09)", | ||
// OsVersion = "macOS Sonoma 14.2.1 (23C71) [Darwin 23.2.0]", | ||
// ProcessorName = "Apple M1 Max", | ||
// PhysicalProcessorCount = "1", | ||
// PhysicalCoreCount = "10", | ||
// LogicalCoreCount = "10", | ||
// RuntimeVersion = ".NET 8.0.0 (8.0.23.53103)", | ||
// Architecture = "Arm64", | ||
// HasAttachedDebugger = false, | ||
// HasRyuJit = true, | ||
// Configuration = "RELEASE", | ||
// DotNetSdkVersion = "8.0.100", | ||
// ChronometerFrequency = 1000000000, | ||
// HardwareTimerKind = "Unknown" | ||
// } | ||
// }.ToPerfEntry().Add( | ||
// new PhdAttributes | ||
// { | ||
// Descriptor = new BdnDescriptor | ||
// { | ||
// DisplayInfo = "BenchmarkDotNet.Samples.IntroExportJson-20240309-013216", | ||
// Namespace = "BenchmarkDotNet.Samples", | ||
// Type = "IntroExportJson", | ||
// Method = "ExportJson", | ||
// MethodTitle = "ExportJson", | ||
// Parameters = "Foo=1" | ||
// } | ||
// }.ToPerfEntry() | ||
// .Add(new PhdAttributes | ||
// { | ||
// Lifecycle = new BdnLifecycle | ||
// { | ||
// IterationMode = "Pilot", | ||
// IterationStage = "Overhead", | ||
// LaunchIndex = 0 | ||
// } | ||
// }.ToPerfEntry() | ||
// .Add(Metric(12, 1)) | ||
// .Add(Metric(13, 2)) | ||
// .Add(Metric(14, 3))) | ||
// .Add(new PhdAttributes | ||
// { | ||
// Lifecycle = new BdnLifecycle | ||
// { | ||
// IterationMode = "Result", | ||
// IterationStage = "Workload", | ||
// LaunchIndex = 1 | ||
// } | ||
// }.ToPerfEntry() | ||
// .Add(Metric(15, 1)) | ||
// .Add(Metric(16, 2)) | ||
// .Add(Metric(17, 3))) | ||
// ); | ||
// | ||
// | ||
// return VerifyPhd(root, schema); | ||
// } | ||
// | ||
// | ||
// } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
using Perfolizer.Phd; | ||
using Perfolizer.Phd.Base; | ||
using Perfolizer.Phd.Dto; | ||
|
||
namespace Perfolizer.Tests.Phd; | ||
|
||
public class PhdEmptyTests : PhdTestsBase | ||
{ | ||
[Fact] | ||
public Task PhdEmpty() => VerifyPhd(new PhdEntry(new PhdAttributes()), new PhdSchema("")); | ||
} |
109 changes: 109 additions & 0 deletions
109
src/Perfolizer/Perfolizer.Tests/Phd/PhdPerforatorTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,109 @@ | ||
using JetBrains.Annotations; | ||
using Perfolizer.Horology; | ||
using Perfolizer.Mathematics.Distributions.ContinuousDistributions; | ||
using Perfolizer.Metrology; | ||
using Perfolizer.Phd; | ||
using Perfolizer.Phd.Base; | ||
using Perfolizer.Phd.Dto; | ||
|
||
namespace Perfolizer.Tests.Phd; | ||
|
||
public class PhdPerforatorTests : PhdTestsBase | ||
{ | ||
[Fact] | ||
public Task PhdPerforator() | ||
{ | ||
var runId = Guid.Parse("11214D6B-4E25-44A4-8032-D4290C9F5617"); | ||
var random = new NormalDistribution(10).Random(1729); | ||
double NextValue() => Math.Round(random.Next(), 3); | ||
int minute = 0; | ||
|
||
PhdEntry CreateEntry(string benchmarkId) => new PhdAttributes | ||
{ | ||
Identity = new PerforatorIdentity | ||
{ | ||
RunId = runId, | ||
Timestamp = DateTimeOffset.Parse($"2021-01-01T00:0{minute++}:00Z").ToUnixTimeMilliseconds() | ||
}, | ||
Source = new PerforatorSource | ||
{ | ||
BuildId = 123456, | ||
Branch = "main", | ||
ConfigurationId = "Configuration1", | ||
}, | ||
Host = new PerforatorHost | ||
{ | ||
Os = "Linux-x64", | ||
ImageId = "Environment1", | ||
}, | ||
Descriptor = new PerforatorDescriptor | ||
{ | ||
BenchmarkId = benchmarkId, | ||
BenchmarkVersion = 1, | ||
}, | ||
}.ToPerfEntry() | ||
.Add(new PhdMetric { Id = "stage1", Value = NextValue(), Unit = TimeUnit.Millisecond }) | ||
.Add(new PhdMetric { Id = "stage2", Version = 2, Value = NextValue(), Unit = TimeUnit.Millisecond }) | ||
.Add(new PhdMetric { Id = "totalTime", Value = NextValue(), Unit = TimeUnit.Millisecond }) | ||
.Add(new PhdMetric { Id = "Footprint", Value = 20, Unit = SizeUnit.MB }) | ||
.Add(new PhdMetric { Id = "Gc.CollectCount", Value = 3 }); | ||
|
||
var root = new PhdAttributes | ||
{ | ||
Info = new PerforatorInfo { Title = "Perforator Measurements" } | ||
}.ToPerfEntry() | ||
.Add(CreateEntry("benchmark1")) | ||
.Add(CreateEntry("benchmark1")) | ||
.Add(CreateEntry("benchmark2")) | ||
.Add(CreateEntry("benchmark2")); | ||
|
||
var schema = new PhdSchema("perforator") | ||
.Add<PerforatorInfo>() | ||
.Add<PerforatorHost>() | ||
.Add<PerforatorExecution>() | ||
.Add<PerforatorDescriptor>() | ||
.Add<PerforatorIdentity>() | ||
.Add<PerforatorSource>(); | ||
|
||
return VerifyPhd(root, schema); | ||
} | ||
|
||
private class PerforatorInfo : PhdInfo | ||
{ | ||
public string Title { get; set; } = ""; | ||
} | ||
|
||
[PublicAPI] | ||
private class PerforatorHost : PhdHost | ||
{ | ||
public string Os { get; set; } = ""; | ||
Check warning on line 79 in src/Perfolizer/Perfolizer.Tests/Phd/PhdPerforatorTests.cs GitHub Actions / build-nix (macOS-latest)
Check warning on line 79 in src/Perfolizer/Perfolizer.Tests/Phd/PhdPerforatorTests.cs GitHub Actions / build-nix (ubuntu-latest)
Check warning on line 79 in src/Perfolizer/Perfolizer.Tests/Phd/PhdPerforatorTests.cs GitHub Actions / build-windows
Check warning on line 79 in src/Perfolizer/Perfolizer.Tests/Phd/PhdPerforatorTests.cs GitHub Actions / build-nix (macOS-latest)
Check warning on line 79 in src/Perfolizer/Perfolizer.Tests/Phd/PhdPerforatorTests.cs GitHub Actions / build-nix (ubuntu-latest)
|
||
public string ImageId { get; set; } = ""; | ||
} | ||
|
||
[PublicAPI] | ||
private class PerforatorExecution : PhdExecution | ||
{ | ||
} | ||
|
||
[PublicAPI] | ||
private class PerforatorDescriptor : PhdDescriptor | ||
{ | ||
public string BenchmarkId { get; set; } = ""; | ||
public int BenchmarkVersion { get; set; } | ||
} | ||
|
||
[PublicAPI] | ||
private class PerforatorIdentity : PhdIdentity | ||
{ | ||
public Guid RunId { get; set; } | ||
public long Timestamp { get; set; } | ||
} | ||
|
||
[PublicAPI] | ||
private class PerforatorSource : PhdSource | ||
{ | ||
public int BuildId { get; set; } | ||
public string ConfigurationId { get; set; } = ""; | ||
public string Branch { get; set; } = ""; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
using System.Text.Json; | ||
using System.Text.Json.Serialization; | ||
using Perfolizer.Json; | ||
using Perfolizer.Phd; | ||
using Perfolizer.Phd.Base; | ||
|
||
namespace Perfolizer.Tests.Phd; | ||
|
||
public class PhdTestsBase | ||
{ | ||
protected static Task VerifyPhd(PhdEntry entry, PhdSchema schema) | ||
{ | ||
// JsonSerializerOptions jsonOptions = new() | ||
// { | ||
// DefaultIgnoreCondition = JsonIgnoreCondition.WhenWritingNull, | ||
// PropertyNamingPolicy = JsonNamingPolicy.CamelCase, | ||
// TypeInfoResolver = new PolymorphicTypeResolver(schema) | ||
// }; | ||
// string json = JsonSerializer.Serialize(entry.Serialize(), jsonOptions); | ||
string json = LightJsonSerializer.Serialize(entry.ToRaw()); | ||
return VerifyJson(json, InitSettings()); | ||
} | ||
|
||
private static VerifySettings InitSettings() | ||
{ | ||
var settings = new VerifySettings(); | ||
settings.UseDirectory("VerifiedFiles"); | ||
settings.UseTypeName("Phd"); | ||
settings.DisableDiff(); | ||
; | ||
return settings; | ||
} | ||
} |
Oops, something went wrong.