From 58e99f9a683b0e59e15cec54f5176d46dd83b799 Mon Sep 17 00:00:00 2001 From: Steve Gordon Date: Tue, 7 Nov 2023 13:46:26 +0000 Subject: [PATCH] WIP --- .../CgroupMetricsProviderBenchmarks.cs | 9 +++- benchmarks/Elastic.Apm.Profiling/Program.cs | 52 +++++-------------- 2 files changed, 22 insertions(+), 39 deletions(-) diff --git a/benchmarks/Elastic.Apm.Benchmarks/CgroupMetricsProviderBenchmarks.cs b/benchmarks/Elastic.Apm.Benchmarks/CgroupMetricsProviderBenchmarks.cs index 318dff688..d00ed31cc 100644 --- a/benchmarks/Elastic.Apm.Benchmarks/CgroupMetricsProviderBenchmarks.cs +++ b/benchmarks/Elastic.Apm.Benchmarks/CgroupMetricsProviderBenchmarks.cs @@ -93,17 +93,24 @@ public void GetSamplesOptimised() } } + // WINDOWS: //| Method | Mean | Error | StdDev | Ratio | RatioSD | Gen0 | Allocated | Alloc Ratio | //|-------------------- |---------:|--------:|---------:|---------:|--------:|-------:|----------:|------------:| //| GetSamplesOriginal | 433.0 us | 8.39 us | 11.20 us | baseline | | 1.9531 | 29.4 KB | | //| GetSamplesOptimised | 409.9 us | 5.11 us | 4.53 us | -5% | 3.0% | - | 1.47 KB | -95% | - // Yield return + // WINDOWS: After yield return //| Method | Mean | Error | StdDev | Ratio | RatioSD | Gen0 | Allocated | Alloc Ratio | //|-------------------- |---------:|--------:|---------:|---------:|--------:|-------:|----------:|------------:| //| GetSamplesOriginal | 429.1 us | 8.08 us | 13.93 us | baseline | | 1.9531 | 29.44 KB | | //| GetSamplesOptimised | 419.7 us | 6.83 us | 6.39 us | -5% | 3.3% | - | 1.46 KB | -95% | + // LINUX: After yield return + //| Method | Mean | Error | StdDev | Ratio | RatioSD | Gen0 | Gen1 | Allocated | Alloc Ratio | + //|-------------------- |---------:|----------:|----------:|---------:|--------:|-------:|-------:|----------:|------------:| + //| GetSamplesOriginal | 9.643 us | 0.1600 us | 0.1418 us | baseline | | 2.3346 | 0.0610 | 29328 B | | + //| GetSamplesOptimised | 5.525 us | 0.0580 us | 0.0569 us | -43% | 1.6% | 0.0534 | - | 680 B | -98% | + // Optimised //| Method | Mean | Error | StdDev | Allocated | //|----------- |---------:|--------:|--------:|----------:| diff --git a/benchmarks/Elastic.Apm.Profiling/Program.cs b/benchmarks/Elastic.Apm.Profiling/Program.cs index 991742428..35ef9ee18 100644 --- a/benchmarks/Elastic.Apm.Profiling/Program.cs +++ b/benchmarks/Elastic.Apm.Profiling/Program.cs @@ -5,66 +5,42 @@ using static Elastic.Apm.Metrics.MetricsProvider.CgroupMetricsProvider; using Elastic.Apm.Logging; -//await DotMemory.EnsurePrerequisiteAsync(); +await DotMemory.EnsurePrerequisiteAsync(); +var path = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.UserProfile), "dotTrace"); +Console.WriteLine($"Saving to {path}"); -var paths = CreateDefaultGroupFiles(); - -//var config = new DotMemory.Config(); -//config.SaveToDir("C:\\Users\\SteveGordon\\Code\\Profiles"); - -//DotMemory.Attach(config); +var config = new DotMemory.Config(); +config.SaveToDir(path); -//DotMemory.GetSnapshot("Before create"); - -//Console.ReadKey(); +var paths = CreateDefaultGroupFiles(); +// WARMUP var sut = TestableCgroupMetricsProvider(new NoopLogger(), new List(), paths.RootPath, true); - -Console.WriteLine("Snapshot"); -Console.ReadKey(); - -Thread.Sleep(5000); - -sut = TestableCgroupMetricsProvider(new NoopLogger(), new List(), paths.RootPath, true); - -Thread.Sleep(3000); - -Console.WriteLine("Snapshot"); -Console.ReadKey(); - -//DotMemory.GetSnapshot("After create"); - foreach (var metricSet in sut.GetSamples()) foreach (var _ in metricSet.Samples) { } -Console.WriteLine("Snapshot"); -Console.ReadKey(); +DotMemory.Attach(config); +DotMemory.GetSnapshot("Before create"); + +sut = TestableCgroupMetricsProvider(new NoopLogger(), new List(), paths.RootPath, true); -Thread.Sleep(5000); +DotMemory.GetSnapshot("After create"); foreach (var metricSet in sut.GetSamples()) foreach (var _ in metricSet.Samples) { } -Thread.Sleep(3000); +DotMemory.GetSnapshot("After get samples"); -Console.WriteLine("Snapshot"); -Console.ReadKey(); - -//DotMemory.GetSnapshot("After get samples"); - -//DotMemory.Detach(); - -//Console.ReadKey(); +DotMemory.Detach(); Directory.Delete(paths.RootPath, true); internal sealed class NoopLogger : IApmLogger { public bool IsEnabled(LogLevel level) => false; - public void Log(LogLevel level, TState state, Exception e, Func formatter) { } }