protected virtual IReadOnlyDictionary <string, object> GetDataToSerialize(BenchmarkReport report) { var benchmark = new Dictionary <string, object> { // We don't need Benchmark.ShortInfo, that info is available via Benchmark.Parameters below { "DisplayInfo", report.BenchmarkCase.DisplayInfo }, { "Namespace", report.BenchmarkCase.Descriptor.Type.Namespace }, { "Type", FullNameProvider.GetTypeName(report.BenchmarkCase.Descriptor.Type) }, { "Method", report.BenchmarkCase.Descriptor.WorkloadMethod.Name }, { "MethodTitle", report.BenchmarkCase.Descriptor.WorkloadMethodDisplayInfo }, { "Parameters", report.BenchmarkCase.Parameters.PrintInfo }, { "FullName", FullNameProvider.GetBenchmarkName(report.BenchmarkCase) }, // do NOT remove this property, it is used for xunit-performance migration // Hardware Intrinsics can be disabled using env vars, that is why they might be different per benchmark and are not exported as part of HostEnvironmentInfo { "HardwareIntrinsics", report.GetHardwareIntrinsicsInfo() ?? "" }, // { "Properties", r.Benchmark.Job.ToSet().ToDictionary(p => p.Name, p => p.Value) }, // TODO { "Statistics", report.ResultStatistics } }; // We show MemoryDiagnoser's results only if it is being used if (report.BenchmarkCase.Config.HasMemoryDiagnoser()) { benchmark.Add("Memory", new { report.GcStats.Gen0Collections, report.GcStats.Gen1Collections, report.GcStats.Gen2Collections, report.GcStats.TotalOperations, BytesAllocatedPerOperation = report.GcStats.GetBytesAllocatedPerOperation(report.BenchmarkCase) }); } if (ExcludeMeasurements == false) { // We construct Measurements manually, so that we can have the IterationMode enum as text, rather than an integer benchmark.Add("Measurements", report.AllMeasurements.Select(m => new { IterationMode = m.IterationMode.ToString(), IterationStage = m.IterationStage.ToString(), m.LaunchIndex, m.IterationIndex, m.Operations, m.Nanoseconds })); if (report.Metrics.Any()) { benchmark.Add("Metrics", report.Metrics.Values); } } return(benchmark); }
private static string GetBenchmarkName(BenchmarkCase benchmark) { var fullName = FullNameProvider.GetBenchmarkName(benchmark); // FullBenchmarkName is passed to Process.Start as an argument and each OS limits the max argument length, so we have to limit it too // Windows limit is 32767 chars, Unix is 128*1024 but we use 1024 as a common sense limit if (fullName.Length < 1024) { return(fullName); } string typeName = FullNameProvider.GetTypeName(benchmark.Descriptor.Type); string methodName = benchmark.Descriptor.WorkloadMethod.Name; string paramsHash = benchmark.HasParameters ? "paramsHash_" + Hashing.HashString(FullNameProvider.GetMethodName(benchmark)).ToString() : string.Empty; return($"{typeName}.{methodName}({paramsHash})"); }
public override void ExportToLog(Summary summary, ILogger logger) { // We construct HostEnvironmentInfo manually, so that we can have the HardwareTimerKind enum as text, rather than an integer // SimpleJson serializer doesn't seem to have an enum String/Value option (to-be-fair, it is meant to be "Simple") var environmentInfo = new { HostEnvironmentInfo.BenchmarkDotNetCaption, summary.HostEnvironmentInfo.BenchmarkDotNetVersion, OsVersion = summary.HostEnvironmentInfo.OsVersion.Value, ProcessorName = ProcessorBrandStringHelper.Prettify(summary.HostEnvironmentInfo.CpuInfo.Value?.ProcessorName ?? ""), summary.HostEnvironmentInfo.CpuInfo.Value?.PhysicalProcessorCount, summary.HostEnvironmentInfo.CpuInfo.Value?.PhysicalCoreCount, summary.HostEnvironmentInfo.CpuInfo.Value?.LogicalCoreCount, summary.HostEnvironmentInfo.RuntimeVersion, summary.HostEnvironmentInfo.Architecture, summary.HostEnvironmentInfo.HasAttachedDebugger, summary.HostEnvironmentInfo.HasRyuJit, summary.HostEnvironmentInfo.Configuration, summary.HostEnvironmentInfo.JitModules, DotNetCliVersion = summary.HostEnvironmentInfo.DotNetSdkVersion.Value, summary.HostEnvironmentInfo.ChronometerFrequency, HardwareTimerKind = summary.HostEnvironmentInfo.HardwareTimerKind.ToString() }; // If we just ask SimpleJson to serialise the entire "summary" object it throws several errors. // So we are more specific in what we serialise (plus some fields/properties aren't relevant) var benchmarks = summary.Reports.Select(r => { var data = new Dictionary <string, object> { // We don't need Benchmark.ShortInfo, that info is available via Benchmark.Parameters below { "DisplayInfo", r.BenchmarkCase.DisplayInfo }, { "Namespace", r.BenchmarkCase.Descriptor.Type.Namespace }, { "Type", FullNameProvider.GetTypeName(r.BenchmarkCase.Descriptor.Type) }, { "Method", r.BenchmarkCase.Descriptor.WorkloadMethod.Name }, { "MethodTitle", r.BenchmarkCase.Descriptor.WorkloadMethodDisplayInfo }, { "Parameters", r.BenchmarkCase.Parameters.PrintInfo }, { "FullName", FullNameProvider.GetBenchmarkName(r.BenchmarkCase) }, // do NOT remove this property, it is used for xunit-performance migration // { "Properties", r.Benchmark.Job.ToSet().ToDictionary(p => p.Name, p => p.Value) }, // TODO { "Statistics", r.ResultStatistics } }; // We show MemoryDiagnoser's results only if it is being used if (summary.Config.HasMemoryDiagnoser()) { data.Add("Memory", r.GcStats); } if (ExcludeMeasurements == false) { // We construct Measurements manually, so that we can have the IterationMode enum as text, rather than an integer data.Add("Measurements", r.AllMeasurements.Select(m => new { IterationMode = m.IterationMode.ToString(), IterationStage = m.IterationStage.ToString(), m.LaunchIndex, m.IterationIndex, m.Operations, m.Nanoseconds })); } return(data); }); JsonSerializer.CurrentJsonSerializerStrategy.Indent = IndentJson; logger.WriteLine(JsonSerializer.SerializeObject(new Dictionary <string, object> { { "Title", summary.Title }, { "HostEnvironmentInfo", environmentInfo }, { "Benchmarks", benchmarks } })); }