Exemple #1
0
        public void WalkTheStackAndExpandSamplesHandlesBrokenStacks(StackSourceFrameIndex kind)
        {
            // Main() calls WRONG
            const double relativeTime = 0.1;
            var          main         = new FakeStackSourceSample(
                relativeTime: relativeTime,
                name: "Main",
                frameIndex: (StackSourceFrameIndex)5,     // 5 is first non-taken enum value
                stackIndex: (StackSourceCallStackIndex)1, // 1 is first non-taken enum value
                callerIndex: StackSourceCallStackIndex.Invalid);
            var wrong = new FakeStackSourceSample(
                relativeTime: relativeTime,
                name: "WRONG",
                frameIndex: kind,
                stackIndex: (StackSourceCallStackIndex)2,
                callerIndex: main.StackIndex);

            var allSamples    = new[] { main, wrong };
            var leafs         = new[] { new Sample(wrong.StackIndex, -1, wrong.RelativeTime, wrong.Metric, -1) };
            var stackSource   = new StackSourceStub(allSamples);
            var frameNameToId = new Dictionary <string, int>();

            var frameIdToSamples = WalkTheStackAndExpandSamples(stackSource, leafs, frameNameToId, new Dictionary <int, FrameInfo>());

            Assert.Equal(0, frameNameToId[main.Name]);
            Assert.False(frameNameToId.ContainsKey(wrong.Name));

            var theOnlySample = frameIdToSamples.Single().Value.Single();

            Assert.Equal(relativeTime, theOnlySample.RelativeTime);
            Assert.Equal(0, theOnlySample.Depth);
        }
Exemple #2
0
        public void GetSortedSamplesReturnsSamplesSortedByRelativeTimeAndGrouppedByThreadWithProcessInfo(string processName, int expectedProcessId)
        {
            const string ThreadName = "Thread (123)";

            var process = new FakeStackSourceSample(
                relativeTime: 0.1,
                name: processName,
                frameIndex: (StackSourceFrameIndex)5,     // 5 is first non-taken enum value
                stackIndex: (StackSourceCallStackIndex)1, // 1 is first non-taken enum value
                callerIndex: StackSourceCallStackIndex.Invalid);
            var thread_1 = new FakeStackSourceSample(
                relativeTime: 0.1,
                name: ThreadName,
                frameIndex: (StackSourceFrameIndex)6,
                stackIndex: (StackSourceCallStackIndex)2,
                callerIndex: process.StackIndex);
            var a_1 = new FakeStackSourceSample(
                relativeTime: 0.1,
                name: "A",
                frameIndex: (StackSourceFrameIndex)7,
                stackIndex: (StackSourceCallStackIndex)3,
                callerIndex: thread_1.StackIndex);
            var thread_2 = new FakeStackSourceSample(
                relativeTime: 0.2,
                name: ThreadName,
                frameIndex: (StackSourceFrameIndex)6,
                stackIndex: (StackSourceCallStackIndex)4,
                callerIndex: process.StackIndex);
            var a_2 = new FakeStackSourceSample(
                relativeTime: 0.2,
                name: "A",
                frameIndex: (StackSourceFrameIndex)7,
                stackIndex: (StackSourceCallStackIndex)5,
                callerIndex: thread_2.StackIndex);

            var sourceSamples = new[] { process, thread_1, thread_2, a_2, a_1 };

            var stackSource = new StackSourceStub(sourceSamples);

            var result = GetSortedSamplesPerThread(stackSource)[new ThreadInfo(ThreadName, 123, expectedProcessId)];

            Assert.Equal(0.1, result[0].RelativeTime);
            Assert.Equal(0.1, result[1].RelativeTime);
            Assert.Equal(0.2, result[2].RelativeTime);
            Assert.Equal(0.2, result[2].RelativeTime);
        }
Exemple #3
0
        public void WalkTheStackAndExpandSamplesProducesFullInformation()
        {
            // Main() calls A() calls B()
            const double relativeTime = 0.1;
            var          main         = new FakeStackSourceSample(
                relativeTime: relativeTime,
                name: "Main",
                frameIndex: (StackSourceFrameIndex)5,     // 5 is first non-taken enum value
                stackIndex: (StackSourceCallStackIndex)1, // 1 is first non-taken enum value
                callerIndex: StackSourceCallStackIndex.Invalid);
            var a = new FakeStackSourceSample(
                relativeTime: relativeTime,
                name: "A",
                frameIndex: (StackSourceFrameIndex)6,
                stackIndex: (StackSourceCallStackIndex)2,
                callerIndex: main.StackIndex);
            var b = new FakeStackSourceSample(
                relativeTime: relativeTime,
                name: "B",
                frameIndex: (StackSourceFrameIndex)7,
                stackIndex: (StackSourceCallStackIndex)3,
                callerIndex: a.StackIndex);

            var allSamples    = new[] { main, a, b };
            var leafs         = new[] { new Sample(b.StackIndex, -1, b.RelativeTime, b.Metric, -1) };
            var stackSource   = new StackSourceStub(allSamples);
            var frameNameToId = new Dictionary <string, int>();

            var frameIdToSamples = WalkTheStackAndExpandSamples(stackSource, leafs, frameNameToId, new Dictionary <int, FrameInfo>());

            Assert.Equal(0, frameNameToId[main.Name]);
            Assert.Equal(1, frameNameToId[a.Name]);
            Assert.Equal(2, frameNameToId[b.Name]);

            Assert.All(frameIdToSamples.Select(pair => pair.Value), samples => Assert.Equal(relativeTime, samples.Single().RelativeTime));
            Assert.Equal(0, frameIdToSamples[0].Single().Depth);
            Assert.Equal(1, frameIdToSamples[1].Single().Depth);
            Assert.Equal(2, frameIdToSamples[2].Single().Depth);
        }
        public void GetSortedSamplesReturnsSamplesSortedByRelativeTimeAndGrouppedByThread()
        {
            const string ThreadName = "Thread (123)";
            var          thread_1   = new FakeStackSourceSample(
                relativeTime: 0.1,
                name: ThreadName,
                frameIndex: (StackSourceFrameIndex)5,     // 5 is first non-taken enum value
                stackIndex: (StackSourceCallStackIndex)1, // 1 is first non-taken enum value
                callerIndex: StackSourceCallStackIndex.Invalid);
            var a_1 = new FakeStackSourceSample(
                relativeTime: 0.1,
                name: "A",
                frameIndex: (StackSourceFrameIndex)6,
                stackIndex: (StackSourceCallStackIndex)2,
                callerIndex: thread_1.StackIndex);
            var thread_2 = new FakeStackSourceSample(
                relativeTime: 0.2,
                name: ThreadName,
                frameIndex: (StackSourceFrameIndex)5,     // 5 is first non-taken enum value
                stackIndex: (StackSourceCallStackIndex)3, // 1 is first non-taken enum value
                callerIndex: StackSourceCallStackIndex.Invalid);
            var a_2 = new FakeStackSourceSample(
                relativeTime: 0.2,
                name: "A",
                frameIndex: (StackSourceFrameIndex)6,
                stackIndex: (StackSourceCallStackIndex)4,
                callerIndex: thread_2.StackIndex);

            var sourceSamples = new[] { thread_1, thread_2, a_2, a_1 };

            var stackSource = new StackSourceStub(sourceSamples);

            var result = SpeedScopeStackSourceWriter.GetSortedSamplesPerThread(stackSource)[ThreadName];

            Assert.Equal(0.1, result[0].RelativeTime);
            Assert.Equal(0.1, result[1].RelativeTime);
            Assert.Equal(0.2, result[2].RelativeTime);
            Assert.Equal(0.2, result[2].RelativeTime);
        }
Exemple #5
0
        public void EndToEnd(string processName, int expectedProcessId)
        {
            const string ThreadName   = "Thread (123)";
            const string MethodName   = "A";
            const double relativeTime = 0.1;
            const float  metric       = 0.1f;

            // we have two samples here:
            // processName -> ThreadName() => MehtodName() starting at 0.1 and lasting 0.1
            // processName -> ThreadName() => MehtodName() starting at 0.2 and lasting 0.1

            var process_1 = new FakeStackSourceSample(
                isLastOnCallStack: false,
                relativeTime: relativeTime,
                metric: metric,
                name: processName,
                frameIndex: (StackSourceFrameIndex)5,     // 5 is first non-taken enum value
                stackIndex: (StackSourceCallStackIndex)1, // 1 is first non-taken enum value
                callerIndex: StackSourceCallStackIndex.Invalid);
            var thread_1 = new FakeStackSourceSample(
                isLastOnCallStack: false,
                relativeTime: process_1.RelativeTime,
                metric: process_1.Metric,
                name: ThreadName,
                frameIndex: (StackSourceFrameIndex)6,
                stackIndex: (StackSourceCallStackIndex)2,
                callerIndex: process_1.StackIndex);
            var a_1 = new FakeStackSourceSample(
                isLastOnCallStack: true,
                relativeTime: thread_1.RelativeTime,
                metric: thread_1.Metric,
                name: MethodName,
                frameIndex: (StackSourceFrameIndex)7,
                stackIndex: (StackSourceCallStackIndex)3,
                callerIndex: thread_1.StackIndex);

            var process_2 = new FakeStackSourceSample(
                isLastOnCallStack: false,
                relativeTime: relativeTime * 2,
                metric: metric,
                name: processName,
                frameIndex: (StackSourceFrameIndex)5,     // 5 is first non-taken enum value
                stackIndex: (StackSourceCallStackIndex)1, // 1 is first non-taken enum value
                callerIndex: StackSourceCallStackIndex.Invalid);
            var thread_2 = new FakeStackSourceSample(
                isLastOnCallStack: false,
                relativeTime: process_2.RelativeTime,
                metric: process_2.Metric,
                name: ThreadName,
                frameIndex: (StackSourceFrameIndex)6,
                stackIndex: (StackSourceCallStackIndex)4,
                callerIndex: process_2.StackIndex);
            var a_2 = new FakeStackSourceSample(
                isLastOnCallStack: true,
                relativeTime: thread_2.RelativeTime,
                metric: thread_2.Metric,
                name: MethodName,
                frameIndex: (StackSourceFrameIndex)7,
                stackIndex: (StackSourceCallStackIndex)5,
                callerIndex: thread_2.StackIndex);

            var sourceSamples = new[] { process_1, thread_1, a_1, process_2, thread_2, a_2 };

            var stackSource = new StackSourceStub(sourceSamples);

            var leafs = GetSortedSamplesPerThread(stackSource)[new ThreadInfo(ThreadName, 123, expectedProcessId)];

            Assert.Equal(relativeTime, leafs[0].RelativeTime);
            Assert.Equal(metric, leafs[0].Metric);
            Assert.Equal(relativeTime * 2, leafs[1].RelativeTime);
            Assert.Equal(metric, leafs[1].Metric);

            var frameNameToId = new Dictionary <string, int>();
            var profileEvents = GetProfileEvents(stackSource, leafs, frameNameToId, new Dictionary <int, FrameInfo>());

            // first: opening the Process at time 0.1
            var openProcess = profileEvents[0];

            Assert.Equal(ProfileEventType.Open, openProcess.Type);
            Assert.Equal(process_1.RelativeTime, openProcess.RelativeTime);
            Assert.Equal(0, openProcess.Depth);
            Assert.Equal(0, openProcess.FrameId);
            Assert.Equal(openProcess.FrameId, frameNameToId[process_1.Name]);

            // second: opening the Thread at time 0.1
            var openThread = profileEvents[1];

            Assert.Equal(ProfileEventType.Open, openThread.Type);
            Assert.Equal(thread_1.RelativeTime, openThread.RelativeTime);
            Assert.Equal(1, openThread.Depth);
            Assert.Equal(1, openThread.FrameId);
            Assert.Equal(openThread.FrameId, frameNameToId[thread_1.Name]);

            // third: opening the A method at time 0.1
            var openMethod = profileEvents[2];

            Assert.Equal(ProfileEventType.Open, openMethod.Type);
            Assert.Equal(a_1.RelativeTime, openMethod.RelativeTime);
            Assert.Equal(2, openMethod.Depth);
            Assert.Equal(2, openMethod.FrameId);
            Assert.Equal(openMethod.FrameId, frameNameToId[a_1.Name]);

            // fourth: close the A method at time 0.3 (relativeTime * 2 + metric)
            var closeMethod = profileEvents[3];

            Assert.Equal(ProfileEventType.Close, closeMethod.Type);
            Assert.Equal(a_1.RelativeTime + a_1.Metric + a_2.Metric, closeMethod.RelativeTime);
            Assert.Equal(2, closeMethod.Depth);
            Assert.Equal(2, closeMethod.FrameId);
            Assert.Equal(closeMethod.FrameId, frameNameToId[a_2.Name]);

            // fifth: close the Thread at time 0.3 (relativeTime * 2 + metric)
            var closeThread = profileEvents[4];

            Assert.Equal(ProfileEventType.Close, closeThread.Type);
            Assert.Equal(thread_1.RelativeTime + thread_1.Metric + thread_2.Metric, closeThread.RelativeTime);
            Assert.Equal(1, closeThread.Depth);
            Assert.Equal(1, closeThread.FrameId);
            Assert.Equal(closeThread.FrameId, frameNameToId[thread_2.Name]);

            // sixth: close the Process at time 0.3 (relativeTime * 2 + metric)
            var closeProcess = profileEvents[5];

            Assert.Equal(ProfileEventType.Close, closeProcess.Type);
            Assert.Equal(process_1.RelativeTime + process_1.Metric + process_2.Metric, closeProcess.RelativeTime);
            Assert.Equal(0, closeProcess.Depth);
            Assert.Equal(0, closeProcess.FrameId);
            Assert.Equal(closeProcess.FrameId, frameNameToId[process_2.Name]);
        }