Example #1
0
        public void TransformSample_ThreadpoolUsageStats_CreatesCorrectMetricValues()
        {
            const int countWorkerThreadsRemaining     = 83;
            const int countWorkerThreadsInUse         = 17;
            const int countCompletionThreadsRemaining = 180;
            const int countCompletionThreadsInUse     = 20;

            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 ThreadpoolUsageStatsSample(countWorkerThreadsRemaining + countWorkerThreadsInUse, countWorkerThreadsRemaining, countCompletionThreadsRemaining + countCompletionThreadsInUse, countCompletionThreadsRemaining);

            _threadStatsTransformer.Transform(sample);

            NrAssert.Multiple(
                () => Assert.AreEqual(4, generatedMetrics.Count),
                () => MetricTestHelpers.CompareMetric(generatedMetrics, MetricNames.GetThreadpoolUsageStatsName(ThreadType.Worker, ThreadStatus.InUse), countWorkerThreadsInUse),
                () => MetricTestHelpers.CompareMetric(generatedMetrics, MetricNames.GetThreadpoolUsageStatsName(ThreadType.Worker, ThreadStatus.Available), countWorkerThreadsRemaining),
                () => MetricTestHelpers.CompareMetric(generatedMetrics, MetricNames.GetThreadpoolUsageStatsName(ThreadType.Completion, ThreadStatus.InUse), countCompletionThreadsInUse),
                () => MetricTestHelpers.CompareMetric(generatedMetrics, MetricNames.GetThreadpoolUsageStatsName(ThreadType.Completion, ThreadStatus.Available), countCompletionThreadsRemaining)
                );
        }
        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)
                );
        }
Example #4
0
        public void TransformSample_ThreadpoolThroughputStats_CreatesCorrectMetricValues()
        {
            const int countThreadRequestsQueued     = 5;
            const int countThreadRequestsDequeued   = 7;
            const int countThreadRequestQueueLength = 19;

            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 ThreadpoolThroughputEventsSample(countThreadRequestsQueued, countThreadRequestsDequeued, countThreadRequestQueueLength);

            _threadStatsTransformer.Transform(sample);

            NrAssert.Multiple(
                () => Assert.AreEqual(3, generatedMetrics.Count),
                () => MetricTestHelpers.CompareMetric(generatedMetrics, MetricNames.GetThreadpoolThroughputStatsName(ThreadpoolThroughputStatsType.Requested), countThreadRequestsQueued),
                () => MetricTestHelpers.CompareMetric(generatedMetrics, MetricNames.GetThreadpoolThroughputStatsName(ThreadpoolThroughputStatsType.Started), countThreadRequestsDequeued),
                () => MetricTestHelpers.CompareMetric(generatedMetrics, MetricNames.GetThreadpoolThroughputStatsName(ThreadpoolThroughputStatsType.QueueLength), countThreadRequestQueueLength)
                );
        }