Ejemplo n.º 1
0
        private static void RegisterProfiler(ContainerBuilder builder)
        {
            if (ConfigurationHelpers.ShouldBeProfiling())
            {
                builder.Register((c, p) => new TextReporter(p.TypedAs <Func <Stream> >()))
                .As <TextReporter>()
                .As <ITransformReports>();

                builder.Register(c => new TimingStorage())
                .OnRelease(
                    storage =>
                {
                    // Write all the profiling results out to disk. Do this the ugly way
                    // because we don't know if any of the other items in the container have
                    // been removed yet.
                    Func <Stream> factory =
                        () => new FileStream(
                            Path.Combine(FileConstants.LogPath(), DefaultProfilerFileName),
                            FileMode.Append,
                            FileAccess.Write,
                            FileShare.Read);
                    var reporter = new TextReporter(factory);
                    reporter.Transform(storage.FromStartTillEnd());
                })
                .As <IStoreIntervals>()
                .As <IGenerateTimingReports>()
                .SingleInstance();

                builder.Register(c => new Profiler(
                                     c.Resolve <IStoreIntervals>()))
                .SingleInstance();
            }
        }
Ejemplo n.º 2
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.º 3
0
        private static void RegisterProfiler(ContainerBuilder builder)
        {
            try
            {
                var value = ConfigurationManager.AppSettings[LoadProfilerAppSetting];

                bool result;
                if (bool.TryParse(value, out result) && result)
                {
                    // Only register the storage and the profiler because we won't be writing out
                    // intermediate results here anyway. No point in registering report converters
                    builder.Register(c => new TimingStorage())
                    .OnRelease(
                        storage =>
                    {
                        // Write all the profiling results out to disk. Do this the ugly way
                        // because we don't know if any of the other items in the container have
                        // been removed yet.
                        Func <Stream> factory =
                            () => new FileStream(
                                Path.Combine(FileConstants.LogPath(), DefaultProfilerFileName),
                                FileMode.OpenOrCreate,
                                FileAccess.Write,
                                FileShare.Read);
                        var reporter = new TextReporter(factory);
                        reporter.Transform(storage.FromStartTillEnd());
                    })
                    .As <IStoreIntervals>();

                    builder.Register(c => new Profiler(
                                         c.Resolve <IStoreIntervals>()));
                }
            }
            catch (ConfigurationErrorsException)
            {
                // could not retrieve the AppSetting from the config file
                // meh ...
            }
        }
Ejemplo n.º 4
0
        private static void RegisterProfiler(ContainerBuilder builder)
        {
            if (ConfigurationHelpers.ShouldBeProfiling())
            {
                builder.Register((c, p) => new TextReporter(p.TypedAs<Func<Stream>>()))
                        .As<TextReporter>()
                        .As<ITransformReports>();

                builder.Register(c => new TimingStorage())
                    .OnRelease(
                        storage =>
                        {
                            // Write all the profiling results out to disk. Do this the ugly way
                            // because we don't know if any of the other items in the container have
                            // been removed yet.
                            Func<Stream> factory =
                                () => new FileStream(
                                    Path.Combine(FileConstants.LogPath(), DefaultProfilerFileName),
                                    FileMode.Append,
                                    FileAccess.Write,
                                    FileShare.Read);
                            var reporter = new TextReporter(factory);
                            reporter.Transform(storage.FromStartTillEnd());
                        })
                    .As<IStoreIntervals>()
                    .As<IGenerateTimingReports>()
                    .SingleInstance();

                builder.Register(c => new Profiler(
                        c.Resolve<IStoreIntervals>()))
                    .SingleInstance();
            }
        }
Ejemplo n.º 5
0
        private static void RegisterProfiler(ContainerBuilder builder)
        {
            try
            {
                var value = ConfigurationManager.AppSettings[LoadProfilerAppSetting];

                bool result;
                if (bool.TryParse(value, out result) && result)
                {
                    // Only register the storage and the profiler because we won't be writing out
                    // intermediate results here anyway. No point in registering report converters
                    builder.Register(c => new TimingStorage())
                        .OnRelease(
                            storage =>
                            {
                                // Write all the profiling results out to disk. Do this the ugly way
                                // because we don't know if any of the other items in the container have
                                // been removed yet.
                                Func<Stream> factory =
                                    () => new FileStream(
                                        Path.Combine(FileConstants.LogPath(), DefaultProfilerFileName),
                                        FileMode.OpenOrCreate,
                                        FileAccess.Write,
                                        FileShare.Read);
                                var reporter = new TextReporter(factory);
                                reporter.Transform(storage.FromStartTillEnd());
                            })
                        .As<IStoreIntervals>();

                    builder.Register(c => new Profiler(
                            c.Resolve<IStoreIntervals>()));
                }
            }
            catch (ConfigurationErrorsException)
            {
                // could not retrieve the AppSetting from the config file
                // meh ...
            }
        }
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);
            }
        }