Ejemplo n.º 1
0
        public void AddBaseInterval()
        {
            var tree = new TimingTree();

            var owner = new Mock <IIntervalOwner>();
            {
                owner.Setup(o => o.CurrentTicks)
                .Returns(10L);
            }

            var group = new TimingGroup();

            using (var interval = new TimerInterval(owner.Object, group, "a"))
            {
                interval.Start();
                tree.AddBaseInterval(interval);

                Assert.That(
                    tree.BaseIntervals(group),
                    Is.EquivalentTo(
                        new ITimerInterval[]
                {
                    interval
                }));
            }
        }
Ejemplo n.º 2
0
        private static TimingTree BuildTree(ITimerInterval[] parents, ITimerInterval[][] children)
        {
            var result = new TimingTree();

            for (int i = 0; i < parents.Length; i++)
            {
                result.AddBaseInterval(parents[i]);
                for (int j = 0; j < children[i].Length; j++)
                {
                    result.AddChildInterval(parents[i], children[i][j]);
                }
            }

            return(result);
        }
Ejemplo n.º 3
0
        public void CopyTreeCompletely()
        {
            var owner = new Mock <IIntervalOwner>();
            {
                owner.Setup(o => o.CurrentTicks)
                .Returns(10L);
            }

            var group   = new TimingGroup();
            var parents = new ITimerInterval[]
            {
                new TimerInterval(owner.Object, group, "a"),
                new TimerInterval(owner.Object, group, "b"),
                new TimerInterval(owner.Object, group, "c"),
            };

            var children = new[]
            {
                new ITimerInterval[]
                {
                    new TimerInterval(owner.Object, group, "aa"),
                    new TimerInterval(owner.Object, group, "ab"),
                    new TimerInterval(owner.Object, group, "ac"),
                },
                new ITimerInterval[]
                {
                    new TimerInterval(owner.Object, group, "ba"),
                    new TimerInterval(owner.Object, group, "bb"),
                    new TimerInterval(owner.Object, group, "bc"),
                },
                new ITimerInterval[]
                {
                    new TimerInterval(owner.Object, group, "ca"),
                    new TimerInterval(owner.Object, group, "cb"),
                    new TimerInterval(owner.Object, group, "cc"),
                },
            };

            var tree      = BuildTree(parents, children);
            var otherTree = new TimingTree(tree);

            Assert.That(otherTree.BaseIntervals(group), Is.EquivalentTo(parents));
            Assert.That(otherTree.ChildIntervals(parents[0]), Is.EquivalentTo(children[0]));
            Assert.That(otherTree.ChildIntervals(parents[1]), Is.EquivalentTo(children[1]));
            Assert.That(otherTree.ChildIntervals(parents[2]), Is.EquivalentTo(children[2]));

            CleanUpIntervals(parents, children);
        }
Ejemplo n.º 4
0
        public void ToReport()
        {
            var group       = new TimingGroup();
            var description = "description";
            var ticks       = 10L;

            var interval = new Mock <ITimerInterval>();
            {
                interval.Setup(i => i.Group)
                .Returns(group);
                interval.Setup(i => i.Description)
                .Returns(description);
                interval.Setup(i => i.TotalTicks)
                .Returns(ticks);
            }

            var           path    = TempFile();
            Func <Stream> builder = () => new FileStream(path, FileMode.Create, FileAccess.Write);

            var reporter = new TextReporter(builder);

            var tree = new TimingTree();

            tree.AddBaseInterval(interval.Object);

            var report = new TimingReport(tree);

            reporter.Transform(report);

            using (var stream = new FileStream(path, FileMode.Open, FileAccess.Read))
            {
                var result = FromStream(stream);
                Assert.AreEqual(
                    string.Format(
                        CultureInfo.CurrentCulture,
                        "Description    Total time (ms)" + Environment.NewLine + "{0}    {1}" + Environment.NewLine,
                        description,
                        ticks / 10000),
                    result);
            }
        }
Ejemplo n.º 5
0
        public void AddChildInterval()
        {
            var tree = new TimingTree();

            var owner = new Mock <IIntervalOwner>();
            {
                owner.Setup(o => o.CurrentTicks)
                .Returns(10L);
            }

            var group = new TimingGroup();

            using (var parent = new TimerInterval(owner.Object, group, "a"))
            {
                parent.Start();
                tree.AddBaseInterval(parent);
                using (var child = new TimerInterval(owner.Object, group, "b"))
                {
                    child.Start();
                    tree.AddChildInterval(parent, child);
                    Assert.That(tree.ChildIntervals(parent), Is.EquivalentTo(new ITimerInterval[] { child }));
                }
            }
        }
Ejemplo n.º 6
0
        public void ToReportWithMultiLevelIntervals()
        {
            var ticks = 10L;

            var group  = new TimingGroup();
            var parent = new Mock <ITimerInterval>();
            {
                parent.Setup(i => i.Group)
                .Returns(group);
                parent.Setup(i => i.Description)
                .Returns("parent");
                parent.Setup(i => i.TotalTicks)
                .Returns(ticks);
            }

            var child1 = new Mock <ITimerInterval>();
            {
                child1.Setup(i => i.Group)
                .Returns(group);
                child1.Setup(i => i.Description)
                .Returns("child1");
                child1.Setup(i => i.TotalTicks)
                .Returns(ticks);
            }

            var child2 = new Mock <ITimerInterval>();
            {
                child2.Setup(i => i.Group)
                .Returns(group);
                child2.Setup(i => i.Description)
                .Returns("child2");
                child2.Setup(i => i.TotalTicks)
                .Returns(ticks);
            }

            var           path    = TempFile();
            Func <Stream> builder = () => new FileStream(path, FileMode.Create, FileAccess.Write);

            var reporter = new TextReporter(builder);

            var tree = new TimingTree();

            tree.AddBaseInterval(parent.Object);
            tree.AddChildInterval(parent.Object, child1.Object);
            tree.AddChildInterval(parent.Object, child2.Object);

            var report = new TimingReport(tree);

            reporter.Transform(report);

            using (var stream = new FileStream(path, FileMode.Open, FileAccess.Read))
            {
                var result      = FromStream(stream);
                var textBuilder = new StringBuilder();
                {
                    textBuilder.AppendLine("Description   Total time (ms)");
                    textBuilder.AppendLine(
                        string.Format(
                            CultureInfo.CurrentCulture,
                            "{0}        {1}",
                            parent.Object.Description,
                            ticks / 10000));
                    textBuilder.AppendLine(
                        string.Format(
                            CultureInfo.CurrentCulture,
                            "    {0}      {1}",
                            child1.Object.Description,
                            ticks / 10000));
                    textBuilder.AppendLine(
                        string.Format(
                            CultureInfo.CurrentCulture,
                            "    {0}      {1}",
                            child2.Object.Description,
                            ticks / 10000));
                }

                Assert.AreEqual(textBuilder.ToString(), result);
            }
        }