From 052fe29037d04094ef91372c18861f6fa48822dc Mon Sep 17 00:00:00 2001 From: Steve Gordon Date: Thu, 9 Nov 2023 09:16:55 +0000 Subject: [PATCH] Fix formatting --- .../CgroupMetricsProviderBenchmarks.cs | 220 +++++++++--------- .../FreeAndTotalMemoryProviderBenchmarks.cs | 78 +++---- benchmarks/Elastic.Apm.Profiling/Program.cs | 22 +- .../Metrics/CgroupMetricsProviderTests.cs | 2 +- .../TestHelpers/CgroupFileHelper.cs | 4 +- 5 files changed, 163 insertions(+), 163 deletions(-) diff --git a/benchmarks/Elastic.Apm.Benchmarks/CgroupMetricsProviderBenchmarks.cs b/benchmarks/Elastic.Apm.Benchmarks/CgroupMetricsProviderBenchmarks.cs index 6c1fb51549..0ee56032a7 100644 --- a/benchmarks/Elastic.Apm.Benchmarks/CgroupMetricsProviderBenchmarks.cs +++ b/benchmarks/Elastic.Apm.Benchmarks/CgroupMetricsProviderBenchmarks.cs @@ -17,114 +17,114 @@ namespace Elastic.Apm.Benchmarks; [MemoryDiagnoser] public class CgroupMetricsProviderBenchmarks { - private CgroupPaths _cgroupPaths; - private CgroupMetricsProvider _cgroupMetricsProvider; - private readonly Consumer _consumer = new(); - - [GlobalSetup] - public void Setup() - { - _cgroupPaths = CreateDefaultCgroupFiles(CgroupVersion.CgroupV2); - _cgroupMetricsProvider = TestableCgroupMetricsProvider(new NoopLogger(), new List(), _cgroupPaths.RootPath, true); - } - - [GlobalSetup(Target = nameof(GetSamplesUnlimited))] - public void SetupUnlimited() - { - _cgroupPaths = CreateDefaultCgroupFiles(CgroupVersion.CgroupV2); - UnlimitedMaxMemoryFiles(_cgroupPaths); - _cgroupMetricsProvider = TestableCgroupMetricsProvider(new NoopLogger(), new List(), _cgroupPaths.RootPath, true); - } - - private static void UnlimitedMaxMemoryFiles(CgroupPaths paths) - { - if (paths.CgroupVersion == CgroupVersion.CgroupV1) - { - using var sr = new StreamWriter(File.Create(Path.Combine(paths.CgroupV1MemoryControllerPath, "memory.limit_in_bytes"))); - sr.WriteAsync($"9223372036854771712\n"); - } - - if (paths.CgroupVersion == CgroupVersion.CgroupV2) - { - using var sr = new StreamWriter(File.Create(Path.Combine(paths.CgroupV2SlicePath, "memory.max"))); - sr.WriteAsync($"max\n"); - } - } - - [GlobalCleanup] - public void Cleanup() - => Directory.Delete(_cgroupPaths.RootPath, true); - - [Benchmark] - public void GetSamples() - { - foreach (var metricSet in _cgroupMetricsProvider.GetSamples()) - { - metricSet.Samples.Consume(_consumer); - } - } - - // 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% | - - // 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% | - - // WINDOWS: Remove metric - //| Method | Mean | Error | StdDev | Allocated | Alloc Ratio | - //|-------------------- |---------:|--------:|--------:|----------:|------------:| - //| GetSamples | 296.9 us | 3.46 us | 3.23 us | 1.05 KB | -96% | - - // 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% | - - // LINUX: Remove metric - //| Method | Mean | Error | Ratio | StdDev | Gen0 | Allocated | Alloc Ratio | - //|-------------------- |---------:|----------:|---------:|----------:|-------:|----------:| | - //| GetSamples | 4.363 us | 0.0458 us | -55% | 0.0382 us | 0.0381 | 496 B | -98% | - - [Benchmark] - public void GetSamplesUnlimited() - { - foreach (var metricSet in _cgroupMetricsProvider.GetSamples()) - { - metricSet.Samples.Consume(_consumer); - } - } - - // WINDOWS: - //| Method | Mean | Error | StdDev | Gen0 | Allocated | - //|-------------------- |---------:|--------:|--------:|-------:|----------:| - //| GetSamplesUnlimited | 467.1 us | 9.28 us | 9.11 us | 0.4883 | 9.5 KB | - - // WINDOWS: Optimised - //| Method | Mean | Error | StdDev | Allocated | - //|-------------------- |---------:|--------:|--------:|----------:| - //| GetSamplesUnlimited | 444.9 us | 8.46 us | 8.69 us | 1.88 KB | - - // WINDOWS: Remove metric - //| Method | Mean | Error | StdDev | Allocated | Alloc Ratio | - //|-------------------- |---------:|--------:|--------:|----------:| | - //| GetSamplesUnlimited | 305.4 us | 5.04 us | 4.71 us | 1.43 KB | -85% | - - // LINUX: Optimised - //| Method | Mean | Error | StdDev | Gen0 | Allocated | - //|-------------------- |---------:|----------:|----------:|-------:|----------:| - //| GetSamplesUnlimited | 7.217 us | 0.1375 us | 0.1350 us | 0.0687 | 864 B | - //** NOTE: This includes some overhead (176 bytes) for building the test path which is not incurred - //in production. This is there equivient to the limited benchmark when this is taken into account. - - // LINUX: Remove metric - //| Method | Mean | Error | StdDev | Gen0 | Allocated | - //|-------------------- |---------:|----------:|----------:|-------:|----------:| - //| GetSamplesUnlimited | 4.908 us | 0.0736 us | 0.0688 us | 0.0534 | 680 B | + private CgroupPaths _cgroupPaths; + private CgroupMetricsProvider _cgroupMetricsProvider; + private readonly Consumer _consumer = new(); + + [GlobalSetup] + public void Setup() + { + _cgroupPaths = CreateDefaultCgroupFiles(CgroupVersion.CgroupV2); + _cgroupMetricsProvider = TestableCgroupMetricsProvider(new NoopLogger(), new List(), _cgroupPaths.RootPath, true); + } + + [GlobalSetup(Target = nameof(GetSamplesUnlimited))] + public void SetupUnlimited() + { + _cgroupPaths = CreateDefaultCgroupFiles(CgroupVersion.CgroupV2); + UnlimitedMaxMemoryFiles(_cgroupPaths); + _cgroupMetricsProvider = TestableCgroupMetricsProvider(new NoopLogger(), new List(), _cgroupPaths.RootPath, true); + } + + private static void UnlimitedMaxMemoryFiles(CgroupPaths paths) + { + if (paths.CgroupVersion == CgroupVersion.CgroupV1) + { + using var sr = new StreamWriter(File.Create(Path.Combine(paths.CgroupV1MemoryControllerPath, "memory.limit_in_bytes"))); + sr.WriteAsync($"9223372036854771712\n"); + } + + if (paths.CgroupVersion == CgroupVersion.CgroupV2) + { + using var sr = new StreamWriter(File.Create(Path.Combine(paths.CgroupV2SlicePath, "memory.max"))); + sr.WriteAsync($"max\n"); + } + } + + [GlobalCleanup] + public void Cleanup() + => Directory.Delete(_cgroupPaths.RootPath, true); + + [Benchmark] + public void GetSamples() + { + foreach (var metricSet in _cgroupMetricsProvider.GetSamples()) + { + metricSet.Samples.Consume(_consumer); + } + } + + // 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% | + + // 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% | + + // WINDOWS: Remove metric + //| Method | Mean | Error | StdDev | Allocated | Alloc Ratio | + //|-------------------- |---------:|--------:|--------:|----------:|------------:| + //| GetSamples | 296.9 us | 3.46 us | 3.23 us | 1.05 KB | -96% | + + // 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% | + + // LINUX: Remove metric + //| Method | Mean | Error | Ratio | StdDev | Gen0 | Allocated | Alloc Ratio | + //|-------------------- |---------:|----------:|---------:|----------:|-------:|----------:| | + //| GetSamples | 4.363 us | 0.0458 us | -55% | 0.0382 us | 0.0381 | 496 B | -98% | + + [Benchmark] + public void GetSamplesUnlimited() + { + foreach (var metricSet in _cgroupMetricsProvider.GetSamples()) + { + metricSet.Samples.Consume(_consumer); + } + } + + // WINDOWS: + //| Method | Mean | Error | StdDev | Gen0 | Allocated | + //|-------------------- |---------:|--------:|--------:|-------:|----------:| + //| GetSamplesUnlimited | 467.1 us | 9.28 us | 9.11 us | 0.4883 | 9.5 KB | + + // WINDOWS: Optimised + //| Method | Mean | Error | StdDev | Allocated | + //|-------------------- |---------:|--------:|--------:|----------:| + //| GetSamplesUnlimited | 444.9 us | 8.46 us | 8.69 us | 1.88 KB | + + // WINDOWS: Remove metric + //| Method | Mean | Error | StdDev | Allocated | Alloc Ratio | + //|-------------------- |---------:|--------:|--------:|----------:| | + //| GetSamplesUnlimited | 305.4 us | 5.04 us | 4.71 us | 1.43 KB | -85% | + + // LINUX: Optimised + //| Method | Mean | Error | StdDev | Gen0 | Allocated | + //|-------------------- |---------:|----------:|----------:|-------:|----------:| + //| GetSamplesUnlimited | 7.217 us | 0.1375 us | 0.1350 us | 0.0687 | 864 B | + //** NOTE: This includes some overhead (176 bytes) for building the test path which is not incurred + //in production. This is there equivient to the limited benchmark when this is taken into account. + + // LINUX: Remove metric + //| Method | Mean | Error | StdDev | Gen0 | Allocated | + //|-------------------- |---------:|----------:|----------:|-------:|----------:| + //| GetSamplesUnlimited | 4.908 us | 0.0736 us | 0.0688 us | 0.0534 | 680 B | } diff --git a/benchmarks/Elastic.Apm.Benchmarks/FreeAndTotalMemoryProviderBenchmarks.cs b/benchmarks/Elastic.Apm.Benchmarks/FreeAndTotalMemoryProviderBenchmarks.cs index f74c8ee312..bf38de9d69 100644 --- a/benchmarks/Elastic.Apm.Benchmarks/FreeAndTotalMemoryProviderBenchmarks.cs +++ b/benchmarks/Elastic.Apm.Benchmarks/FreeAndTotalMemoryProviderBenchmarks.cs @@ -16,49 +16,49 @@ namespace Elastic.Apm.Benchmarks; [MemoryDiagnoser] public class FreeAndTotalMemoryProviderBenchmarks { - private CgroupPaths _cgroupPaths; - private FreeAndTotalMemoryProvider _freeAndTotalMemoryProvider; - private readonly Consumer _consumer = new(); + private CgroupPaths _cgroupPaths; + private FreeAndTotalMemoryProvider _freeAndTotalMemoryProvider; + private readonly Consumer _consumer = new(); - [GlobalSetup] - public void Setup() - { - _cgroupPaths = CreateDefaultCgroupFiles(CgroupVersion.CgroupV2); - _freeAndTotalMemoryProvider = FreeAndTotalMemoryProvider - .TestableFreeAndTotalMemoryProvider(new NoopLogger(), new List(), _cgroupPaths.RootPath, true); - } + [GlobalSetup] + public void Setup() + { + _cgroupPaths = CreateDefaultCgroupFiles(CgroupVersion.CgroupV2); + _freeAndTotalMemoryProvider = FreeAndTotalMemoryProvider + .TestableFreeAndTotalMemoryProvider(new NoopLogger(), new List(), _cgroupPaths.RootPath, true); + } - [GlobalCleanup] - public void Cleanup() - => Directory.Delete(_cgroupPaths.RootPath, true); + [GlobalCleanup] + public void Cleanup() + => Directory.Delete(_cgroupPaths.RootPath, true); - //[Benchmark(Baseline = true)] - //public void GetSamplesOriginal() - //{ - // foreach (var metricSet in _freeAndTotalMemoryProvider.GetSamplesOriginal()) - // { - // metricSet.Samples.Consume(_consumer); - // } - //} + //[Benchmark(Baseline = true)] + //public void GetSamplesOriginal() + //{ + // foreach (var metricSet in _freeAndTotalMemoryProvider.GetSamplesOriginal()) + // { + // metricSet.Samples.Consume(_consumer); + // } + //} - [Benchmark] - public void GetSamples() - { - foreach (var metricSet in _freeAndTotalMemoryProvider.GetSamples()) - { - metricSet.Samples.Consume(_consumer); - } - } + [Benchmark] + public void GetSamples() + { + foreach (var metricSet in _freeAndTotalMemoryProvider.GetSamples()) + { + metricSet.Samples.Consume(_consumer); + } + } - // WINDOWS - //| Method | Mean | Error | StdDev | Ratio | RatioSD | Gen0 | Allocated | Alloc Ratio | - //|------------------- |---------:|---------:|---------:|---------:|--------:|-------:|----------:|------------:| - //| GetSamplesOriginal | 600.1 ns | 12.00 ns | 17.22 ns | baseline | | 0.0277 | 352 B | | - //| GetSamples | 553.8 ns | 10.57 ns | 12.98 ns | -8% | 3.2% | 0.0162 | 208 B | -41% | + // WINDOWS + //| Method | Mean | Error | StdDev | Ratio | RatioSD | Gen0 | Allocated | Alloc Ratio | + //|------------------- |---------:|---------:|---------:|---------:|--------:|-------:|----------:|------------:| + //| GetSamplesOriginal | 600.1 ns | 12.00 ns | 17.22 ns | baseline | | 0.0277 | 352 B | | + //| GetSamples | 553.8 ns | 10.57 ns | 12.98 ns | -8% | 3.2% | 0.0162 | 208 B | -41% | - // LINUX - //| Method | Mean | Error | StdDev | Ratio | RatioSD | Gen0 | Gen1 | Allocated | Alloc Ratio | - //|------------------- |-----------:|---------:|----------:|---------:|--------:|-------:|-------:|----------:|------------:| - //| GetSamplesOriginal | 3,693.2 ns | 73.86 ns | 108.27 ns | baseline | | 0.7324 | 0.0191 | 9216 B | | - //| GetSamples | 438.7 ns | 8.57 ns | 8.41 ns | -88% | 3.1% | 0.0215 | - | 272 B | -97% | + // LINUX + //| Method | Mean | Error | StdDev | Ratio | RatioSD | Gen0 | Gen1 | Allocated | Alloc Ratio | + //|------------------- |-----------:|---------:|----------:|---------:|--------:|-------:|-------:|----------:|------------:| + //| GetSamplesOriginal | 3,693.2 ns | 73.86 ns | 108.27 ns | baseline | | 0.7324 | 0.0191 | 9216 B | | + //| GetSamples | 438.7 ns | 8.57 ns | 8.41 ns | -88% | 3.1% | 0.0215 | - | 272 B | -97% | } diff --git a/benchmarks/Elastic.Apm.Profiling/Program.cs b/benchmarks/Elastic.Apm.Profiling/Program.cs index c6ec7f9869..78f6bfcf19 100644 --- a/benchmarks/Elastic.Apm.Profiling/Program.cs +++ b/benchmarks/Elastic.Apm.Profiling/Program.cs @@ -43,17 +43,17 @@ static void UnlimitedMaxMemoryFiles(CgroupPaths paths) { - if (paths.CgroupVersion == CgroupVersion.CgroupV1) - { - using var sr = new StreamWriter(File.Create(Path.Combine(paths.CgroupV1MemoryControllerPath, "memory.limit_in_bytes"))); - sr.WriteAsync($"9223372036854771712\n"); - } - - if (paths.CgroupVersion == CgroupVersion.CgroupV2) - { - using var sr = new StreamWriter(File.Create(Path.Combine(paths.CgroupV2SlicePath, "memory.max"))); - sr.WriteAsync($"max\n"); - } + if (paths.CgroupVersion == CgroupVersion.CgroupV1) + { + using var sr = new StreamWriter(File.Create(Path.Combine(paths.CgroupV1MemoryControllerPath, "memory.limit_in_bytes"))); + sr.WriteAsync($"9223372036854771712\n"); + } + + if (paths.CgroupVersion == CgroupVersion.CgroupV2) + { + using var sr = new StreamWriter(File.Create(Path.Combine(paths.CgroupV2SlicePath, "memory.max"))); + sr.WriteAsync($"max\n"); + } } internal sealed class NoopLogger : IApmLogger diff --git a/test/Elastic.Apm.Tests/Metrics/CgroupMetricsProviderTests.cs b/test/Elastic.Apm.Tests/Metrics/CgroupMetricsProviderTests.cs index c6ea06b0c9..0aeecfa2b5 100644 --- a/test/Elastic.Apm.Tests/Metrics/CgroupMetricsProviderTests.cs +++ b/test/Elastic.Apm.Tests/Metrics/CgroupMetricsProviderTests.cs @@ -53,7 +53,7 @@ public void TestLimitedCgroup1() public void TestLimitedCgroup2() { using var paths = CreateDefaultCgroupFiles(CgroupVersion.CgroupV2); - + var sut = TestableCgroupMetricsProvider(new NoopLogger(), new List(), paths.RootPath, true); var samples = sut.GetSamples().ToList(); diff --git a/test/Elastic.Apm.Tests/TestHelpers/CgroupFileHelper.cs b/test/Elastic.Apm.Tests/TestHelpers/CgroupFileHelper.cs index b527f972b0..7c8eb509f2 100644 --- a/test/Elastic.Apm.Tests/TestHelpers/CgroupFileHelper.cs +++ b/test/Elastic.Apm.Tests/TestHelpers/CgroupFileHelper.cs @@ -14,7 +14,7 @@ internal static class CgroupFileHelper internal sealed class CgroupPaths : IDisposable { public CgroupPaths(CgroupVersion cgroupVersion) => CgroupVersion = cgroupVersion; - + public CgroupVersion CgroupVersion { get; } public string RootPath { get; set; } public string ProcPath { get; set; } @@ -107,7 +107,7 @@ public static CgroupPaths CreateDefaultCgroupFiles(CgroupVersion cgroupVersion) memoryLimitInBytes.WriteAsync($"{DefaultMemoryLimitBytes}\n"); memoryLimitInBytes.Flush(); } - + using (var cgroup = new StreamWriter(File.Create(Path.Combine(procSelfPath, "mountinfo")))) { sb.Clear();