Exemplo n.º 1
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);
        }
Exemplo n.º 2
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 }));
                }
            }
        }
Exemplo n.º 3
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);
            }
        }