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 SpeedScopeStackSourceWriter.Sample(wrong.StackIndex, -1, wrong.RelativeTime, wrong.Metric, -1) }; var stackSource = new StackSourceStub(allSamples); var frameNameToId = new Dictionary <string, int>(); var frameIdToSamples = SpeedScopeStackSourceWriter.WalkTheStackAndExpandSamples(stackSource, leafs, frameNameToId); 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); }
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 SpeedScopeStackSourceWriter.Sample(b.StackIndex, -1, b.RelativeTime, b.Metric, -1) }; var stackSource = new StackSourceStub(allSamples); var frameNameToId = new Dictionary <string, int>(); var frameIdToSamples = SpeedScopeStackSourceWriter.WalkTheStackAndExpandSamples(stackSource, leafs, frameNameToId); 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); }