public void TransformSample_CallExpectedMethods() { var expectedMemoryPhysicalMetric = _metricBuilder.TryBuildMemoryPhysicalMetric(2); var expectedMemoryWorkingSetMetric = _metricBuilder.TryBuildMemoryWorkingSetMetric(4); var sample = new ImmutableMemorySample(2, 4); Transform(sample); Mock.Assert(() => _metricAggregator.Collect(expectedMemoryPhysicalMetric)); Mock.Assert(() => _metricAggregator.Collect(expectedMemoryWorkingSetMetric)); }
public void TransformSample_CreatesNoMemoryMetricsValueZero() { var generatedMetrics = new Dictionary <string, MetricDataWireModel>(); long expectedMemoryPhysicalValue = 0L; long expectedMemoryWorkingSetValue = 0L; Mock.Arrange(() => _metricAggregator.Collect(Arg.IsAny <MetricWireModel>())).DoInstead <MetricWireModel>(m => generatedMetrics.Add(m.MetricName.Name, m.Data)); var sample = new ImmutableMemorySample(expectedMemoryPhysicalValue, expectedMemoryWorkingSetValue); Transform(sample); Assert.IsEmpty(generatedMetrics); }
public void TransformSample_UsesAppropriateMemorySampleForPlatform(bool isWindows, float expectedMemoryPhysicalValue, float expectedWorkingSetValue) { var generatedMetrics = new Dictionary <string, MetricDataWireModel>(); Mock.Arrange(() => _metricAggregator.Collect(Arg.IsAny <MetricWireModel>())).DoInstead <MetricWireModel>(m => generatedMetrics.Add(m.MetricName.Name, m.Data)); var sample = new ImmutableMemorySample(PrivateBytesTestValue, WorkingSetTestValue); Transform(sample, isWindows); NrAssert.Multiple( () => Assert.AreEqual(2, generatedMetrics.Count), () => MetricTestHelpers.CompareMetric(generatedMetrics, MetricNames.MemoryPhysical, expectedMemoryPhysicalValue), () => MetricTestHelpers.CompareMetric(generatedMetrics, MetricNames.MemoryWorkingSet, expectedWorkingSetValue) ); }
public void TransformSample_CreatesUnscopedMetrics() { var generatedMetrics = new Dictionary <string, MetricDataWireModel>(); long expectedMemoryPhysicalValue = 2348987234L; float expectedMemoryPhysicalValueAsFloat = expectedMemoryPhysicalValue / BytesPerMb; long expectedMemoryWorkingSetValue = 42445745745L; float expectedMemoryWorkingSetValueAsFloat = expectedMemoryWorkingSetValue / BytesPerMb; Mock.Arrange(() => _metricAggregator.Collect(Arg.IsAny <MetricWireModel>())).DoInstead <MetricWireModel>(m => generatedMetrics.Add(m.MetricName.Name, m.Data)); var sample = new ImmutableMemorySample(expectedMemoryPhysicalValue, expectedMemoryWorkingSetValue); Transform(sample); NrAssert.Multiple( () => Assert.AreEqual(2, generatedMetrics.Count), () => MetricTestHelpers.CompareMetric(generatedMetrics, MetricNames.MemoryPhysical, expectedMemoryPhysicalValueAsFloat), () => MetricTestHelpers.CompareMetric(generatedMetrics, MetricNames.MemoryWorkingSet, expectedMemoryWorkingSetValueAsFloat) ); }
public void Transform(ImmutableMemorySample sample) { //Physical memory on windows is measured by PrivateBytes but on Linux it is better measured using WorkingSet. //This will allow us to report memory usage that more closely resembles the memory usage provided by tools //on both operating systems. //The physical memory metric is what supported out of the box by the APM UI. // Do not create metrics if memory values are 0 // Value may be 0 due to lack of support on called platform (i.e. Linux does not provide Process.PrivateMemorySize64 for older versions of .net core) if (sample.MemoryPrivate > 0 && _isWindows) { RecordMemoryPhysicalMetric(sample.MemoryPrivate); } if (sample.MemoryWorkingSet > 0) { RecordMemoryWorkingSetMetric(sample.MemoryWorkingSet); if (!_isWindows) { RecordMemoryPhysicalMetric(sample.MemoryWorkingSet); } } }
private void Transform(ImmutableMemorySample sample, bool isWindows) { var transformer = new MemorySampleTransformer(_metricBuilder, _metricAggregator, () => isWindows); transformer.Transform(sample); }
private void Transform(ImmutableMemorySample sample) { Transform(sample, true); }