Exemplo n.º 1
0
        public void CloseMetricCanBeZeroIfItDoesNotCreateAProfileEventThatStartsAndEndsAtTheSameMoment()
        {
            const double metric = 0.1;

            var samples = new[]
            {
                new SpeedScopeStackSourceWriter.Sample((StackSourceCallStackIndex)1, metric: metric, relativeTime: 0.1, depth: 0, callerFrameId: 0),
                new SpeedScopeStackSourceWriter.Sample((StackSourceCallStackIndex)1, metric: metric, relativeTime: 0.2, depth: 0, callerFrameId: 0),
                new SpeedScopeStackSourceWriter.Sample((StackSourceCallStackIndex)1, metric: 0.0, relativeTime: 0.3, depth: 0, callerFrameId: 0), // 0.0 metric
            };

            var input = new Dictionary <int, List <SpeedScopeStackSourceWriter.Sample> >()
            {
                { 0, samples.ToList() }
            };

            var aggregatedEvents = SpeedScopeStackSourceWriter.GetAggregatedOrderedProfileEvents(input);

            // we should have:
            //  Open at 0.1 depth 0 and Close 0.3
            Assert.Equal(2, aggregatedEvents.Count);

            Assert.Equal(SpeedScopeStackSourceWriter.ProfileEventType.Open, aggregatedEvents[0].Type);
            Assert.Equal(0.1, aggregatedEvents[0].RelativeTime);
            Assert.Equal(0, aggregatedEvents[0].Depth);

            Assert.Equal(SpeedScopeStackSourceWriter.ProfileEventType.Close, aggregatedEvents[1].Type);
            Assert.Equal(0.3, aggregatedEvents[1].RelativeTime);
            Assert.Equal(0, aggregatedEvents[0].Depth);
        }
Exemplo n.º 2
0
        public void TwoSamplesCanNotHappenAtTheSameTime()
        {
            const double zeroMetric   = 0.0;
            const double relativeTime = 0.1;

            var samples = new[]
            {
                new SpeedScopeStackSourceWriter.Sample((StackSourceCallStackIndex)1, metric: zeroMetric, relativeTime: relativeTime, depth: 0, callerFrameId: 0), // 0.0 metric
                new SpeedScopeStackSourceWriter.Sample((StackSourceCallStackIndex)1, metric: zeroMetric, relativeTime: relativeTime, depth: 0, callerFrameId: 0), // 0.0 metric and same relative time
            };

            var input = new Dictionary <int, List <SpeedScopeStackSourceWriter.Sample> >()
            {
                { 0, samples.ToList() }
            };

            Assert.Throws <ArgumentException>(() => SpeedScopeStackSourceWriter.GetAggregatedOrderedProfileEvents(input));
        }
Exemplo n.º 3
0
        public void GetAggregatedOrderedProfileEventsConvertsContinuousSamplesWithPausesToMultipleEvents()
        {
            const double metric = 0.1;

            var samples = new[]
            {
                new SpeedScopeStackSourceWriter.Sample((StackSourceCallStackIndex)1, callerFrameId: 0, metric: metric, depth: 0, relativeTime: 0.1),
                new SpeedScopeStackSourceWriter.Sample((StackSourceCallStackIndex)1, callerFrameId: 0, metric: metric, depth: 0, relativeTime: 0.2),

                new SpeedScopeStackSourceWriter.Sample((StackSourceCallStackIndex)1, callerFrameId: 0, metric: metric, depth: 0, relativeTime: 0.7),

                new SpeedScopeStackSourceWriter.Sample((StackSourceCallStackIndex)1, callerFrameId: 0, metric: metric, depth: 0, relativeTime: 1.1),
                new SpeedScopeStackSourceWriter.Sample((StackSourceCallStackIndex)1, callerFrameId: 0, metric: metric, depth: 0, relativeTime: 1.2),
                new SpeedScopeStackSourceWriter.Sample((StackSourceCallStackIndex)1, callerFrameId: 0, metric: metric, depth: 0, relativeTime: 1.3),
            };

            var input = new Dictionary <int, List <SpeedScopeStackSourceWriter.Sample> >()
            {
                { 0, samples.ToList() }
            };

            var aggregatedEvents = SpeedScopeStackSourceWriter.GetAggregatedOrderedProfileEvents(input);

            // we should have <0.1, 0.3> and <0.7, 0.8> (the tool would ignore <0.7, 0.7>) and <1.1, 1.4>
            Assert.Equal(6, aggregatedEvents.Count);

            Assert.Equal(0.1, aggregatedEvents[0].RelativeTime);
            Assert.Equal(SpeedScopeStackSourceWriter.ProfileEventType.Open, aggregatedEvents[0].Type);
            Assert.Equal(0.2 + metric, aggregatedEvents[1].RelativeTime);
            Assert.Equal(SpeedScopeStackSourceWriter.ProfileEventType.Close, aggregatedEvents[1].Type);

            Assert.Equal(0.7, aggregatedEvents[2].RelativeTime);
            Assert.Equal(SpeedScopeStackSourceWriter.ProfileEventType.Open, aggregatedEvents[2].Type);
            Assert.Equal(0.7 + metric, aggregatedEvents[3].RelativeTime);
            Assert.Equal(SpeedScopeStackSourceWriter.ProfileEventType.Close, aggregatedEvents[3].Type);

            Assert.Equal(1.1, aggregatedEvents[4].RelativeTime);
            Assert.Equal(SpeedScopeStackSourceWriter.ProfileEventType.Open, aggregatedEvents[4].Type);
            Assert.Equal(1.3 + metric, aggregatedEvents[5].RelativeTime);
            Assert.Equal(SpeedScopeStackSourceWriter.ProfileEventType.Close, aggregatedEvents[5].Type);
        }
Exemplo n.º 4
0
        public void GetAggregatedOrderedProfileEventsConvertsContinuousSamplesWithDifferentCallerIdToMultipleEvents()
        {
            const double metric = 0.1;

            var samples = new[]
            {
                new SpeedScopeStackSourceWriter.Sample((StackSourceCallStackIndex)1, metric: metric, relativeTime: 0.1, depth: 0, callerFrameId: 0),
                new SpeedScopeStackSourceWriter.Sample((StackSourceCallStackIndex)1, metric: metric, relativeTime: 0.2, depth: 0, callerFrameId: 1), // callerFrameId change!
            };

            var input = new Dictionary <int, List <SpeedScopeStackSourceWriter.Sample> >()
            {
                { 0, samples.ToList() }
            };

            var aggregatedEvents = SpeedScopeStackSourceWriter.GetAggregatedOrderedProfileEvents(input);

            // we should have:
            //  Open at 0.1 depth 0 and Close 0.2
            //  Open at 0.2 depth 0 and Close 0.3
            Assert.Equal(4, aggregatedEvents.Count);

            Assert.Equal(SpeedScopeStackSourceWriter.ProfileEventType.Open, aggregatedEvents[0].Type);
            Assert.Equal(0.1, aggregatedEvents[0].RelativeTime);
            Assert.Equal(0, aggregatedEvents[0].Depth);

            Assert.Equal(SpeedScopeStackSourceWriter.ProfileEventType.Close, aggregatedEvents[1].Type);
            Assert.Equal(0.1 + metric, aggregatedEvents[1].RelativeTime);
            Assert.Equal(0, aggregatedEvents[0].Depth);

            Assert.Equal(SpeedScopeStackSourceWriter.ProfileEventType.Open, aggregatedEvents[2].Type);
            Assert.Equal(0.2, aggregatedEvents[2].RelativeTime);
            Assert.Equal(0, aggregatedEvents[2].Depth);

            Assert.Equal(SpeedScopeStackSourceWriter.ProfileEventType.Close, aggregatedEvents[3].Type);
            Assert.Equal(0.2 + metric, aggregatedEvents[3].RelativeTime);
            Assert.Equal(0, aggregatedEvents[3].Depth);
        }